Advertisement
Guest User

Mice-up === Alexunutrei

a guest
May 31st, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.39 KB | None | 0 0
  1. tfm.exec.disableAutoShaman(true)
  2. tfm.exec.disableAutoNewGame(true)
  3. tfm.exec.disableAutoScore(true)
  4. tfm.exec.disableAutoTimeLeft(true)
  5.  
  6.  
  7. maps={'@6017977'}
  8.  
  9. candy={}
  10.  
  11. local namePattern = "[%a_:][%w%.%-_:]*"
  12. function parseXml(xml)
  13.     local root = {}
  14.     local parents = {}
  15.     local element = root
  16.     for closing, name, attributes, empty, text in string.gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  17.         if closing == "/" then
  18.             local parent = parents[element]
  19.             if parent and name == element.name then
  20.                 element = parent
  21.             end
  22.         else
  23.             local child = {name = name, attribute = {}}
  24.             table.insert(element, child)
  25.             parents[child] = element
  26.             if empty ~= "/" then
  27.                 element = child
  28.             end
  29.             for name, value in string.gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  30.                 child.attribute[name] = value
  31.             end
  32.         end
  33.         if text ~= "" then
  34.             local child = {text = fast and text or xmlUnescape(text)}
  35.             table.insert(element, child)
  36.             parents[child] = element
  37.         end
  38.     end
  39.     return root[1]
  40. end
  41.  
  42. function generateXml(element)
  43.     if element.name then
  44.         local xml = "<" .. element.name
  45.         for name, value in pairs(element.attribute) do
  46.             xml = xml .. " " .. name .. "=\"" .. tostring(value) .. "\""
  47.         end
  48.         if #element == 0 then
  49.             xml = xml .. " />"
  50.         else
  51.             xml = xml .. ">"
  52.             for i, child in ipairs(element) do
  53.                 xml = xml .. generateXml(child)
  54.             end
  55.             xml = xml .. "</" .. element.name .. ">"
  56.         end
  57.         return xml
  58.     elseif element.text then
  59.         return tostring(element.text)
  60.     end
  61. end
  62.  
  63. function path(nodes, ...)
  64.     nodes = {nodes}
  65.     for i, name in ipairs(arg) do
  66.         local match = {}
  67.         for i, node in ipairs(nodes) do
  68.             for i, child in ipairs(node) do
  69.                 if child.name == name then
  70.                     table.insert(match, child)
  71.                 end
  72.             end
  73.         end
  74.         nodes = match
  75.     end
  76.     return nodes
  77. end
  78.  
  79. function eventNewGame()
  80. toDespawn={}
  81. for i=1,#candy+10 do
  82. ui.removeTextArea(i,nil)
  83. end
  84.  
  85. candy={}
  86.     local xml = tfm.get.room.xmlMapInfo.xml
  87.     if xml then
  88.         local dom = parseXml(xml, true)
  89.         local d = path(dom, "Z", "O")[1]
  90.         for i, node in ipairs(d) do
  91.             local name = node.name
  92.             if name == "O" and tonumber(node.attribute.C)==12 then
  93.                 local x, y = tonumber(node.attribute.X) or 0, tonumber(node.attribute.Y) or 0
  94.                           table.insert(candy, {x = x, y = y, t = 0})
  95.              
  96.                 end
  97.             end
  98.         end
  99.  
  100. for n,p in pairs(tfm.get.room.playerList) do
  101. eventNewPlayer(n)
  102. end
  103. end
  104.  
  105. toDespawn={}
  106.  
  107. function eventLoop(te,tr)
  108. for i=1,#candy+10 do
  109. ui.removeTextArea(i,nil)
  110. end
  111. for i=1,#candy do
  112. if candy[i].t<=0 then
  113. ui.addTextArea(i,[[<p align="center"><font size="20"><b>!</b></font></p>]],nil,candy[i].x-15,candy[i].y-15,30,30)
  114. else
  115. candy[i].t=candy[i].t-0.5
  116. end
  117. end
  118. for i,cannon in ipairs(toDespawn) do
  119. if cannon[1] <= os.time()-5000 then
  120. tfm.exec.removeObject(cannon[2])
  121. table.remove(toDespawn,i)
  122. end
  123. end
  124. if tr<=0 then newMap()
  125. end
  126. end
  127.  
  128. players={}
  129.  
  130. function eventNewPlayer(n)
  131. players[n]={power='not'}
  132. tfm.exec.bindKeyboard(n,32,true,true)
  133. tfm.exec.bindKeyboard(n,75,true,true)
  134. tfm.exec.bindKeyboard(n,87,true,true)
  135. tfm.exec.bindKeyboard(n,38,true,true)
  136.  
  137. ui.addTextArea(999,[[<p align="center">Power:
  138.  
  139. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  140. end
  141.  
  142. for n,p in pairs(tfm.get.room.playerList) do
  143. eventNewPlayer(n)
  144. end
  145.  
  146. function eventKeyboard(n,k,down,x,y)
  147. if k==32 then
  148. local cnnd=0
  149. for i,candyze in ipairs(candy) do
  150. cnnd=cnnd+1
  151. if x<=candyze.x+15 and x>=candyze.x-15 and y<=candyze.y+15 and y>=candyze.y-15 then
  152. if candyze.t==0 then
  153. ui.removeTextArea(cnnd,nil)
  154. candyze.t=math.random(10,20)
  155. setPower(n)
  156. break
  157. elseif candyze.t==-1 then
  158. table.remove(candy,i)
  159. ui.removeTextArea(cnnd,nil)
  160. local id=tfm.exec.addShamanObject(68,x,y)
  161. table.insert(toDespawn,{os.time(),id})
  162. break
  163. end
  164. end
  165. end
  166. end
  167. ------------------
  168. if k==87 or k==38 then
  169. if players[n].power=='Double jump' and tfm.get.room.playerList[n].isJumping then
  170. tfm.exec.movePlayer(n,0,0,true,0,-75,true)
  171. players[n].power='Not'
  172. ui.removeTextArea(999,n)
  173. ui.addTextArea(999,[[<p align="center">Power:
  174.  
  175. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  176. end
  177. end
  178. ------------------
  179.  
  180. if k==75 then
  181. if players[n].power=='Speed' then
  182. tfm.exec.movePlayer(n,0,0,true,tfm.get.room.playerList[n].isFacingRight and 100 or -100,0,true)
  183. players[n].power='Not'
  184. ui.removeTextArea(999,n)
  185. ui.addTextArea(999,[[<p align="center">Power:
  186.  
  187. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  188. elseif players[n].power=='Spirit jump' then
  189. tfm.exec.addShamanObject(24,x,y+20)
  190. players[n].power='Not'
  191. ui.removeTextArea(999,n)
  192. ui.addTextArea(999,[[<p align="center">Power:
  193.  
  194. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  195. elseif players[n].power=='Trap' then
  196. ui.addTextArea(#candy+1,[[<p align="center"><font size="20"><b>!</b></font></p>]],nil,x-15,y-15,30,30)
  197. table.insert(candy, {x = x, y = y, t = -1})
  198. players[n].power='Not'
  199. ui.removeTextArea(999,n)
  200. ui.addTextArea(999,[[<p align="center">Power:
  201.  
  202. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  203. end
  204. end
  205.  
  206. end
  207.  
  208. powers={'Double jump','Speed','Spirit jump','Trap'}
  209.  
  210. function setPower(n)
  211. players[n].power=powers[math.random(#powers)]
  212. ui.addTextArea(999,[[<p align="center">Power:
  213.  
  214. ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
  215. end
  216.  
  217.  
  218. function newMap()
  219. tfm.exec.newGame(maps[math.random(#maps)])
  220. end
  221.  
  222. function eventPlayerDied(n)
  223. local abcdx=0
  224. for namme,pl in pairs(tfm.get.room.playerList) do
  225. if not tfm.get.room.playerList[namme].isDead  then abcdx=abcdx+1
  226. end
  227. end
  228. if abcdx<3 and abcdx>0 then tfm.exec.setGameTime(20)
  229. elseif abcdx==0 then tfm.exec.setGameTime(3)
  230. end
  231. end
  232.  
  233. function eventPlayerWon(n)
  234. local abcdx=0
  235. for namme,pl in pairs(tfm.get.room.playerList) do
  236. if not tfm.get.room.playerList[namme].isDead  then abcdx=abcdx+1
  237. end
  238. end
  239. if abcdx<3 and abcdx>0 then tfm.exec.setGameTime(20)
  240. elseif abcdx==0 then tfm.exec.setGameTime(3)
  241. end
  242. end
  243. newMap()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement