Hello, sorry for my bad english

In a while ago I found a way of how to block player respawn. It can be done by using a CS_SwitchTeam function on a spectator. To give player ability to respawn back CS_RespawnPlayer is only needed. I wrote a little test code that will block respawn when client is just joined a team and will spawn him on next round:
PHP Code:
new player_team[MAXPLAYERS + 1];
new bool:need_respawn[MAXPLAYERS + 1];
new just_swaped[MAXPLAYERS + 1];
public OnPluginStart()
{
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Post);
HookEvent("round_start", Event_NewRound, EventHookMode_Post);
}
public Action:Event_PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// player_team will fire three times in a row and we must ignor two of them
if (just_swaped[client] < 2)
{
just_swaped[client]++;
return Plugin_Continue;
}
new team = GetEventInt(event, "team");
if (client == 0 || team == 1 || IsFakeClient(client) || !IsClientInGame(client))
{
return Plugin_Continue;
}
PrintToChatAll("Step 1!");
player_team[client] = team;
// We dont wanna get a server crash so timer is needed before team change
CreateTimer(0.01, EnforceTeamSpec, any:client);
return Plugin_Continue;
}
public Action:EnforceTeamSpec(Handle:timer, any:client)
{
if (!IsClientInGame(client))
{
return;
}
PrintToChatAll("Step 2!");
just_swaped[client] = 0;
// Move player to spectators for a milisecond
ChangeClientTeam(client, 1);
CreateTimer(0.1, EnforceTeam, any:client);
}
public Action:EnforceTeam(Handle:timer, any:client)
{
if (!IsClientInGame(client))
{
return;
}
PrintToChatAll("Step 3!");
// Now move player back to team where he tried to join, he will never respawn by himself now
CS_SwitchTeam(client, player_team[client]);
need_respawn[client] = true;
}
public Action:Event_NewRound(Handle:event, const String:name[], bool:dontBroadcast)
{
// Now lets spawn poor player :)
for (new client = 1; client <= MaxClients; client++)
{
if (!IsClientInGame(client))
{
continue;
}
if (need_respawn[client] == true)
{
CS_RespawnPlayer(client);
need_respawn[client] = false;
}
}
return Plugin_Continue;
}
public OnClientPutInServer(client)
{
need_respawn[client] = false;
just_swaped[client] = 2;
}
I do not like this way because script will fire two fictive events and will print two chat messages about swapping client. I also could just use RegConsoleCmd("jointeam", CommandJoinTeam) but in that way I must check many of other situations based on does client have permission to join team or not. If anybody have a suggestions about how to modify this test script in a better way please post replies.
__________________