AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Damage message, help with DamageType (https://forums.alliedmods.net/showthread.php?t=301039)

Reel mafioso 09-06-2017 06:47

Damage message, help with DamageType
 
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?

killerZM 09-06-2017 11:35

Re: Damage message, help with DamageType
 
i think this could be used in ham_takedamage

Natsheh 09-06-2017 12:35

Re: Damage message, help with DamageType
 
register_event("Damage", "takedamage","b", "2>1", "3=2");

Reel mafioso 09-06-2017 14:32

Re: Damage message, help with DamageType
 
Quote:

Originally Posted by Natsheh (Post 2547093)
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...)?

Natsheh 09-06-2017 15:08

Re: Damage message, help with DamageType
 
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
       
}



Reel mafioso 09-06-2017 15:49

Re: Damage message, help with DamageType
 
Quote:

Originally Posted by Natsheh (Post 2547145)
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?

Natsheh 09-06-2017 16:41

Re: Damage message, help with DamageType
 
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
}


kristi 09-06-2017 16:56

Re: Damage message, help with DamageType
 
Shouldn't it be (damagebits & DMG_BULLET) ?

Natsheh 09-06-2017 17:13

Re: Damage message, help with DamageType
 
Quote:

Originally Posted by kristi (Post 2547163)
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.

Bugsy 09-06-2017 17:58

Re: Damage message, help with DamageType
 
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.


All times are GMT -4. The time now is 09:56.

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