IsTimer: Difference between revisions
Jump to navigation
Jump to search
(→Syntax) |
(OOP syntax added) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
{{Server client function}} | {{Server client function}} | ||
This function checks if a variable is a [[timer]]. | This function checks if a variable is a [[timer]]. | ||
{{Note|This function is not reliable as timer ids are eventually recycled. Always make sure you nil variables containing a timer after it has expired.}} | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">bool isTimer ( timer theTimer )</syntaxhighlight> | <syntaxhighlight lang="lua">bool isTimer ( timer theTimer )</syntaxhighlight> | ||
{{OOP||[[timer]]:isValid|valid|}} | |||
===Required Arguments=== | ===Required Arguments=== | ||
* ''' | * '''theTimer''': The variable that we want to check. | ||
===Returns=== | ===Returns=== | ||
Line 23: | Line 23: | ||
if isTimer(antiSpam[source]) then -- Check if timer is running using isTimer (this is an example of its use and all) | if isTimer(antiSpam[source]) then -- Check if timer is running using isTimer (this is an example of its use and all) | ||
cancelEvent() -- If timer is running then cancel the event | cancelEvent() -- If timer is running then cancel the event | ||
outputChatBox("Sorry | outputChatBox("Sorry bro, you may only send 1 message a second to prevent spam.", source, 255, 255, 0) -- Message to player | ||
else | else | ||
antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) -- Timer lasting 1 second. | antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) -- Timer lasting 1 second. |
Latest revision as of 07:03, 12 July 2014
This function checks if a variable is a timer.
Syntax
bool isTimer ( timer theTimer )
OOP Syntax Help! I don't understand this!
- Method: timer:isValid(...)
- Variable: .valid
Required Arguments
- theTimer: The variable that we want to check.
Returns
Returns true if the passed value is a timer, false otherwise.
Example
Click to collapse [-]
ServerThis example uses isTimer to prevent players from using chat/teamchat/me more than once a second, to prevent spammers.
-- This anti spam is just an example and won't work if you have other scripts and game modes which manipulate chat, -- If you do then this script would need to be put with the other script/gamemode that handles chat else cancelEvent() won't work. antiSpam = {} -- This makes a table called antiSpam function antiChatSpam() -- The function that the event has called. Will stop all mainchat/teamchat/me spam. if isTimer(antiSpam[source]) then -- Check if timer is running using isTimer (this is an example of its use and all) cancelEvent() -- If timer is running then cancel the event outputChatBox("Sorry bro, you may only send 1 message a second to prevent spam.", source, 255, 255, 0) -- Message to player else antiSpam[source] = setTimer(function(source) antiSpam[source] = nil end, 1000, 1, source) -- Timer lasting 1 second. -- The "function(source) antiSpam[source] = nil end" should clear the player from table after 1 second so he can chat again. -- antiSpam[source] = setTimer(... is using the table to bind that player to the timer. end end addEventHandler("onPlayerChat", root, antiChatSpam) -- Event we're using, don't waste your time with getRootElement() (root is the same) -- You now have an antispam to prevent people super spamming your chatbox!
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace