corrado33 Posted October 5, 2018 Share Posted October 5, 2018 I've been wondering lately, is it bad if my mod places scripts on the player? Especially if those scripts have overarching conditions like "OnSpellCast" or "OnItemAdded"? Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 5, 2018 Share Posted October 5, 2018 Directly on the player? Yes, it is bad as there can only be one player record and any other mod could come along and wipe out your script(s). On an alias where the player is assigned? No, these are safe as they are present so long as your quest is running. Rule of thumb when it comes to the player: Always use quest alias whenever possible. Link to comment Share on other sites More sharing options...
foamyesque Posted October 5, 2018 Share Posted October 5, 2018 (edited) A billion and one mods add scripts to the player. As long as a. your script is applied via alias and b. your script is well-designed, there should be no real issues. Someone running enough script-heavy things on the player can bog the game's script engine down, so if possible try to keep stuff running on the player proper fast and short, and you'll want to be cautious of stack dumps if you're setting up inventory management stuff. OnItemAdded() and OnItemRemoved() events particularly can cause stack dumps (i.e generate events that the script engine just throws out because there's too many at once, which can impact more than just your script) because a player can be having a bargeload of items moved in or out. Consider being thrown in jail, or reclaiming your inventory after being thrown in jail, or the Diplomatic Immunity quest. A simple way to see whether this is happening with your stuff is to turn on logging, coc into the QASmoke test cell, and do a Take All on one of the QASmoke containers with every weapon or armour in the game. Inventory event filters are your best bet to avoid this as they will only generate events if the items you are interested in are being shifted around. Edited October 5, 2018 by foamyesque Link to comment Share on other sites More sharing options...
corrado33 Posted October 5, 2018 Author Share Posted October 5, 2018 (edited) A billion and one mods add scripts to the player. As long as a. your script is applied via alias and b. your script is well-designed, there should be no real issues. Someone running enough script-heavy things on the player can bog the game's script engine down, so if possible try to keep stuff running on the player proper fast and short, and you'll want to be cautious of stack dumps if you're setting up inventory management stuff. OnItemAdded() and OnItemRemoved() events particularly can cause stack dumps (i.e generate events that the script engine just throws out because there's too many at once, which can impact more than just your script) because a player can be having a bargeload of items moved in or out. Consider being thrown in jail, or reclaiming your inventory after being thrown in jail, or the Diplomatic Immunity quest. A simple way to see whether this is happening with your stuff is to turn on logging, coc into the QASmoke test cell, and do a Take All on one of the QASmoke containers with every weapon or armour in the game. Inventory event filters are your best bet to avoid this as they will only generate events if the items you are interested in are being shifted around. Good to know. Unfortunately I think the newest (unreleased) version of script does exactly what you described. So I suppose I shall ask this. What's the best way to enable an "onItemAdded() event" once the player begins crafting. I mean... the base question is "how do I enable an event based on another thing in game?" I don't know how to enable/disable events at all, other than an IF statement INSIDE the event. (Which is what I currently have, a simple "Is player sitting && aksourcecontainer = None") If you must know, the reason for this is simple. Say I have some grilled leeks in my "food" container. Therefore it's on the "Food" formlist. If I'm out in the middle of nowhere and enable my crafting auto retrieve on a cooking pot, then make some grilled leeks, when I leave the cooking pot my newly made grilled leeks will be transferred away from me, because they're on the formlist. This is SUPER annoying because it essentially prevents you from making some things when you're away from home, and I don't currently have any way to retrieve things from the storage chests. So what I'm currently doing in the unreleased version is checking for items added to the player's inventory when crafting. If an item is added, it is removed from all formlists, therefore it won't be transferred away from the player when they finish crafting. I suppose I could have ANOTHER quest alias with a script attached with an onitemadded event but the quest alias is only filled with the player when the player begins crafting (and more specifically, after I transfer everything to them.). I'll try that. Is there an easier way? Edited October 5, 2018 by corrado33 Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 5, 2018 Share Posted October 5, 2018 Try breaking down how you transfer things. Instead of transferring EVERYTHING that has been stored, create a list of just ingredients for the workstation. Use that list to transfer from and to when crafting. That may be a bit difficult in-game to be honest. However, a script made for TES5Edit could populate such a formlist and provide compatibility off the bat for mod added recipes. If that is an approach you are interested in, I already have such a script (although it does additional things too). Link to comment Share on other sites More sharing options...
corrado33 Posted October 6, 2018 Author Share Posted October 6, 2018 (edited) Try breaking down how you transfer things. Instead of transferring EVERYTHING that has been stored, create a list of just ingredients for the workstation. Use that list to transfer from and to when crafting. That may be a bit difficult in-game to be honest. However, a script made for TES5Edit could populate such a formlist and provide compatibility off the bat for mod added recipes. If that is an approach you are interested in, I already have such a script (although it does additional things too). Yeah... I've been meaning to implement what you speak of. Right now the player obviously get EVERYTHING at ANY crafting station. I mean, it wouldn't be hard for me, just a check of the crafting station's keywords that would populate a formlist of chests to transfer. Eh, I'll try my way first, then, when it fails, I'll likely be back. :smile: OH EDIT: I figured out the duplication glitch! My script doesn't play well with ordinator's "Recycle Material" perk. :smile: (Which, I'm assuming, monitors items removed from your inventory while crafting and "additem"'s them back after you stop. Since I remove EVERYTHING, it just duplicates everything. Edited October 6, 2018 by corrado33 Link to comment Share on other sites More sharing options...
foamyesque Posted October 6, 2018 Share Posted October 6, 2018 As it happens I solved a very similar problem for someone else. Let me see if I can find it, but in the meantime, the solution to enabling or disabling events in general is papyrus states. If the script is not in a state where the event is defined, no event will fire, because Papyrus has an optimization where it will throw out events if they have no code whatsoever associated with them. Link to comment Share on other sites More sharing options...
corrado33 Posted October 6, 2018 Author Share Posted October 6, 2018 As it happens I solved a very similar problem for someone else. Let me see if I can find it, but in the meantime, the solution to enabling or disabling events in general is papyrus states. If the script is not in a state where the event is defined, no event will fire, because Papyrus has an optimization where it will throw out events if they have no code whatsoever associated with them. Ahhhh, that seems like a good idea but I'm not entirely sure how I'd implement it. If I had a script on a player alias, how would I access the state within that script... I could set a global variable... but that'd involve checking that global variable occasionally and that's stupid. Something needs to fire to change the states. I don't... think you can change a script's state from another script.... if you could then it'd be easy. Link to comment Share on other sites More sharing options...
IsharaMeradin Posted October 6, 2018 Share Posted October 6, 2018 Have a function on the script where you want to change the states then call that function from some other script. Link to comment Share on other sites More sharing options...
foamyesque Posted October 6, 2018 Share Posted October 6, 2018 (edited) GotoState() is an available function in any script and can be externally accessed. EDIT: I found what I was thinking of, but on checking it I'm not sure how useful it will be to you. The person was trying to execute a swap of their modded ingredients, but only while crafting, in order to avoid breaking alchemy, and I went with an inventory filter solution. Still, on the offchance: https://forums.nexusmods.com/index.php?/topic/6580351-need-help-speeding-up-my-script/page-3 Edited October 6, 2018 by foamyesque Link to comment Share on other sites More sharing options...
Recommended Posts