AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Kills per round (https://forums.alliedmods.net/showthread.php?t=249795)

muh 10-12-2014 09:26

Kills per round
 
Hello :3
I want to make a plugin that prints a chat message at the end of a round with the total number of kills a player ever made on a server. My first attempt was to use get_user_stats, but if I use it at the end of a round I am not able to get the current number of kills. So I thought I could remember this number and add to this number every round the number of kills a player made. I tried it with get_user_frags, but this also includes teamkills, defuse a bomb, etc. I only want to know how many enemies a player killed in 1 round. How can I get this number? Or is there any other solution how I can get the total number of kills a player ever made on a server at the end of every round?

HamletEagle 10-12-2014 09:36

Re: Kills per round
 
Create a variable like playerKills[ 33 ] and hook the death event, increase the counter and print it when you need.

HENNESSY 10-12-2014 09:42

Re: Kills per round
 
Here you go (not tested)

PHP Code:

#include < amxmodx >

new g_iKills33 ];
new 
g_iMaxPlayers;

public 
plugin_init( )
{
    
register_logevent"LogEvent_RoundEnd"2"1=Round_End" );
    
register_logevent"LogEvent_RoundStart"2"1=Round_Start" );
    
    
register_event"DeathMsg""Event_DeathMsg""a" );
    
    
g_iMaxPlayers get_maxplayers( );
}

public 
LogEvent_RoundEnd( )
{
    new 
iBest 0;
    
    for( new 
1<= g_iMaxPlayers; ++)
    {
        if( !
is_user_connected) )
            continue;
            
        if( 
g_iKills] > g_iKillsiBest ] )
        {
            
iBest i;
        }
    }
    
    new 
szName32 ];
    
get_user_nameiBestszNamecharsmaxszName ) );
    
    
client_print0print_chat"%s did the most kills this round."szName );
}

public 
LogEvent_RoundStart( )
{
    
arraysetg_iKills032 );
}

public 
Event_DeathMsg( )
{
    new 
iKiller read_data);
    new 
iVictim read_data);
    
    if( 
iKiller == iVictim || get_user_teamiKiller ) == get_user_teamiVictim ) )
        return;
    
    ++
g_iKillsiKiller ];



RateX 10-12-2014 09:48

Re: Kills per round
 
PHP Code:

arrayset 

Never seen this one before. Nice way to avoid looping.
PHP Code:

for( new 1<= g_iMaxPlayers; ++

This has been discussed many times, use get_players() instead.

HamletEagle 10-12-2014 10:04

Re: Kills per round
 
arrayset is a loop too, but runs on a faster layer, cause it's from a module.

HENNESSY 10-12-2014 10:13

Re: Kills per round
 
Quote:

Originally Posted by RateX (Post 2210157)
PHP Code:

arrayset 

Never seen this one before. Nice way to avoid looping.
PHP Code:

for( new 1<= g_iMaxPlayers; ++

This has been discussed many times, use get_players() instead.

what is the difference between my way to get_players( )?

HamletEagle 10-12-2014 10:25

Re: Kills per round
 
You way is much more slower and is not a good way. get_players exists for a reason, it also let you specify flags to filter the search.

HENNESSY 10-12-2014 10:29

Re: Kills per round
 
Quote:

Originally Posted by HamletEagle (Post 2210170)
You way is much more slower and is not a good way. get_players exists for a reason, it also let you specify flags to filter the search.

Thanks for the advice :)

Shlomi 10-12-2014 15:18

Re: Kills per round
 
Quote:

Originally Posted by HENNESSY (Post 2210154)
Here you go (not tested)

PHP Code:

#include < amxmodx >

new g_iKills33 ];
new 
g_iMaxPlayers;

public 
plugin_init( )
{
    
register_logevent"LogEvent_RoundEnd"2"1=Round_End" );
    
register_logevent"LogEvent_RoundStart"2"1=Round_Start" );
    
    
register_event"DeathMsg""Event_DeathMsg""a" );
    
    
g_iMaxPlayers get_maxplayers( );
}

public 
LogEvent_RoundEnd( )
{
    new 
iBest 0;
    
    for( new 
1<= g_iMaxPlayers; ++)
    {
        if( !
is_user_connected) )
            continue;
            
        if( 
g_iKills] > g_iKillsiBest ] )
        {
            
iBest i;
        }
    }
    
    new 
szName32 ];
    
get_user_nameiBestszNamecharsmaxszName ) );
    
    
client_print0print_chat"%s did the most kills this round."szName );
}

public 
LogEvent_RoundStart( )
{
    
arraysetg_iKills032 );
}

public 
Event_DeathMsg( )
{
    new 
iKiller read_data);
    new 
iVictim read_data);
    
    if( 
iKiller == iVictim || get_user_teamiKiller ) == get_user_teamiVictim ) )
        return;
    
    ++
g_iKillsiKiller ];



you can avoid hooking new round and reset your array when the round ends, after you printed what you've wanted.

muh 10-12-2014 19:49

Re: Kills per round
 
Quote:

Originally Posted by HENNESSY (Post 2210154)
Here you go (not tested)

PHP Code:

#include < amxmodx >

new g_iKills33 ];
new 
g_iMaxPlayers;

public 
plugin_init( )
{
    
register_logevent"LogEvent_RoundEnd"2"1=Round_End" );
    
register_logevent"LogEvent_RoundStart"2"1=Round_Start" );
    
    
register_event"DeathMsg""Event_DeathMsg""a" );
    
    
g_iMaxPlayers get_maxplayers( );
}

public 
LogEvent_RoundEnd( )
{
    new 
iBest 0;
    
    for( new 
1<= g_iMaxPlayers; ++)
    {
        if( !
is_user_connected) )
            continue;
            
        if( 
g_iKills] > g_iKillsiBest ] )
        {
            
iBest i;
        }
    }
    
    new 
szName32 ];
    
get_user_nameiBestszNamecharsmaxszName ) );
    
    
client_print0print_chat"%s did the most kills this round."szName );
}

public 
LogEvent_RoundStart( )
{
    
arraysetg_iKills032 );
}

public 
Event_DeathMsg( )
{
    new 
iKiller read_data);
    new 
iVictim read_data);
    
    if( 
iKiller == iVictim || get_user_teamiKiller ) == get_user_teamiVictim ) )
        return;
    
    ++
g_iKillsiKiller ];



Well, that's not exactly what I wanted to do, but nevertheless it was very useful. Thanks! :)


All times are GMT -4. The time now is 17:44.

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