getTickCount | Multi Theft Auto: Wiki Skip to content

getTickCount

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task.

Important

The value returned by this function client-side may not be reliable if a client is maliciously modifying their operating system speed.

Syntax

getTickCount ( )

Code Examples

server

The below code is a good example on how to implement basic anti-spam protection for a command, for which using getTickCount is better than the regular timer functions.

local spam = {}
function setSkin(player, cmd, skin)
if spam[player] and getTickCount() - spam[player] < 4000 then
return outputChatBox("You cannot change skin that often!", player, 255, 0, 0)
end
skin = skin and tonumber(skin)
if getElementModel(player) == skin or isPedDead(player) then
return
end
if skin and skin <= 99999 then -- what do we know about dynamic ped ID range?
setElementModel(player, skin)
spam[player] = getTickCount()
else
outputChatBox("Invalid skin ID!", player, 255, 0, 0)
end
end
addCommandHandler("skin", setSkin)
function cleanUp()
if spam[source] then
spam[source] = nil
end
end
addEventHandler("onPlayerQuit", root, cleanUp)