AlliedModders

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

bibu 06-19-2011 07:18

Float problem with Ham_TakeDamage
 
Alright, I am still not that friendly with floats. :oops:
Are the parameters right at all? The main problem is in "fm_set_user_health".

PHP Code:

public Ham_CBasePlayer_TakeDamage_Post(idpevInflictorpevAttackerFloat:flDamagebitsDamageType)
{
    if(
IsPlayer(pevAttacker) && is_user_connected(pevAttacker) && HasUserMirror(id) && id != pevAttacker)
    {
            new 
Float:damage_done Float:flDamage get_pcvar_num(md_hp_division)
        
            new 
Float:HP get_user_health(pevAttacker) - Float:damage_done
            
            
if(Float:HP 5.0)
            {
                
fm_set_user_health(pevAttackerfm_get_user_health(pevAttacker) - Float:damage_done)
                
fade_red(pevAttackerget_pcvar_num(md_fade_amount))
            }
    }
}

stock fm_set_user_health(idhealth)
{
    
health set_pev(idpev_healthfloat(health)) : dllfunc(DLLFunc_ClientKillid)
    return 
1
}

stock fm_get_user_health(id)
{
    return 
pev(idpev_health)



Exolent[jNr] 06-19-2011 07:56

Re: Float problem with Ham_TakeDamage
 
Use the functions from the fun module instead.
They are much faster.

PHP Code:

public Ham_CBasePlayer_TakeDamage_Post(idpevInflictorpevAttackerFloat:flDamagebitsDamageType)
{
    if(
IsPlayer(pevAttacker) && is_user_connected(pevAttacker) && HasUserMirror(id) && id != pevAttacker)
    {
            
// removed unnecessary forced float tag for flDamage
            // changed to get_pcvar_float()
            
new Float:damage_done flDamage get_pcvar_float(md_hp_division)
        
            
// float() for get_user_health() since it returns integer
            // removed unnecessary forced float tag for damage_done
            
new Float:HP float(get_user_health(pevAttacker)) - damage_done
            
            
// removed unnecessary forced float tag for HP
            
if(HP 5.0)
            {
                
// changed to set_user_health()
                // redundant fm_get_user_health() calculation since HP variable contains that same calculation
                
set_user_health(pevAttackerfloatround(HP))
                
fade_red(pevAttackerget_pcvar_num(md_fade_amount))
            }
    }


Since this is a POST hook, you are hooking after the damage is already done to the player.
Therefore, you will be doing damage twice to the player.
You should hook this as a PRE hook and change the damage parameter.
Then you should hook it as POST and check if remaining health of the player is more than 5.


All times are GMT -4. The time now is 23:26.

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