- Documentation
- Shared functions
- cancelEvent
Function
cancelEvent
Cancels the current event from inside its handler. For events that allow it, it blocks the default action, e.g. onPlayerChat (the message will not appear in chat), onPickupHit (the pickup will not be collected), onVehicleStartEnter (the player will not get in). Other handlers still run and can check the state with wasEventCancelled. On the server you can give a reason, readable with getCancelReason.
Syntax
bool cancelEvent([bool cancel = true, string reason = ""])Arguments
cancelbool, optional = true- Server only:
false= do nothing.Not in MTA:SA reasonstring, optional = ""- Server only: the cancellation reason.Not in MTA:SA
Differences from MTA:SA
- Arguments in a different colour differ from MTA:SA.
In MTA:SA
cancelEvent()Returns
true when called during an event.
Example
addEventHandler("onPlayerChat", root, function(message)
if message:find("http") then
cancelEvent()
outputChatBox("Linki sa zablokowane", source, 255, 0, 0)
end
end)
See also
wasEventCancelledChecks whether the current event was cancelled withcancelEventin an earlier handler; outside an event - whether the last event was cancelled.getCancelReasonReturns the reason given incancelEvent(true, reason)by the last event cancellation, e.g. the reason for rejecting a connection inonPlayerConnect.