Scripting Tutorial: Get PlayerRef

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
Tools used in this tutorial


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.

Now there is some history behind this. I also know there was a lengthy discussion on this wiki about it. I also found this information.

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
; now access plyrRef in any other script

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).