Hello everyone. I was trying to make my own nick change restriction script because people started to spam with it on my server. Well I wrote the next code, even if i tried many things, I always get the same error:
on line 20 ( nickChangeRestriction[source] = true ) it says table index is nil. It must be an stupid error, but I cant find it. Thanks in advance.
My code:
local nickChangeRestriction = {}
local timer = {}
addEventHandler("onPlayerCommand",getRootElement(),
function(command)
if command == "nick" then
if nickChangeRestriction[source] then
cancelEvent()
local a,b,c = getTimerDetails ( timer[source] )
local waitTime = a/1000
if waitTime < 60 then
waitTime = tostring(math.round(waitTime)).." seconds"
else
waitTime = tostring(math.round(waitTime/60, 0, "ceil")).." minutes"
end
outputChatBox("#FF9900*[PM][ANTI FLOOD] #FFFFFFYou have to wait #ABCDEF"..tostring(waitTime).." #FFFFFFto change your nick again",source,255,0,0, true)
return
end
--outputChatBox("GTFO",source,255,0,0,true)
nickChangeRestriction[source] = true
timer[source] = setTimer(function () nickChangeRestriction[source] = false end, 5000, 1)
--end
end
end)
function math.round(number, decimals, method)
decimals = decimals or 0
local factor = 10 ^ decimals
if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
else return tonumber(("%."..decimals.."f"):format(number)) end
end