Martin

Veteran
Veteran
Joined
Apr 8, 2015
Messages
192
Reaction score
47
First Language
swe
Primarily Uses
RMMV
Hi, I can't figure out how to use a item in the eventing window.

I want this to happen on a main map
on player touch
Hero consume item 1

.. must i 'change items' and make a eventing of the items effect and restore?
 

mishakoc

Professional Procrastinator
Veteran
Joined
Jan 1, 2019
Messages
146
Reaction score
876
First Language
Czech
Primarily Uses
RMMV
You use Change Item: "Item Name" - 1. Then you event what the effect of using the item is.

Let's say you have a bread and you want the player to eat it when they sit on a chair and get 100 HP (or whatever):
>Change Item: Bread - 1
>Show text: The bread was delicious, you are now energized.
>Change HP: +100
 

Martin

Veteran
Veteran
Joined
Apr 8, 2015
Messages
192
Reaction score
47
First Language
swe
Primarily Uses
RMMV
So there is no way to "force use" an item?
I was kinda looking to avoid making the desired effect anywhere but on the item itself.

but thanks :)
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
There was a Script Line Snippet for that in VX-Ace, not seen someone offer it for MV yet.
With the standard Editor its not possible, but if you use the Eventcommand Script on 3rd Page of Eventcommands,
than it would theoretically be possible, but sadly i dont know the scriptcall equivalent for that.

Sorry for such useless answer.
I would like to have that snippet too for mv.

Edit here is the snippet from vx - ace , maybe someone can translate it to mv?
Code:
hero = $game_party.members[0]#<-The User
item = $data_items[0]  #[]<-Item_Id (I normaly exchange the Zero with a Game Variable to connect it with the key item choice window variable)
hero.use_item(item)
targets = if !item.for_friend?
[]
elsif item.for_all?
$game_party.members
else
[hero]
end
targets.each do |target|
item.repeats.times{target.item_apply(hero,item)}
end
This was usefull for Key Item Menu, you could use the Item ID you get when you choose an Item in Key Item List, to automatically consume that item and make use of its inbuild standard efects.
I realy hope someone can translate it and shares it with us.
 
Last edited:

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Not tested all that much, but it should work mostly maybe?

Code:
(function(v,i,a,u,t) {
i = $dataItems[+v || 0];
if (i) {
u = $gameParty.members()[0];
u.useItem(i);
a = new Game_Action(u);
a.setItemObject(i);
t = a.makeTargets();
for (n in t) a.apply(t[n]);
}})(YOUR_ITEM_ID_HERE);

Replace YOUR_ITEM_ID_HERE with the ID of the item to use. It can be a fixed value, a $gameVariable, etc.

Sorry it looks so ugly, but I wanted it to be compact so people could easily use it in the script box, given the limited space. Yes, that even means I committed the personal sin of having the opening curly brace on the same line as the block it belongs to.)

You'll have to apply any sound effects, visuals, etc whatever yourself, but this will use the item and consume it if consumable. I hope.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
Partialy it works, for example the Healing Potion works when you dont have full HP, but in standard MV it doesnt work if
you got full HP, the vx ace script snippet provided that behavior, the current mv translation does not.

Thank you for the Help, could you maybe assist fixing this?
And it is no Problem if you offer two Versions, one short one and one longer easier readable one, but thats up to you.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
I admit I don't really speak a word of ruby or whatever vxa uses, so I had to guess. What do you mean by "it doesn't work if you have full hp?" Do you mean it's consuming the potion regardless of full hp or partial hp?

Edit: And yeah, I can post a longer, more readable version once I get it working more in line with what the original did. (I'll need details on the differences though) I'll do that tomorrow though, it's late.
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
Yes exactly that.

Standard MV:
If Actor got full HP, the HP potion will not be used.
If Actor got partialy HP , the potion will be used.
this also works with elements and other stuff, like if you allready got poison, the poison item will not work until its stackable.

With the snippet:
it doesnt care about the hp or other things like normal mv does, the item is used no matter what.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Yeah so last night's was hastily written. This version tests to see if the item can be used before using it:

Code:
(function(v,i,t,a,c,u) {
i = $dataItems[+v || 0];
u = $gameParty.members()[0];
a = new Game_Action(u);
a.setItemObject(i);
t = a.makeTargets();
for (n in t) c = a.testApply(t[n]) || c;
if (u.canUse(i) && c) {
u.useItem(i);
for (n in t) a.apply(t[n]);
}})(YOUR_ITEM_ID_HERE);

And the more readable version (which probably won't fit in the script window)

Code:
(function(value, item, target, action, canBeApplied, user)
{
  item = $dataItems[+value || 0]; // assigns item, or no item if invalid
  user = $gameParty.members()[0]; // first party member = user
  action = new Game_Action(user); // create the action
  action.setItemObject(item); // assign the item to the action
  target = action.makeTargets(); // generate targets based on scope
  for (n in target) canBeApplied = action.testApply(target[n]) || canBeApplied; // test use
  if (user.canUse(item) && canBeApplied)
  {
    user.useItem(item); // use the item (consuming if consumable)
    for (n in target) action.apply(target[n]); // apply effect to target(s)
  }
})(YOUR_ITEM_ID_HERE); // replace YOUR_ITEM_HERE with an item id -- variables are good choices here
 
  • Like
Reactions: Bex

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
Thank you for the quick reply.
There seems to be an Error.
I made an Item that gives a Poison state and it seems the script uses it nearly Random on one of the Actors.
No matter if i change formation and put marsha actor id 3 on pos 2 , 3 or 4 the item is used on her., if i put her into lead position, than the actor on 2nd position is used for item. This nearly random behavior confuses me. Iam not native english, not sure if i explained well enough.

It should try to aply the item on the actor which is on Party member position 1.
When its for one Actor target.
When its for group, than on all group
The script reads like it would do that, but it doesnt for some reason.(i used the short version)
Edit:
Or like in Item Menu that you choose on which actor it should aply....but that isnt needed.
And maybe asked a little to much.
 
Last edited:

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Oh, right. makeTargets() is used (I think) by enemies to get targets based on scope, hence the random behavior when targeting one ally.

Code:
(function(v,i,t,a,c,u) {
i = $dataItems[+v || 0];
u = $gameParty.members()[0];
a = new Game_Action(u);
a.setItemObject(i);
t = i.scope == 7 ? [u] : a.makeTargets();
for (n in t) c = a.testApply(t[n]) || c;
if (u.canUse(i) && c) {
u.useItem(i);
for (n in t) a.apply(t[n]);
}})($gameVariables.value(5));

Code:
(function(value, item, target, action, canBeApplied, user)
{
  item = $dataItems[+value || 0]; // assigns item, or no item if invalid
  user = $gameParty.members()[0]; // first party member = user
  action = new Game_Action(user); // create the action
  action.setItemObject(item); // assign the item to the action
  target = item.scope == 7 ? [user] : a.makeTargets(); // generate targets based on scope
  for (n in target) canBeApplied = action.testApply(target[n]) || canBeApplied; // test use
  if (user.canUse(item) && canBeApplied)
  {
   user.useItem(item); // use the item (consuming if consumable)
   for (n in target) action.apply(target[n]); // apply effect to target(s)
  }
})(YOUR_ITEM_ID_HERE); // replace YOUR_ITEM_HERE with an item id -- variables are good choices here

That should just about do it I think. :)
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
This is awesome, the scope for User = Party Member 1, All Allies = All Party Members, and the compromiss for scope 1 Allie = Party Member 1
all semm to work fine.
2 Bugs was found and i additionaly asked Caethyril for assistence but i thought its maybe better written down here to, and who knows if he can help in this case.
1 Bug if Item Selection is Canceled with Escape Button, the Game Crashes, Item Scope Error Message appears. There is no Item Id in that case i believe, thats causing the error, maybe this can be solved with some kind of if statement to check that if there is no item id that the snippet does not need to run.
2 Bug if the Item has no Scope but is usable, in standard menu you can use those items, the script snippet seems not to do that.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Yeah oops, I forgot that a game action probably wouldn't take too kindly to having null items dropped on it (what happens when you cancel out)

Code:
(function(v,i,t,a,c,u) {
i = $dataItems[+v || 0];
if (i) { u = $gameParty.members()[0];
a = new Game_Action(u);
a.setItemObject(i);
t = i.scope == 7 ? [u] : a.makeTargets();
for (n in t) c = a.testApply(t[n]) || c;
if (u.canUse(i) && c) {
u.useItem(i);
for (n in t) a.apply(t[n]);
}}})(YOUR_ITEM_ID_HERE);

Code:
(function(value, item, target, action, canBeApplied, user)
{
  item = $dataItems[+value || 0]; // assigns item, or no item if invalid
  if (item)
  {
    user = $gameParty.members()[0]; // first party member = user
    action = new Game_Action(user); // create the action
    action.setItemObject(item); // assign the item to the action
    target = item.scope == 7 ? [user] : a.makeTargets(); // generate targets based on scope
    for (n in target) canBeApplied = action.testApply(target[n]) || canBeApplied; // test use
    if (user.canUse(item) && canBeApplied)
    {
     user.useItem(item); // use the item (consuming if consumable)
     for (n in target) action.apply(target[n]); // apply effect to target(s)
    }
  }
})(YOUR_ITEM_ID_HERE); // replace YOUR_ITEM_HERE with an item id -- variables are good choices here

What would a no-scope item do when used, anyway? Just common events? Never bothered with usable no-scope items so no idea!
 

Martin

Veteran
Veteran
Joined
Apr 8, 2015
Messages
192
Reaction score
47
First Language
swe
Primarily Uses
RMMV
Wow this is amazing, I must try it out, I hate having to "fake the use of items with eventing" with this I can control the desired outcome more accurate. :) thx to all of you!
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
Thank you so much for your help this works like a charm so far.
I asked Caethyril about the usage of Items without Scope, maybe he can help else i will work around that. No big Deal.

This is incredible and makes alot of things much easier thank you Aesica for taking the time and effort for this/us.

@Martin, if you might want the Item Description Text Box while selecting an Item with Show Item List Eventcommand?
https://forums.rpgmakerweb.com/index.php?threads/select-item-description.96045/#post-868387

Edit: Yes you are right the long version of the scriptsnippet doesnt fit in MV Scriptbox, the short one does. VX-Ace got a bigger one =), maybe that changes in the future?
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,048
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
Maybe try this for the no-scope stuff? It's based on Aesica's solution: applyGlobal runs any common event effects, and I've added an action repeat loop for items with Repeats > 1. I also very slightly restructured the code~ :kaothx:
Code:
(function(v,i,t,a,c,u) {
  if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[0];
    a = new Game_Action(u);
    a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && c) {
      u.useItem(i);
      for (n in t) for (var m = a.numRepeats(); m--;) a.apply(t[n]);
      a.applyGlobal();
}}})(YOUR_ITEM_ID_HERE);
Excerpt from base code (RMMV v1.6.2) for reference:
Code:
Scene_ItemBase.prototype.applyItem = function() {
    var action = new Game_Action(this.user());
    action.setItemObject(this.item());
    this.itemTargetActors().forEach(function(target) {
        for (var i = 0; i < action.numRepeats(); i++) {
            action.apply(target);
        }
    }, this);
    action.applyGlobal();
};
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Ooh nice catches--I completely forgot about both numRepeats and applyGlobal. :D

Edit: Since I figured a plugin command version of this might be worth adding to one of my utility plugins at some point, I thought I'd say "thanks for the idea" by sharing a bonus version which will also play the item's animation, if any: (based on caethyril's version)

Code:
(function(v,i,t,a,c,u) {
  if (i = $dataItems[+v || 0]) {
   u = $gameParty.members()[0];
   a = new Game_Action(u);
   a.setItemObject(i);
   t = i.scope === 7 ? [u] : a.makeTargets();
   for (n in t) c = c || a.testApply(t[n]);
   if (u.canUse(i) && c) {
     u.useItem(i); if (!$gameParty.inBattle() && i.animationId) $gamePlayer.requestAnimation(i.animationId);
     for (n in t) for (var m = a.numRepeats(); m--;){ if ($gameParty.inBattle() && i.animationId) t[n].startAnimation(i.animationId); a.apply(t[n]); }
     a.applyGlobal();
}}})(YOUR_ITEM_ID_HERE);

That code real estate's getting pretty packed. :D
 
Last edited:

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,512
Reaction score
417
First Language
German
Primarily Uses
RMMV
Caethyril, your last Code Snippet seems to do the same thing like Aesicas.
The Item with Scope None is also not used in Caethyrils Snippet, wasnt it supposed to solve that?
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,852
Reaction score
1,798
First Language
English
Primarily Uses
RMMV
Hmm, you're right it's not. Did the vxa version execute common events properly? If so, something has changed to make setting up common events a bigger pain than I thought.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,048
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
Ack! Yea, I think it's because of how the "can use" thing is checked (or rather, not checked) in the case of no targets. I tested this time: this version definitely works for me with a "Scope: None" item. Feel free to add the animation stuff back in~
Code:
(function(v,i,t,a,c,u) {
  if (i = $dataItems[+v || 0]) {
    u = $gameParty.members()[0];
    a = new Game_Action(u);
    a.setItemObject(i);
    t = i.scope === 7 ? [u] : a.makeTargets();
    for (n in t) c = c || a.testApply(t[n]);
    if (u.canUse(i) && (i.scope === 0 || c)) {
      u.useItem(i);
      for (n in t) for (var m = a.numRepeats(); m--;) a.apply(t[n]);
      a.applyGlobal();
}}})(YOUR_ITEM_ID_HERE);
Basically, I just added a scope check to this line, so scope 0 ("None") will ignore the apply test:
Code:
    if (u.canUse(i) && (i.scope === 0 || c)) {
 

Latest Threads

Latest Posts

Latest Profile Posts

My entire family and I have Covid... If it's this bad with the vaccine, without must be terrible. Stay safe, everyone. This thing is a doozy.
Ugh. Head heavy with sick juice. I wish I could work on my stuff. o_O
GZZPUeX.png

Overflow Form
I'm coming back to my work with Learn RPG Maker MV. Soon I'll be posting previews screenshots for my "paterons"! :guffaw:

Forum statistics

Threads
118,520
Messages
1,116,603
Members
155,534
Latest member
aubycringe
Top