CancelEvent

From Multi Theft Auto: Wiki
Revision as of 14:41, 31 May 2007 by EAi (talk | contribs)
Jump to navigation Jump to search

This function is used to stop the automatic internal handling of events, for exmaple this can be used to prevent an item being given to a player when they walk over a pickup, by canceling the onPickupUse event.

cancelEvent does not have an effect on all events, see the individual event's pages for information on what happens when the event is canceled. cancelEvent does not stop further event handlers from being called, as the order of event handlers being called is undefined in many cases. Instead, you can see if the currently active event has been cancelled using wasEventCanceled.

The use of cancelEvent outside of an event handler has no effect.

If you implement your own custom events and want to handle them being cancelled, you should call wasEventCanceled to check after your call to triggerEvent.

Syntax

bool cancelEvent ()   

Returns

Always returns true.

Example

This example stops the player huntedPlayer from entering a vehicle:

-- call 'stopVehicleEntry' whenever hunterPlayer is about to enter a vehicle:
addEventHandler ( "onVehicleStartEnter", huntedPlayer, "stopVehicleEntry" )
function stopVehicleEntry ( theplayer, seat, jacked )
   cancelEvent () -- stop the event from occuring
end

See Also