Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.55 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 06/02/2017
  3. --Last update: 26/07/2017
  4.  
  5. --[[ Module ]]--
  6. local module = {
  7.     _VERSION = "3.8",
  8.     _NAME = "grounds",
  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.         -- 2 : Commands
  38.         Bodykudo = 2,
  39.         Error_404 = 2,
  40.         Jordynl = 2,
  41.         Laagaadoo = 2,
  42.         Sebafrancuz = 2,
  43.         Tocutoeltuco = 2,
  44.         -- 1 : Some commands
  45.         Artinoe = 1,
  46.         Bapereira = 1,
  47.         Barberserk = 1,
  48.         Byontr = 1,
  49.         Claumiau = 1,
  50.         Drescen = 1,
  51.         Ekull = 1,
  52.         Elvismouse = 1,
  53.         Grastfetry = 1,
  54.         Kimsterjay = 1,
  55.         Mcqv = 1,
  56.         Mescouleur = 1,
  57.         Mquk = 1,
  58.         Reshman = 1,
  59.         Rikkeshang = 1,
  60.         Ruamorangos = 1,
  61.         Sammynya = 1,
  62.     },
  63. }
  64.  
  65. --[[ Optimization ]]--
  66.   --[[ String ]]--
  67. 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
  68.   --[[ Math ]]--
  69. 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
  70.   --[[ Table ]]--
  71. 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
  72.  
  73. --[[ API ]]--
  74.     -- Timers
  75. system.newGameTimer = 0
  76.  
  77.     -- Control
  78. system.officialMode = {"",""}
  79. system.setAdmins = function()
  80.     local out = {}
  81.     for k,v in next,module._FREEACCESS do
  82.         if v > 2 then
  83.             out[k] = true
  84.         end
  85.     end
  86.     return out
  87. end
  88.  
  89.     -- Improvements
  90. tableconcat = function(list,sep,f,i,j)
  91.     local txt = ""
  92.     sep = sep or ""
  93.     i,j = i or 1,j or #list
  94.     for k,v in next,list do
  95.         if type(k) ~= "number" and true or (k >= i and k <= j) then
  96.             txt = txt .. (f and f(k,v) or v) .. sep
  97.         end
  98.     end
  99.     return stringsub(txt,1,-1-#sep)
  100. end
  101. do
  102.     local newGame = tfm.exec.newGame
  103.     tfm.exec.newGame = function(code)
  104.         if os.time() > system.newGameTimer then
  105.             system.newGameTimer = os.time() + 6000
  106.             newGame(code)
  107.             return true
  108.         end
  109.         return false
  110.     end
  111.    
  112.     local addImage = tfm.exec.addImage
  113.     local removeImage = tfm.exec.removeImage
  114.     tfm.exec.addImage = function(...)
  115.         local id = addImage(...)
  116.         if id then
  117.             system.objects.image[id] = true
  118.         end
  119.         return id
  120.     end
  121.     tfm.exec.removeImage = function(id)
  122.         removeImage(id)
  123.         if system.objects.image[id] then
  124.             system.objects.image[id] = nil
  125.         end
  126.     end
  127.    
  128.     local addTextArea = ui.addTextArea
  129.     ui.addTextArea = function(id,...)
  130.         addTextArea(id,...)
  131.         if not system.objects.textarea[id] then
  132.             system.objects.textarea[id] = true
  133.         end
  134.     end
  135.    
  136.     local chatMessage = tfm.exec.chatMessage
  137.     tfm.exec.chatMessage = function(txt,n)
  138.         if #txt > 1000 then
  139.             local total = 0
  140.             while #txt > total do
  141.                 chatMessage(stringsub(txt,total,total + 1000),n)
  142.                 total = total + 1001
  143.             end
  144.         else
  145.             chatMessage(txt,n)
  146.         end
  147.     end
  148.    
  149.     local loadPlayerData = system.loadPlayerData
  150.     system.loadPlayerData = function(n)
  151.         if module._STATUS == "official" then
  152.             return loadPlayerData(n)
  153.         else
  154.             if _G["eventPlayerDataLoaded"] then
  155.                 eventPlayerDataLoaded(n,"")
  156.             end
  157.             return true
  158.         end
  159.     end
  160.    
  161.     local savePlayerData = system.savePlayerData
  162.     system.savePlayerData = function(n,data)
  163.         if module._STATUS == "official" then
  164.             savePlayerData(n,data)
  165.             return true
  166.         else
  167.             return false
  168.         end
  169.     end
  170. end
  171.  
  172.     -- Room
  173. system.isRoom = stringbyte(tfm.get.room.name,2) ~= 3
  174. system.roomAdmins = system.setAdmins()
  175. system.miscAttrib = 0
  176. system.roomNumber,system.roomAttributes = (function()
  177.     if system.isRoom then
  178.         local number,attribute = stringmatch(tfm.get.room.name,"%*?#"..module._NAME.."(%d+)(.*)")
  179.         return tonumber(number) or "",attribute or ""
  180.     else
  181.         return "",""
  182.     end
  183. end)()
  184.  
  185.     -- Player
  186. system.isPlayer = function(n)
  187.     --[[
  188.         The player must not be a souris;
  189.         The player must have played Transformice for at least 5 days
  190.     ]]
  191.     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
  192. end
  193. system.players = function(alivePlayers)
  194.     local alive,total = 0,0
  195.     if alivePlayers then
  196.         alive = {}
  197.     end
  198.     for k,v in next,tfm.get.room.playerList do
  199.         if system.isPlayer(k) then
  200.             if not v.isDead and not v.isVampire then
  201.                 if alivePlayers then
  202.                     alive[#alive + 1] = k
  203.                 else
  204.                     alive = alive + 1
  205.                 end
  206.             end
  207.             total = total + 1
  208.         end
  209.     end
  210.     if alivePlayers then
  211.         return alive
  212.     else
  213.         return alive,total
  214.     end
  215. end
  216.  
  217.     -- System
  218. currentTime,leftTime = 0,0
  219. system.loadTable = function(s)
  220.     -- "a.b.c.1" returns a[b][c][1]
  221.     local list
  222.     for tbl in stringgmatch(s,"[^%.]+") do
  223.         tbl = tonumber(tbl) and tonumber(tbl) or tbl
  224.         list = (list and list[tbl] or _G[tbl])
  225.     end
  226.     return list
  227. end
  228. system.getTranslation = function(index,n)
  229.     local t = stringformat("mode.%s.translations.%s.%s",system.gameMode,(n and mode[system.gameMode].info[n].langue or mode[system.gameMode].langue),index)
  230.     return system.loadTable(t) or system.loadTable(stringgsub(t,"translations%..-%.",function() return "translations.en." end))
  231. end
  232. system.looping = function(f,tick)
  233.     local s = 1000 / tick
  234.     local t = {}
  235.    
  236.     local fooTimer = function()
  237.         t[#t+1] = system.newTimer(f,1000,true)
  238.     end
  239.     for timer = 0,1000 - s,s do
  240.         system.newTimer(fooTimer,1000 + timer,false)
  241.     end
  242.     return t
  243. end
  244.  
  245.     -- Interface
  246. ui.banner = function(image,aX,aY,n,time)
  247.     time = time or 5
  248.     axis = axis or {100,100}
  249.    
  250.     local img = tfm.exec.addImage(image .. ".png","&0",aX,aY,n)
  251.     system.newTimer(function()
  252.         tfm.exec.removeImage(img)
  253.     end,time * 1000,false)
  254. end
  255.  
  256.     -- Math
  257. mathisNegative = function(x,iN,iP)
  258.     return (x<0 and (iN or x) or (iP or x))
  259. end
  260. mathpercent = function(x,y,v)
  261.     v = (v or 100)
  262.     local m = x/y * v
  263.     return mathmin(m,v)
  264. end
  265. mathpythag = function(x1,y1,x2,y2,range)
  266.     return (x1-x2)^2 + (y1-y2)^2 <= (range^2)
  267. end
  268. mathsetLim = function(value,min,max)
  269.     return mathmax(min,mathmin(max,value))
  270. end
  271.  
  272.     -- String
  273. stringsplit = function(value,pattern,f)
  274.     local out = {}
  275.     for v in stringgmatch(value,pattern) do
  276.         out[#out + 1] = (f and f(v) or v)
  277.     end
  278.     return out
  279. end
  280. stringnick = function(player)
  281.     return stringgsub(stringlower(player),"%a",stringupper,1)
  282. end
  283.  
  284.     -- Table
  285. tablefind = function(list,value,index,f)
  286.     for k,v in next,list do
  287.         local i = (type(v) == "table" and index and v[index] or v)
  288.         if (f and f(i) or i) == value then
  289.             return true,k
  290.         end
  291.     end
  292.     return false,0
  293. end
  294. tableturnTable = function(x)
  295.     return (type(x)=="table" and x or {x})
  296. end
  297. tablerandom = function(t)
  298.     return (type(t) == "table" and t[mathrandom(#t)] or mathrandom())
  299. end
  300. tableshuffle = function(t)
  301.     local randomized = {}
  302.     for v = 1,#t do
  303.         tableinsert(randomized,mathrandom(#randomized),t[v])
  304.     end
  305.     return randomized
  306. end
  307.  
  308.     -- Others
  309. deactivateAccents=function(str)
  310.     local letters = {a = {"á","â","à","å","ã","ä"},e = {"é","ê","è","ë"},i = {"í","î","ì","ï"},o = {"ó","ô","ò","õ","ö"},u = {"ú","û","ù","ü"}}
  311.     for k,v in next,letters do
  312.         for i = 1,#v do
  313.             str = stringgsub(str,v[i],tostring(k))
  314.         end
  315.     end
  316.     return str
  317. end
  318. normalizeTime = function(time)
  319.     return mathfloor(time) + ((time - mathfloor(time)) >= .5 and .5 or 0)
  320. end
  321. disableChatCommand = function(command)
  322.     system.disableChatCommandDisplay(command,true)
  323.     system.disableChatCommandDisplay(stringlower(command),true)
  324.     system.disableChatCommandDisplay(stringupper(command),true)
  325. end
  326. normalizeTranslation = function()
  327.     local t = mode[system.gameMode].translations
  328.  
  329.     for k,v in next,t.en do
  330.         for i,j in next,t do
  331.             if i ~= "en" then
  332.                 if not j[k] then
  333.                     j[k] = v
  334.                 end
  335.             end
  336.         end
  337.     end
  338. end
  339.  
  340.     -- XML Dealer
  341. xml = {}
  342. xml.parse = function(currentXml)
  343.     currentXml = stringmatch(currentXml,"<P (.-)/>") or ""
  344.     local out = {}
  345.     for tag,_,value in stringgmatch(currentXml,"([%-%w]+)=([\"'])(.-)%2") do
  346.         out[tag] = value
  347.     end
  348.     return out
  349. end
  350. xml.attribFunc = function(currentXml,funcs)
  351.     local attributes = xml.parse(currentXml)
  352.     for k,v in next,funcs do
  353.         if attributes[v.attribute] then
  354.             v.func(attributes[v.attribute])
  355.         end
  356.     end
  357. end
  358. xml.addAttrib = function(currentXml,out,launch)
  359.     local parameters = stringmatch(currentXml,"<P (.-)/>") or ""
  360.     for k,v in next,out do
  361.         if not stringfind(parameters,v.tag) then
  362.             currentXml = stringgsub(currentXml,"<P (.-)/>",function(attribs)
  363.                 return stringformat("<P %s=\"%s\" %s/>",v.tag,v.value,attribs)
  364.             end)
  365.         end
  366.     end
  367.     if launch then
  368.         tfm.exec.newGame(currentXml)
  369.     else
  370.         return currentXml
  371.     end
  372. end
  373. xml.getCoordinates = function(s)
  374.     if stringfind(s,";") then
  375.         local x,y
  376.         local axis,value = stringmatch(s,"(%a);(%d+)")
  377.         value = tonumber(value)
  378.         if value then
  379.             if axis == "x" then x = value else y = value end
  380.         end
  381.         return x or 0,y or 0
  382.     else
  383.         local pos = {}
  384.         for x,y in stringgmatch(s,"(%d+) ?, ?(%d+)") do
  385.             pos[#pos+1] = {x = x,y = y}
  386.         end
  387.         return pos
  388.     end
  389. end
  390.  
  391. --[[ GameMode ]]--
  392. system.submodes = {}
  393.  
  394. system.gameMode = module._NAME
  395. system.modeChanged = os.time() + 10e3
  396.  
  397. system.getGameMode = function(value,notFirst)
  398.     local found,submode = tablefind(system.submodes,stringlower(value),nil,stringlower)
  399.     if found then
  400.         system.gameMode = system.submodes[submode]
  401.        
  402.         if notFirst then
  403.             eventModeChanged()
  404.         end
  405.        
  406.         system.modeChanged = os.time() + 10e3
  407.     end
  408.     return found
  409. end
  410.  
  411. --[[ Modes ]]--
  412. mode = setmetatable({},{
  413.     __newindex = function(list,key,value)
  414.         rawset(list,key,value)
  415.         system.submodes[#system.submodes+1] = key
  416.     end
  417. })
  418.  
  419. --[[ Sharpie ]]--
  420. mode.sharpie = {
  421.     -- Translations
  422.     translations = {
  423.         en = {
  424.             -- Init
  425.             welcome = "Welcome to #sharpie! Fly pressing space.",
  426.  
  427.             -- Warning
  428.             nothacker = "The mice flying are NOT hackers!",
  429.  
  430.             -- Sample words
  431.             won = "won",
  432.            
  433.             -- Messages
  434.             first = {
  435.                 "yay 2 in a row",
  436.                 "super pro",
  437.                 "oml are you playing alone or what",
  438.                 "wooow 4 in a row!",
  439.                 "getting hard? good luck pro!",
  440.                 "you noob just unlocked the title lightning",
  441.                 "woah speedmaster",
  442.                 "formula 1",
  443.                 "time traveler you sir",
  444.                 "queen of the win",
  445.                 "as pro as the developer",
  446.                 "ILLUMINATI!",
  447.                 "are you a real hacker?",
  448.                 "I hope you dont loose the chance of seeing the last message",
  449.                 "THIS IS A SHIT MESSAGE BECAUSE YOU DIDNT DESERVE IT",
  450.             },
  451.             hardMode = "The hard mode is activated this round!",
  452.         },
  453.         br = {
  454.             welcome = "Bem-vindo ao #sharpie! Voe apertando espaço.",
  455.  
  456.             nothacker = "Os ratos voando NÃO são hackers!",
  457.  
  458.             won = "venceu",
  459.  
  460.             first = {
  461.                 "yay 2 seguidas",
  462.                 "super pro",
  463.                 "omg você tá jogando sozinho ou o que",
  464.                 "etaaa 4 seguidas!",
  465.                 "ficando difícil? boa sorte mito!",
  466.                 "vc noob acaba de desbloquear o título relâmpago",
  467.                 "vuash mestre da corrida",
  468.                 "relâmpago marquinhos",
  469.                 "viajante do tempo vc senhor",
  470.                 "rainha da vitória",
  471.                 "tão pro quanto o criador do jogo",
  472.                 "ILLUMINATI!",
  473.                 "éres um hacker de verdade?",
  474.                 "Espero que você não perca a chance de ler a última mensagem",
  475.                 "ESSA É UMA MENSAGEM DE MERDA PQ VC N MERECEU ISSO",
  476.             },
  477.             hardMode = "O modo difícil está ativado nessa partida!",
  478.         },
  479.     },
  480.     langue = "en",
  481.     --[[ Settings ]]--
  482.     flyPower = -50,
  483.     firstRow = {"",0}, -- Player, amount
  484.     podium = 0,
  485.     totalPlayers = 0,
  486.     hardmode = false,
  487.     modeImages = {"15cbdb3c427","15cbdb479ca","15cbdb4a1ca","15cbdb4cae5"},
  488.     mapInfo = {800,400},
  489.     --[[ UI ]]--
  490.     uiborder = function(t,x,y)
  491.         local colors = {
  492.             {"#F7F918","#EC4848"},
  493.             {"#4CE7F7","#2C9F5B"},
  494.             {"#4BD9CD","#2A64E9"},
  495.             {"#D4F31A","#8C8fA4"},
  496.         }
  497.         local color = tablerandom(colors)
  498.  
  499.         ui.addTextArea(0,"<font color='" .. color[2] .. "'><B>"..t,nil,x,y-1,900,25,1,1,0,true)
  500.         ui.addTextArea(1,"<font color='" .. color[2] .. "'><B>"..t,nil,x,y+1,900,25,1,1,0,true)
  501.         ui.addTextArea(2,"<font color='" .. color[2] .. "'><B>"..t,nil,x+1,y,900,25,1,1,0,true)
  502.         ui.addTextArea(3,"<font color='" .. color[2] .. "'><B>"..t,nil,x-1,y,900,25,1,1,0,true)
  503.         ui.addTextArea(4,"<font color='" .. color[1] .. "'><B>"..t,nil,x,y,900,25,1,1,0,true)
  504.     end,
  505.     --[[ Init ]]--
  506.     init = function()
  507.         mode.sharpie.translations.pt = mode.sharpie.translations.br
  508.  
  509.         if mode.sharpie.translations[tfm.get.room.community] then
  510.             mode.sharpie.langue = tfm.get.room.community
  511.         end
  512.    
  513.         -- Init
  514.         tfm.exec.disableAutoShaman()
  515.         tfm.exec.disableAutoScore()
  516.        
  517.         tfm.exec.newGame()
  518.     end,
  519.     --[[ Events ]]--
  520.     -- NewGame
  521.     eventNewGame = function()
  522.         mode.sharpie.podium = 0
  523.        
  524.         local currentXml = tfm.get.room.xmlMapInfo
  525.         currentXml = currentXml and currentXml.xml or ""
  526.        
  527.         mode.sharpie.mapInfo = {800,400}
  528.         mode.sharpie.flyPower = -50
  529.        
  530.         xml.attribFunc(currentXml or "",{
  531.             [1] = {
  532.                 attribute = "G",
  533.                 func = function(value)
  534.                     value = stringsplit(value,"[^,]+")
  535.                     value = tonumber(value[2]) or value
  536.                     mode.sharpie.flyPower = value < 0 and 50 or -50
  537.                 end
  538.             },
  539.             [2] = {
  540.                 attribute = "L",
  541.                 func = function(value)
  542.                     value = tonumber(value)
  543.                     if value then
  544.                         mode.sharpie.mapInfo[1] = value
  545.                     end
  546.                 end
  547.             },
  548.             [3] = {
  549.                 attribute = "H",
  550.                 func = function(value)
  551.                     value = tonumber(value)
  552.                     if value then
  553.                         mode.sharpie.mapInfo[2] = value
  554.                     end
  555.                 end
  556.             },
  557.             [4] = {
  558.                 attribute = "P",
  559.                 func = function()
  560.                     tableforeach(tfm.get.room.playerList,tfm.exec.killPlayer)
  561.                     tfm.exec.setGameTime(5,false)
  562.                 end
  563.             },
  564.         })
  565.        
  566.         mode.sharpie.hardmode = mathrandom(10) == 6
  567.         if mode.sharpie.hardmode then
  568.             tfm.exec.chatMessage("<CH>" .. system.getTranslation("hardMode"))
  569.         end
  570.     end,
  571.     -- NewPlayer
  572.     eventNewPlayer = function(n)
  573.         tfm.exec.chatMessage("<CE>" .. system.getTranslation("welcome"),n)
  574.  
  575.         system.bindKeyboard(n,32,true,true)
  576.        
  577.         ui.banner("15d60d8e5b8",130,100,n)
  578.     end,
  579.     -- Keyboard
  580.     eventKeyboard = function(n,k,d,x,y)
  581.         if k == 32 then
  582.             tfm.exec.movePlayer(n,0,0,true,0,mode.sharpie.flyPower,true)
  583.             tfm.exec.displayParticle(3,x,y)
  584.         end
  585.     end,
  586.     -- PlayerWon
  587.     eventPlayerWon = function(n)
  588.         mode.sharpie.podium = mode.sharpie.podium + 1
  589.         if mode.sharpie.podium == 1 then
  590.             if mode.sharpie.firstRow[1] == n then
  591.                 mode.sharpie.firstRow[2] = mode.sharpie.firstRow[2] + 1
  592.                
  593.                 if mode.sharpie.totalPlayers > 3 then
  594.                     local msg = system.getTranslation("first")
  595.                     tfm.exec.chatMessage("<G># <ROSE>" .. (msg[mode.sharpie.firstRow[2] - 1] or tablerandom({msg[2],msg[3],msg[6],msg[13],msg[15]})),n)
  596.                 end
  597.             else
  598.                 mode.sharpie.firstRow = {n,1}
  599.             end
  600.  
  601.             tfm.exec.setPlayerScore(n,(mode.sharpie.firstRow[2]+1) * 5,true)
  602.  
  603.             tfm.exec.chatMessage(stringformat("<J>%s %s! %s",n,system.getTranslation("won"),mode.sharpie.firstRow[2] > 1 and "("..mode.sharpie.firstRow[2]..")" or ""))
  604.         else
  605.             tfm.exec.setPlayerScore(n,5,true)
  606.         end
  607.     end,
  608.     -- Loop
  609.     eventLoop = function()
  610.         if _G.currentTime % 5 == 0 then
  611.             local alive,total = system.players()
  612.             mode.sharpie.totalPlayers = total
  613.            
  614.             -- Warning
  615.             mode.sharpie.uiborder(system.getTranslation("nothacker"),10,382)
  616.         end
  617.  
  618.         if mode.sharpie.hardmode and _G.currentTime > 1 and _G.currentTime % 14 == 0 then
  619.             system.newTimer(function()
  620.                 local x,y = mathrandom(0,mode.sharpie.mapInfo[1]),mathrandom(0,mode.sharpie.mapInfo[2])
  621.                 local id = tfm.exec.addImage(tablerandom(mode.sharpie.modeImages) .. ".png","&0",x - 56,y - 51) -- 112x103 img
  622.                 system.newTimer(function()
  623.                     tfm.exec.removeImage(id)
  624.  
  625.                     tfm.exec.displayParticle(24,x,y)
  626.                     tfm.exec.explosion(x,y,50,100)
  627.                 end,1250,false)
  628.             end,1000,false)
  629.         end
  630.     end,
  631. }
  632.  
  633. --[[ Chat ]]--
  634. mode.chat = {
  635.     -- Translations
  636.     translations = {
  637.         en = {
  638.             -- Init
  639.             welcome = "<J>Welcome to #chat. Enjoy while you are muted ?! Report any issue to Bolodefchoco.",
  640.        
  641.             -- Info
  642.             loadmap = "loaded by",
  643.             enabled = "enabled",
  644.             disabled = "disabled",
  645.            
  646.             -- Cats
  647.             shaman = "shaman",
  648.             newGame = "Auto New Game",
  649.            
  650.             -- Misc
  651.             title = "%s has just unlocked the «%s» title.\n<ROSE>Type /title to choose a title",
  652.         },
  653.         ar = {
  654.             welcome = "<J>مرحبًا بك في #chat. استمتع بينما أنت مكتوم ?! بلغ عن أي مشكلة إلى Bolodefchoco.",
  655.        
  656.             loadmap = "شُغل بواسطة",
  657.             enabled = "فُعل",
  658.             disabled = "أُلغي",
  659.            
  660.             shaman = "الشامان",
  661.             newGame = "جولة جديدة تلقائية",
  662.            
  663.             title = "%s has just unlocked the «%s» title.\n<ROSE>Type /title to choose a title",
  664.         },
  665.         br = {
  666.             welcome = "<J>Bem-vindo ao #chat. Aproveite enquanto você está mutado ?! Reporte qualquer problema para Bolodefchoco.",
  667.        
  668.             loadmap = "carregado por",
  669.             enabled = "ativado",
  670.             disabled = "desativado",
  671.            
  672.             shaman = "shaman",
  673.             newGame = "Novo Jogo Automático",
  674.            
  675.             title = "%s Desbloqueou o título «%s»\n<ROSE>Digite /title para escolher um título.",
  676.         },
  677.     },
  678.     langue = "en",
  679.     --[[ Data ]]--
  680.     info = {},
  681.     data = {},
  682.     displayData = {},
  683.     messageId = 0,
  684.     --[[ Settings ]]--
  685.     -- New Game
  686.     hasShaman = false,
  687.     autoNeWGame = false,
  688.     -- Chat
  689.     chatTitle = "Chat",
  690.     --[[ System ]]--
  691.     -- Chat
  692.     chat = function(n,message,update)
  693.         if not update then
  694.             ui.addPopup(0,2,"",n,107,325,565,true)
  695.         end
  696.         ui.addTextArea(0,"",n,108,73,564,253,0x212E35,0x212E35,1,true)
  697.         ui.addTextArea(1,message,n,110,75,560,250,0x324650,0x324650,1,true)
  698.         ui.addTextArea(2,"<p align='center'><B><V>" .. mode.chat.chatTitle,n,108,53,564,20,0x212E35,0x212E35,1,true)
  699.         ui.addTextArea(3,"<p align='right'><B><R><a href='event:close'>X",n,110,54,560,20,1,1,0,true)
  700.     end,
  701.     -- Length
  702.     getTextLength = function(line)
  703.         return stringlen(stringgsub(line,"<.*>",""))
  704.     end,
  705.     -- Data
  706.     loadData = function()
  707.         local message = "<font size='7'>\n</font>"
  708.         for i = 18,1,-1 do
  709.             if #message < 1900 then
  710.                 local line = mode.chat.displayData[i] or ""
  711.                 message = message .. line
  712.             end
  713.         end
  714.         return message
  715.     end,
  716.     -- Update
  717.     updateToRead = function(n)
  718.         ui.addTextArea(4,"<p align='center'><V><a href='event:open'><B>" .. stringsub(stringlower(mode.chat.chatTitle),1,8) .. "</B> <J>" .. mode.chat.info[n].toRead,n,712,378,80,nil,0x324650,0x212E35,1,true)
  719.     end,
  720.     -- Display
  721.     displayChat = function(n,update)
  722.         local loadedM = mode.chat.loadData()
  723.         if not update then
  724.             mode.chat.chat(n,loadedM)
  725.         else
  726.             for k,v in next,mode.chat.info do
  727.                 if v.open then
  728.                     mode.chat.chat(k,loadedM,k ~= n)
  729.                 else
  730.                     v.toRead = v.toRead + 1
  731.                     mode.chat.updateToRead(k)
  732.                 end
  733.             end
  734.         end
  735.     end,
  736.     -- Message
  737.     newMessage = function(message,n)
  738.         mode.chat.messageId = mode.chat.messageId + 1
  739.         tableinsert(mode.chat.data,{mode.chat.messageId,n,stringgsub(stringgsub(message,"@%((.*)%)",function(text) return text end),"{.-:(.-)}",function(text) return text end)})
  740.    
  741.         if mode.chat.getTextLength(message) > 50 then
  742.             message = stringsub(message,1,47) .. "..."
  743.         end
  744.         message = stringgsub(message,"<","&lt;") -- < to <
  745.         message = stringgsub(message,"https?","") -- https to ""
  746.         message = stringgsub(message,"://","") -- :// to ""
  747.         message = stringgsub(message,"@%((.*)%)",function(text) -- @(link:text)
  748.             return stringformat("<a href='event:display.%s'>%s</a>",mode.chat.messageId,text)
  749.         end)
  750.        
  751.         if #message > 0 then
  752.             if stringsub(message,1,1) == "/" then
  753.                 mode.chat.eventChatCommand(n,stringsub(message,2))
  754.             else
  755.                 message = stringgsub(message,"{(.-):(.-)}",function(color,text) -- {colorTag:Text}
  756.                     color = stringupper(color)
  757.                     if tablefind({"BV","R","BL","J","N","N2","PT","CE","CEP","CS","S","PS","G","V","VP","VI","ROSE","CH","T"},color) then
  758.                         return stringformat("<%s>%s</%s>",color,text,color)
  759.                     else
  760.                         return text
  761.                     end
  762.                 end)
  763.                 tableinsert(mode.chat.displayData,1,stringformat("<V>[%s] <N>%s\n",n,message))
  764.             end
  765.         end
  766.     end,
  767.     --[[ Init ]]--
  768.     init = function()
  769.         mode.chat.translations.pt = mode.chat.translations.br
  770.         mode.chat.langue = mode.chat.translations[tfm.get.room.community] and tfm.get.room.community or "en"
  771.         tfm.exec.setRoomMaxPlayers(30)
  772.         system.disableChatCommandDisplay("title",true)
  773.         mode.chat.displayChat()
  774.     end,
  775.     --[[ Events ]]--
  776.     -- NewPlayer
  777.     eventNewPlayer = function(n)
  778.         mode.chat.info[n] = {
  779.             open = true,
  780.             toRead = 0,
  781.         }
  782.         mode.chat.displayChat(n)
  783.         tfm.exec.chatMessage(system.getTranslation("welcome"),n)
  784.     end,
  785.     -- PopupAnswer
  786.     eventPopupAnswer = function(i,n,a)
  787.         if #stringgsub(a," ","") > 0 then
  788.             mode.chat.newMessage(a,n)
  789.             mode.chat.displayChat(n,true)
  790.         else
  791.             mode.chat.displayChat(n)
  792.         end
  793.     end,
  794.     -- TextAreaCallback
  795.     eventTextAreaCallback = function(i,n,c)
  796.         local p = stringsplit(c,"[^%.]+")
  797.         if p[1] == "close" then
  798.             ui.addPopup(0,2,"",n,1e7,1e7)
  799.             for i = 0,3 do
  800.                 ui.removeTextArea(i,n)
  801.             end
  802.             mode.chat.info[n].open = false
  803.             mode.chat.updateToRead(n)
  804.         elseif p[1] == "open" then
  805.             mode.chat.info[n].open = true
  806.             mode.chat.info[n].toRead = 0
  807.             mode.chat.displayChat(n)
  808.             ui.removeTextArea(4,n)
  809.         elseif p[1] == "display" then
  810.             local msg = mode.chat.data[tonumber(p[2])]     
  811.             tfm.exec.chatMessage(stringformat("<N>> <V>[%s] <N>%s",msg[2],msg[3]),n)
  812.         end
  813.     end,
  814.     -- ChatCommand
  815.     eventChatCommand = function(n,c)
  816.         local p = stringsplit(c,"[^%s]+",stringlower)
  817.         if p[1] == "title" and p[2] and system.roomAdmins[n] then
  818.             mode.chat.chatTitle = stringsub(tableconcat(p," ",nil,2),1,40)
  819.             mode.chat.displayChat()
  820.         elseif p[1] == "np" and p[2] then
  821.             tfm.exec.chatMessage(stringformat("<S>%s %s %s",stringsub(p[2],1,1) == "@" and p[2] or "@" .. p[2],system.getTranslation("loadmap"),n))
  822.             tfm.exec.newGame(p[2])
  823.         elseif p[1] == "sha" then
  824.             mode.chat.hasShaman = not mode.chat.hasShaman
  825.            
  826.             tfm.exec.chatMessage("<S>• " .. system.getTranslation("shaman") .. " " .. system.getTranslation((mode.chat.hasShaman and "disabled" or "enabled")),n)
  827.             tfm.exec.disableAutoShaman(mode.chat.hasShaman)
  828.         elseif p[1] == "new" then
  829.             mode.chat.autoNeWGame = not mode.chat.autoNeWGame
  830.        
  831.             tfm.exec.chatMessage("<S>• " .. system.getTranslation("newGame") .. " " .. system.getTranslation((mode.chat.autoNeWGame and "disabled" or "enabled")),n)
  832.             tfm.exec.disableAutoNewGame(mode.chat.autoNeWGame)
  833.             tfm.exec.disableAutoTimeLeft(mode.chat.autoNeWGame)
  834.         elseif stringsub(c,1,6) == "unlock" then
  835.             tfm.exec.chatMessage("<J>" .. stringformat(system.getTranslation("title"),n,stringsub(c,8)),n)
  836.         end
  837.     end,
  838. }
  839.  
  840. --[[ ModeChanged ]]--
  841. system.objects = {
  842.     image = {},
  843.     textarea = {}
  844. }
  845. eventModeChanged = function()
  846.     -- Remove content
  847.     for k in next,system.objects.image do
  848.         tfm.exec.removeImage(k)
  849.     end
  850.    
  851.     for k in next,system.objects.textarea do
  852.         ui.removeTextArea(k,nil)
  853.     end
  854.    
  855.     system.objects = {
  856.         image = {},
  857.         textarea = {}
  858.     }
  859.    
  860.     ui.addPopup(0,0,"",nil,-1500,-1500)
  861.    
  862.     -- Unbind keyboard and mouse, also normalize color name and scores
  863.     for k in next,tfm.get.room.playerList do
  864.         for i = 0,255 do
  865.             for v = 0,1 do
  866.                 system.bindKeyboard(k,i,v == 0,false)
  867.             end
  868.         end
  869.        
  870.         system.bindMouse(k,false)
  871.        
  872.         tfm.exec.setNameColor(k,-1)
  873.         tfm.exec.setPlayerScore(k,0)
  874.     end
  875.    
  876.     -- Set admin back
  877.     system.roomAdmins = system.setAdmins()
  878.    
  879.     -- Reset settings
  880.     for k,v in next,{"AutoScore","WatchCommand","AutoNewGame","AutoShaman","AllShamanSkills","MortCommand","DebugCommand","MinimalistMode","AfkDeath","PhysicalConsumables","AutoTimeLeft"} do
  881.         tfm.exec["disable" .. v](false)
  882.     end
  883.     tfm.exec.setAutoMapFlipMode()
  884.    
  885.     tfm.exec.setRoomMaxPlayers(25)
  886.     tfm.exec.setRoomPassword("")   
  887. end
  888.  
  889. --[[ Events ]]--
  890. events = {}
  891.  
  892. events.eventLoop = function(currentTime,leftTime)
  893.     _G.currentTime = normalizeTime(currentTime / 1e3)
  894.     _G.leftTime = normalizeTime(leftTime / 1e3)
  895. end
  896.  
  897. events.eventChatCommand = function(n,c)
  898.     disableChatCommand(c)
  899.     if module._FREEACCESS[n] then
  900.         if c == "refresh" and (not system.isRoom or module._FREEACCESS[n] > 1) then
  901.             eventModeChanged()
  902.             system.init(true)
  903.         elseif stringsub(c,1,4) == "room" and (not system.isRoom or module._FREEACCESS[n] > 1) then
  904.             system.roomNumber = tonumber(stringsub(c,6)) or 0
  905.             if _G["eventChatCommand"] then
  906.                 eventChatCommand(n,"refresh")
  907.             end
  908.         elseif stringsub(c,1,4) == "load" and (not system.isRoom or module._FREEACCESS[n] > 2) then
  909.             if os.time() > system.modeChanged and os.time() > system.newGameTimer then
  910.                 local newMode = system.getGameMode(stringsub(c,6),true)
  911.                 if newMode then
  912.                     system.init(system.isRoom)
  913.                 end
  914.             end
  915.         end
  916.     end
  917.     if stringsub(c,1,6) == "module" then
  918.         c = stringupper(stringsub(c,8))
  919.         if module["_" .. c] then
  920.             tfm.exec.chatMessage(c .. " : " .. tableconcat(tableturnTable(module["_" .. c]),"\n",function(k,v)
  921.                 return (c == "FREEACCESS" and stringformat("%s(%s)",k,v) or v)
  922.             end),n)
  923.         else
  924.             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)
  925.         end
  926.     elseif c == "modes" then
  927.         tfm.exec.chatMessage(tableconcat(system.submodes,"\n",function(k,v)
  928.             return "#" .. v
  929.         end),n)
  930.     elseif c == "admin" then
  931.         tfm.exec.chatMessage(tableconcat(system.roomAdmins,", ",tostring),n)
  932.     elseif c == "stop" and system.roomAdmins[n] then
  933.         system.exit()
  934.     elseif stringsub(c,1,3) == "adm" and (system.roomAdmins[n] or module._FREEACCESS[n] > 2) then
  935.         system.roomAdmins[stringnick(stringsub(c,5))] = true
  936.     end
  937. end
  938.  
  939. events.eventNewPlayer = function(n)
  940.     tfm.exec.lowerSyncDelay(n)
  941.    
  942.     if system.officialMode[2] ~= "" then
  943.         tfm.exec.chatMessage(system.officialMode[2],n)
  944.     end
  945. end
  946.  
  947. --[[ RoomSettings ]]--
  948. system.roomSettings = {
  949.     ["@"] = function(n)
  950.         system.roomAdmins[stringnick(n)] = true
  951.     end,
  952.     ["#"] = function(id)
  953.         system.miscAttrib = tonumber(id) or 1
  954.         system.miscAttrib = mathsetLim(system.miscAttrib,1,99) -- mathmax(1,mathmin(system.miscAttrib,99))
  955.     end,
  956.     ["*"] = function(name)
  957.         local game = system.getGameMode(name)
  958.         if not game then
  959.             system.gameMode = module._NAME
  960.         end
  961.     end
  962. }
  963. system.setRoom = function()
  964.     if system.isRoom and system.roomAttributes then
  965.         local chars = ""
  966.         for k in next,system.roomSettings do
  967.             chars = chars .. k
  968.         end
  969.  
  970.         for char,value in stringgmatch(system.roomAttributes,"(["..chars.."])([^"..chars.."]+)") do
  971.             value = stringmatch(value,"[^%s]+")
  972.             for k,v in next,system.roomSettings do
  973.                 if k == char then
  974.                     v(value)
  975.                     break
  976.                 end
  977.             end
  978.         end
  979.        
  980.         local officialModes = {
  981.             {"vanilla","<VP>Enjoy your vanilla (: .. okno"},
  982.             {"survivor","<R>Aw, you cannot play survivor on #grounds"},
  983.             {"racing","<CH>Uh, racing? Good luck!"},
  984.             {"music","<BV>Music? Nice choice! Why don't you try a rock'n'roll?"},
  985.             {"bootcamp","<PT>Bootcamp? Ok. This is unfair and your data won't be saved out of the room."},
  986.             {"defilante","<R>Aw, you cannot play defilante on #grounds"},
  987.             {"village","<R>You cannot play village on #grounds. Please, change your room."},
  988.         }
  989.         for k,v in next,officialModes do
  990.             if stringfind(system.roomAttributes,v[1] .. "$") then
  991.                 system.officialMode = {v[1],v[2]}
  992.                 break
  993.             end
  994.         end
  995.     end
  996. end
  997.  
  998. --[[ Initialize ]]--
  999. execute = {}
  1000. system.setRoom()
  1001.  
  1002. system.init = function(refresh)
  1003.     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
  1004.         local e = "event" .. event
  1005.        
  1006.         local found = false
  1007.         for k,v in next,mode[system.gameMode] do
  1008.             if k == e then
  1009.                 execute[e] = v
  1010.                 found = true
  1011.                 break
  1012.             end
  1013.         end
  1014.         if not found then
  1015.             execute[e] = function() end
  1016.         end
  1017.  
  1018.         _G[e] = function(...)
  1019.             if events[e] then
  1020.                 events[e](...)
  1021.             end
  1022.             execute[e](...)
  1023.         end
  1024.     end
  1025.  
  1026.     if refresh then
  1027.         if mode[system.gameMode].reset then
  1028.             mode[system.gameMode].reset()
  1029.         end
  1030.     end
  1031.    
  1032.     if _G["eventNewPlayer"] then
  1033.         tableforeach(tfm.get.room.playerList,eventNewPlayer)
  1034.     end
  1035.    
  1036.     normalizeTranslation()
  1037.     mode[system.gameMode].init()
  1038. end
  1039. system.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement