Scripting Tutorial: Get PlayerRef

From the Oblivion ConstructionSet Wiki
Revision as of 12:06, 1 May 2010 by imported>Demolishun
Jump to navigation Jump to search
Tools used in this tutorial

Required


A Simple Approach

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

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

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