# onPlayerCommand (Server)

> Fired when a player sends a command to the server, before it runs. Cancelling the event stops the command.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Server
- **Category**: Keyboard
- **Cancellable**: `cancelEvent`
- **URL**: https://wiki.mymp.gg/en/onPlayerCommand

## Syntax

```lua
addEventHandler("onPlayerCommand", root, function(string command) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `command` | `string` | The command's name, without its arguments. |

## Source

The player who sent the command.

The client sends the server the commands no client script handled and the ones only the server runs, such as the resource commands. `executeCommandHandler` does not fire this event.

## Example

```lua
local lastCommand = {}

addEventHandler("onPlayerCommand", root, function(command)
    local now = getTickCount()
    if lastCommand[source] and now - lastCommand[source] < 500 then
        cancelEvent()
        return
    end
    lastCommand[source] = now
end)
```

## See also

- [addCommandHandler (Shared)](https://wiki.mymp.gg/en/addCommandHandler.md): Registers a function that runs when the command is typed in the console. The arguments arrive as space-separated strings.
- [executeCommandHandler (Server)](https://wiki.mymp.gg/en/executeCommandHandler-server.md): Runs the handlers server scripts registered for a command, as if the player had typed it.
- [cancelEvent (Shared)](https://wiki.mymp.gg/en/cancelEvent.md): Marks the running event as cancelled. What cancelling prevents depends on the event.
