Jump to content

Is it possible to toggle (enable/disable) a script in-game?


vizex1

Recommended Posts

I have armors in my mod that have a script attached to them.

I want to give the player an option to enable or disable this script.

Can I stop the scripts attached to the armors from running at all if an option is selected to disable it?

The script is not really essential to the mod, I'd just like to have it as an optional thing, but it would be cool if I could have it as an option that could be disabled or enabled in-game.

Edited by vizex1
Link to comment
Share on other sites

Simple way could be to apply the script by conditional Ench->Mgef, so it only exists while equipped - but only is reliable for Player. Depends on purpose, just use conditional code execution, state switching on events, maybe. Some curious thing is, that even if a mod's esp, which attaches a script to a CK-placed object, is removed - the script keeps running, so it's not easy to remove/disable in general, once added.

I saw this also - AttachPapyrusScript command, but don't know if there's a papyrus analogue and reverse variant in SE or else.

Edited by hereami
Link to comment
Share on other sites

You can add magic effects (by enchanting) through OMODs. This way you attach the script to the magic effect. When the player equips the item with the modification, the script will run. Else it doesnât exist on the armor. If you remove the OMOD afterwards at the armor workbench, the script is also âžremovedâ from your armor.

 

Technically the script is never attached to your armor. But your armor applies a magic effect on equip to the wearer which will then execute the script. No magic effect => No script.

Link to comment
Share on other sites

Thanks hereami and icestormng.

 

 

Some curious thing is, that even if a mod's esp, which attaches a script to a CK-placed object, is removed - the script keeps running, so it's not easy to remove/disable in general, once added.

Is this also true if an object is scrapped at workbench or unequipping the armor with the Ench->Mgef before removing the mod's esp?

 

 

Technically the script is never attached to your armor. But your armor applies a magic effect on equip to the wearer which will then execute the script. No magic effect => No script.

So does that mean the script is completely disabled? Like for example if there is any RegisterForRemoteEvents would they all unregister?

Link to comment
Share on other sites

 

Is this also true if an object is scrapped at workbench or unequipping the armor with the Ench->Mgef before removing the mod's esp?

If deleted, shouldn't exist anymore, both object and script. Anyway, only suitable for modified ck refs that stay, not any custom objects added by a mod - they should disappear. That was mainly an example of how sticky they are on refs, not simply toggled on/off - was a headache for me once. Can find some info here https://www.creationkit.com/index.php?title=Save_File_Notes_(Papyrus) and there was even more for F4 somewhere in wiki, don't remember where exactly (also regarding registering for events).

For scrapping - another curious thing, i don't know, how long does an object exists after the operation - if Enabled immediately after scrap, it will reappear, so it's not destroyed at once. But disabled objects do not run their scripts, i guess? oh, that's Workshop, nvm, items should be destroyed at workbenches, anyway, they are unequipped.

 

Scripts on magic effects should go off and unregister for all events, when mgef dispels or is removed, or their parent object unequipped (probably, also unregister when spell makes it inactive by conditions, anyway, script doesn't do anything, while mgef is inactive). There is generic well-known issue also. When it's a vanilla mgef, but spell is custom and equipped - the effect may persist, after the spell is gone with its mod. So it's best to unequip everything related to a mod, before removing it.

Edited by hereami
Link to comment
Share on other sites

  • Recently Browsing   0 members

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