AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D2] How to detect winner teams ? (https://forums.alliedmods.net/showthread.php?t=340391)

alasfourom 11-15-2022 16:30

[L4D2] How to detect winner teams ?
 
Hello guys,

When trying to detect winners team for l4d2 while hooking round_end event, winners team will be equal to 0 ???

If this method doesnt work, is there any other way to do so?

Thanks

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdkhooks>
#include <sdktools>

public void OnPluginStart()
{
    
HookEvent("round_end"Event_RoundEnd);
}

void Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
int WinnerTeam GetEventInt(event"winner");
    
    for (
int i 1<= MaxClientsi++)
    {
        if(
GetClientTeam(i) == WinnerTeamPrintToChat(i"Winner Team == %d"WinnerTeam);
        else 
PrintToChat(i"Losing Team != %d"WinnerTeam);
    }



oqyh 11-16-2022 02:39

Re: [L4D2] How to detect winner teams ?
 
PHP Code:

#pragma semicolon 1
#pragma newdecls required

//////here is list of L4D Teams///////////////////
#define SPECTEAM 1
#define SURVIVORTEAM 2
#define INFECTEDTEAM 3
///////////////////////////////////////////////

#include <sourcemod>

public void OnPluginStart()
{
    
HookEvent("round_end"Event_RoundEnd);
}

void Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
int WinnerTeam GetEventInt(event"winner");
    
    for(
int i 1<= MaxClients; ++i)
    {
        if (
IsClientInGame(i))
        {
            if (
IsPlayerAlive(i))
            {
                if (
WinnerTeam == SURVIVORTEAM//so if WinnerTeam which is GetEventInt the winner, and int on top at define are equal together means team winner
                
{
                    
//do stuff here if survivor win
                
}else if (WinnerTeam == INFECTEDTEAM//here also same but we change to infected team
                
{
                    
//do stuff here if infected win
                
}
            }
        }
    }



Silvers 11-16-2022 06:38

Re: [L4D2] How to detect winner teams ?
 
Quote:

Originally Posted by oqyh (Post 2792903)
-

What on earth is that?

- Loop should be to "<= MaxClients" not "< MaxClients"
- delete IsValidEntity line
- delete IsClientConnected line

and why even do this when you're using "PrintToChatAll", just use that without a loop, or you want to print the message as many times as clients in game?

oqyh 11-16-2022 07:27

Re: [L4D2] How to detect winner teams ?
 
Quote:

Originally Posted by Silvers (Post 2792920)
What on earth is that?

- Loop should be to "<= MaxClients" not "< MaxClients"
- delete IsValidEntity line
- delete IsClientConnected line

and why even do this when you're using "PrintToChatAll", just use that without a loop, or you want to print the message as many times as clients in game?


hello silvers xD
im just giving example i dont what he want exactly IsValidEntity just in case if he use edict

Bacardi 11-16-2022 07:38

Re: [L4D2] How to detect winner teams ?
 
You can look server events with:
sm_cvar net_showevents 2

To log those:
Code:

sm_cvar con_logtimestamp 1
sm_cvar con_logfile mylogs.log // use .log file name extension

Sometimes server not follow all events in some cases.
Use plugin for that.
Here is one of those plugins, it will print in server console events with parameters.
-Snip- Hook Events From Files

But use above things only for testing debug/purpose, these will lag server a lot (because lot of printing in console)


Quote:

Originally Posted by alasfourom (Post 2792882)
Hello guys,

When trying to detect winners team for l4d2 while hooking round_end event, winners team will be equal to 0 ???

If this method doesnt work, is there any other way to do so?

Thanks

PHP Code:

#pragma semicolon 1#pragma newdecls required#include <sourcemod>#include <sdkhooks>#include <sdktools>public void OnPluginStart(){    HookEvent("round_end", Event_RoundEnd);}void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast){    int WinnerTeam = GetEventInt(event, "winner");        for (int i = 1; i <= MaxClients; i++)    {        if(GetClientTeam(i) == WinnerTeam) PrintToChat(i, "Winner Team == %d", WinnerTeam);        else PrintToChat(i, "Losing Team != %d", WinnerTeam);    }} 




All times are GMT -4. The time now is 16:06.

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