Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local caller = getScriptCaller()
- local t = getAllUserData()
- local rate_prefix = "rate"
- local time_delay = 1*60*60
- function contains(table, val)
- for i=1,#table do
- if table[i] == val then
- return true
- end
- end
- return false
- end
- function getDelta()
- local t = {}
- t.current = getLocalData(rate_prefix .. tostring(caller.id))
- t.delta = math.random(0, 10)
- t.delta = signRoll(t.delta)
- if t.current + t.delta < 0 then
- t.delta = -t.current
- t.current = 0
- else
- t.current = t.current + t.delta
- end
- setLocalData(rate_prefix .. tostring(caller.id), t.current)
- return t
- end
- function updateTime(timeType)
- setLocalData(rate_prefix .. tostring(caller.id) .. timeType, os.time())
- end
- function checkTime(timeType)
- local time = getLocalData(rate_prefix .. tostring(caller.id) .. timeType)
- if not time then
- setLocalData(rate_prefix .. tostring(caller.id), 0)
- updateTime(timeType)
- return true
- end
- if time and os.time() - tonumber(time) > time_delay then
- updateTime(timeType)
- return true
- end
- return false
- end
- function printTop()
- local t = getAllUserData()
- local s = 'РЕЙТИНГ ЧЛЕНОВ КОНФЫ\n'
- --local r = {}
- if not getUserCount() then
- return 'Используй в конфе!'
- end
- for i = 1, getUserCount() do
- if t[i] and t[i].id and getLocalData(rate_prefix .. tostring(t[i].id)) then
- t[i].score = tonumber(getLocalData(rate_prefix .. tostring(t[i].id)))
- else
- t[i] = nil
- end
- end
- local c = {}
- for i = 1, getUserCount() do
- if t[i] then
- table.insert(c, t[i])
- end
- end
- table.sort(c, function(a,b) return a.score > b.score end)
- for i = 1, #c do
- if c[i].first_name then
- s = s .. c[i].first_name .. ' - ' ..c[i].score .. '\n'
- end
- end
- return s
- end
- function rate(params, rep)
- if params == caller.username then return "*Нельзя изменять рейтинг самому себе!" end
- if checkTime('rate') then
- for i = 1, getUserCount() do
- if t[i] and t[i].id and t[i].username == params then
- local current = getLocalData(rate_prefix .. tostring(t[i].id)) or 0
- setLocalData(rate_prefix .. tostring(t[i].id), current+rep)
- if rep == 1 then action = "повысил" else action = "понизил" end
- return "@" .. caller.username .. " " .. action .. " рейтинг @".. params .. "\nНовый рейтинг: " .. current+rep .. "."
- end
- end
- return "*Не нахожу чувака с ником " .. params
- else
- return os.date('Ты уже использовал эту команду.\n Приходи через %H часов %M минут', time_delay - os.time() + tonumber(getLocalData(rate_prefix .. tostring(caller.id .. 'rate'))))
- end
- end
- function serve(action, params)
- if action == "+" then return rate(params, 1) end
- if action == "-" then return rate(params, -1) end
- return "*Неверная команда - " .. action
- end
- if _ARGS == 'top' or _ARGS == 'топ' then
- return printTop()
- end
- if _ARGS == 'reset' or _ARGS == 'сброс' then
- if getScriptCaller().username == "Ox7FF"
- then
- setLocalData(rate_prefix .. tostring(caller.id) .. "rate", 0)
- return "*Временные настройки сброшены."
- else return "*Ты не админ."
- end
- end
- if _ARGS then
- local index = string.find(_ARGS, ' ')
- if index then
- action = string.sub(_ARGS, 1, index - 1)
- params = string.sub(_ARGS, index + 1)
- params = string.gsub(params, "@", "")
- return serve(action, params)
- else
- action = _ARGS
- end
- end
- return [[
- ==========СИСТЕМА РЕЙТИНГА==========
- !!rate + username - повысить рейтинг.
- !!rate - username - понизить рейтинг.
- !!rate top - вывести топ пользователей.
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement