Problems with OBSE commands

Post » Fri Oct 22, 2010 2:47 am

I'm a newbie when it comes to modding so I may be missing something obvious here. I'm trying to figure out what's wrong with the following test script:

Spoiler

scriptName BFGEnchantedArmorScale

ref HeadObj
ref UpperObj
ref LowerObj
ref HandObj
ref FootObj
ref ShieldObj
ref TailObj

float fQuestDelayTime
float HeadObjCurHP
float UpperObjCurHP
float LowerObjCurHP
float HandObjCurHP
float FootObjCurHP
float ShieldObjCurHP
float TailObjCurHP
float Percentage

long HeadObjHP
long UpperObjHP
long LowerObjHP
long HandObjHP
long FootObjHP
long ShieldObjHP
long TailObjHP

begin GameMode
set fQuestDelayTime to 2

let HeadObj := (Player.GetEquippedObject 0) ;0 = head

If HeadObj == 0
let HeadObj := (Player.GetEquippedObject 1) ;1 = hair
Endif

let UpperObj := (Player.GetEquippedObject 2) ;2 = cuirass
let LowerObj := (Player.GetEquippedObject 3) ;3 = greaves
let HandObj := (Player.GetEquippedObject 4) ;4 = gauntlets/bracers
let FootObj := (Player.GetEquippedObject 5) ;5 = boots
let ShieldObj := (Player.GetEquippedObject 13) ;13 = shield
let TailObj := (Player.GetEquippedObject 15) ;15 = tail

if LowerObj == 0
if UpperObj == 0
if FootObj == 0
if HandObj == 0
let UpperObj := (Player.GetEquippedObject 20) ;20 = cuirass + greaves + gauntlets + boots
else
let UpperObj := (Player.GetEquippedObject 19) ;19 = cuirass + greaves + boots
endif
else
let UpperObj := (Player.GetEquippedObject 18) ;18 = cuirass + greaves
endif
endif
endif

if HeadObj.IsArmor
let HeadObjCurHP := Player.GetEquippedCurrentHealth 0
if HeadObjCurHP == 0
let HeadObjCurHP := Player.GetEquippedCurrentHealth 1
endif
if HeadObjCurHP == 0
player.UnequipitemNS HeadObj
endif
let HeadObjHP := HeadObj.GetObjectHealth
let Percentage := HeadObjCurHP / HeadObjHP
Message "Helmet Health is %.0f%%.", Percentage
endif

if UpperObj.IsArmor
let UpperObjCurHP := Player.GetEquippedCurrentHealth 2
if UpperObjCurHP == 0
player.UnequipitemNS UpperObj
endif
let UpperObjHP := UpperObj.GetObjectHealth
let Percentage := UpperObjCurHP / UpperObjHP
Message "Cuirass Health is %.0f%%.", Percentage
endif

end


"HeadObj.IsArmor" and "UpperObj.IsArmor" are never true, at least in my test case - a custom enchanted hood and custom enchanted Perfect Madness cuirass. For that matter, HeadObj.IsClothing and UpperObj.IsClothing are never true either. But the Object IDs are being properly recognized.

Is there a limitation to these commands that prevents them from recognizing custom enchanted armor/clothing, or am I missing something? Thanks in advance!

(By the way, any other general suggestions are also appreciated. The ultimate goal of this mod is to scale the enchantments of armor so that the more damage the armor takes, the less potent the enchantment. For example a cuirass at 20% health may only have 60% of its enchantment in effect.)
User avatar
Alisha Clarke
 
Posts: 3461
Joined: Tue Jan 16, 2007 2:53 am

Post » Fri Oct 22, 2010 12:08 am

Bump...
User avatar
Kerri Lee
 
Posts: 3404
Joined: Sun Feb 25, 2007 9:37 pm

Post » Fri Oct 22, 2010 1:26 am

GetEquippedObject returns a base object. The thing to the left of the dot in a function call must be a reference, not a base object.
Use isArmor headObj.
User avatar
Cayal
 
Posts: 3398
Joined: Tue Jan 30, 2007 6:24 pm

Post » Thu Oct 21, 2010 5:38 pm

Thanks, that did fix the problem.

A follow-up question for you:
The next thing I need to do in this mod is determine, for example, the magnitude of each magic effect on the helmet, so that I can then modify that magnitude based on the helmet's current health. I've done some reading and think I need to use the GetNthEffectItemMagnitude HeadObj 0 command to do this. But it requires a reference, not an ObjectID, in place of HeadObj. Am I totally off base in using this approach, or am I at least heading in the right direction? If so, how would you recommend that I read the magnitude of each effect on the helmet, as so far I only have the helmet's ObjectID?

Thanks in advance - I really appreciate it.
User avatar
SaVino GοΜ
 
Posts: 3360
Joined: Mon Sep 17, 2007 8:00 pm

Post » Fri Oct 22, 2010 5:19 am

short idxref headObjref enchantmentshort maglet enchantment := GetEnchantment headObjlet idx := GetMagicItemEffectCount enchantmentwhile idx > 0  let idx -= 1  let mag := GetNthEffectItemMagnitude enchantment idx  ; // do stuffloop

User avatar
barbara belmonte
 
Posts: 3528
Joined: Fri Apr 06, 2007 6:12 pm

Post » Fri Oct 22, 2010 6:50 am

Thanks again for your help! I have one more general question for anyone interested.

There's a few different purposes to this mod:
(1) Scale armor enchantments according to armor condition (20%-120% of the base enchantment). For example, a Resist Magic 20% Cuirass will only be one fifth effective (Resist Magic 4) when it's about to break, or it'll have a small bonus (Resist Magic 24) at 125%.
(2) Scale weapon charges according to weapon condition. A Grand Soul gem weapon would only effectively have 320 charges when it's about to break, or 1920 when it's at 125%.
(3) Broken armor is automatically unequipped and any clothing in inventory is equipped to take its place.
(4) Also apply all of the above to NPCs.
(5) Make armor and weapons more difficult to repair in-field. Experts and Masters can repair to 75% in-field, Journeyman and below to 50%. To repair to the Vanilla values, the player has to be within a few feet of an anvil. Using the Dwemer Forge (at Battlehorn Castle) allows repairs to 150%.

First, I'm interested in any general comments on the above. Second, I'm trying to figure out how to implement #1 and #2. The problem is that I don't know how to keep track of the "base enchantment" (i.e. enchantment at 100% strength) on each item. For example, when the mod first loads, let's say it finds the PC is wearing a Resist Magic 20 cuirass that is half damaged, so scales it down to Resist Magic 12. If the Cuirass is saved that way and the game is reloaded, that same Cuirass will get scaled down again to Resist Magic 7, because the mod doesn't know it was originally Resist Magic 20. Any suggestions on how to get around this?
User avatar
Alexandra Ryan
 
Posts: 3438
Joined: Mon Jul 31, 2006 9:01 am

Post » Thu Oct 21, 2010 5:28 pm

Are you modifying the charge of the base object or the equipped weapon/armor?
Based on your description it sounds like you want to modify the charges of specific items in an actor's inventory (using SetCurrentCharge) rather than modifying all instances of the base object. This is possible for equipped items (SetEquippedCurrentCharge); it will not be possible more generally until OBSE 0019 becomes available.
User avatar
W E I R D
 
Posts: 3496
Joined: Tue Mar 20, 2007 10:08 am


Return to IV - Oblivion