Common Event When Selling Specific Item

How hard it is to make a script that runs an event when player sells a specified item to any shop?
One thing you can do is check the amount of the specific item the player has before opening the shop, storing it in a variable. After exiting the shop make another variable check the amount the player has of that item, and if it's -1 or less than the previous variable, then you can tell that the player sold the item. :3
.......ok, you can just alias the shop's call to gain_item() and poke in your function.
Try this and see if it works for you. I got it to display a message, but not enter a battle. So some functions may be invalid.
You must exit the sell scene to have the CE call anything, from what I can see.
Code:
#------------------------------------------------------------------------------#
#  Roninator2 - Call Common Event on Sell Item
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.0
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
#  2018-04-15 - Version 1.0 - initial
#------------------------------------------------------------------------------#


# Call Common Event when selling a specific item
module Sellit
#------------------------------------------------------------------------------#
# Item that needs to be checked
CEsell = 1
#------------------------------------------------------------------------------#
# Common Event that will be called
CEcall = 1
#------------------------------------------------------------------------------#
end

class Scene_Shop < Scene_MenuBase
  def do_sell(number)
    $game_party.gain_gold(number * selling_price)
    $game_party.lose_item(@item, number)
    if @item.id == Sellit::CEsell
      SceneManager.return
      $game_temp.reserve_common_event(Sellit::CEcall)
    end
  end
end
If it can display a message, surely it can run more events after that. Afaik displaying text boxes closes the menu. Atleast the item menu.
I had an item that runs common event that displays message upon consumption, and after that message you were no longer in the item menu.

---edit

Script works, but it works when I try to sell any item.
Seems my initial attempt is off. I'll work on it, but the reason it always works is that I forgot a equal sign in there.

*EDIT - try it now. Changes made in code above.
If you can fix that, that'll suffice. I don't quite understand what's wrong there, so can't do it myself.
I can add a simple switch check, so that only specified shops react to the item selling
That code won't differentiate between items, weapons or armors, it just checks the ID of the sold item, not it's type.
This could lead to some rather weird moments in the game, I guess. 😀

But this can easily be done with an alias instead of overwriting the method, and it could also read the sold item's note-tag to see if it has a common event trigger or not.
Something like this:
Spoiler
Works like a charm, thank you very much!
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/common-event-when-selling-specific-item.94107/