WasEventCancelled: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server client function}} This function checks whether or not the currently active event was canceled. This is mainly useful for custom events created by scripts. ==Syntax== <...)
 
mNo edit summary
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool wasEventCanceled ( )   
bool wasEventCancelled ( )   
</syntaxhighlight>
</syntaxhighlight>


Line 21: Line 21:
         triggerEvent ( "onFlagPickup", source, thePlayer ) -- trigger our onFlagPickup event
         triggerEvent ( "onFlagPickup", source, thePlayer ) -- trigger our onFlagPickup event
          
          
         if ( not wasEventCanceled() ) then -- if the handler for the event didn't cancel it then
         if ( not wasEventCancelled() ) then -- if the handler for the event 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

Revision as of 16:30, 2 December 2007

This function checks whether or not the currently active event was canceled. This is mainly useful for custom events created by scripts.

Syntax

bool wasEventCancelled ( )   

Returns

Returns true if the event was canceled, 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", "thePlayer" )

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 the handler for the event didn't cancel it then
            setElementData ( thePlayer, "hasFlag", true ) -- set that the player picked up the flag
        end
    end
end
addEventHandler ( "onMarkerHit", getRootElement(), flagHitCheck )

See Also