You are on page 1of 7

local perm = { ['Lintrax#5327'] = true } -- Admins

local players = {}

local canFinish = false


local kicking = false
local startGame = false
local finishGame = false

local maxPlayers = 100


local playersInGame = 0

local mapName = '#Elimination'


local mapCode = '17'
local roundWinner = ''
local mapWinner = ''

-- [[ Disable ]] --
system.disableChatCommandDisplay(nil)

for _, v in next, {'AutoTimeLeft', 'AutoShaman', 'AutoNewGame', 'AutoScore',


'AfkDeath', 'PhysicalConsumables'} do
tfm.exec['disable' .. v]()
end

-- [[ Functions Lib ]] --
local split = function(str, s)
local res = {}
for part in string.gmatch(str, "[^" .. s .. "]+") do
table.insert(res, part)
end
return res
end

local showPlayers = function(name, display)


if (display == nil) then display = true end

local addTextArea = function(...) if (display) then ui.addTextArea(...) end end

if (playersInGame > 0) then


local a = 1

local list = { "<p align='center'>" }


local n, i, id = 0, 1, 1

local text = ''

for k in next, players do


if (k ~= name) then
local nick, tag = k:match('(.-)#(%d+)');tag = "<g><font size='9'>#"
.. tag .. "</font></g>"

n = (n + 1)
if (n >= 10) then
i = (i + 1);list[i] = "<p align='center'>"

text = (kicking and "<a href='event:" .. k .. "'>" or '') ..


nick .. tag .. '\n'

n = 1
id = (id + 1)
else
text = (kicking and "<a href='event:" .. k .. "'>" or '') ..
nick .. tag .. '\n'
end

list[i] = list[i] .. text


end
end

local x = 6
for i = 1, #list do
addTextArea(i, list[i], name, x, 80, 180, 310, 0x324650, 0x000000, .8,
true)

x = (x + (i == 1 and 193 or 203))


end

if (kicking) then
addTextArea(0, "<p align='center'><font size='16'><b>Escolha quem
eliminar", name, 5, 25, 790, 25, 0x324650, 0, .8)
end

return #list
end
end

local start = function()


playersInGame = 0

tfm.exec.newGame('<C><P Ca=""/><Z><S><S L="795" o="66666" H="56" X="401"


Y="373" T="12" P="0,0,0.3,0.2,0,0,0,0" i="-4,-398,1688b86f4fa.jpg" /></S><D /><O
/></Z></C>')

for k in next, perm do


ui.addTextArea(-1, "<p align='center'><a href='event:start'><j>Começar", k,
5, 25, 150, 20, 0x324650, 0, .8)
end

ui.addTextArea(0, "<p align='center'><a href='event:entry'><j>Participar", nil,


325, 25, 150, 20, 0x324650, 0, .8)

for k in next, tfm.get.room.playerList do


tfm.exec.setPlayerScore(k, 0)
end

showPlayers(nil)
end

-- [[ API Functions ]] --
function eventNewPlayer(name)
if (not startGame) then
local text = "<p align='center'><j>Você está participando."
if (not players[name]) then
text = "<p align='center'><a href='event:entry'><j>Participar"
end

ui.addTextArea(0, text, name, 325, 25, 150, 20, 0x324650, 0, .8)


showPlayers(name)
end

tfm.exec.setPlayerScore(name, 0)
end
table.foreach(tfm.get.room.playerList, eventNewPlayer)

function eventNewGame()
canFinish = false
kicking = false

mapWinner = ''

if (startGame) then
ui.removeTextArea(0);local a = showPlayers('?', false);for b = 1, a do
ui.removeTextArea(b, name) end

tfm.exec.addPhysicObject(0, 380, -325, {type = 14, width = 40, height =


10})
tfm.exec.addPhysicObject(1, 380, -365, {type = 14, width = 60, height =
10})
tfm.exec.addPhysicObject(2, 355, -340, {type = 14, width = 40, height = 10,
angle = -90})
tfm.exec.addPhysicObject(3, 405, -340, {type = 14, width = 40, height = 10,
angle = -90})

for k in next, tfm.get.room.playerList do


if (not players[k]) then
tfm.exec.movePlayer(k, 380, -340)
end
end

tfm.exec.setGameTime(63)

if (roundWinner ~= '') then


if (finishGame) then
if (players[roundWinner] and #players[roundWinner] > 0) then
local text = 'Eliminou: '

for i = 1, #players[roundWinner] do
local nick, tag = '<n>' .. players[roundWinner]
[i]:match('(.-)#[0-9]+$'), "<ch><font size='9'>" .. players[roundWinner]
[i]:match('#[0-9]+$')
text = text .. nick .. tag .. (i < #players[roundWinner]
and '<n>,</n> ' or '<n>.</n>')
end

ui.addTextArea(0, text, nil, 5, 25, 200, nil, 0x324650, 0, .8)


end

tfm.exec.setGameTime(30)
end
end
else
players = {}

tfm.exec.setGameTime(99999)
end
mapName = (tfm.get.room.xmlMapInfo.author ~= '#Module' and
tfm.get.room.xmlMapInfo.author or mapName)
mapCode = tfm.get.room.currentMap or mapCode
ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>|
<n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
end

function eventLoop(elapsed, remaining)


local remaining = math.floor(remaining / 1000)

if (elapsed <= 1000) then


tfm.exec.playEmote(roundWinner, 0)
end

if (remaining < 0) then


if (finishGame) then
finishGame = false
startGame = false

start()

return
end

if (startGame) then
if (canFinish and roundWinner ~= '') then
finishGame = true

tfm.exec.newGame('<C><P /><Z><S><S i="-200,-250,16692e791eb.png"


P=",,9999,,,,," L="400" H="10" Y="270" T="14" X="400" /><S P=",,9999,,,,," i="-66,-
20,1669252905c.png" L="200" H="10" Y="300" T="14" X="400" /></S><D><DS Y="300"
X="400" /></D><O /></Z></C>')
else
tfm.exec.newGame('#17')
end
else
ui.removeTextArea(0)

start()
end
end
end

function eventPlayerWon(name)
if (startGame) then
if (mapWinner == '') then
mapWinner = name

local a = 0
for k in next, players do
a = (a + 1)
end
if (a > 2) then
kicking = true

tfm.exec.setGameTime(10, false)

showPlayers(name)
else
for k in next, players do
if (k ~= name) then
players[k] = nil

break
end
end

canFinish = true

roundWinner = name

tfm.exec.setGameTime(4, false)
end

tfm.exec.setPlayerScore(name, tfm.get.room.playerList[name].score + 1)
end
end
end

function eventPlayerDied(name)
local t = {}

for k, v in next, tfm.get.room.playerList do


if (not v.isDead) then
t[#t + 1] = k
end
end

for i = 1, #t do
if (players[t[i]]) then
return
end
end

if (startGame) then
tfm.exec.newGame('#17')
end
end

function eventPlayerLeft(name)
if (players[name]) then
players[name] = nil

if (playersInGame > 0) then playersInGame = (playersInGame - 1) end


ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>|
<n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
end

if (not startGame) then


showPlayers(nil)
end

if (kicking) then
showPlayers(mapWinner)
end
end
function eventChatCommand(name, cmd)
cmd = split(cmd, ' ')

-- [[ Adm Commands ]] --
if (perm[name]) then
if (cmd[1] == 'start') then
local a = playersInGame
if (a > 1) then
for i = -1, a do
ui.removeTextArea(i)
end

startGame = true

tfm.exec.newGame('#17')
end
end
end
end

function eventTextAreaCallback(id, name, cb)


if (cb == 'entry') then
if (not players[name]) then
players[name] = {}

playersInGame = (playersInGame + 1)
ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>|
<n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)
ui.updateTextArea(0, '<j>Você está participando.', name)

showPlayers(nil)
end
elseif (cb == 'start') then
eventChatCommand(name, cb)
elseif (players[cb] and kicking) then
if (playersInGame > 0) then playersInGame = (playersInGame - 1) end

kicking = false
players[cb] = nil

local a = 1
for k in next, players do
a = (a + 1)
end
for i = 1, a do
ui.removeTextArea(i)
end

players[name][#players[name] + 1] = cb

ui.addTextArea(0, "<p align='center'><font size='16'><b><v>" .. name .. "


eliminou <r>" .. cb, nil, 5, 25, 790, 25, 0x324650, 0, .8)

ui.setMapName('<j>' .. mapName .. ' <bl>- ' .. mapCode .. ' <g>|


<n>Competidores : <v>' .. playersInGame .. '/' .. maxPlayers)

tfm.exec.setGameTime(15, false)
end
end
start()

You might also like