Sigh...more scripting help needed please...

Post » Fri Nov 19, 2010 5:50 am

I'm new to scripting...
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


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.
User avatar
Petr Jordy Zugar
 
Posts: 3497
Joined: Tue Jul 03, 2007 10:10 pm

Post » Fri Nov 19, 2010 10:27 am

In OBSE 19 they're going to release some inventory-walking functions, which will assign temporary reference ID's to inventory items. If you can wait until OBSE 19 is released, your problems will likely be solved then.
User avatar
Melissa De Thomasis
 
Posts: 3412
Joined: Tue Feb 27, 2007 6:52 pm

Post » Thu Nov 18, 2010 11:08 pm

Heh, sounds like I'm just being impatient then. :) Thanks for letting me know - I hadn't heard v19 would have that available.

Fortunately, in the meantime I've figured a way around this block, using a completely different method. Unfortunately, that method won't work for weapons...still need to get that figured out.
(The updated mod is on TESNexus, BFG_Enhanced_Armory, if anyone wants to check it out.)
User avatar
~Amy~
 
Posts: 3478
Joined: Sat Aug 12, 2006 5:38 am


Return to IV - Oblivion