Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 06/02/2017
- --Last update: 26/07/2017
- --[[ Module ]]--
- local module = {
- _VERSION = "3.8",
- _NAME = "grounds",
- _STATUS = "semi-official",
- _AUTHOR = "Bolodefchoco",
- _LICENSE = [[
- MIT LICENSE
- Copyright (c) 2017 @Transformice + @Bolodefchoco
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
- The above copyright notice and this permission notice shall be included
- in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR
- A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ]],
- _FREEACCESS = { -- Verified players
- -- 3 : Commands + Room admin + Debug
- Bolodefchoco = 3,
- -- 2 : Commands
- Bodykudo = 2,
- Error_404 = 2,
- Jordynl = 2,
- Laagaadoo = 2,
- Sebafrancuz = 2,
- Tocutoeltuco = 2,
- -- 1 : Some commands
- Artinoe = 1,
- Bapereira = 1,
- Barberserk = 1,
- Byontr = 1,
- Claumiau = 1,
- Drescen = 1,
- Ekull = 1,
- Elvismouse = 1,
- Grastfetry = 1,
- Kimsterjay = 1,
- Mcqv = 1,
- Mescouleur = 1,
- Mquk = 1,
- Reshman = 1,
- Rikkeshang = 1,
- Ruamorangos = 1,
- Sammynya = 1,
- },
- }
- --[[ Optimization ]]--
- --[[ String ]]--
- 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
- --[[ Math ]]--
- 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
- --[[ Table ]]--
- 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
- --[[ API ]]--
- -- Timers
- system.newGameTimer = 0
- -- Control
- system.officialMode = {"",""}
- system.setAdmins = function()
- local out = {}
- for k,v in next,module._FREEACCESS do
- if v > 2 then
- out[k] = true
- end
- end
- return out
- end
- -- Improvements
- tableconcat = function(list,sep,f,i,j)
- local txt = ""
- sep = sep or ""
- i,j = i or 1,j or #list
- for k,v in next,list do
- if type(k) ~= "number" and true or (k >= i and k <= j) then
- txt = txt .. (f and f(k,v) or v) .. sep
- end
- end
- return stringsub(txt,1,-1-#sep)
- end
- do
- local newGame = tfm.exec.newGame
- tfm.exec.newGame = function(code)
- if os.time() > system.newGameTimer then
- system.newGameTimer = os.time() + 6000
- newGame(code)
- return true
- end
- return false
- end
- local addImage = tfm.exec.addImage
- local removeImage = tfm.exec.removeImage
- tfm.exec.addImage = function(...)
- local id = addImage(...)
- if id then
- system.objects.image[id] = true
- end
- return id
- end
- tfm.exec.removeImage = function(id)
- removeImage(id)
- if system.objects.image[id] then
- system.objects.image[id] = nil
- end
- end
- local addTextArea = ui.addTextArea
- ui.addTextArea = function(id,...)
- addTextArea(id,...)
- if not system.objects.textarea[id] then
- system.objects.textarea[id] = true
- end
- end
- local chatMessage = tfm.exec.chatMessage
- tfm.exec.chatMessage = function(txt,n)
- if #txt > 1000 then
- local total = 0
- while #txt > total do
- chatMessage(stringsub(txt,total,total + 1000),n)
- total = total + 1001
- end
- else
- chatMessage(txt,n)
- end
- end
- local loadPlayerData = system.loadPlayerData
- system.loadPlayerData = function(n)
- if module._STATUS == "official" then
- return loadPlayerData(n)
- else
- if _G["eventPlayerDataLoaded"] then
- eventPlayerDataLoaded(n,"")
- end
- return true
- end
- end
- local savePlayerData = system.savePlayerData
- system.savePlayerData = function(n,data)
- if module._STATUS == "official" then
- savePlayerData(n,data)
- return true
- else
- return false
- end
- end
- end
- -- Room
- system.isRoom = stringbyte(tfm.get.room.name,2) ~= 3
- system.roomAdmins = system.setAdmins()
- system.miscAttrib = 0
- system.roomNumber,system.roomAttributes = (function()
- if system.isRoom then
- local number,attribute = stringmatch(tfm.get.room.name,"%*?#"..module._NAME.."(%d+)(.*)")
- return tonumber(number) or "",attribute or ""
- else
- return "",""
- end
- end)()
- -- Player
- system.isPlayer = function(n)
- --[[
- The player must not be a souris;
- The player must have played Transformice for at least 5 days
- ]]
- 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
- end
- system.players = function(alivePlayers)
- local alive,total = 0,0
- if alivePlayers then
- alive = {}
- end
- for k,v in next,tfm.get.room.playerList do
- if system.isPlayer(k) then
- if not v.isDead and not v.isVampire then
- if alivePlayers then
- alive[#alive + 1] = k
- else
- alive = alive + 1
- end
- end
- total = total + 1
- end
- end
- if alivePlayers then
- return alive
- else
- return alive,total
- end
- end
- -- System
- currentTime,leftTime = 0,0
- system.loadTable = function(s)
- -- "a.b.c.1" returns a[b][c][1]
- local list
- for tbl in stringgmatch(s,"[^%.]+") do
- tbl = tonumber(tbl) and tonumber(tbl) or tbl
- list = (list and list[tbl] or _G[tbl])
- end
- return list
- end
- system.getTranslation = function(index,n)
- local t = stringformat("mode.%s.translations.%s.%s",system.gameMode,(n and mode[system.gameMode].info[n].langue or mode[system.gameMode].langue),index)
- return system.loadTable(t) or system.loadTable(stringgsub(t,"translations%..-%.",function() return "translations.en." end))
- end
- system.looping = function(f,tick)
- local s = 1000 / tick
- local t = {}
- local fooTimer = function()
- t[#t+1] = system.newTimer(f,1000,true)
- end
- for timer = 0,1000 - s,s do
- system.newTimer(fooTimer,1000 + timer,false)
- end
- return t
- end
- -- Interface
- ui.banner = function(image,aX,aY,n,time)
- time = time or 5
- axis = axis or {100,100}
- local img = tfm.exec.addImage(image .. ".png","&0",aX,aY,n)
- system.newTimer(function()
- tfm.exec.removeImage(img)
- end,time * 1000,false)
- end
- -- Math
- mathisNegative = function(x,iN,iP)
- return (x<0 and (iN or x) or (iP or x))
- end
- mathpercent = function(x,y,v)
- v = (v or 100)
- local m = x/y * v
- return mathmin(m,v)
- end
- mathpythag = function(x1,y1,x2,y2,range)
- return (x1-x2)^2 + (y1-y2)^2 <= (range^2)
- end
- mathsetLim = function(value,min,max)
- return mathmax(min,mathmin(max,value))
- end
- -- String
- stringsplit = function(value,pattern,f)
- local out = {}
- for v in stringgmatch(value,pattern) do
- out[#out + 1] = (f and f(v) or v)
- end
- return out
- end
- stringnick = function(player)
- return stringgsub(stringlower(player),"%a",stringupper,1)
- end
- -- Table
- tablefind = function(list,value,index,f)
- for k,v in next,list do
- local i = (type(v) == "table" and index and v[index] or v)
- if (f and f(i) or i) == value then
- return true,k
- end
- end
- return false,0
- end
- tableturnTable = function(x)
- return (type(x)=="table" and x or {x})
- end
- tablerandom = function(t)
- return (type(t) == "table" and t[mathrandom(#t)] or mathrandom())
- end
- tableshuffle = function(t)
- local randomized = {}
- for v = 1,#t do
- tableinsert(randomized,mathrandom(#randomized),t[v])
- end
- return randomized
- end
- -- Others
- deactivateAccents=function(str)
- local letters = {a = {"á","â","à","å","ã","ä"},e = {"é","ê","è","ë"},i = {"í","î","ì","ï"},o = {"ó","ô","ò","õ","ö"},u = {"ú","û","ù","ü"}}
- for k,v in next,letters do
- for i = 1,#v do
- str = stringgsub(str,v[i],tostring(k))
- end
- end
- return str
- end
- normalizeTime = function(time)
- return mathfloor(time) + ((time - mathfloor(time)) >= .5 and .5 or 0)
- end
- disableChatCommand = function(command)
- system.disableChatCommandDisplay(command,true)
- system.disableChatCommandDisplay(stringlower(command),true)
- system.disableChatCommandDisplay(stringupper(command),true)
- end
- normalizeTranslation = function()
- local t = mode[system.gameMode].translations
- for k,v in next,t.en do
- for i,j in next,t do
- if i ~= "en" then
- if not j[k] then
- j[k] = v
- end
- end
- end
- end
- end
- -- XML Dealer
- xml = {}
- xml.parse = function(currentXml)
- currentXml = stringmatch(currentXml,"<P (.-)/>") or ""
- local out = {}
- for tag,_,value in stringgmatch(currentXml,"([%-%w]+)=([\"'])(.-)%2") do
- out[tag] = value
- end
- return out
- end
- xml.attribFunc = function(currentXml,funcs)
- local attributes = xml.parse(currentXml)
- for k,v in next,funcs do
- if attributes[v.attribute] then
- v.func(attributes[v.attribute])
- end
- end
- end
- xml.addAttrib = function(currentXml,out,launch)
- local parameters = stringmatch(currentXml,"<P (.-)/>") or ""
- for k,v in next,out do
- if not stringfind(parameters,v.tag) then
- currentXml = stringgsub(currentXml,"<P (.-)/>",function(attribs)
- return stringformat("<P %s=\"%s\" %s/>",v.tag,v.value,attribs)
- end)
- end
- end
- if launch then
- tfm.exec.newGame(currentXml)
- else
- return currentXml
- end
- end
- xml.getCoordinates = function(s)
- if stringfind(s,";") then
- local x,y
- local axis,value = stringmatch(s,"(%a);(%d+)")
- value = tonumber(value)
- if value then
- if axis == "x" then x = value else y = value end
- end
- return x or 0,y or 0
- else
- local pos = {}
- for x,y in stringgmatch(s,"(%d+) ?, ?(%d+)") do
- pos[#pos+1] = {x = x,y = y}
- end
- return pos
- end
- end
- --[[ GameMode ]]--
- system.submodes = {}
- system.gameMode = module._NAME
- system.modeChanged = os.time() + 10e3
- system.getGameMode = function(value,notFirst)
- local found,submode = tablefind(system.submodes,stringlower(value),nil,stringlower)
- if found then
- system.gameMode = system.submodes[submode]
- if notFirst then
- eventModeChanged()
- end
- system.modeChanged = os.time() + 10e3
- end
- return found
- end
- --[[ Modes ]]--
- mode = setmetatable({},{
- __newindex = function(list,key,value)
- rawset(list,key,value)
- system.submodes[#system.submodes+1] = key
- end
- })
- --[[ Sharpie ]]--
- mode.sharpie = {
- -- Translations
- translations = {
- en = {
- -- Init
- welcome = "Welcome to #sharpie! Fly pressing space.",
- -- Warning
- nothacker = "The mice flying are NOT hackers!",
- -- Sample words
- won = "won",
- -- Messages
- first = {
- "yay 2 in a row",
- "super pro",
- "oml are you playing alone or what",
- "wooow 4 in a row!",
- "getting hard? good luck pro!",
- "you noob just unlocked the title lightning",
- "woah speedmaster",
- "formula 1",
- "time traveler you sir",
- "queen of the win",
- "as pro as the developer",
- "ILLUMINATI!",
- "are you a real hacker?",
- "I hope you dont loose the chance of seeing the last message",
- "THIS IS A SHIT MESSAGE BECAUSE YOU DIDNT DESERVE IT",
- },
- hardMode = "The hard mode is activated this round!",
- },
- br = {
- welcome = "Bem-vindo ao #sharpie! Voe apertando espaço.",
- nothacker = "Os ratos voando NÃO são hackers!",
- won = "venceu",
- first = {
- "yay 2 seguidas",
- "super pro",
- "omg você tá jogando sozinho ou o que",
- "etaaa 4 seguidas!",
- "ficando difícil? boa sorte mito!",
- "vc noob acaba de desbloquear o título relâmpago",
- "vuash mestre da corrida",
- "relâmpago marquinhos",
- "viajante do tempo vc senhor",
- "rainha da vitória",
- "tão pro quanto o criador do jogo",
- "ILLUMINATI!",
- "éres um hacker de verdade?",
- "Espero que você não perca a chance de ler a última mensagem",
- "ESSA É UMA MENSAGEM DE MERDA PQ VC N MERECEU ISSO",
- },
- hardMode = "O modo difícil está ativado nessa partida!",
- },
- },
- langue = "en",
- --[[ Settings ]]--
- flyPower = -50,
- firstRow = {"",0}, -- Player, amount
- podium = 0,
- totalPlayers = 0,
- hardmode = false,
- modeImages = {"15cbdb3c427","15cbdb479ca","15cbdb4a1ca","15cbdb4cae5"},
- mapInfo = {800,400},
- --[[ UI ]]--
- uiborder = function(t,x,y)
- local colors = {
- {"#F7F918","#EC4848"},
- {"#4CE7F7","#2C9F5B"},
- {"#4BD9CD","#2A64E9"},
- {"#D4F31A","#8C8fA4"},
- }
- local color = tablerandom(colors)
- ui.addTextArea(0,"<font color='" .. color[2] .. "'><B>"..t,nil,x,y-1,900,25,1,1,0,true)
- ui.addTextArea(1,"<font color='" .. color[2] .. "'><B>"..t,nil,x,y+1,900,25,1,1,0,true)
- ui.addTextArea(2,"<font color='" .. color[2] .. "'><B>"..t,nil,x+1,y,900,25,1,1,0,true)
- ui.addTextArea(3,"<font color='" .. color[2] .. "'><B>"..t,nil,x-1,y,900,25,1,1,0,true)
- ui.addTextArea(4,"<font color='" .. color[1] .. "'><B>"..t,nil,x,y,900,25,1,1,0,true)
- end,
- --[[ Init ]]--
- init = function()
- mode.sharpie.translations.pt = mode.sharpie.translations.br
- if mode.sharpie.translations[tfm.get.room.community] then
- mode.sharpie.langue = tfm.get.room.community
- end
- -- Init
- tfm.exec.disableAutoShaman()
- tfm.exec.disableAutoScore()
- tfm.exec.newGame()
- end,
- --[[ Events ]]--
- -- NewGame
- eventNewGame = function()
- mode.sharpie.podium = 0
- local currentXml = tfm.get.room.xmlMapInfo
- currentXml = currentXml and currentXml.xml or ""
- mode.sharpie.mapInfo = {800,400}
- mode.sharpie.flyPower = -50
- xml.attribFunc(currentXml or "",{
- [1] = {
- attribute = "G",
- func = function(value)
- value = stringsplit(value,"[^,]+")
- value = tonumber(value[2]) or value
- mode.sharpie.flyPower = value < 0 and 50 or -50
- end
- },
- [2] = {
- attribute = "L",
- func = function(value)
- value = tonumber(value)
- if value then
- mode.sharpie.mapInfo[1] = value
- end
- end
- },
- [3] = {
- attribute = "H",
- func = function(value)
- value = tonumber(value)
- if value then
- mode.sharpie.mapInfo[2] = value
- end
- end
- },
- [4] = {
- attribute = "P",
- func = function()
- tableforeach(tfm.get.room.playerList,tfm.exec.killPlayer)
- tfm.exec.setGameTime(5,false)
- end
- },
- })
- mode.sharpie.hardmode = mathrandom(10) == 6
- if mode.sharpie.hardmode then
- tfm.exec.chatMessage("<CH>" .. system.getTranslation("hardMode"))
- end
- end,
- -- NewPlayer
- eventNewPlayer = function(n)
- tfm.exec.chatMessage("<CE>" .. system.getTranslation("welcome"),n)
- system.bindKeyboard(n,32,true,true)
- ui.banner("15d60d8e5b8",130,100,n)
- end,
- -- Keyboard
- eventKeyboard = function(n,k,d,x,y)
- if k == 32 then
- tfm.exec.movePlayer(n,0,0,true,0,mode.sharpie.flyPower,true)
- tfm.exec.displayParticle(3,x,y)
- end
- end,
- -- PlayerWon
- eventPlayerWon = function(n)
- mode.sharpie.podium = mode.sharpie.podium + 1
- if mode.sharpie.podium == 1 then
- if mode.sharpie.firstRow[1] == n then
- mode.sharpie.firstRow[2] = mode.sharpie.firstRow[2] + 1
- if mode.sharpie.totalPlayers > 3 then
- local msg = system.getTranslation("first")
- tfm.exec.chatMessage("<G># <ROSE>" .. (msg[mode.sharpie.firstRow[2] - 1] or tablerandom({msg[2],msg[3],msg[6],msg[13],msg[15]})),n)
- end
- else
- mode.sharpie.firstRow = {n,1}
- end
- tfm.exec.setPlayerScore(n,(mode.sharpie.firstRow[2]+1) * 5,true)
- tfm.exec.chatMessage(stringformat("<J>%s %s! %s",n,system.getTranslation("won"),mode.sharpie.firstRow[2] > 1 and "("..mode.sharpie.firstRow[2]..")" or ""))
- else
- tfm.exec.setPlayerScore(n,5,true)
- end
- end,
- -- Loop
- eventLoop = function()
- if _G.currentTime % 5 == 0 then
- local alive,total = system.players()
- mode.sharpie.totalPlayers = total
- -- Warning
- mode.sharpie.uiborder(system.getTranslation("nothacker"),10,382)
- end
- if mode.sharpie.hardmode and _G.currentTime > 1 and _G.currentTime % 14 == 0 then
- system.newTimer(function()
- local x,y = mathrandom(0,mode.sharpie.mapInfo[1]),mathrandom(0,mode.sharpie.mapInfo[2])
- local id = tfm.exec.addImage(tablerandom(mode.sharpie.modeImages) .. ".png","&0",x - 56,y - 51) -- 112x103 img
- system.newTimer(function()
- tfm.exec.removeImage(id)
- tfm.exec.displayParticle(24,x,y)
- tfm.exec.explosion(x,y,50,100)
- end,1250,false)
- end,1000,false)
- end
- end,
- }
- --[[ Chat ]]--
- mode.chat = {
- -- Translations
- translations = {
- en = {
- -- Init
- welcome = "<J>Welcome to #chat. Enjoy while you are muted ?! Report any issue to Bolodefchoco.",
- -- Info
- loadmap = "loaded by",
- enabled = "enabled",
- disabled = "disabled",
- -- Cats
- shaman = "shaman",
- newGame = "Auto New Game",
- -- Misc
- title = "%s has just unlocked the «%s» title.\n<ROSE>Type /title to choose a title",
- },
- ar = {
- welcome = "<J>مرحبًا بك في #chat. استمتع بينما أنت مكتوم ?! بلغ عن أي مشكلة إلى Bolodefchoco.",
- loadmap = "شُغل بواسطة",
- enabled = "فُعل",
- disabled = "أُلغي",
- shaman = "الشامان",
- newGame = "جولة جديدة تلقائية",
- title = "%s has just unlocked the «%s» title.\n<ROSE>Type /title to choose a title",
- },
- br = {
- welcome = "<J>Bem-vindo ao #chat. Aproveite enquanto você está mutado ?! Reporte qualquer problema para Bolodefchoco.",
- loadmap = "carregado por",
- enabled = "ativado",
- disabled = "desativado",
- shaman = "shaman",
- newGame = "Novo Jogo Automático",
- title = "%s Desbloqueou o título «%s»\n<ROSE>Digite /title para escolher um título.",
- },
- },
- langue = "en",
- --[[ Data ]]--
- info = {},
- data = {},
- displayData = {},
- messageId = 0,
- --[[ Settings ]]--
- -- New Game
- hasShaman = false,
- autoNeWGame = false,
- -- Chat
- chatTitle = "Chat",
- --[[ System ]]--
- -- Chat
- chat = function(n,message,update)
- if not update then
- ui.addPopup(0,2,"",n,107,325,565,true)
- end
- ui.addTextArea(0,"",n,108,73,564,253,0x212E35,0x212E35,1,true)
- ui.addTextArea(1,message,n,110,75,560,250,0x324650,0x324650,1,true)
- ui.addTextArea(2,"<p align='center'><B><V>" .. mode.chat.chatTitle,n,108,53,564,20,0x212E35,0x212E35,1,true)
- ui.addTextArea(3,"<p align='right'><B><R><a href='event:close'>X",n,110,54,560,20,1,1,0,true)
- end,
- -- Length
- getTextLength = function(line)
- return stringlen(stringgsub(line,"<.*>",""))
- end,
- -- Data
- loadData = function()
- local message = "<font size='7'>\n</font>"
- for i = 18,1,-1 do
- if #message < 1900 then
- local line = mode.chat.displayData[i] or ""
- message = message .. line
- end
- end
- return message
- end,
- -- Update
- updateToRead = function(n)
- 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)
- end,
- -- Display
- displayChat = function(n,update)
- local loadedM = mode.chat.loadData()
- if not update then
- mode.chat.chat(n,loadedM)
- else
- for k,v in next,mode.chat.info do
- if v.open then
- mode.chat.chat(k,loadedM,k ~= n)
- else
- v.toRead = v.toRead + 1
- mode.chat.updateToRead(k)
- end
- end
- end
- end,
- -- Message
- newMessage = function(message,n)
- mode.chat.messageId = mode.chat.messageId + 1
- tableinsert(mode.chat.data,{mode.chat.messageId,n,stringgsub(stringgsub(message,"@%((.*)%)",function(text) return text end),"{.-:(.-)}",function(text) return text end)})
- if mode.chat.getTextLength(message) > 50 then
- message = stringsub(message,1,47) .. "..."
- end
- message = stringgsub(message,"<","<") -- < to <
- message = stringgsub(message,"https?","") -- https to ""
- message = stringgsub(message,"://","") -- :// to ""
- message = stringgsub(message,"@%((.*)%)",function(text) -- @(link:text)
- return stringformat("<a href='event:display.%s'>%s</a>",mode.chat.messageId,text)
- end)
- if #message > 0 then
- if stringsub(message,1,1) == "/" then
- mode.chat.eventChatCommand(n,stringsub(message,2))
- else
- message = stringgsub(message,"{(.-):(.-)}",function(color,text) -- {colorTag:Text}
- color = stringupper(color)
- if tablefind({"BV","R","BL","J","N","N2","PT","CE","CEP","CS","S","PS","G","V","VP","VI","ROSE","CH","T"},color) then
- return stringformat("<%s>%s</%s>",color,text,color)
- else
- return text
- end
- end)
- tableinsert(mode.chat.displayData,1,stringformat("<V>[%s] <N>%s\n",n,message))
- end
- end
- end,
- --[[ Init ]]--
- init = function()
- mode.chat.translations.pt = mode.chat.translations.br
- mode.chat.langue = mode.chat.translations[tfm.get.room.community] and tfm.get.room.community or "en"
- tfm.exec.setRoomMaxPlayers(30)
- system.disableChatCommandDisplay("title",true)
- mode.chat.displayChat()
- end,
- --[[ Events ]]--
- -- NewPlayer
- eventNewPlayer = function(n)
- mode.chat.info[n] = {
- open = true,
- toRead = 0,
- }
- mode.chat.displayChat(n)
- tfm.exec.chatMessage(system.getTranslation("welcome"),n)
- end,
- -- PopupAnswer
- eventPopupAnswer = function(i,n,a)
- if #stringgsub(a," ","") > 0 then
- mode.chat.newMessage(a,n)
- mode.chat.displayChat(n,true)
- else
- mode.chat.displayChat(n)
- end
- end,
- -- TextAreaCallback
- eventTextAreaCallback = function(i,n,c)
- local p = stringsplit(c,"[^%.]+")
- if p[1] == "close" then
- ui.addPopup(0,2,"",n,1e7,1e7)
- for i = 0,3 do
- ui.removeTextArea(i,n)
- end
- mode.chat.info[n].open = false
- mode.chat.updateToRead(n)
- elseif p[1] == "open" then
- mode.chat.info[n].open = true
- mode.chat.info[n].toRead = 0
- mode.chat.displayChat(n)
- ui.removeTextArea(4,n)
- elseif p[1] == "display" then
- local msg = mode.chat.data[tonumber(p[2])]
- tfm.exec.chatMessage(stringformat("<N>> <V>[%s] <N>%s",msg[2],msg[3]),n)
- end
- end,
- -- ChatCommand
- eventChatCommand = function(n,c)
- local p = stringsplit(c,"[^%s]+",stringlower)
- if p[1] == "title" and p[2] and system.roomAdmins[n] then
- mode.chat.chatTitle = stringsub(tableconcat(p," ",nil,2),1,40)
- mode.chat.displayChat()
- elseif p[1] == "np" and p[2] then
- tfm.exec.chatMessage(stringformat("<S>%s %s %s",stringsub(p[2],1,1) == "@" and p[2] or "@" .. p[2],system.getTranslation("loadmap"),n))
- tfm.exec.newGame(p[2])
- elseif p[1] == "sha" then
- mode.chat.hasShaman = not mode.chat.hasShaman
- tfm.exec.chatMessage("<S>• " .. system.getTranslation("shaman") .. " " .. system.getTranslation((mode.chat.hasShaman and "disabled" or "enabled")),n)
- tfm.exec.disableAutoShaman(mode.chat.hasShaman)
- elseif p[1] == "new" then
- mode.chat.autoNeWGame = not mode.chat.autoNeWGame
- tfm.exec.chatMessage("<S>• " .. system.getTranslation("newGame") .. " " .. system.getTranslation((mode.chat.autoNeWGame and "disabled" or "enabled")),n)
- tfm.exec.disableAutoNewGame(mode.chat.autoNeWGame)
- tfm.exec.disableAutoTimeLeft(mode.chat.autoNeWGame)
- elseif stringsub(c,1,6) == "unlock" then
- tfm.exec.chatMessage("<J>" .. stringformat(system.getTranslation("title"),n,stringsub(c,8)),n)
- end
- end,
- }
- --[[ ModeChanged ]]--
- system.objects = {
- image = {},
- textarea = {}
- }
- eventModeChanged = function()
- -- Remove content
- for k in next,system.objects.image do
- tfm.exec.removeImage(k)
- end
- for k in next,system.objects.textarea do
- ui.removeTextArea(k,nil)
- end
- system.objects = {
- image = {},
- textarea = {}
- }
- ui.addPopup(0,0,"",nil,-1500,-1500)
- -- Unbind keyboard and mouse, also normalize color name and scores
- for k in next,tfm.get.room.playerList do
- for i = 0,255 do
- for v = 0,1 do
- system.bindKeyboard(k,i,v == 0,false)
- end
- end
- system.bindMouse(k,false)
- tfm.exec.setNameColor(k,-1)
- tfm.exec.setPlayerScore(k,0)
- end
- -- Set admin back
- system.roomAdmins = system.setAdmins()
- -- Reset settings
- for k,v in next,{"AutoScore","WatchCommand","AutoNewGame","AutoShaman","AllShamanSkills","MortCommand","DebugCommand","MinimalistMode","AfkDeath","PhysicalConsumables","AutoTimeLeft"} do
- tfm.exec["disable" .. v](false)
- end
- tfm.exec.setAutoMapFlipMode()
- tfm.exec.setRoomMaxPlayers(25)
- tfm.exec.setRoomPassword("")
- end
- --[[ Events ]]--
- events = {}
- events.eventLoop = function(currentTime,leftTime)
- _G.currentTime = normalizeTime(currentTime / 1e3)
- _G.leftTime = normalizeTime(leftTime / 1e3)
- end
- events.eventChatCommand = function(n,c)
- disableChatCommand(c)
- if module._FREEACCESS[n] then
- if c == "refresh" and (not system.isRoom or module._FREEACCESS[n] > 1) then
- eventModeChanged()
- system.init(true)
- elseif stringsub(c,1,4) == "room" and (not system.isRoom or module._FREEACCESS[n] > 1) then
- system.roomNumber = tonumber(stringsub(c,6)) or 0
- if _G["eventChatCommand"] then
- eventChatCommand(n,"refresh")
- end
- elseif stringsub(c,1,4) == "load" and (not system.isRoom or module._FREEACCESS[n] > 2) then
- if os.time() > system.modeChanged and os.time() > system.newGameTimer then
- local newMode = system.getGameMode(stringsub(c,6),true)
- if newMode then
- system.init(system.isRoom)
- end
- end
- end
- end
- if stringsub(c,1,6) == "module" then
- c = stringupper(stringsub(c,8))
- if module["_" .. c] then
- tfm.exec.chatMessage(c .. " : " .. tableconcat(tableturnTable(module["_" .. c]),"\n",function(k,v)
- return (c == "FREEACCESS" and stringformat("%s(%s)",k,v) or v)
- end),n)
- else
- 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)
- end
- elseif c == "modes" then
- tfm.exec.chatMessage(tableconcat(system.submodes,"\n",function(k,v)
- return "#" .. v
- end),n)
- elseif c == "admin" then
- tfm.exec.chatMessage(tableconcat(system.roomAdmins,", ",tostring),n)
- elseif c == "stop" and system.roomAdmins[n] then
- system.exit()
- elseif stringsub(c,1,3) == "adm" and (system.roomAdmins[n] or module._FREEACCESS[n] > 2) then
- system.roomAdmins[stringnick(stringsub(c,5))] = true
- end
- end
- events.eventNewPlayer = function(n)
- tfm.exec.lowerSyncDelay(n)
- if system.officialMode[2] ~= "" then
- tfm.exec.chatMessage(system.officialMode[2],n)
- end
- end
- --[[ RoomSettings ]]--
- system.roomSettings = {
- ["@"] = function(n)
- system.roomAdmins[stringnick(n)] = true
- end,
- ["#"] = function(id)
- system.miscAttrib = tonumber(id) or 1
- system.miscAttrib = mathsetLim(system.miscAttrib,1,99) -- mathmax(1,mathmin(system.miscAttrib,99))
- end,
- ["*"] = function(name)
- local game = system.getGameMode(name)
- if not game then
- system.gameMode = module._NAME
- end
- end
- }
- system.setRoom = function()
- if system.isRoom and system.roomAttributes then
- local chars = ""
- for k in next,system.roomSettings do
- chars = chars .. k
- end
- for char,value in stringgmatch(system.roomAttributes,"(["..chars.."])([^"..chars.."]+)") do
- value = stringmatch(value,"[^%s]+")
- for k,v in next,system.roomSettings do
- if k == char then
- v(value)
- break
- end
- end
- end
- local officialModes = {
- {"vanilla","<VP>Enjoy your vanilla (: .. okno"},
- {"survivor","<R>Aw, you cannot play survivor on #grounds"},
- {"racing","<CH>Uh, racing? Good luck!"},
- {"music","<BV>Music? Nice choice! Why don't you try a rock'n'roll?"},
- {"bootcamp","<PT>Bootcamp? Ok. This is unfair and your data won't be saved out of the room."},
- {"defilante","<R>Aw, you cannot play defilante on #grounds"},
- {"village","<R>You cannot play village on #grounds. Please, change your room."},
- }
- for k,v in next,officialModes do
- if stringfind(system.roomAttributes,v[1] .. "$") then
- system.officialMode = {v[1],v[2]}
- break
- end
- end
- end
- end
- --[[ Initialize ]]--
- execute = {}
- system.setRoom()
- system.init = function(refresh)
- 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
- local e = "event" .. event
- local found = false
- for k,v in next,mode[system.gameMode] do
- if k == e then
- execute[e] = v
- found = true
- break
- end
- end
- if not found then
- execute[e] = function() end
- end
- _G[e] = function(...)
- if events[e] then
- events[e](...)
- end
- execute[e](...)
- end
- end
- if refresh then
- if mode[system.gameMode].reset then
- mode[system.gameMode].reset()
- end
- end
- if _G["eventNewPlayer"] then
- tableforeach(tfm.get.room.playerList,eventNewPlayer)
- end
- normalizeTranslation()
- mode[system.gameMode].init()
- end
- system.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement