Advertisement
Fooksie

house.lua

Jul 29th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.16 KB | None | 0 0
  1. groups={}
  2. players={}
  3. houses={"@1984227","@2365752","@2875713","@2999993","@4052896"}
  4. function groups_make(name,data)
  5.     if not groups[name] then
  6.         groups[name]={
  7.             name=name
  8.             }
  9.         end
  10.     if data then
  11.         for key,value in pairs(data) do
  12.             groups[name][key]=value
  13.             end
  14.         end
  15.     return groups[name]
  16.     end
  17. function groups_delete(name)
  18.     if groups[name] then
  19.         groups[name]=nil
  20.         for name,group in pairs(players) do
  21.             players[name]=nil
  22.             end
  23.         return true
  24.     else
  25.         return false
  26.         end
  27.     end
  28. function groups_priv(name,priv,set)
  29.     if groups[name] then
  30.         groups[name][priv]=set
  31.         return true
  32.     else
  33.         return false
  34.         end
  35.     end
  36. function groups_get(name)
  37.     return players[name] or groups.public
  38.     end
  39. function groups_add(name,group)
  40.     if groups[group] then
  41.         players[name]=groups[group]
  42.         return true
  43.     else
  44.         return false
  45.         end
  46.     end
  47. function groups_remove(name,group)
  48.     if players[name]==groups[group] then
  49.         players[name]=nil
  50.         return true
  51.     else
  52.         return false
  53.         end
  54.     end
  55. groups_make("public",{
  56.     queuemap=true
  57.     })
  58. groups_make("admin",{
  59.     playmap=true,
  60.     queuemap=true,
  61.     makegroup=true,
  62.     settime=true,
  63.     setgroup=true,
  64.     sethouse=true,
  65.     setconstants=true
  66.     })
  67. for name,player in pairs(tfm.get.room.playerList) do
  68.     players[name]=groups.admin
  69.     break
  70.     end
  71. function eventNewPlayer(name)
  72.     if greeting then
  73.         tfm.exec.chatMessage("<N>"..greeting,name)
  74.     else
  75.         eventChatCommand(name,"help")
  76.         end
  77.     tfm.exec.respawnPlayer(name)
  78.     end
  79. function eventPlayerDied(name)
  80.     tfm.exec.respawnPlayer(name)
  81.     end
  82. function eventPlayerWon(name)
  83.     tfm.exec.respawnPlayer(name)
  84.     end
  85. function eventNewGame()
  86.     queue=nil
  87.     if round_time then
  88.         tfm.exec.setGameTime(round_time)
  89.         end
  90.     end
  91. function eventLoop(time,remaining)
  92.     local inhouse=tfm.get.room.currentMap==house
  93.     if queue and inhouse then
  94.         tfm.exec.newGame(queue)
  95.     elseif remaining<=500 and not inhouse then
  96.         tfm.exec.setGameTime(5)
  97.         tfm.exec.disableAutoShaman(not queue)
  98.         tfm.exec.newGame(queue or house)
  99.         end
  100.     end
  101. function eventChatCommand(name,message)
  102.     local args={}
  103.     for arg in message:gmatch("[^%s]+") do
  104.         table.insert(args,arg:lower())
  105.         end
  106.     local privs=groups_get(name)
  107.     message=message:match("%s(.*)") or ""
  108.     if args[1]=="help" then
  109.         tfm.exec.chatMessage("<N><b>Welcome to "..tfm.get.room.name.."</b><br>You can use the following features...",name)
  110.         local cando={}
  111.         if privs.playmap then
  112.             table.insert(cando,{"%s to play a map","np @code"})
  113.             end
  114.         if privs.queuemap then
  115.             table.insert(cando,{"%s to queue a map (play next)","npp @code"})
  116.             end
  117.         if privs.settime then
  118.             table.insert(cando,{"%s to set time to # seconds","set time #"})
  119.             end
  120.         if privs.sethouse then
  121.             table.insert(cando,{"%s to change the tribe house","set house @code"})
  122.             end
  123.         table.insert(cando,{"%s to get groups (or other things)","get groups"})
  124.         for i=1,#cando do
  125.             tfm.exec.chatMessage("<N> • "..cando[i][1]:format("<VP>!"..cando[i][2].."<N>"),name)
  126.             end
  127.     elseif args[1]=="a" then
  128.         tfm.exec.chatMessage("<V>[~Anonymous]<N> "..message)
  129.     elseif args[1]=="np" and privs.playmap then
  130.         local map=args[2] or house
  131.         tfm.exec.chatMessage(" • "..name.." played "..map)
  132.         tfm.exec.newGame(map)
  133.     elseif args[1]=="npp" and privs.queuemap then
  134.         queue=args[2] or house
  135.         tfm.exec.chatMessage(" • "..name.." queued "..queue)
  136.     elseif args[1]=="add" then
  137.         if args[2]=="group" and privs.makegroup then
  138.             groups_make(args[3])
  139.             tfm.exec.chatMessage(" • Added group "..args[3])
  140.         elseif args[2]=="priv" and args[4]=="to" and args[5] then
  141.             if groups_priv(args[5],args[3],true) then
  142.                 tfm.exec.chatMessage(" • Added privilege "..args[3].." to "..args[5])
  143.             else
  144.                 tfm.exec.chatMessage(" • No such group "..args[5],name)
  145.                 end
  146.         elseif args[3]=="to" and args[4] then
  147.             local user=args[2]:gsub("^%l",string.upper)
  148.             if groups_add(user,args[4]) then
  149.                 tfm.exec.chatMessage(" • Added "..user.." to "..args[4])
  150.             else
  151.                 tfm.exec.chatMessage(" • No such group "..args[4],name)
  152.                 end
  153.             end
  154.     elseif args[1]=="remove" then
  155.         if args[2]=="group" then
  156.             if groups_delete(args[3]) then
  157.                 tfm.exec.chatMessage(" • Removed group "..args[3])
  158.             else
  159.                 tfm.exec.chatMessage(" • No such group "..args[3],name)
  160.                 end
  161.         elseif args[2]=="priv" and args[4]=="from" and args[5] then
  162.             if groups_priv(args[5],args[3],false) then
  163.                 tfm.exec.chatMessage(" • Removed privilege "..args[3].." from "..args[5])
  164.             else
  165.                 tfm.exec.chatMessage(" • No such group "..args[5],name)
  166.                 end
  167.         elseif args[3]=="from" and args[4] then
  168.             local name=args[2]:gsub("^%l",string.upper)
  169.             if groups_remove(name,args[4]) then
  170.                 tfm.exec.chatMessage(" • Removed "..name.." from "..args[4])
  171.             else
  172.                 tfm.exec.chatMessage(" • "..name.." isn't in "..args[4],name)
  173.                 end
  174.             end
  175.     elseif args[1]=="get" then
  176.         if args[2]=="groups" then
  177.             for group,data in pairs(groups) do
  178.                 local privs={}
  179.                 for priv,set in pairs(data) do
  180.                     if set==true then
  181.                         table.insert(privs,priv)
  182.                         end
  183.                     end
  184.                 tfm.exec.chatMessage(" • "..group.." ("..table.concat(privs,", ")..")",name)
  185.                 end
  186.         elseif args[2] then
  187.             tfm.exec.chatMessage(" • "..args[2].." = "..tostring(_G[args[2]]),name)
  188.             end
  189.     elseif args[1]=="set" then
  190.         if args[2]=="house" and privs.sethouse then
  191.             house=args[3] or houses[math.random(#houses)]
  192.             tfm.exec.chatMessage(" • Room house set to "..house)
  193.         elseif args[2]=="time" and privs.settime and tonumber(args[3]) then
  194.             tfm.exec.setGameTime(tonumber(args[3]),args[4]=="relative")
  195.             tfm.exec.chatMessage(" • Set time to "..args[3].."s")
  196.         elseif privs.setconstants then
  197.             args[3]=message:match("%s(.*)")
  198.             args[3]=tonumber(args[3]) or args[3]
  199.             if not args[3] or not _G[args[2]] or type(args[3])==type(_G[args[2]]) then
  200.                 _G[args[2]]=args[3]
  201.                 tfm.exec.chatMessage(" • Set "..args[2].." = "..tostring(args[3]),name)
  202.             else
  203.                 tfm.exec.chatMessage(" • "..args[2].." is not a "..type(args[3]).."!",name)
  204.                 end
  205.             end
  206.         end
  207.     end
  208. groups_add("Fxie","admin")
  209. eventChatCommand("Fxie","set house")
  210. tfm.exec.disableAutoNewGame(true)
  211. for i,command in ipairs({"a","np","npp","get","set","add","remove"}) do
  212.     system.disableChatCommandDisplay(command)
  213.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement