Jump to content

Scripting Help for Armor Durability Mod


tnt90

Recommended Posts

Just have one thing that would make my life so much simpler if it could be done, but I don't know how to do it.

 

Does anyone know how to reference the object reference a script is attached to without having to manually define it with a property every time you attach the script?

 

Having to manually define the armor each time I add the script to an armor is a pain, but that's what I've been doing so far. Finally got fed up enough to ask the forums.

 

Thank you.

Link to comment
Share on other sites

You could use GetFormID() from the form script section of creadtion kit papyrus page http://www.creationkit.com/Form_Script

But this would come with multiple issues. If you are attaching the script to say the iron cuirass form as I suspect then it would reference all iron cuirasses in the game, not just the 1 instance of it. Also if you are attaching the script to all items in the gsme it would make all other mods that alter them, incompatable. I've made a mod, helmet toggle which alters all the helmets in the game and for that I had to add a script to the player that references all helmets in the game through propertys, though its made easier by naming them exactly then clicking auto add propertys to link them all to the form of the same name. though that may not be much help either if u need to reference the instance. I'll have another look for instance referencing scripts. I'd also be interested in how your script works at the moment if you wouldnt mind sharing.

 

Edit - also you could reference it using event on equip if that works with form scripts.

Type

 
Form property currentobject
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
Currentobject = akbaseobject

CurrentObject will then be the form you refur too in the script.

 

It might be

form current object

instead, cant remember

Edited by maniczombie
Link to comment
Share on other sites

Yeah, in order to have each armor have a unique stored HP value, it's almost necessary to add a script to each one. I've had some ideas where I could make a version without altering the armors but it wouldn't keep track of them once the player has dropped them.

Haven't tried GetFormID() yet, so I'll have a go at that and see if it returns what I want. I'm pretty much using this to get access to the armor's keywords so I can tell what it is to generate its HP.

 

My code bits are as follows, there are three main scripts, one for the armor, one for hit detection, and one to keep track of everything.

 

 

  Reveal hidden contents

 

 

Thats pretty much it, other than a simple effect script that tell you what the armor HP values are.

Also, this code isn't commented so.. yeah sorry about that.

 

Edit: Nope, GetFormID() didn't work.

 

Edit2: Can't use OnObjectEquipped either because I'm not certain which occurs first, OnObjectEquipped or OnContainerChange.

Tried putting in form current object but the compiler just gives me errors.

Edited by tnt90
Link to comment
Share on other sites

I'll have another look tommorrow, trying to read through this much code on my phone isn't easy >.< lol

 

Edit - all I can think of at the moment is doing it through the script on the player as the only known (to me) ways to get for base object is through container change and equip events.

Edited by maniczombie
Link to comment
Share on other sites

Yeah take your time, there's a lot of code and I haven't really commented it at all. My programming professors would skin me alive for not doing so. :P

 

I'll probably go back through that post and try to add in a few comments on what everything should do.

Link to comment
Share on other sites

I only started learning this stuff yesterday so I'm probably wrong or maybe I don't understand what you're asking, but isn't that what Self is for?

 

ScriptName someObjRefScript Extends ObjectReference

ObjectReference objRef

Event OnInit()
   objRef = Self as ObjectReference
EndIf

Link to comment
Share on other sites

Yes, but aren't they sort of one in the same, indirectly? I mean, I assume you want an ObjectReference pointer so you can call methods on it, which will execute against the base object - presumably the object the script is attached to. At least that's how it seems to work in the 1 script I've written so far.

 

Sorry if I'm way off, I'm still a little confused by the blur between scripts and objects in Papyrus.

Link to comment
Share on other sites

I just re-read your first post. I mis-understood. I thought you wanted an ObjectReference variable, not a variable of some specific object type, like Armor. Maybe this will work

 

ScriptName someArmor Extends ObjectReference

Armor theArmor

Event OnInit()
   theArmor = GetBaseObject() as Armor
EndEvent

Link to comment
Share on other sites

Tried that, didn't work though. GetBaseObject() just returns a None.

 

So far I've tried:

GetBaseObject() - returned None

self - returned the script

self.GetBaseObject() - can't remember what it returned but it wasn't the armor

GetFormID() - returned 0

probably some others I can't remember as well

 

The only thing I can think of is checking which block OnContainerChange of the incoming object or OnItemAdded() on the player triggers first and if it is consistent.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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