Advertisement
Eliaseeg

Admin system

Jul 6th, 2014
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local admins = {"Fresitho"}
  2. local bans = {}
  3.  
  4. function inTable(t, a)
  5.   if type(t)=="table" then
  6.     for x,y in pairs(t) do
  7.       if a==y then return true end
  8.       end
  9.     return false
  10.   end
  11. end
  12.  
  13. function table.delete(tbl, element)
  14. for k,v in pairs(tbl) do
  15.   if v == element then
  16.     if tonumber(k) == nil then
  17.         return false
  18.     else
  19.         table.remove(tbl, k)
  20.         return true
  21.      end
  22.    end
  23.  end
  24. end
  25.  
  26. function eventLoop()
  27.   for name,_ in pairs(tfm.get.room.playerList) do
  28.     if inTable(admins, name) then
  29.       tfm.exec.setNameColor(name, 0x191919)
  30.     end
  31.   end
  32. end
  33.  
  34. function eventChatCommand(name, command)
  35. local admin = inTable(admins, name)
  36. local banned = inTable(bans, name)
  37. local args = split(command, "%s")
  38.   if args[1] == "admin" and admin then
  39.     table.insert(admins, capitalize(args[2]))
  40.   elseif args[1] == "ban" and not banned then
  41.     table.insert(bans, capitalize(args[2]))
  42.     tfm.exec.killPlayer(capitalize(args[2]))
  43.   elseif args[1] == "unban" and banned then
  44.     table.delete(bans, capitalize(args[2]))
  45.   end
  46. end
  47.  
  48. function capitalize(word)
  49.   if word:sub(1,1)=="+" then
  50.     return "+"..string.upper(word:sub(2,2))..""..string.lower(word:sub(3))..""
  51.   else
  52.     return ""..string.upper(word:sub(1,1))..""..string.lower(word:sub(2))..""
  53.   end
  54. end
  55.  
  56. function split(input, seperator)
  57.     local res = {};
  58.     for part in string.gmatch(input, "[^" .. seperator .. "]+") do
  59.         table.insert(res, part);
  60.     end
  61.     return res;
  62. end
  63.  
  64. function eventPlayerRespawn(name)
  65.   if inTable(bans, name) then
  66.     tfm.exec.killPlayer(name)
  67.   end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement