Advertisement
TFM-T-L

[Script] Portal Gun

Feb 7th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. tm = os.time()
  2. local players = {}
  3. local gmatch, match = string.gmatch, string.match
  4. local rad, cos, sin, floor = math.rad, math.cos, math.sin, math.floor
  5.  
  6. local groundGridManager = function()
  7. local self = { }
  8. local map = { }
  9. local grounds = { }
  10. local coroMap
  11. local dots = 1
  12. local text = "<p align='center'><font size='30'>Loading map grid"
  13.  
  14. local getGroundsData = function(xml)
  15. local grounds, counter = { }, 0
  16. for ground in gmatch(xml, "<S (.-)/>") do
  17. counter = counter + 1
  18. grounds[counter] = { }
  19.  
  20. for attribute, _, value in gmatch(ground, "(%-?%w+) *= *([\"'])(.-)%2") do
  21. grounds[counter][attribute] = tonumber(value) or value
  22. end
  23. end
  24. return grounds
  25. end
  26.  
  27. local rotatePoint = function(x, y, angle, xC, yC)
  28. angle = rad(angle)
  29. local sin = sin(angle)
  30. local cos = cos(angle)
  31.  
  32. x = xC - x
  33. y = yC - y
  34.  
  35. local nx = x * cos - y * sin
  36. local ny = y * cos + x * sin
  37.  
  38. x = nx + xC
  39. y = ny + yC
  40.  
  41. return floor(x), floor(y)
  42. end
  43.  
  44. local createPoint = function(x, y)
  45. if not map[x] then
  46. map[x] = { [y] = true }
  47. else
  48. map[x][y] = true
  49. end
  50. end
  51.  
  52. local updateText = function(pixels)
  53. ui.updateTextArea(-667, text .. string.rep('.', dots) .. "\n<font size='15'>" .. pixels .. " pixels loaded.")
  54. dots = dots % 3 + 1
  55. end
  56.  
  57. local generateMap = function()
  58. ui.addTextArea(-666, "", nil, -1500, -1500, 3000, 3000, 0x6A7495, 0x6A7495, 1, true)
  59. ui.addTextArea(-667, text, nil, 5, 170, 790, nil, 0x6A7495, 0x6A7495, 1, true)
  60.  
  61. local pixels = 0
  62.  
  63. local g, halfX, halfY, angle
  64. for z = 1, #grounds do
  65. g = grounds[z]
  66. if grounds.T ~= 12 then
  67. halfX = g.X - floor(g.L / 2)
  68. halfY = g.Y - floor(g.H / 2)
  69. angle = tonumber(match(g.P, ".-,.-,.-,.-,([^,]+)")) or 0
  70. for d = 1, g.L * g.H do
  71. local x = halfX + ((d - 1) % g.L)
  72. local y = halfY + floor(d / g.L)
  73.  
  74. if ang ~= 0 then
  75. x, y = rotatePoint(x, y, angle, g.X, g.Y)
  76. end
  77. createPoint(x, y)
  78.  
  79. pixels = pixels + 1
  80. if pixels % 480 == 0 then
  81. updateText(pixels)
  82. coroutine.yield()
  83. end
  84. end
  85. end
  86. end
  87.  
  88. ui.removeTextArea(-666)
  89. ui.removeTextArea(-667)
  90. end
  91.  
  92. self.updateMap = function()
  93. if not coroMap then return end
  94.  
  95. if coroMap == true then
  96. coroMap = coroutine.create(generateMap)
  97. end
  98.  
  99. if coroutine.status(coroMap) ~= "dead" then
  100. coroutine.resume(coroMap)
  101. else
  102. coroMap = nil
  103. for playerName in next, tfm.get.room.playerList do
  104. tfm.exec.respawnPlayer(playerName)
  105. end
  106. end
  107. end
  108.  
  109. self.new = function(xml)
  110. map = { }
  111.  
  112. grounds = getGroundsData(xml)
  113.  
  114. coroMap = true
  115. self.updateMap()
  116. end
  117.  
  118. self.refresh = function()
  119. map = { }
  120. coroMap = nil
  121. end
  122.  
  123. self.isGround = function(x, y)
  124. return map[x] and map[x][y] or false
  125. end
  126.  
  127. return self
  128. end
  129. local mapGrid = groundGridManager()
  130. eventLoop = function()
  131. mapGrid.updateMap()
  132. end
  133.  
  134. eventNewGame = function()
  135. for playerName in next, tfm.get.room.playerList do
  136. tfm.exec.killPlayer(playerName)
  137. end
  138.  
  139. local xml = tfm.get.room.xmlMapInfo
  140. if xml then
  141. mapGrid.new(xml.xml)
  142. else
  143. mapGrid.refresh()
  144. end
  145. end
  146.  
  147. system.bindMouse("Sla#3700")
  148. function eventMouse(name, x, y)
  149. local X2 = x - players[name].x
  150. local Y2 = y - players[name].y
  151. X2 = X2 / math.sqrt(math.pow(X2, 2) + math.pow(Y2, 2))
  152. Y2 = Y2 / math.sqrt(math.pow(X2, 2) + math.pow(Y2, 2))
  153. for z = 0, math.huge, math.min(math.abs(5 / X2), math.abs(5 / Y2)) do
  154. X3 = players[name].x + X2 * z
  155. Y3 = players[name].y + Y2 * z
  156. if X3 < 0 or X3 > 800 or Y3 < 0 or Y3 > 400 then
  157. break
  158. end
  159. end
  160. if mapGrid.isGround(players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15)) then
  161. tfm.exec.addShamanObject(26, players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15))
  162. prtl = true
  163. tfm.exec.displayParticle(9, players[name].x + X2 * (0 - 15), players[name].y + Y2 * (0 - 15), 0, 0, 0, 0)
  164. end
  165. end
  166.  
  167. function eventNewPlayer(name)
  168. players[name] = {x = tfm.get.room.playerList[name].x, y = tfm.get.room.playerList[name].y, dead = tfm.get.room.playerList[name].isDead }
  169. print(players[name].dead)
  170. end
  171. table.foreach(tfm.get.room.playerList, eventNewPlayer)
  172.  
  173. 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>')
  174. tfm.exec.disableAutoNewGame(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement