114529 Posted March 18, 2023 Share Posted March 18, 2023 Hello, I am making a mod which adds custom flags which you can equip using the torch mechanics as a way to hold the flag. To force NPC's to equip flags, I made a script for an enchanted ring. The magic effect for the ring states as condition that the target must have one or more of the flags in their inventory.When that is true, the script fires. It checks which flag is in the npc's inventory and equips that specific flag. When the ring is removed, the npc unequips the flag.I gave it a 3 second delay, because I have mods which allow me to trade items with non followers. The script/trademod combo didn't work without this delay. My guess is those mods run scripts of their own and I need mine to run after those. So far, the script compiled and works in game.However, this is still my first script and my first mod for Skyrim. Could someone check my script to see if I could improve it? The script goes as follows: Scriptname FLAGS_BearerDesignation extends activemagiceffect light property FLAGSauto auto Light Property FLAGSSons Auto Light Property FLAGSImperial AutoLight Property FLAGSWhiterun Auto MagicEffect Property FLAGS_enchantment Auto Form Flag event OnEffectStart(Actor target, Actor caster) If (Target.GetItemCount(FLAGSauto) >= 1) Flag = FLAGSauto Debug.MessageBox("The person should now equip the normal flag") ElseIf (target.GetItemCount(FLAGSImperial) >= 1) Flag = FLAGSImperial Debug.MessageBox("The person should now equip the imperial flag") ElseIf (target.GetItemCount(FLAGSWhiterun) >= 1) Flag = FLAGSWhiterun Debug.MessageBox("The person should now equip the Whiterun flag") ElseIf (target.GetItemCount(FLAGSSons) >= 1) Flag = FLAGSSons Debug.MessageBox("The person should now equip the Stormcloak flag") Else Debug.MessageBox("No flag detected") EndIf RegisterForSingleUpdate(3.0)endEvent Event OnUpdate() actor target = getTargetActor()target.EquipItem(FLAG,true,true)EndEvent Event OnEffectFinish(Actor Target, Actor caster) Target.UnequipItem(FLAG)EndEvent Link to comment Share on other sites More sharing options...
scorrp10 Posted March 19, 2023 Share Posted March 19, 2023 Ugh... MessageBox? Why not use Debug.Notification instead? In OnEffectStart, I would set 'Flag = None' in the Else clause. In OnUpdate, add a check: if (Flag != None) target.EquipItem(FLAG,true,true) EndIfIn OnEffectFinish, you got to be careful. It is called on object destruction, meaning object's variables might have already been destroyed, which includes the 'flag'. What you coulld do: Form _item = target.GetEquippedObject(0) If(_item as Light != None) target.UnEquipItem(_item, true, true) EndIfWhich is still not ideal, but a step in right direction... Link to comment Share on other sites More sharing options...
114529 Posted March 19, 2023 Author Share Posted March 19, 2023 Thank you for taking the time to correct my script. ''In OnEffectStart, I would set 'Flag = None' in the Else clause. In OnUpdate, add a check:'' if (Flag != None) target.EquipItem(FLAG,true,true) EndIfThis is to make the script only equip a flag when there is a flag in the inventory, right? I have already placed conditions in the magic effect itself, so the entire script doesn't fire without a flag in the inventory.Would this still be necessary? ''In OnEffectFinish, you got to be careful. It is called on object destruction, meaning object's variables might have already been destroyed, which includes the 'flag'. What you coulld do: '' Form _item = target.GetEquippedObject(0) If(_item as Light != None) target.UnEquipItem(_item, true, true) EndIfGot it, thanks. Why would this not be ideal though? Link to comment Share on other sites More sharing options...
scorrp10 Posted March 19, 2023 Share Posted March 19, 2023 Because, if effect starts on an actor who has no flag, and then, when it ends, they are actually holding a torch, it will unequip the torch... Link to comment Share on other sites More sharing options...
Recommended Posts