Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tfm.exec.disableAutoNewGame()
- tfm.exec.disableAutoShaman()
- tfm.exec.disableAfkDeath()
- _TIMERS = {
- }
- _PLAYERS = {}
- _MODULES = {
- configPlayer = {
- running = true,
- callbacks = {
- on_eventNewPlayer = function(player)
- for _, key in pairs({0, 1, 2, 3, 32}) do
- system.bindKeyboard(player, key, true, true)
- end
- end
- }
- },
- tagging = {
- running = false,
- mapWidth = 17,
- mapHeight = 17,
- diffX = 640,
- blockArea = 40,
- players = {},
- board = {},
- colors = {[0] = "FA5956","F55E56","F06356","EB6856","E76D56","E27256","DD7856","D87D56","D48256","CF8756","CA8C56","C59256","C19756","BC9C56","B7A156","B2A656","AEAC56","A9B156","A4B656","9FBB56","9BC056","96C656","91CB56","8CD056","88D556","83DA56","7EE056","79E556","75EA56","70EF56","6BF456"},
- userHoldingPotato = "",
- sprites = {
- [1] = {
- south = "1553d3f187c",
- east = "1553d3f5870",
- west = "1553d570f97",
- north = "1553d57aef5",
- offsetX = 23,
- offsetY = 0
- },
- [2] = {
- south = "15541318d67",
- east = "1554131c12c",
- west = "155412984a5",
- north = "15541289c9c",
- offsetX = 23,
- offsetY = 0
- }
- },
- tiles = {
- [1] = {
- url = "1553c658200.png",
- offsetX = 0,
- offsetY = -2
- },
- [2] = {
- url = "1553c3d754d.png",
- offsetX = 1,
- offsetY = 1
- },
- [3] = {
- url = "1554c73efa8.png",
- offsetX = -78,
- offsetY = 31
- }
- },
- removeTileTimer = os.time(),
- callbacks = {
- on_startModule = function()
- local self = _MODULES.tagging
- tfm.exec.newGame("@6711195")
- self.roomPotatoTimer = os.time()
- self.callbacks.initializeBoard()
- end,
- on_eventNewPlayer = function()
- local self = _MODULES.tagging
- self.callbacks.displayBoard(nil)
- end,
- on_eventLoop = function()
- local self = _MODULES.tagging
- if self.gameRunning and self.players[self.userHoldingPotato].alive then
- local potatoTimer = 30-math.ceil((os.time()-self.roomPotatoTimer)/1000)
- local color = self.colors[potatoTimer]
- if potatoTimer < 5 then
- end
- ui.addTextArea(-1, "<font color='#000000' font='Courier' size='20'>"..potatoTimer, nil, 16, 31, nil, nil, 0, 0, 0, true)
- ui.addTextArea(-2, "<font color='#"..color.."' font='Courier' size='20'>"..potatoTimer, nil, 15, 30, nil, nil, 0, 0, 0, true)
- if potatoTimer == 0 then
- self.callbacks.killPlayerBlock(self.userHoldingPotato)
- self.roomPotatoTimer = os.time()
- end
- --[[if self.removeTileTimer < os.time()-3000 then
- for i = 1, self.mapWidth do
- for j = 1, self.mapHeight do
- if self.board[i][j].hasBlock and self.board[i][j].player == "" then
- self.board[i][j].hasBlock = false
- self.removeTileTimer = os.time()
- self.board[i][j].deleted = true
- for k, v in pairs(self.board[i][j].spriteId) do
- tfm.exec.removeImage(v)
- end
- return
- end
- end
- end
- end]]--
- end
- end,
- killPlayerBlock = function(player)
- local self = _MODULES.tagging
- local data = self.players[player]
- data.alive = false
- tfm.exec.removeImage(data.imageId)
- ui.removeTextArea(data.textId)
- tfm.exec.killPlayer(player)
- local aliveBlocks = self.callbacks.getAliveBlocks()
- if player == self.userHoldingPotato then
- if #aliveBlocks > 1 then
- local newPotato = table.randomKey(aliveBlocks)
- local str = string.translate("userPotatoEliminated", {username = self.userHoldingPotato, newUser = newPotato})
- tfm.exec.chatMessage(str)
- self.callbacks.updatePlayerPotato(newPotato)
- else
- local winner = aliveBlocks[1]
- local str = string.translate("gameWon", {username = self.userHoldingPotato, won = winner})
- tfm.exec.chatMessage(str)
- end
- end
- end,
- getAliveBlocks = function()
- local self = _MODULES.tagging
- local t = {}
- for player, data in pairs(self.players) do
- if data.alive then
- table.insert(t, player)
- end
- end
- return t
- end,
- on_eventKeyboard = function(player, key, down, x, y)
- local self = _MODULES.tagging
- if self.players[player] and self.players[player].alive and self.players[player].movementTimer < os.time()-150 and self.gameRunning then
- self.players[player].movementTimer = os.time()
- local diffX = 0
- local diffY = 0
- local looking = "south"
- if key == 0 then
- diffX = -1
- diffY = 0
- looking = "west"
- elseif key == 1 then
- diffX = 0
- diffY = -1
- looking = "north"
- elseif key == 2 then
- diffX = 1
- diffY = 0
- looking = "east"
- elseif key == 3 then
- diffX = 0
- diffY = 1
- looking = "south"
- else
- return
- end
- if diffX == 0 and diffY == 0 then
- return
- end
- local posX = self.players[player].x+diffX
- local posY = self.players[player].y+diffY
- if self.board[posX] and self.board[posX][posY] and self.board[posX][posY].hasBlock then
- if self.board[self.players[player].x][self.players[player].y].player == player then
- self.board[self.players[player].x][self.players[player].y].player = ""
- end
- self.players[player].y = posY
- self.players[player].x = posX
- if not (player == self.userHoldingPotato) then
- self.board[self.players[player].x][self.players[player].y].player = player
- end
- self.players[player].looking = looking
- self.callbacks.updatePlayerImage(player)
- if player == self.userHoldingPotato then
- local tile = self.board[self.players[player].x][self.players[player].y]
- if tile.player ~= "" and self.players[tile.player].canCatch < os.time()-5000 then
- self.players[player].canCatch = os.time()
- self.callbacks.updatePlayerPotato(tile.player)
- self.callbacks.updatePlayerImage(player)
- self.callbacks.updatePlayerImage(tile.player)
- local str = string.translate("potatoSwapped", {username = player, newUser = tile.player})
- tfm.exec.chatMessage(str)
- end
- end
- end
- end
- end,
- displayExplosion = function()
- local particles = {"15545c58f26", "15545c6aa79", "15545c7327f", "15545c7d1a1", "15545c85e31", "15545c8f98d"}
- end,
- initializeBoard = function()
- local self = _MODULES.tagging
- local canVertical = false
- local canHorizontal = false
- local spawningPlaces = {}
- self.board = {}
- for i = 1, self.mapWidth do
- self.board[i] = {}
- canHorizontal = not canHorizontal
- for j = 1, self.mapHeight do
- self.board[i][j] = {
- hasBlock = true,
- depth = {},
- player = "",
- spriteId = {}
- }
- if i == 1 or i == self.mapWidth or j == 1 or j == self.mapHeight then
- self.board[i][j].hasBlock = false
- else
- canVertical = not canVertical
- if canVertical and canHorizontal then
- self.board[i][j].hasBlock = false
- else
- table.insert(spawningPlaces, {i,j})
- end
- end
- end
- end
- self.callbacks.displayBoard(nil)
- local uniqueId = 0
- local players = {}
- for player, data in pairs(tfm.get.room.playerList) do
- local coords = table.randomKey(spawningPlaces)
- uniqueId = uniqueId+1
- self.players[player] = {
- x = coords[1],
- y = coords[2],
- looking = "south",
- imageId = -1,
- potatoTimer = false,
- movementTimer = os.time(),
- textId = uniqueId,
- alive = true,
- canCatch = os.time()
- }
- table.insert(players, player)
- self.callbacks.updatePlayerImage(player)
- end
- local p = table.randomKey(players)
- self.callbacks.updatePlayerPotato(p)
- self.gameRunning = true
- local str = string.translate("userPotato", {username = p})
- tfm.exec.chatMessage(str)
- end,
- updatePlayerPotato = function(player)
- local self = _MODULES.tagging
- self.userHoldingPotato = player
- self.players[self.userHoldingPotato].potatoTimer = os.time()
- self.callbacks.updatePlayerImage(self.userHoldingPotato)
- end,
- updatePlayerImage = function(player)
- local self = _MODULES.tagging
- local data = self.players[player]
- local spriteId = 1
- if self.userHoldingPotato == player then
- spriteId = 2
- end
- local isometric = math.toIso(data.x, data.y, self.blockArea)
- local tile = self.board[data.x][data.y]
- local imgData = self.sprites[spriteId]
- tfm.exec.removeImage(data.imageId)
- data.imageId = tfm.exec.addImage(imgData[data.looking]..".png", "!8000", self.diffX+isometric.x+imgData.offsetX, isometric.y+imgData.offsetY, nil)
- --local playerX = 400*(math.floor((self.diffX+isometric.x)/400))+280
- --local playerY = 200*(math.floor(isometric.y/200))+120
- --playerY = playerY > 680 and 660 or playerY
- tfm.exec.movePlayer(player, self.diffX+isometric.x, isometric.y, false, 0, 0, false)
- local text = string.format("«%s»", player)
- ui.addTextArea(data.textId, "<font color='#FFF3CE' font='Courier'>"..text, nil, (self.diffX+isometric.x+(imgData.offsetX*2)-5)-((string.len(text)*6)/2), (isometric.y+imgData.offsetY)-15, nil, nil, 0x1, 0x0, 0, false)
- ui.addTextArea(data.textId, "<font color='#6FFD57' font='Courier'>"..text, player, (self.diffX+isometric.x+(imgData.offsetX*2)-5)-((string.len(text)*6)/2), (isometric.y+imgData.offsetY)-15, nil, nil, 0x1, 0x0, 0, false)
- end,
- displayBoard = function(player)
- local self = _MODULES.tagging
- local coroutineBuilder = coroutine.create(
- function()
- for i = self.mapWidth, 1, -1 do
- for j = self.mapHeight, 1, -1 do
- local index = 1
- if self.board[i][j].hasBlock then
- index = 2
- end
- local isometric = math.toIso(i, j, self.blockArea)
- local tile = self.tiles[index]
- table.insert(self.board[i][j].spriteId, tfm.exec.addImage(tile.url, "!4", self.diffX+isometric.x+tile.offsetX, isometric.y+tile.offsetY, nil))
- end
- coroutine.yield()
- end
- end)
- _TIMERS["board"..tostring(player)] = loop(function()
- local status, result = coroutine.resume(coroutineBuilder)
- if result then
- if _TIMERS["board"..tostring(player)] then
- for _, timerId in pairs(_TIMERS["board"..tostring(player)]) do
- system.removeTimer(timerId)
- end
- end
- end
- return true
- end, 5)
- end
- }
- }
- }
- function removePlayerFromTile(tile, player)
- for index, depth in pairs(tile.depth) do
- if depth.type == "player" and depth.id == player then
- table.remove(tile.depth, index)
- break
- end
- end
- end
- function loop(fnc, ticks)
- local s = 1000/ticks
- local timers = {}
- for t = 0, 1000 - s, s do
- system.newTimer(function() table.insert(timers, system.newTimer(fnc, 1000, true)) end, 1000 + t, false)
- end
- return timers
- end
- function table.getKeys(rawTable)
- keys = {}
- for index in pairs(rawTable) do
- table.insert(keys, index)
- end
- return keys
- end
- function table.randomKey(rawTable)
- return rawTable[math.random(#rawTable)]
- end
- function math.toIso(x, y, area)
- local x2 = x-y
- local y2 = (x+y)/2
- return {x = x2*area, y = y2*area}
- end
- function math.toCart(x, y, area)
- local x2 = ((2*y+x)/2)/area
- local y2 = ((2*y-x)/2)/area
- return {x = math.ceil(x2), y = math.ceil(y2)}
- end
- _MESSAGES = {
- br = {
- userPotato = "{username} pegou a batata, fujam!",
- userPotatoEliminated = "{username} foi eliminado, {newUser} pegou a batata!",
- gameWon = "{username} foi eliminado, {won} é o vencedor!",
- potatoSwapped = "{username} passou a batata para {newUser}!",
- },
- en = {
- userPotato = "{username} got the potato, run!",
- userPotatoEliminated = "{username} has been eliminated, {newUser} has the potato!",
- gameWon = "{username} has been eliminated, {won} is the winner!",
- potatoSwapped = "{username} gave the potato to {newUser}!",
- }
- }
- function string.translate(key, args)
- local langue = tfm.get.room.community
- local translatedString = _MESSAGES[langue] or _MESSAGES.en
- translatedString = translatedString[key] or key
- return "<G>"..string.gsub(translatedString, "%{([A-Za-z0-9]+)%}", function(s)
- return "<BV>"..(args[s] or s).."</BV>"
- end)
- end
- function INIT(registeredModules)
- local pipes = {"eventNewPlayer", "eventNewGame", "eventKeyboard", "eventMouse", "eventLoop"}
- for _, moduleEvent in pairs(pipes) do
- _G[moduleEvent] = function(...)
- local args = {...}
- for _, moduleName in pairs(registeredModules) do
- if _MODULES[moduleName].running and _MODULES[moduleName].callbacks["on_"..moduleEvent] then
- _MODULES[moduleName].callbacks["on_"..moduleEvent](table.unpack(args))
- end
- end
- end
- end
- for player, data in pairs(tfm.get.room.playerList) do
- eventNewPlayer(player)
- print(player)
- end
- initNewModule()
- end
- function initNewModule()
- local registeredModules = {"tagging"}
- local randomModule = table.randomKey(registeredModules)
- _MODULES[randomModule].running = true
- _MODULES[randomModule].callbacks.on_startModule()
- end
- local registeredModules = {"tagging", "configPlayer"}
- INIT(registeredModules)
Advertisement
Add Comment
Please, Sign In to add comment