Script help :: 3 of 4 flags needed to win game


(Ifurita) #1

In my map, a team has to capture 3 out of 4 flags to win. I’m using checkpoint flags with the functions axis_capture and allied_capture 1) showing the flag in the map, 2) changing the command map marker to show the state of the map, 3) assessing gamepoints and 4) adjusting gamepoints if this was the first capture for a flag. Here is the script - I used the same logic as in Steelrat’s forward spawn prefab.


checkpoint01
{
   	spawn 
   	{ 
      		wait 200 
      		accum 0 set 2         // Who owns flag: 0-Axis, 1-Allied 
      		accum 2 set 0         // Axis have not captures flag once yet 
      		accum 3 set 0         // Allies have not captured flag once yet 
   	} 

   	trigger axis_capture            // Touched by an Axis player 
   	{ 
      		accum 0 abort_if_equal 0       // do Axis own flag? 
      		accum 0 set 0             // Axis own the flag 
      		wm_announce "Axis have captured the Cafe. Axis get 1 point" // the get one point is just a visual reminder to check if the script is working

	                     remapshader "gfx/breakout/flag1neutral" "gfx/breakout/flag1axis"
	                     remapshader "gfx/breakout/flag1allied" "gfx/breakout/flag1axis"
		remapshaderflush 

		globalaccum 1 inc -1 //allies lose a point
		globalaccum 2 inc 1 //axis gain a point
		trigger game_manager axis_checkgame

      		accum 3 abort_if_equal 1         //Abort if Allies have captured flag once 
      		accum 2 abort_if_equal 1         //Abort if Axis have captured flag once 
      		accum 2 set 1               //Axis have captured at least once 
		globalaccum 1 inc 1 //if the allies have not captured the flag before, their accum gains one, effectively resetting the net loss to 0
      		wm_announce "allied accum reset by 1"
   	} 

   	trigger allied_capture            // Touched by an allied player 
   	{ 
      		accum 0 abort_if_equal 1       // do Allies own flag? 
     		accum 0 set 1             // Allies own the flag 
      		wm_announce "Allies capture the Cafe.  Allies get 1 point" 

		remapshader "gfx/breakout/flag1neutral" "gfx/breakout/flag1allied"
		remapshader "gfx/breakout/flag1axis" "gfx/breakout/flag1allied"
		remapshaderflush

		globalaccum 1 inc 1
		globalaccum 2 inc -1
		trigger game_manager allied_checkgame

		accum 3 abort_if_equal 1 //Abort if Allies have captured flag once
      		accum 2 abort_if_equal 1 //Abort if Axis have captured flag once 
      		accum 3 set 1            //Allies have captured flag at least once
		globalaccum 2 inc 1 
      		wm_announce "axis accum reset by 1"
   	} 
}

It seems that if the axis run thru and touch 2 of the flags and then the allies run thru and touch 3 flags, something isn’t registering accum values or something, the allies are not winning the game when they should. :frowning:


(nUllSkillZ) #2

You could insert


// prints out the value of  accum 'accumNumber'
printaccum   <accumNumber>

and


// prints out the value of global accum 'globalaccumnumber'
printglobalaccum   <globalaccumnumber>

at suitable places and then run the map in script debug mode (not sure how to set this anymore).
Then the accum’s and globalaccum’s are printed to the log file.

Edit:

I’ve found the console command:


/g_scriptdebug (default 0)


(]UBC[ McNite) #3

I remember I read somewhere that globalaccums are no nice thing to use… anyway I don’t hink you need them.
Maybe this is an approach: Set up a scriptblock for the checking on the points like this

points
{
             spawn
             {
                         wait 200
                         accum 0 set 0 // axis points
                         accum 1 set 0 // allies points
             }

             trigger axispoint_inc // increases axis points after a flag-win
            {
                         accum 0 inc 1
                         wm_announce "accum 0 increased by 1" //announce to see ingame which part of the script got executed
                         accum 0 abort_if_not_equal 3 //checks whether axis got enough flags
                         trigger game_manager axis_wins //ends the game cuz axis got 3 flags
             }

             trigger alliespoint_dec // decreases allies points after axis got a flag back
            {
                         accum 1 abort_if_equal 0 //shouldn't be necessary cuz of the check whether allies had the flag before in axiscapture
                         accum 1 inc -1
             }
}

You need alliespoint_inc and axispoint_dec too, i also didn’t bother about messages for this.
The wm_announce should be disabled when the script works but is cool for testing, because you just know what is going on. And you especially know what is NOT going on when it should :smiley: I put them in a lot of placed in my scripts. That way there is no need for debug-things… you simply get a message when a relevant part of the script got executed.

In the flagscripts there should be blocks like this:

checkpoint01
{
             spawn
             {
                         wait 200
                         accum 0 set 0 // axis doesnt have the flag
                         accum 1 set 0 // allies don't have the flag
             }

             trigger axis_capture
             {
                         accum 0 abort_if_equal 1//axis got the flag already
                         accum 0 set 1 // axis got the flag
                         trigger points axispoint_inc // triggers the count +1 in the points-script
                         accum 1 abort_if_equal 0 //allies don't have the flag
                         accum 1 set 0 // allies loose the flag
                         trigger points alliespoint_dec //triggers the count -1 in the points-script
             }

             trigger allies_capture
             {
                         (same as above just the other way round)
             }
}

Its just an idea, maybe it works… let me know when it does :smiley:


(nUllSkillZ) #4

The “points”-scriptblock won’t work.
Because it has to be related to an entity.
But this part could all be done in the “game_manager”-scriptblock.


(Ifurita) #5

I’m using globalaccums because there is an objective worth 2 points. so it inc 2, unless you can execute an accum increase/game check scrip twice in one scriptblock


(]UBC[ McNite) #6

well… if you want to increase by 2 you can

a) put in the line with “accum X inc 1” twice in a row (very simple but efficient)
b) try “accum X inc 2” (no idea whether this works, its just a guess)

still I don’t see the point of using globals when you can get it done in a script-block in the game_manager.
After a second look at your flag-script I get the impression that using 3 accums for 1 flag is a bit messy too… 2 are sufficient because with 0 and 1 you can depict simply whether one team got the flag or not.


(Ifurita) #7

well, there are 3 possible states when a flag is captured:

  • first time capture (by allies) score should be 1- 0
  • first time capture (by axis) score should be 0 - 1
  • subsequent captures by anyones (score should increase 1 for the capturing team and decrease 1 for the losing team

(]UBC[ McNite) #8

Methinks that you mix the states of the flag (uncaptured, captured by allies, captured by axis) with the score for the teams (getting/loosing a point). This is where the trouble starts imo. What you point out as “possible states” are the possible situations of scoring (not states of flags).
And I think the next step to making it more difficult than necessary is that you give the starting positions (first capture) the rank of a state themselves. Try to look at them as a simple capture.

What I suggest by using another structure is: separate the states of the flags from the scoring of the teams. Put the states of the flags into the flags script, and use a block within the game_manager solely for the scoring. Trigger the scoring by triggers from the flag-script.

I agree that there are 3 possible states of a flag. And I would depict them this way, using only 2 accums in the flag script.

a) uncaptured >> accum 0 is 0, accum 1 is 0 in (the flag-script, at start of map; accum 0 is for axis, accum 1 is for allies)
b) capture by allies >> accum 0 is 0, accum 1 is 1
c) capture by axis >> accum 0 is 1, accum 1 is 0

You set a) uncaptured in the spawn-block:

accum 0 set 0 // axis don’t have it
accum 1 set 0 // allies don’t have it either

For each capture there is (in this example of a capture by axis) for the capturing team:

a check whether the touching team already has the flag: accum 0 abort_if_equal 1//axis got the flag already
change of state for the flag: accum 0 set 1 // axis got the flag
add 1 point for the touching team: trigger points axispoint_inc // triggers the count +1 in the points-script

for the other team there is:

a check whether they had the flag already: accum 1 abort_if_equal 0 //allies don’t have the flag
change of state for the flag: accum 1 set 0 // allies loose the flag
take 1 point of the team that lost the flag: trigger points alliespoint_dec

This way I only need 2 accums for the flag to depict the 3 different states of a flag.

As for the total score I’d choose to use a script in the game_manager:

a) uncaptured >> axis 0 points, allies 0 points (at start of map)
b) capture by allies >> allies +1, axis -1 if they held it already
c) capture by axis >> axis +1, allies -1 if they held it already

The adding or taking of the points is triggered within the flag-script by

trigger points axispoint_inc (adds a point for axis for the capture)
trigger points alliespoint_dec (takes a point of allies for the loss, but only in case they had it before which is checked by:
accum 1 abort_if_equal 0 //allies don’t have the flag


(Mean Mr. Mustard) #9

Sunds like you need some scripting expertise…should I reinstall Radiant? :wink: