# cancelEvent (Shared)

> Marks the running event as cancelled. What cancelling prevents depends on the event.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Events
- **URL**: https://wiki.mymp.gg/en/cancelEvent

## Syntax

```lua
bool cancelEvent([bool cancel = true, string reason = ""])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `cancel` | `bool` | `true` cancels, `false` undoes a cancel made by an earlier handler. *(default: `true`)* |
| `reason` | `string` | The reason, read later with `getCancelReason`. *(default: `""`)* |

## Returns

`true` if it was marked, `false` if it was not called inside a handler.

Whoever triggered the event sees the result: `triggerEvent` returns `false` for a cancelled event.

## Example

```lua
local banned = { ["c3f1a2"] = true }

addEventHandler("onPlayerQueue", root, function(accountId)
    if banned[accountId] then
        cancelEvent(true, "banned")
    end
end)
```

### Note

The event's later handlers are still called.

## See also

- [wasEventCancelled (Shared)](https://wiki.mymp.gg/en/wasEventCancelled.md): Tells whether the last event that finished running on this side was cancelled.
- [getCancelReason (Shared)](https://wiki.mymp.gg/en/getCancelReason.md): Gives the reason passed to cancelEvent in the last event that finished running on this side.
- [triggerEvent (Shared)](https://wiki.mymp.gg/en/triggerEvent.md): Triggers an event on this side, on source. The element's own handlers and its ancestors' propagating ones are called right away, before the function returns.
