Bolodefchoco_LUAXML

[Game] Hardcamp

Sep 16th, 2017
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 40.54 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 06/02/2017
  3. --Last update: 16/09/2017
  4.  
  5. --[[ Module ]]--
  6. local module = {
  7.     _VERSION = "1",
  8.     _NAME = "hardcamp",
  9.     _STATUS = "semi-official",
  10.     _AUTHOR = "Bolodefchoco",
  11.     _LICENSE = [[
  12.         MIT LICENSE
  13.        
  14.         Copyright (c) 2017 @Transformice + @Bolodefchoco
  15.        
  16.         Permission is hereby granted, free of charge, to any person obtaining
  17.         a copy of this software and associated documentation files (the
  18.         "Software"), to deal in the Software without restriction, including
  19.         without limitation the rights to use, copy, modify, merge, and to
  20.         permit persons to whom the Software is furnished to do so, subject to
  21.         the following conditions:
  22.  
  23.         The above copyright notice and this permission notice shall be included
  24.         in all copies or substantial portions of the Software.
  25.  
  26.         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  27.         OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR
  28.         A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  29.         IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  30.         CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  31.         TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  32.         SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33.     ]],
  34.     _FREEACCESS = { -- Verified players
  35.         -- 3 : Commands + Room admin + Debug
  36.         Bolodefchoco = 3,
  37.         Trumpuke = 3,
  38.         -- 2 : Commands
  39.         Bodykudo = 2,
  40.         Error_404 = 2,
  41.         Jordynl = 2,
  42.         Laagaadoo = 2,
  43.         Mescouleur = 2,
  44.         Sebafrancuz = 2,
  45.         Tocutoeltuco = 2,
  46.         -- 1 : Some commands
  47.         Abdeltif = 1,
  48.         Animjarcanin = 1,
  49.         Artinoe = 1,
  50.         Atinesta = 1,
  51.         Auroraclears = 1,
  52.         Bapereira = 1,
  53.         Barberserk = 1,
  54.         Bataatiinha = 1,
  55.         Bellaxo = 1,
  56.         Bibsho = 1,
  57.         Bielbateriax = 1,
  58.         Bjikata = 1,
  59.         Bruniinhoowx = 1,
  60.         Byontr = 1,
  61.         Caiolopelope = 1,
  62.         Chocodivo = 1,
  63.         Claumiau = 1,
  64.         Connow = 1,
  65.         Daelea = 1,
  66.         Distances = 1,
  67.         Drescen = 1,
  68.         Ekull = 1,
  69.         Exsilium = 1,
  70.         Flindix = 1,
  71.         Gemalugeter = 1,
  72.         Grastfetry = 1,
  73.         Grincreep = 1,
  74.         Ikkemon = 1,
  75.         Jotatavo = 1,
  76.         Kimsterjay = 1,
  77.         Kingtenso = 1,
  78.         Lebluemice = 1,
  79.         Lucasrslv = 1,
  80.         Mcqv = 1,
  81.         Miyakogotoku = 1,
  82.         Mousetat = 1,
  83.         Mquk = 1,
  84.         Myelou = 1,
  85.         Nedior = 1,
  86.         Nlff = 1,
  87.         Okpatinhos = 1,
  88.         Pjfsamora = 1,
  89.         Prysmos = 1,
  90.         Reshman = 1,
  91.         Rianmojang1 = 1,
  92.         Rosianna_rabbit = 1,
  93.         Ruamorangos = 1,
  94.         Sammynya = 1,
  95.         Squalleze = 1,
  96.         Tdft = 1,
  97.         Thegbc = 1,
  98.         Tockego = 1,
  99.         Treasuredsoul = 1,
  100.         Victorruanpk = 1,
  101.         Viniciusdara = 1,
  102.         Vinitexeira = 1,
  103.         Xfelrat = 1,
  104.         Xorcist = 1,
  105.         Yuir = 1,
  106.         Zacriker = 1,
  107.         Zippydoodah = 1,
  108.         Zagear = 1,
  109.         Zombiewd = 1,
  110.     },
  111. }
  112.  
  113. --[[ Optimization ]]--
  114.   --[[ String ]]--
  115. local stringlen,stringfind,stringgmatch,stringbyte,stringdump,stringreverse,stringupper,stringformat,stringrep,stringlower,stringsub,stringgsub,stringmatch,stringchar = string.len,string.find,string.gmatch,string.byte,string.dump,string.reverse,string.upper,string.format,string.rep,string.lower,string.sub,string.gsub,string.match,string.char
  116.   --[[ Math ]]--
  117. local mathdeg,mathfmod,mathrandom,mathasin,mathmax,mathmodf,mathfloor,mathcosh,mathldexp,mathatan2,mathpow,mathrandomseed,mathfrexp,mathabs,mathtanh,mathacos,mathlog,mathtan,mathmin,mathceil,mathsinh,mathsqrt,mathhuge,mathrad,mathsin,mathexp,mathcos,mathatan,mathpi = math.deg,math.fmod,math.random,math.asin,math.max,math.modf,math.floor,math.cosh,math.ldexp,math.atan2,math.pow,math.randomseed,math.frexp,math.abs,math.tanh,math.acos,math.log,math.tan,math.min,math.ceil,math.sinh,math.sqrt,math.huge,math.rad,math.sin,math.exp,math.cos,math.atan,math.pi
  118.   --[[ Table ]]--
  119. local tablepack,tableforeachi,tableforeach,tableremove,tableinsert,tableunpack,tableconcat,tablesort = table.pack,table.foreachi,table.foreach,table.remove,table.insert,table.unpack,table.concat,table.sort
  120.  
  121. --[[ API ]]--
  122.     --[[ Control ]]--
  123. system.newGameTimer = 0
  124. system.officialMode = {"",""}
  125. system.playerMessage = ""
  126. system.setAdmins = function()
  127.     local out = {}
  128.     for k,v in next,module._FREEACCESS do
  129.         if v > 2 then
  130.             out[k] = true
  131.         end
  132.     end
  133.     return out
  134. end
  135.     --[[ Improvements ]]--
  136. tableconcat = function(list,sep,f,i,j)
  137.     local txt = ""
  138.     sep = sep or ""
  139.     i,j = i or 1,j or #list
  140.     for k,v in next,list do
  141.         if type(k) ~= "number" and true or (k >= i and k <= j) then
  142.             txt = txt .. (f and f(k,v) or v) .. sep
  143.         end
  144.     end
  145.     return stringsub(txt,1,-1-#sep)
  146. end
  147. do
  148.     local newGame = tfm.exec.newGame
  149.     tfm.exec.newGame = function(code)
  150.         if os.time() > system.newGameTimer then
  151.             system.newGameTimer = os.time() + 6000
  152.             newGame(code or "#" .. tablerandom({0,0,0,0,1,1,1,4,5,6,7,8,9,1,4,5,6,7,8,9,0}))
  153.             return true
  154.         end
  155.         return false
  156.     end
  157.    
  158.     local addImage = tfm.exec.addImage
  159.     local removeImage = tfm.exec.removeImage
  160.     tfm.exec.addImage = function(...)
  161.         local id = addImage(...)
  162.         if id then
  163.             system.objects.image[id] = true
  164.         end
  165.         return id or -1
  166.     end
  167.     tfm.exec.removeImage = function(id)
  168.         removeImage(id)
  169.         if system.objects.image[id] then
  170.             system.objects.image[id] = nil
  171.         end
  172.     end
  173.    
  174.     local addTextArea = ui.addTextArea
  175.     ui.addTextArea = function(id,...)
  176.         addTextArea(id,...)
  177.         if not system.objects.textarea[id] then
  178.             system.objects.textarea[id] = true
  179.         end
  180.     end
  181.    
  182.     local chatMessage = tfm.exec.chatMessage
  183.     tfm.exec.chatMessage = function(txt,n)
  184.         txt = tostring(txt)
  185.         if #txt > 1000 then
  186.             local total = 0
  187.             while #txt > total do
  188.                 chatMessage(stringsub(txt,total,total + 1000),n)
  189.                 total = total + 1001
  190.             end
  191.         else
  192.             chatMessage(txt,n)
  193.         end
  194.     end
  195.    
  196.     local loadPlayerData = system.loadPlayerData
  197.     system.loadPlayerData = function(n)
  198.         if module._STATUS == "official" then
  199.             return loadPlayerData(n)
  200.         else
  201.             if _G["eventPlayerDataLoaded"] then
  202.                 eventPlayerDataLoaded(n,"")
  203.             end
  204.             return true
  205.         end
  206.     end
  207.    
  208.     local savePlayerData = system.savePlayerData
  209.     system.savePlayerData = function(n,data)
  210.         if module._STATUS == "official" then
  211.             savePlayerData(n,data)
  212.             return true
  213.         else
  214.             return false
  215.         end
  216.     end
  217. end
  218.     --[[ Room ]]--
  219. system.isRoom = stringbyte(tfm.get.room.name,2) ~= 3
  220. system.roomAdmins = system.setAdmins()
  221. system.miscAttrib = 0
  222. system.roomNumber,system.roomAttributes = (function()
  223.     if system.isRoom then
  224.         local number,attribute = stringmatch(tfm.get.room.name,"%*?#"..module._NAME.."(%d+)(.*)")
  225.         return tonumber(number) or 0,attribute or ""
  226.     else
  227.         return 0,""
  228.     end
  229. end)()
  230. system.roomLanguage = ""
  231.     --[[ Player ]]--
  232. system.isPlayer = function(n)
  233.     --[[
  234.         The player must not be a souris;
  235.         The player must have played Transformice for at least 5 days
  236.     ]]
  237.     return tfm.get.room.playerList[n] and stringsub(n,1,1) ~= "*" and tfm.get.room.playerList[n].registrationDate and (os.time() - (tfm.get.room.playerList[n].registrationDate or 0) >= 432e6) or false
  238. end
  239. system.players = function(alivePlayers)
  240.     local alive,total = 0,0
  241.     if alivePlayers then
  242.         alive = {}
  243.     end
  244.     for k,v in next,tfm.get.room.playerList do
  245.         if system.isPlayer(k) then
  246.             if not v.isDead and not v.isVampire then
  247.                 if alivePlayers then
  248.                     alive[#alive + 1] = k
  249.                 else
  250.                     alive = alive + 1
  251.                 end
  252.             end
  253.             total = total + 1
  254.         end
  255.     end
  256.     if alivePlayers then
  257.         return alive
  258.     else
  259.         return alive,total
  260.     end
  261. end
  262.     --[[ System ]]--
  263. events = {}
  264. currentTime,leftTime = 0,0
  265. system.loadTable = function(s)
  266.     -- "a.b.c.1" returns a[b][c][1]
  267.     local list
  268.     for tbl in stringgmatch(s,"[^%.]+") do
  269.         tbl = tonumber(tbl) and tonumber(tbl) or tbl
  270.         list = (list and list[tbl] or _G[tbl])
  271.     end
  272.     return list
  273. end
  274. system.getTranslation = function(index,n)
  275.     local t = stringformat("mode.%s.translations.%s.%s",system.gameMode,(n and mode[system.gameMode].info[n].langue or mode[system.gameMode].langue),index)
  276.     return system.loadTable(t) or system.loadTable(stringgsub(t,"translations%..-%.",function() return "translations.en." end))
  277. end
  278. system.looping = function(f,tick)
  279.     local s = 1000 / tick
  280.     local t = {}
  281.    
  282.     local fooTimer = function()
  283.         t[#t+1] = system.newTimer(f,1000,true)
  284.     end
  285.     for timer = 0,1000 - s,s do
  286.         system.newTimer(fooTimer,1000 + timer,false)
  287.     end
  288.     return t
  289. end
  290.     --[[ Interface ]]--
  291. ui.banner = function(image,aX,aY,n,time)
  292.     time = time or 5
  293.     axis = axis or {100,100}
  294.    
  295.     local img = tfm.exec.addImage(image .. ".png","&0",aX,aY,n)
  296.     system.newTimer(function()
  297.         tfm.exec.removeImage(img)
  298.     end,time * 1000,false)
  299. end
  300.     --[[ Math ]]--
  301. mathisNegative = function(x,iN,iP)
  302.     iN = iN == nil and x or iN
  303.     iP = iP == nil and x or iP
  304.     return (x<0 and iN or iP)
  305. end
  306. mathpercent = function(x,y,v)
  307.     v = (v or 100)
  308.     local m = x/y * v
  309.     return mathmin(m,v)
  310. end
  311. mathpythag = function(x1,y1,x2,y2,range)
  312.     return (x1-x2)^2 + (y1-y2)^2 <= (range^2)
  313. end
  314. mathsetLim = function(value,min,max)
  315.     return mathmax(min,mathmin(max,value))
  316. end
  317.     --[[ String ]]--
  318. stringsplit = function(value,pattern,f)
  319.     local out = {}
  320.     for v in stringgmatch(value,pattern) do
  321.         out[#out + 1] = (f and f(v) or v)
  322.     end
  323.     return out
  324. end
  325. stringnick = function(player)
  326.     return stringgsub(stringlower(player),"%a",stringupper,1)
  327. end
  328. stringtrim = function(s)
  329.     return (stringgsub(s,"^%s*(.-)%s*$","%1"))
  330. end
  331.     --[[ Table ]]--
  332. tablefind = function(list,value,index,f)
  333.     for k,v in next,list do
  334.         local i = (type(v) == "table" and index and v[index] or v)
  335.         if (f and f(i) or i) == value then
  336.             return true,k
  337.         end
  338.     end
  339.     return false,0
  340. end
  341. tableturnTable = function(x)
  342.     return (type(x)=="table" and x or {x})
  343. end
  344. tablerandom = function(t)
  345.     return (type(t) == "table" and t[mathrandom(#t)] or mathrandom())
  346. end
  347. tableshuffle = function(t)
  348.     local randomized = {}
  349.     for v = 1,#t do
  350.         tableinsert(randomized,mathrandom(#randomized),t[v])
  351.     end
  352.     return randomized
  353. end
  354. tablemerge = function(this,src)
  355.     for k,v in next,src do
  356.         if this[k] then
  357.             if type(v) == "table" then
  358.                 this[k] = tableturnTable(this[k])
  359.                 tablemerge(this[k],v)
  360.             else
  361.                 this[k] = this[k] or v
  362.             end
  363.         else
  364.             this[k] = v
  365.         end
  366.     end
  367. end
  368.     --[[ Others ]]--
  369. deactivateAccents=function(str)
  370.     local letters = {a = {"á","â","à","å","ã","ä"},e = {"é","ê","è","ë"},i = {"í","î","ì","ï"},o = {"ó","ô","ò","õ","ö"},u = {"ú","û","ù","ü"}}
  371.     for k,v in next,letters do
  372.         for i = 1,#v do
  373.             str = stringgsub(str,v[i],tostring(k))
  374.         end
  375.     end
  376.     return str
  377. end
  378. normalizeTime = function(time)
  379.     return mathfloor(time) + ((time - mathfloor(time)) >= .5 and .5 or 0)
  380. end
  381. disableChatCommand = function(command,...)
  382.     for k,v in next,{command,...} do
  383.         system.disableChatCommandDisplay(v,true)
  384.         system.disableChatCommandDisplay(stringlower(v),true)
  385.         system.disableChatCommandDisplay(stringupper(v),true)
  386.     end
  387. end
  388. normalizeTranslation = function()
  389.     local t = mode[system.gameMode].translations
  390.  
  391.     if mode[system.gameMode].langue == "" then
  392.         mode[system.gameMode].translations.pt = mode[system.gameMode].translations.br
  393.        
  394.         -- Sets the main language according to the community
  395.         local p = {system.roomLanguage,tfm.get.room.community}
  396.         for i = 1,#p do
  397.             if mode[system.gameMode].translations[p[i]] then
  398.                 mode[system.gameMode].langue = p[i]
  399.             end
  400.         end
  401.     end
  402.  
  403.     for k,v in next,t do
  404.         if k ~= "en" then
  405.             tablemerge(v,t.en)
  406.         end
  407.     end
  408. end
  409. normalizeNumber = function(number,sep)
  410.     sep = sep or " "
  411.     number = tostring(mathfloor(number))
  412.     number = stringgsub(number,"E(%d+)",function(cn) -- e5 = 00000
  413.         return stringrep("0",tonumber(cn))
  414.     end)
  415.     number = stringgsub(stringreverse(number),"(...)",function(c)
  416.         return c .. sep
  417.     end)
  418.     return stringreverse(number)
  419. end
  420. pairsByIndexes = function(list,f)
  421.     local out = {}
  422.     for index in next,list do
  423.         out[#out + 1] = index
  424.     end
  425.     tablesort(out,f)
  426.    
  427.     local i = 0
  428.     return function()
  429.         i = i + 1
  430.         if out[i] == nil then
  431.             return nil
  432.         else
  433.             return out[i],list[out[i]]
  434.         end
  435.     end
  436. end
  437.     --[[ XML ]]--
  438. xml = {}
  439. xml.parse = function(currentXml)
  440.     currentXml = stringmatch(currentXml,"<P (.-)/>") or ""
  441.     local out = {}
  442.     for tag,_,value in stringgmatch(currentXml,"([%-%w]+)=([\"'])(.-)%2") do
  443.         out[tag] = value
  444.     end
  445.     return out
  446. end
  447. xml.attribFunc = function(currentXml,funcs)
  448.     local attributes = xml.parse(currentXml)
  449.     for k,v in next,funcs do
  450.         if attributes[v.attribute] then
  451.             v.func(attributes[v.attribute])
  452.         end
  453.     end
  454. end
  455. xml.addAttrib = function(currentXml,out,launch)
  456.     local parameters = stringmatch(currentXml,"<P (.-)/>") or ""
  457.     for k,v in next,out do
  458.         if not stringfind(parameters,v.tag) then
  459.             currentXml = stringgsub(currentXml,"<P (.-)/>",function(attribs)
  460.                 return stringformat("<P %s=\"%s\" %s/>",v.tag,v.value,attribs)
  461.             end)
  462.         end
  463.     end
  464.     if launch then
  465.         tfm.exec.newGame(currentXml)
  466.     else
  467.         return currentXml
  468.     end
  469. end
  470. xml.getCoordinates = function(s)
  471.     if stringfind(s,";") then
  472.         local x,y
  473.         local axis,value = stringmatch(s,"(%a);(%d+)")
  474.         value = tonumber(value)
  475.         if value then
  476.             if axis == "x" then x = value else y = value end
  477.         end
  478.         return x or 0,y or 0
  479.     else
  480.         local pos = {}
  481.         for x,y in stringgmatch(s,"(%d+) ?, ?(%d+)") do
  482.             pos[#pos+1] = {x = x,y = y}
  483.         end
  484.         return pos
  485.     end
  486. end
  487.     --[[ Color ]]--
  488. color = {
  489.     hexToRgb = function(hex)
  490.         local h = stringformat("%06x",hex)
  491.         return tonumber("0x"..stringsub(h,1,2)),tonumber("0x"..stringsub(h,3,4)),tonumber("0x"..stringsub(h,5,6))
  492.     end,
  493.     rgbToHsl = function(r,g,b)
  494.         r,g,b = r/255,g/255,b/255
  495.  
  496.         local max,min = mathmax(r,g,b),mathmin(r,g,b)
  497.         local h,s,l
  498.  
  499.         h = (max + min) / 2
  500.         s,l = h,h
  501.  
  502.         if max == min then
  503.             h,s = 0,0
  504.         else
  505.             local d = max - min
  506.            
  507.             local s = l > .5 and (d/(2 - max - min)) or (d/(max + min))
  508.            
  509.             if max == r then
  510.                 h = (g-b)/d
  511.                 if g < b then
  512.                     h = h + 6
  513.                 end
  514.             elseif max == g then
  515.                 h = (b-r)/d + 2
  516.             elseif max == b then
  517.                 h = (r-g)/d + 4
  518.             end
  519.             h = h/6
  520.         end
  521.  
  522.         return {h=h,s=s,l=l}
  523.     end,
  524.     hslToRgb = function(h,s,l)
  525.         local r,g,b
  526.  
  527.         if s == 0 then
  528.             r,g,b = l,l,l
  529.         else
  530.             local hueToRgb = function(p,q,t)
  531.                 if t < 0 then
  532.                     t = t + 1
  533.                 end
  534.                 if t > 1 then
  535.                     t = t - 1
  536.                 end
  537.                 if t < 1/6 then
  538.                     return p + (q - p) * 6 * t
  539.                 end
  540.                 if t < 1/2 then
  541.                     return q
  542.                 end
  543.                 if t < 2/3 then
  544.                     return p + (q - p) * (2/3 - t) * 6
  545.                 end
  546.                 return p
  547.             end
  548.  
  549.             local q = l < .5 and (l * (1 + s)) or (l + s - l * s)
  550.             local p = 2 * l - q
  551.  
  552.             r = hueToRgb(p,q,h + 1/3)
  553.             g = hueToRgb(p,q,h)
  554.             b = hueToRgb(p,q,h - 1/3)
  555.         end
  556.  
  557.         return r * 255,g * 255,b * 255
  558.     end,
  559.     rgbToHex = function(r,g,b)
  560.         return tonumber(stringformat('%02x%02x%02x',r,g,b),16)
  561.     end,
  562.     YELLOW = 0xF9EC27,
  563.     RED = 0xF94226,
  564.     LIGHT_RED = 0xD1605D,
  565.     BLUE = 0x34A4E5,
  566.     DEEP_BLUE = 0x4F7F9A,
  567.     DARK_BLUE = 0x2D80AF,
  568.     GRAY = 0x969696,
  569.     SALMON = 0xAC6C64,
  570.     BROWN = 0x89635A,
  571.     BEIGE = 0x937A53,
  572.     TURQUOISE = 0x59D1C8,
  573.     ROSE = 0x816669,
  574.     MOSS_GREEN = 0x689636,
  575. }
  576.  
  577. --[[ GameMode ]]--
  578. system.submodes = {}
  579.  
  580. system.gameMode = module._NAME
  581. system.modeChanged = os.time() + 1000
  582.  
  583. system.getGameMode = function(value,notFirst)
  584.     local found,submode = tablefind(system.submodes,stringlower(value),nil,stringlower)
  585.     if found then
  586.         system.gameMode = system.submodes[submode]
  587.        
  588.         if notFirst then
  589.             eventModeChanged()
  590.         end
  591.        
  592.         system.modeChanged = os.time() + 1000
  593.     end
  594.     return found
  595. end
  596.  
  597. --[[ Modes ]]--
  598. mode = setmetatable({},{
  599.     __newindex = function(list,key,value)
  600.         rawset(list,key,setmetatable(value,{
  601.             __index = function(nList,nKey)
  602.                 if nKey == "langue" then
  603.                     return "en"
  604.                 end
  605.             end
  606.         }))
  607.         system.submodes[#system.submodes+1] = key
  608.     end
  609. })
  610.  
  611. --[[ Hardcamp ]]--
  612. mode.hardcamp = {
  613.     -- Translations
  614.     translations = {
  615.         en = {
  616.             -- Init
  617.             welcome = "Welcome to <B>#Hardcamp</B>! Type !info to check the commands\n\tReport any issue to Bolodefchoco!",
  618.            
  619.             -- Info
  620.             info = "Checkpoint:\n\tIf the checkpoint system is enabled, press <B>E</B> to put a checkpoint and <B>Shift+E</B> to remove it.\nAdmin\n\tIf you are a room admin, there are some commands that you can execute:\n\tMaps\n\t\t!next <V>--> Pass the map</V>\n\t\t!again <V>--> Resets the current map</V>\n\t\t!np @Code <VP>or</VP> !map @Code <V>--> Loads a map</V>\n\t\t!queue clear <V>--> Clear the map queue</V>\n\t\t!queue add @Code <V>--> Adds a map in the map queue</V>\n\t\t!queue P3 <VP>or</VP> P13 <VP>or</VP> P23 <V>--> Adds the whole official rotation of P3 or P13 or P23 in the map queue</V>\n\tTime\n\t\t!time TimeInMinutes <V>--> Set the time of the current round in TimeInMinutes</V>\n\t\t!standtime TimeInMinutes <V>--> Set the time of all the rounds in TimeInMinutes</V>\n\tOthers\n\t\t<B>Shift+Click</B> in a ground to read its properties\n\t\t!checkpoint [[not] cheese] <V>--> Enables/Disables the checkpoint system</V>\n\t\tKey Delete <V>--> Kills you</V>",
  621.             skip = "<VP>%s</VP> just skipped the map!",
  622.             restart = "<VP>%s</VP> just restarted the current map!",
  623.             loadmap = "<VP>%s</VP> just loaded the map %s!",
  624.             settime = "The time has been set to %s minutes!",
  625.             setstandtime = "The standard time of all the rounds has been set to %s minutes!",
  626.             enabled = "enabled! Press <B>E</B> to put a checkpoint and <B>Shift+E</B> to remove it.",
  627.             queuecleared = "%s just cleared the map queue",
  628.             queuemapadded = "%s just added the map %s to the map queue",
  629.             queueperm = "%s just added the category %s to the map queue",
  630.             queuereset = "%s just reseted the queue to the main maps",
  631.            
  632.             -- Simple words
  633.             disabled = "disabled!",
  634.         },
  635.         br = {
  636.             welcome = "Bem-vindo ao <B>#Hardcamp</B>! Digite !info para checar os comandos\n\tReporte quaisquer problemas para Bolodefchoco!",
  637.            
  638.             info = "Checkpoint:\n\tSe o sistema de checkpoint está ativado, pressione <B>E</B> para marcar um checkpoint e <B>Shift+E</B> para remove-lo.\nAdmin\n\tSe você é um administrador da sala, há alguns comandos que você pode executar:\n\tMapas\n\t\t!next <V>--> Passa o mapa</V>\n\t\t!again <V>--> Reinicia o mapa atual</V>\n\t\t!np @Código <VP>ou</VP> !map @Código <V>--> Carrega um mapa</V>\n\t\t!queue clear <V>--> Limpa a lista de mapas</V>\n\t\t!queue add @Código <V>--> Adiciona um mapa na lista de mapas</V>\n\t\t!queue P3 <VP>ou</VP> P13 <VP>ou</VP> P23 <V>--> Adiciona a rotação inteira de P3 ou P13 ou P23 na lista de mapas</V>\n\tTempo\n\t\t!time TempoEmMinutos <V>--> Define o tempo do mapa atual em TempoEmMinutos</V>\n\t\t!standtime TempoEmMinutos <V>--> Define o tempo de todas as partidas em TempoEmMinutos</V>\n\tOutros\n\t\t<B>Shift+Click</B> sobre um piso para ler suas propriedades\n\t\t!checkpoint [[not] cheese] <V>--> Ativa/Desativa o sistema de checkpoint</V>\n\t\tTecla Delete <V>--> Mata-o</V>",
  639.             skip = "<VP>%s</VP> acabou de passar o mapa!",
  640.             restart = "<VP>%s</VP> acabou de reiniciar o mapa atual!",
  641.             loadmap = "<VP>%s</VP> acabou de carregar o mapa %s!",
  642.             settime = "O tempo foi definido para %s minutos!",
  643.             setstandtime = "O tempo padrão para todas as partidas foram definidas para %s minutos!",
  644.             enabled = "ativado! Pressione <B>E</B> para marcar um checkpoint e <B>Shift+E</B> para remove-lo.",
  645.             queuecleared = "%s acabou de limpar a rotação de mapas",
  646.             queuemapadded = "%s acabou de adicionar o mapa %s na rotação de mapas",
  647.             queueperm = "%s acabou de adicionar a categoria %s na rotação de mapas",
  648.             queuereset = "%s acabou de resetar a rotação de mapas para os mapas principais",
  649.            
  650.             disabled = "desativado!",
  651.         },
  652.         pl = {
  653.             welcome = "Witaj w <B>#Hardcamp</B>! Wpisz !info na czacie aby sprawdzić jakie są komendy\n\tZgłaszaj wszelkie błędy do Bolodefchoco!",
  654.    
  655.             info = "Checkpoint:\n\tJeżeli system checkpointów jest włączony, kliknij <B>E</B>, aby ustawić checkpoint i <B>Shift+E</B>, aby go usunąć.\nAdmin\n\tJeżeli jesteś administratorem pokoju, jest kilka komend, które możesz użyć:\n\tMapy\n\t\t!next <V>--> Przełącza mapę</V>\n\t\t!again <V>--> Restartuje mapę</V>\n\t\t!np @Code <VP>albo</VP> !map @Code <V>--> Ładuje mapę</V>\n\t\t!queue clear <V>--> Czyści kolejkę map</V>\n\t\t!queue add @Code <V>--> Dodaję mapę do kolejki</V>\n\t\t!queue P3 <VP>albo</VP> P13 <VP>albo</VP> P23 <V>--> Dodaje wszystkie oficjalne rotacje z permów P3 albo P13 albo P23 do kolejki map</V>\n\tCzas\n\t\t!time CzasWMinutach <V>--> Ustawia czas obecnej mapy na CzasWMinutach</V>\n\t\t!standtime CzasWMinutach <V>--> Ustawia czas dla wszystkich rund na CzasWMinutach</V>\n\tInne\n\t\t<B>Shift+Click</B> na gruncie aby przeczytać jego właściwości\n\t\t!checkpoint [[not] cheese] <V>--> Włącza/Wyłącza system checkpointów</V>\n\t\tKey Delete <V>--> Kills you</V>",
  656.             skip = "<VP>%s</VP> pominął/-ęła mapę!",
  657.             restart = "<VP>%s</VP> zrestartował/-a mapę!",
  658.             loadmap = "<VP>%s</VP> załadował/-a mapę %s!",
  659.             settime = "Czas został ustawiony na %s minut!",
  660.             setstandtime = "Standardowy czas dla wszystkich map został ustawiony na %s minut!",
  661.             enabled = "włączony! Kliknij <B>E</B>, aby ustawić checkpoint i <B>Shift+E</B>, aby go usunąć.",
  662.             queuecleared = "%s just cleared the map queue",
  663.             queuemapadded = "%s just added the map %s to the map queue",
  664.             queueperm = "%s just added the category %s to the map queue",
  665.             queuereset = "%s just reseted the queue to the main maps",
  666.            
  667.             disabled = "wyłączony!",
  668.         },
  669.     },
  670.     langue = "",
  671.     --[[ Data ]]--
  672.     info = {},
  673.     --[[ Maps ]]--
  674.     maps = {},
  675.     map = function()
  676.         mode.hardcamp.maps = {6501305,6118143,2604997,2836937,6921682,3339586,5776126,5678468,6531399,5847160,5745650,7091808,7000003,6999993,4559999,4784241,3883780,4976520,4854044,6374076,3636206,6793803,4499335,4694197,5485847,6258690,3938895,1719709,4209243,6550335,3866650,3999455,4095418,4523127,1964971,1554670,4423047,764650,4883346,2978216,1947288,7025830,7108857,4766627,5888889,6782978,5699275,6422459,2634659,4808290,3620953,2973289,2604643,6591698,7134487,7054821,7159725,3737744,6933187,6864581,4701337,6631702,6761156,4212122,4160675,4623227,5191670,1132272,2781845,7167027,4834444,3734991,7037760,6502657,6469688,6092666,2749928,7175796,7142063,7167539,7173296,6995540,7151000,3931358,3374686,6324891,3704015,3937060,2429057,7192029,7192034,7192689,3883883,7192031,7192035,4559999,7189846,7192152,7227889,7194815,7192039,7192051,6911697,7106057,7196825,7205876,7228130,1533335,6931020,7066666}
  677.     end,
  678.     --[[ Settings ]]--
  679.     groundsData = {},
  680.     mapData = {},
  681.     standardTime = 6,
  682.     checkpoint = false,
  683.     respawnCheese = false,
  684.     --[[ Leaderboard ]]--
  685.     rank = function(players,fromValue,showPos,showPoints,pointsName,lim)
  686.         local p,rank = {},""
  687.         fromValue,lim = fromValue or {tfm.get.room.playerList,"score"},tonumber(lim) or 100
  688.         for n in next,players do
  689.             p[#p+1] = {name=n,v=fromValue[1][n][fromValue[2]]}
  690.         end
  691.         tablesort(p,function(f,s) return f.v>s.v end)
  692.         for o,n in next,p do
  693.             if o <= lim then
  694.                 rank = rank .. (showPos and "<J>"..o..". " or "") .. "<V>" .. n.name .. (showPoints and " <BL>- <VP>" .. n.v .. " "..(pointsName or "points") .."\n" or "\n")
  695.             end
  696.         end
  697.         return rank
  698.     end,
  699.     --[[ Init ]]--
  700.     reset = function()
  701.         -- Data
  702.         mode.hardcamp.info = {}
  703.     end,
  704.     init = function()
  705.         -- Settings
  706.         mode.hardcamp.respawnCheese = system.miscAttrib == 1
  707.        
  708.         -- Init
  709.         for _,f in next,{"AutoShaman","AutoScore","AutoTimeLeft","AutoNewGame","PhysicalConsumables","AfkDeath"} do
  710.             tfm.exec["disable"..f]()
  711.         end
  712.         tfm.exec.setAutoMapFlipMode(false)
  713.  
  714.         mode.hardcamp.map()
  715.         tfm.exec.newGame(tablerandom(mode.hardcamp.maps))
  716.        
  717.         -- Auto Admin
  718.         system.roomAdmins.Mquk = true
  719.     end,
  720.     --[[ Events ]]--
  721.     -- NewGame
  722.     eventNewGame = function()
  723.         tfm.exec.setGameTime(mode.hardcamp.standardTime * 60)
  724.         mode.hardcamp.groundsData = {}
  725.         mode.hardcamp.mapData = {}
  726.         for k,v in next,mode.hardcamp.info do
  727.             v.cheese = false
  728.             v.checkpoint = {false,0,0,false}
  729.             ui.removeTextArea(1,n)
  730.         end
  731.        
  732.         local xml = tfm.get.room.xmlMapInfo.xml
  733.         if xml then
  734.             local grounds = stringmatch(xml,"<S>(.-)</S>")
  735.             local properties = stringmatch(xml,"<C><P (.-)/>.*<Z>")
  736.             if properties then
  737.                 mode.hardcamp.mapData = {
  738.                     width = stringmatch(properties,'L="(%d+)"') or 800,
  739.                     heigth = stringmatch(properties,'H="(%d+)"') or 400,
  740.                 }
  741.             else
  742.                 mode.hardcamp.mapData = {
  743.                     width = 800,
  744.                     heigth = 400,
  745.                 }
  746.             end
  747.  
  748.             local data = {}
  749.             local foo = function(attributes)
  750.                 data[#data + 1] = attributes
  751.             end
  752.             stringgsub(grounds,"<S (.-)/>",foo)
  753.             for i = 1,#data do
  754.                 mode.hardcamp.groundsData[i] = {}
  755.                
  756.                 local type = stringmatch(data[i],'T="(%d+)"')
  757.                 mode.hardcamp.groundsData[i].type = type and tonumber(type) or -1
  758.  
  759.                 local x = stringmatch(data[i],'X="(%d+)"')
  760.                 mode.hardcamp.groundsData[i].x = x and tonumber(x) or 0
  761.  
  762.                 local y = stringmatch(data[i],'Y="(%d+)"')
  763.                 mode.hardcamp.groundsData[i].y = y and tonumber(y) or 0
  764.  
  765.                 local width = stringmatch(data[i],'L="(%d+)"')
  766.                 mode.hardcamp.groundsData[i].width = width and tonumber(width) or 0
  767.  
  768.                 local heigth = stringmatch(data[i],'H="(%d+)"')
  769.                 mode.hardcamp.groundsData[i].heigth = heigth and tonumber(heigth) or 0
  770.  
  771.                 local info = stringmatch(data[i],'P="(.*)"')
  772.                 info = stringsplit(info,"[^,]+")
  773.  
  774.                 mode.hardcamp.groundsData[i].friction = info[3] and tonumber(info[3]) or .3
  775.                 mode.hardcamp.groundsData[i].restitution = info[3] and tonumber(info[4]) or .2
  776.                 mode.hardcamp.groundsData[i].angle = info[3] and tonumber(info[5]) or 0
  777.             end
  778.         end
  779.     end,
  780.     -- NewPlayer
  781.     eventNewPlayer = function(n)
  782.         if not mode.hardcamp.info[n] then
  783.             mode.hardcamp.info[n] = {
  784.                 shift = false,
  785.                 checkpoint = {false,0,0,false},
  786.                 cheese = false,
  787.             }
  788.         end
  789.        
  790.         tfm.exec.respawnPlayer(n)
  791.        
  792.         system.bindMouse(n,true)
  793.         for i = 1,2 do
  794.             system.bindKeyboard(n,16,i==1,true)
  795.             system.bindKeyboard(n,stringbyte("K"),i==1,true)
  796.         end
  797.        
  798.         system.bindKeyboard(n,stringbyte("E"),true,true)
  799.         system.bindKeyboard(n,46,true,true) -- Delete key
  800.         tfm.exec.chatMessage("<T>" .. system.getTranslation("welcome") .. "\n\t<CEP>/w Mquk #bootcamp+ @mapCode",n)
  801.        
  802.         ui.banner("15d75ac6aa9",120,100,n)
  803.     end,
  804.     -- Mouse
  805.     eventMouse = function(n,x,y)
  806.         if mode.hardcamp.info[n].shift then
  807.             for i = #mode.hardcamp.groundsData,1,-1 do
  808.                 local g = mode.hardcamp.groundsData[i]
  809.                 local rad = mathrad(g.angle)
  810.                 local ax = {mathcos(rad),mathsin(rad)}
  811.  
  812.                 local gX = g.x + ax[1] * (x - g.x) - ax[2] * (y - g.y)
  813.                 local gY = g.y + ax[2] * (x - g.x) + ax[1] * (y - g.y)
  814.  
  815.                 if (g.type == 13 and mathpythag(x,y,g.x,g.y,g.width/2) or (mathabs(gX - g.x) < g.width/2 and mathabs(gY - g.y) < g.heigth/2)) then
  816.                     local properties = {"Type","ID","X","Y","Heigth","Width","Friction","Restitution","Angle"}
  817.                     local info = ""
  818.  
  819.                     for k,v in next,properties do
  820.                         info = info .. stringformat("<N>%s : <V>%s\n",v,(v == "ID" and i or v == "Type" and (({[0] = "Unknown","Wood","Ice","Trampoline","Lava","Chocolate","Earth","Grass","Sand","Cloud","Water","Stone","Snow","Rectangle","Circle","Spiderweb"})[g.type + 1]) or tostring(g[stringlower(v)])))
  821.                     end
  822.  
  823.                     local mapW = tonumber(mode.hardcamp.mapData.width)
  824.                     local mapH = tonumber(mode.hardcamp.mapData.heigth)
  825.                     ui.addTextArea(0,info,n,(x + 150 <= mapW and x) or (x < 0 and 0) or (mapW - 150),(y + 180 <= mapH and y > 20 and y) or (y < 20 and 25) or (mapH - 180),nil,nil,nil,nil,.8,false)
  826.                 end
  827.             end
  828.         else
  829.             ui.removeTextArea(0,n)
  830.         end
  831.     end,
  832.     -- Keyboard
  833.     eventKeyboard = function(n,k,d,x,y)
  834.         if k == 16 then
  835.             mode.hardcamp.info[n].shift = d
  836.         elseif k == stringbyte("E") and mode.hardcamp.checkpoint then
  837.             if mode.hardcamp.info[n].shift then
  838.                 mode.hardcamp.info[n].checkpoint = {false,0,0,mode.hardcamp.info[n].checkpoint[4]}
  839.                 ui.removeTextArea(1,n)
  840.             else
  841.                 mode.hardcamp.info[n].checkpoint = {true,x,y,true}
  842.                 ui.addTextArea(1,"",n,x-5,y-5,10,10,0x56A75A,0x56A75A,.5,true)
  843.             end
  844.         elseif k == stringbyte("K") then
  845.             if d then
  846.                 ui.addTextArea(2,mode.hardcamp.rank(tfm.get.room.playerList,{tfm.get.room.playerList,"score"},true,true,"points",20),n,5,30,nil,200,nil,nil,.8,true)
  847.             else
  848.                 ui.removeTextArea(2,n)
  849.             end
  850.         elseif k == 46 then
  851.             tfm.exec.killPlayer(n)
  852.         end
  853.     end,
  854.     -- ChatCommand
  855.     eventChatCommand = function(n,c)
  856.         local p = stringsplit(c,"[^%s]+",stringlower)
  857.         if p[1] == "info" then
  858.             tfm.exec.chatMessage("<T>" .. system.getTranslation("info"),n)
  859.         else
  860.             if system.roomAdmins[n] then
  861.                 if p[1] == "next" and os.time() > system.newGameTimer then
  862.                     tfm.exec.newGame(tablerandom(mode.hardcamp.maps))
  863.                     tfm.exec.chatMessage("<T>• " .. stringformat(system.getTranslation("skip"),n))
  864.                 elseif p[1] == "again" and os.time() > system.newGameTimer then
  865.                     tfm.exec.newGame(tfm.get.room.currentMap)
  866.                     tfm.exec.chatMessage("<T>• " .. stringformat(system.getTranslation("restart"),n))
  867.                 elseif (p[1] == "np" or p[1] == "map") and os.time() > system.newGameTimer then
  868.                     tfm.exec.newGame(p[2])
  869.                     tfm.exec.chatMessage("<T>• " .. stringformat(system.getTranslation("loadmap"),n,stringfind(p[2],"@") and p[2] or "@"..p[2]))
  870.                 elseif p[1] == "time" then
  871.                     tfm.exec.setGameTime(p[2] * 60)
  872.                     tfm.exec.chatMessage(stringformat(system.getTranslation("settime"),p[2]))
  873.                 elseif p[1] == "standtime" then
  874.                     p[2] = p[2] and tonumber(p[2]) or 6
  875.                     if p[2] > 0 and p[2] < 10 then
  876.                         mode.hardcamp.standardTime = p[2]
  877.                         tfm.exec.chatMessage(stringformat(system.getTranslation("setstandtime",p[2])))
  878.                     end
  879.                 elseif p[1] == "checkpoint" then
  880.                     local attribute = false
  881.                     if p[2] then
  882.                         attribute = true
  883.                         if p[2] == "not" and p[3] and p[3] == "cheese" then
  884.                             mode.hardcamp.respawnCheese = false
  885.                         elseif p[2] == "cheese" then
  886.                             mode.hardcamp.respawnCheese = true
  887.                         else
  888.                             attribute = false
  889.                         end
  890.                     end
  891.                    
  892.                     if not (mode.hardcamp.checkpoint and attribute) then
  893.                         mode.hardcamp.checkpoint = not mode.hardcamp.checkpoint
  894.                         tfm.exec.chatMessage("<T>Checkpoint " .. system.getTranslation(mode.hardcamp.checkpoint and "enabled" or "disabled"))
  895.                    
  896.                         if not mode.hardcamp.checkpoint then
  897.                             ui.removeTextArea(1,nil)
  898.                             for k,v in next,mode.hardcamp.info do
  899.                                 v.checkpoint = {false,0,0,v.checkpoint[4]}
  900.                             end
  901.                             if system.miscAttrib ~= 1 then
  902.                                 mode.hardcamp.respawnCheese = false
  903.                             end
  904.                             for k,v in next,mode.hardcamp.info do
  905.                                 v.cheese = false
  906.                             end
  907.                         end
  908.                     end
  909.                 elseif p[1] == "queue" then
  910.                     if p[2] == "clear" then
  911.                         mode.hardcamp.maps = {}
  912.                         tfm.exec.chatMessage("• " .. stringformat(system.getTranslation("queuecleared"),n))
  913.                     elseif p[2] == "add" then
  914.                         mode.hardcamp.maps[#mode.hardcamp.maps + 1] = p[3]
  915.                         tfm.exec.chatMessage("• " .. stringformat(system.getTranslation("queuemapadded"),n,stringfind(p[3],"@") and p[3] or "@"..p[3]))
  916.                     elseif p[2] and stringsub(p[2],1,1) == "p" then
  917.                         if p[2] == "p3" or p[2] == "p13" or p[2] == "p23" then
  918.                             mode.hardcamp.maps[#mode.hardcamp.maps + 1] = "#" .. stringsub(p[2],2)
  919.                             tfm.exec.chatMessage("• " .. stringformat(system.getTranslation("queueperm"),n,stringupper(p[2])))
  920.                         end
  921.                     else
  922.                         mode.hardcamp.map()
  923.                         tfm.exec.chatMessage("• " .. stringformat(system.getTranslation("queuereset"),n))
  924.                     end
  925.                 end
  926.             end
  927.         end
  928.     end,
  929.     -- Loop
  930.     eventLoop = function()
  931.         if _G.leftTime < 1 then
  932.             tfm.exec.newGame(tablerandom(mode.hardcamp.maps))
  933.         end
  934.     end,
  935.     -- PlayerDied
  936.     eventPlayerDied = function(n)
  937.         system.newTimer(function()
  938.             tfm.exec.respawnPlayer(n)
  939.            
  940.             if mode.hardcamp.checkpoint and mode.hardcamp.info[n].checkpoint[1] then
  941.                 tfm.exec.movePlayer(n,mode.hardcamp.info[n].checkpoint[2],mode.hardcamp.info[n].checkpoint[3])
  942.             end
  943.             if mode.hardcamp.checkpoint and mode.hardcamp.info[n].cheese and mode.hardcamp.respawnCheese then
  944.                 tfm.exec.giveCheese(n)
  945.             end
  946.         end,1500,false)
  947.     end,
  948.     -- PlayerWon
  949.     eventPlayerWon = function(n,t,time)
  950.         mode.hardcamp.info[n].cheese = false
  951.         mode.hardcamp.info[n].checkpoint = {false,0,0,mode.hardcamp.info[n].checkpoint[4]}
  952.         ui.removeTextArea(1,n)
  953.  
  954.         mode.hardcamp.eventPlayerDied(n)
  955.         tfm.exec.setPlayerScore(n,1,true)
  956.         tfm.exec.chatMessage(stringformat("<ROSE>%s (%ss <PT>(%scheckpoint)</PT>)",n,time/100,mode.hardcamp.info[n].checkpoint[4] and "" or "no "),n)
  957.     end,
  958.     -- PlayerGetCheese
  959.     eventPlayerGetCheese = function(n)
  960.         if mode.hardcamp.checkpoint and mode.hardcamp.respawnCheese then
  961.             mode.hardcamp.info[n].cheese = true
  962.         end
  963.     end,
  964. }
  965.  
  966. --[[ ModeChanged ]]--
  967. system.objects = {
  968.     image = {},
  969.     textarea = {}
  970. }
  971. eventModeChanged = function()
  972.     -- Remove content
  973.     for k in next,system.objects.image do
  974.         tfm.exec.removeImage(k)
  975.     end
  976.    
  977.     for k in next,system.objects.textarea do
  978.         ui.removeTextArea(k,nil)
  979.     end
  980.    
  981.     system.objects = {
  982.         image = {},
  983.         textarea = {}
  984.     }
  985.    
  986.     ui.addPopup(0,0,"",nil,-1500,-1500)
  987.    
  988.     -- Unbind keyboard and mouse, also normalize color name and scores
  989.     for k in next,tfm.get.room.playerList do
  990.         for i = 0,255 do
  991.             for v = 0,1 do
  992.                 system.bindKeyboard(k,i,v == 0,false)
  993.             end
  994.         end
  995.        
  996.         system.bindMouse(k,false)
  997.        
  998.         tfm.exec.setNameColor(k,-1)
  999.         tfm.exec.setPlayerScore(k,0)
  1000.     end
  1001.    
  1002.     -- Set admin back
  1003.     system.roomAdmins = system.setAdmins()
  1004.    
  1005.     -- Reset settings
  1006.     tfm.exec.snow(0)
  1007.     for k,v in next,{"AutoScore","WatchCommand","AutoNewGame","AutoShaman","AllShamanSkills","MortCommand","DebugCommand","MinimalistMode","AfkDeath","PhysicalConsumables","AutoTimeLeft"} do
  1008.         tfm.exec["disable" .. v](false)
  1009.     end
  1010.     tfm.exec.setAutoMapFlipMode()
  1011.    
  1012.     tfm.exec.setRoomMaxPlayers(25)
  1013.     tfm.exec.setRoomPassword("")   
  1014. end
  1015.  
  1016. --[[ Events ]]--
  1017.     --[[ eventLoop ]]--
  1018. events.eventLoop = function(currentTime,leftTime)
  1019.     _G.currentTime = normalizeTime(currentTime / 1e3)
  1020.     _G.leftTime = normalizeTime(leftTime / 1e3)
  1021. end
  1022.     --[[ eventNewPlayer ]]--
  1023. events.eventNewPlayer = function(n)
  1024.     tfm.exec.lowerSyncDelay(n)
  1025.    
  1026.     if system.officialMode[2] ~= "" then
  1027.         tfm.exec.chatMessage(system.officialMode[2],n)
  1028.     end
  1029.    
  1030.     if system.playerMessage ~= "" then
  1031.         tfm.exec.chatMessage("<J>" .. system.playerMessage,n)
  1032.     end
  1033. end
  1034.     --[[ eventChatCommand ]]--
  1035. events.eventChatCommand = function(n,c)
  1036.     if system.isPlayer(n) then
  1037.         system.disableChatCommandDisplay(c,true)
  1038.        
  1039.         local p = stringsplit(c,"[^%s]+",stringlower)
  1040.         disableChatCommand(p[1])
  1041.    
  1042.         if module._FREEACCESS[n] then
  1043.             if p[1] == "refresh" and (module._FREEACCESS[n] > 1 or not system.isRoom) then
  1044.                 eventModeChanged()
  1045.                 system.init(true)
  1046.                 return
  1047.             end
  1048.            
  1049.             if p[1] == "room" and (module._FREEACCESS[n] > 1 or not system.isRoom) then
  1050.                 local room = tonumber(p[2]) or 0
  1051.                 if _G["eventChatCommand"] and system.roomNumber ~= room then
  1052.                     system.roomNumber = room
  1053.                     eventChatCommand(n,"refresh")
  1054.                 end
  1055.                 return
  1056.             end
  1057.            
  1058.             if p[1] == "setmisc" and p[2] and (module._FREEACCESS[n] > 1 or not system.isRoom) then
  1059.                 system.miscAttrib = tonumber(p[2]) or 0
  1060.                 system.miscAttrib = mathsetLim(system.miscAttrib,0,99)
  1061.                 if p[3] == "true" then
  1062.                     eventChatCommand(n,"refresh")
  1063.                 end
  1064.                 return
  1065.             end
  1066.            
  1067.             if p[1] == "load" and (module._FREEACCESS[n] > 2 or not system.isRoom) then
  1068.                 if os.time() > system.modeChanged and os.time() > system.newGameTimer then
  1069.                     if system.getGameMode(p[2],true) then
  1070.                         system.init(system.isRoom)
  1071.                     end
  1072.                 end            
  1073.                 return
  1074.             end
  1075.         end
  1076.        
  1077.         if p[1] == "module" then
  1078.             p[2] = stringupper(p[2] or "")
  1079.            
  1080.             if module["_" .. p[2]] then
  1081.                 if p[2] == "FREEACCESS" then
  1082.                     if p[3] then
  1083.                         p[3] = stringnick(p[3])
  1084.                         tfm.exec.chatMessage(p[3] .. " ~> " .. (module._FREEACCESS[p[3]] or 0),n)
  1085.                     else
  1086.                         tfm.exec.chatMessage(p[2] .. " : ",n)
  1087.                         for k,v in pairsByIndexes(module._FREEACCESS,function(a,b) return module._FREEACCESS[a] > module._FREEACCESS[b] end) do
  1088.                             tfm.exec.chatMessage(stringformat("%s ~> %s",k,v),n)
  1089.                         end
  1090.                     end
  1091.                 else
  1092.                     tfm.exec.chatMessage(p[2] .. " : " .. tableconcat(tableturnTable(module["_" .. p[2]]),"\n",function(k,v)
  1093.                         return v
  1094.                     end),n)
  1095.                 end
  1096.             else
  1097.                 tfm.exec.chatMessage(stringformat("VERSION : %s\nNAME : %s\nSTATUS : %s\nAUTHOR : %s\n\nMODE : %s",module._VERSION,module._NAME,module._STATUS,module._AUTHOR,system.gameMode),n)
  1098.             end
  1099.             return
  1100.         end
  1101.        
  1102.         if p[1] == "modes" then
  1103.             tfm.exec.chatMessage(tableconcat({tableunpack(system.submodes,2)},"\n",function(k,v)
  1104.                 return stringformat("~> /room #%s%s@%s#%s",module._NAME,mathrandom(0,999),n,v)
  1105.             end),n)
  1106.             return
  1107.         end
  1108.  
  1109.         if p[1] == "stop" and system.roomAdmins[n] then
  1110.             system.exit()
  1111.         end
  1112.        
  1113.         if p[1] == "admin" then
  1114.             tfm.exec.chatMessage(tableconcat(system.roomAdmins,", ",tostring),n)
  1115.             return
  1116.         end
  1117.        
  1118.         if p[1] == "adm" and p[2] and (system.roomAdmins[n] or (module._FREEACCESS[n] and module._FREEACCESS[n] > 2)) then
  1119.             if tablefind({"true","false"},p[3]) then
  1120.                 local pl = stringnick(p[2])
  1121.                 system.roomAdmins[pl] = (module._FREEACCESS[pl] and true) or p[3] == "true" or nil
  1122.             end
  1123.             return
  1124.         end
  1125.        
  1126.         if p[1] == "setroomlanguage" and p[2] and (system.roomAdmins[n] or (module._FREEACCESS[n] and module._FREEACCESS[n] > 2)) then
  1127.             if mode[system.gameMode].translations[p[2]] then
  1128.                 system.roomLanguage = p[2]
  1129.                 mode[system.gameMode].langue = system.roomLanguage
  1130.             end
  1131.             return
  1132.         end
  1133.        
  1134.         if p[1] == "me" then
  1135.             local commands = {
  1136.                 [0] = {},
  1137.                 [1] = {"!refresh (tribe house)","!setMisc [number] [refresh] (tribe house)","!room [number] (tribe house)","!load [mode] (tribe house)"},
  1138.                 [2] = {"!refresh","!setMisc [number] [refresh]","!room [number]","!load [mode] (tribe house)"},
  1139.                 [3] = {"!refresh","!setMisc [number] [refresh]","!room [number]","!load [mode]"}
  1140.             }
  1141.            
  1142.             local access = module._FREEACCESS[n] or 0
  1143.            
  1144.             if system.roomAdmins[n] then
  1145.                 for k,v in next,{"!stop","!adm [playerName] [true/false]","!setRoomLanguage [language]"} do
  1146.                     commands[access][#commands[access] + 1] = v
  1147.                 end
  1148.             end
  1149.            
  1150.             tfm.exec.chatMessage(stringformat("@%s\nACCESS : %s\nROOM ADMIN : %s\n\n~> Commands: %s",n,access,tostring(not not system.roomAdmins[n]),tableconcat(commands[access],"; ")),n)
  1151.             return
  1152.         end
  1153.     end
  1154. end
  1155.  
  1156. --[[ RoomSettings ]]--
  1157. system.roomSettings = {
  1158.     -- 0 = Only the first value
  1159.     -- 1 = All the text
  1160.     ["@"] = {0,function(n)
  1161.         if n and #n > 2 then
  1162.             system.roomAdmins[stringnick(n)] = true
  1163.         end
  1164.     end},
  1165.     ["*"] = {0,function(id)
  1166.         system.miscAttrib = tonumber(id) or 1
  1167.         system.miscAttrib = mathsetLim(system.miscAttrib,1,99)
  1168.     end},
  1169.     ["#"] = {0,function(name)
  1170.         if name then
  1171.             local game = system.getGameMode(name)
  1172.             if not game then
  1173.                 system.gameMode = module._NAME
  1174.             end
  1175.         end
  1176.     end},
  1177.     [":"] = {1,function(text)
  1178.         if text and #text > 0 then
  1179.             system.playerMessage = stringsub(text,1,40)
  1180.         end
  1181.     end},
  1182.     ["!"] = {0,function(langue)
  1183.         if langue and #langue > 0 then
  1184.             system.roomLanguage = stringlower(langue)
  1185.         end
  1186.     end}
  1187. }
  1188. system.setRoom = function()
  1189.     if system.isRoom and system.roomAttributes then
  1190.         local chars = ""
  1191.         for k in next,system.roomSettings do
  1192.             chars = chars .. k
  1193.         end
  1194.  
  1195.         for char,value in stringgmatch(system.roomAttributes,"(["..chars.."])([^"..chars.."]+)") do
  1196.             for k,v in next,system.roomSettings do
  1197.                 if k == char then
  1198.                     v[2](v[1] == 0 and stringmatch(value,"[^%s]+") or value)
  1199.                     break
  1200.                 end
  1201.             end
  1202.         end
  1203.        
  1204.         local officialModes = {
  1205.             {"vanilla","<VP>Enjoy your vanilla (: .. okno"},
  1206.             {"survivor","<R>Aw, you cannot play survivor on #grounds"},
  1207.             {"racing","<CH>Uh, racing? Good luck!"},
  1208.             {"music","<BV>Music? Nice choice! Why don't you try a rock'n'roll?"},
  1209.             {"bootcamp","<PT>Bootcamp? Ok. This is unfair and your data won't be saved out of the room."},
  1210.             {"defilante","<R>Aw, you cannot play defilante on #grounds"},
  1211.             {"village","<R>You cannot play village on #grounds. Please, change your room."},
  1212.         }
  1213.         for k,v in next,officialModes do
  1214.             if stringfind(stringlower(system.roomAttributes),v[1]) then
  1215.                 system.officialMode = {v[1],v[2]}
  1216.                 break
  1217.             end
  1218.         end
  1219.     end
  1220. end
  1221.  
  1222. --[[ Initialize ]]--
  1223. execute = {}
  1224. system.setRoom()
  1225.  
  1226. system.init = function(refresh)
  1227.     for i,event in next,{"Loop","NewGame","PlayerDied","PlayerGetCheese","PlayerVampire","PlayerWon","PlayerLeft","EmotePlayed","Keyboard","Mouse","PopupAnswer","TextAreaCallback","ChatCommand","ChatMessage","SummoningStart","SummoningEnd","SummoningCancel","NewPlayer","PlayerRespawn","ColorPicked"} do
  1228.         local e = "event" .. event
  1229.        
  1230.         local found = false
  1231.         for k,v in next,mode[system.gameMode] do
  1232.             if k == e then
  1233.                 execute[e] = v
  1234.                 found = true
  1235.                 break
  1236.             end
  1237.         end
  1238.         if not found then
  1239.             execute[e] = function() end
  1240.         end
  1241.  
  1242.         _G[e] = function(...)
  1243.             if events[e] then
  1244.                 events[e](...)
  1245.             end
  1246.             execute[e](...)
  1247.         end
  1248.     end
  1249.  
  1250.     if refresh then
  1251.         if mode[system.gameMode].reset then
  1252.             mode[system.gameMode].reset()
  1253.         end
  1254.     end
  1255.    
  1256.     normalizeTranslation()
  1257.     mode[system.gameMode].init()
  1258.  
  1259.     if _G["eventNewPlayer"] then
  1260.         tableforeach(tfm.get.room.playerList,eventNewPlayer)
  1261.     end
  1262. end
  1263. system.init()
Add Comment
Please, Sign In to add comment