GetWornForm() Question

Post » Mon Nov 19, 2012 3:12 pm

I'm trying to make functional armor degradation. I need to move equipped armor pieces (at random) into lists, which then have a perk that says (for example) if the armor piece is in the list ArmDegList9, multiple the armor rating by 0.90. So, here's the script I have set up.

Scriptname ARMDEG_CastingSpellScript extends activemagiceffectFormList Property ArmDegList0 autoFormList Property ArmDegList1 autoFormList Property ArmDegList2 autoFormList Property ArmDegList3 autoFormList Property ArmDegList4 autoFormList Property ArmDegList5 autoFormList Property ArmDegList6 autoFormList Property ArmDegList7 autoFormList Property ArmDegList8 autoFormList Property ArmDegList9 autoevent OnEffectStart(Actor C, Actor T)Degrade(C)endEventfunction Degrade(Actor T)ObjectReference ArmorInQuestion = PickSlot(T)if (ArmorInQuestion)  Debug.Notification("ArmorInQuestion Exists")  if ArmDegList1.HasForm(ArmorInQuestion)   ArmDegList0.addForm(ArmorInQuestion)   ArmDegList1.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList2.HasForm(ArmorInQuestion)   ArmDegList1.addForm(ArmorInQuestion)   ArmDegList2.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList3.HasForm(ArmorInQuestion)   ArmDegList2.addForm(ArmorInQuestion)   ArmDegList3.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList4.HasForm(ArmorInQuestion)   ArmDegList3.addForm(ArmorInQuestion)   ArmDegList4.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList5.HasForm(ArmorInQuestion)   ArmDegList4.addForm(ArmorInQuestion)   ArmDegList5.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList6.HasForm(ArmorInQuestion)   ArmDegList5.addForm(ArmorInQuestion)   ArmDegList6.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList7.HasForm(ArmorInQuestion)   ArmDegList6.addForm(ArmorInQuestion)   ArmDegList7.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList8.HasForm(ArmorInQuestion)   ArmDegList7.addForm(ArmorInQuestion)   ArmDegList8.RemoveAddedForm(ArmorInQuestion)  elseIf ArmDegList9.HasForm(ArmorInQuestion)   ArmDegList8.addForm(ArmorInQuestion)   ArmDegList9.RemoveAddedForm(ArmorInQuestion)  else   ArmDegList9.addForm(ArmorInQuestion)  endIfDebug.Notification("A piece of armor has degraded.")endIf  endFunctionObjectReference Function PickSlot(Actor T)int SlotNum = Utility.RandomInt(1,5)Debug.Notification("SlotNum = " +SlotNum)if SlotNum==1;Cuirassif  ((T.GetWornForm(0x00000004) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000004) as Armor).IsLightArmor())  return T.GetWornForm(0x00000004) as ObjectReferenceelse  return NONEendIfelseIf SlotNum==2;GauntletsIf T.GetWornForm(0x00000010) as ObjectReference && ((T.GetWornForm(0x00000010) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000010) as Armor).IsLightArmor())  return T.GetWornForm(0x00000010) as ObjectReferenceelseIf T.GetWornForm(0x00000018) as ObjectReference && ((T.GetWornForm(0x00000018) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000018) as Armor).IsLightArmor())  return T.GetWornForm(0x00000018) as ObjectReferenceelseIf T.GetWornForm(0x00000008) as ObjectReference && ((T.GetWornForm(0x00000008) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000008) as Armor).IsLightArmor())  return T.GetWornForm(0x00000008) as ObjectReferenceelse  return NONEendIfelseIf SlotNum==3;shieldreturn T.GetWornForm(0x00000200) as ObjectReferenceelseIf SlotNum==4;helmetIf T.GetWornForm(0x00000001) as ObjectReference && ((T.GetWornForm(0x00000001) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000001) as Armor).IsLightArmor())  return T.GetWornForm(0x00000001) as ObjectReferenceelseIf T.GetWornForm(0x00000002) as ObjectReference && ((T.GetWornForm(0x00000002) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000002) as Armor).IsLightArmor())  return T.GetWornForm(0x00000002) as ObjectReferenceelseIf T.GetWornForm(0x00000003) as ObjectReference && ((T.GetWornForm(0x00000003) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000003) as Armor).IsLightArmor())  return T.GetWornForm(0x00000003) as ObjectReferenceelse  return NONEendIfelseIf SlotNum==5; bootsIf T.GetWornForm(0x00000080) as ObjectReference && ((T.GetWornForm(0x00000080) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000080) as Armor).IsLightArmor())  return T.GetWornForm(0x00000080) as ObjectReferenceelseIf T.GetWornForm(0x00000100) as ObjectReference && ((T.GetWornForm(0x00000100) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000100) as Armor).IsLightArmor())  return T.GetWornForm(0x00000100) as ObjectReferenceelseIf T.GetWornForm(0x00000180) as ObjectReference && ((T.GetWornForm(0x00000180) as Armor).IsHeavyArmor()||(T.GetWornForm(0x00000180) as Armor).IsLightArmor())  return T.GetWornForm(0x00000180) as ObjectReferenceelse  return NONEendIfendIfendFunction

This spell is autocast every time you are hit by the way (I will eventually make it 3-5% of the time) and the debug notifications are going off, until the one that says "ArmorInQuestion Exists". So, I guess I'm getting NONE returned from PickSlot().

Is this because I can't cast GetWornForm()s as ObjectReferences or something? Because I don't get any errors like that...

Supplementary question:
If I get this working, will it effect (for example) EVERY IronCuirass if my IronCuirass I have equipped gets damaged? Because that would be unfortunate.

EDIT: Yep, doing a find replace of the word ObjectReference with Form makes it work perfectly, but apply to every instance of the armor. Time for an alias workaround.
EDIT2: DARNIT! I can't do an alias workaround, as doing so would demand putting the equipped object into an alias, and I can't ForceRefTo, as if it isn't persistent there is nothing to force it to.
User avatar
Mark Churchman
 
Posts: 3363
Joined: Sun Aug 05, 2007 5:58 am

Post » Mon Nov 19, 2012 7:16 pm

SKSE's brand new TempClone might help. Haven't tinkered with it, but since you're already relying on SKSE it seems worth mentioning.
User avatar
Hayley O'Gara
 
Posts: 3465
Joined: Wed Nov 22, 2006 2:53 am

Post » Mon Nov 19, 2012 5:01 pm

Actually I've gotten rid of my GetWornForm reliance and used aliases instead, but that isn't working either. I'll look into TempClone.
EDIT: Another possible solution occurred to me.

Event OnObjectEquipped(Form BO, ObjectReference Ref)  ; this eliminates all of the copies of the BO that aren't equipped from the inventory temporarily  int OtherBOCount = PlayerREF.GetItemCount(BO)+-1  PlayerREF.RemoveItem(BO, OtherBOCount)	 ObjectReference FunctionalRef = PlayerREF.DropObject(BO); this makes it temporarily persistent	 FunctionalRef.RegisterForSingleUpdate(10);then we fill the proper alias (here nicknamed EqSlot) with the ref	 EqSlot.ForceRefTo(FunctionalRef)	 PlayerREF.addItem(EqSlot.GetReference(), 1, TRUE)    PlayerREF.EquipItem(EqSlot.GetReference(), true)    PlayerREF.addItem(BO, OtherBOCount, true)endEvent
User avatar
Manuel rivera
 
Posts: 3395
Joined: Mon Sep 10, 2007 4:12 pm

Post » Mon Nov 19, 2012 7:29 pm

That will remove degradation from any similar items in the inventory, won't it? You could move them to a container and back.
User avatar
Louise Lowe
 
Posts: 3262
Joined: Fri Jul 28, 2006 9:08 am

Post » Mon Nov 19, 2012 3:27 pm

Crap you're right. Oh well, easily fixed. I'm having trouble getting other aspects of it working too (for example, when I have the thing scripted re-equip, it triggers the event over again, so everything constantly loops as far as equipping/unequipping).
User avatar
evelina c
 
Posts: 3377
Joined: Tue Dec 19, 2006 4:28 pm


Return to V - Skyrim