Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 2016 03 20 - Remove Grounds
- Remove any ground you want by clicking.
- Commands
- =========================================================================
- msg Send a public chat message as [Funcorp] in orange text
- kill Kill all mice except for you
- removegrounds Enable/disable removing grounds by clicking
- Controls
- =========================================================================
- Admin: Click on any ground to remove it, you'll have to click on rotated
- grounds near the center. Doesn't work in vanilla maps.
- ]]
- admins = {"Sebaisseba#0020"}
- text = {}
- text.en = {
- welcome = "<VP>Welcome to the FunCorp room!\n<J>Stats don't count here."
- }
- text.es = {
- welcome = "<VP>¡Bienvenido a la sala FunCorp!\n<J>Aquí no cuentan los stats."
- }
- commands = {"msg","kill","removegrounds"}
- adminMice = {}
- ground = {}
- ground_n = 0
- lang = text[tfm.get.room.community] or text.en
- function main()
- for _,c in pairs(commands) do
- system.disableChatCommandDisplay(c)
- end
- for n in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- end
- function table.contains(t,v)
- for p,i in pairs(t) do
- if i==v then
- return true
- end
- end
- return false
- end
- function newAdmin(name)
- adminMice[name] = {
- removeGrounds = true
- }
- system.bindMouse(name, true)
- end
- function eventNewPlayer(name)
- if table.contains(admins,name) then newAdmin(name) end
- tfm.exec.chatMessage(lang.welcome, name)
- end
- for k,v in pairs(tfm.get.room.playerList) do
- eventNewPlayer(k)
- end
- local ownXml, mapCode
- function eventNewGame()
- if ownXml then
- ui.setMapName("<font color='#ff8547'>FunCorp</font><BL> / @"..mapCode)
- ownXml = false
- else
- local xmlMapInfo = tfm.get.room.xmlMapInfo
- if not xmlMapInfo then print(ownXml) return end
- local oldCode = mapCode
- mapCode = xmlMapInfo.mapCode
- if mapCode == oldCode then tfm.exec.newGame() end
- xmldom = parseXml(xmlMapInfo.xml, true)
- ground = {}
- ground_n = 0
- for i,s in ipairs(path(xmldom, "Z", "S")[1]) do
- local ss = s.attribute
- local dx,dy = ss.L/2, ss.H/2
- ground_n = ground_n + 1
- ground[ground_n] = {
- x1 = ss.X - dx,
- x2 = ss.X + dx,
- y1 = ss.Y - dy,
- y2 = ss.Y + dy,
- id = i
- }
- ss.lua = i
- end
- ownXml = true
- tfm.exec.newGame(generateXml(xmldom, true))
- end
- end
- function eventMouse(name, mx, my)
- if not adminMice[name].removeGrounds then return end
- for i=1,ground_n do
- local g = ground[i]
- if mx>g.x1 and mx<g.x2 and my>g.y1 and my<g.y2 then
- tfm.exec.removePhysicObject(g.id)
- table.remove(ground, i)
- ground_n = ground_n - 1
- return
- end
- end
- end
- function eventChatCommand(name, mes)
- if table.contains(admins,name) then
- if mes:sub(1,3) == "msg" then
- tfm.exec.chatMessage("<font color='#ff8547'>[FunCorp] "..mes:sub(5).."</font>", nil)
- elseif mes == "removegrounds" then
- local state = adminMice[name].removeGrounds
- local t = state and "<R>Remove grounds disabled" or "<VP>Remove grounds enabled"
- adminMice[name].removeGrounds = not state
- tfm.exec.chatMessage(t, name)
- elseif mes == "kill" then
- for n in pairs(tfm.get.room.playerList) do
- if n ~= name then
- tfm.exec.killPlayer(n)
- end
- end
- end
- end
- end
- -- Makinit's xml library (full)
- do
- local namePattern = "[%a_:][%w%.%-_:]*"
- function parseXml(xml, fast)
- if not fast then
- xml = string.gsub(xml, "<!%[CDATA%[(.-)%]%]>", xmlEscape) -- replace CDATA with escaped text
- xml = string.gsub(xml, "<%?.-%?>", "") -- remove processing instructions
- xml = string.gsub(xml, "<!%-%-.-%-%->", "") -- remove comments
- xml = string.gsub(xml, "<!.->", "")
- end
- 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] = fast and value or xmlUnescape(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, fast)
- if element.name then
- local xml = "<" .. element.name
- for name, value in pairs(element.attribute) do
- xml = xml .. " " .. name .. "=\"" .. (fast and tostring(value) or xmlEscape(tostring(value))) .. "\""
- end
- if #element == 0 then
- xml = xml .. " />"
- else
- xml = xml .. ">"
- for i, child in ipairs(element) do
- xml = xml .. generateXml(child, fast)
- end
- xml = xml .. "</" .. element.name .. ">"
- end
- return xml
- elseif element.text then
- return fast and tostring(element.text) or xmlEscape(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
- --(un)escape functions
- local escapeCache = {}
- function xmlEscape(s)
- local r = escapeCache[s]
- if not r then
- local g = string.gsub
- r = g(s, "&", "&")
- r = g(r, "\"", """)
- r = g(r, "'", "'")
- r = g(r, "<", "<")
- r = g(r, ">", ">")
- escapeCache[s] = r
- end
- return r
- end
- local unescapeCache = {}
- function xmlUnescape(s)
- local r = unescapeCache[s]
- if not r then
- local g = string.gsub
- r = g(s, """, "\"")
- r = g(r, "'", "'")
- r = g(r, "<", "<")
- r = g(r, ">", ">")
- r = g(r, "&#(%d%d?%d?%d?);", dec2char)
- r = g(r, "&#x(%x%x?%x?%x?);", hex2char)
- r = g(r, "&", "&")
- unescapeCache[s] = r
- end
- return r
- end
- function dec2char(code)
- code = tonumber(code)
- return string.char(code > 255 and 0 or code)
- end
- function hex2char(code)
- code = tonumber(code, 16)
- return string.char(code > 255 and 0 or code)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement