User Tools

Site Tools


scripting:samples:teamcombatsubgame

This script sets up a team CTF game. It assumes we've got vehicles 6 and 7 set up to be used by each team, and a script zones 6 and 7 added to the map as the spawn points.

First function is called when the player joins the game:

function	CTFSignup()
{
	$team = TeamAutoSelect()

	if ( $team == 1 )
	{
		*setvehicle %PLAYER% 6
		*respawninscriptzone %PLAYER% 6
	}
	else
	{
		*setvehicle %PLAYER% 7
		*respawninscriptzone %PLAYER% 7
	}
	
}

Next function sets the flag base and capture destinations to specific buildings (buildings 132 and 138 have already been added to the map) and sets the spawn zone for each team.

function	CTFServerStart()
{
	*flagsetbase 1 138 1
	*flagsetcapturedest 1 132
	*flagsetbase 2 132 2
	*flagsetcapturedest 2 138

	*setteamrespawnscriptzone 1 6
	*setteamrespawnscriptzone 2 7

        // Activate the subgame scoreboard
	SubgameActivateScoreboard( 0, 0 )
}

For each player in the subgame, we add a weapon to the player and start a timer:

function	CTFStart()
{
        *bonusweapon %PLAYER% 11 1000
	*onscreentimer %PLAYER%,0,180
}

Events track the flag captures and add a special effect when the player captures a flag:

Event( "FlagCapture", "1" )
{
	SubgameIncrementScore( $kBongochimpSubgameID, 1 )
	*uieffect %PLAYER% 1
}

Event( "FlagCapture", "2" )
{
	SubgameIncrementScore( $kBongochimpSubgameID, 0 )
	*uieffect %PLAYER% 1
}

Finally, when the timer expires, we check the scores and announce winners:

function	BongochimpShowTeamScoreResults()
{
     $subgameID = 0
	$team1Score = SubgameGetScore( $subgameID, 0 )
	$team2Score = SubgameGetScore( $subgameID, 1 )
	
	if ( $team1Score > $team2Score )
	{
		SubgameMessageAll( $subgameID, "Team 1 victorious!", 1 )
		SubgameEventTeam( $subgameID, 1, "TeamPrizeWin", "" )
		*say Team 1 defeated Team 2 : $team1Score - $team2Score
	}
	else if ( $team2Score > $team1Score )
	{
		SubgameMessageAll( $subgameID, "Team 2 victorious!", 1 )
		SubgameEventTeam( $subgameID, 2, "TeamPrizeWin", "" )
		*say Team 2 defeated Team 1 : $team2Score - $team1Score
	}
	else  /// scores are equal
	{
	    SubgameMessageAll( $subgameID, "Match tied!", 1 )
		*say Team game tied : $team1Score - $team2Score
	}
}
scripting/samples/teamcombatsubgame.txt · Last modified: 2020/02/12 17:07 by mit

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki