Jump to content

[LE] Change global variable value when opening/closing activators?


Recommended Posts

I'd like for a small script to run whenever a cooking station (cooking pots, cooking spits) or a tanning rack is activated and again when they are closed. What would be the best way to implement this? I would like to keep my mod as compatible as possible with other mods. One option would be to add a script directly to the cooking stations/tanning racks, but I'm not sure if that would cause issues with many other mods.

 

My second question; I assume I can use OnActivate to trigger when the player activates cooking stations/tanning racks, but what should I use for when they exit the crafting stations? Could I use OnMenuClose (SKSE)?

Link to comment
Share on other sites

Is it better to attach the script directly to the stations in the CK or to add it via a ReferenceAlias?

 

Also, I'm not sure how a RegistryForSingleUpdate would work here. I'd prefer the change to happen when the menu closes, not before or too much after. I think maybe I don't understand exactly what you're suggesting to do.

Edited by candlepin
Link to comment
Share on other sites

I have a spell that switches vanilla items to ingredient versions of the same item (food carrot --> ingredient carrot). It does this using formlists during OnItemAdded (it also switches the players inventory when initially cast). For the sake of compatibility, I'd like the switching spell be cast whenever one of the crafting stations is opened and cast a second time when the menu is closed. That way, the vanilla items are available for crafting, but are converted back to the ingredient version once the menu has closed. I'm open to other ideas on how to do this.
Link to comment
Share on other sites

So if I'm understanding you correctly, the idea is that while your mod is going, stuff are ingredients, but you want to convert them back to vanilla when someone goes to use a crafting station?

 

... why make them ingredients in the first place then?

Edited by foamyesque
Link to comment
Share on other sites

I would like carrots, for example, to be ingredients. I still want them to be usable for cooking though.

 

My plan is to have the food version of carrots converted into the ingredient form so it can be used in alchemy. Those works perfectly. Now what I would like to happen is for carrots to be converted back to the food version whenever a cooking pot is activated. That way I don't have to change any recipes and it makes my mod compatible with mods that add cooking recipes. Then, when the cooking pot menu is closed, I want carrots to be converted back to the ingredient form so they can be used in alchemy. My spell can achieve this switching, I just have to figure out where to attach a script (and what triggers to use) that will cast the spell when these stations are activated and when they are exited. Does this make more sense?

Link to comment
Share on other sites

Okay. I think my approach would be to run a search quest every time a cell attaches to the player, looking for, specifically, the cooking crafting stations (by keyword, I think). Shouldn't need more than a dozen aliases, I would say. A simple script goes on those to check for activations. Another script goes on the player via an alias, for state control, and to control the inventory swaps and check for menu closes. When one of the cooking stations is activated, it calls a function in the inactive state of the player script, which flips it into the listening state for an OnMenuClose. When the OnMenuClose fires, it flips the player script back into the inactive state. In the inactive state, there's no OnMenuClose, and in the active one, the attempted state-change function is empty. You can call your swaps on entering and leaving the active state. The state change functions are very quick to execute and should prevent weird race conditions from happening (e.g. the player triggering multiple swaps by spamming the activation button).

 

An alternate means to find nearby stations would be through a cloak magic effect, but that tends to interfere with brawls and certain other events.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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