[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

I think after I get this game done, I'm going to take a long vacation from game development. It feels great to see the coding skills get better and it is fun - but god it is also so exhausting.
Just advertising that I released version 0.9 of my game yesterday, for feedback purposes. My first game or creative endeavor ever :D Would be cool if someone tries it out!
An overall view of my full set of sprites so far, this was really fun to work in this past year! :kaopride:
1653056206274.png

Even though the game is cancelled, I'm still doing art in my spare time and seeing how it'd look.

It's a lot of fun. Wish I could be an artist!

Forum statistics

Threads
121,971
Messages
1,145,564
Members
160,250
Latest member
CaptainGummiFrogg
Top