Raised This Month: $32 Target: $400
 8% 

Damage message, help with DamageType


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 09-06-2017 , 06:47   Damage message, help with DamageType
Reply With Quote #1

How do I use damagetype to filter out damage ONLY done by bullets?

Like this?
Code:
 register_event("Damage", "takedamage","b", "2>1", "3 = (1<<1)");
?

From hlsdk_const I found that list if damage types and for bullets it states:
Code:
 #define DMG_BULLET 1<<1
How do I use bitwise values in this case?
Or alternatively how could I read value of the third parameter and filter the rest with a simple if statement?
Reel mafioso is offline
killerZM
Senior Member
Join Date: Sep 2016
Old 09-06-2017 , 11:35   Re: Damage message, help with DamageType
Reply With Quote #2

i think this could be used in ham_takedamage
killerZM is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-06-2017 , 12:35   Re: Damage message, help with DamageType
Reply With Quote #3

register_event("Damage", "takedamage","b", "2>1", "3=2");
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 09-06-2017 , 14:32   Re: Damage message, help with DamageType
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
register_event("Damage", "takedamage","b", "2>1", "3=2");
I have tried that now and it doesn't work at all. The function just doesn't get called.
I even put client_print in it to check, but nothing happens.
Is there some other way I can hook a function to be called from only bullet damage?

Or possibly use ham_takedamage (which I don't know how to use) for the same purpose? (Would loading hamsandvich just for that one thing be worth it more than using register_event...)?
__________________
>Hurr use fakemeta xDDDD

Last edited by Reel mafioso; 09-06-2017 at 14:41.
Reel mafioso is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-06-2017 , 15:08   Re: Damage message, help with DamageType
Reply With Quote #5

Well using ham is better and simple.


Hook
PHP Code:
RegisterHam(Ham_Takedamage"player""player_taking_damage"

Function
PHP Code:
public player_taking_damage(victiminflictorattackerFloat:damageDamagebitsum)
{
       if(
Damagebitsum == 2)
       {
                 
/// code here
       
}

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-06-2017 at 15:14.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reel mafioso
Member
Join Date: Oct 2014
Location: wouldn't you like to kno
Old 09-06-2017 , 15:49   Re: Damage message, help with DamageType
Reply With Quote #6

Quote:
Originally Posted by Natsheh View Post
Well using ham is better and simple.


Hook
PHP Code:
RegisterHam(Ham_Takedamage"player""player_taking_damage"

Function
PHP Code:
public player_taking_damage(victiminflictorattackerFloat:damageDamagebitsum)
{
       if(
Damagebitsum == 2)
       {
                 
/// code here
       
}

Welp I tried it again and it still doesn't work.

Code:
public plugin_init()
{
        RegisterHam(Ham_TakeDamage, "player", "takedamage");
}
public takedamage(Victim, Useless, Attacker, Float:damage, damagebits)
{
if(damagebits == 2)
{
	health = get_user_health(Attacker);
	if(health == 100)
	{
		return HAM_HANDLED
	}
	if((health + (damage*0.5)) >=100)
	{
		set_user_health(Attacker, 100);
		return HAM_HANDLED
	}
	set_user_health(Attacker, floatround(((damage*0.6)+health)));
	emit_sound(Attacker, CHAN_WEAPON, "misc/arrow_impact_crossbow_heal.wav", 0.7, ATTN_NORM, 0, PITCH_NORM);
}
}
Even without the damagebits == 2 check it still doesn't work :L
Thanks for trying atleast!
My version with Damage message worked sorta, but the user would get healed if he took fall damage. Should I post the entire plugin instead?
__________________
>Hurr use fakemeta xDDDD
Reel mafioso is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-06-2017 , 16:41   Re: Damage message, help with DamageType
Reply With Quote #7

I suppose it should work fine


Code:
public plugin_init()
{
        RegisterHam(Ham_TakeDamage, "player", "takedamage");
}
public takedamage(Victim, Useless, Attacker, Float:damage, damagebits)
{
if(damagebits == 2)
{
	health = get_user_health(Attacker);
	
	if((health + (damage*0.5)) >=100)
	{
	        SetHamParamFloat(4, 0.0)
		return HAM_HANDLED
	}
	
        SetHamParamFloat(4, (damage*-0.5))
	emit_sound(Attacker, CHAN_WEAPON, "misc/arrow_impact_crossbow_heal.wav", 0.7, ATTN_NORM, 0, PITCH_NORM);
        return HAM_HANDLED;
}

rerurn HAM_IGNORED
}
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-06-2017 at 16:42.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
kristi
Senior Member
Join Date: Nov 2016
Old 09-06-2017 , 16:56   Re: Damage message, help with DamageType
Reply With Quote #8

Shouldn't it be (damagebits & DMG_BULLET) ?
kristi is offline
Send a message via Skype™ to kristi
Natsheh
Veteran Member
Join Date: Sep 2012
Old 09-06-2017 , 17:13   Re: Damage message, help with DamageType
Reply With Quote #9

Quote:
Originally Posted by kristi View Post
Shouldn't it be (damagebits & DMG_BULLET) ?
not really, read more about bitsums....

(damagebits & DMG_BULLET) its if damagebits contain 2 >> lets imagine thats damagebits carry this bitsum value which is 1111 and DMG_BULLET value its 2 which in bitsum its 0010

so the & operator works like this (1111 & 0010) will return this bitsum value 0010 which its 2.

and (damagebits == DMG_BULLET) this condition will only works when its only a bullet damage.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 09-06-2017 at 18:02.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-06-2017 , 17:58   Re: Damage message, help with DamageType
Reply With Quote #10

I agree with kristi, you should use bit-wise operators when working with bitsums. Yes, a direct == will work, but it's more proper to check the specific bit(s) you're looking for. If you are checking for multiple bits then you need to use equals on the result of the operation, such as: if ( ( BitSum & ( FLAG_1 | FLAG_2 ) ) == ( FLAG_1 | FLAG_2 ) ). This will ensure the result includes both bits, not only one or the other.

Also, 0100 is 4, 0010 (1<<1) is 2.

So to check for only bullet damage, if ( damagebits & DMG_BULLET ) is good.
__________________
Bugsy 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 20:21.


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