Here's what my script is supposed to do: When the player clicks on a food item in their inventory, the food's information is passed to a function so that it can be processed and runger reduced appropriately.
Here's what it does: When I click on a food item in my inventory, I get a CTD. I commented out all of the code that's supposed to happen, so that the only thing left is a PrintToConsole, but I still get a CTD. What the heck?
I'm using OBSE v19. Here's my script.
scn HvHungerOBSEWort;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;This script detects when the player eats food from their inventory, and reduces hunger appropriately.;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;short initfloat fQuestDelayTimeref FoodRefshort EatOnce ;;;;; We only need to run the script while the player is in their inventory screen (MenuMode 1002), so that's all we'll be using. ;;;;;Begin MenuMode 1002 ;;;;; Here we initialize the script. This is only ever done once. ;;;;; if ( init == 0 ) let fQuestDelayTime := 0.01 let init := 1 endif ;;;;; Here, we detect the menu selection your mouse is currently scrolled over. If it's food, we disable the left mouse button. ;;;;; ;;;;; With the left mouse button disabled, we can detect the button press via the script. If it is pressed, we can first pass the ;;;;; ;;;;; food's information to the rest of the script, then force-eat the food. When the player isn't mousing over a food item, we ;;;;; ;;;;; enable the left mouse button again. ;;;;; let FoodRef := GetActiveMenuSelection if eval ( IsIngredient FoodRef ) && ( IsFood FoodRef ) DisableControl 4 else EnableControl 4 return endif ;;;;; The following block runs when the player presses down "control 4" (by default, left mouse button). ;;;;; if ( OnControlDown 4 ) ;if ( IsKeyPressed3 42 ) ;; <- This checks if the player is holding the left shift key - ie, to drop the food instead of eat it. ;; ; Player.Drop FoodRef 1 ; PrintToConsole "Force-dropped n% (or tried to)." FoodRef ;else ; ;Call HvEat FoodRef 0 ;;;;; <- caused a ctd? ;;;;; ; Player.EquipItemNS FoodRef ;;;; <- happened twice? ;;;;; PrintToConsole "Force-ate n% (or tried to)." FoodRef ;endif endifEnd
Note: I've tried using IsControlPressed instead of OnControlDown, with a check to make sure it only runs once. I wasn't getting a CTD, but it was eating 2 pieces of food instead of one. Also, when I called the function, it *still* CTD'd.