- Documentation
- Server functions
- getCancelReason
Function
getCancelReason
Returns the reason given in cancelEvent(true, reason) by the last event cancellation, e.g. the reason for rejecting a connection in onPlayerConnect.
Syntax
string getCancelReason()Returns
The reason or an empty string.
Example
addEventHandler("onPlayerConnect", root, function(nick)
if nick:find("admin") then cancelEvent(true, "Zakazany nick") end
end)
addEventHandler("onPlayerConnect", root, function()
if wasEventCancelled() then outputServerLog("Odrzucono: " .. getCancelReason()) end
end)
See also
cancelEventCancels 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 withwasEventCancelled. On the server you can give a reason, readable withgetCancelReason.wasEventCancelledChecks whether the current event was cancelled withcancelEventin an earlier handler; outside an event - whether the last event was cancelled.