Raised This Month: $51 Target: $400
 12% 

Problem with armor calculation Ham_TakeDamage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kavahns
Junior Member
Join Date: Dec 2017
Old 03-09-2024 , 07:23   Problem with armor calculation Ham_TakeDamage
Reply With Quote #1

Hey, for the past few days, I've been struggling to implement the functionality in my plugin that reads real damage inflicted by players and adds it to a table, excluding damage dealt to armor. I've noticed that I should use pev_dmg_take, but no matter how hard I try, I can't seem to get it to work. I also attempted to use the client_damage event, but with no success.
Is there somebody who knows how to do that?

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#define PLUGIN "Display Damage"
#define VERSION "1.0"
#define AUTHOR "unknown"
#define MAX_PLAYERS 32

new pCvarAllowCommand
new pCvarDisplayAttacksOnly
new pCvarAliveOnly
new pCvarExcludeBots

enum
{
    
iTaken,
    
iReceived
}

const 
MAX_HEALTH 100

new g_iHits[MAX_PLAYERS 1][MAX_PLAYERS 1]
new 
g_iDamage[MAX_PLAYERS 1][MAX_PLAYERS 1]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
pCvarDisplayAttacksOnly register_cvar("dmg_display_attacksonly""1")
    
pCvarAliveOnly register_cvar("dmg_cmd_alive_only""1")
    
pCvarAllowCommand register_cvar("dmg_cmd_allow""1")
    
pCvarExcludeBots register_cvar("dmg_exclude_bots""0")

    
register_logevent("logevent_roundend",2,"1=Round_End")
    
    
    
    
RegisterHam(Ham_TakeDamage"player""ham_TakeDamage_Post"0)    
    
RegisterHam(Ham_Spawn"player""ham_PlayerSpawn"1)
}

public 
ham_PlayerSpawn(id)
{
    for (new 
isizeof g_iHitsi++)
    {
        
arrayset(g_iHits[i], 0sizeof g_iHits[])
    }

    for (new 
isizeof g_iDamagei++)
    {
        
arrayset(g_iDamage[i], 0sizeof g_iDamage[])
    }
}

public 
ham_TakeDamage_Post(iVictimiInflictoriAttackerFloat:fDamageiDamageBits)
{
    if(!
is_user_connected(iAttacker) || !is_user_connected(iVictim))
        return 
HAM_IGNORED
        
    g_iHits
[iAttacker][iVictim]++

    new 
iDamage FloatRound(fDamage), iVictimHealth get_user_health(iVictim);


    
g_iDamage[iAttacker][iVictim] += iDamage
    

    
return HAM_IGNORED;
}


public 
FloatRound(Float:value)
{
    return (
value >= 0.0) ? floatround(valuefloatround_floor) : -floatround(-valuefloatround_floor);
}


public 
logevent_roundend()
{
    new 
iPlayers[MAX_PLAYERS], iNum
    get_players
(iPlayersiNum)    
    for(new 
i;iNum;i++)
    {
        
displayDamage(iPlayers[i])
    }
}


public 
displayDamage(id)
{
    new 
iPlayers[MAX_PLAYERS], iNum
    
if (get_pcvar_num(pCvarExcludeBots))
        
get_players(iPlayersiNum"ch")
    else
        
get_players(iPlayersiNum"h")
    
    new 
team get_user_team(id)

    for(new 
iiPlayerszName[MAX_PLAYERS], iDmg[1],iHit[1];iNum;i++)
    {
        
iPlayer iPlayers[i]

        if(
iPlayer == id || get_user_team(iPlayer) == team)
            continue

        
iHit[0] = g_iHits[id][iPlayer// Hit Done
            
        
if(get_pcvar_num(pCvarDisplayAttacksOnly) && (!iHit[0]))
            continue
            
        
iDmg[0] = g_iDamage[id][iPlayer// Damage Done
                    
        
get_user_name(iPlayerszNamecharsmax(szName))
        
        
// Shorten szName if longer than 16 characters
        
copy(szNamemin(strlen(szName), 16), szName)
            
            new 
user_health;
        if (
is_user_alive(iPlayer)) {
            
user_health get_user_health(iPlayer)
            } else {
    
user_health 0
   
}

ChatColor(id" ^x01[^x04%i^x01 dmg / ^x04%i^x01 hits] - ^x03%s^x01 (^x04%i^x01 HP)"min(iDmg[0], MAX_HEALTH), iHit[0], szNameuser_health)

    }
}


ChatColor(const id, const input[], any:...)
{
    static 
mMessageSayText
    
if(!mMessageSayText)
    {
        
mMessageSayText get_user_msgid("SayText")
    }

        new 
iCount 1iPlayers[MAX_PLAYERS]
        static 
szMessage[192]
        
vformat(szMessagecharsmax(szMessage), input3)

        
replace_all(szMessagecharsmax(szMessage), "!g""^4")
        
replace_all(szMessagecharsmax(szMessage), "!y""^1")
        
replace_all(szMessagecharsmax(szMessage), "!t""^3")

        if(
id)     iPlayers[0] = id
    
else     get_players(iPlayersiCount"ch")
        
        for (new 
iplayeriCounti++)
        {
        
message_begin(MSG_ONE_UNRELIABLEmMessageSayText_, (player iPlayers[i]))
        
write_byte(player)
        
write_string(szMessage)
        
message_end()
        }

kavahns is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 03-09-2024 , 09:11   Re: Problem with armor calculation Ham_TakeDamage
Reply With Quote #2

Code:
public ham_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits)
{
    if(!is_user_connected(iAttacker) || !is_user_connected(iVictim))
        return HAM_IGNORED

    g_iHits[iAttacker][iVictim]++

    static iDamage; iDamage = floatround(fDamage);
    static iVictimHealth; iVictimHealth = get_user_health(iVictim);

    iVictimHealth -=iDamage

    g_iDamage[iAttacker][iVictim] += iDamage

    return HAM_IGNORED;
}
__________________
DJEarthQuake is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-09-2024 , 23:27   Re: Problem with armor calculation Ham_TakeDamage
Reply With Quote #3

If you're looking for the true damage (loss in HP) use pev( id , pev_dmg_take ), after the damage was issued -- takedamage post will be fine. The damage value passed through Ham_TakeDamage is total damage, which gets reduced by armor that the player may have.
__________________
Bugsy is offline
kavahns
Junior Member
Join Date: Dec 2017
Old 03-10-2024 , 20:07   Re: Problem with armor calculation Ham_TakeDamage
Reply With Quote #4

yes, correctly using pev_dmg_take is the answer. I was using it totally wrong for the past few days.
It works now
kavahns 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 14:43.


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