OnPlayerCommand: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 32: | Line 32: | ||
-- Add one to the table | -- Add one to the table | ||
end | end | ||
setTimer(function() commandSpam[source] = 0 end, 1000, 0) | |||
end | end | ||
addEventHandler("onPlayerCommand", root, preventCommandSpam) | addEventHandler("onPlayerCommand", root, preventCommandSpam) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
{{See also/Server event|Player events}} | {{See also/Server event|Player events}} | ||
Revision as of 18:43, 22 July 2017
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
Cancel effect
The command will not be executed
Example
This example prevents players executing more than 5 commands a second, recommended for all servers
local commandSpam = {}
function preventCommandSpam()
if (not commandSpam[source]) then
commandSpam[source] = 1
-- New person so add to table
elseif (commandSpam[source] == 5) then
cancelEvent()
outputChatBox("Please refrain from command spamming!", source, 255, 0, 0)
-- This person is command spamming!
else
commandSpam[source] = commandSpam[source] + 1
-- Add one to the table
end
setTimer(function() commandSpam[source] = 0 end, 1000, 0)
end
addEventHandler("onPlayerCommand", root, preventCommandSpam)
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