Raised This Month: $ Target: $400
 0% 

Weapon Name


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-22-2014 , 13:12   Re: Weapon Name
Reply With Quote #1

For weapon name, use 4th DeathMsg arg (get_user_weapon fails on grenade kills).
To prevent errors when players are killed by world, add filter "1>0" in register_event
To prevent errors when players are killed by entities, check is killer index is a player index.

PHP Code:
new g_iMaxPlayers;
#define IsPlayer(%0)    ( 1 <= (%0) <= g_iMaxPlayers )

public plugin_init()
{
    
register_event("DeathMsg""event_DeathMsg""a""1>0");
    
g_iMaxPlayers get_maxplayers();
}

public 
event_DeathMsg(id)
{
    new 
iKiller read_data(1);
    new 
iVictim read_data(2);

    if(
iKiller != iVictim && IsPlayer(iKiller))
    {
        new 
name[32], szWeapon[32];

        
get_user_name(iKillernamecharsmax(name));
        
read_data(4szWeaponcharsmax(szWeapon));

        
chat_color(iVictim"!nKilled by !t%s !nwith !g%s !nand remained with !g%d !nhp"nameszWeaponget_user_health(iKiller));
    }


Also, at other places than DeathMsg callback, if you have a weapon name with format "weapon_****" and you want to print it without 'weapon_', just do :
PHP Code:
"weapon is %s"szWeapon[7
Don't use replace it is not needed at all.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 01-22-2014 at 13:15.
ConnorMcLeod is offline
daNzEt
Senior Member
Join Date: Sep 2010
Location: Romania
Old 01-07-2014 , 05:46   Re: Weapon Name
Reply With Quote #2

PHP Code:
public event_DeathMsg(id)
{
    new 
iKiller read_data(1
    new 
iVictim    read_data(2)     
    
    if(
iKiller == iVictim
    { 
        return 
PLUGIN_HANDLED
    } 
    
    else 
    {
        new 
name[32], weapon[32];
        new 
wpn get_user_weapon(iKiller);
        
get_user_name(iKillername31)
        
get_weaponname(wpnweaponcharsmax(weapon));
        
replace(weaponcharsmax(weapon), "weapon_""");
         
        new 
health get_user_health(iKiller); 
         
        
chat_color(iVictim"!nJucatorul !t%s !nte-a ucis cu !g%s !nsi a ramas cu !g%d !nhp"nameweaponhealth
    } 
    
    return 
PLUGIN_HANDLED

daNzEt is offline
Send a message via Yahoo to daNzEt Send a message via Skype™ to daNzEt
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 01-07-2014 , 06:08   Re: Weapon Name
Reply With Quote #3

im sorry maybe i should repeat myself.. the WHOLE code... thats just the death event.
__________________
Blizzard_87 is offline
daNzEt
Senior Member
Join Date: Sep 2010
Location: Romania
Old 01-07-2014 , 06:16   Re: Weapon Name
Reply With Quote #4

PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < csstats >
#include < csx >

#define STATS_KILLS             0
#define STATS_DEATHS            1
#define STATS_HS                2
#define STATS_TKS               3
#define STATS_SHOTS             4
#define STATS_HITS              5
#define STATS_DAMAGE            6

new t_sName[31 1]     = ""
new g_sBuffer[2047 1] = ""

new const g_szTopColors[ ][ ] = { "#ff0000""#07fcff""#fff007"};

public 
plugin_init()
{    
    
register_event("DeathMsg""event_DeathMsg""a"

    
register_clcmd"say /rank""cmdRank");
    
register_clcmd"say /top15""cmdTop15");
}

Float:effec(izStats[8])
{
    if (!
izStats[STATS_KILLS])
        return (
0.0)
    
    return (
100.0 float(izStats[STATS_KILLS]) / float(izStats[STATS_KILLS] + izStats[STATS_DEATHS]))
}

Float:accuracy(izStats[8])
{
    if (!
izStats[STATS_SHOTS])
        return (
0.0)
    
    return (
100.0 float(izStats[STATS_HITS]) / float(izStats[STATS_SHOTS]))
}

format_top15sBuffer[2047+1] )
{
    new 
iMax get_statsnum()
    new 
izStats[8], izBody[8]
    new 
iLen 0

    
if (iMax 15)
    {
        
iMax 15
    
}

    new 
lKills[16], lDeaths[16], lHits[16], lShots[16], lEff[16], lAcc[16]
    
    
format(lKills15"Kill")
    
format(lDeaths15"Deaths")
    
format(lHits15"Hits")
    
format(lShots15"Shots")
    
format(lEff15"Eff.")
    
format(lAcc15"Acc.")
    
    
ucfirst(lEff)
    
ucfirst(lAcc)

    
iLen format(sBuffer2047"<body bgcolor=#000000><font color=#FFFFFF><pre>")
    
iLen += format(sBuffer[iLen], 1500-iLen,"<center><img src=^"http://s15.************/i9k79lhln/rsz_2n5irhd.png^"></center></img>");
    
iLen += format(sBuffer[iLen], 2047 iLen"%s %-22.20s %5s %7s %8s %7s %5s %8s %5s^n""#""Nick"lKillslDeathslHitslShots"HS"lEfflAcc)    
    new 
iMaxColors sizeofg_szTopColors );
    
    for (new 
0iMax && 2047 iLen 0i++)
    {
        
get_stats(iizStatsizBodyt_sName31)
        
replace_all(t_sName31"<""[")
        
replace_all(t_sName31">""]")
        
        if( 
iMaxColors 
        {
            
iLen += format(sBuffer[iLen], 2047 iLen"<font color=%s>%2d %-17.14s %7d %7d %8d %8d %6d %6.0f%% %6.0f%%</font>^n"g_szTopColors], 1t_sNameizStats[STATS_KILLS], 
                        
izStats[STATS_DEATHS], izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_HS], effec(izStats), accuracy(izStats))
        }
        
        else
        {
            
iLen += format(sBuffer[iLen], 2047 iLen"%2d %-17.14s %7d %7d %8d %8d %6d %6.0f%% %6.0f%%^n"1t_sNameizStats[STATS_KILLS], 
                        
izStats[STATS_DEATHS], izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_HS], effec(izStats), accuracy(izStats))
        }
    }
}

public 
cmdTop15id )
{    
    
format_top15g_sBuffer );
    
    
show_motdidg_sBuffer"Top 15" );
    
    return 
PLUGIN_CONTINUE;
}

public 
cmdRankid )
{    
    new 
izStats[8], izBody[8];
    
    new 
iRankPosiRankMax;    
    
iRankPos get_user_statsidizStatsizBody );    
    
iRankMax get_statsnum();
    
    
chat_color(id"!nPozitia ta in rank este !t%d !ndin !t%d !n[!g%d !nkills] [!g%d !ndeaths] [!g%d !nhits]"iRankPosiRankMaxizStats[STATS_KILLS], izStats[STATS_DEATHS], izStats[STATS_HITS] );
    
    return 
PLUGIN_CONTINUE;
}

public 
event_DeathMsg(id)
{
    new 
iKiller read_data(1
    new 
iVictim    read_data(2)     
    
    if(
iKiller == iVictim
    { 
        return 
PLUGIN_HANDLED
    } 
    
    else 
    {
        new 
name[32], weapon[32];
        new 
wpn get_user_weapon(iKiller);
        
get_user_name(iKillername31)
        
get_weaponname(wpnweaponcharsmax(weapon));
        
replace(weaponcharsmax(weapon), "weapon_""");
         
        new 
health get_user_health(iKiller); 
         
        
chat_color(iVictim"!nJucatorul !t%s !nte-a ucis cu !g%s !nsi a ramas cu !g%d !nhp"nameweaponhealth
    } 
    
    return 
PLUGIN_HANDLED
}

stock chat_color(const id, const input[], any:...)
{
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)

    
replace_all(msg190"!g""^4")
    
replace_all(msg190"!n""^1")
    
replace_all(msg190"!t""^3")

    if (
idplayers[0] = id; else get_players(playerscount"ch")
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

daNzEt is offline
Send a message via Yahoo to daNzEt Send a message via Skype™ to daNzEt
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 01-07-2014 , 07:27   Re: Weapon Name
Reply With Quote #5

Just check if killer is valid
(1 <= iKiller <= iMaxPlayers)
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster is offline
joshknifer
Veteran Member
Join Date: Jun 2011
Location: Denver, CO
Old 01-22-2014 , 12:47   Re: Weapon Name
Reply With Quote #6

Quote:
Originally Posted by daNzEt View Post
Anyone know how to solve the problem?
Quote:
Originally Posted by pokemonmaster View Post
Just check if killer is valid
(1 <= iKiller <= iMaxPlayers)
__________________
joshknifer is offline
Send a message via Skype™ to joshknifer
daNzEt
Senior Member
Join Date: Sep 2010
Location: Romania
Old 01-08-2014 , 03:23   Re: Weapon Name
Reply With Quote #7

Can you edit with this code so i can see better?

Last edited by daNzEt; 01-08-2014 at 03:23.
daNzEt is offline
Send a message via Yahoo to daNzEt Send a message via Skype™ to daNzEt
daNzEt
Senior Member
Join Date: Sep 2010
Location: Romania
Old 01-22-2014 , 12:07   Re: Weapon Name
Reply With Quote #8

Anyone know how to solve the problem?
daNzEt is offline
Send a message via Yahoo to daNzEt Send a message via Skype™ to daNzEt
daNzEt
Senior Member
Join Date: Sep 2010
Location: Romania
Old 01-23-2014 , 12:34   Re: Weapon Name
Reply With Quote #9

Thanks for support.

Now the plugins looks like:

PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < csstats >
#include < csx >

#define STATS_KILLS     0
#define STATS_DEATHS    1
#define STATS_HS        2
#define STATS_TKS        3
#define STATS_SHOTS        4
#define STATS_HITS        5
#define STATS_DAMAGE    6

#define IsPlayer(%0)    ( 1 <= (%0) <= g_iMaxPlayers )

new t_sName[31 1]     = ""
new g_sBuffer[2047 1] = ""
new g_iMaxPlayers;

new const 
g_szTopColors[ ][ ] = { "#ff0000""#07fcff""#fff007"};

public 
plugin_init()
{
    
register_plugin"Rank + Top15""1.0""daNzEt")
    
    
register_event("DeathMsg""event_DeathMsg""a""1>0");

    
register_clcmd"say /rank""cmdRank");    
    
register_clcmd"say /stats""cmdRank");
    
register_clcmd"say /rankstats""cmdRank");
    
register_clcmd"say /top15""cmdTop15");
    
    
g_iMaxPlayers get_maxplayers();
}

Float:effec(izStats[8])
{
    if (!
izStats[STATS_KILLS])
        return (
0.0)
    
    return (
100.0 float(izStats[STATS_KILLS]) / float(izStats[STATS_KILLS] + izStats[STATS_DEATHS]))
}

Float:accuracy(izStats[8])
{
    if (!
izStats[STATS_SHOTS])
        return (
0.0)
    
    return (
100.0 float(izStats[STATS_HITS]) / float(izStats[STATS_SHOTS]))
}

format_top15sBuffer[2047+1] )
{
    new 
iMax get_statsnum()
    new 
izStats[8], izBody[8]
    new 
iLen 0

    
if (iMax 15)
    {
        
iMax 15
    
}

    new 
lKills[16], lDeaths[16], lHits[16], lShots[16], lEff[16], lAcc[16]
    
    
format(lKills15"Kill")
    
format(lDeaths15"Deaths")
    
format(lHits15"Hits")
    
format(lShots15"Shots")
    
format(lEff15"Eff.")
    
format(lAcc15"Acc.")
    
    
ucfirst(lEff)
    
ucfirst(lAcc)

    
iLen format(sBuffer2047"<body bgcolor=#000000><font color=#FFFFFF><pre>")
    
iLen += format(sBuffer[iLen], 1500-iLen,"<center><img src=^"http://s15.************/i9k79lhln/rsz_2n5irhd.png^"></center></img>");
    
iLen += format(sBuffer[iLen], 2047 iLen"%s %-22.20s %5s %7s %8s %7s %5s %8s %5s^n""#""Nick"lKillslDeathslHitslShots"HS"lEfflAcc)    
    new 
iMaxColors sizeofg_szTopColors );
    
    for (new 
0iMax && 2047 iLen 0i++)
    {
        
get_stats(iizStatsizBodyt_sName31)
        
replace_all(t_sName31"<""[")
        
replace_all(t_sName31">""]")
        
        if( 
iMaxColors 
        {
            
iLen += format(sBuffer[iLen], 2047 iLen"<font color=%s>%2d %-17.14s %7d %7d %8d %8d %6d %6.0f%% %6.0f%%</font>^n"g_szTopColors], 1t_sNameizStats[STATS_KILLS], 
                        
izStats[STATS_DEATHS], izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_HS], effec(izStats), accuracy(izStats))
        }
        
        else
        {
            
iLen += format(sBuffer[iLen], 2047 iLen"%2d %-17.14s %7d %7d %8d %8d %6d %6.0f%% %6.0f%%^n"1t_sNameizStats[STATS_KILLS], 
                        
izStats[STATS_DEATHS], izStats[STATS_HITS], izStats[STATS_SHOTS], izStats[STATS_HS], effec(izStats), accuracy(izStats))
        }
    }
}

public 
cmdTop15id )
{    
    
format_top15g_sBuffer );
    
    
show_motdidg_sBuffer"Top 15" );
    
    return 
PLUGIN_CONTINUE;
}

public 
cmdRankid )
{    
    new 
izStats[8], izBody[8];
    
    new 
iRankPosiRankMax;    
    
iRankPos get_user_statsidizStatsizBody );    
    
iRankMax get_statsnum();
    
    
chat_color(id"!nPozitia ta in rank este !t%d !ndin !t%d !n[!g%d !nkills] [!g%d !ndeaths] [!g%d !nhits]"iRankPosiRankMaxizStats[STATS_KILLS], izStats[STATS_DEATHS], izStats[STATS_HITS] );
    
    return 
PLUGIN_CONTINUE;
}

public 
event_DeathMsg(id)
{
    new 
iKiller read_data(1);
    new 
iVictim read_data(2);

    if(
iKiller != iVictim && IsPlayer(iKiller))
    {
        new 
name[32], szWeapon[32];

        
get_user_name(iKillernamecharsmax(name));
        
read_data(4szWeaponcharsmax(szWeapon));

        
chat_color(iVictim"!nJucatorul !t%s !nte-a ucis cu !g%s !nsi a ramas cu !g%d !nhp"nameszWeaponget_user_health(iKiller));
    }
}

stock chat_color(const id, const input[], any:...)
{
    new 
count 1players[32]
    static 
msg[191]
    
vformat(msg190input3)

    
replace_all(msg190"!g""^4")
    
replace_all(msg190"!n""^1")
    
replace_all(msg190"!t""^3")

    if (
idplayers[0] = id; else get_players(playerscount"ch")
    {
        for (new 
0counti++)
        {
            if (
is_user_connected(players[i]))
            {
                
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _players[i])
                
write_byte(players[i]);
                
write_string(msg);
                
message_end();
            }
        }
    }

How can i remove definitely Eff and Acc. from /top15 cmd?

Last edited by daNzEt; 01-23-2014 at 12:35.
daNzEt is offline
Send a message via Yahoo to daNzEt Send a message via Skype™ to daNzEt
joshknifer
Veteran Member
Join Date: Jun 2011
Location: Denver, CO
Old 01-23-2014 , 13:11   Re: Weapon Name
Reply With Quote #10

I believe that question has already been answered in the other thread you posted.
__________________
joshknifer is offline
Send a message via Skype™ to joshknifer
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 20:36.


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