Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make things happen only in a certain area
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#7
RE: How to make things happen only in a certain area

I'd say there are two common ways to trigger an event only while in an area. One is to activate it when you enter, then deactivate it when you leave. The other is to run it, but always check if the player is in the area before doing it. The latter is more robust, but there's (as far as I know) no super easy way of checking player collision. You might be able to if you tinker with more than one function though. GetEntitiesCollide does not support Player.

Here's an example using the activation method (which is much like what has already been suggested):

PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("Player""SlowMoveArea""ChangeCAMSState"false0); 
    
//Notice I put 0 in the end. This enables both enter and exit events.
}

void ChangeCAMSState(string &in asParentstring &in asChildint alState)
{
    if(
alState == 1) {
        
//This will activate once, when you enter the area. 
        //If you need it to keep happening, add a looping timer here. Like so:
        
TimerLoop("");
    }
    else if(
alState == -1) {
        
//This runs when you leave the area. 
        //If you have a looping timer, use RemoveTimer(); here.
    
}
}

void TimerLoop(string &in asTimer)
{
    
//Do whatever you want here.
    
AddTimer("timerloop"1.0f"TimerLoop"); //This adds itself everytime, effectively looping. 
    //The first argument is the internal name you need in order to remove the timer.
    //The 1.0f is the tickrate of the loop. If you need your actions to happen often, use a low value.
    //Find the balance you need for your event.


(This post was last modified: 06-15-2015, 02:41 PM by Mudbill.)
06-15-2015, 02:34 PM
Find


Messages In This Thread
RE: How to make things happen only in a certain area - by Mudbill - 06-15-2015, 02:34 PM



Users browsing this thread: 1 Guest(s)