Damascus
Senior Member
Posts: 646
Threads: 118
Joined: Mar 2012
Reputation:
29
|
Timer not stopping
void OnStart() { for (int i = 0; i < 14; i++) { AddEntityCollideCallback("Player", "ShadowArea_"+i, "ShadowDamage", true, 0); } }
void ShadowDamage(string &in asParent, string &in asChild, int alState) { if (alState == 1) { AddTimer("damage", 2.0f, "TimerDamage"); } else if (alState == -1) { RemoveTimer("damage"); } }
void TimerDamage(string &in asTimer) { GivePlayerDamage(20, "BloodSplat", true, true); PlayGuiSound("attack_claw_hit.snt", 0.5f); AddTimer("damage", RandFloat(5.0f, 7.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?
|
|
01-01-2013, 04:43 PM |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
RE: Timer not stopping
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
Trying is the first step to success.
|
|
01-01-2013, 04:58 PM |
|
TheGreatCthulhu
Member
Posts: 213
Threads: 10
Joined: Oct 2010
Reputation:
32
|
RE: Timer not stopping
(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:
// 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 = 0; i < 14; i++) { AddEntityCollideCallback("Player", "ShadowArea_"+i, "ShadowDamage", true, 0); } }
void ShadowDamage(string &in asParent, string &in asChild, int 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", true, true); PlayGuiSound("attack_claw_hit.snt", 0.5f); AddTimer("damage", RandFloat(5.0f, 7.0f), "TimerDamage"); } }
|
|
01-01-2013, 08:10 PM |
|
Damascus
Senior Member
Posts: 646
Threads: 118
Joined: Mar 2012
Reputation:
29
|
RE: Timer not stopping
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.
|
|
01-01-2013, 08:53 PM |
|
TheGreatCthulhu
Member
Posts: 213
Threads: 10
Joined: Oct 2010
Reputation:
32
|
RE: Timer not stopping
Oh, I missed that! Good.
|
|
01-01-2013, 09:11 PM |
|
|