In L4D1/2 you need to use SDK call as ChangeClientTeam(client, 2) dosn't put you in control of a survivor bot. FakeClientCommand(client, "jointeam 2" is another attempt that works but the problem with this command is that it won't let you take over a survivor bot if the survivor is dead or incapaciated.
I've been using this code and recently found out that it crashes the server sometimes. The only weird part here is that it sometimes works without crashing the server. I tried this all alone on one of my servers sp I know the issue is related to this team-switching code.
My question now, how can I make this code different and get it working without server crashes? If there are alive survivor bots available, I want the client to take over those, and if there are no alive bots, I want the survivor to take over one of the dead ones.
#define L4D_MAXCLIENTS_PLUS1 (MaxClients+1)
#define L4D_TEAM_SURVIVORS 2
PHP Code:
if (team == 2)
{
new Bot = GetAliveSurvivors();
if(GetAliveSurvivors() > 0)
{
ChangeClientTeam(target, 1);
SDKCall(fSHS, Bot, target);
SDKCall(fTOB, target, true);
}
else
{
new dBot = GetDeadSurvivors();
if (GetDeadSurvivors() > 0)
{
ChangeClientTeam(target, 1);
SDKCall(fSHS, dBot, target);
SDKCall(fTOB, target, true);
}
}
}
stock GetAliveSurvivors()
{
new alive = 0;
new i;
for(i = 1; i < L4D_MAXCLIENTS_PLUS1; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == L4D_TEAM_SURVIVORS)
{
alive++;
}
}
return alive;
}
stock GetDeadSurvivors()
{
new dead = 0;
new i;
for(i = 1; i < L4D_MAXCLIENTS_PLUS1; i++)
{
if(IsClientInGame(i) && !IsPlayerAlive(i) && GetClientTeam(i) == L4D_TEAM_SURVIVORS)
{
dead++;
}
}
return dead;
}
gamedata:
Code:
"Games"
{
"left4dead2"
{
"Signatures"
{
"TakeOverBot"
{
"library" "server"
"linux" "@_ZN13CTerrorPlayer11TakeOverBotEb"
"windows" "\x81*****\x53\x55\x56\x8D***\x57\x8B\xF1\x33\xDB"
}
"SetHumanSpec"
{
"library" "server"
"linux" "@_ZN11SurvivorBot17SetHumanSpectatorEP13CTerrorPlayer"
"windows" "\x53\x56\x8B\xF1\x33\xDB\x39*******\x5E\x32\xC0\x5B"
}
}
}
}