Script call for using/activating an item

Epic EP

Villager
Member
Joined
Jun 14, 2016
Messages
9
Reaction score
0
First Language
Finnish
Primarily Uses
RMMV
I hope this is the right place to post this. :p I'm total newbie with coding, so I might be totally lost with this one.

The problem I'm having is failing to find a script based command for using an item with ID X in RPG Maker MV.

What I'm trying to do with this:
I'm making some quick slots for my game, so that instead of going to item menu player could use selected items by pressing dedicated keys. I have managed to make a common event to select an item and bind its ID to a variable. And tried to use items with that variable. I have managed to use it to reduce the number of the items with a script command, but not yet find a way to actually use/activate them.

This should work on a map rather than in a battle.

My best guess is at the moment something like this:

$gameActors.actor(0).useItem($dataItems[$gameVariables.value(141)], 1);
OR
$gameParty.useItem($dataItems[$gameVariables.value(141)], 1);

'$gameVariables.value(141)' being the ID X of an item as mentioned earlier.

Thanks for the tips and help. ^^

PS As a bonus: if somebody knows how to draw an icon of a state or item for example as a picture of floating image, I would appreciate learning that too. ;)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
A lot of people are going a slightly different route: have your script make the effects of that item directly and remove it from inventory after that.

The problem here is that the original function for use item is in the menues and opens the selection screen for the use - that is not easy to replicate in another section of the code, because it needs the screen. So people don't look for that function, but replicate the effect of the item.

Unfortunately this means that you have to check the item functions itself, and that depends on how many items you have. For a few items, you can simply replicate the effects - for a large item list, you would have to identify the effects based on item database, then call the same effects - that is a more complex code.
 

Epic EP

Villager
Member
Joined
Jun 14, 2016
Messages
9
Reaction score
0
First Language
Finnish
Primarily Uses
RMMV
A lot of people are going a slightly different route: have your script make the effects of that item directly and remove it from inventory after that.
Thank you for the quick reply. ^^

Although I must say this is a let down, because I was planing on having loads of items player might want to put there. And this forces me to limit the freedom of the choice to only few items, or I might just put the most commonly used items to the hot keys readily available.

Nevertheless thank you for the help and this solved my problems.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
not exactly - as I said there are two ways, but the other will require more complex code.

The item effects are stored in the datafiles, and with a large item list you'll have to identify the effects from those structures and then replicate them. That way you only need the item ID to continue, but you'll have to check the effect list and call them yourself.
 

Epic EP

Villager
Member
Joined
Jun 14, 2016
Messages
9
Reaction score
0
First Language
Finnish
Primarily Uses
RMMV
True. I probably misunderstood something at first. As I said I'm quite new to this stuff. ^^'
But I think I got the idea now- It requires a bit more studying the database and probably learning more coding, but I might get there.

I must say I am intrigued, and the second option definitely is more appealing, I'm just unsure if I can pull that off just yet.

Before I start to dig deeper, I want to make sure I got the idea about the process close enough.

Could the process be like:

1. Get the item id (as a variable).
After checking that the party has those items with them. etc ofc.

2. Check the items.json for the effects of the item with that id.
- Also checking that the item can be used out of battle (and other possible restrictions). If not abort and notify player.

3. Replicate those effects.
Meaning after identifying the effects I could just call\ execute them with some code. (Right?)

4. Decrease the number of items by one, if consumable.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
basically yes, but no need to go to the json files - the itemdata is already loaded and available
 

Epic EP

Villager
Member
Joined
Jun 14, 2016
Messages
9
Reaction score
0
First Language
Finnish
Primarily Uses
RMMV
Hmm. I see.

I need to learn few things like how to actually check the database and replicate the effects. Which means basically everything I guess. ^^'

Well I'll start going through the forums tomorrow. Too tired to do that now.

Thanks! You have been most helpful.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
start with the help file, not the forums - then perhaps go to the forum topic about script call equivalents to event commands as that might also help
 

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

Latest Threads

Latest Posts

Latest Profile Posts

"You can thank my later", "But you haven't done anything", "Well, that's why ..."
Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

Forum statistics

Threads
105,884
Messages
1,017,240
Members
137,609
Latest member
shododdydoddy
Top