AlliedModders

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

Mini_Midget 01-28-2007 01:14

damage event
 
Heres my damage event which works like life steal
PHP Code:

public event_damage_lifesteal(id)
{
    new 
damage read_data(2)
    new 
BodypartWeaponattacker get_user_attacker(idWeaponBodypart)
    
    if(!
is_user_alive(id) || !is_user_connected(id))
        return 
PLUGIN_CONTINUE
    
    
new current_hp get_user_health(attacker)
    new 
max_hp get_pcvar_num(zomb_hp)
    new 
life_steal floatround(float(current_hp) + (float(damage)))
    
    if(
g_zombie[attacker])
    {
        if(
current_hp max_hp
        {
            
set_user_health(attackermax_hp)
            } else {
            
current_hp += life_steal 
            
if(current_hp >= max_hp)
            {
                
current_hp max_hp
            
}
            
set_user_health(idcurrent_hp)
        }
    }
    return 
PLUGIN_CONTINUE


I'm trying to get rid of this bug where if your hp is below 90 and you stab then. You get like 140 hp instead of the maximum 100. But when I use this. This has no effect in the game.

lunarwolfx 01-28-2007 01:20

Re: damage event
 
Code:
new life_steal = floatround(float(current_hp) + (float(damage)))

Not that this would help your problem, but, isn't that the same as this:

Code:
new life_steal = current_hp + damage

You made them both floats, only to floatround afterwards?

Mini_Midget 01-28-2007 01:23

Re: damage event
 
yes it is the same but I'm not sure if damage can be a float or not so I just made it into a float then rounded it up to a integer

[ --<-@ ] Black Rose 01-28-2007 06:00

Re: damage event
 
Quote:

Originally Posted by Mini_Midget (Post 432546)
yes it is the same but I'm not sure if damage can be a float or not so I just made it into a float then rounded it up to a integer

That makes no sense at all. Neither does your code.
Now, try to explain, what is the ammount to give to who and we will be able to fix it.

bcas current_hp + current_hp + damage = new life? makes no sense.
If attacker has 70 hp and damage 35 it would be 70 + 70 + 35 = 175.
And on top of that, that gives the player who gets damaged extra life. This means no one would be able to kill anyone unless damage > 100.

This gives attacker +(damage/3) to life
so if attacker does 140 damage he gets 46 hp:
Code:
public event_damage_lifesteal(id) {         new damage = read_data(2)     new attacker = get_user_attacker(id)         if ( ! is_user_alive(id) || ! is_user_connected(id) )         return PLUGIN_CONTINUE         new current_hp = get_user_health(attacker)     new max_hp = get_pcvar_num(zomb_hp)         current_hp += damage / 3         if ( g_zombie[attacker] ) {         if ( current_hp >= max_hp )             set_user_health(attacker, max_hp)         else             set_user_health(attacker, current_hp)     }     return PLUGIN_CONTINUE }

Mini_Midget 01-28-2007 20:04

Re: damage event
 
thxs [ --<-@ ] Black Rose
works like a charm


All times are GMT -4. The time now is 00:41.

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