As part of the mod I'm working on, I'm trying to get things set up to where the enchantments on worn armor or weapons scales with the condition of the armor/weapons. For example, at 100% health a Cuirass will have the enchantment you expect (e.g. Resist Magic 20), but when it's about to break most of the enchantment will be ineffective (e.g. Resist Magic 4).
I think the code I've written for this would work...if the functions I was using went off of ObjectIDs instead of References. I've scoured help files for a long time and I can't for the life of me figure out how to set a variable to reference the armor currently being worn by the player! I can get the ObjectID, however, with let Obj := (Player.GetEquippedObject x).
Here's the code I've written, for reference:
Spoiler
scriptName BFGEnchantedArmor02
ref Obj
short ArmorSlot
short fQuestDelayTime
short ObjCurHP
short ObjTtlHP
short numbereffects
short tempa
short tempb
short marea
short mdura
short mmagn
short mfactor
float Percentage
begin GameMode
set fQuestDelayTime to 2.5
let ArmorSlot := 2
let Obj := (Player.GetEquippedObject ArmorSlot)
if IsArmor Obj == 0
Return
else
let ObjCurHP := Player.GetEquippedCurrentHealth ArmorSlot
if ObjCurHP <= 0
bunch of other stuff
else
let ObjTtlHP := GetObjectHealth Obj
let Percentage := ObjCurHP / ObjTtlHP
let numbereffects := GetMagicItemEffectCount Obj
let tempa := -1
While tempa < numbereffects - 1
let mfactor := 0 ;mfactor counts how many degrees (area, duration, magnitude) we have
let tempa := tempa + 1
let marea := GetNthEffectItemArea Obj tempa
let mdura := GetNthEffectItemDuration Obj tempa
let mmagn := GetNthEffectItemMagnitude Obj tempa
if marea != 0
let mfactor := mfactor + 1
endif
if mdura != 0
let mfactor := mfactor + 1
endif
if mmagn != 0
let mfactor := mfactor + 1
endif
if mfactor > 0
let tempb := (Percentage * 0.8 * marea) + (0.2 * marea) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemArea tempb Obj tempa
let tempb := (Percentage * 0.8 * mdura) + (0.2 * mdura) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemDuration tempb Obj tempa
let tempb := (Percentage * 0.8 * mmagn) + (0.2 * mmagn) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemMagnitude tempb Obj tempa
endif
loop
endif
endif
end
scriptName BFGEnchantedArmor02
ref Obj
short ArmorSlot
short fQuestDelayTime
short ObjCurHP
short ObjTtlHP
short numbereffects
short tempa
short tempb
short marea
short mdura
short mmagn
short mfactor
float Percentage
begin GameMode
set fQuestDelayTime to 2.5
let ArmorSlot := 2
let Obj := (Player.GetEquippedObject ArmorSlot)
if IsArmor Obj == 0
Return
else
let ObjCurHP := Player.GetEquippedCurrentHealth ArmorSlot
if ObjCurHP <= 0
bunch of other stuff
else
let ObjTtlHP := GetObjectHealth Obj
let Percentage := ObjCurHP / ObjTtlHP
let numbereffects := GetMagicItemEffectCount Obj
let tempa := -1
While tempa < numbereffects - 1
let mfactor := 0 ;mfactor counts how many degrees (area, duration, magnitude) we have
let tempa := tempa + 1
let marea := GetNthEffectItemArea Obj tempa
let mdura := GetNthEffectItemDuration Obj tempa
let mmagn := GetNthEffectItemMagnitude Obj tempa
if marea != 0
let mfactor := mfactor + 1
endif
if mdura != 0
let mfactor := mfactor + 1
endif
if mmagn != 0
let mfactor := mfactor + 1
endif
if mfactor > 0
let tempb := (Percentage * 0.8 * marea) + (0.2 * marea) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemArea tempb Obj tempa
let tempb := (Percentage * 0.8 * mdura) + (0.2 * mdura) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemDuration tempb Obj tempa
let tempb := (Percentage * 0.8 * mmagn) + (0.2 * mmagn) * (1.666666 ^ (mfactor - 1)) + 0.5
SetNthEffectItemMagnitude tempb Obj tempa
endif
loop
endif
endif
end
As you can see, I'm trying to use Obj, which is an Object ID, as a Reference, and I think that's why the whole thing isn't working. Any help is appreciated.