How to get an item to add a state or set variable without selecting a particular actor?

There's a way I can do this through multiple common events, but I am trying to decrease my amount of common events and put the event into just one due to the amount of this particular type of item. Efficiency and all that. That's why I'm posting this under Javascript/Plugin Support, as I'm thinking I'll either need a plugin, or some Yanfly notetag for this to do as I want.

I have an item called "Basket of Fruit." Scope is set to "None." On use of the item, the party receives +5 apples. This is done by calling a common event, and then adding +5 apples to inventory. Simple enough.

The problem I have is that I have a lot of these "Baskets." Basket of Fruit, Basket of Vegetables, Basket of... Whatever, etc. etc. etc.

So I'd like to just use 1 common event with multiple conditional branches that checks for a state (or variable) before doing adding the items. The item would do this on activation:
  • Add an invisible state ("Fruit," "Vegetable," etc.) (or alternatively, set a variable, which would help cut down on the # of states I have)
  • Call on the common event "Gain Items"
  • Common event contains multiple conditional branches. "If actor has state Fruit, then +5 apples." "If actor has state Vegetables, then +5 broccoli."
  • Common event then removes the state from the actor.
  • User is free to now open up their basket of Vegetables and repeat the process.
But because the game wants to add a state to someone, it only works if I select who to add the state to. It doesn't matter to the user who has the state, and gives the process an unnecessary step I'd like to avoid. (Of course, in terms of programming, obviously it matters that the main actor would have the state). I just want to skip that selection altogether.

Setting the scope to "None" does what I want, but it doesn't add the state to anyone, so while the common event technically runs, it's not doing anything because no one has a state. Alternatively, with a scope of "None," I tried setting a variable using a damage formula "v[38] = 1" and making the conditional, "If variable 38 = 1, then +5 apples" but that didn't work either.

Any ideas?

Sorry for the wall of text. I feel like this is a simple matter and I overexplained myself, lol.
all of those ways should work if done correctly - if they don't work for you then you did something wrong.
and any solution we point to might go wrong as well if we don't correct the mistakes that prevented your older tries from succeeding.

can you give us a screenshot of how the common event works?
It works if I set the Scope to anything other than "None." "None" is the only way I can bypass the Actor Select scene, but when it's "None," no one is getting the state, so the conditional doesn't activate.

ScopeNone1.JPG

ScopeNone2.JPG
You can have 1000 Common Events, why complicating your life?
Maybe we can use the Damage Formula to change a Variable, i will try.
Edit: I have to little knowledge of the damage formula.
Using common Events seems to be efficient, easy and allready working. But anyways good luck =).
@Bex Thanks 🙂 I think using multiple common events is making my life complicated haha, instead of figuring out an efficient method of just using 1 common event. I already have 60 that I have to scroll through to find what I want and I'm still at the beginning stages of the game. I was hoping to avoid adding 20 more for these items.

So if anyone knows how to skip the actor select scene, that'd be great! Right now I'm getting away with simply using "All Allies" which isn't a terrible compromise.
Try making the item Menu only.
Set the type to hp recovery. Scope All.
Use the damage formula to set a variable.
I think it's \V[x] .
So your formula would look like:

\V[1] = Y; 0;
If that doesn't work, you can try:
$gameVariables.value[X] = Y; 0;

(It has to have a number at the end)

Then call your common event as you have been.
Now you can make your CE look for that variable value and run the conditional based on that.
No plugin needed.

The id of the last item used is stored:
Code:
$gameParty._lastItem._itemId
Call your common event and get the id of the last item used, store it in a variable.
Add items depending on the last item used with conditionnals.
Yeah, using states is a very roundabout way of doing what you're after. Use the method above, so the common event just looks at what item was used.

Control Variables [20 Item Used] = Script: $gameParty._lastItem._itemId
(from above post - I knew it was there somewhere, but I didn't look it up myself)
then use the variable in your conditional branches.

(with your method, instead of having 50 simple common events, you'd have 50 states and one very complicated common event - what's the difference?)
@Astfgl66 @Shaz
I hadn't checked back here because I thought it was a hopeless case, but you guys seriously saved the day!! Thank you! I had no idea _lastItem was something I could use. Awesome!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-an-item-to-add-a-state-or-set-variable-without-selecting-a-particular-actor.105431/