Jump to content

OnItemRemoved Firing Twice


Recommended Posts

Welp, managed to solve it -- easiest thing is to just bust the hotkey eating out into its own function and jump out of the item removed loop:

 

 

Function handle_removed_item(Form item, int count, \
ObjectReference ref, ObjectReference dst)
if !is_enabled || is_looting || is_trading || UI.isMenuOpen("Console") \
|| removing_item ;; OnItemRemoved will be strangely triggered twice
return
endif

removing_item = True
int type = item.getType()
_debug("Item removed - " + item.getName() + " (" + type + ")")

if is_crafting && mods.handle_removed_item(item)
removing_item = False
return
endif


if type == 46 ;; food
int food_eaten_now = Game.queryStat("Food Eaten")
Bool isInventoryMenuOpen = UI.IsMenuOpen("InventoryMenu")
if food_eaten_now > food_eaten && isInventoryMenuOpen
_debug("Food eaten from inventory")
eating_time_to_pass += eating_minute / 60
food_eaten = food_eaten_now
elseif food_eaten_now > food_eaten && !isInventoryMenuOpen
food_eaten = food_eaten_now
hotkey_eating()
endif


elseif type == 27 ;; book
int spell_learned_now = Game.queryStat("Spells Learned")
if spell_learned_now > spell_learned
_debug("Spell learned")
pass_time(spell_learning_hour)
spell_learned = spell_learned_now
endif
endif
removing_item = False
EndFunction

 

Function hotkey_eating()
_debug("Food eaten via hotkey")
eating_time_to_pass = eating_minute / 60
pass_time(eating_time_to_pass)
eating_time_to_pass = 0.0
EndFunction

 

This way, I can still do the generic absence of the inventory menu check but still get the action of the hotkey without actually listening for a specific hotkey. It works! Plus, I got to create a function called hotkey_eating. What more could you want? :smile:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...