Difference between revisions of "Scripting Tutorial: Get PlayerRef"
no edit summary
imported>Demolishun |
imported>Demolishun |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}} | {{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}} | ||
Line 8: | Line 6: | ||
set playerRef to player | set playerRef to player | ||
</pre> | </pre> | ||
Inside of an onTrigger function does not normally have access to the playerRef reference so I had to find another way to get it. This simple approach is one of the easier ways. What it came down to was checking the player ref against other refs. | |||
Now there is some history behind this. I also know there was a lengthy [http://cs.elderscrolls.com/constwiki/index.php/Talk:GetSelf discussion] on this wiki about it. I also found this [http://cs.elderscrolls.com/constwiki/index.php/Player information]. | |||
== Other Ways == | |||
There are other methods, but what threw me was I could not manually set a ref. That would have taken care of the problem if I could set a ref to 0x14. OBSE couldn't do it. I didn't want to add a plugin for OBSE to do it either. Now I did find other ways to get a ref or to compare a ref: | |||
<pre> | |||
; this method is for comparing refs | |||
... | |||
if (GetIsReference player == 0) ; not player ref | |||
... | |||
</pre> | |||
<pre> | |||
; this uses a quest as quests can access playerRef | |||
; code run in gamemode of quest | |||
if (plyrRef == 0) | |||
set plyrRef to playerRef | |||
endif | |||
... | |||
; now access plyrRef in any other script | |||
<questname>.plyrRef | |||
</pre> | |||
== Conclusion == | |||
I can't remember where I found the simpler approach of assigning player to a ref variable to force the engine to compile player into a ref during that instance. That is funny thing about player. It can be a base object or a ref depending upon context. So by setting player to a ref variable we create the context where player returns its ref (0x14) rather than its base object (0x07). | |||
[[Category: Scripting]] | |||
[[Category: Useful Code]] |