Transforme Object Reference into Actor property

Post » Tue Jun 19, 2012 1:26 pm

Hi

I have a script with an activator but Onactivated event return an ObjectReference

if i use actor function with an ObjectReference it's don't work

Scriptname Firearrow extends ObjectReference Event OnActivate(ObjectReference MyActivator)if (Myactivator().GetEquippedItemType(0) == 7)debug.messagebox("Actor have a bow")endifEndEvent

I have this error
c:\program files (x86)\steam\steamapps\common\skyrim\Data\Scripts\Source\temp\Firearrow.psc(9,16): GetEquippedItemType is not a function or does not exist

And it existe a funtion for return the ObjectReference wiwh the script is attached?

If i put 2 or 3 activator on my map i want return ObjectReference of activator when it's actived
User avatar
Katharine Newton
 
Posts: 3318
Joined: Tue Jun 13, 2006 12:33 pm

Post » Tue Jun 19, 2012 12:09 pm

You want to use a cast. Look for the Cast Reference page on the Creation Kit wiki. (I would post a direct link, but this forums' stringent anti-spam rules prevent me from doing that yet.)

In your case, the syntax would be:

scriptname Firearrow extends ObjectReference event OnActivate( ObjectReference MyActivator )	Actor actorActivator = MyActivator as Actor	if( actorActivator != None && actorActivator.GetEquippedItemType(0) == 7 )		Debug.MessageBox( "Actor has a bow" )	endifendevent

Note the actorActivator != None check. It could happen that your object is not activated by an Actor. If this happens, the cast will return None, which you want to guard against or your script will fail to run.
User avatar
Shelby Huffman
 
Posts: 3454
Joined: Wed Aug 08, 2007 11:06 am

Post » Tue Jun 19, 2012 5:51 pm

Very thanks you it's work perfectly
User avatar
John Moore
 
Posts: 3294
Joined: Sun Jun 10, 2007 8:18 am


Return to V - Skyrim