OnPlayerCommand
Jump to navigation
Jump to search
This event is triggered when a player issues a command.
Parameters
string command
Source
The source of this event is the player who tried to execute a command.
Result of cancelling this event
The command will not be executed.
Example
Click to collapse [-]
ServerThis example implements an anti-flood protection timer for commands
local CMD_INTERVAL = 200 --// The interval that needs to pass before the player can execute another cmd local KICK_AFTER_INTERVAL = 50 --// Kick the player if they execute more than 20 cmds/sec local executions = setmetatable({}, { --// Metatable for non-existing indexes __index = function(t, k) rawset(t, k, 0) return 0 end }) addEventHandler("onPlayerCommand", root, function() if (executions[source]-getTickCount()<=CMD_INTERVAL) then if (executions[source]-getTickCount()<=KICK_AFTER_INTERVAL) then kickPlayer(source, "Anti-Flood", "Don't flood") end cancelEvent() end executions[source] = getTickCount() end )
This example disables the hardcoded command 'whois'
addEventHandler("onPlayerCommand",root, function(command) if (command == "whois") then cancelEvent() end end)
See Also
Player events
- onPlayerACInfo
- onPlayerBan
- onPlayerChangeNick
- onPlayerChat
- onPlayerClick
- onPlayerCommand
- onPlayerConnect
- onPlayerContact
- onPlayerDamage
- onPlayerJoin
- onPlayerLogin
- onPlayerLogout
- onPlayerMarkerHit
- onPlayerMarkerLeave
- onPlayerModInfo
- onPlayerMute
- onPlayerNetworkStatus
- onPlayerPickupHit
- onPlayerPickupLeave
- onPlayerPickupUse
- onPlayerPrivateMessage
- onPlayerQuit
- onPlayerScreenShot
- onPlayerSpawn
- onPlayerStealthKill
- onPlayerTarget
- onPlayerUnmute
- onPlayerVehicleEnter
- onPlayerVehicleExit
- onPlayerVoiceStart
- onPlayerVoiceStop
- onPlayerWasted
- onPlayerWeaponFire
- onPlayerWeaponSwitch
Event functions
- addEvent
- addEventHandler
- cancelEvent
- cancelLatentEvent
- getEventHandlers
- getLatentEventHandles
- getLatentEventStatus
- removeEventHandler
- triggerEvent
- wasEventCancelled