[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

Current status screens for Shadows of the Earth: The Vrila'an Legend. Need to do something about the color scheme lol
Captura de pantalla (259).pngCaptura de pantalla (260).png
My first serious victim in game hacking - Pawnbarian.
Diana Path 2.png
I love these two design wise lol... The high school principal and the captain of the women's wrestling team. they team up as bosses to save the school's accreditation.
Kanori24 wrote on TheRamenGirl's profile.
I love your profile pic. Definitely one of my favorite scenes from OPM :D

Forum statistics

Threads
122,074
Messages
1,146,305
Members
160,359
Latest member
TheRagingKing
Top