SleePyCode Forums

Special Site & Other Boards => PasteBin => Topic started by: Liam on Jul 20, 2013, 08:57 PM

Title: Paste-1374353864:v:use_geshi-1:v:type-lua
Post by: Liam on Jul 20, 2013, 08:57 PM
debug.disableEventLog(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAutoTimeLeft(true)
tfm.exec.disableAutoScore(true)
tfm.exec.disableAutoShaman(true)
TICKS = 10;

local s = 1000/TICKS;
for t = 0, 1000 - s, s do
   system.newTimer(function () system.newTimer(loop, 1000, true) end, 1000 + t, false);
end

function newRound()
   tfm.exec.newGame(2876844)
   players={}
   fights={}
   spawns={}
   runes={}
   runestime={}
   runesshot={}
   canShoot={}
   fightsalive = 0
   spawnsalive = 0
end

function eventNewGame()
   for name,player in pairs(tfm.get.room.playerList) do
      table.insert(players,player)
      bindKeys(name, true)
   end
   for i=1,#players,1 do
      local index=math.random(#players)
      local player=players[index]
      if i%3==0 then
         table.insert(fights,player.playerName)
         --tfm.exec.chatMessage("<R>"..player.playerName)
         tfm.exec.movePlayer(player.playerName,1380,215)
         tfm.exec.setNameColor(player.playerName,0xc13535)
         fightsalive = fightsalive + 1
      elseif i%2==0 then
         table.insert(spawns,player.playerName)
         --tfm.exec.chatMessage("<BV>"..player.playerName)
         tfm.exec.movePlayer(player.playerName,140,345)
         tfm.exec.setNameColor(player.playerName,0x354fc1)
         canShoot[player.playerName]=true
         spawnsalive = spawnsalive + 1
      else
         table.insert(fights,player.playerName)
         --tfm.exec.chatMessage("<R>"..player.playerName)
         tfm.exec.movePlayer(player.playerName,1380,215)
         tfm.exec.setNameColor(player.playerName,0xc13535)
         fightsalive = fightsalive + 1
      end
      table.remove(players,index)
   end
end

function eventLoop(time,remaining)
   if remaining<=0 or fightsalive<=0 or spawnsalive<=0 then
      newRound()
   end
end

function loop()
   for k,v in pairs(runestime) do
      if v~=0 and (tonumber(os.time())>v+5000) then
         tfm.exec.removeObject(runes[k])
         canShoot[runesshot[k]] = true
         --runestime[v] = 0
         table.remove(runestime,k)
         table.remove(runes,k)
         table.remove(runesshot,k)
         break
      end
   end
end

function eventPlayerLeft(playerName)
   bindKeys(playerName, false)
end

function bindKeys(playerName, active)
   tfm.exec.bindKeyboard(playerName,83,active,true) -- S
   tfm.exec.bindKeyboard(playerName,40,active,true) -- DOWN
end

function eventKeyboard(playerName, key, down, x, y)
   if (key==83 or key==40) and inTable(spawns,playerName) and canShoot[playerName]==true then
      rune=tfm.exec.addShamanObject(62,x+25,y,0,0,0,true)
      table.insert(runes,rune)
      table.insert(runestime,os.time())
      table.insert(runesshot,playerName)
      canShoot[playerName]=false
   end
end

function eventPlayerDied(playerName)
   if inTable(fights,playerName) then
      fightsalive = fightsalive - 1
   end
   if inTable(spawns,playerName) then
      spawnsalive = spawnsalive - 1
   end
end

function eventPlayerWon(playerName)
   if inTable(fights,playerName) then
      fightsalive = fightsalive - 1
   end
   if inTable(spawns,playerName) then
      fightsalive = fightsalive - 1
   end
end

function tfm.exec.giveWinAll()
   for playerName,player in pairs(tfm.get.room.playerList) do
      if not player.isDead then
         tfm.exec.giveCheese(playerName)
         tfm.exec.playerVictory(playerName)
      end
   end
end

function inTable(tbl, item)
   for key, value in pairs(tbl) do
      if value == item then
         return key
      end
   end
   return false
end

newRound()