Frictional Games Forum (read-only)
How to make things happen only in a certain area - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: How to make things happen only in a certain area (/thread-30120.html)



How to make things happen only in a certain area - MrWallas - 06-15-2015

I'm using a script based off of Wapez's Custom Ambient Map Scares script. But one thing about the script that I'm finding is that the random things continue to happen even when you're outside of the area.

I have one area where I want there to be random breath sounds coming from the player but I want it to ONLY happen in that particular area, and stop outside of the area, but then start back up when you enter the area again.

Is there any way I can do that?

Here's the code, which works as it is right now, but it doesn't do exactly what I want it to do.
Code:
void OnStart()
{
float RandomBreathSoundsTimerNumber = RandFloat( 2.0f, 15.0f );
AddTimer("bs_soundstimer_first", RandomBreathSoundsTimerNumber, "RandomBreathSounds");
AddEntityCollideCallback("Player", "SlowMoveArea", "ChangeCAMSState", false, 1);
}

void RandomBreathSounds(string &in asTimer)
{
    if(GetLocalVarString("CAMS_State") == "SlowMoveArea"){
        SetLocalVarInt("BS_AreaNumber", RandInt( 1, 4 ));
        AddDebugMessage("Playing sounds in SlowMoveArea", false);
    }
    
    int SS_CountNumber = RandInt( 1, 3 );
    
    if( SS_CountNumber == 1 ) PlayGuiSound("react_breath.snt", 1.0f);
    if( SS_CountNumber == 2 ) PlayGuiSound("react_sigh.snt", 1.0f);
    if( SS_CountNumber == 3 ) PlayGuiSound("react_breath_slow.snt", 1.0f);
    
    AddDebugMessage("Played sound at SlowMoveArea", false);
    
    float RandomBreathSoundsTimerNumber = RandFloat( 2.0f, 15.0f );
    
    AddTimer("bs_soundstimer", RandomBreathSoundsTimerNumber, "RandomBreathSounds");
    
}



RE: How to make things happen only in a certain area - Artsy - 06-15-2015

Just put the contents of the timer in a collision callback...?


RE: How to make things happen only in a certain area - DnALANGE - 06-15-2015

Try this :

PHP Code:
        void ChangeCAMSState(string &in asEntityint alState
{
if(
alState == 1)
{
// THIS is where you are IN the specific area.
}

if(
alState == -1)
{
// THIS is where you are OUT the specific area.
}




RE: How to make things happen only in a certain area - Darkfire - 06-15-2015

That's why I don't paste code which I can't understand.
Try replacing PlayGuiSound function with PlaySoundAtEntity and use the area you want as the entity. Seems you're not too experienced, so make sure to check these functions in the engine scripts site.


RE: How to make things happen only in a certain area - FlawlessHappiness - 06-15-2015

To me, the idea is to have an area that starts a repeating timer, and stops a repeating timer.

void CollideCallback(string &in asParent, string &in asChild, int alState)
{
if(alState == 1) //If going inside area.
{
if(GetTimerTimeLeft("Breath") > 0)
else
{
AddTimer("Breath", 1.0f, "BreathTimer");
}
SetLocalVarInt("BreathTimerVar", 1);
}

if(alState == -1) //If going outside of area
{
SetLocalVarInt("BreathTimerVar", 0);
}
}

void BreathTimer(string &in asTimer)
{
if(GetLocalVarInt("BreathTimerVar") == 1)
{
//PlaySound
AddTimer("Breath", 1.0f, "BreathTimer");
}
}


RE: How to make things happen only in a certain area - MrWallas - 06-15-2015

(06-15-2015, 10:49 AM)Darkfire Wrote: That's why I don't paste code which I can't understand.
Try replacing PlayGuiSound function with PlaySoundAtEntity and use the area you want as the entity. Seems you're not too experienced, so make sure to check these functions in the engine scripts site.

Yeah, you're right, I'm not too experienced, but I'm capable of learning, I learned how that code, in and of itself, works. I appreciate the suggestion but I really don't appreciate the snarky attitude you seem to be giving me.


RE: How to make things happen only in a certain area - Mudbill - 06-15-2015

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