Papyrus -- Getting reference for object script is attached t

Post » Mon Jun 18, 2012 7:55 pm

I'd like to make a general script which I can attach to several game items. Rather than copy and paste each item's name into function calls for the script, I wonder if there is a way for the script to get the reference of the object it is attached to.

I found the function getreference(), but this seems to just return the reference for an alias attached to it (e.g. Bob.getreference()).

For example, say I attach the script to an item. When the item is sold I want to give it to another character.
e.g.

Event OnSell(Actor akSeller)
Actor giftee = Game.FindRandomActor(0.0,0.0,0.0,100) {or whatever to get a valid Actor}
giftee.AddItem(akItemReference)

My problem is that I need the object reference to pass to AddItem. So how can I get the reference of the object my script is currently attached to? If I can't figure out how to fetch it in the script, I'd have to change the script by hand for every game item I attach it to.

e.g. ObjectReference myCurrentItem = ???

Is there some default objectreference variable set for whatever your script is attached to?

Thanks for any pointers,

-mrmra
User avatar
Eoh
 
Posts: 3378
Joined: Sun Mar 18, 2007 6:03 pm

Post » Mon Jun 18, 2012 8:12 am

Perhaps using the Self variable?

I'm really not sure if it can be used like that, but http://www.creationkit.com/Function_Reference talks about it.
User avatar
kiss my weasel
 
Posts: 3221
Joined: Tue Feb 20, 2007 9:08 am

Post » Mon Jun 18, 2012 10:56 am

Perhaps using the Self variable?

I'm really not sure if it can be used like that, but http://www.creationkit.com/Function_Reference talks about it.

It can. Ive used it for checking if an item had a spell cast upon it.
User avatar
c.o.s.m.o
 
Posts: 3419
Joined: Sat Aug 12, 2006 9:21 am

Post » Mon Jun 18, 2012 8:03 pm

Hey, that seems to work, thanks kindly! I wasn't aware there was a "self" variable. I'll go back into the Wiki and see if I can find a list of variables.

Cheers,

-mrmra
User avatar
Euan
 
Posts: 3376
Joined: Mon May 14, 2007 3:34 pm

Post » Mon Jun 18, 2012 11:21 am

A "list of variables" isn't quite what you're looking for, as the vast majority of variables will be those that you declare yourself. Certain types of script have access to the special "Self" and "Parent" variables, though, as described here - http://www.creationkit.com/Function_Reference#Special_Variables

Cipscis
User avatar
Adrian Morales
 
Posts: 3474
Joined: Fri Aug 10, 2007 3:19 am


Return to V - Skyrim