Jump to content

cancelEvent not being streamed ??


Recommended Posts

Hey!

I have this script in a resource:

addEventHandler("onClientPlayerDamage", localPlayer, function () 
     --if checks... 
          cancelEvent() 
     --end 
end) 

And in another resource I have this

addEventHandler("onClientPlayerDamage", localPlayer, function (_, _, body, loss) 
     if body == 9 and not wasEventCancelled() then 
          setElementHealth(source, getElementHealth(source)-(loss*0.5) 
     end 
end) 

And it's not working... I mean, even if the first resource's event gets cancelled, the second one does not dettect that cancel.

I am sure it's cancelling because in another body parts it does not take health.

Link to comment
addEventHandler("onClientPlayerDamage", localPlayer, function (_, _, body, loss) 
     if body == 9 and not wasEventCancelled() then 
          setElementHealth(source, getElementHealth(source)-(loss*0.5) 
     end 
end) 

The "not" means if the event was NOT cancelled. But you want to check if it was. Also you should ensure the second EventHandler gets called after the first always. So use the priority argument (the first one is "normal" by default, so "normal-1" should work flawlessly):

addEventHandler("onClientPlayerDamage", localPlayer, function (_, _, body, loss) 
     if body == 9 and wasEventCancelled() then 
          setElementHealth(source, getElementHealth(source)-(loss*0.5) 
     end 
end, true, "normal-1") 

Link to comment
I want to give the players more damage if they were hit on the head, so if the damage event got cancelled I don't want the damage to be given...

So I must use NOT!

And that priority thing isn't working

<> :fadein:

addEventHandler("onClientPlayerDamage", localPlayer, function (_, _, body, loss) 
     if body == 9 and not wasEventCancelled() then 
          setElementHealth(source, getElementHealth(source) - 1 ) 
     end 
end 
) 
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...