Advertisement
Eliaseeg

Detectar si se invoca un objeto en la madriguera

May 29th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. local maps = {
  2.     '<C><P /><Z><S><S L="200" Y="300" P="0,0,0.3,0.2,0,0,0,0" T="0" X="400" H="50" /></S><D><T X="350" Y="275" /><F X="450" Y="270" /></D><O /></Z></C>'
  3. }
  4. local holeX
  5. local holeY
  6.  
  7. function main()
  8.     tfm.exec.disableAutoNewGame(true)
  9.     tfm.exec.newGame(maps[math.random(#maps)])
  10. end
  11.  
  12. function eventNewGame()
  13.     local xml = tfm.get.room.xmlMapInfo.xml
  14.     xmldom = parseXml(xml)
  15.     for _,s in ipairs(path(xmldom, "Z", "D", "T")) do
  16.         local ss = s.attribute
  17.         holeX = ss.X
  18.         holeY = ss.Y
  19.     end
  20. end
  21.  
  22. function eventSummoningEnd(name, object, x, y, angle, xSpeed, ySpeed, objectType, other)
  23.     if pythag(holeX, holeY, x, y, 30) then
  24.         for name, player in pairs(tfm.get.room.playerList) do
  25.             if player.isShaman then
  26.                 tfm.exec.killPlayer(name)
  27.             end
  28.         end
  29.     end
  30. end
  31.  
  32. function pythag(x1,y1,x2,y2,r)
  33.     local x=x2-x1
  34.     local y=y2-y1
  35.     local r=r+r
  36.     return x*x+y*y<r*r
  37. end
  38.  
  39.  
  40. -- Makinit's XML Library
  41. do
  42.     local namePattern = "[%a_:][%w%.%-_:]*"
  43.     function parseXml(xml)
  44.         local root = {}
  45.         local parents = {}
  46.         local element = root
  47.         for closing, name, attributes, empty, text in string.gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  48.             if closing == "/" then
  49.                 local parent = parents[element]
  50.                 if parent and name == element.name then
  51.                     element = parent
  52.                 end
  53.             else
  54.                 local child = {name = name, attribute = {}}
  55.                 table.insert(element, child)
  56.                 parents[child] = element
  57.                 if empty ~= "/" then
  58.                     element = child
  59.                 end
  60.                 for name, value in string.gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  61.                     child.attribute[name] = value
  62.                 end
  63.             end
  64.             if text ~= "" then
  65.                 local child = {text = text}
  66.                 table.insert(element, child)
  67.                 parents[child] = element
  68.             end
  69.         end
  70.         return root[1]
  71.     end
  72.  
  73.     function path(nodes, ...)
  74.         nodes = {nodes}
  75.         for i, name in ipairs(arg) do
  76.             local match = {}
  77.             for i, node in ipairs(nodes) do
  78.                 for i, child in ipairs(node) do
  79.                     if child.name == name then
  80.                         table.insert(match, child)
  81.                     end
  82.                 end
  83.             end
  84.             nodes = match
  85.         end
  86.         return nodes
  87.     end
  88. end
  89.  
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement