YEP Equip Requirement Help

My game has a similar system to the S.P.E.C.I.A.L system in Fallout. I'm trying to make is so that a character can't equip weapons/items unless their stat is high enough. I found a plugin that let me limit equipment by stats but there was no way to differentiate whose stats were checked so I gave up on it. I saw a similar yanfly plugin and after looking around and playing with it I saw the "insanity" scripting feature and figured that would work. The base script is...

<Custom Equip Requirement Condition>
if (user.name() === ‘Harold’) {
condition = true;
} else {
condition = false;
}
</Custom Equip Requirement Condition>

I'm trying to use that and get it to work with an additional line to check a variable like so...

<Custom Equip Requirement Condition>
if (user.name() === 'Harold')
if $gameVariables.value(301) >== 1
{
condition = true;
} else {
condition = false;
}
</Custom Equip Requirement Condition>

It doesn't work but I feel like this should, in theory, I'm just not writing the coding right. What would be the proper way for me to write that? Assuming I can even get it to work the way I want.
What exactly are you trying to accomplish? If you want it so that the actor can't equip something if their base attack stat is too low then you can just use this:

<Equip Requirement>
atk >= 10
</Equip Requirement>

Now this will only be available if the actor's attack stat is equal to or greater then 10.
Yeah, I know if I wanted to use the attack stat, or any default parameter, I could just do that. I don't want to do that though. Like I said, my game uses a system similar to the S.P.E.C.I.A.L system in Fallout.

I want the game to:
1, check which actor is trying to equip something.
2, depending on which actor is attempting to equip something, check a variable to see if said actor can equip the item.
Ah ok that part wasn't clear. I thought you had renamed the default stats to the SPECIAL acronym and was doing that for the checking. So what you actually want is the equipment to check for certain variables.
Basically
is there any chance your character is not named "harold"?
because the code you provided is VERY similar to the example code.

anyway, in JS >== is not valid.. you want >= (greater or equal to)
by the way the === is a strict version of ==.

you should also read this:
https://www.w3schools.com/jsref/jsref_operators.asp

Also on your note tags they can't be any trailing spaces in the <>.
There aren't on your but there are in Yanfly's example.

Code:
<Something Good> //Good
<Something Bad > //Bad

so this should do what you want
Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(5) >= 90 && //checks Variable 5 to bear greater or equal to 90
user.name() == 'Harold'; //are you sure you need this
</Custom Equip Requirement Condition>



hope it helps
Why are you checking the name rather than the id?
@Fornoreason1000 Heh. No, my character's name isn't Harold, but I just copied the default code as an example. I changed the name to my characters name in the code I used. I tried your suggestion as well, still doesn't work tough. This is the code I tried...
Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(301) >= 7 &&
user.name() == 'Dope';
</Custom Equip Requirement Condition>

@Shaz Because that's how Yanfly had it setup. I honestly don't care how it checks, actor name or ID, I just want it to check.
@Fornoreason1000
Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(301) >= 7 &&
user.name() == 'Dope';
</Custom Equip Requirement Condition>

I find that strange since that code works like a charm for me. are you absolutely sure Variable 301 is reaching 7? you can check it or force it by Pressing F9 and setting it.
Also make sure 'Dope' is spelt correctly, I believe it is case sensitive.

And to be sure, i pasted the code the works on my end.
Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(301) >= 7 &&
user.name() == "Dope";
</Custom Equip Requirement Condition>

and to doubly make sure,
Code:
 $gameVariables.value(index) >= value
// index is the variable number
// value is the actual value of the variable
// >= means Greater or Equal to


now the reason @Shaz is asking you about the name is because some games allow you to change the player name, which makes checking the name a very poor choice. if you don't plan on changing your characters name then it isn't a issue. another possible problem is if you have two characters with the same name, but if you don't then again no issue
@Fornoreason1000 I went back and tried again and I got it to work! I had to sell the weapon already in the players inventory and buy a new one but it's working fine. If I wanted to have one weapon have conditions for multiple actors could I attach more lines of code like...

Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(301) >= 7 &&
user.name() == "Dope";
condition = $gameVariables.value(303) >= 7 &&
user.name() == "Char2";
condition = $gameVariables.value(305) >= 7 &&
user.name() == "Char3";
</Custom Equip Requirement Condition>

Yeah I get Shaz's reasoning, from a coding standpoint it would probably be easier to specify it based on actor as well. I'm not sure how that would look though and presented it in the fashion I found it. I'm just happy to get things working right 🙂
Glad you got it working 🙂


To Answer your Question
Code:
<Custom Equip Requirement Condition>
condition = $gameVariables.value(301) >= 7 &&
user.name() == "Dope";
condition = $gameVariables.value(303) >= 7 &&
user.name() == "Char2";
condition = $gameVariables.value(305) >= 7 &&
user.name() == "Char3";
</Custom Equip Requirement Condition>
This will not work, Becuase the second condition will cancel out the first, and the third cancels out the the rest.
your code will do this when Char2 try to equip it
Code:
not "Dope" cannot equip...
is 'Char 2" yes we can equip
not "Char 3" we cannot equip
result: cannot equip

Dope isnt much better
Code:
when Dope
is Dope, can equip
not char2, cannot equip
not char3 cannot equip
result: cannot equip

infact only char3 can equip it
Code:
when Dope
not Dope, cannot equip
not char2, cannot equip
is char3 can equip
result: can equip

This obviously is undesirable since only char3 will ever be able to equip it. so here it becomes a little more complex.
we make an array that contains the "Names" of our characters then check if the current name exist within the array.

Code:
var validChars = ["Dope", "Dopey", "Hope"];
condition = $gameVariables.value(301) >= 7 &&
validChars.contains(user.name());

and if you decide to use Actor Id's
Code:
var validChars = [1,2,1025];
condition = $gameVariables.value(301) >= 7 &&
validChars.contains(user.actorId());
@Fornoreason1000 Ah, figured it wouldn't be that easy. I understand the array and see how it's setup, however, if done that way then each valid actor would be checking for only 1 variable. 301 in this case. That's not going to work because the variables are independent between actors.

Unless I misunderstand how that code is going to work, if...
301 = Dope's strength | 303 = Dopey's strength | 305 = Hope's strength
301=8 | 303=5 | 305=2
Dopey can still equip the weapon even though his strength is 5, Hope as well with 2, because Dope's strength is 8.
The other things with using names is that if you let your player name a character, you have to cater for all variations of that name - dope, Dope, DOPE are 3 different names and if you checked for 'Dope' only one would match. If you DON'T let your player name a character, you would have an issue if you got half way through the game and decided you wanted to change their name, or you'd spelled it wrong.

You would be looking for something like this ... gets more untidy the more characters you have:

<Custom Equip Requirement Condition>
condition = ($gameVariables.value(301) >= 7 && user.name() == "Dope") ||
($gameVariables.value(303) >= 7 && user.name() == "Char2") ||
($gameVariables.value(305) >= 7 && user.name() == "Char3")
</Custom Equip Requirement Condition>

I don't use Yanfly's plugins, so I'm not sure about the syntax or if you can expand a single condition over multiple lines. But that just shows how you can check for multiple conditions in a single call.
@Shaz Wow. My good sir, I just tried it out and that actually works! Thanks for the help! @Fornoreason1000 as well!

Edit:
One more question, for completion sake. If I wanted to look up multiple variables for multiple actors actors could I? Would I set it up like...

Code:
<Custom Equip Requirement Condition>
condition = ($gameVariables.value(301) >= 7 && $gameVariables.value(311) >= 7 && user.name() == "Dope") ||
($gameVariables.value(303) >= 7 && $gameVariables.value(303) >= 7 && user.name() == "Char2") ||
($gameVariables.value(305) >= 7 && $gameVariables.value(303) >= 7 && user.name() == "Char3")
</Custom Equip Requirement Condition>

I'll probably switch over to using acrot ID's, but first I want to make sure I can do everything else working with the script.

Edit 2: I tried with multiple variables and it's working like a charm. Thanks again for all the help!
@Fornoreason1000 Ah, figured it wouldn't be that easy. I understand the array and see how it's setup, however, if done that way then each valid actor would be checking for only 1 variable. 301 in this case. That's not going to work because the variables are independent between actors.

Unless I misunderstand how that code is going to work, if...
301 = Dope's strength | 303 = Dopey's strength | 305 = Hope's strength
301=8 | 303=5 | 305=2
Dopey can still equip the weapon even though his strength is 5, Hope as well with 2, because Dope's strength is 8.

oops, yeah didn't realize you are using different Variables.
the array thing still can be done, just you need two of them
Code:
<Custom Equip Requirement Condition>
//Our characters
var ValidChars = ["DOPE", "Dope", 'dope"];

//Variable Number representing STR, must be in same Order as ValidChars
var STR = [301,303,305];

//if we don't have a valid char, findIndex() will return -1!
var index = ValidChars.findIndex(Char => Char == user.name());

//if index is undefined, that means it is not a valid character,
condition = index != -1 && $gameVariables.value(STR[index]) >= 7;
</Custom Equip Requirement Condition>

makes it much easier in-case you game has like 30 characters that can equip this

and for future reference , using actorId's is more or less the same!

Code:
<Custom Equip Requirement Condition>
//Our characters
var ValidChars = [1,2,1024];

//Variable Number representing STR, must be in same Order as ValidChars
var STR = [301,303,305];

//if we don't have a valid char, findIndex() will return -1!
var index = ValidChars.findIndex(Char => Char == user.actorId());

//if index is undefined, that means it is not a valid character,
condition = index != -1 && $gameVariables.value(STR[index]) >= 7;
</Custom Equip Requirement Condition>

Hope it helps
And yet another suggestion you could use key/value pairs.

Code:
var varMap = {
    Dope: 301,
    Dopey: 303,
    Hope: 305
};
condition = $gameVariables.value(varMap[user.name()]) >= 7;

Original thread: https://forums.rpgmakerweb.com/threads/yep-equip-requirement-help.103278/