Scripting Tutorial: Get PlayerRef
A Simple Approach[edit | edit source]
The approach I am using is simple:
set playerRef to player
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.
Other Ways[edit | edit source]
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:
; this method is for comparing refs ... if (GetIsReference player == 0) ; not player ref ...
; 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
Conclusion[edit | edit source]
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).