Raised This Month: $ Target: $400
 0% 

Ham_TakeDamage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
z-@T
New Member
Join Date: May 2010
Old 05-13-2010 , 16:58   Ham_TakeDamage
Reply With Quote #1

Ok, here's the problem:
I have this code:

PHP Code:
public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
RegisterHam(Ham_TakeDamage"player""eventTakeDamage");
    
RegisterHam(Ham_Spawn"player""eventSpawn");
}

public 
eventSpawn(id)
{
    
dmgPlayer 0;
    return 
PLUGIN_CONTINUE;
}

public 
eventTakeDamage(idweaponattackerFloat:damagedamagebits)
{
    
dmgPlayer += damage;
    
get_user_name(idVictimName29);
    if(
attacker != && attacker != id)
    {
        
client_print(attackerprint_chat"You have done %i damage to %s!"dmgPlayerVictimName);
    }
    return 
PLUGIN_HANDLED;

And now the problem is that eventTakeDamage function prints me "You have done 1026698563 damage to r0cc0".

I'm sure you noticed that it's quite impossible for me to have made r0cc0 that much damage, but that is what the message returned.

I have other mistakes with the code too, but nothing I can't handle so this is the main problem.

Hope you help.
z-@T is offline
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 05-13-2010 , 17:00   Re: Ham_TakeDamage
Reply With Quote #2

That code isn't even close to what you'll need to simulate something like that.

http://forums.alliedmods.net/showthread.php?t=121028

You can work off of that, though there are improvements I will be making shortly to the code. None of the improvements are too significant, so you should just work off the code that's there.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2010 , 18:16   Re: Ham_TakeDamage
Reply With Quote #3

dmgPlayer needs to be defined as float. Also, accurate damage can be obtained with pev_dmg_take; the damage passed to ham takedamage is full damage without considering armor that the player may have.
__________________
Bugsy is offline
z-@T
New Member
Join Date: May 2010
Old 05-14-2010 , 04:00   Re: Ham_TakeDamage
Reply With Quote #4

Thanks for the info, I'll start changing my code right away.
z-@T is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-14-2010 , 08:44   Re: Ham_TakeDamage
Reply With Quote #5

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 #6

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