Raised This Month: $12 Target: $400
 3% 

[L4D2] How to detect winner teams ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 11-15-2022 , 16:30   [L4D2] How to detect winner teams ?
Reply With Quote #1

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);
    }

__________________

Last edited by alasfourom; 11-15-2022 at 16:32.
alasfourom is offline
oqyh
Senior Member
Join Date: May 2019
Location: United Arab Emirates
Old 11-16-2022 , 02:39   Re: [L4D2] How to detect winner teams ?
Reply With Quote #2

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
                
}
            }
        }
    }

__________________
.:[ >> My Plugins << ]:.

My discord : oqyh

Last edited by oqyh; 11-16-2022 at 07:33.
oqyh is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 11-16-2022 , 06:38   Re: [L4D2] How to detect winner teams ?
Reply With Quote #3

Quote:
Originally Posted by oqyh View Post
-
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?
__________________
Silvers is offline
oqyh
Senior Member
Join Date: May 2019
Location: United Arab Emirates
Old 11-16-2022 , 07:27   Re: [L4D2] How to detect winner teams ?
Reply With Quote #4

Quote:
Originally Posted by Silvers View Post
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
__________________
.:[ >> My Plugins << ]:.

My discord : oqyh
oqyh is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 11-16-2022 , 07:38   Re: [L4D2] How to detect winner teams ?
Reply With Quote #5

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 View Post
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);    }} 
__________________
Do not Private Message @me
Bacardi is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:52.


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