Difference between revisions of "Reference Variables for Nearby Actors"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>DragoonWraith
 
imported>QQuix
(Byline removed)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Originally posted on [http://www.elderscrolls.com/forums/ Elder Scrolls Forums] by Tegid
 
----
This is much easier to do with OBSE's [[GetFirstRef|Reference walking functions]].
----
 


I know there have been several people who have wanted to get references for the various enemies and actors in their area. Here are the steps to do this with the current set of Script commands.
I know there have been several people who have wanted to get references for the various enemies and actors in their area. Here are the steps to do this with the current set of Script commands.
Line 8: Line 12:
Now we need our script effect. This one is definitely not perfect (I don't seem to ever hit my ScriptFinishEffect, but it isn't necessary anyhow.)
Now we need our script effect. This one is definitely not perfect (I don't seem to ever hit my ScriptFinishEffect, but it isn't necessary anyhow.)


CODE
scriptname EntityFinderEffect
 
scriptname EntityFinderEffect
short runOnce
 
short NotReported
short NotReported
ref self
ref self
 
float timer
float timer
 
begin ScriptEffectStart
begin ScriptEffectStart
  set self to GetSelf
    set self to GetSelf
; message "Casting EntityFinderEffect", 20
;   message "Casting EntityFinderEffect", 20
  set timer to 0
    set timer to 0
  if (self != player)
    if (self != player)
    set NotReported to 1
        set NotReported to 1
  else
    else
    set NotReported to 0
        set NotReported to 0
  endif
    endif
end
end
 
begin ScriptEffectUpdate
begin ScriptEffectUpdate
  if (timer > 0)
    if (timer > 0)
    set timer to (timer - GetSecondsPassed)
        set timer to (timer - GetSecondsPassed)
    return
        return
  else
    else
    if (runOnce == 0)
        set timer to 0.5
      set timer to 0.5
    endif
      set runOnce to 1
    if (NotReported == 1)
    else
        if (EnemyFinderRef1.RefsRequested == 0)
  endif
            set NotReported to 0
  if (NotReported == 1)
        else
    if (EnemyFinderRef1.RefsRequested == 0)
            if (EnemyFinderRef1.RefsRequested == 1)
      set NotReported to 0
              if (EnemyFinderRef1.ref1full == 0)
    elseif (EnemyFinderRef1.RefsRequested == 1)
                set EnemyFinderRef1.ref1full to 1
        if (EnemyFinderRef1.ref1full == 0)
                set EnemyFinderRef1.reference1 to self
          set EnemyFinderRef1.ref1full to 1
;               Message "Reported to Reference1",1
          set EnemyFinderRef1.reference1 to self
                set NotReported to 0
;       Message "Reported to Reference1",1
              elseif (EnemyFinderRef1.ref2full == 0)
          set NotReported to 0
                set EnemyFinderRef1.ref2full to 1
        elseif (EnemyFinderRef1.ref2full == 0)
                set EnemyFinderRef1.reference2 to self
          set EnemyFinderRef1.ref2full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference2 to self
;               Message "Reported to Reference2",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref3full == 0)
;       Message "Reported to Reference2",1
                set EnemyFinderRef1.ref3full to 1
        elseif (EnemyFinderRef1.ref3full == 0)
                set EnemyFinderRef1.reference3 to self
          set EnemyFinderRef1.ref3full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference3 to self
;               Message "Reported to Reference3",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref4full == 0)
;       Message "Reported to Reference3",1
                set EnemyFinderRef1.ref4full to 1
        elseif (EnemyFinderRef1.ref4full == 0)
                set EnemyFinderRef1.reference4 to self
          set EnemyFinderRef1.ref4full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference4 to self
;               Message "Reported to Reference4",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref5full == 0)
;       Message "Reported to Reference4",1
                set EnemyFinderRef1.ref5full to 1
        elseif (EnemyFinderRef1.ref5full == 0)
                set EnemyFinderRef1.reference5 to self
          set EnemyFinderRef1.ref5full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference5 to self
;               Message "Reported to Reference5",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref6full == 0)
;       Message "Reported to Reference5",1
                set EnemyFinderRef1.ref6full to 1
        elseif (EnemyFinderRef1.ref6full == 0)
                set EnemyFinderRef1.reference6 to self
          set EnemyFinderRef1.ref6full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference6 to self
;               Message "Reported to Reference6",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref7full == 0)
;       Message "Reported to Reference6",1
                set EnemyFinderRef1.ref7full to 1
        elseif (EnemyFinderRef1.ref7full == 0)
                set EnemyFinderRef1.reference7 to self
          set EnemyFinderRef1.ref7full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference7 to self
;               Message "Reported to Reference7",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref8full == 0)
;       Message "Reported to Reference7",1
                set EnemyFinderRef1.ref8full to 1
        elseif (EnemyFinderRef1.ref8full == 0)
                set EnemyFinderRef1.reference8 to self
          set EnemyFinderRef1.ref8full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference8 to self
;               Message "Reported to Reference8",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref9full == 0)
;       Message "Reported to Reference8",1
                set EnemyFinderRef1.ref9full to 1
        elseif (EnemyFinderRef1.ref9full == 0)
                set EnemyFinderRef1.reference9 to self
          set EnemyFinderRef1.ref9full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference9 to self
;               Message "Reported to Reference9",1
          set NotReported to 0
              elseif (EnemyFinderRef1.ref10full == 0)
;       Message "Reported to Reference9",1
                set EnemyFinderRef1.ref10full to 1
        elseif (EnemyFinderRef1.ref10full == 0)
                set EnemyFinderRef1.reference10 to self
          set EnemyFinderRef1.ref10full to 1
                set NotReported to 0
          set EnemyFinderRef1.reference10 to self
;               Message "Reported to Reference10",1
          set NotReported to 0
              endif
;       Message "Reported to Reference10",1
            endif
         endif
         endif
      endif
     endif
     endif
end
End
 
begin ScriptEffectFinish
Begin ScriptEffectFinish
;    if (NotReported == 1)
  if (NotReported == 1)
;        return
    return
;    else
  else
;; I have never seen the following code execute.  It isn't necessary anyhow, but it was an attempt to directly
    MessageBox "Activating the EnemyFinder"
;; return the reference
    EnemyFinderRef1.Activate self 1
        MessageBox "Activating the EnemyFinder"
  endif
        EnemyFinderRef1.Activate self 1
End
;    endif
end


Clearly I have some debug code in there you can uncomment etc. Now, you can see it references variables in an EnemyFinderRef1 that we don't know about. Well first, let's define the script that defines those variables.
Clearly I have some debug code in there you can uncomment etc. Now, you can see it references variables in an EnemyFinderRef1 that we don't know about. Well first, let's define the script that defines those variables.


CODE
scriptname EnemyFinder
 
scriptname EnemyFinder
ref AskingRef
 
short RefsRequested
ref AskingRef
ref reference1
short RefsRequested
ref reference2
ref reference1
ref reference3
ref reference2
ref reference4
ref reference3
ref reference5
ref reference4
ref reference6
ref reference5
ref reference7
ref reference6
ref reference8
ref reference7
ref reference9
ref reference8
ref reference10
ref reference9
ref reference10
short ref1full
 
short ref2full
short ref1full
short ref3full
short ref2full
short ref4full
short ref3full
short ref5full
short ref4full
short ref6full
short ref5full
short ref7full
short ref6full
short ref8full
short ref7full
short ref9full
short ref8full
short ref10full
short ref9full
short ref10full
ref temp
 
ref self
ref temp
ref self
short doonce
 
short doonce
Begin OnActivate
 
  if (doonce == 0)
begin OnActivate
    set self to EnemyFinderRef1
    if (doonce == 0)
    set AskingRef to GetActionRef
        set self to EnemyFinderRef1
    set doonce to 1
        set AskingRef to GetActionRef
  endif
        set doonce to 1
;The code until the sets is supposed to deal with the ScriptEffectFinish code
    endif
  set temp to GetActionRef
;;The code until the sets is supposed to deal with the ScriptEffectFinish code
  if (temp != AskingRef)
    set temp to GetActionRef
    if (temp != player)
    if (temp != AskingRef)
      AskingRef.Activate temp 1
        if (temp != player)
    endif
            AskingRef.Activate temp 1
  endif
        endif
  set ref1full to 0
    endif
  set ref2full to 0
    set ref1full to 0
  set ref3full to 0
    set ref2full to 0
  set ref4full to 0
    set ref3full to 0
  set ref5full to 0
    set ref4full to 0
  set ref6full to 0
    set ref5full to 0
  set ref7full to 0
    set ref6full to 0
  set ref8full to 0
    set ref7full to 0
  set ref9full to 0
    set ref8full to 0
  set ref10full to 0
    set ref9full to 0
  set RefsRequested to 1
    set ref10full to 0
  float xval
    set RefsRequested to 1
  float yval
    float xval
  float zval
    float yval
  self.moveto player, 0.0, 0.0, 100.0
    float zval
; set xval to (self.getpos x)
    self.moveto player, 0.0, 0.0, 100.0
; set yval to (self.getpos y)
;   set xval to (self.getpos x)
; set zval to (self.getpos z)
;   set yval to (self.getpos y)
; MessageBox "Moved to (%.2f, %.2f, %.2f)", xval, yval, zval
;   set zval to (self.getpos z)
  cast TargetDetection Player
;   MessageBox "Moved to (%.2f, %.2f, %.2f)", xval, yval, zval
End
    cast TargetDetection Player
end
 


Again I have some debug code there. Basically this is a script that will store the references and the checks to see if they are full. It goes on an object (an Activator is a great choice) and each time it is activated, it moves to roughly the actors location and casts the spell at the actor(it does no damage and isn't hostile, I just needed a target for it). Right now you can still hear the spell go off, but I didn't worry too much about that for this Proof of Concept (I named the spell TargetDetection remember?).
Again I have some debug code there. Basically this is a script that will store the references and the checks to see if they are full. It goes on an object (an Activator is a great choice) and each time it is activated, it moves to roughly the actors location and casts the spell at the actor(it does no damage and isn't hostile, I just needed a target for it). Right now you can still hear the spell go off, but I didn't worry too much about that for this Proof of Concept (I named the spell TargetDetection remember?).
Line 186: Line 185:
Now all that must be done is to Activate EnemyFinderRef1. I added a script to an Iron Bow to test it, but you could put it on anything, or you could make the EnemyFinderRef1 run in GameMode instead of on activate and go off every X seconds as you decide. I will include the script I have which is object agnostic (it isn't bow specific) and you can take the code and modify it as you see fit. I've included printouts that aren't perfect but work to the script code. You'll get the first two message boxes (if there are two nearby references) right now since I didn't bother to fix the MessageBox chain. I tried to print the reference values but that failed.
Now all that must be done is to Activate EnemyFinderRef1. I added a script to an Iron Bow to test it, but you could put it on anything, or you could make the EnemyFinderRef1 run in GameMode instead of on activate and go off every X seconds as you decide. I will include the script I have which is object agnostic (it isn't bow specific) and you can take the code and modify it as you see fit. I've included printouts that aren't perfect but work to the script code. You'll get the first two message boxes (if there are two nearby references) right now since I didn't bother to fix the MessageBox chain. I tried to print the reference values but that failed.


CODE
scriptname RangeTest
 
scriptname RangeTest
float timer
 
short doonce
float timer
short player_owned
short doonce
short player_owned
ref actorfinder
 
ref myself
ref actorfinder
ref myself
Begin OnActivate
 
  if (IsActionRef player == 1)
begin OnActivate
    set player_owned to 1
    if (IsActionRef player == 1)
    set actorfinder to enemyfinderref1
        set player_owned to 1
    set myself to this
        set actorfinder to enemyfinderref1
    Activate
        set myself to this
  else
        Activate
    long distance
    else
    ref actor
        long distance
    set actor to GetActionRef
        ref actor
    set distance to (GetDistance actor)
        set actor to GetActionRef
    MessageBox "I am %.0f distance from %.0f", distance, actor
        set distance to (GetDistance actor)
  endif
        MessageBox "I am %.0f distance from %.0f", distance, actor
End
    endif
end
Begin OnDrop
 
 
begin OnDrop
  set player_owned to 0
    set player_owned to 0
end
End
 
begin GameMode
Begin GameMode
    if (player_owned)
  if (player_owned)
        if (doonce == 0)
    if (doonce == 0)
            set timer to 10
      set timer to 10
            set doonce to 1
      set doonce to 1
        endif
    endif
        if (timer > 0)
    if (timer > 0)
            set timer to timer - GetSecondsPassed
      set timer to timer - GetSecondsPassed
            long distance
      long distance
            short button
      short button
            ref actor
      ref actor
            if (timer < 5)
      if (timer < 5)
                set EnemyFinderRef1.RefsRequested to 0
        set EnemyFinderRef1.RefsRequested to 0
            endif
      endif
            if (EnemyFinderRef1.ref1full == 1)
      if (EnemyFinderRef1.ref1full == 1)
                set actor to EnemyFinderRef1.reference1
        set actor to EnemyFinderRef1.reference1
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 1 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 1 %.0f", distance, actor
                set EnemyFinderRef1.ref1full to 0
        set EnemyFinderRef1.ref1full to 0
            endif
      endif
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref2full == 1)
      if (button > -1 && EnemyFinderRef1.ref2full == 1)
                set actor to EnemyFinderRef1.reference2
        set actor to EnemyFinderRef1.reference2
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 2 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 2 %.0f", distance, actor
                set EnemyFinderRef1.ref2full to 0
        set EnemyFinderRef1.ref2full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref3full == 1)
      if (button > -1 && EnemyFinderRef1.ref3full == 1)
                set actor to EnemyFinderRef1.reference3
        set actor to EnemyFinderRef1.reference3
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 3 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 3 %.0f", distance, actor
                set EnemyFinderRef1.ref3full to 0
        set EnemyFinderRef1.ref3full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref4full == 1)
      if (button > -1 && EnemyFinderRef1.ref4full == 1)
                set actor to EnemyFinderRef1.reference4
        set actor to EnemyFinderRef1.reference4
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 4 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 4 %.0f", distance, actor
                set EnemyFinderRef1.ref4full to 0
        set EnemyFinderRef1.ref4full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref5full == 1)
      if (button > -1 && EnemyFinderRef1.ref5full == 1)
                set actor to EnemyFinderRef1.reference5
        set actor to EnemyFinderRef1.reference5
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 5 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 5 %.0f", distance, actor
                set EnemyFinderRef1.ref5full to 0
        set EnemyFinderRef1.ref5full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref6full == 1)
      if (button > -1 && EnemyFinderRef1.ref6full == 1)
                set actor to EnemyFinderRef1.reference6
        set actor to EnemyFinderRef1.reference6
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 6 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 6 %.0f", distance, actor
                set EnemyFinderRef1.ref6full to 0
        set EnemyFinderRef1.ref6full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref7full == 1)
      if (button > -1 && EnemyFinderRef1.ref7full == 1)
                set actor to EnemyFinderRef1.reference7
        set actor to EnemyFinderRef1.reference7
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 7 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 7 %.0f", distance, actor
                set EnemyFinderRef1.ref7full to 0
        set EnemyFinderRef1.ref7full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref8full == 1)
      if (button > -1 && EnemyFinderRef1.ref8full == 1)
                set actor to EnemyFinderRef1.reference8
        set actor to EnemyFinderRef1.reference8
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 8 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 8 %.0f", distance, actor
                set EnemyFinderRef1.ref8full to 0
        set EnemyFinderRef1.ref8full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref9full == 1)
      if (button > -1 && EnemyFinderRef1.ref9full == 1)
                set actor to EnemyFinderRef1.reference9
        set actor to EnemyFinderRef1.reference9
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 9 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 9 %.0f", distance, actor
                set EnemyFinderRef1.ref9full to 0
        set EnemyFinderRef1.ref9full to 0
            endif
      endif
            set button to -2
      set button to -2
            set button to getbuttonpressed
      set button to getbuttonpressed
            if (button > -1 && EnemyFinderRef1.ref10full == 1)
      if (button > -1 && EnemyFinderRef1.ref10full == 1)
                set actor to EnemyFinderRef1.reference10
        set actor to EnemyFinderRef1.reference10
                set distance to (GetDistance actor)
        set distance to (GetDistance actor)
                MessageBox "I am %.0f distance from Reference 10 %.0f", distance, actor
        MessageBox "I am %.0f distance from Reference 10 %.0f", distance, actor
                set EnemyFinderRef1.ref10full to 0
        set EnemyFinderRef1.ref10full to 0
            endif
      endif
        else             
    else             
            Message "Looking for Actor Range", 1
      Message "Looking for Actor Range", 1
            actorfinder.Activate  myself 1
      actorfinder.Activate  myself 1
            set timer to 10
      set timer to 10
        endif
    endif
    endif
  endif
end
 
End


Clearly you could make your timeout value a global or set it to something different based on the situation. Also you want to pull the references out from your script as soon as possible so that you can make sure you don't miss the one you want due to a one not being able to report in time because the registers are full.
Clearly you could make your timeout value a global or set it to something different based on the situation. Also you want to pull the references out from your script as soon as possible so that you can make sure you don't miss the one you want due to a one not being able to report in time because the registers are full.

Latest revision as of 06:14, 24 June 2012


This is much easier to do with OBSE's Reference walking functions.



I know there have been several people who have wanted to get references for the various enemies and actors in their area. Here are the steps to do this with the current set of Script commands.

First we need to create a new spell. It should be a Script Effect Spell (I named it TargetDetection) with an area of effect of 4-6000 (in practice 4000 is on the edge of fading out on low end systems), 0 damage and check to ignore immunity/resistance, LOS etc. Basically we want this thing to hit no matter what. Oh, and uncheck hostile and auto-calc costs. (This is probably spread across two dialogs)

Now we need our script effect. This one is definitely not perfect (I don't seem to ever hit my ScriptFinishEffect, but it isn't necessary anyhow.)

scriptname EntityFinderEffect

short runOnce
short NotReported
ref self

float timer

begin ScriptEffectStart
  set self to GetSelf
; message "Casting EntityFinderEffect", 20
  set timer to 0
  if (self != player)
    set NotReported to 1
  else
    set NotReported to 0
  endif
end

begin ScriptEffectUpdate
  if (timer > 0)
    set timer to (timer - GetSecondsPassed)
    return
  else
    if (runOnce == 0)
      set timer to 0.5
      set runOnce to 1
    else
  endif
  if (NotReported == 1)
    if (EnemyFinderRef1.RefsRequested == 0)
      set NotReported to 0
    elseif (EnemyFinderRef1.RefsRequested == 1)
       if (EnemyFinderRef1.ref1full == 0)
         set EnemyFinderRef1.ref1full to 1
         set EnemyFinderRef1.reference1 to self
;        Message "Reported to Reference1",1
         set NotReported to 0
       elseif (EnemyFinderRef1.ref2full == 0)
         set EnemyFinderRef1.ref2full to 1
         set EnemyFinderRef1.reference2 to self
         set NotReported to 0
;        Message "Reported to Reference2",1
       elseif (EnemyFinderRef1.ref3full == 0)
         set EnemyFinderRef1.ref3full to 1
         set EnemyFinderRef1.reference3 to self
         set NotReported to 0
;        Message "Reported to Reference3",1
       elseif (EnemyFinderRef1.ref4full == 0)
         set EnemyFinderRef1.ref4full to 1
         set EnemyFinderRef1.reference4 to self
         set NotReported to 0
;        Message "Reported to Reference4",1
       elseif (EnemyFinderRef1.ref5full == 0)
         set EnemyFinderRef1.ref5full to 1
         set EnemyFinderRef1.reference5 to self
         set NotReported to 0
;        Message "Reported to Reference5",1
       elseif (EnemyFinderRef1.ref6full == 0)
         set EnemyFinderRef1.ref6full to 1
         set EnemyFinderRef1.reference6 to self
         set NotReported to 0
;        Message "Reported to Reference6",1
       elseif (EnemyFinderRef1.ref7full == 0)
         set EnemyFinderRef1.ref7full to 1
         set EnemyFinderRef1.reference7 to self
         set NotReported to 0
;        Message "Reported to Reference7",1
       elseif (EnemyFinderRef1.ref8full == 0)
         set EnemyFinderRef1.ref8full to 1
         set EnemyFinderRef1.reference8 to self
         set NotReported to 0
;        Message "Reported to Reference8",1
       elseif (EnemyFinderRef1.ref9full == 0)
         set EnemyFinderRef1.ref9full to 1
         set EnemyFinderRef1.reference9 to self
         set NotReported to 0
;        Message "Reported to Reference9",1
       elseif (EnemyFinderRef1.ref10full == 0)
         set EnemyFinderRef1.ref10full to 1
         set EnemyFinderRef1.reference10 to self
         set NotReported to 0
;        Message "Reported to Reference10",1
       endif
     endif
   endif
End

Begin ScriptEffectFinish
 if (NotReported == 1)
   return
 else
    MessageBox "Activating the EnemyFinder"
    EnemyFinderRef1.Activate self 1
 endif
End

Clearly I have some debug code in there you can uncomment etc. Now, you can see it references variables in an EnemyFinderRef1 that we don't know about. Well first, let's define the script that defines those variables.

scriptname EnemyFinder

ref AskingRef
short RefsRequested
ref reference1
ref reference2
ref reference3
ref reference4
ref reference5
ref reference6
ref reference7
ref reference8
ref reference9
ref reference10

short ref1full
short ref2full
short ref3full
short ref4full
short ref5full
short ref6full
short ref7full
short ref8full
short ref9full
short ref10full

ref temp
ref self

short doonce

Begin OnActivate
  if (doonce == 0)
    set self to EnemyFinderRef1
    set AskingRef to GetActionRef
    set doonce to 1
  endif
;The code until the sets is supposed to deal with the ScriptEffectFinish code
  set temp to GetActionRef
  if (temp != AskingRef)
    if (temp != player)
      AskingRef.Activate temp 1
    endif
  endif
  set ref1full to 0
  set ref2full to 0
  set ref3full to 0
  set ref4full to 0
  set ref5full to 0
  set ref6full to 0
  set ref7full to 0
  set ref8full to 0
  set ref9full to 0
  set ref10full to 0
  set RefsRequested to 1
  float xval
  float yval
  float zval
  self.moveto player, 0.0, 0.0, 100.0
; set xval to (self.getpos x)
; set yval to (self.getpos y)
; set zval to (self.getpos z)
; MessageBox "Moved to (%.2f, %.2f, %.2f)", xval, yval, zval
  cast TargetDetection Player
End

Again I have some debug code there. Basically this is a script that will store the references and the checks to see if they are full. It goes on an object (an Activator is a great choice) and each time it is activated, it moves to roughly the actors location and casts the spell at the actor(it does no damage and isn't hostile, I just needed a target for it). Right now you can still hear the spell go off, but I didn't worry too much about that for this Proof of Concept (I named the spell TargetDetection remember?).

Now, I make a new activator with the TrigZone01.nif model (to create a new Activator you need to unpack your Oblivion - Meshes.bsa file to have access to the individual files.) Then I add the EnemyFinder script to the object.

At this point I add a copy of it to the world map outside of the Sewers at the beginning of the game. I make that copy a persistent reference named EnemyFinderRef1 (hence the name in the file above).

Now all that must be done is to Activate EnemyFinderRef1. I added a script to an Iron Bow to test it, but you could put it on anything, or you could make the EnemyFinderRef1 run in GameMode instead of on activate and go off every X seconds as you decide. I will include the script I have which is object agnostic (it isn't bow specific) and you can take the code and modify it as you see fit. I've included printouts that aren't perfect but work to the script code. You'll get the first two message boxes (if there are two nearby references) right now since I didn't bother to fix the MessageBox chain. I tried to print the reference values but that failed.

scriptname RangeTest

float timer
short doonce
short player_owned

ref actorfinder
ref myself

Begin OnActivate
  if (IsActionRef player == 1)
    set player_owned to 1
    set actorfinder to enemyfinderref1
    set myself to this
    Activate
  else
    long distance
    ref actor
    set actor to GetActionRef
    set distance to (GetDistance actor)
    MessageBox "I am %.0f distance from %.0f", distance, actor
  endif
End

Begin OnDrop
 
 set player_owned to 0

End

Begin GameMode
  if (player_owned)
    if (doonce == 0)
      set timer to 10
      set doonce to 1
    endif
    if (timer > 0)
      set timer to timer - GetSecondsPassed
      long distance
      short button
      ref actor
      if (timer < 5)
        set EnemyFinderRef1.RefsRequested to 0
      endif
      if (EnemyFinderRef1.ref1full == 1)
        set actor to EnemyFinderRef1.reference1
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 1 %.0f", distance, actor
        set EnemyFinderRef1.ref1full to 0
      endif
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref2full == 1)
        set actor to EnemyFinderRef1.reference2
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 2 %.0f", distance, actor
        set EnemyFinderRef1.ref2full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref3full == 1)
        set actor to EnemyFinderRef1.reference3
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 3 %.0f", distance, actor
        set EnemyFinderRef1.ref3full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref4full == 1)
        set actor to EnemyFinderRef1.reference4
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 4 %.0f", distance, actor
        set EnemyFinderRef1.ref4full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref5full == 1)
        set actor to EnemyFinderRef1.reference5
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 5 %.0f", distance, actor
        set EnemyFinderRef1.ref5full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref6full == 1)
        set actor to EnemyFinderRef1.reference6
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 6 %.0f", distance, actor
        set EnemyFinderRef1.ref6full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref7full == 1)
        set actor to EnemyFinderRef1.reference7
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 7 %.0f", distance, actor
        set EnemyFinderRef1.ref7full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref8full == 1)
        set actor to EnemyFinderRef1.reference8
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 8 %.0f", distance, actor
        set EnemyFinderRef1.ref8full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref9full == 1)
        set actor to EnemyFinderRef1.reference9
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 9 %.0f", distance, actor
        set EnemyFinderRef1.ref9full to 0
      endif
      set button to -2
      set button to getbuttonpressed
      if (button > -1 && EnemyFinderRef1.ref10full == 1)
        set actor to EnemyFinderRef1.reference10
        set distance to (GetDistance actor)
        MessageBox "I am %.0f distance from Reference 10 %.0f", distance, actor
        set EnemyFinderRef1.ref10full to 0
      endif
    else            
      Message "Looking for Actor Range", 1
      actorfinder.Activate  myself 1
      set timer to 10
    endif
  endif

End

Clearly you could make your timeout value a global or set it to something different based on the situation. Also you want to pull the references out from your script as soon as possible so that you can make sure you don't miss the one you want due to a one not being able to report in time because the registers are full.

While having this go off every ten seconds had no appreciable effect on frame rate, having it go off on activate allows you to use it from all kinds of scripts and on command rather than having to wait for it to go off on it's own. For instance. Assume you are scripting a quest with several NPCs and they are preparing to attack all the other people in the area. You could activate the EnemyFinderRef1, identify the references that aren't your party and then have the NPCs start combat with those references, effectively picking targets at random and starting to attack. By leaving it on activate you give yourself extra flexibility.

I hope this is helpful to someone and that you haven't all figured this out already or I'll feel dumb for having spent a few late nights working on it.

See Also[edit | edit source]

Dynamic Storage - may be useful in keeping track of the list of actors