AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [L4D2] Trying to make sure clients are in the correct team (https://forums.alliedmods.net/showthread.php?t=342180)

alasfourom 03-14-2023 18:01

[L4D2] Trying to make sure clients are in the correct team
 
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_RoundEndEventHookMode_PostNoCopy);
    
g_sCampaign = new StringMap();
}

public 
void OnMapStart()
{
    
g_bTrigger false;
}

void Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    if (!
GameRules_GetProp("m_bInSecondHalfOfRound") || g_bTrigger) return;
    
    if (!
L4D2_AreTeamsFlipped())
    {
        
g_iSurvivor_Score L4D_GetTeamScore(1true);
        
g_iInfected_Score L4D_GetTeamScore(2true);
    }
    else
    {
        
g_iSurvivor_Score L4D_GetTeamScore(2true);
        
g_iInfected_Score L4D_GetTeamScore(1true);
    }
    
    
g_sCampaign.Clear();
    
g_bTrigger true;
    
    
CreateTimer(2.0Timer_SavePlayersTeamTIMER_FLAG_NO_MAPCHANGE);
}

Action Timer_SavePlayersTeam(Handle timer)
{
    
int iTeam;
    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i) || IsFakeClient(i)) continue;
        
        
char auth[32];
        
GetClientAuthId(iAuthId_Steam2authsizeof(auth));
        
        if(
g_iSurvivor_Score >= g_iInfected_Score)
        {
            if(
GetClientTeam(i) == 1iTeam 1;
            else if(
GetClientTeam(i) == 2iTeam 2;
            else 
iTeam 3;
        }
        else
        {
            if(
GetClientTeam(i) == 1iTeam 1;
            else if(
GetClientTeam(i) == 3iTeam 2;
            else 
iTeam 3;
            
            
PrintToChat(i"Your saved team for the next chapter is: %i"iTeam);
        }
        
        
g_sCampaign.SetValue(authiTeamtrue);
    }
    return 
Plugin_Handled;
}

public 
void OnClientPostAdminCheck(int client)
{
    if (!
IsClientInGame(client) || IsFakeClient(client)) return;
    
CreateTimer(1.0Timer_RepositionClientsGetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
}

Action Timer_RepositionClients(Handle timerint userid)
{
    
int client GetClientOfUserId(userid);
    if(
client == || !IsClientInGame(client) || IsFakeClient(client)) return Plugin_Handled;
    
    
char auth[32];
    
GetClientAuthId(clientAuthId_Steam2authsizeof(auth));
    
    
int iTeam;
    if(
g_sCampaign.GetValue(authiTeam))
    {
        if(
iTeam || iTeam 3) return Plugin_Handled;
        
PrintToChat(client"Your loaded team this chapter should be set to: %i"iTeam);
    }
    
    return 
Plugin_Handled;



sorallll 03-14-2023 21:28

Re: [L4D2] Trying to make sure clients are in the correct team
 
You can refer to this plugin


All times are GMT -4. The time now is 00:58.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.