AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   prevent a Ham registered event from going through (https://forums.alliedmods.net/showthread.php?t=232781)

striker07 01-04-2014 18:55

prevent a Ham registered event from going through
 
RegisterHam(Ham_TakeDamage, "player", "player_hurt_pre", 1)

as you can see, i hooked Ham_TakeDamage
when this fires and my condition to block the event from continuing its normal proces is met i return HAM_SUPERCEDE.

Unfortunatly this doesnt work and damage still goes through and the player still hits his target.
I need a full stop, how could i do that?

matsi 01-04-2014 20:04

Re: prevent a Ham registered event from going through
 
Code:
/**  * Stops a ham forward from triggering.  * Use the return value from RegisterHam as the parameter here!  *  * @param fwd           The forward to stop.  */ native DisableHamForward(HamHook:fwd); /**  * Starts a ham forward back up.  * Use the return value from RegisterHam as the parameter here!  *  * @param fwd           The forward to re-enable.  */ native EnableHamForward(HamHook:fwd);

fysiks 01-04-2014 21:01

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by striker07 (Post 2081197)
RegisterHam(Ham_TakeDamage, "player", "player_hurt_pre", 1)

as you can see, i hooked Ham_TakeDamage
when this fires and my condition to block the event from continuing its normal proces is met i return HAM_SUPERCEDE.

Unfortunatly this doesnt work and damage still goes through and the player still hits his target.
I need a full stop, how could i do that?

You can't stop a function when you hook it as post (like you are doing). You have to hook it as a prehook (aka post=0 or omit the last argument). So, if you hook it correctly, HAM_SUPERCEDE will work.

Quote:

Originally Posted by matsi (Post 2081221)
Code:
/**  * Stops a ham forward from triggering.  * Use the return value from RegisterHam as the parameter here!  *  * @param fwd           The forward to stop.  */ native DisableHamForward(HamHook:fwd); /**  * Starts a ham forward back up.  * Use the return value from RegisterHam as the parameter here!  *  * @param fwd           The forward to re-enable.  */ native EnableHamForward(HamHook:fwd);

He doesn't want to disable the forward, he wants to act on the event.

matsi 01-04-2014 21:14

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by fysiks (Post 2081235)
He doesn't want to disable the forward, he wants to act on the event.

Well i thought about that because of the last sentence:

Quote:

Originally Posted by striker07 (Post 2081197)
I need a full stop, how could i do that?

To be honest i don't really understand what he is trying to explain. :)

fysiks 01-04-2014 22:53

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by matsi (Post 2081245)
To be honest i don't really understand what he is trying to explain. :)

When someone is taking damage, he is checking to see if he wants the damage to actually be inflicted on that person. So, for example, if you wanted to make someone invincible, you would check if the person that is taking damage is that person. If yes, then you supercede the event so that they don't take any damage.

ConnorMcLeod 01-05-2014 05:06

Re: prevent a Ham registered event from going through
 
This is wrong : RegisterHam(Ham_TakeDamage, "player", "player_hurt_pre", 1)

Already stated by fysiks but you may understand better like this :


RegisterHam(Ham_TakeDamage, "player", "player_hurt_pre", 0) <- you can stop this one because you hook it before it is executed


RegisterHam(Ham_TakeDamage, "player", "player_hurt_post", 1) <- you can't stop this one because you hook it after it has been executed

matsi 01-05-2014 06:13

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by fysiks (Post 2081268)
When someone is taking damage, he is checking to see if he wants the damage to actually be inflicted on that person. So, for example, if you wanted to make someone invincible, you would check if the person that is taking damage is that person. If yes, then you supercede the event so that they don't take any damage.

Its funny. Reading it late last night it didn't make any sense but today after sleeping the first post makes sense to me when reading it again now. :lol:

striker07 01-05-2014 07:07

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by fysiks (Post 2081268)
When someone is taking damage, he is checking to see if he wants the damage to actually be inflicted on that person. So, for example, if you wanted to make someone invincible, you would check if the person that is taking damage is that person. If yes, then you supercede the event so that they don't take any damage.

Thats exactly what i tried to explain :).
Thanks for pointing out that i need to use 0 for pre and 1 for post, the discription sais the exact opposite :).

Also it's good to know that you guy's are still active here, you guys are like legends when it comes to this :)

Quote:

Originally Posted by matsi (Post 2081375)
Its funny. Reading it late last night it didn't make any sense but today after sleeping the first post makes sense to me when reading it again now. :lol:

it was late for me aswell yesterday when i posted my first message, i totally understand your pain :)

YamiKaitou 01-05-2014 07:12

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by striker07 (Post 2081407)
the discription sais the exact opposite

Why do people always think that? 0 means false and 1 means true. Therefore by putting 0, you are saying to NOT hook it as post.

ConnorMcLeod 01-05-2014 08:53

Re: prevent a Ham registered event from going through
 
Quote:

Originally Posted by striker07 (Post 2081407)
the discription sais the exact opposite

The description is correct :

Quote:

* @param post Whether or not to forward this in post.

native HamHook:RegisterHam(Ham:function, const EntityClass[], const Callback[], Post=0);



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

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