Raised This Month: $ Target: $400
 0% 

Tracing damage indicator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 10-21-2010 , 20:30   Tracing damage indicator
Reply With Quote #1

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!
Lulu the hero is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 10-22-2010 , 08:20   Re: Tracing damage indicator
Reply With Quote #2

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.
__________________
Hunter-Digital is offline
Lulu the hero
Senior Member
Join Date: Oct 2009
Location: Budapest, Hungary
Old 10-26-2010 , 18:22   Re: Tracing damage indicator
Reply With Quote #3

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.
Lulu the hero is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-26-2010 , 18:25   Re: Tracing damage indicator
Reply With Quote #4

Quote:
Originally Posted by Hunter-Digital View Post
message_* can't be hooked, emessage_* can.

If other plugins use that you can't hook them unless they're emessage_*.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-27-2010 , 01:45   Re: Tracing damage indicator
Reply With Quote #5

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.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 10-27-2010 at 01:47.
ConnorMcLeod is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 10-27-2010 , 05:03   Re: Tracing damage indicator
Reply With Quote #6

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

Anyway, nice method
__________________
Hunter-Digital is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-27-2010 , 12:35   Re: Tracing damage indicator
Reply With Quote #7

I don't think there is anything to round, even if health is a float
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 10:28.


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