AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Ham_TakeDamage (https://forums.alliedmods.net/showthread.php?t=126804)

z-@T 05-13-2010 16:58

Ham_TakeDamage
 
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.

wrecked_ 05-13-2010 17:00

Re: Ham_TakeDamage
 
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.

Bugsy 05-13-2010 18:16

Re: Ham_TakeDamage
 
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.

z-@T 05-14-2010 04:00

Re: Ham_TakeDamage
 
Thanks for the info, I'll start changing my code right away.

Bugsy 05-14-2010 08:44

Re: Ham_TakeDamage
 
Quote:

Originally Posted by z-@T (Post 1179700)
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;



ConnorMcLeod 05-14-2010 12:53

Re: Ham_TakeDamage
 
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.


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

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