Jump to content

Scripting Help for Armor Durability Mod


tnt90

Recommended Posts

Interesting that GetBaseObject() returns None but self.GetBaseObject() didn't. I would have thought they'd return the exact same thing.

 

GetBaseObject() returns a Form object which is the "root" type of objects like Armor and Weapon. Did you try casting (the 'as' operator) the result of GetBaseObject() to Armor like I did in my last example?

 

Perhaps if you posted what you have. You never mentioned what your script extends.

Link to comment
Share on other sites

All three scripts are in the spoiler tag in the 3rd post. The primary script we're dealing with here extends an object reference. Specifically an armor, it is designed such that the same script should be able to go on any armor. Currently you have to tell it via an armor property what the armor is the script is attached to, then from that it uses the keywords to determine the values for the armor. The goal here is to save time and not have to tell each script which armor it is on.

 

I suppose I haven't tried casting the GetBaseObject() command but it would seem that if the raw command returns None then casting that wouldn't do me any better.

self.GetBaseObject() very well could have returned None, its been a while since I tested that and I can't remember exactly.

 

Don't really have time at the moment to go back and do it again, have a Java lab to finish up for Tuesday.

Link to comment
Share on other sites

Sorry, missed the spoiler tag... I wrote this quickie test script and it worked

 

ScriptName armorTest Extends ObjectReference

Armor thisArmor

Event OnInit()
   thisArmor = self.GetBaseObject() as Armor
   
   If thisArmor
       Debug.MessageBox("thisAmor not none")
   EndIf
EndEvent

Event OnEquipped(Actor akActor)
   Debug.MessageBox("equipped")
EndEvent

 

I attached the script to a piece of armor (dragonscale boots), when I loaded a save I got "thisArmor not none" message. I had another script create a new instance of the boots and drop it at my feet. I picked it up and equipped it and got the "equipped" message.

Link to comment
Share on other sites

Sweet, if you have a moment could you modify that to:

 

ScriptName armorTest Extends ObjectReference

Armor thisArmor

Event OnInit()
   thisArmor = self.GetBaseObject() as Armor
   
   If thisArmor.haskeywordstring("ArmorBoots")
       Debug.MessageBox("these are boots")
   EndIf
EndEvent

Event OnEquipped(Actor akActor)
   Debug.MessageBox("equipped")
EndEvent

 

If that displays the boot message correctly for the boots you were testing, then the issue is solved.

Edited by tnt90
Link to comment
Share on other sites

Alright, sounds like that does it then. I'll post back here later on when I implement that into the code and report if it all works.

Thank you both.

 

Edit: I saw it work twice. Returned the correct keywords. But after trying to get it to work with the rest of the script, nothing. Going to try for another 10 min or so. I think I've had enough coding for one day.

Edited by tnt90
Link to comment
Share on other sites

Conclusions so far:

 

If I call the self.GetBaeObject() in the OnContainerChange(...) event then it will return the armor successfully when I drop the armor but not when I pick it up.

If I call the self.GetBaeObject() in an OnInit() event then adding it via console doesn't return armor correctly. And it doesn't appear to work on preexisting armors. (Note checking condition calls in the OnContainerChange(...) event.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...