Fooksie

tribewar

Jul 28th, 2013
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.59 KB | None | 0 0
  1. round=0
  2. ranked=false
  3. players={}
  4. round_duration=6
  5. referees={
  6.     "Fxie",
  7.     "Moepl",
  8.     "Begentle"
  9.     }
  10. tfm.exec.disableAutoScore(true)
  11. tfm.exec.disableAutoShaman(true)
  12. tfm.exec.disableAutoNewGame(true)
  13. function tribe_list()
  14.     local tribes={}
  15.     for name,tribe in pairs(players) do
  16.         if not tribes[tribe] then
  17.             tribes[tribe]={
  18.                 name=tribe,
  19.                 score=0,
  20.                 members={}
  21.                 }
  22.             end
  23.         table.insert(tribes[tribe].members,name)
  24.         tribes[tribe].score=tribes[tribe].score+tfm.get.room.playerList[name].score
  25.         end
  26.     return tribes
  27.     end
  28. function tribe_ladder()
  29.     local ladder={}
  30.     for name,tribe in pairs(tribe_list()) do
  31.         table.insert(ladder,tribe)
  32.         end
  33.     table.sort(ladder,function(a,b) return a.score/#a.members>b.score/#b.members end)
  34.     return ladder
  35.     end
  36. function isRef(name)
  37.     for i=1,#referees do
  38.         if referees[i]==name then
  39.             return true
  40.             end
  41.         end
  42.     return false
  43.     end
  44. function eventNewGame()
  45.     places={}
  46.     round=round+1
  47.     local modulo=math.fmod(round,round_duration)
  48.     if modulo==0 then
  49.         tfm.exec.chatMessage("<VP><b>Winners of round "..(round/round_duration).."</b>")
  50.         local ladder=tribe_ladder()
  51.         for i=1,math.min(#ladder,3) do
  52.             local leader,topscore="nobody",0
  53.             for ii,name in ipairs(ladder[i].members) do
  54.                 local score=tfm.get.room.playerList[name].score
  55.                 if score>topscore then
  56.                     leader=name
  57.                     topscore=score
  58.                     end
  59.                 if i==1 then
  60.                     tfm.exec.movePlayer(name,math.random(40,760),160)
  61.                     end
  62.                 end
  63.             tfm.exec.chatMessage("<N> "..i..". <b>"..ladder[i].name.."</b> led by "..leader)
  64.             end
  65.         for name,player in pairs(tfm.get.room.playerList) do
  66.             tfm.exec.setPlayerScore(name,0)
  67.             end
  68.         for i=1,12 do
  69.             tfm.exec.addShamanObject(57,i*60,200)
  70.             end
  71.         for i=1,40 do
  72.             tfm.exec.addShamanObject(28,i*20,math.random(360),nil,nil,nil,true)
  73.             end
  74.         end
  75.     end
  76. eventNewGame()
  77. function eventLoop(time,remaining)
  78.     if remaining<=500 then
  79.         local modulo=math.fmod(round,2)
  80.         local map=math.fmod(round+1,round_duration)==0 and 0
  81.             or modulo==0 and "#7"
  82.             or modulo==1 and "#17"
  83.             or 2
  84.         ranked=map~=0
  85.         tfm.exec.newGame(map)
  86.         end
  87.     end
  88. function eventNewPlayer(name)
  89.     tfm.exec.setPlayerScore(name,0)
  90.     tfm.exec.chatMessage("<VP>Welcome to <N>Tribewar<VP>! ",name)
  91.     tfm.exec.chatMessage("<T>As always, type <N>!help<T> if you need it. Let the games begin!",name)
  92.     if isRef(name) then
  93.         tfm.exec.chatMessage("Referee "..name.." has joined.")
  94.         end
  95.     tfm.exec.chatMessage("![order] [requestTribe]"..name,"Moempf")
  96.     end
  97. for name,player in pairs(tfm.get.room.playerList) do
  98.     eventNewPlayer(name)
  99.     end
  100. function eventPlayerLeft(name)
  101.     players[name]=nil
  102.     end
  103. function eventPlayerDied(name)
  104.     local skip=true
  105.     for name,player in pairs(tfm.get.room.playerList) do
  106.         if not player.isDead then
  107.             skip=false
  108.             break
  109.             end
  110.         end
  111.     if skip then
  112.         eventLoop(0,0)
  113.         end
  114.     end
  115. function eventPlayerWon(name)
  116.     if players[name] and ranked then
  117.         table.insert(places,name)
  118.         if #places<4 then
  119.             local points=4-#places
  120.             tfm.exec.setPlayerScore(name,points,true)
  121.             tfm.exec.chatMessage("<J><b>"..name.."</b> scored "..points.." points for <b>"..players[name].."</b>!")
  122.             end
  123.         end
  124.     end
  125. function eventChatCommand(name,message)
  126.     local args={}
  127.     local admin=isRef(name)
  128.     for arg in message:gmatch("[^%s]+") do
  129.         table.insert(args,arg:lower())
  130.         end
  131.     message=message:match("%s(.*)") or ""
  132.     if args[1]=="help" then
  133.         tfm.exec.chatMessage("<N>U NEED SUM HELP?!",name)
  134.     elseif args[1]:match("tribe") then
  135.         local ladder=tribe_ladder()
  136.         tfm.exec.chatMessage("<VP><b>Leading tribes</b><T> ("..#ladder.." total)",name)
  137.         for i=1,math.min(#ladder,3) do
  138.             tfm.exec.chatMessage("<N> • "..ladder[i].score.." pts - <b>"..ladder[i].name.."</b> - "..table.concat(ladder[i].members,", "),name)
  139.             end
  140.     elseif args[1]=="unrank" and admin then
  141.         ranked=false
  142.         for i=1,math.min(#places,3) do
  143.             tfm.exec.setPlayerScore(places[i],i-4,true)
  144.             end
  145.         tfm.exec.chatMessage("<J>This round has been unranked.")
  146.     elseif args[1]=="skip" and admin then
  147.         eventLoop(0,0)
  148.     elseif args[1]=="play" and admin then
  149.         ranked=false
  150.         tfm.exec.newGame(args[2])
  151.     elseif args[1]=="[order]" and name=="Moempf" then
  152.         args[2]=message:match("%[(%w+)")
  153.         args[3]=message:match("%](%w+)")
  154.         args[4]=message:match("%-(.*)")
  155.         if args[2]=="responseTribe" and #args[4]>0 then
  156.             players[args[3]]=args[4]
  157.             for i,member in ipairs(tribe_list()[args[4]].members) do
  158.                 tfm.exec.chatMessage("<T>• "..args[3].." just joined the fight!",member)
  159.                 end
  160.             end
  161.         end
  162.     end
  163. system.disableChatCommandDisplay("help")
  164. system.disableChatCommandDisplay("unrank")
  165. system.disableChatCommandDisplay("[order]")
Advertisement
Add Comment
Please, Sign In to add comment