Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tm = os.time()
- local players = {}
- local gmatch, match = string.gmatch, string.match
- local rad, cos, sin, floor = math.rad, math.cos, math.sin, math.floor
- local groundGridManager = function()
- local self = { }
- local map = { }
- local grounds = { }
- local coroMap
- local dots = 1
- local text = "<p align='center'><font size='30'>Loading map grid"
- local getGroundsData = function(xml)
- local grounds, counter = { }, 0
- for ground in gmatch(xml, "<S (.-)/>") do
- counter = counter + 1
- grounds[counter] = { }
- for attribute, _, value in gmatch(ground, "(%-?%w+) *= *([\"'])(.-)%2") do
- grounds[counter][attribute] = tonumber(value) or value
- end
- end
- return grounds
- end
- local rotatePoint = function(x, y, angle, xC, yC)
- angle = rad(angle)
- local sin = sin(angle)
- local cos = cos(angle)
- x = xC - x
- y = yC - y
- local nx = x * cos - y * sin
- local ny = y * cos + x * sin
- x = nx + xC
- y = ny + yC
- return floor(x), floor(y)
- end
- local createPoint = function(x, y)
- if not map[x] then
- map[x] = { [y] = true }
- else
- map[x][y] = true
- end
- end
- local updateText = function(pixels)
- ui.updateTextArea(-667, text .. string.rep('.', dots) .. "\n<font size='15'>" .. pixels .. " pixels loaded.")
- dots = dots % 3 + 1
- end
- local generateMap = function()
- ui.addTextArea(-666, "", nil, -1500, -1500, 3000, 3000, 0x6A7495, 0x6A7495, 1, true)
- ui.addTextArea(-667, text, nil, 5, 170, 790, nil, 0x6A7495, 0x6A7495, 1, true)
- local pixels = 0
- local g, halfX, halfY, angle
- for z = 1, #grounds do
- g = grounds[z]
- if grounds.T ~= 12 then
- halfX = g.X - floor(g.L / 2)
- halfY = g.Y - floor(g.H / 2)
- angle = tonumber(match(g.P, ".-,.-,.-,.-,([^,]+)")) or 0
- for d = 1, g.L * g.H do
- local x = halfX + ((d - 1) % g.L)
- local y = halfY + floor(d / g.L)
- if ang ~= 0 then
- x, y = rotatePoint(x, y, angle, g.X, g.Y)
- end
- createPoint(x, y)
- pixels = pixels + 1
- if pixels % 480 == 0 then
- updateText(pixels)
- coroutine.yield()
- end
- end
- end
- end
- ui.removeTextArea(-666)
- ui.removeTextArea(-667)
- end
- self.updateMap = function()
- if not coroMap then return end
- if coroMap == true then
- coroMap = coroutine.create(generateMap)
- end
- if coroutine.status(coroMap) ~= "dead" then
- coroutine.resume(coroMap)
- else
- coroMap = nil
- for playerName in next, tfm.get.room.playerList do
- tfm.exec.respawnPlayer(playerName)
- end
- end
- end
- self.new = function(xml)
- map = { }
- grounds = getGroundsData(xml)
- coroMap = true
- self.updateMap()
- end
- self.refresh = function()
- map = { }
- coroMap = nil
- end
- self.isGround = function(x, y)
- return map[x] and map[x][y] or false
- end
- return self
- end
- local mapGrid = groundGridManager()
- eventLoop = function()
- mapGrid.updateMap()
- end
- eventNewGame = function()
- for playerName in next, tfm.get.room.playerList do
- tfm.exec.killPlayer(playerName)
- end
- local xml = tfm.get.room.xmlMapInfo
- if xml then
- mapGrid.new(xml.xml)
- else
- mapGrid.refresh()
- end
- end
- system.bindMouse("Sla#3700")
- function eventMouse(name, x, y)
- local X2 = x - players[name].x
- local Y2 = y - players[name].y
- X2 = X2 / math.sqrt(math.pow(X2, 2) + math.pow(Y2, 2))
- Y2 = Y2 / math.sqrt(math.pow(X2, 2) + math.pow(Y2, 2))
- for z = 0, math.huge, math.min(math.abs(5 / X2), math.abs(5 / Y2)) do
- X3 = players[name].x + X2 * z
- Y3 = players[name].y + Y2 * z
- if X3 < 0 or X3 > 800 or Y3 < 0 or Y3 > 400 then
- break
- end
- end
- if mapGrid.isGround(players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15)) then
- tfm.exec.addShamanObject(26, players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15))
- prtl = true
- tfm.exec.displayParticle(9, players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15), 0, 0, 0, 0)
- end
- end
- function eventNewPlayer(name)
- players[name] = {x = tfm.get.room.playerList[name].x, y = tfm.get.room.playerList[name].y, dead = tfm.get.room.playerList[name].isDead }
- print(players[name].dead)
- end
- table.foreach(tfm.get.room.playerList, eventNewPlayer)
- tfm.exec.newGame('<C><P /><Z><S><S L="801" o="324650" H="58" X="400" Y="372" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="25" o="324650" H="139" X="145" Y="173" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="52" o="324650" H="105" X="523" Y="160" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="86" o="324650" H="62" X="364" Y="138" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S L="41" o="324650" H="57" X="673" Y="174" T="12" P="0,0,0.3,0.2,0,0,0,0" /></S><D /><O /></Z></C>')
- tfm.exec.disableAutoNewGame(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement