Raised This Month: $ Target: $400
 0% 

Damage Absorption


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 06-08-2010 , 08:53   Damage Absorption
Reply With Quote #1

I'm trying to manipulate the damage absorption towards the armor. I'm going to base it around how Natural Selection Armor system works. (Here's the site about the Armor System in NS http://www.unknownworlds.com/ns/stat...rmorSystem.htm)

I'm going for a 70% damage absorption with a 50% damage negation. This is my code so far...

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <cstrike>
#include <hamsandwich>
#include <fun>

public plugin_init() 
{
    
register_plugin("Tester ""1.0""Mazza")
    
RegisterHam(Ham_TakeDamage,"player""bacon_takedamage")
}

public 
bacon_takedamage(victiminflictorattackerFloat:Damagedamagetype)
{
    if(
damagetype DMG_GENERIC || victim == attacker || !is_user_alive(victim) || !is_user_connected(attacker))
        return 
HAM_IGNORED

    
new CurrentHealth get_user_health(victim)
    new 
CsArmorTypeArmorTypeCurrentArmor cs_get_user_armor(victimArmorType)

    if(
CurrentArmor)
    {
        new 
FloatDamageAbsorptionFloatDamageNegation
        DamageAbsorption 
CurrentArmor - (Damage 0.7)
        
DamageNegation CurrentHealth - (DamageAbsorption 0.5)

        if(
DamageAbsorption 0
            
Damage += CurrentArmor
        
if(DamageNegation 0
            
Damage += CurrentHealth

        cs_set_user_armor
(victimclamp(CurrentArmor0255), ArmorType)
        
set_user_health(victimclamp(CurrentHealth0255))
        
        
SetHamParamFloat(4Damage)

        
client_print(attackerprint_chat"[Test] Damage: %f Armor Damage: %f, Heatlh Damage, %f"DamageDamageAbsorptionDamageNegation)
    }
    
    return 
HAM_IGNORED

__________________
It's a mystery.
Mini_Midget is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-08-2010 , 09:01   Re: Damage Absorption
Reply With Quote #2

Are you asking a question or are you just showing the code?
Code:
        SetHamParamFloat(4, Damage)         client_print(attacker, print_chat, "[Test] Damage: %f Armor Damage: %f, Heatlh Damage, %f", Damage, DamageAbsorption, DamageNegation)         return HAM_HANDLED     }
__________________

Last edited by Bugsy; 06-08-2010 at 09:16.
Bugsy is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 06-08-2010 , 09:41   Re: Damage Absorption
Reply With Quote #3

Asking a question and for some help...
That code is just how far I've gotten.
It's not manipulating the damage how I want to.
Say....
I do 75 damage on a player with 100hp and 100ap.

It should calculate 70% of the damage (75*0.7 = 52.5).
This is the damage absorbed.

The remaining 30% of the damage (75*0.3 = 22.5) should minus the players hp. (100 - 22.5 = 77.5)

With the damage absorbed values, it should half it (52.5 / 2 = 26.25) and deduct it from the player's armor. (100 - 26.26 = 73.75)

If player A with 100hp and 100ap gets damaged by 75. Player A should be left with 77.5hp and 73.75ap.

(I know the Engine will round the values in the end so I don't bother with it within the code)
__________________
It's a mystery.
Mini_Midget is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-08-2010 , 13:43   Re: Damage Absorption
Reply With Quote #4

I think the easiest way is to determine the damage/reduction values for health and armor (based on a % of damage passed to TakeDamage) and set the users health/armor accordingly and then return HAM_SUPERCEDE so the actual damage passed in HamTakeDamage does not affect the player. The damage passed to TakeDamage, as you probably already know, is total damage without factoring armor so altering the value (SetHamParamFloat()) doesn't give you any control over how it is distributed by the engine (inflicted to hp or armor).

Something like this, untested.
PHP Code:
public fw_HamTakeDamageiVictim iInflictor iAttacker Float:fDamage iDmgBits )
{
    new 
iDmgHP floatroundfDamage 0.3 );
    new 
iDmgArmor floatround( ( fDamage 0.7 ) * 0.5 ); //or 0.35
    
new iHealth get_user_healthiVictim );

    
set_user_armoriVictim clampget_user_armoriVictim ) - iDmgArmor 100 ) );
    ( ( 
iHealth iDmgHP ) <= ) ? user_killiVictim ) : set_user_healthiVictim iHealth iDmgHP );

    return 
HAM_SUPERCEDE;
}

or

public 
fw_HamTakeDamageiVictim iInflictor iAttacker Float:fDamage iDmgBits )
{
    new 
iDmgHP floatroundfDamage 0.3 );
    new 
iDmgArmor floatround( ( fDamage 0.7 ) * 0.5 ); //or 0.35
    
new iHealth get_user_healthiVictim );
 
    if ( ( 
iHealth iDmgHP ) <= )    
    {
        
//enough damage to kill player so a deathmsg is displayed
        
SetHamParamFloat500.0 );
        return 
HAM_HANDLED;
    }
    else
    {
        
set_user_healthiVictim iHealth iDmgHP );
        
set_user_armoriVictim clampget_user_armoriVictim ) - iDmgArmor 100 ) );
        return 
HAM_SUPERCEDE;    
    }

__________________

Last edited by Bugsy; 06-08-2010 at 21:58.
Bugsy is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 06-14-2010 , 05:54   Re: Damage Absorption
Reply With Quote #5

Thanks Bugsy!

Exactly what I was trying to do!
Was quickly testing yours and noticed that when you are hit, players don't spill blood or slow down so I just moved some things around and added a few things.
The only downside to this is when you are using a 3rd party plugin which displays the damage dealt to the victim. It doesn't display anything until the last hit where the victim drops dead. Anyway around this if that is possible?

PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <hamsandwich>
#include <fun>

public plugin_init() 
{
    
register_plugin("Damage Absorption ""1.0""Mazza")
    
RegisterHam(Ham_TakeDamage,"player""fw_HamTakeDamage")
}

public 
fw_HamTakeDamageiVictim iInflictor iAttacker Float:fDamage iDmgBits 

    
// client_print(iVictim, print_chat, "Dmg Type: %i", iDmgBits)

    
if(iDmgBits DMG_GENERIC || /*iVictim == iAttacker ||*/ !is_user_alive(iVictim) || !is_user_connected(iAttacker)) 
        return 
HAM_IGNORED 

    
new iDmgHP floatroundfDamage 0.3 ); 
    new 
iDmgArmor floatround( ( fDamage 0.7 ) * 0.5 ); //or 0.35 
    
new iHealth get_user_healthiVictim ); 
    new 
CsArmorTypeArmorTypeiArmor cs_get_user_armoriVictimArmorType)

    if(
iArmor)
    {
        if ( ( 
iHealth iDmgHP ) <= )     
        { 
            
//enough damage to kill player so a deathmsg is displayed 
            
SetHamParamFloatfDamage ); 
            return 
HAM_HANDLED
        } 
        else 
        { 
            
ExecuteHam(Ham_TakeDamageiVictimiInflictoriAttacker0.0DMG_BULLET DMG_NEVERGIB);
            
set_user_healthiVictim iHealth iDmgHP ); 
            
cs_set_user_armoriVictim clampiArmor iDmgArmor 100 ), ArmorType ); 
            return 
HAM_SUPERCEDE;     
        } 
    }
    
    return 
HAM_IGNORED

__________________
It's a mystery.
Mini_Midget is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-14-2010 , 20:50   Re: Damage Absorption
Reply With Quote #6

Quote:
Originally Posted by Mini_Midget View Post
The only downside to this is when you are using a 3rd party plugin which displays the damage dealt to the victim. It doesn't display anything until the last hit where the victim drops dead. Anyway around this if that is possible?
This works for me.

If you are concerned with that we will also need to correct the damage value displayed since we are modifying the issued damage. Setting the damage amount to pev_dmg_take in TakeDamage-post will alter what amx_super displays as damage; it will work in TakeDamage pre as well but the value is not always accurate. I can't guarantee it will work for all damage-display plugins but you can experiment.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <hamsandwich>
#include <fun>

new Float:fDisplayDamage33 ];

public 
plugin_init() 
{
    
register_plugin("Damage Absorption ""1.0""Mazza")
    
    
RegisterHam(Ham_TakeDamage,"player""fw_HamTakeDamage")
    
RegisterHam(Ham_TakeDamage,"player""fw_HamTakeDamage_Post" )
}

public 
fw_HamTakeDamage_PostiVictim iInflictor iAttacker Float:fDamage iDmgBits 

    if ( 
fDisplayDamageiVictim ] )
    {
        
set_peviVictim pev_dmg_take fDisplayDamageiVictim ] );
        
fDisplayDamageiVictim ] = 0.0;
    }
}

public 
fw_HamTakeDamageiVictim iInflictor iAttacker Float:fDamage iDmgBits 

    if ( 
iDmgBits DMG_GENERIC || /*iVictim == iAttacker ||*/ !is_user_aliveiVictim ) || !is_user_connectediAttacker ) ) 
        return 
HAM_IGNORED;

    new 
CsArmorTypeArmorTypeiArmor cs_get_user_armoriVictim ArmorType );
    
    if( !
iArmor )
        return 
HAM_IGNORED;
        
    new 
iDmgHP floatroundfDamage 0.3 ); 
    new 
iDmgArmor floatround( ( fDamage 0.7 ) * 0.5 ); //or 0.35 
    
new iHealth get_user_healthiVictim );

    if ( ( 
iHealth iDmgHP ) > )
    { 
        
ExecuteHamHam_TakeDamage iVictim iInflictor iAttacker 0.0 DMG_BULLET DMG_NEVERGIB );
        
set_user_healthiVictim iHealth iDmgHP ); 
        
cs_set_user_armoriVictim clampiArmor iDmgArmor 100 ), ArmorType ); 
        
fDisplayDamageiVictim ] = floatiDmgHP );

        
//*** for testing ***
        
client_printprint_chat "Adjusted Damage = %d" iDmgHP );
        
        return 
HAM_SUPERCEDE;     
    } 
    
    return 
HAM_IGNORED

__________________

Last edited by Bugsy; 06-14-2010 at 23:13.
Bugsy is offline
Mini_Midget
Veteran Member
Join Date: Jan 2006
Location: It's a mystery.
Old 06-17-2010 , 06:01   Re: Damage Absorption
Reply With Quote #7

Mm... Works for what I use on my server.
Just one quick question before I'm (hopefully) done with this.
I've never used pev_dmg_take and nor have I seen it been used.
Can you kindly explain to me whats it purposes are?

Thanks again, Bugsy!
__________________
It's a mystery.
Mini_Midget is offline
Reply



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 05:26.


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