Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoScore(true)
- tfm.exec.disableAutoTimeLeft(true)
- maps={'@6017977'}
- candy={}
- local namePattern = "[%a_:][%w%.%-_:]*"
- function parseXml(xml)
- local root = {}
- local parents = {}
- local element = root
- for closing, name, attributes, empty, text in string.gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
- if closing == "/" then
- local parent = parents[element]
- if parent and name == element.name then
- element = parent
- end
- else
- local child = {name = name, attribute = {}}
- table.insert(element, child)
- parents[child] = element
- if empty ~= "/" then
- element = child
- end
- for name, value in string.gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
- child.attribute[name] = value
- end
- end
- if text ~= "" then
- local child = {text = fast and text or xmlUnescape(text)}
- table.insert(element, child)
- parents[child] = element
- end
- end
- return root[1]
- end
- function generateXml(element)
- if element.name then
- local xml = "<" .. element.name
- for name, value in pairs(element.attribute) do
- xml = xml .. " " .. name .. "=\"" .. tostring(value) .. "\""
- end
- if #element == 0 then
- xml = xml .. " />"
- else
- xml = xml .. ">"
- for i, child in ipairs(element) do
- xml = xml .. generateXml(child)
- end
- xml = xml .. "</" .. element.name .. ">"
- end
- return xml
- elseif element.text then
- return tostring(element.text)
- end
- end
- function path(nodes, ...)
- nodes = {nodes}
- for i, name in ipairs(arg) do
- local match = {}
- for i, node in ipairs(nodes) do
- for i, child in ipairs(node) do
- if child.name == name then
- table.insert(match, child)
- end
- end
- end
- nodes = match
- end
- return nodes
- end
- function eventNewGame()
- toDespawn={}
- for i=1,#candy+10 do
- ui.removeTextArea(i,nil)
- end
- candy={}
- local xml = tfm.get.room.xmlMapInfo.xml
- if xml then
- local dom = parseXml(xml, true)
- local d = path(dom, "Z", "O")[1]
- for i, node in ipairs(d) do
- local name = node.name
- if name == "O" and tonumber(node.attribute.C)==12 then
- local x, y = tonumber(node.attribute.X) or 0, tonumber(node.attribute.Y) or 0
- table.insert(candy, {x = x, y = y, t = 0})
- end
- end
- end
- for n,p in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- end
- toDespawn={}
- function eventLoop(te,tr)
- for i=1,#candy+10 do
- ui.removeTextArea(i,nil)
- end
- for i=1,#candy do
- if candy[i].t<=0 then
- ui.addTextArea(i,[[<p align="center"><font size="20"><b>!</b></font></p>]],nil,candy[i].x-15,candy[i].y-15,30,30)
- else
- candy[i].t=candy[i].t-0.5
- end
- end
- for i,cannon in ipairs(toDespawn) do
- if cannon[1] <= os.time()-5000 then
- tfm.exec.removeObject(cannon[2])
- table.remove(toDespawn,i)
- end
- end
- if tr<=0 then newMap()
- end
- end
- players={}
- function eventNewPlayer(n)
- players[n]={power='not'}
- tfm.exec.bindKeyboard(n,32,true,true)
- tfm.exec.bindKeyboard(n,75,true,true)
- tfm.exec.bindKeyboard(n,87,true,true)
- tfm.exec.bindKeyboard(n,38,true,true)
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- end
- for n,p in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- function eventKeyboard(n,k,down,x,y)
- if k==32 then
- local cnnd=0
- for i,candyze in ipairs(candy) do
- cnnd=cnnd+1
- if x<=candyze.x+15 and x>=candyze.x-15 and y<=candyze.y+15 and y>=candyze.y-15 then
- if candyze.t==0 then
- ui.removeTextArea(cnnd,nil)
- candyze.t=math.random(10,20)
- setPower(n)
- break
- elseif candyze.t==-1 then
- table.remove(candy,i)
- ui.removeTextArea(cnnd,nil)
- local id=tfm.exec.addShamanObject(68,x,y)
- table.insert(toDespawn,{os.time(),id})
- break
- end
- end
- end
- end
- ------------------
- if k==87 or k==38 then
- if players[n].power=='Double jump' and tfm.get.room.playerList[n].isJumping then
- tfm.exec.movePlayer(n,0,0,true,0,-75,true)
- players[n].power='Not'
- ui.removeTextArea(999,n)
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- end
- end
- ------------------
- if k==75 then
- if players[n].power=='Speed' then
- tfm.exec.movePlayer(n,0,0,true,tfm.get.room.playerList[n].isFacingRight and 100 or -100,0,true)
- players[n].power='Not'
- ui.removeTextArea(999,n)
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- elseif players[n].power=='Spirit jump' then
- tfm.exec.addShamanObject(24,x,y+20)
- players[n].power='Not'
- ui.removeTextArea(999,n)
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- elseif players[n].power=='Trap' then
- ui.addTextArea(#candy+1,[[<p align="center"><font size="20"><b>!</b></font></p>]],nil,x-15,y-15,30,30)
- table.insert(candy, {x = x, y = y, t = -1})
- players[n].power='Not'
- ui.removeTextArea(999,n)
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- end
- end
- end
- powers={'Double jump','Speed','Spirit jump','Trap'}
- function setPower(n)
- players[n].power=powers[math.random(#powers)]
- ui.addTextArea(999,[[<p align="center">Power:
- ]]..players[n].power..[[</a>]],n,375,20,80,50,nil,nil,0.5,true)
- end
- function newMap()
- tfm.exec.newGame(maps[math.random(#maps)])
- end
- function eventPlayerDied(n)
- local abcdx=0
- for namme,pl in pairs(tfm.get.room.playerList) do
- if not tfm.get.room.playerList[namme].isDead then abcdx=abcdx+1
- end
- end
- if abcdx<3 and abcdx>0 then tfm.exec.setGameTime(20)
- elseif abcdx==0 then tfm.exec.setGameTime(3)
- end
- end
- function eventPlayerWon(n)
- local abcdx=0
- for namme,pl in pairs(tfm.get.room.playerList) do
- if not tfm.get.room.playerList[namme].isDead then abcdx=abcdx+1
- end
- end
- if abcdx<3 and abcdx>0 then tfm.exec.setGameTime(20)
- elseif abcdx==0 then tfm.exec.setGameTime(3)
- end
- end
- newMap()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement