[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
148
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
148
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

Not a bad weekend but anxiety kicking my but. Also wondering about Ms Littlefish. Some people move on. Anyways how is everyone doing?
I did a video review on Psychronic Games' Star Shift Origins, as they did a review on my game.
Check it out!
can someone show me how to play movies in RPG MAKER MZ?I don't know how to insert a movie
SF_People3_5 added!
index.php

Marketing seems to be about reducing dependence on luck to sell a product, as well as expanding the number of avenues in which luck can play a role in selling a product.

Forum statistics

Threads
118,635
Messages
1,117,452
Members
155,725
Latest member
PatrickCreator
Top