SeraVerte Posted March 22, 2021 Share Posted March 22, 2021 I have two versions of an armor and I'm trying to make it 'break' visually when the actor wearing it is under a certain amount of health.There's a script attached to a activemagiceffect on the actor.In the spell script, on an event, I can get the worn armor using GetWornForm().But how can I get the attached script? The armor itself has a script that has a property to the broken armor.I want to then get that property as Armor and equipItem() the broken armor. How can I do this?Note: the activemagiceffect script does not know which armor it is until run time,.as I have many armors, all with their own broken versions. Link to comment Share on other sites More sharing options...
dylbill Posted March 22, 2021 Share Posted March 22, 2021 You can get the script attached by casting as. If the script on your armor is this: Scriptname TM_ArmorScript extends Armor Armor Property BrokenArmor Auto In your magic effect script you can do this: Event OnEffectStart(Actor akTarget, Actor akCaster) TM_ArmorScript ScriptRef = akTarget.GetWornForm(0x00000004) as TM_ArmorScript akTarget.EquipItem(ScriptRef.BrokenArmor) EndEvent Link to comment Share on other sites More sharing options...
SeraVerte Posted March 22, 2021 Author Share Posted March 22, 2021 You can get the script attached by casting as. If the script on your armor is this: Scriptname TM_ArmorScript extends Armor Armor Property BrokenArmor Auto In your magic effect script you can do this: Event OnEffectStart(Actor akTarget, Actor akCaster) TM_ArmorScript ScriptRef = akTarget.GetWornForm(0x00000004) as TM_ArmorScript akTarget.EquipItem(ScriptRef.BrokenArmor) EndEvent Thanks a lot. I had something similar but my armor script was extending Object Reference instead of armor. Works now! As a follow up question what happens when you try to access a none in papyrus? Would the game crash in this case if ScriptRef was none? Link to comment Share on other sites More sharing options...
dylbill Posted March 22, 2021 Share Posted March 22, 2021 No problem. The game won't crash but will throw errors in the log. You can account for that in the script though if you're worried about it. Event OnEffectStart(Actor akTarget, Actor akCaster) TM_ArmorScript ScriptRef = akTarget.GetWornForm(0x00000004) as TM_ArmorScript If ScriptRef != None If ScriptRef.BrokenArmor != None akTarget.EquipItem(ScriptRef.BrokenArmor) Endif Endif EndEvent Link to comment Share on other sites More sharing options...
Recommended Posts