Trying to change a value upon a certain character using an item?

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
Hey hey,
So I'm trying to do something where any character can use a consumable item, but using it on one particular character triggers a change in a variable. I've patched together a snippet of code, but it doesn't seem to be doing anything- maybe I'm not using the right syntax, or maybe I'm just going about it completely wrong, I'm not sure, but I'm a total beginner to JS, so any help at all would be appreciated.
Code:
if ($gameActors.actor(1) .consumeItem) {
$gameVariables.setValue(18, 3);
}
Thank you!
 

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
Looks like consumeItem is a function which is a truthy value in JS. When the if statement is executed variable 18 will always be set to the number 3. If you're not seeing 3 then the statement isn't being executed so there's one part you might have to troubleshoot. Is there more code to this?
 

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
Well, there certainly arent any 3s showing up in that variable...I wonder why it isn't executing? I have it set as a common event called when the item is used. Should I put it in the item's note tags instead?
 

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
Aha! I got it to work! For future reference: I had to nest it in another conditional branch to check that the actor was in the party first. Thanks for your help!
 

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
wait- no, it doesn't only work on the one character. Hmmm. This is tricky.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,089
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
I'd recommend Yanfly's Skill Core plugin here, if you're not using it already. It offers a set of <[Phase] Eval> tags that let you run JS code on use of the corresponding skill or item. Tested it with the following and it seemed to work:
Code:
<After Eval>
if (target.isActor() && target.actorId() === 1) {
  $gameVariables.setValue(18, 3);
}
</After Eval>
This will set variable #18's value to 3 immediately after being used on actor #1; change the values as appropriate.
 

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
I was having the item call a common event with the script in it upon use. Does the script only work in battle? It won't let me use it on the field, unless I'm just doing something wrong- the code you gave me goes in the item's notes, right? Sorry for being so needy about this, ugh.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,089
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
Yes, just put it in the item's notebox. Also, before you test, be sure to save your project after importing the Skill Core plugin. =)
 

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
Hm- I believe you, but it won't let me use any skill or item with the code applied...I'm really sorry to keep hassling about this!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,089
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
It's OK, happy to help out! ^_^

By default, MV disallows use of items if the item would have no effect, e.g. you can't use a healing potion on someone at full HP. (It's kinda annoying, I'll look into it.) I tested using an item that applied silence to the target, and it worked (and set the variable if used on actor #1) on the map and in battle. If that works for you, maybe you could just make an invisible state that does nothing and apply that when you use the item? :kaoswt:

Otherwise, what other plugins (if any) are you using?

Edit: @SpitBlaze :kaohi: I'm heading off for now, need some sleep. :kaoslp: Will check back tomorrow!
 
Last edited:

SpitBlaze

Villager
Member
Joined
Oct 9, 2016
Messages
11
Reaction score
2
First Language
English
Primarily Uses
Aha, that did it! Thank you so much for this, you're a total lifesaver! I should've just tried doing that before, haha. Thank you so much!!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,089
Reaction score
1,508
First Language
EN
Primarily Uses
RMMZ
Well, it's not the most obvious thing to try. =P

Happy RPG Making! :kaothx:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,868
Messages
1,017,066
Members
137,576
Latest member
SadaSoda
Top