Raised This Month: $ Target: $400
 0% 

Ham_TakeDamage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-14-2010 , 08:44   Re: Ham_TakeDamage
Reply With Quote #1

Quote:
Originally Posted by z-@T View Post
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_iDmgPlayerMaxPlayers ][ MaxPlayers ];
new 
g_szNameMaxPlayers ][ 33 ];

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

public plugin_init() 
{
    
RegisterHamHam_TakeDamage "player" "eventTakeDamage_Post" );
    
RegisterHamHam_Spawn "player" "eventSpawn_Post" );
    
    
g_iMaxPlayers get_maxplayers();
}

public 
client_putinserverid )
{
    
get_user_nameid g_szNameid ] , charsmaxg_szName[] ) );
}

public 
eventSpawn_Post(id)
{
    if ( 
is_user_aliveid ) )
        
arraysetg_iDmgPlayerid ] , MaxPlayers );
}

public 
eventTakeDamage_Post(idweaponattackerFloat:damagedamagebits)
{
    if( !
IsPlayerattacker ) || ( attacker == id ) )
        return 
HAM_IGNORED;
        
    
g_iDmgPlayerattacker ][ id ] += pevid pev_dmg_take );
    
client_print(attackerprint_chat"* You have done %i damage to %s!"g_iDmgPlayerattacker ][ id ] , g_szNameid ] );

    return 
HAM_IGNORED;

__________________
Bugsy is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-14-2010 , 12:53   Re: Ham_TakeDamage
Reply With Quote #2

Also, note that second param is not the weapon, but the attacker himself, except if it's nade, in that case it's the nade index.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 03:44.


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