[SOLVED] Big Confusion with simple code snippet for MV

tzamis

Villager
Member
Joined
Nov 28, 2017
Messages
21
Reaction score
4
First Language
Greek
Primarily Uses
RMMV
I'm pretty new to JS, but I usually manage to pull off small variations to the default gameplay, by using some basic, non-complex scripting. Normally I have no trouble at all, but this time it seems that I hit a dead end.

What I want to achieve : Actor X gets afflicted by a State. At the moment of his next action ( I use Yanfly's BuffsStatesCore notetags for this), if another particular actor in the party doesn't wear a specific armor, Actor X gets afflicted by an additional State.

What I tried :
Code:
<Custom Action Start Effect>
var actor = $gameActors.actor(id);
var armor = $dataArmors[id];
if (!actor.equips(4, armor)) {
  target.addState(id);
}
</Custom Action Start Effect>

Unfortunately, nothing happens!

Then I experimented a bit by removing the exclamation mark

Code:
<Custom Action Start Effect>
var actor = $gameActors.actor(id);
var armor = $dataArmors[id];
if (actor.equips(4, armor)) {
  target.addState(id);
}
</Custom Action Start Effect>

Funny conclusion with this one: the second state affects the target, no matter if the other actor equips the item or not!

I must be missing something very basic here...
 

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
149
First Language
English
Primarily Uses
RMMV
Use the condition !actor.hasArmor(armor) instead. Should work.
Also maybe change target.addState to user.addState (because the target I believe would refer to the target of whatever skill the actor uses, not the actor himself).
 

tzamis

Villager
Member
Joined
Nov 28, 2017
Messages
21
Reaction score
4
First Language
Greek
Primarily Uses
RMMV
Thanks a lot, it worked indeed! Do you have any idea what's different on your "command" that makes it successful? I mean, it's almost identical to the "equips" one, which has worked fine for me in the past, except this single occasion. I didn't even know that hasArmor existed in the first place, until you mentioned it and I took a look in the rpg_objects.js file.

Thanks again friend!
 

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
149
First Language
English
Primarily Uses
RMMV
No problem, glad it worked out!

Your command isn't entirely wrong, but it's not called correctly. If you look at the rpg_objects.js file, the actor.equips() function doesn't accept any arguments. It simply returns an array containing the actor's equipped items. Therefore, you would want to check if that array includes the item you're looking for.

So, the correct way to call it would be actor.equips().contains(armor); which would return true if the actor did have the armor equipped.

And guess what, the actor.hasArmor(armor); does exactly that. Neat.
 

tzamis

Villager
Member
Joined
Nov 28, 2017
Messages
21
Reaction score
4
First Language
Greek
Primarily Uses
RMMV
Thanks a lot for the thorough explanation! Gave me a better insight of how things work!
 

Latest Threads

Latest Posts

Latest Profile Posts

I'm really sorry I haven't done any streams. I actually just got home from the hospital after a week and a half.
I'm not dead - I promise :stickytongue:

Anyway, some pokemon inspired art (dont ask me which one tho xD)
reali.png
Writing boss music for Pale Coins. This is the Goblin Mage's theme!

Caz
I've been trying to upload more video tutorials for RMMZ lately! Does anyone have a topic they'd like to see covered? :ehappy:

Forum statistics

Threads
129,716
Messages
1,204,592
Members
170,791
Latest member
Clementine
Top