Advertisement
KananGamer

[TFM-LUA] Ranks na tribo

Jan 15th, 2017
543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.06 KB | None | 0 0
  1. --[[
  2.     Author: Nettoork#0000
  3.     OBS: Script 90% terminado, falta os menus.
  4. ]]--
  5.  
  6. userPrivilege = {
  7.     owner = {users = {'Nettoork#0000', 'Sandstorm#4261'}},
  8.     admin = {users = {}},
  9.     moderator = {users = {}},
  10.     vip = {users = {}},
  11.     member = {users = {}}
  12. }
  13.  
  14. textContent = {
  15.     buyVipMessage = 'Que tal comprar vip? Só falar com um dos donos!',
  16.     welcomeMessage = 'Seja Bem-vindo ao cafofo da tribo!',
  17.     noPlayers = 'Não há jogadores online nesta categoria',
  18.     yePlayers = function(a, b) return string.format('Jogadores %s online: %s', a, b) end
  19. }
  20.  
  21. rankPrivilege = {
  22.     owner = {tag = '<font color="#00FFF9">Owner</font>', permissions = {'nick', 'me', 'all', 'others'}, commands = {':admin'}},
  23.     admin = {tag = '<font color="#FF0000">Admin</font>', permissions = {'nick', 'me', 'all', 'others'}, commands = {':moderator', 'cheese', 'hole', 'shaman', 'kill'}},
  24.     moderator = {tag = '<font color="#00FFBD">Moderator</font>', permissions = {'nick', 'me', 'all'}, commands = {':vip', 'nextmap', 'np', 'score', 'maptime'}},
  25.     vip = {tag = '<font color="#F2FF00">Vip</font>', permissions = {'nick', 'me'}, commands = {':member', 'up', 'meep', 'vamp', 'snow', 'respawn', 'blackname', 'tp', 'explode'}},
  26.     member = {tag = '<font color="#02FF00">Member</font>', permissions = {'me'}, commands = {'dance', 'confetti'}}
  27. }
  28.  
  29. function rankCommands()
  30.     for i, v in next, {'member', 'vip', 'moderator', 'admin', 'owner'} do
  31.         for o, a in next, rankPrivilege[v].commands do
  32.             if a:sub(1, 1) == ':' then
  33.                 for _, __ in next, rankPrivilege[a:sub(2, #a)].commands do
  34.                     rankPrivilege[v].commands[#rankPrivilege[v].commands + 1] = __
  35.                 end
  36.                 table.remove(rankPrivilege[v].commands, o)
  37.                 break
  38.             end
  39.         end
  40.     end
  41. end
  42.  
  43. function tableStringToTable(tableC)
  44.     local finalTable = {}
  45.     for i, v in next, tableC do
  46.         finalTable[v] = v
  47.     end
  48.     return finalTable
  49. end
  50.  
  51. function changeTables()
  52.     for i, v in next, rankPrivilege do
  53.         rankPrivilege[i]['commands'] = tableStringToTable(v['commands'])
  54.         rankPrivilege[i]['permissions'] = tableStringToTable(v['permissions'])
  55.     end
  56.     for i, v in next, userPrivilege do
  57.         userPrivilege[i]['users'] = tableStringToTable(v['users'])
  58.     end
  59. end
  60.  
  61. function split(t, s)
  62.     local a={}
  63.     for i in string.gmatch(t, "[^" .. (s or "%s") .. "]+") do
  64.         a[#a + 1] = i
  65.     end
  66.     return a
  67. end
  68.  
  69. function executeCommand(name, cmd, func, meall)
  70.     if meall then
  71.         if not cmd[meall] then return end
  72.         func(cmd)
  73.     elseif cmd[2] == havePermission(name, 'me') then
  74.         func(name)
  75.     elseif cmd[2] == havePermission(name, 'all') then
  76.         table.foreach(tfm.get.room.playerList, func)
  77.     elseif cmd[2] == havePermission(name, 'others') then
  78.         for i in next, tfm.get.room.playerList do
  79.             if i ~= name then
  80.                 func(i)
  81.             end
  82.         end
  83.     elseif havePermission(name, 'nick') then
  84.         func(cmd[2])
  85.     end
  86. end
  87.  
  88. function havePermission(name, permission)
  89.     return rankPrivilege[getTagPrivilege(name)[1]].permissions[permission]
  90. end
  91.  
  92. function haveCommand(name, command)
  93.     return rankPrivilege[getTagPrivilege(name)[1]].commands[command]
  94. end
  95.  
  96. function getTagPrivilege(name)
  97.     local rank = {'nothing', '<font color="#FFFFFF">Desconhecido</font>'}
  98.     for i, v in next, userPrivilege do
  99.         if v.users[name] then
  100.             rank = {i, rankPrivilege[i]['tag']}
  101.         end
  102.     end
  103.     return rank
  104. end
  105.  
  106. function buyVipMenu(name)
  107.     ui.addTextArea(5, 'Em construção.', name, 250, 60, 300, 300, 1, 0x324650, 1, true)
  108. end
  109.  
  110. function commandMenu(name)
  111.     ui.addTextArea(5, 'Em construção.', name, 250, 60, 300, 300, 1, 0x324650, 1, true)
  112. end
  113.  
  114. function playersOnlineMenu(name, rank)
  115.     ui.addTextArea(6, '<DE><a href="event:close_playersOnline">'..playersOnline(rank), name, 5, 28, 700, 0, 1, 0x9F9F9F, 0.5, true)
  116. end
  117.  
  118. function playersOnline(rank)
  119.     playersOn={}
  120.     table.foreach(tfm.get.room.playerList, function(p) if rank and getTagPrivilege(p)[1] == rank then playersOn[#playersOn+1] = p end end)
  121.     if playersOn[1] then
  122.         return textContent['yePlayers'](rankPrivilege[rank].tag, table.concat(playersOn, ", "))
  123.     else return textContent['noPlayers'] end
  124. end
  125.  
  126. function eventNewPlayer(name)
  127.     if tfm.get.room.playerList[name].tribeName == tfm.get.room.name:sub(3, #tfm.get.room.name) and getTagPrivilege(name)[1] == 'nothing' then
  128.         userPrivilege.member.users[name] = true
  129.     end
  130.     ui.addTextArea(1, '<font color="#ED3232">  Menu', name, 725, 30, 60, 25 , 0x0e232b, 0x173845, 1, true)
  131.     ui.addTextArea(2, '<p align="center"><a href="event:menu"><font color="#E22E2E">           ▼', name, 726, 32, 60, 25, 0, 0, 0, true)
  132.     ui.addTextArea(3, '<p align="center">Rank:\n'..getTagPrivilege(name)[2], name, 695, 365, 100, 30, 1, 0x9F9F9F, 0.5, true)
  133.     ui.addTextArea(4, '<p align="center"><a href="event:fechar_cmd_1">'..textContent['welcomeMessage'], name, 5, 375, 320, 20, 1, 0x9F9F9F, 0.5, true)
  134. end
  135.  
  136. function eventChatCommand(name, cmd)
  137.     cmd = split(cmd, ' ')
  138.     if cmd[1] == 'owners' or cmd[1] == 'admins' or cmd[1] == 'moderators' or cmd[1] == 'vips' or cmd[1] == 'members' then
  139.         playersOnlineMenu(name, cmd[1]:gsub('s', ''))
  140.     elseif cmd[1] == haveCommand(name, 'cheese') then
  141.         executeCommand(name, cmd, function(name)
  142.             tfm.exec.giveCheese(name)
  143.         end)
  144.     elseif cmd[1] == haveCommand(name, 'hole') then
  145.         executeCommand(name, cmd, function(name)
  146.             tfm.exec.playerVictory(name)
  147.         end)
  148.     elseif cmd[1] == haveCommand(name, 'up') then
  149.         executeCommand(name, cmd, function(name)
  150.             tfm.exec.movePlayer(name, 0, 1)
  151.         end)
  152.     elseif cmd[1] == haveCommand(name, 'meep') then
  153.         executeCommand(name, cmd, function(name)
  154.             tfm.exec.giveMeep(name)
  155.         end)
  156.     elseif cmd[1] == haveCommand(name, 'shaman') then
  157.         executeCommand(name, cmd, function(name)
  158.             tfm.exec.setShaman(name)
  159.         end)
  160.     elseif cmd[1] == haveCommand(name, 'vamp') then
  161.         executeCommand(name, cmd, function(name)
  162.             tfm.exec.setVampirePlayer(name)
  163.         end)
  164.     elseif cmd[1] == haveCommand(name, 'snow') then
  165.         executeCommand(name, cmd, function(config)
  166.             tfm.exec.snow(config[2])
  167.         end, 2)
  168.     elseif cmd[1] == haveCommand(name, 'dance') then
  169.         executeCommand(name, cmd, function(name)
  170.             tfm.exec.playEmote(name, 0)
  171.         end)
  172.     elseif cmd[1] == haveCommand(name, 'confetti') then
  173.         executeCommand(name, cmd, function(name)
  174.             tfm.exec.playEmote(name, 9)
  175.         end)
  176.     elseif cmd[1] == haveCommand(name, 'respawn') then
  177.         executeCommand(name, cmd, function(name)
  178.             tfm.exec.respawnPlayer(name)
  179.         end)
  180.     elseif cmd[1] == haveCommand(name, 'kill') then
  181.         executeCommand(name, cmd, function(name)
  182.             tfm.exec.killPlayer(name)
  183.         end)
  184.     elseif cmd[1] == haveCommand(name, 'blackname') then
  185.         executeCommand(name, cmd, function(name)
  186.             tfm.exec.setNameColor(name, 0x333333)
  187.         end)
  188.     elseif cmd[1] == haveCommand(name, 'nextmap') then
  189.         executeCommand(name, cmd, function()
  190.             tfm.exec.newGame()
  191.         end, 2)
  192.     elseif cmd[1] == haveCommand(name, 'np') then
  193.         executeCommand(name, cmd, function(config)
  194.             tfm.exec.newGame(config[2])
  195.         end, 2)
  196.     elseif cmd[1] == haveCommand(name, 'maptime') then
  197.         executeCommand(name, cmd, function(config)
  198.             tfm.exec.setGameTime(config[2])
  199.         end, 2)
  200.     elseif cmd[1] == haveCommand(name, 'explode') then
  201.         executeCommand(name, cmd, function(name)
  202.             if not tfm.get.room.playerList[name] then return end
  203.             tfm.exec.explosion(tfm.get.room.playerList[name].x, tfm.get.room.playerList[name].y+2, 15, 100)
  204.         end)
  205.     elseif cmd[1] == haveCommand(name, 'score') then
  206.         executeCommand(name, cmd, function(config)
  207.             if config[4] == 'true' then config[4] = true else config[4] = false end
  208.             executeCommand(name, config, function(name)
  209.                 if type(name) == 'table' then name = name[2] end
  210.                 tfm.exec.setPlayerScore(name, config[3], config[4])
  211.             end)
  212.         end, 4)
  213.     elseif cmd[1] == haveCommand(name, 'tp') then
  214.         executeCommand(name, cmd, function(config)
  215.             if not tfm.get.room.playerList[config[3]] then return end
  216.             executeCommand(name, config, function(config2)
  217.                 if not tfm.get.room.playerList[config2] then return end
  218.                 tfm.exec.movePlayer(config2, tfm.get.room.playerList[config[3]].x, tfm.get.room.playerList[config[3]].y, false, 0, 0, false)
  219.             end)
  220.         end, 3)
  221.     end
  222. end
  223.  
  224. rankCommands()
  225. changeTables()
  226. table.foreach(tfm.get.room.playerList, eventNewPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement