Return Consumable item Id

fenler

Villager
Member
Joined
Mar 30, 2019
Messages
5
Reaction score
1
First Language
english
Primarily Uses
RMMV
Hello,
I'm trying to get store the id of a consumable as it's used. Long story short, I creating several alcoholic consumables that run through a common event that checks how sloppy the characters gotten. When they've had too many, the system kicks back a message saying so and prevents further use. The problem is that I couldn't find a way to do this without consuming the item. My solution was to use a $gameParty.gainItem with the items id to restore the lost item. I can't figure out the script to return the used item's id though. Any help would be much appreciated.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,115
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
If you have a Game_Item object (i.e. anything from the party inventory) then you should be able to retrieve its ID as item.itemId(). If you're using an entry from $dataItems then it'll be item.id. Plugins may affect this (e.g. independent items from Yanfly's Item Core).

I actually made a simple plugin a while back that lets you set script conditions in notetags for consuming items; the item still gets applied to the target as usual, but if the condition isn't met then it won't be consumed. Not sure if that's quite what you want, and my approach is probably not the most efficient, but here's a link in case you want to have a look: view/download file (Google Drive).

When selecting an item to use, the game first checks whether anyone in the party can use the item, by calling the canUse function on each party member. So another approach could be to alias the canUse function. :)
 

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
557
Reaction score
232
First Language
english
Primarily Uses
RMMV
you shouldnt need a script call for this. just use Change Item to add 1 back into inventory same time as the "to drunk" message in the common event
 

fenler

Villager
Member
Joined
Mar 30, 2019
Messages
5
Reaction score
1
First Language
english
Primarily Uses
RMMV
Thanks for the quick responses. Apologies in advance for my lack of knowledge on how to work a forum. This is like the third time in my life I've used one.
you shouldnt need a script call for this. just use Change Item to add 1 back into inventory same time as the "to drunk" message in the common event
The reason this didn't work for me is that Change Item requires you to select the item. I was trying to get the common event to store the itemId as a variable and then run Change Item taking the variable as one of the arguments. That way I wouldn't need to build a conditional branch for each item.
If you have a Game_Item object (i.e. anything from the party inventory) then you should be able to retrieve its ID as item.itemId(). If you're using an entry from $dataItems then it'll be item.id. Plugins may affect this (e.g. independent items from Yanfly's Item Core).

I actually made a simple plugin a while back that lets you set script conditions in notetags for consuming items; the item still gets applied to the target as usual, but if the condition isn't met then it won't be consumed. Not sure if that's quite what you want, and my approach is probably not the most efficient, but here's a link in case you want to have a look: view/download file (Google Drive).
Your plugin worked like a charm. For my own learning though, what would be the proper way to call the item.itemId() function. I'm a total novice with javascript. I've tried:
Code:
$gameVariables.setValue(15,$dataItems[item.itemId()])
as well as several other iterations of that. In the common events, it just doesn't work. Using notetag scripts (with the HIME_FormulaEffects plugin), it breaks the game and returns a type error.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,115
Reaction score
1,525
First Language
EN
Primarily Uses
RMMZ
Your plugin worked like a charm. For my own learning though, what would be the proper way to call the item.itemId() function. I'm a total novice with javascript. I've tried:
Code:
$gameVariables.setValue(15,$dataItems[item.itemId()])
as well as several other iterations of that. In the common events, it just doesn't work.
This is because script calls are executed in the context of an event interpreter, where there's generally no "item" variable to reference (thus, probably, a "cannot read property x of undefined" error). When an item is used from the inventory (Scene_Item) it performs the effects then, if there's a common event to run, it returns to Scene_Map, unloading the previous scene and its data in the process. Long story short, I'm fairly sure the engine has forgotten which item was used by the time it runs any attached common event. :kaoswt:

Without using a plugin to extend/override the basic code, one workaround could be to assign a variable in the item formula (assuming your item makes use of the formula box). E.g. if your item has a formula like this:
Code:
50 + a.mat
You could change it to something like this:
Code:
v[15] = this.item().id; 50 + a.mat
This should set game variable 15 equal to the ID of the item being used, then evaluate and return the original formula as usual. :kaojoy:

The damage formula is evaluated in a Game_Action context, hence the access to the item function. This function retrieves the database entry for the appropriate item, so the item ID is found in the id property. :)

If you want to avoid using the formula box, Yanfly's Skill Core is a plugin that offers, for example, an <After Eval> skill/item notetag. With that, you could try something like this:
Code:
<After Eval>
$gameVariables.setValue(15, item.id);
</After Eval>
Yanfly's plugin explicitly defines the item variable before processing the notetag eval, that's why it can be referenced here so concisely/easily~
 

fenler

Villager
Member
Joined
Mar 30, 2019
Messages
5
Reaction score
1
First Language
english
Primarily Uses
RMMV
Oh I see. Both methods took care of it. I guess the plugin running the notetags before weren't defining the variable before running the common event. I'm quickly discovering I need to pick apart how the software runs to make full use of the plugins. I planned on it anyways, just not so soon. Thank you for the help.
 

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top