RMMV Equip weight system with YEP_EquipRequirements

Chazareth

Veteran
Veteran
Joined
Jul 18, 2016
Messages
157
Reaction score
27
First Language
English
Primarily Uses
RMMV
I'm creating a game with a weight system for equipment, where each actor has a certain amount of Power, and each piece of equipment has Weight. The actors can only equip items as long as the total Weight does not exceed Power.

To do this, the Max HP parameter has been changed to Power and the Max MP parameter has been changed to Weight. Then by using Yanfly's Equip Core and Equip Requirements I can use note tags to make this effect work.

First, each actor's Max HP (Power) is set to x amount. Then, each piece of equipment has a Weight value by setting the Max MP in the editor. Finally, a note tag is used so that if the actor tries to equip that item and it's weight value exceeds remaining Power, the item cannot be equipped. Here is the note tag that I use:



<Custom Equip Requirement Condition>
var output = user.mhp;
var weight = user.mmp;
var power = output - weight; //Sets the amount of available power
if (Math.floor(user.equips()[1].params[1] - 87) >= 0) { //Check if the item to be equipped is lighter than what is currently equipped. If so...
condition = true; //Can be equipped
} else { //If not...
var diff = Math.abs(user.equips()[1].params[1] - 87); //Since the item to be equipped is heavier, get the absolute value of the difference in weight
if (diff <= power) { //If the difference in weight is less than or equal to the amount of available power...
condition = true; //Can be equipped
} else {
condition = false; //Cannot be equipped
}
}
</Custom Equip Requirement Condition>

EDIT: I had the note tag wrong initially, but it seems to be fixed now. Everything is working now except for the problem of empty equip slots, where the weight in that slot is 0 (nothing equipped), but the actual value is undefined.
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,818
Reaction score
5,213
First Language
Dutch
Primarily Uses
RMXP

I've moved this thread to Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.

 

Chazareth

Veteran
Veteran
Joined
Jul 18, 2016
Messages
157
Reaction score
27
First Language
English
Primarily Uses
RMMV
The problem I'm having now is that it won't work for equipment slots that are empty. The reason is because user.equips()[1].params[1] is trying to find a value that doesn't exist because nothing is equipped in that slot. If nothing is equipped, the value is simply undefined, but in the context of the game, the value should be 0 (nothing is equipped so that slot should have a weight value of 0). I was wondering if there was a way to initialize these undefined values for empty equip slots so that they start out as 0.
 
Last edited:

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
216
Reaction score
168
First Language
English
Primarily Uses
RMMV
I'm still learning javascript myself but could you add "|| 0" somewhere to your if statement to check if the value is zero and allow equipping?
 

Chazareth

Veteran
Veteran
Joined
Jul 18, 2016
Messages
157
Reaction score
27
First Language
English
Primarily Uses
RMMV
I'm still learning javascript myself but could you add "|| 0" somewhere to your if statement to check if the value is zero and allow equipping?
Yeah, I tried that but I got the same result. The weight value for an empty slot starts out as undefined, so it won't work. I tried equipping the item anyway (this drops an error but doesn't crash the game), and then checking the weight value for that slot through the console. It actually returned the proper weight value, which would mean the the note tag will now work but I noticed that when I unequipped the item, the weight value became undefined again, as expected. So maybe now I'm wondering if there's a way to make the game treat all undefined values as 0.
 

xDRAGOONx

Veteran
Veteran
Joined
Jan 22, 2019
Messages
216
Reaction score
168
First Language
English
Primarily Uses
RMMV
Maybe you just need an auto event that runs a script at the start of the game that sets these values to zero before it attempts to use them. The same way you would declare any variables used in damage formulas.

-EDIT-
Maybe you can set them in a script like this:
$gameActors(1).equips()[1].params[1] = $gameActors(1).equips()[1].params[1] || 0;
 
Last edited:

Chazareth

Veteran
Veteran
Joined
Jul 18, 2016
Messages
157
Reaction score
27
First Language
English
Primarily Uses
RMMV
Maybe you can set them in a script like this:
$gameActors(1).equips()[1].params[1] = $gameActors(1).equips()[1].params[1] || 0;
Still nothing. The error says object is not a function. I'm guessing $gameActors(1).equips()[1].params[1] is not actually a variable, which means that it can't be changed by using a script call to change the values of variables.

Maybe what I'm trying to do requires scripting beyond what I'm capable of.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Evil7 added!


I did a bit of a remake on one of the maps, also I made a particle for jumping into the portal, and one for traveling through the portal. I'll probably add more sparkles later to embellish it. :LZSwink:
Polished the animation and added details :kaojoy:
Ami
What do you think about the Wood Bridge inside of Volcano?
Yet another gaming question, i'm currently playing Last of Us 2 and want to get another game to play next but can't decide between Ghost of Tsushima, Miles Morales & Jedi Fallen Order. After the latest mandalorian i AM on a star wars kick, but i also LOVED the last spiderman game that prequels Miles Morales. Ghost of Tsushima is the bottom of my list but i heard it was AWESOME. Just want a good story & fun gameplay.

Forum statistics

Threads
105,686
Messages
1,015,541
Members
137,362
Latest member
sdramose
Top