Raised This Month: $ Target: $400
 0% 

Mirror Damage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tm.
Member
Join Date: Apr 2010
Old 05-19-2010 , 12:46   Mirror Damage
Reply With Quote #1

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?
tm. is offline
unnyquee
Senior Member
Join Date: Jun 2009
Location: Constanta, Romania
Old 05-19-2010 , 13:07   Re: Mirror Damage
Reply With Quote #2

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

Last edited by unnyquee; 05-19-2010 at 13:24.
unnyquee is offline
tm.
Member
Join Date: Apr 2010
Old 05-19-2010 , 14:53   Re: Mirror Damage
Reply With Quote #3

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?
tm. is offline
FlyingHorse
Senior Member
Join Date: Apr 2010
Location: Under your bed.
Old 05-19-2010 , 16:00   Re: Mirror Damage
Reply With Quote #4

set_user_armor
FlyingHorse is offline
Send a message via Skype™ to FlyingHorse
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-19-2010 , 16:17   Re: Mirror Damage
Reply With Quote #5

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.
__________________
Bugsy is offline
tm.
Member
Join Date: Apr 2010
Old 05-19-2010 , 16:33   Re: Mirror Damage
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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.

Last edited by tm.; 05-19-2010 at 16:51.
tm. is offline
tm.
Member
Join Date: Apr 2010
Old 05-20-2010 , 09:01   Re: Mirror Damage
Reply With Quote #7

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?
tm. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2010 , 09:59   Re: Mirror Damage
Reply With Quote #8

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
__________________

Last edited by Bugsy; 05-20-2010 at 13:46.
Bugsy is offline
tm.
Member
Join Date: Apr 2010
Old 05-20-2010 , 11:06   Re: Mirror Damage
Reply With Quote #9

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 .
tm. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-20-2010 , 12:26   Re: Mirror Damage
Reply With Quote #10

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;

__________________

Last edited by Bugsy; 05-20-2010 at 13:44.
Bugsy is offline
Reply


Thread Tools
Display Modes

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:54.


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