Raised This Month: $ Target: $400
 0% 

Solved How to print all players/highest player kills at the end of the round?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
alasfourom
Senior Member
Join Date: Feb 2022
Old 08-03-2022 , 06:03   How to print all players/highest player kills at the end of the round?
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; 08-11-2022 at 16:54.
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, Taipei
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
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
alasfourom
Senior Member
Join Date: Feb 2022
Old 08-10-2022 , 20:04   Re: How to print all players/highest player kills at the end of the round?
Reply With Quote #5

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
__________________
Now I Know: Peace
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 #6

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

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

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

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

__________________
Now I Know: Peace

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 #10

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
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 15:41.


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