globalaccum / dynamite count trouble


(FireFly) #1

In my map allies have to dynamite the maindoor ( like in Radar). If an allie plants the dynamite an alarm goes off, if the dynamite gets defused (by allie or axis), or the maindoor blows the alarm stops.

The entities used are a trigger_objective_info with targetname / scriptname: maindoor1_trig

targeting a func_explosive (the maindoor that needs to be blown) with a targetname / scriptname: maindoor1

and a speaker for the sound with a targetname: maindooralarm

See also this topic: http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&t=7917

here’s the script I was currently using:

maindoor1 
{
	spawn
	{
		accum 2 set 0
		wait 50
		constructible_class	3
		setstate maindoor1 default
	}

	death
	{
		trigger tank doors_destroyed
		trigger game_manager maindoor1_destroyed
		disablespeaker maindooralarm
	}
	
	defused
	{ 
		disablespeaker maindooralarm	
   	}

	
}

maindoor1_trig
{
	spawn
	{
	}

	 dynamited 
   	{ 
		enablespeaker maindooralarm
   	}
		
	
	

}

It basically works, except when there is more than one dynamite planted ( a level 4 engineer with full bar can manage to plant 3 dynamites)

For example if an allie was planting 2 dynamites and only 1 dynamite gets defused by axis the alarm stops. ( obviously if you look at the script above) But what I really wanted was that the alarm only stops after all dyna has been defused.

So I created a sort of dynamite-count :

maindoor1 
{
	spawn
	{
		accum 2 set 0
		wait 50
		constructible_class	3
		setstate maindoor1 default
	}

	death
	{
		trigger tank doors_destroyed
		trigger game_manager maindoor1_destroyed
		disablespeaker maindooralarm
	}
	
	defused
	{ 
      		globalaccum 9 inc -1
		globalaccum 9 abort_if_not_equal 0
		disablespeaker maindooralarm
		
   	}

	
}

maindoor1_trig
{
	spawn
	{
	 }

	 dynamited 
   	{ 
      		globalaccum 9 inc 1
		globalaccum 9 abort_if_equal 0
		enablespeaker maindooralarm
   	}
		
	
	

}

the globalaccum 9 is set to 0, meaning no dynamite is planted

every time one gets planted ( globalaccum 9 inc 1) the globalaccum 9 increases with 1, and when one gets defused it decreases with 1…

so the alarm sound should only stop if the globalaccum 9 is set to 0 again… (globalaccum 9 abort_if_not_equal 0)

well, guess what, it doesn’t work! If 1 or more gets planted the alarm sounds, but after defusing the alarm does not stop…

with /g_scriptdebug 1 and /logfile 1 I got this:

270550 : (maindoor1_trig) GScript event: dynamited
270550 : (maindoor1_trig) GScript command: globalaccum 9 inc 1
270550 : (maindoor1_trig) GScript command: globalaccum 9 abort_if_equal 0
270550 : (maindoor1_trig) GScript command: enablespeaker maindooralarm
Planted at the Main Entrance to the Rocket Base.

280650 : (maindoor1_trig) GScript event: dynamited
280650 : (maindoor1_trig) GScript command: globalaccum 9 inc 1
280650 : (maindoor1_trig) GScript command: globalaccum 9 abort_if_equal 0
280650 : (maindoor1_trig) GScript command: enablespeaker maindooralarm
Planted at the Main Entrance to the Rocket Base.

285750 : (maindoor1) GScript event: defused
285750 : (maindoor1) GScript command: globalaccum 9 inc -1
285750 : (maindoor1) GScript command: globalaccum 9 abort_if_not_equal 0
Defused at the Main Entrance to the Rocket Base.

290850 : (maindoor1) GScript event: defused
290850 : (maindoor1) GScript command: globalaccum 9 inc -1
290850 : (maindoor1) GScript command: globalaccum 9 abort_if_not_equal 0
Defused at the Main Entrance to the Rocket Base.

I’m sure I must be missing something , because for some reason after both dynamite have been defused globalaccum 9 isn’t set to 0 , as it is supposed to do…