Frictional Games Forum (read-only)
Timer not stopping - 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: Timer not stopping (/thread-19762.html)



Timer not stopping - Damascus - 01-01-2013

PHP Code:
void OnStart()
{
    for (
int i 014i++)
    {
        
AddEntityCollideCallback("Player""ShadowArea_"+i"ShadowDamage"true0);
    }
}

void ShadowDamage(string &in asParentstring &in asChildint alState)
{
    if (
alState == 1)
    {
        
AddTimer("damage"2.0f"TimerDamage");
    }
    else if (
alState == -1)
    {
        
RemoveTimer("damage");
    }
}

void TimerDamage(string &in asTimer)
{
    
GivePlayerDamage(20"BloodSplat"truetrue);
    
PlayGuiSound("attack_claw_hit.snt"0.5f);
    
AddTimer("damage"RandFloat(5.0f7.0f), "TimerDamage");


I'm trying to make an area that damages you ever 5-7 seconds while you're inside, but stops damaging you when you leave it. However, even after I leave the area, I keep getting damaged over and over. Am I missing something here?


RE: Timer not stopping - FlawlessHappiness - 01-01-2013

You can make the whole timer activate if a variable is 1
Then set it to 0 to make the timer not call


Timers that call themselves can be tricky


RE: Timer not stopping - TheGreatCthulhu - 01-01-2013

(01-01-2013, 04:43 PM)Damascus Wrote: I'm trying to make an area that damages you ever 5-7 seconds while you're inside, but stops damaging you when you leave it. However, even after I leave the area, I keep getting damaged over and over. Am I missing something here?

You could try something like this - of the top of my head:
PHP Code:
// NOTE: I'll use
      // <----------------
// to mark the important points.
// This assumes that the damage areas don't overlap.


// Add a bool variable here to use as an indicator
bool isInsideDamageArea false;    // <---------------

void OnStart()
{
    for (
int i 014i++)
    {
        
AddEntityCollideCallback("Player""ShadowArea_"+i"ShadowDamage"true0);
    }
}

void ShadowDamage(string &in asParentstring &in asChildint alState)
{
    
// Set isInsideDamageArea:
    // will be true if state == 1 (on enter area event),
    // otherwise false.
    
isInsideDamageArea = (state == 1);   // <-----------------    

    
if (alState == 1)
    {
        
AddTimer("damage"2.0f"TimerDamage");
    }
    else if (
alState == -1)
    {
        
RemoveTimer("damage");
    }
}

void TimerDamage(string &in asTimer)
{
    
// Wrap everything inside an if-statement:

    
if(isInsideDamageArea)    // <---------------
    
{
        
GivePlayerDamage(20"BloodSplat"truetrue);
        
PlayGuiSound("attack_claw_hit.snt"0.5f);
        
AddTimer("damage"RandFloat(5.0f7.0f), "TimerDamage");
    }




RE: Timer not stopping - Damascus - 01-01-2013

I figured out what my (stupid) mistake was.

AddEntityCollideCallback("Player", "ShadowArea_"+i, "ShadowDamage", true, 0);

This had to be false, cause the callback is autoremoved otherwise.


RE: Timer not stopping - TheGreatCthulhu - 01-01-2013

Oh, I missed that! Big Grin Good.