JS: Detect Item Usage

I never did figure out how to do this on RPGMAker VX Ace, and I was hoping RPG Maker MV would have a solution.


I would like to be able fire a common event from the use of an Item. 


In that common event how do I determine who the item was used on?


Example:


 I use a potion on an actor who has maximum hp.  I would like to have my common event apply a "Medicated" state to the actor.  I have many other ideas similar to this but without knowing how to detect who the item was used on, it becomes tedious on the coding.


Thank you in advance,
Maybe try Yanfly's Buff and State Core?
Hmm use the damage formula to do the heal, that way you can even add the state directly using the damage formula.. or if you need to do other things, you can just make the damage formula set a variable equal to the id of the actor that it was used on. 
I am trying to write my own plugin actually and was looking to see how to detect when an item is used how to determine their the target.
Hmm use the damage formula to do the heal, that way you can even add the state directly using the damage formula.. or if you need to do other things, you can just make the damage formula set a variable equal to the id of the actor that it was used on. 

The problem is I don't know how to set the variable equal to the id of the actor it was used on. I can set to specific id's but not the target of the item. That is in essence my problem. Thank you though for responding.
You can get the ID of an actor using actor_object.actorId()


If using the damage formula:


$gameVariables.set(variable_id,b.actorId())


In case you want the caster instead, just change b.actorId() to a.actorId()


Take note though that this will only work if the target is an Actor, if you use it on something that target's the enemy it won't run.
Thank you for your response, you had me looking in a few areas, none of the suggestions above seem to work though.


I tried putting this in a script line in the common event called by the use item and it still doesn't work. am I on the right track?


$gameVariables.setValue(0,$gameParty._lastItem._subjectActorId) 
I am sorry to keep spamming my own thread but I've gotten closer after staring at the code. I came up with the following:


$gameVariables.setValue(0,$gameParty.menuActor().actorId) and lo and behold I got something very wierd.

my variable does not contain the id but the following text:


function () { return this._actorId; }


help!
It's because you used .actorId instead of .actorId(), if you look at my reply, I wrote .actorId() and not just .actorId


Function calls need the () else they will return the function definition which is exactly what happened to you. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/js-detect-item-usage.74003/