Here is an updated method:
PHP Code:
Callback_StartGameType()
{
------------- snip ----------------
thread startGame();
thread updateGametypeCvars();
thread updateAllPlayers();
thread kickRandomBot();
}
updateAllPlayers()
{
if( !isDefined( level.playerDvars ) )
level.playerDvars = [];
if( !isDefined( level.playerDvarValues ) )
level.playerDvarValues = [];
for( ;; )
{
level waittill( "connected", player );
dvar = "player_" + player getEntityNumber();
name = player.name;
level.playerDvars[level.playerDvars.size] = dvar;
level.playerDvarValues[level.playerDvarValues.size] = name;
player thread setDvarsOnPlayers( level.playerDvars, level.playerDvarValues );
}
}
setDvarsOnPlayers( dvarArray, nameArray )
{
for( i=0; i < dvarArray.size; i++ )
{
self setClientCvar( dvarArray[i], nameArray[i] );
println( "^1------------ DVARS AND NAMES ------------" );
println( dvarArray[i] );
println( nameArray[i] );
println( "^1----------------------------------------" );
}
}
updateDvarsOnPlayers( dvarArray, nameArray )
{
players = getEntArray( "player", "classname" );
for( i=0; i < players.size; i++ )
{
for( j=0; j < dvarArray.size; j++ )
{
players[i] setClientCvar( dvarArray[j], nameArray[j] );
println( "^1------------ DVARS AND NAMES ------------" );
println( dvarArray[j] );
println( nameArray[j] );
println( "^1----------------------------------------" );
}
}
}
remove_from_array( array, element )
{
if( !isdefined( element ) )
return( array );
newarray = [];
for( i = 0; i < array.size; i++ )
{
if( array[ i ] == element )
continue;
newarray[ newarray.size ] = array[ i ];
}
return( newarray );
}
kickRandomBot()
{
AllBots = [];
for( ;; )
{
wait( 30 );
players = getEntArray( "player", "classname" );
for( i=0; i < players.size; i++ )
{
if( !demon\_bots::IsBot( players[i] ) )
continue;
AllBots[AllBots.size] = players[i];
}
break;
}
candidate = AllBots[ randomInt( AllBots.size ) ];
Kick( candidate getEntityNumber() );
}
Callback_PlayerDisconnect()
{
if(!level.splitscreen)
iprintln(&"MP_DISCONNECTED", self);
level.playerDvars = remove_from_array( level.playerDvars, "player_" + self getEntityNumber() );
level.playerDvarValues = remove_from_array( level.playerDvarValues, self.name );
self thread updateDvarsOnPlayers( level.playerDvars, level.playerDvarValues );
if(isdefined(self.pers["team"]))
{
if(self.pers["team"] == "allies")
setplayerteamrank(self, 0, 0);
else if(self.pers["team"] == "axis")
setplayerteamrank(self, 1, 0);
else if(self.pers["team"] == "spectator")
setplayerteamrank(self, 2, 0);
}
lpselfnum = self getEntityNumber();
lpGuid = self getGuid();
logPrint("Q;" + lpGuid + ";" + lpselfnum + ";" + self.name + "\n");
}
This method:
1. builds an array for each player dvar derived from "player_" + the player's entity number.
2. builds an array for each player's name
3. Updates all players as they connect, and cycles through both player dvar and player name from the arrays
4. Removes the player's data from both player dvar array and player name array when they disconnect.
In the code above you will see a method to randomly kick a bot after 30 seconds. I did this for testing purposes because I wanted to use println() and record someone leaving and getting their data removed from the arrays from the player disconnect method. Obviously, it would have been ideal to have been able to run a dedicated server and leave myself, as the println() would print out the updated arrays, but I couldn't do this as you cannot run a dedicated server in developer mode. And I couldn't do it on a local server and leave myself as the println() would not have time to print before the server shut down. Hence the need to do it on a bot.
Here is the console log file showing the arrays updated when the bot left (it was bot 1 that got kicked). You will see that everyone got the Cvars updated minus the removed bot:
Code:
execing custombuttons.cfg
PunkBuster Client: PnkBstrA successfully loaded PnkBstrB
SV_DirectConnect()
Connecting player #1 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 1 guid 0)
SV_SendClientGameState() for bot0
Going from CS_CONNECTED to CS_PRIMED for bot0
Sending 16566 bytes in gamestate to client: 1
Going from CS_PRIMED to CS_ACTIVE for bot0
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
PunkBuster Client: PnkBstrB service installed and started successfully
dvar set scr_demon_hardcore 0
dvar set ui_axis_medic_total 1
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 1
SV_DirectConnect()
Connecting player #2 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 2 guid 0)
SV_SendClientGameState() for bot1
Going from CS_CONNECTED to CS_PRIMED for bot1
Sending 16566 bytes in gamestate to client: 2
Going from CS_PRIMED to CS_ACTIVE for bot1
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_allies_officer_total 0
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #3 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 3 guid 0)
SV_SendClientGameState() for bot2
Going from CS_CONNECTED to CS_PRIMED for bot2
Sending 16566 bytes in gamestate to client: 3
Going from CS_PRIMED to CS_ACTIVE for bot2
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_axis_assault_total 4
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #4 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 4 guid 0)
SV_SendClientGameState() for bot3
Going from CS_CONNECTED to CS_PRIMED for bot3
Sending 16566 bytes in gamestate to client: 4
Going from CS_PRIMED to CS_ACTIVE for bot3
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_axis_engineer_total 4
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #5 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 5 guid 0)
SV_SendClientGameState() for bot4
Going from CS_CONNECTED to CS_PRIMED for bot4
Sending 16566 bytes in gamestate to client: 5
Going from CS_PRIMED to CS_ACTIVE for bot4
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_allies_officer_total 0
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #6 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 6 guid 0)
SV_SendClientGameState() for bot5
Going from CS_CONNECTED to CS_PRIMED for bot5
Sending 16566 bytes in gamestate to client: 6
Going from CS_PRIMED to CS_ACTIVE for bot5
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_axis_engineer_total 3
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #7 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 7 guid 0)
SV_SendClientGameState() for bot6
Going from CS_CONNECTED to CS_PRIMED for bot6
Sending 16566 bytes in gamestate to client: 7
Going from CS_PRIMED to CS_ACTIVE for bot6
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_allies_sniper_total 1
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
Giving bot6 a 999 ping - !count:
SV_DirectConnect()
Connecting player #8 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 8 guid 0)
SV_SendClientGameState() for bot7
Going from CS_CONNECTED to CS_PRIMED for bot7
Sending 16566 bytes in gamestate to client: 8
Going from CS_PRIMED to CS_ACTIVE for bot7
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_allies_assault_total 3
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
SV_DirectConnect()
Connecting player #9 has a zero GUID
Going from CS_FREE to CS_CONNECTED for (num 9 guid 0)
SV_SendClientGameState() for bot8
Going from CS_CONNECTED to CS_PRIMED for bot8
Sending 16566 bytes in gamestate to client: 9
Going from CS_PRIMED to CS_ACTIVE for bot8
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_2
bot1
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
dvar set scr_demon_hardcore 0
dvar set ui_axis_engineer_total 2
dvar set ui_allow_allies_assault 1
dvar set ui_allow_allies_engineer 1
dvar set ui_allow_allies_gunner 1
dvar set ui_allow_allies_sniper 1
dvar set ui_allow_allies_medic 1
dvar set ui_allow_allies_officer 0
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
------------ DVARS AND NAMES ------------
player_0
Tally
----------------------------------------
------------ DVARS AND NAMES ------------
player_1
bot0
----------------------------------------
------------ DVARS AND NAMES ------------
player_3
bot2
----------------------------------------
------------ DVARS AND NAMES ------------
player_4
bot3
----------------------------------------
------------ DVARS AND NAMES ------------
player_5
bot4
----------------------------------------
------------ DVARS AND NAMES ------------
player_6
bot5
----------------------------------------
------------ DVARS AND NAMES ------------
player_7
bot6
----------------------------------------
------------ DVARS AND NAMES ------------
player_8
bot7
----------------------------------------
------------ DVARS AND NAMES ------------
player_9
bot8
----------------------------------------
Going to CS_ZOMBIE for bot1
7:bot1 EXE_PLAYERKICKED
]\quit
quitting...
----- CL_Shutdown -----
dvar set sv_disableClientConsole 0
writing to: C:\Program Files (x86)\Activision\Call of Duty 2\servercache.dat
-----------------------
----- Server Shutdown -----
==== ShutdownGame ====
Going to CS_ZOMBIE for Tally
0:Tally EXE_DISCONNECTED
Going to CS_ZOMBIE for bot0
1:bot0 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot1
2:bot1 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot2
3:bot2 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot3
4:bot3 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot4
5:bot4 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot5
6:bot5 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot7
8:bot7 EXE_DISCONNECTED
Going to CS_ZOMBIE for bot8
9:bot8 EXE_DISCONNECTED
dvar set sv_running 0
---------------------------