AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved How to print all with highest int value at round end separately (https://forums.alliedmods.net/showthread.php?t=338911)

alasfourom 08-03-2022 06:03

How to print all with highest int value at round end separately
 
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

Marttt 08-03-2022 08:57

Re: How to print all players/highest player kills at the end of the round?
 
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

HarryPotter 08-03-2022 09:40

Re: How to print all players/highest player kills at the end of the round?
 
https://github.com/fbef0102/L4D1_2-P...e/master/kills

alasfourom 08-03-2022 10:56

Re: How to print all players/highest player kills at the end of the round?
 
Both are not easy to do,

I will try it in the weekend thanks Marttt and Harry

moschinovac 08-10-2022 20:59

Re: How to print all players/highest player kills at the end of the round?
 
Quote:

Originally Posted by alasfourom (Post 2786146)
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

Marttt 08-10-2022 22:08

Re: How to print all players/highest player kills at the end of the round?
 
Sort Descending -> First

alasfourom 08-11-2022 06:31

Re: How to print all players/highest player kills at the end of the round?
 
Thanks, seems working fine now

alasfourom 08-11-2022 07:36

Re: How to print all players/highest player kills at the end of the round?
 
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);



Grey83 08-11-2022 08:12

Re: How to print all players/highest player kills at the end of the round?
 
Quote:

Originally Posted by alasfourom (Post 2786190)
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); 


Bacardi 08-11-2022 08:20

Re: How to print all players/highest player kills at the end of the round?
 
...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);
    }
}



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

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