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,787
Reaction score
5,209
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
210
Reaction score
165
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
210
Reaction score
165
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

Just finished composing a boss battle theme!
Scripted a multi-variable weather system that randomizes wind speed, cloudiness, rain, fogginess, etc, while attempting to realistically account for interactions between them (e.g. wind speed affects fogginess, cloudiness affects rain, etc), the current weather pattern, and the player's biome e.g. swamp, beach, etc. Now I "just" have to tie visuals and sounds to the variables so stuff actually happens...
I'm having a headache balancing the combat using flat defense so I'm gonna use percentual armor, in this pic, Simon has 16 on Defense which means all the incoming damage will be reduced by 16% this will ease my burden a bit.
!Have a nice day everybody¡
SO glad they patched outer worlds for switch! I can finally play it! Weird that other peeps are still having issues. I know it was really chugging on my lite when it first came out.

Forum statistics

Threads
105,555
Messages
1,014,620
Members
137,231
Latest member
anjing_gila
Top