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

Solved Damage top to decrease


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 04-03-2019 , 12:52   Damage top to decrease
Reply With Quote #1

Hello. Got into a stupid situation.
I can't make the damage top 3 players.
The first place works, on 2 and 3 place a random player takes both places with zero damage.

PHP Code:


#include <sourcemod>
#include <sdktools>

new Damage[65];
new 
String:DamageP[16] = "dmg_health";



public 
void OnPluginStart()
{
    
HookEvent("player_hurt"hurtEventHookMode_Post);
    
HookEvent("round_end"RoundEndEventHookMode_PostNoCopy);
}


public 
hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
dmg GetClientOfUserId(GetEventInt(event,"attacker"));    
    if (
dmg
    {
        
Damage[dmg] += GetEventInt(event,DamageP);
    }
    
}

public 
RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
first 0second 0third 0;
    
    
Damage[0] = 0;
    
    
    for (new 
1<= MaxClientsi++)
    if (
IsClientInGame(i))
    {
        if (
Damage[i] > Damage[first]) first i;
        else if (
Damage[i] == Damage[first]) first i;    
    }
    
    for (new 
1<= MaxClientsi++)
    if (
IsClientInGame(i))
    {
        if (
Damage[i] < Damage[first]) second i;
        else if ((
Damage[i] == Damage[second]) && (Damage[second] < Damage[first])) second i;
    }
    
    for (new 
1<= MaxClientsi++)
    if (
IsClientInGame(i))
    {
        if (
Damage[i] < Damage[second]) third i;
        else if ((
Damage[i] == Damage[third]) && (Damage[third] < Damage[second])) third i;
    }
    
    
decl String:firstName[257];
    
decl String:secondName[257];
    
decl String:thirdName[257];
    
    
    
GetClientName(firstfirstName50);
    
GetClientName(secondsecondName50);
    
GetClientName(thirdthirdName50);
    
    
PrintToChatAll("1 %s - dmg %i"firstNameDamage[first]);
    
PrintToChatAll("2 %s - dmg %i"secondNameDamage[second]);
    
PrintToChatAll("3 %s - dmg %i"thirdNameDamage[third]);
    
    for (
int i 1<= MaxClientsi++) 
    {
        
Damage[i] = 0;
    }        


Last edited by farawayf; 04-04-2019 at 10:06.
farawayf is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 04-03-2019 , 16:20   Re: Damage top to decrease
Reply With Quote #2

Not tested but should work fine

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

int Damage[MAXPLAYERS 1];
#define DamageP "dmg_health"



public void OnPluginStart()
{
    
HookEvent("player_hurt"Event_HurtEventHookMode_Post);
    
HookEvent("round_end"RoundEndEventHookMode_PostNoCopy);
}


public 
void Event_Hurt(Event eventchar[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("attacker"));    
    if (
client)
    {
        
Damage[client] += event.GetInt(DamageP);
    }
    
}

public 
void RoundEnd(Event eventchar[] namebool dontBroadcast)
{
    
int firstsecondthird;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i) && Damage[i] >= Damage[first])
        {
            
first i;
        }
    }
    
    if(
first)
    {
        
PrintToChatAll("1 %N - dmg %i"firstDamage[first]);
        
        for (
int i 1<= MaxClientsi++)
        {
            if (
!= first && IsClientInGame(i) && Damage[i] >= Damage[second])
            {
                
second i;
            }
        }
        
        if(
second)
        {
            
PrintToChatAll("2 %N - dmg %i"secondDamage[second]);
            
            for (
int i 1<= MaxClientsi++)
            {
                if (
!= first && != second && IsClientInGame(i) && Damage[i] >= Damage[third])
                {
                    
third i;
                }
            }
            if(
third)
            {
                
PrintToChatAll("3 %N - dmg %i"thirdDamage[third]);
            }
        }
    }
    
    for (
int i 1<= MaxClientsi++) 
    {
        
Damage[i] = 0;
    }        

__________________

Last edited by impossible_cc; 04-03-2019 at 16:20.
impossible_cc is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 04-04-2019 , 10:06   Re: Damage top to decrease
Reply With Quote #3

It works, thank you.
farawayf is offline
Reply



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 01:30.


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