AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Remaining Health on Damage (https://forums.alliedmods.net/showthread.php?t=144174)

ichiban 11-29-2010 22:18

Remaining Health on Damage
 
I am having trouble storing damage by attacker.

If the victim has 30 health and 120 damage is done to the victim, 120 damage is stored. I would like it to only save the remaining health as damage (30).

PHP Code:

public fwd_TakeDamage_Post(victiminflictorattackerFloat:damagedamage_type)
{
    
//This adds ALL of the damage given
    
iDamage[attacker] += damage


How can I check the remaining health of the victim to check if damage is greater?

Exolent[jNr] 11-29-2010 22:24

Re: Remaining Health on Damage
 
Code:
#include < amxmodx > #include < fakemeta > #include < hamsandwich > const MAX_PLAYERS = 32; new Float:g_flTakeDamage_Health[ MAX_PLAYERS + 1 ]; public plugin_init( ) {     RegisterHam( Ham_TakeDamage, "player", "FwdPlayerDamage" );     RegisterHam( Ham_TakeDamage, "player", "FwdPlayerDamagePost", 1 ); } public FwdPlayerDamage( iVictim, iInflictor, iAttacker, Float:flDamage, iDamageType ) {     // save player's health before the damage is done     pev( iVictim, pev_health, g_flTakeDamage_Health[ iVictim ] ); } public FwdPlayerDamagePost( iVictim, iInflictor, iAttacker, Float:flDamage, iDamageType ) {     // gets real damage that was affected by armor     // flDamage in the forward params does not have the armor-affected value     // you can only get this in POST hook (not PRE)     new Float:flRealDamage;     pev( iVictim, pev_dmg_take, flRealDamage );         // the amount of health taken from the player     new Float:flHealthTaken = floatmin( flRealDamage, g_flTakeDamage_Health[ iVictim ] ); }

ichiban 11-29-2010 23:27

Re: Remaining Health on Damage
 
Thank you for this. It is working.

It does not include HE grenade damage. How can I include it?

Exolent[jNr] 11-29-2010 23:48

Re: Remaining Health on Damage
 
Quote:

Originally Posted by ichiban (Post 1359971)
Thank you for this. It is working.

It does not include HE grenade damage. How can I include it?

Yes, it does. Show your code.

ichiban 11-30-2010 01:34

Re: Remaining Health on Damage
 
Quote:

Originally Posted by Exolent[jNr] (Post 1359975)
Yes, it does. Show your code.

Here it is
PHP Code:

#include < amxmodx >

#include < fakemeta >
#include < hamsandwich >

const MAX_PLAYERS 32;

new 
iDamage[33]

new 
Float:g_flTakeDamage_HealthMAX_PLAYERS ];

public 
plugin_init( )
{
    
RegisterHamHam_TakeDamage"player""FwdPlayerDamage" );
    
RegisterHamHam_TakeDamage"player""FwdPlayerDamagePost");
    
    
register_clcmd("say /damage","showDamage");
}

public 
FwdPlayerDamageiVictimiInflictoriAttackerFloat:flDamageiDamageType )
{
    
// save player's health before the damage is done
    
peviVictimpev_healthg_flTakeDamage_HealthiVictim ] );
}

public 
FwdPlayerDamagePostiVictimiInflictoriAttackerFloat:flDamageiDamageType )
{
    
// gets real damage that was affected by armor
    // flDamage in the forward params does not have the armor-affected value
    // you can only get this in POST hook (not PRE)
    
new Float:flRealDamage;
    
peviVictimpev_dmg_takeflRealDamage );
    
    
// the amount of health taken from the player
    
new Float:flHealthTaken floatminflRealDamageg_flTakeDamage_HealthiVictim ] );
    
    
//Add to total damage
    
new num floatround(flHealthTaken)
    
iDamage[iInflictor] += num;
}

public 
showDamage(id)
{
    
client_print(idprint_chat"Total Damage: %i"iDamage[id]);



ConnorMcLeod 11-30-2010 01:51

Re: Remaining Health on Damage
 
You could directly work in Post TakeDamage and only check pev(victim, pev_dmg_take) and take it as an integer.

This should be ok :

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"
#define PLUGIN ""

#define FIRST_PLAYER_ID    1
#define MAX_PLAYERS        32
new g_iMaxPlayers
#define IsPlayer(%1)    ( FIRST_PLAYER_ID <= %1 <= g_iMaxPlayers )

new g_iDamage[MAX_PLAYERS+1]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
RegisterHam(Ham_Spawn"player""Ham_CBasePlayer_Spawn_Post"1)
    
RegisterHam(Ham_TakeDamage"player""CBasePlayer_TakeDamage_Post"1)
    
g_iMaxPlayers get_maxplayers()
}

public 
Ham_CBasePlayer_Spawn_Postid )
{
    
g_iDamage[id] = 0
}

public 
CBasePlayer_TakeDamage_Post(idiInflictoriAttackerFloat:flDamagebitsDamageType)
{
    if( 
id != iAttacker && IsPlayer(iAttacker) && cs_get_user_team(id) != cs_get_user_team(iAttacker) )
    {
        
g_iDamage[iAttacker] += pev(idpev_dmg_take)

        if( !
is_user_alive(id) )
        {
            
g_iDamage[iAttacker] += get_user_health(id)
        }
    }    



Anyway, i think csx module already provides some natives that could give you exactly what you want.


All times are GMT -4. The time now is 11:17.

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