Hello guys, this is part of a long script
Left 4 Dead 2 - Versus Mode
Trying to sort clients and put them in their correct team upon changing to next map.
This will also help me solve other issues as well. My main issue is: I'm not able to detect the actual winning team (team with the higher score) weather they are survivors or infected. Specially sometimes teams are flipped making it a bit complicated for me.
Thanks
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <left4dhooks>
StringMap g_sCampaign;
int g_iSurvivor_Score;
int g_iInfected_Score;
bool g_bTrigger;
public void OnPluginStart()
{
HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
g_sCampaign = new StringMap();
}
public void OnMapStart()
{
g_bTrigger = false;
}
void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
if (!GameRules_GetProp("m_bInSecondHalfOfRound") || g_bTrigger) return;
if (!L4D2_AreTeamsFlipped())
{
g_iSurvivor_Score = L4D_GetTeamScore(1, true);
g_iInfected_Score = L4D_GetTeamScore(2, true);
}
else
{
g_iSurvivor_Score = L4D_GetTeamScore(2, true);
g_iInfected_Score = L4D_GetTeamScore(1, true);
}
g_sCampaign.Clear();
g_bTrigger = true;
CreateTimer(2.0, Timer_SavePlayersTeam, TIMER_FLAG_NO_MAPCHANGE);
}
Action Timer_SavePlayersTeam(Handle timer)
{
int iTeam;
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i)) continue;
char auth[32];
GetClientAuthId(i, AuthId_Steam2, auth, sizeof(auth));
if(g_iSurvivor_Score >= g_iInfected_Score)
{
if(GetClientTeam(i) == 1) iTeam = 1;
else if(GetClientTeam(i) == 2) iTeam = 2;
else iTeam = 3;
}
else
{
if(GetClientTeam(i) == 1) iTeam = 1;
else if(GetClientTeam(i) == 3) iTeam = 2;
else iTeam = 3;
PrintToChat(i, "Your saved team for the next chapter is: %i", iTeam);
}
g_sCampaign.SetValue(auth, iTeam, true);
}
return Plugin_Handled;
}
public void OnClientPostAdminCheck(int client)
{
if (!IsClientInGame(client) || IsFakeClient(client)) return;
CreateTimer(1.0, Timer_RepositionClients, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}
Action Timer_RepositionClients(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if(client == 0 || !IsClientInGame(client) || IsFakeClient(client)) return Plugin_Handled;
char auth[32];
GetClientAuthId(client, AuthId_Steam2, auth, sizeof(auth));
int iTeam;
if(g_sCampaign.GetValue(auth, iTeam))
{
if(iTeam < 1 || iTeam > 3) return Plugin_Handled;
PrintToChat(client, "Your loaded team this chapter should be set to: %i", iTeam);
}
return Plugin_Handled;
}
__________________