CancelEvent: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
{{Needs_Checking|I'm making assumptions here.. [[User:Erorr404|Erorr404]]}}
__NOTOC__
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 [[onPickupPickup]] event. cancelEvent is not compatible with all events. 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 canceled using [[wasEventCanceled]].


__NOTOC__
The use of cancelEvent outside of an event handler has no effect.
This function is used to stop events from occuring when they otherwise would. When a player walks over a pickup for example, this function can stop them from getting it. cancelEvent is not compatible with all events.
 
See individual event pages for information on the effect of canceling them, if any.


==Syntax==  
==Syntax==  
Line 8: Line 10:
bool cancelEvent ()   
bool cancelEvent ()   
</syntaxhighlight>
</syntaxhighlight>
===Usage===
cancelEvent must be called from inside an event handler (a function that is called when an event is triggered).
Here is a list of compatible events:
* onVehicleStartEnter


===Returns===
===Returns===
Returns ''true'' if the event was canceled successfully, ''false'' if the event is incompatible.
Always returns ''true''.


==Example==  
==Example==  

Revision as of 10:29, 11 September 2006

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 onPickupPickup event. cancelEvent is not compatible with all events. 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 canceled using wasEventCanceled.

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

See individual event pages for information on the effect of canceling them, if any.

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