Quote:
Originally Posted by z-@T
Thanks for the info, I'll start changing my code right away.
|
There's a few more things to keep in mind with these changes.
- You need to hook Ham_TakeDamage post because pev_dmg_take will not hold the damage value until then. You can also use an integer to store this damage value.
- You will need a 2-dimension array so each players damage can be recorded for every other player. This array needs to be reset to 0 at each spawn (unless you want to store a cumulative value of damage, if so reset at client_disconnect).
- You should retrieve a users name when he connects and store it a global array so you do not constantly need to retrieve their name.
Try all of these revisions for yourself. Below is code with these fixes that you can refer to if you have problems.
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
const MaxPlayers = 32;
new g_iMaxPlayers;
new g_iDmgPlayer[ MaxPlayers + 1 ][ MaxPlayers + 1 ];
new g_szName[ MaxPlayers + 1 ][ 33 ];
#define IsPlayer(%1) (1<=%1<=g_iMaxPlayers)
public plugin_init()
{
RegisterHam( Ham_TakeDamage , "player" , "eventTakeDamage_Post" , 1 );
RegisterHam( Ham_Spawn , "player" , "eventSpawn_Post" , 1 );
g_iMaxPlayers = get_maxplayers();
}
public client_putinserver( id )
{
get_user_name( id , g_szName[ id ] , charsmax( g_szName[] ) );
}
public eventSpawn_Post(id)
{
if ( is_user_alive( id ) )
arrayset( g_iDmgPlayer[ id ] , 0 , MaxPlayers + 1 );
}
public eventTakeDamage_Post(id, weapon, attacker, Float:damage, damagebits)
{
if( !IsPlayer( attacker ) || ( attacker == id ) )
return HAM_IGNORED;
g_iDmgPlayer[ attacker ][ id ] += pev( id , pev_dmg_take );
client_print(attacker, print_chat, "* You have done %i damage to %s!", g_iDmgPlayer[ attacker ][ id ] , g_szName[ id ] );
return HAM_IGNORED;
}
__________________