AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Tracing damage indicator (https://forums.alliedmods.net/showthread.php?t=141282)

Lulu the hero 10-21-2010 20:30

Tracing damage indicator
 
Hi everyone!

I was looking for new methods of filtering damage recieving for my damage_displayer.sma, and I've had an interesting idea.

I would like to hook the state, where the user has a damage indication red paralelogram around the cursor. I know that hamsandwich's damage hook has a damage_type parameter, but what of the situations, where damage is composed of the following two steps:
1) set user's health directly
2) put a DMG_BULLET indication on it's HUD.

Like in monstermod, or in zp_extra_lasermine, or in much other plugins.

First of all, I've tried invoking it, and came up with the code below:
PHP Code:

#include <amxmodx>
#include <fakemeta>

new msgid_damage;

public 
plugin_init() {
    
msgid_damage get_user_msgid("Damage");
    
    
register_forward(FM_PlayerPreThink,"fw_playerPreThink",1);
}

public 
fw_playerPreThink(id){
    static 
buttons;
    
    
buttons pev(id,pev_button);
    
    if(
buttons&IN_ATTACK){
        
message_begin(MSG_ONE_UNRELIABLEmsgid_damage_id)
        
write_byte(5// damage save
        
write_byte(10// damage take
        
write_long(DMG_BULLET// damage type
        
write_coord(1// x
        
write_coord(1// y
        
write_coord(1// z
        
message_end()
    }


And hurray, we have "damage" all over us. :)

But how to hook this.

I've tried the code below:
PHP Code:

//in plugin_init:
register_message(msgid_damage,"message_damage");

public 
message_damage(msg_id,msg_dest,msg_ent){
    static 
damagedamage_type;
    
    
damage get_msg_arg_int(2);
    
damage_type get_msg_arg_int(3);
    
    
client_print(msg_ent,print_chat,"damage: %d, type: %d",damage,damage_type);
    
    return 
PLUGIN_CONTINUE;


But the code above only displays, when damage is "properly" invoked - not as explaned above. Plus, at any damage, the damage type is 0. We need special damage, eg. drowning in water to get a 16384 value(1<<14), which is DMG_DROWN according to hldsk_const.inc .

So how can I hook a MSG_ONE_UNRELIABLE? Or any other ideas on how to track if the user has the damage on their screen?

Thanks guys in advance!

Hunter-Digital 10-22-2010 08:20

Re: Tracing damage indicator
 
You're having problems hooking your own messages or what ?

message_* can't be hooked, emessage_* can.

If other plugins use that you can't hook them unless they're emessage_*.

Ham_TakeDamage would be the best way, that triggers whenever player takes real damage.
Hooking health msg could also work and you can get the dmg type from an offset (I think).

If that's not it, then I don't really understand what you want.

Lulu the hero 10-26-2010 18:22

Re: Tracing damage indicator
 
Oh, sorry, forgot to mention. I am trying to avoid hamsandwich, so my plugin would be applyable to mods as sven-coop, where there is no linux libraries( yet ), so hamsandwich could not be written fully. And Ham_TakeDamage also doesn't work.

Exolent[jNr] 10-26-2010 18:25

Re: Tracing damage indicator
 
Quote:

Originally Posted by Hunter-Digital (Post 1331609)
message_* can't be hooked, emessage_* can.

If other plugins use that you can't hook them unless they're emessage_*.


ConnorMcLeod 10-27-2010 01:45

Re: Tracing damage indicator
 
To make the game itself send a Damage event, all you have to do is to set properly pev_dmg_take, m_bitsDamageType and pev_dmg_inflictor, Damage message will be sent at UpdateClientData :

Code:

        if (pev->dmg_take || pev->dmg_save || m_bitsHUDDamage != m_bitsDamageType)
        {
                // Comes from inside me if not set
                Vector damageOrigin = pev->origin;
                // send "damage" message
                // causes screen to flash, and pain compass to show direction of damage
                edict_t *other = pev->dmg_inflictor;
                if ( other )
                {
                        CBaseEntity *pEntity = CBaseEntity::Instance(other);
                        if ( pEntity )
                                damageOrigin = pEntity->Center();
                }

                // only send down damage type that have hud art
                int visibleDamageBits = m_bitsDamageType & DMG_SHOWNHUD;

                MESSAGE_BEGIN( MSG_ONE, gmsgDamage, NULL, pev );
                        WRITE_BYTE( pev->dmg_save );
                        WRITE_BYTE( pev->dmg_take );
                        WRITE_LONG( visibleDamageBits );
                        WRITE_COORD( damageOrigin.x );
                        WRITE_COORD( damageOrigin.y );
                        WRITE_COORD( damageOrigin.z );
                MESSAGE_END();
       
                pev->dmg_take = 0;
                pev->dmg_save = 0;
                m_bitsHUDDamage = m_bitsDamageType;
               
                // Clear off non-time-based damage indicators
                m_bitsDamageType &= DMG_TIMEBASED;
        }

From my gasnade plugin :

PHP Code:

TakeDamage(idiEntiAttackerFloat:flDmgiDmgBit)
{
    new 
Float:flHealth;
    
pev(idpev_healthflHealth);

    
flHealth -= flDmg;

    if( 
flHealth )
    {
        
ExecuteHamBHam_KilledidiAttacker);
        return;
    }

    
set_pev(idpev_healthflHealth);

    
set_pev(idpev_dmg_takeflDmg);
    
set_pdata_int(idm_bitsDamageTypeiDmgBit);
    
set_pev(idpev_dmg_inflictoriEnt);


This is an alternative to ExecuteHamB(Ham_TakeDamage so you know the exact damage done, because with Ham_TakeDamage you can't know the final damage.
Then the game will know that player has just taken damage and will send a Damage message with correct origins values.

Hunter-Digital 10-27-2010 05:03

Re: Tracing damage indicator
 
Hmm, how's the HUD health rounded, up or down ?
If it's up, I belive flHealth should be checked <= 0

Anyway, nice method :P

ConnorMcLeod 10-27-2010 12:35

Re: Tracing damage indicator
 
I don't think there is anything to round, even if health is a float :)


All times are GMT -4. The time now is 10:28.

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