AlliedModders

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

tm. 05-19-2010 12:46

Mirror Damage
 
Hi. I have this mirror damage plugin:
PHP Code:

#include <amxmodx>
#include <fun>

public plugin_init()
{
    
register_plugin("Mirror Damage""1.0.0""EKS")
    
register_event("Damage""Event_Damage""b""2!0""3=0""4!0")
}

public 
Event_Damage()
{
    new 
damage read_data(2)
    new 
victim read_data(0)
    new 
attacker get_user_attacker(victim)

    if(
get_user_team(victim) == get_user_team(attacker) && victim != attacker)
    {
        if (
is_user_alive(attacker))
        {
            new 
HP get_user_health(attacker) - damage

            
if(HP 0)
                
set_user_health(attackerHP)

            else
                
user_kill(attacker)
        
            new 
vName[32]
            
get_user_name(victimvName31)
            
client_print(attackerprint_chat"[AMXX] You team attacked %s and lost %d hp"vNamedamage)
        }

        if (
is_user_alive(victim))
        {
            new 
HP get_user_health(victim) + damage
            set_user_health
(victimHP)
        }
    }


My question: is it possible to block victim's death if the damage inflicted to the victim is greater then the victim's hp?

unnyquee 05-19-2010 13:07

Re: Mirror Damage
 
Yes, it is :).

PHP Code:

#include <amxmodx>
#include <hamsandwich>

new g_cDamageFactor

public plugin_init()
{
      
register_plugin("Mirror Damage""1.0.0""EKS");
      
      
g_cDamageFactor register_cvar("md_damage_factor""0.2");
      
      
RegisterHam(Ham_TakeDamage"player""Fwd_TakeDamage");
}

public 
Fwd_TakeDamage(iVictimiInflictoriAttackerFloat:flDamageiDamageBits)
{
      if((
get_user_team(iVictim) == get_user_team(iAttacker)) && (iVictim != iAttacker))
      {
            if(
get_user_health(iVictim) < flDamage)
                  
SetHamParamFloat(4flDamage get_pcvar_float(g_cDamageFactor));
      }
      
      return 
HAM_IGNORED;


Not tested and, if you want to implement this in a plugin, you'll have to optimize it as well.
I have written this in hurry and didn't have time to optimize.

tm. 05-19-2010 14:53

Re: Mirror Damage
 
Hmm, thanks, but not exactly what I need. I don't want to minimize the damage, I want to block victim's death even in the worst case scenario, let's say he has 1 hp and gets a headshot with awp.
And another question, related somehow to this: it's possible to restore the victim's armor, without using set_task?

FlyingHorse 05-19-2010 16:00

Re: Mirror Damage
 
set_user_armor

Bugsy 05-19-2010 16:17

Re: Mirror Damage
 
return HAM_SUPERCEDE will block all damage in Ham_TakeDamage.

When exactly and under what circumstances do you want to restore armor?

unnyquee, you need to return HAM_HANDLED for that to work. Also, damage passed to take_damage is total damage without factoring armor. Hooking take_damage post and using pev_dmg_take will return the actual reduction in victim hp.

tm. 05-19-2010 16:33

Re: Mirror Damage
 
Quote:

Originally Posted by Bugsy (Post 1185329)
When exactly and under what circumstances do you want to restore armor?

Same as HP, if the player is attacked by a teammate, but I guess with return HAM_SUPERCEDE in Ham_TakeDamage the player will not lose any armor?

LE: Yeap, it works, that's what I need. Thank you.

tm. 05-20-2010 09:01

Re: Mirror Damage
 
I hope this isn't interpreted as a bump, but I already stated in the post above that the problem was solved and just now realized that it's not, so nobody would'd noticed an edit.

So it's not possible to block the damage taken by the victim with HAM_SUPERCEDE and in the same time to get the correct damage (if victim has armor) so I could pass it to the attacker? Cause I tried something like this
PHP Code:

      RegisterHam(Ham_TakeDamage"player""fw_Damage"1)
}

public 
fw_Damage(victimattacker)
{
      if(
get_user_team(victim) == get_user_team(attacker) && victim != attacker && is_user_alive(attacker))
    {
        new 
iDamage pev(victimpev_dmg_take)

        new 
hp get_user_health(attacker) - iDamage

        
if(hp 0)
            
set_user_health(attackerhp)

        else
            
user_kill(attacker)

        new 
vName[32]
        
get_user_name(victimvName31)
        
client_print(attackerprint_chat"[AMXX] You team attacked %s and lost %d hp"vNameiDamage)
    }

    return 
HAM_SUPERCEDE


and it's obviously that it won't work.
And what's the thing with the inflictor param? I've tested it and notice that is 0 when not attacked by a player, 1...2 (i can test it only with two players so I guess it's the attacker's id, and 116 or 128 or other values maybe if the damage was made by a he grenade. If I'm right it's a safe way to detect he damage?

Bugsy 05-20-2010 09:59

Re: Mirror Damage
 
Inflictor is the entity id if damage caused by a nade.

Do you only need to inflict the damage on attacker? Or do you also want to record damage?

TakeDamage pre:

SetHamParamEntity( 1 , iAttacker )
return HAM_HANDLED

tm. 05-20-2010 11:06

Re: Mirror Damage
 
No, just to inflict the damage to the attacker. Can you give me more details about SetHamParamInt( 1 , iAttacker ), aka I have no idea what to do with it :).

Bugsy 05-20-2010 12:26

Re: Mirror Damage
 
Just put that in your ham takedamage pre (not post) forward.

PHP Code:

RegisterHamHam_TakeDamage"player""Fwd_TakeDamage");

public 
Fwd_TakeDamageiVictimiInflictoriAttackerFloatflDamageiDamageBits )
{
     if ( 
conditions )
     {
          
SetHamParamEntityiAttacker );
          return 
HAM_HANDLED;
     }

     return 
HAM_IGNORED;




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

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