Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local maps={
- '<C><P F="8" /><Z><S><S H="400" P="0,0,0.3,0.2,0,0,0,0" L="20" X="10" Y="200" T="6" /><S H="20" P="0,0,0.3,0.2,0,0,0,0" L="715" X="377" Y="88" T="6" /><S P="0,0,0.3,0.2,0,0,0,0" L="20" H="400" X="790" Y="200" T="6" /><S P="0,0,0.3,0.2,0,0,0,0" L="715" H="20" X="421" Y="175" T="6" /><S P="0,0,0.3,0.2,0,0,0,0" L="715" H="20" X="377" Y="260" T="6" /><S P="0,0,0.3,0.2,0,0,0,0" L="715" H="20" X="421" Y="340" T="6" /><S P="0,0,0.3,0.2,0,0,0,0" L="760" H="20" X="400" Y="405" T="6" /><S H="53" P="0,0,0.3,0.2,0,0,0,0" L="213" o="ff00" X="209" c="4" Y="50" T="12" /><S H="66" P="0,0,0.3,0.2,0,0,0,0" L="210" o="fff000" X="221" c="4" Y="131" T="12" /><S H="64" P="0,0,0.3,0.2,0,0,0,0" L="197" o="ff00ff" X="491" c="4" Y="218" T="12" /><S H="58" P="0,0,0.3,0.2,0,0,0,0" L="245" o="0" X="250" c="4" Y="300" T="12" /></S><D><T Y="394" X="757" /><DS Y="63" X="45" /></D><O /></Z></C>'
- }
- local gameLoaded = false
- local areas
- local areas_n
- local _green,_yellow,_purple,_black = 0x00FF00,0xFFF000,0xFF00FF,0x000000
- function main()
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.newGame(maps[math.random(#maps)])
- end
- function eventNewGame()
- gameLoaded = true
- areas = {}
- areas_n = 0
- local xml = tfm.get.room.xmlMapInfo.xml
- xmldom = parseXml(xml)
- for _,s in ipairs(path(xmldom, "Z", "S")[1]) do
- local ss = s.attribute
- if ss.T == "12" and ss.c == "4" then
- local x,y,w,h = ss.X,ss.Y,ss.L,ss.H
- local dx,dy = w/2,h/2
- local a = {
- x1 = x - dx,
- x2 = x + dx,
- y1 = y - dy,
- y2 = y + dy,
- color = tonumber(ss.o, 16)}
- areas_n = areas_n + 1
- areas[areas_n] = a
- end
- end
- end
- function eventLoop(t, tr)
- if not gameLoaded then return end
- for name,p in pairs(tfm.get.room.playerList) do
- for i=1,areas_n do
- local a = areas[i]
- if p.x > a.x1 and p.x < a.x2 and p.y > a.y1 and p.y < a.y2 then
- if a.color == _green then
- -- give speed
- elseif a.color == _yellow then
- tfm.exec.giveCheese(name)
- elseif a.color == _purple then
- tfm.exec.playerVictory(name)
- elseif a.color == _black then
- tfm.exec.killPlayer(name)
- end
- end
- end
- end
- end
- -- Makinit's xml library (short version for reading only)
- do
- 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 = text}
- table.insert(element, child)
- parents[child] = element
- end
- end
- return root[1]
- 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
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement