Jump to content

Referencing Object of Script


Riain

Recommended Posts

Hi,

 

I have a script that may different object use. I know how to check if the object is equipped by using Player.GetEquipped [object ID] but that requires me defining the ID myself. I was wondering if you could reference the object running the script instead so that the script is more flexible. Something like

 

ref MyObject

 

set MyObject to ObjectRunningThisScript

 

If Player.GetEquipped MyObject ...

 

 

I tried using GetSelf but it didn't seem to work. Apparently Oblivion had something like:

 

ref self

ref myBase

set self to getSelf

set myBase to self.getBaseObject

 

But GetBaseObject is not a FO3 command, and I don't want to use FOSE if I can help it.

Link to comment
Share on other sites

Firstly, inventory items aren't usually assigned RefIDs so GetSelf should never be called on an item while it is in an inventory. Luckily, you don't need to use GetSelf (in fact you really shouldn't be using it here) as you can simply use implied reference syntax:

ref rBaseObject
set rBaseObject to GetBaseObject
if player.GetEquipped rBaseObject

Keep in mind that GetBaseObject is a FOSE function, so you'll need to run the GECK via FOSE in order to compile it correctly, and you'll need to run Fallout 3 via FOSE in order for the script to run.

 

Unless you want to "hard code" the EditorID in the script, you have no choice but to use FOSE. There really isn't any reason to be afraid of it - it's an incredibly useful tool.

 

Cipscis

Link to comment
Share on other sites

If the item that you're checking is an armour, then you'd be better off using an Object Effect, as this can cause code to run only when the item is equipped without worrying about being broken by EquipItem. If it's a weapon, then you'd be better off using code like this:

short sIsEquipped
Begin OnEquip
set sIsEquipped to 1
End

Begin GameMode
if sIsEquipped
; Do stuff
endif
End

Begin OnUnequip
set sIsEquipped to 0
End

If you use GetEquipped, and there are multiple copies of the inventory item in the player's inventory, then multiple instances of the script will run. If this will never be the case, then you should be able to "hard code" the EditorID of the Base Object instead of having to rely on GetBaseObject.

 

Cipscis

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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