Raised This Month: $32 Target: $400
 8% 

Solved How to print all with highest int value at round end separately


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-03-2022 , 06:03   How to print all with highest int value at round end separately
Reply With Quote #1

Hello everyone,

I want to know 2 things,

Lets take this script as an example which show you how many kills players got "Frags".

PHP Code:
int KillCount [MAXPLAYERS+1];


public 
void OnPluginStart() 
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("player_death"EVENT_PlayerDeath);
}

public 
void Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
        if (
IsClientInGame(i)) KillCount[i] = 0;
}

public 
void EVENT_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int victim GetClientOfUserId(event.GetInt("userid"));
    if (!
victim || !IsClientInGame(victim)) return;
    
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    if (!
attacker || !IsClientInGame(attacker)) return;
    
    if(
attacker != victim)
    {
        
KillCount[attacker]++;
        
        if (
KillCount[attacker] > 0PrintHintText(attacker"Kills: %d"KillCount[attacker]);
    }


- The first thing I would like to know, is how print in the end of the round everyone's kill like:
mario kills: 15, sonic kills: 10, dragon kills: 8, noob kills: 5


- The second thing is how to show in the end of the round only the highest killer, like:
mario kills: 15 > thats all


Thank you

Last edited by alasfourom; 12-26-2022 at 04:16.
alasfourom is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-03-2022 , 08:57   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #2

You have to sort.

Example (not same scenario)

Spoiler


Probably has other ways to do it, is an old code I did a long time ago to sort specs
__________________

Last edited by Marttt; 08-03-2022 at 08:58.
Marttt is offline
HarryPotter
Veteran Member
Join Date: Sep 2017
Location: Taiwan, Asia
Old 08-03-2022 , 09:40   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #3

https://github.com/fbef0102/L4D1_2-P...e/master/kills
__________________
HarryPotter is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-03-2022 , 10:56   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #4

Both are not easy to do,

I will try it in the weekend thanks Marttt and Harry
alasfourom is offline
moschinovac
Member
Join Date: Mar 2019
Location: Vietnam
Old 08-10-2022 , 20:59   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #5

Quote:
Originally Posted by alasfourom View Post
I was able to make it to work

but I wanna know one more thing, how to print only the highest player with kills for example instead of printing everyone with his kills
I assume u use Harry Potter’s plugins. In line 141, just only Print the first value satisfy condition of j then break the Loop, no need to print full the Loop

Last edited by moschinovac; 08-10-2022 at 21:01.
moschinovac is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-10-2022 , 22:08   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #6

Sort Descending -> First
__________________
Marttt is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-11-2022 , 06:31   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #7

Thanks, seems working fine now
__________________
alasfourom is offline
alasfourom
Senior Member
Join Date: Feb 2022
Location: Saudi Arabia
Old 08-11-2022 , 07:36   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #8

Its working fine, but I'm not sure is this the right method, and if there is for example 0 kills, how to make it display "None"

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

bool  g_bRoundEnd;

int SI_KillCount     [MAXPLAYERS+1];
int Boss_KillCount [MAXPLAYERS+1];

public 
void OnPluginStart() 
{
    
HookEvent("round_start"Event_RoundStart);
    
HookEvent("round_end"Event_RoundEnd);
    
HookEvent("player_death"EVENT_OnSpecialDeath);
    
HookEvent("tank_killed"EVENT_OnTankDeath);
    
HookEvent("witch_killed"EVENT_OnWitchDeath);
}

/* =============================================================================================================== *
 *                                                   Round Start                                                   *
 *================================================================================================================ */

public void Event_RoundStart(Event event, const char[] namebool dontBroadcast)
{
    
g_bRoundEnd false;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            
SI_KillCount     [i] = 0;
            
Boss_KillCount    [i] = 0;
        }
    }
}

/* =============================================================================================================== *
 *                                                   MVP: SI Kills                                                 *
 *================================================================================================================ */

public void EVENT_OnSpecialDeath(Event event, const char[] namebool dontBroadcast)
{
    
int victim GetClientOfUserId(event.GetInt("userid"));
    if (!
victim || !IsClientInGame(victim) || IsTank(victim)) return;
    
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    if (!
attacker || !IsClientInGame(attacker)) return;
    
    if(
attacker != victim && GetClientTeam(attacker) == 2)
    {
        
SI_KillCount[attacker]++;
        
        if (
SI_KillCount[attacker] > 0PrintHintText(attacker"Special Kills: %d"SI_KillCount[attacker]);
    }
}

/* =============================================================================================================== *
 *                                                   MVP: Boss Kills                                               *
 *================================================================================================================ */

public void EVENT_OnWitchDeath(Event event, const char[] namebool dontBroadcast)
{
    
int attacker GetClientOfUserId(event.GetInt("userid"));
    if (!
attacker || !IsClientInGame(attacker)) return;
    
    if(
GetClientTeam(attacker) == 2)
    {
        
Boss_KillCount[attacker]++;
        if (
Boss_KillCount[attacker] > 0PrintHintText(attacker"Boss Kills: %d"Boss_KillCount[attacker]);
    }
}

public 
void EVENT_OnTankDeath(Event event, const char[] namebool dontBroadcast)
{
    
int tank GetClientOfUserId(event.GetInt("userid"));
    if (!
tank || !IsClientInGame(tank)) return;
    
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    if (!
attacker || !IsClientInGame(attacker)) return;
    
    if(
attacker != tank && GetClientTeam(attacker) == 2)
    {
        
Boss_KillCount[attacker]++;
        if (
Boss_KillCount[attacker] > 0PrintHintText(attacker"Boss Kills: %d"Boss_KillCount[attacker]);
    }
}

/* =============================================================================================================== *
 *                                                       Round End                                                 *
 *================================================================================================================ */

public Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    if(!
g_bRoundEnd
    {
        
MVP_Display(); //Display Players With MVP
        
g_bRoundEnd true;
    }
    return 
Plugin_Handled;
}

/* =============================================================================================================== *
 *                                                       MVP Display                                               *
 *================================================================================================================ */

void MVP_Display()
{
    
int client;
    
int players 0;
    
    
int[] players_clients = new int[MaxClients+1];
    
    
int SI_KillCount_MVPBoss_KillCount_MVP;
    
    for (
client 1client <= MaxClientsclient++)
    {
        if (!
IsClientInGame(client) || GetClientTeam(client) == 3) continue;
        
players_clients[players] = client;
        
players++;
    }
    
    
SortCustom1D(players_clientsplayersSortDescending);
    {
        
client players_clients [0];
        
SI_KillCount_MVP SI_KillCount [client];
        
PrintToChatAll("MVP SI Kills: %N (%d)"clientSI_KillCount_MVP);
    }
    
    
SortCustom1D(players_clientsplayersSortDescending);
    {
        
client players_clients    [0];
        
Boss_KillCount_MVP Boss_KillCount [client];
        
PrintToChatAll("MVP Boss Kills: %N (%d)"clientBoss_KillCount_MVP);
    }
}

public 
int SortDescending(int elem1int elem2, const int[] array, Handle hndl)
{
    if (
SI_KillCount[elem1] > SI_KillCount[elem2]) return -1;
    else if (
Boss_KillCount[elem1] > Boss_KillCount[elem2]) return -1;
    else if (
SI_KillCount[elem2] > SI_KillCount[elem1]) return 1;
    else if (
Boss_KillCount[elem2] > Boss_KillCount[elem1]) return 1;
    else if (
elem1 elem2) return -1;
    else if (
elem2 elem1) return 1;
    return 
0;
}

/* =============================================================================================================== *
 *                                                       Check Tank                                                 *
 *================================================================================================================ */

stock bool IsTank(int client)
{
    return (
client 
        
&& client <= MaxClients 
        
&& IsClientInGame(client
        && 
GetClientTeam(client) == 
        
&& GetEntProp(clientProp_Send"m_zombieClass") == 8);

__________________

Last edited by alasfourom; 08-11-2022 at 07:38.
alasfourom is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 08-11-2022 , 08:12   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #9

Quote:
Originally Posted by alasfourom View Post
if there is for example 0 kills, how to make it display "None"
PHP Code:
PrintToChatAll("MVP SI Kills: %N (%d)"clientSI_KillCount_MVP); 
==>
PHP Code:
if(SI_KillCount_MVP 0PrintToChatAll("MVP SI Kills: %N (%d)"clientSI_KillCount_MVP);
else 
PrintToChatAll("MVP SI Kills: %N (None)"client); 
__________________
Grey83 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-11-2022 , 08:20   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #10

...tips
Code:
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
    g_bRoundEnd = false;
    
    for (int i = 1; i <= MaxClients; i++)
    {
        if (IsClientInGame(i))
        {
            SI_KillCount     [i] = 0;
            Boss_KillCount    [i] = 0;
        }
    }
}
Why not reset whole array, either client is in game or not.


Code:
    for (client = 1; client <= MaxClients; client++)
    {
        if (!IsClientInGame(client) || GetClientTeam(client) == 3) continue;
        players_clients[players] = client;
        players++;
    }
... I don't remember L4D teams, but now you exlude clients from that team only. What about spectators ?
Should it be GetClientTeam(client) != 2, if any another team than index 2



This look nonsense, what happened here ?
Code:
    
    SortCustom1D(players_clients, players, SortDescending);
    {
        client = players_clients [0];
        SI_KillCount_MVP = SI_KillCount [client];
        PrintToChatAll("MVP SI Kills: %N (%d)", client, SI_KillCount_MVP);
    }
    
    SortCustom1D(players_clients, players, SortDescending);
    {
        client = players_clients    [0];
        Boss_KillCount_MVP = Boss_KillCount [client];
        PrintToChatAll("MVP Boss Kills: %N (%d)", client, Boss_KillCount_MVP);
    }
}
__________________
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 02:59.


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