Advertisement
Guest User

Untitled

a guest
Oct 15th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. local maps={
  2.     '<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>'
  3. }
  4.  
  5. local gameLoaded = false
  6. local areas
  7. local areas_n
  8.  
  9. local _green,_yellow,_purple,_black = 0x00FF00,0xFFF000,0xFF00FF,0x000000
  10.  
  11. function main()
  12.     tfm.exec.disableAutoNewGame(true)
  13.     tfm.exec.disableAutoShaman(true)
  14.     tfm.exec.newGame(maps[math.random(#maps)])
  15. end
  16.  
  17. function eventNewGame()
  18.     gameLoaded = true
  19.    
  20.     areas = {}
  21.     areas_n = 0
  22.    
  23.     local xml = tfm.get.room.xmlMapInfo.xml
  24.     xmldom = parseXml(xml)
  25.    
  26.     for _,s in ipairs(path(xmldom, "Z", "S")[1]) do
  27.         local ss = s.attribute
  28.         if ss.T == "12" and ss.c == "4" then
  29.             local x,y,w,h = ss.X,ss.Y,ss.L,ss.H
  30.             local dx,dy = w/2,h/2
  31.             local a = {
  32.                 x1 = x - dx,
  33.                 x2 = x + dx,
  34.                 y1 = y - dy,
  35.                 y2 = y + dy,
  36.                 color = tonumber(ss.o, 16)}
  37.            
  38.             areas_n = areas_n + 1
  39.             areas[areas_n] = a
  40.         end
  41.     end
  42. end
  43.  
  44. function eventLoop(t, tr)
  45.     if not gameLoaded then return end
  46.     for name,p in pairs(tfm.get.room.playerList) do
  47.         for i=1,areas_n do
  48.             local a = areas[i]
  49.             if p.x > a.x1 and p.x < a.x2 and p.y > a.y1 and p.y < a.y2 then
  50.                 if a.color == _green then
  51.                     -- give speed
  52.                 elseif a.color == _yellow then
  53.                     tfm.exec.giveCheese(name)
  54.                 elseif a.color == _purple then
  55.                     tfm.exec.playerVictory(name)
  56.                 elseif a.color == _black then
  57.                     tfm.exec.killPlayer(name)
  58.                 end
  59.             end
  60.         end
  61.     end
  62. end
  63.  
  64. --  Makinit's xml library (short version for reading only)
  65. do
  66.     local namePattern = "[%a_:][%w%.%-_:]*"
  67.     function parseXml(xml)
  68.         local root = {}
  69.         local parents = {}
  70.         local element = root
  71.         for closing, name, attributes, empty, text in string.gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  72.             if closing == "/" then
  73.                 local parent = parents[element]
  74.                 if parent and name == element.name then
  75.                     element = parent
  76.                 end
  77.             else
  78.                 local child = {name = name, attribute = {}}
  79.                 table.insert(element, child)
  80.                 parents[child] = element
  81.                 if empty ~= "/" then
  82.                     element = child
  83.                 end
  84.                 for name, value in string.gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  85.                     child.attribute[name] = value
  86.                 end
  87.             end
  88.             if text ~= "" then
  89.                 local child = {text = text}
  90.                 table.insert(element, child)
  91.                 parents[child] = element
  92.             end
  93.         end
  94.         return root[1]
  95.     end
  96.  
  97.     function path(nodes, ...)
  98.         nodes = {nodes}
  99.         for i, name in ipairs(arg) do
  100.             local match = {}
  101.             for i, node in ipairs(nodes) do
  102.                 for i, child in ipairs(node) do
  103.                     if child.name == name then
  104.                         table.insert(match, child)
  105.                     end
  106.                 end
  107.             end
  108.             nodes = match
  109.         end
  110.         return nodes
  111.     end
  112. end
  113.  
  114. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement