Set a Variable accordingly to last item used?

Hiii. I was wondering how I could make it that consuming a certain Item would give its ID to a certain Variable, and so update it each time you consume a new Item. I'm not good at scripting so I'm getting nowhere...
Something like $game_variables[x] = item.id...? But where should I put it and how? No idea.
if the item has a value, you can place the code into the damage formula.
and because this formula is unique for each item, you can simply use the number for the item there.
something like

$game_variables[x]=123; regular damage formula

for the item with the ID 123.

If the item has no damage formula to execute, then it becomes more problematic and you'll have to use a script to place the line into the engine's item execution process.
I did what works on the menu, only works with consumables.



It does not work in battles, because I did not understand the proposal of your need, I will leave it open for modifications.
(Sorry for my bad English)

@Syddo I hope your feedback

Edited:
I modified it a little, now if the item calls a Common Event it will also be memorized in the variable.
It does not work in battles
Are you saying you didn't just alias Game_Battler#item_effect? That's what I would have done.

Code:
# Game Variable ID that will store the last used item
LAST_ITEM_VAR_ID = 10

class Game_Battler
  alias store_item_id_in_var_on_use item_effect
  def item_effect(item)
    effective = store_item_id_in_var_on_use(item)
    $game_variables[LAST_ITEM_VAR_ID] = item.id if effective
    effective
  end
end
I think it... Worked? My item have no damage formula so Andar's suggestion didn't fit. (Thank you, btw!)
I couldn't even get to work Dev's suggestion (Did I have to write something more than Gamevar_Item = x? I guess so, sorry I really know nothing)
Anyway I randomly tried to put a "$game_variables[70] = @item.id" under the consumable condition in Scene_Item, and it works??? Is my PC going to explode because I can't script and I just put a random thing without any knowledge? Hahah
KK20, I don't need to use those items in battle so I guess I was alright with Dev's suggestion. Altough someone may get to this post and need that too, so thanks anyway!
If you still need it, here it is.
I had to consider the various conditions that the inventory menu presents when trying to use any item.
I basically made a copy of the Class that already existed and adapted the "Consumable" part.
Any consumable items will be considered, infinite and what you call common events.

It is possible to change a variable that will register an ID during the game with a simple command. All instructions are very clear in the Script:

If anyone has a better method, I would be happy to update.

Original thread: https://forums.rpgmakerweb.com/threads/set-a-variable-accordingly-to-last-item-used.136774/