Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.37 KB | None | 0 0
  1. --[[
  2. 2016 03 20 - Remove Grounds
  3. Remove any ground you want by clicking.
  4.  
  5. Commands
  6. =========================================================================
  7. msg               Send a public chat message as [Funcorp] in orange text
  8. kill              Kill all mice except for you
  9. removegrounds     Enable/disable removing grounds by clicking
  10.  
  11. Controls
  12. =========================================================================
  13. Admin: Click on any ground to remove it, you'll have to click on rotated
  14.        grounds near the center. Doesn't work in vanilla maps.
  15. ]]
  16.  
  17.  
  18. admins = {"Sebaisseba#0020"}
  19.  
  20. text = {}
  21. text.en = {
  22.     welcome = "<VP>Welcome to the FunCorp room!\n<J>Stats don't count here."
  23. }
  24. text.es = {
  25.     welcome = "<VP>¡Bienvenido a la sala FunCorp!\n<J>Aquí no cuentan los stats."
  26. }
  27.  
  28. commands = {"msg","kill","removegrounds"}
  29. adminMice = {}
  30. ground = {}
  31. ground_n = 0
  32. lang = text[tfm.get.room.community] or text.en
  33.  
  34. function main()
  35.     for _,c in pairs(commands) do
  36.         system.disableChatCommandDisplay(c)
  37.     end
  38.     for n in pairs(tfm.get.room.playerList) do
  39.         eventNewPlayer(n)
  40.     end
  41. end
  42.  
  43. function table.contains(t,v)
  44.  for p,i in pairs(t) do
  45.   if i==v then
  46.    return true
  47.   end
  48.  end
  49.  return false
  50. end
  51.  
  52. function newAdmin(name)
  53.     adminMice[name] = {
  54.         removeGrounds = true
  55.     }
  56.     system.bindMouse(name, true)
  57. end
  58.  
  59. function eventNewPlayer(name)
  60.     if table.contains(admins,name) then newAdmin(name) end
  61.     tfm.exec.chatMessage(lang.welcome, name)
  62. end
  63.  
  64. for k,v in pairs(tfm.get.room.playerList) do
  65.  eventNewPlayer(k)
  66. end
  67.  
  68. local ownXml, mapCode
  69. function eventNewGame()
  70.     if ownXml then
  71.         ui.setMapName("<font color='#ff8547'>FunCorp</font><BL> / @"..mapCode)
  72.         ownXml = false
  73.     else
  74.         local xmlMapInfo = tfm.get.room.xmlMapInfo
  75.         if not xmlMapInfo then print(ownXml) return end
  76.         local oldCode = mapCode
  77.         mapCode = xmlMapInfo.mapCode
  78.         if mapCode == oldCode then tfm.exec.newGame() end
  79.         xmldom = parseXml(xmlMapInfo.xml, true)
  80.        
  81.         ground = {}
  82.         ground_n = 0
  83.        
  84.         for i,s in ipairs(path(xmldom, "Z", "S")[1]) do
  85.             local ss = s.attribute
  86.             local dx,dy = ss.L/2, ss.H/2
  87.             ground_n = ground_n + 1
  88.             ground[ground_n] = {
  89.                 x1 = ss.X - dx,
  90.                 x2 = ss.X + dx,
  91.                 y1 = ss.Y - dy,
  92.                 y2 = ss.Y + dy,
  93.                 id = i
  94.             }
  95.             ss.lua = i
  96.         end
  97.         ownXml = true
  98.         tfm.exec.newGame(generateXml(xmldom, true))
  99.     end
  100. end
  101.  
  102. function eventMouse(name, mx, my)
  103.     if not adminMice[name].removeGrounds then return end
  104.     for i=1,ground_n do
  105.         local g = ground[i]
  106.         if mx>g.x1 and mx<g.x2 and my>g.y1 and my<g.y2 then
  107.             tfm.exec.removePhysicObject(g.id)
  108.             table.remove(ground, i)
  109.             ground_n = ground_n - 1
  110.             return
  111.         end
  112.     end
  113. end
  114.  
  115. function eventChatCommand(name, mes)
  116.     if table.contains(admins,name) then
  117.         if mes:sub(1,3) == "msg" then
  118.             tfm.exec.chatMessage("<font color='#ff8547'>[FunCorp] "..mes:sub(5).."</font>", nil)
  119.         elseif mes == "removegrounds" then
  120.             local state = adminMice[name].removeGrounds
  121.             local t = state and "<R>Remove grounds disabled" or "<VP>Remove grounds enabled"
  122.             adminMice[name].removeGrounds = not state
  123.             tfm.exec.chatMessage(t, name)
  124.         elseif mes == "kill" then
  125.             for n in pairs(tfm.get.room.playerList) do
  126.                 if n ~= name then
  127.                     tfm.exec.killPlayer(n)
  128.                 end
  129.             end
  130.         end
  131.     end
  132. end
  133.  
  134. --  Makinit's xml library (full)
  135. do
  136.     local namePattern = "[%a_:][%w%.%-_:]*"
  137.     function parseXml(xml, fast)
  138.         if not fast then
  139.             xml = string.gsub(xml, "<!%[CDATA%[(.-)%]%]>", xmlEscape) -- replace CDATA with escaped text
  140.             xml = string.gsub(xml, "<%?.-%?>", "") -- remove processing instructions
  141.             xml = string.gsub(xml, "<!%-%-.-%-%->", "") -- remove comments
  142.             xml = string.gsub(xml, "<!.->", "")
  143.         end
  144.         local root = {}
  145.         local parents = {}
  146.         local element = root
  147.         for closing, name, attributes, empty, text in string.gmatch(xml, "<(/?)(" .. namePattern .. ")(.-)(/?)>%s*([^<]*)%s*") do
  148.             if closing == "/" then
  149.                 local parent = parents[element]
  150.                 if parent and name == element.name then
  151.                     element = parent
  152.                 end
  153.             else
  154.                 local child = {name = name, attribute = {}}
  155.                 table.insert(element, child)
  156.                 parents[child] = element
  157.                 if empty ~= "/" then
  158.                     element = child
  159.                 end
  160.                 for name, value in string.gmatch(attributes, "(" .. namePattern .. ")%s*=%s*\"(.-)\"") do
  161.                     child.attribute[name] = fast and value or xmlUnescape(value)
  162.                 end
  163.             end
  164.             if text ~= "" then
  165.                 local child = {text = fast and text or xmlUnescape(text)}
  166.                 table.insert(element, child)
  167.                 parents[child] = element
  168.             end
  169.         end
  170.         return root[1]
  171.     end
  172.  
  173.     function generateXml(element, fast)
  174.         if element.name then
  175.             local xml = "<" .. element.name
  176.             for name, value in pairs(element.attribute) do
  177.                 xml = xml .. " " .. name .. "=\"" .. (fast and tostring(value) or xmlEscape(tostring(value))) .. "\""
  178.             end
  179.             if #element == 0 then
  180.                 xml = xml .. " />"
  181.             else
  182.                 xml = xml .. ">"
  183.                 for i, child in ipairs(element) do
  184.                     xml = xml .. generateXml(child, fast)
  185.                 end
  186.                 xml = xml .. "</" .. element.name .. ">"
  187.             end
  188.             return xml
  189.         elseif element.text then
  190.             return fast and tostring(element.text) or xmlEscape(tostring(element.text))
  191.         end
  192.     end
  193.  
  194.     function path(nodes, ...)
  195.         nodes = {nodes}
  196.         for i, name in ipairs(arg) do
  197.             local match = {}
  198.             for i, node in ipairs(nodes) do
  199.                 for i, child in ipairs(node) do
  200.                     if child.name == name then
  201.                         table.insert(match, child)
  202.                     end
  203.                 end
  204.             end
  205.             nodes = match
  206.         end
  207.         return nodes
  208.     end
  209.  
  210.     --(un)escape functions
  211.     local escapeCache = {}
  212.     function xmlEscape(s)
  213.         local r = escapeCache[s]
  214.         if not r then  
  215.             local g = string.gsub
  216.             r = g(s, "&", "&amp;")
  217.             r = g(r, "\"", "&quot;")
  218.             r = g(r, "'", "&apos;")
  219.             r = g(r, "<", "&lt;")
  220.             r = g(r, ">", "&gt;")
  221.             escapeCache[s] = r
  222.         end
  223.         return r
  224.     end
  225.     local unescapeCache = {}
  226.     function xmlUnescape(s)
  227.         local r = unescapeCache[s]
  228.         if not r then
  229.             local g = string.gsub
  230.             r = g(s, "&quot;", "\"")
  231.             r = g(r, "&apos;", "'")
  232.             r = g(r, "&lt;", "<")
  233.             r = g(r, "&gt;", ">")
  234.             r = g(r, "&#(%d%d?%d?%d?);", dec2char)
  235.             r = g(r, "&#x(%x%x?%x?%x?);", hex2char)
  236.             r = g(r, "&amp;", "&")
  237.             unescapeCache[s] = r
  238.         end
  239.         return r
  240.     end
  241.     function dec2char(code)
  242.         code = tonumber(code)
  243.         return string.char(code > 255 and 0 or code)
  244.     end
  245.     function hex2char(code)
  246.         code = tonumber(code, 16)
  247.         return string.char(code > 255 and 0 or code)
  248.     end
  249. end
  250.  
  251. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement