WasEventCancelled: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m (Edited language change) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | {{Server client function}} | ||
Events can be cancelled using [[cancelEvent]], this indicates that the resource | This function checks if the last completed event was cancelled. This is mainly useful for custom events created by scripts. | ||
Events can be cancelled using [[cancelEvent]], this indicates that the resource which triggered the event should do whatever it can to reverse any changes made by whatever caused the event. See [[triggerEvent]] for a more detailed explanation of this. | |||
==Syntax== | ==Syntax== | ||
Line 11: | Line 12: | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if the event was | Returns ''true'' if the event was cancelled, ''false'' if it wasn't or doesn't exist. | ||
==Example== | ==Example== | ||
This example implements a custom event ''onFlagPickup'' that would be triggered if an ''onMarkerHit'' event was triggered on a marker whose parent was a ''flag'' element. If the event isn't canceled then an element data value is set on the player. | This example implements a custom event ''onFlagPickup'' that would be triggered if an ''onMarkerHit'' event was triggered on a marker whose parent was a ''flag'' element. If the event isn't canceled then an element data value is set on the player. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
addEvent ( "onFlagPickup", | addEvent ( "onFlagPickup", true ) | ||
function flagHitcheck ( thePlayer ) | function flagHitcheck ( thePlayer ) | ||
Line 23: | Line 24: | ||
triggerEvent ( "onFlagPickup", source, thePlayer ) -- trigger our onFlagPickup event | triggerEvent ( "onFlagPickup", source, thePlayer ) -- trigger our onFlagPickup event | ||
if ( not wasEventCancelled() ) then -- if | if ( not wasEventCancelled() ) then -- if handlers for 'onFlagPickup' didn't cancel it then | ||
setElementData ( thePlayer, "hasFlag", true ) -- set that the player picked up the flag | setElementData ( thePlayer, "hasFlag", true ) -- set that the player picked up the flag | ||
end | end | ||
Line 33: | Line 34: | ||
==See Also== | ==See Also== | ||
{{Event functions}} | {{Event functions}} | ||
[[ru:wasEventCancelled]] |
Latest revision as of 11:51, 8 June 2022
This function checks if the last completed event was cancelled. This is mainly useful for custom events created by scripts.
Events can be cancelled using cancelEvent, this indicates that the resource which triggered the event should do whatever it can to reverse any changes made by whatever caused the event. See triggerEvent for a more detailed explanation of this.
Syntax
bool wasEventCancelled ( )
Returns
Returns true if the event was cancelled, false if it wasn't or doesn't exist.
Example
This example implements a custom event onFlagPickup that would be triggered if an onMarkerHit event was triggered on a marker whose parent was a flag element. If the event isn't canceled then an element data value is set on the player.
addEvent ( "onFlagPickup", true ) function flagHitcheck ( thePlayer ) parentElement = getElementParent ( source ) -- get the parent of the marker if ( getElementType ( parentElement ) == "flag" ) then -- if it was a flag element then triggerEvent ( "onFlagPickup", source, thePlayer ) -- trigger our onFlagPickup event if ( not wasEventCancelled() ) then -- if handlers for 'onFlagPickup' didn't cancel it then setElementData ( thePlayer, "hasFlag", true ) -- set that the player picked up the flag end end end addEventHandler ( "onMarkerHit", getRootElement(), flagHitCheck )