Jump to content

[LE] Creating a Script to check InventoryWeight and trigger drain stamina spell effect


Recommended Posts

I was originally trying to rebalance Cardio SE to work better with a bunch of other mods I have that alter movement speed and stamina. I created a spreadsheet and a formula that lists values for draining stamina more or less as the stamina pool increases, in order to restrict maximum running time without encumbrance. I created another formula which generates another list of values for draining stamina more or less depending on how much inventory weight the player has. These two stamina drains would work together in two separate spells.

 

The problem is that I'd like the mod to check more granular values than the original mod, which uses a few spells with a small number of effects each. I'm led to understand that having spells with large quantities of effects are computationally prohibitive as they would need to be checked every second... and that using a script would avoid this? Let me know if that is correct or not.

 

I just started modding Skyrim and am still not very knowledgeable. I have had a small amount of experience scripting in Oblivion. I understand the magic effects and spell effects related to this mod fairly well. I basically need to learn how to write a script that will check the stamina pool and inventory weights to trigger the spell effects when needed. Google searches are not giving me much in the way of intuitive information.

Link to comment
Share on other sites

With SKSE use GetTotalItemWeight as items are added to and removed from the player inventory in order to determine the current weight of the player. You would use this with the OnItemAdded and OnItemRemoved events on a reference alias script assigned to an alias on a quest pointing to the player record. To help reduce on processing, you may wish to use SKSE even further and register for the inventory, container as well as gift and barter menus with RegisterForMenu and use the OnMenuClose event and get the player's weight that way. You'll need to use both methods to catch everything added but the first should be disabled by switching states or flipping a bool value when the inventory and container menus are opened (See OnMenuOpen event). Why both? There is no sense stacking up multiple calls to do the same thing while the player is moving stuff about between inventory and a container or selling stuff etc.

 

As far as stamina pool that is an actor value and you would use GetActorValue for that. Unless you want the max value rather than the momentary current value then you may need GetActorValuePercentage and / or GetBaseActorValue.

 

Now whether or not papyrus is more efficient than spells with lots of effects, I cannot say as I have no idea.

Link to comment
Share on other sites

I just remembered that there is CarryWeight as well as InventoryWeight in the Actor Value list. You can use those with GetActorValue instead of trying to track weight changes of the player as items are added removed. Depending upon how often you want the effects to be updated will depend upon what events you wish to use.

 

You could get away with an update loop that checks for changes every so often. Or you can use the OnItemAdded and / or OnItemRemoved events to try and get more precise. There will be a point tho where precision needs to give way to processing.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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