Advertisement
ACheats

RATE

Nov 30th, 2023 (edited)
788
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. local caller = getScriptCaller()
  2. local t = getAllUserData()
  3. local rate_prefix = "rate"
  4. local time_delay = 1*60*60
  5.  
  6. function contains(table, val)
  7.    for i=1,#table do
  8.       if table[i] == val then
  9.          return true
  10.       end
  11.    end
  12.    return false
  13. end
  14.  
  15. function getDelta()
  16.   local t = {}
  17.   t.current = getLocalData(rate_prefix .. tostring(caller.id))
  18.   t.delta = math.random(0, 10)
  19.   t.delta = signRoll(t.delta)
  20.   if t.current + t.delta < 0 then
  21.     t.delta = -t.current
  22.     t.current = 0
  23.   else
  24.     t.current = t.current + t.delta
  25.   end
  26.   setLocalData(rate_prefix .. tostring(caller.id), t.current)
  27.   return t
  28. end
  29.  
  30. function updateTime(timeType)
  31.   setLocalData(rate_prefix .. tostring(caller.id) .. timeType, os.time())
  32. end
  33.  
  34.  
  35. function checkTime(timeType)
  36.   local time = getLocalData(rate_prefix .. tostring(caller.id) .. timeType)
  37.   if not time then
  38.     setLocalData(rate_prefix .. tostring(caller.id), 0)
  39.     updateTime(timeType)
  40.     return true
  41.   end
  42.   if time and os.time() - tonumber(time) > time_delay then
  43.     updateTime(timeType)
  44.     return true
  45.   end
  46.   return false
  47. end
  48.  
  49. function printTop()
  50.   local t = getAllUserData()
  51.   local s = 'РЕЙТИНГ ЧЛЕНОВ КОНФЫ\n'
  52.   --local r = {}
  53.   if not getUserCount() then
  54.     return 'Используй в конфе!'
  55.   end
  56.   for i = 1, getUserCount() do
  57.     if t[i] and t[i].id and getLocalData(rate_prefix .. tostring(t[i].id)) then
  58.       t[i].score = tonumber(getLocalData(rate_prefix .. tostring(t[i].id)))
  59.     else
  60.       t[i] = nil
  61.     end
  62.   end
  63.   local c = {}
  64.   for i = 1, getUserCount() do
  65.     if t[i] then
  66.       table.insert(c, t[i])
  67.     end
  68.   end
  69.   table.sort(c, function(a,b) return a.score > b.score end)
  70.   for i = 1, #c do
  71.     if c[i].first_name then
  72.       s = s .. c[i].first_name .. ' - ' ..c[i].score .. '\n'
  73.     end
  74.   end
  75.   return s
  76. end
  77.  
  78. function rate(params, rep)
  79. if params == caller.username then return "*Нельзя изменять рейтинг самому себе!" end
  80. if checkTime('rate') then
  81.       for i = 1, getUserCount() do
  82.         if t[i] and t[i].id and t[i].username == params then
  83.           local current = getLocalData(rate_prefix ..  tostring(t[i].id)) or 0
  84.           setLocalData(rate_prefix ..  tostring(t[i].id), current+rep)
  85.           if rep == 1 then action = "повысил" else action = "понизил" end
  86.           return "@" .. caller.username .. " " .. action .. " рейтинг @".. params .. "\nНовый рейтинг: " .. current+rep .. "."
  87.         end
  88.       end
  89.       return "*Не нахожу чувака с ником " .. params
  90.        else
  91.         return os.date('Ты уже использовал эту команду.\n Приходи через %H часов %M минут', time_delay - os.time() + tonumber(getLocalData(rate_prefix ..  tostring(caller.id .. 'rate'))))
  92.     end
  93. end
  94.  
  95. function serve(action, params)
  96.   if action == "+" then return rate(params, 1) end
  97.   if action == "-" then return rate(params, -1) end
  98.   return "*Неверная команда -  " .. action
  99. end
  100.  
  101. if _ARGS == 'top' or _ARGS == 'топ' then
  102.   return printTop()
  103. end
  104.  
  105. if _ARGS == 'reset' or _ARGS == 'сброс' then
  106.   if getScriptCaller().username == "Ox7FF"
  107.     then
  108.       setLocalData(rate_prefix ..  tostring(caller.id) .. "rate", 0)
  109.     return "*Временные настройки сброшены."
  110.   else return "*Ты не админ."
  111.   end
  112. end
  113.  
  114.  
  115.  
  116. if _ARGS then
  117.   local index = string.find(_ARGS, ' ')
  118.  
  119.   if index then
  120.     action = string.sub(_ARGS, 1, index - 1)
  121.     params = string.sub(_ARGS, index + 1)
  122.     params = string.gsub(params, "@", "")
  123.  
  124.     return serve(action, params)
  125.   else
  126.     action = _ARGS
  127.   end
  128. end
  129.  
  130. return [[
  131. ==========СИСТЕМА РЕЙТИНГА==========
  132. !!rate + username - повысить рейтинг.
  133. !!rate - username - понизить рейтинг.
  134. !!rate top - вывести топ пользователей.
  135. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement