baddarkl Posted February 27, 2019 Share Posted February 27, 2019 (edited) I'm making a player stash mod, and I want the player to be able to choose, when picking up an item in the world, whether to put it in the regular inventory or the stash. This is what I have right now: scn PlayerStashOnAddScript ref rItemref rContainer begin Function {rItem, rContainer} if Player.IsSneaking == 1 if Player.IsInCombat == 0 rItem.RemoveMeIRAlt 1 0 PlayerStashInstance else MessageEx "Leave Combat First" Player.DropAlt rItem endifendif end None of this works, and I can't figure out why. Edited February 27, 2019 by baddarkl Link to comment Share on other sites More sharing options...
baddarkl Posted February 27, 2019 Author Share Posted February 27, 2019 (edited) I should add I have a script for setting event handlers. It does this one, plus another for directly accessing the stash. scn PlayerStashPreLoadScript begin MenuMode if (GetGameRestarted)else returnendif SetEventHandler "OnAdd" PlayerStashOnAddScript "second"::PlayerRefSetOnKeyDownEventHandler PlayerStashHotkeyScript 1 14 end The keydown event handler is working just fine. Edited February 27, 2019 by baddarkl Link to comment Share on other sites More sharing options...
dubiousintent Posted February 27, 2019 Share Posted February 27, 2019 I'm not seeing anything obviously wrong with "scn PlayerStashOnAddScript", but notice that you don't have anything that tells you whether the "if Player.IsSneaking == 1" test failed. That would give you the appearance of "nothing is happening". When things don't appear to work, you need to add "debug messages" to ensure you know exactly what is happening so you can determine if things are not as expected. It also helps to ensure you have considered every alternative test result, such as an "Else" for every "If". You may think it "unlikely", but when things fail ... the unlikely is always a suspect. See:TIP Best Practice Encapsulation Parens Brackets and BracesTIP Debugging Compound ConditionalsTIP Debugging data to filein the "Scripting" section of the wiki "Getting started creating mods using GECK" article. -Dubious- Link to comment Share on other sites More sharing options...
baddarkl Posted February 27, 2019 Author Share Posted February 27, 2019 I amended the script to look like this: scn PlayerStashOnAddScript ref rItemref rContainer begin Function {rItem, rContainer} PrintC "Add Test" if Player.IsSneaking == 1 PrintC "Sneaking" if Player.IsInCombat == 0 PrintC "Not in Combat" rItem.RemoveMeIRAlt 1 0 PlayerStashInstance else MessageEx "Leave Combat First" PrintC "In Combat" Player.DropAlt rItem endifelse PrintC "Not Sneaking"endif end None of the messages print to console, including the first. I can only guess that the script is never being called for OnAdd events. Link to comment Share on other sites More sharing options...
dubiousintent Posted February 27, 2019 Share Posted February 27, 2019 According to the GECKWiki page, this is probably due to "The item must remain in the new container for at least one frame after it is added in order for the block to trigger", but an EventHandler runs BEFORE the actual triggering event is processed. You might want to see if another "event" works better. "OnActivate" seems likely, but you might need it to wait that frame before your "Add" event is triggered. (I haven't dealt with this specific situation, so hopefully some else has some more pertinent experience to offer.) See also 'TIP Block Types Multiple vs Single Frame processing' under the "Scripting" section. I will be interested to hear how this eventually gets resolved. -Dubious- Link to comment Share on other sites More sharing options...
KiCHo666 Posted February 28, 2019 Share Posted February 28, 2019 dubiousintent is right.I had the same issue with Quick Use mod. What I did was to use a Callback.With that you can delay the execution of function by amount of frames you specify. From my experience, you need at least 2 frames of delay between taking an item and running a script on said item. I used OnAdd to trigger the Callback and after 2 frames I ran a script on item that I've took. I just needed to pass the ref to callback using aux vars.Hope that helps. Link to comment Share on other sites More sharing options...
baddarkl Posted February 28, 2019 Author Share Posted February 28, 2019 (edited) I'm beginning to think there's something wrong with my install. I'm playing around with Quick Use right now, and I can't eat consumables in real time with Left Shift. I even added a PrintC debug message to the MadQuickUseOnAddFUNCTION, and it never appears in the console. (BTW the right-click to consume in a container menu works just fine) I tried different versions of JIP LN, but the same result. There are a few people on the Quick Use mod page having the same problem I have, and since you asked them, I'll say my framerate hovers around 60 for the most part. Edited February 28, 2019 by baddarkl Link to comment Share on other sites More sharing options...
KiCHo666 Posted February 28, 2019 Share Posted February 28, 2019 (edited) You have to press Use key, whatever that key might be in your game (mine is F, for example) while Left shift is pressed. So, you hold Left shift and press Use key while there's some ingestible item under your crosshair. Edited February 28, 2019 by KiCHo666 Link to comment Share on other sites More sharing options...
baddarkl Posted February 28, 2019 Author Share Posted February 28, 2019 I know that's what I'm supposed to do. I added a PrintC test message to the start of the UDF and it never prints to console. The UDF should be called on any item being added to the player's inventory, regardless of whether I'm holding Left Shift. So if it's not printing my test message, I can only conclude that the UDF isn't being called at all, which is consistent with the problem my own mod has. Link to comment Share on other sites More sharing options...
Mktavish Posted February 28, 2019 Share Posted February 28, 2019 I've been puzzling over this one for a bit , and sorry I am a cripple with event handlers.But it seems to me you need to be resetting the handler every time you change your inventory ?And GetGameRestarted only registers once right ? But off hand question ... have you tried your preload script with a GameMode block ? Link to comment Share on other sites More sharing options...
Recommended Posts