PDA

View Full Version : Some questions about Allies and Axis



Loveboy
14th June 2013, 06:46
Hi Guys, i want to make a zombie server.
I have got some questions:

How i can check that there is only one player on my server / on team axis? ( In Script )
How i can make that the axis will be allies switched? / and the allies to axis? ( In script )

If you can help me, please then write as coment. Thank you!

kung foo man
14th June 2013, 08:45
1)




getDeadPlayers()
{
players = getentarray("player", "classname");
tmp = [];
for (i=0; i<players.size; i++)
{
if (players[i].pers["team"] == "axis" || players[i].pers["team"] == "allies")
if (players[i].sessionstate != "playing")
tmp[tmp.size] = players[i];
}
return tmp;
}



// in your function you write:

if (getDeadPlayers().size == 1)
iprintlnbold("only one zombie roaming!");


2)

When a player dies, DON'T respawn any player. The respawn-logic needs to be handled by a gametype-thread, which is an endless loop.

The loop is like:



getAliveHunters()
{
players = getentarray("player", "classname");
tmp = [];
for (i=0; i<players.size; i++)
{
if (players[i].pers["team"] == "allies")
if (players[i].sessionstate == "playing")
tmp[tmp.size] = players[i];
}
return tmp;
}

while (1)
{
wait 0.05;
if (getAliveHunters().size == 0)
{
iprintlnbold("all hunters died, round restart... or server is just empty ;D");

newZombie = level.lastKilled; // set that always in playerkilled-callback
// iterate over player now and respawn them as axis or allies... work for you!

}

}


You can also set game["state"] == "roundrestart" etc. to handle new connected players e.g., but I just want you to understand the basic idea. Now you should be able to work the rest out.

Tally
14th June 2013, 10:41
Hi Guys, i want to make a zombie server.
I have got some questions:

How i can check that there is only one player on my server / on team axis? ( In Script )
How i can make that the axis will be allies switched? / and the allies to axis? ( In script )

If you can help me, please then write as coment. Thank you!

When you say you want allies to become axis, and axis to become allies, do you mean you want the players to switch teams? Or do you mean you want attackers to become defenders, and defenders to become attackers?

One is a team change;
the other other is a role change.

You need to tell us clearly what you want. You can't do both, because you will end up undoing what you set out to do: if defenders change team, and the new team they switch to are the attackers, you just made them attackers all over again. Which is kind of pointless.

kung foo man
14th June 2013, 12:16
It's a team switch on death (typical zombie mod)

Tally
14th June 2013, 12:55
This is a general method to swap players to a new team:


swapTeams()
{
level endon( "gameover" );

players = getentarray( "player", "classname" );
for( i = 0; i < players.size; i++ )
{
// don't do anything with spectators
if( !isDefined( players[i].pers["team"] ) || players[i].pers["team"] == "spectator" ) continue;

newTeam = undefined;

if( players[i].pers["team"] == "axis" )
newTeam = "allies";
else if( players[i].pers["team"] == "allies" )
newTeam = "axis";

players[i].pers["team"] = newTeam;
players[i].pers["savedmodel"] = undefined;
players[i] thread clearWeapons();

if( newTeam == "allies" )
player thread switchteams( "allies" );
else
player thread switchteams( "axis" );

}

tempscore = game["alliedscore"];
game["alliedscore"] = game["axisscore"];
game["axisscore"] = tempscore;
setTeamScore( "allies", game["alliedscore"] );
setTeamScore( "axis", game["axisscore"] );
}

switchteams( Team )
{
if( self.sessionstate != "dead" )
{
self.switching_teams = true;
self.joining_team = Team;
self.leaving_team = self.pers["team"];
self suicide();
}

self.pers["team"] = Team;
self.team = Team;
self.pers["teamTime"] = undefined;
self.sessionteam = self.pers["team"];

// update spectator permissions immediately on change of team
self maps\mp\gametypes\_spectating::setSpectatePermissi ons();

self notify( "end_respawn" );

}

clearWeapons()
{
self endon("disconnect");

// clear standard weapons
self.pers["weapon"] = undefined;
self.pers["weapon1"] = undefined;
self.pers["weapon2"] = undefined;
self.pers["spawnweapon"] = undefined;

// clear saved roundbased weapons
if( isDefined( game[self.name] ) )
{
if( isDefined( game[self.name]["weapon1"] ) )
game[self.name]["weapon1"] = undefined;
if( isDefined( game[self.name]["weapon2"] ) )
game[self.name]["weapon2"] = undefined;
}
}


It can be easily modified if you know who the player is, because you wont have to search all players. Just pass the known player through the method, and that will switch them to a new team.