Jump to content

How to use a trigger to detect player and other actors ?


Delzaron

Recommended Posts

Posted

Hi

 

I met an interesting problem :

 

Once I activated a trigger, I need to check :

- if player is still inside after an amount of time.

- if this trigger contains a follower.

 

How I can do that, please ? Thanks in advance.

Posted

Handle the two events of the trigger:

 

OnTriggerEnter(ObejctReference akRef)

 

OnTriggerLeave(ObjectReference akRef)

 

 

Add a variable to the script (maybe a property if you need to check from another script):

 

bool isPlayerInside

 

 

in OnEnter, check if the akRef is PlayerRef, if yes then set the boolean to true, and start a quick OnUpdate, e.g. RegisterForSingleUpdate(10.0)

 

In the OnUpdate, check the boolean for the player is still true, and increment the seconds, and re-register.

 

When the player leaves, put the boolean to false, and resent the conuter, and stop for Updates.

 

Example:

 

Scriptname myTrigger extends Activator
 
Actor Property PlayerRef Auto
bool Property isPlayerIn Auto
bool Property hasBeenInFor2mins Auto
int numSeconds
 
Event OnTriggerEnter(ObjectReference akRef)
  if akRef==PlayerRef && !isPlayerIn
    isPlayerIn = true
    hasBeenInFor2mins = false
    numSeconds = 0
    RegisterForSingleUpdate(10)
  endIf
endEvent
 
Event OnTriggerLeave(ObjectReference akRef)
  if akRef==PlayerRef && isPLayerIn
    isPlayerIn = false
    hasBeenInFor2mins = false
    numSeconds = 0
    UnregisterForUpdates()
  endIf
endEvent
 
Event onUpdate()
  numSeconds+=10
  hasBeenInFor2mins = (numSeconds>120)
  if isPLayerIn
    RegisterForSingleUpdate(10)
  endIf
endEvent
 
Posted

That's a very complex script...

 

So, how I can trigger a function ?

For example, if player is still in the trigger, something will happen... like death, skeever rape, etc... ?

 

How I can checl if a follower is present in that trigger too ?

Posted

For followers, you can convert akRef to actor, and then check .isPlayerTeamMate()

 

 

To trigger actions is just scripting.

If you have a function in one of your Quests, then just put a reference to the Quest (a property) and then call the function you like.

Posted

For followers, you can convert akRef to actor, and then check .isPlayerTeamMate()

 

 

To trigger actions is just scripting.

If you have a function in one of your Quests, then just put a reference to the Quest (a property) and then call the function you like.

 

You're a god ! I never thought about using booleans...

 

I will try your solution soon as possible ! Thanks !

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...