Difference between revisions of "Scripting Tutorial: Get PlayerRef"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Demolishun
imported>Demolishun
Line 1: Line 1:
= WIP =
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}
{{Tools|req0=[[The Elder Scrolls Construction Set|Construction Set]]}}


Line 7: Line 5:
<pre>
<pre>
set playerRef to player
set playerRef to player
</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>
</pre>


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 itI also found this [http://cs.elderscrolls.com/constwiki/index.php/Player information].
== 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 playerIt 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).

Revision as of 12:06, 1 May 2010

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