Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creator: Bolodefchoco
- --Made in: 06/02/2017
- --Last update: 16/09/2017
- --[[ Module ]]--
- local module = {
- _VERSION = "1",
- _NAME = "signal",
- _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,
- Trumpuke = 3,
- -- 2 : Commands
- Bodykudo = 2,
- Error_404 = 2,
- Jordynl = 2,
- Laagaadoo = 2,
- Mescouleur = 2,
- Sebafrancuz = 2,
- Tocutoeltuco = 2,
- -- 1 : Some commands
- Abdeltif = 1,
- Animjarcanin = 1,
- Artinoe = 1,
- Atinesta = 1,
- Auroraclears = 1,
- Bapereira = 1,
- Barberserk = 1,
- Bataatiinha = 1,
- Bellaxo = 1,
- Bibsho = 1,
- Bielbateriax = 1,
- Bjikata = 1,
- Bruniinhoowx = 1,
- Byontr = 1,
- Caiolopelope = 1,
- Chocodivo = 1,
- Claumiau = 1,
- Connow = 1,
- Daelea = 1,
- Distances = 1,
- Drescen = 1,
- Ekull = 1,
- Exsilium = 1,
- Flindix = 1,
- Gemalugeter = 1,
- Grastfetry = 1,
- Grincreep = 1,
- Ikkemon = 1,
- Jotatavo = 1,
- Kimsterjay = 1,
- Kingtenso = 1,
- Lebluemice = 1,
- Lucasrslv = 1,
- Mcqv = 1,
- Miyakogotoku = 1,
- Mousetat = 1,
- Mquk = 1,
- Myelou = 1,
- Nedior = 1,
- Nlff = 1,
- Okpatinhos = 1,
- Pjfsamora = 1,
- Prysmos = 1,
- Reshman = 1,
- Rianmojang1 = 1,
- Rosianna_rabbit = 1,
- Ruamorangos = 1,
- Sammynya = 1,
- Squalleze = 1,
- Tdft = 1,
- Thegbc = 1,
- Tockego = 1,
- Treasuredsoul = 1,
- Victorruanpk = 1,
- Viniciusdara = 1,
- Vinitexeira = 1,
- Xfelrat = 1,
- Xorcist = 1,
- Yuir = 1,
- Zacriker = 1,
- Zippydoodah = 1,
- Zagear = 1,
- Zombiewd = 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 ]]--
- --[[ Control ]]--
- system.newGameTimer = 0
- system.officialMode = {"",""}
- system.playerMessage = ""
- 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 or "#" .. tablerandom({0,0,0,0,1,1,1,4,5,6,7,8,9,1,4,5,6,7,8,9,0}))
- 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 or -1
- 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)
- txt = tostring(txt)
- 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 0,attribute or ""
- else
- return 0,""
- end
- end)()
- system.roomLanguage = ""
- --[[ 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 ]]--
- events = {}
- 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)
- iN = iN == nil and x or iN
- iP = iP == nil and x or iP
- return (x<0 and iN or iP)
- 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
- stringtrim = function(s)
- return (stringgsub(s,"^%s*(.-)%s*$","%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
- tablemerge = function(this,src)
- for k,v in next,src do
- if this[k] then
- if type(v) == "table" then
- this[k] = tableturnTable(this[k])
- tablemerge(this[k],v)
- else
- this[k] = this[k] or v
- end
- else
- this[k] = v
- end
- end
- 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,...)
- for k,v in next,{command,...} do
- system.disableChatCommandDisplay(v,true)
- system.disableChatCommandDisplay(stringlower(v),true)
- system.disableChatCommandDisplay(stringupper(v),true)
- end
- end
- normalizeTranslation = function()
- local t = mode[system.gameMode].translations
- if mode[system.gameMode].langue == "" then
- mode[system.gameMode].translations.pt = mode[system.gameMode].translations.br
- -- Sets the main language according to the community
- local p = {system.roomLanguage,tfm.get.room.community}
- for i = 1,#p do
- if mode[system.gameMode].translations[p[i]] then
- mode[system.gameMode].langue = p[i]
- end
- end
- end
- for k,v in next,t do
- if k ~= "en" then
- tablemerge(v,t.en)
- end
- end
- end
- normalizeNumber = function(number,sep)
- sep = sep or " "
- number = tostring(mathfloor(number))
- number = stringgsub(number,"E(%d+)",function(cn) -- e5 = 00000
- return stringrep("0",tonumber(cn))
- end)
- number = stringgsub(stringreverse(number),"(...)",function(c)
- return c .. sep
- end)
- return stringreverse(number)
- end
- pairsByIndexes = function(list,f)
- local out = {}
- for index in next,list do
- out[#out + 1] = index
- end
- tablesort(out,f)
- local i = 0
- return function()
- i = i + 1
- if out[i] == nil then
- return nil
- else
- return out[i],list[out[i]]
- end
- end
- end
- --[[ XML ]]--
- 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
- --[[ Color ]]--
- color = {
- hexToRgb = function(hex)
- local h = stringformat("%06x",hex)
- return tonumber("0x"..stringsub(h,1,2)),tonumber("0x"..stringsub(h,3,4)),tonumber("0x"..stringsub(h,5,6))
- end,
- rgbToHsl = function(r,g,b)
- r,g,b = r/255,g/255,b/255
- local max,min = mathmax(r,g,b),mathmin(r,g,b)
- local h,s,l
- h = (max + min) / 2
- s,l = h,h
- if max == min then
- h,s = 0,0
- else
- local d = max - min
- local s = l > .5 and (d/(2 - max - min)) or (d/(max + min))
- if max == r then
- h = (g-b)/d
- if g < b then
- h = h + 6
- end
- elseif max == g then
- h = (b-r)/d + 2
- elseif max == b then
- h = (r-g)/d + 4
- end
- h = h/6
- end
- return {h=h,s=s,l=l}
- end,
- hslToRgb = function(h,s,l)
- local r,g,b
- if s == 0 then
- r,g,b = l,l,l
- else
- local hueToRgb = function(p,q,t)
- if t < 0 then
- t = t + 1
- end
- if t > 1 then
- t = t - 1
- end
- if t < 1/6 then
- return p + (q - p) * 6 * t
- end
- if t < 1/2 then
- return q
- end
- if t < 2/3 then
- return p + (q - p) * (2/3 - t) * 6
- end
- return p
- end
- local q = l < .5 and (l * (1 + s)) or (l + s - l * s)
- local p = 2 * l - q
- r = hueToRgb(p,q,h + 1/3)
- g = hueToRgb(p,q,h)
- b = hueToRgb(p,q,h - 1/3)
- end
- return r * 255,g * 255,b * 255
- end,
- rgbToHex = function(r,g,b)
- return tonumber(stringformat('%02x%02x%02x',r,g,b),16)
- end,
- YELLOW = 0xF9EC27,
- RED = 0xF94226,
- LIGHT_RED = 0xD1605D,
- BLUE = 0x34A4E5,
- DEEP_BLUE = 0x4F7F9A,
- DARK_BLUE = 0x2D80AF,
- GRAY = 0x969696,
- SALMON = 0xAC6C64,
- BROWN = 0x89635A,
- BEIGE = 0x937A53,
- TURQUOISE = 0x59D1C8,
- ROSE = 0x816669,
- MOSS_GREEN = 0x689636,
- }
- --[[ GameMode ]]--
- system.submodes = {}
- system.gameMode = module._NAME
- system.modeChanged = os.time() + 1000
- 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() + 1000
- end
- return found
- end
- --[[ Modes ]]--
- mode = setmetatable({},{
- __newindex = function(list,key,value)
- rawset(list,key,setmetatable(value,{
- __index = function(nList,nKey)
- if nKey == "langue" then
- return "en"
- end
- end
- }))
- system.submodes[#system.submodes+1] = key
- end
- })
- --[[ Signal ]]--
- mode.signal = {
- -- Translations
- translations = {
- en = {
- -- Init
- welcome = "Welcome to <PS>#Signal<S>! Follow the signs and join the hole! Use !help to read more informations.\n\tReport any issue to Bolodefchoco",
- -- Info
- info = {
- [1] = {"Run","Run the faster you can. Do not stop!"},
- [2] = {"Attention","Pay attention! You can die in a few seconds!"},
- [3] = {"Stop","Stop or die!"},
- },
- skip = "<PS>[•] <S>Impossible map? Type !skip",
- skipped = "Your vote to skip the map has been recorded.",
- -- Simple words
- close = "Close",
- },
- br = {
- welcome = "Bem-vindo ao <PS>#Signal<S>! Siga os sinais e entre na toca! Use !help para ler mais informações.\n\tReporte qualquer problema para Bolodefchoco",
- info = {
- [1] = {"Corra","Corra o mais rápido que puder. Não pare!"},
- [2] = {"Atenção","Preste atenção! Você poderá morrer a qualquer momento!"},
- [3] = {"Pare","Pare ou morra!"},
- },
- skip = "<PS>[•] <S>Mapa impossÃvel? Digite !skip",
- skipped = "Seu voto para passar o mapa foi registrado.",
- close = "Fechar",
- },
- pl = {
- welcome = "Witaj w <PS>#Signal<S>! Patrz na tabliczke i wejdź do norki! Użyj komendy !help, aby przeczytać więcej informacji.\n\tZgłoś wszystkie błędy jakie znajdziesz do Bolodefchoco",
- info = {
- [1] = {"Biegnij","Biegnij jak najszybciej do norki. Nie zatrzymuj siÄ™!"},
- [2] = {"Uważaj","Uważaj! Możesz zginąć za kilka sekund!"},
- [3] = {"Stój","Stój albo zgiń!"},
- },
- skip = "<PS>[•] <S>Niemożliwa mapa? Wpisz komendę !skip",
- skipped = "Twój głos na ominięcie mapy został policzony.",
- close = "Zamknij",
- },
- },
- langue = "",
- --[[ Data ]]--
- info = {},
- --[[ Maps ]]--
- generateMap = function()
- local groundProperties = {[0] = {.3,.2},[4] = {20,.2},[5] = {.3,.2},[6] = {.3,.2},[7] = {.1,.2},[10] = {.3,0},[11] = {.05,.1},[3] = {5,20}}
- local groundDecorations = {[0] = {0,4,5},[4] = {1,42,51},[5] = {1,2,4,12,18,20,32,42,46},[6] = {0,1,2,3,4,5,11,42},[7] = {7,8,9,10},[10] = {42,103,118},[11] = {51,106},[3] = {}}
- local newGround = "<S L=\"%s\" H=\"%s\" X=\"%s\" Y=\"%s\" T=\"%s\" P=\"0,0,%s,%s,0,0,0,0\" />"
- local newDecoration = "<P P=\"%s,0\" X=\"%d\" Y=\"%d\" T=\"%d\" />"
- local object = "<%s X=\"%s\" Y=\"%s\"/>"
- local objects = {hole="T",mice="DS",cheese="F"}
- local mapHeight = mathrandom(1500,3000)
- local grounds = {}
- local decorations = {}
- for i = 1,mathceil(mapHeight/180) do
- local T = tablerandom({0,4,5,6,7,10,11,tablerandom({4,5,6,10,3})})
- local H = T==3 and mathrandom(10,20) or mathrandom(40,100)
- local Y = (#grounds > 1 and grounds[#grounds].Y < 320 and mathrandom(230,310) or mathrandom(300,350)) or mathrandom(290,350)
- local X,L
- repeat
- X = (#grounds > 1 and (grounds[#grounds].X + ((mathrandom(-1,1) * 30) + 200)) or mathrandom(50,300))
- X = X < 60 and 100 or X > mapHeight - 100 and mapHeight - 300 or X
- L = T==3 and H or mathrandom(40,mathceil(mapHeight/18))
- until (X - (L/2)) > 50 and (X + (L/2)) < mapHeight - 50
- local properties = groundProperties[T]
- grounds[#grounds + 1] = {X=X,Y=Y,L=L,H=H,stringformat(newGround,L,H,X,Y,T,properties[1],properties[2])}
- if T ~= 3 and mathrandom(20) < 10 then
- local decoList = groundDecorations[T]
- decorations[#decorations + 1] = stringformat(newDecoration,tablerandom({0,0,0,mathrandom(0,1),1}),X - mathrandom(-((L/4)+1),((L/4)+1)),Y - (H/2),tablerandom(decoList))
- end
- end
- local cheeseX
- local foo = function()
- for k,v in next,grounds do
- if (cheeseX + 10) > (v.X - v.L/2) and (cheeseX - 10) < (v.X + v.L/2) then
- return false
- end
- end
- return true
- end
- repeat
- cheeseX = mathrandom(200,mapHeight - 500)
- until foo()
- grounds[#grounds + 1] = {X=0,Y=0,L=0,H=0,stringformat(newGround,200,40,100,380,2,.3,.9)}
- grounds[#grounds + 1] = {X=0,Y=0,L=0,H=0,stringformat(newGround,300,40,mapHeight - 150,380,6,.3,.2)}
- tfm.exec.newGame(stringformat("<C><P G=\"0,%s\" F=\"%s\" L=\"%s\" /><Z><S>%s</S><D>%s%s%s%s</D><O /></Z></C>",tablerandom({mathrandom(7,12),10,11,9}),tablerandom({0,1,2,3,4,5,7,8}),mapHeight,tableconcat(grounds,"",function(k,v) return v[1] end),stringformat(object,objects.hole,mapHeight - 30,360),stringformat(object,objects.mice,10,365),stringformat(object,objects.cheese,cheeseX,mathrandom(280,340)),tableconcat(decorations)))
- end,
- loadMap = function()
- mode.signal.rounds = mode.signal.rounds + 1
- if mode.signal.rounds % 5 == 0 or system.miscAttrib > 0 then
- mode.signal.generateMap()
- else
- tfm.exec.newGame("#7")
- end
- end,
- --[[ Settings ]]--
- -- New Game
- sys = {0,1},
- discrepancy = 0,
- lights = {"15b52f8717d","15b52f8583a","15b52f88765"},
- lightId = -1,
- skip = 0,
- rounds = 0,
- possible = false,
- isGeneratedMap = false,
- -- UpdateLight
- update = function(id)
- tfm.exec.removeImage(mode.signal.lightId)
- mode.signal.lightId = tfm.exec.addImage(mode.signal.lights[mode.signal.sys[2]] .. ".png","&0",375,30)
- local color = ({0x1CB70C,0xF4D400,0xEC0000})[mode.signal.sys[2]]
- for k,v in next,mode.signal.info do
- if id == 1 then
- if not v.afk and v.canRev then
- tfm.exec.respawnPlayer(k)
- end
- end
- tfm.exec.setNameColor(k,color)
- end
- end,
- --[[ UI ]]--
- displayInfo = function(n,id)
- local color = ({"<VP>","<J>","<R>"})[id]
- ui.addTextArea(1,"<p align='center'><font size='25'>" .. color .. system.getTranslation("info."..id..".1") .. "\n</font></p><p align='left'><font size='14'>" .. system.getTranslation("info."..id..".2"),n,250,110,300,181,0x324650,0x27343A,1,true)
- ui.addTextArea(2,"<font size='2'>\n</font><p align='center'><font size='16'><a href='event:close'>" .. system.getTranslation("close"),n,250,300,300,30,0x27343A,0x27343A,1,true)
- ui.addTextArea(3,"<p align='center'><font size='20'><a href='event:info.1'><VP>•</a> <a href='event:info.2'><J>•</a> <a href='event:info.3'><R>•</a>",n,250,145,300,30,1,1,0,true)
- tfm.exec.removeImage(mode.signal.info[n].imageId)
- mode.signal.info[n].imageId = tfm.exec.addImage(mode.signal.lights[id] .. ".png","&1",375,200,n)
- end,
- --[[ Init ]]--
- reset = function()
- -- Data
- mode.signal.info = {}
- end,
- init = function()
- for _,f in next,{"AutoShaman","AutoNewGame","AutoTimeLeft","PhysicalConsumables"} do
- tfm.exec["disable"..f]()
- end
- mode.signal.loadMap()
- end,
- --[[ Events ]]--
- -- NewPlayer
- eventNewPlayer = function(n)
- if not mode.signal.info[n] then
- mode.signal.info[n] = {
- isMoving = {false,false,false,false},
- imageId = -1,
- afk = true,
- skipped = false,
- canRev = true,
- }
- end
- for i = 0,3 do
- system.bindKeyboard(n,i,true,true)
- system.bindKeyboard(n,i,false,true)
- end
- tfm.exec.chatMessage("<S>" .. system.getTranslation("welcome"),n)
- ui.banner("15d60d9212c",220,130,n)
- end,
- -- NewGame
- eventNewGame = function()
- mode.signal.skip = 0
- mode.signal.possible = false
- mode.signal.isGeneratedMap = tfm.get.room.xmlMapInfo.author == "#Module"
- if mode.signal.isGeneratedMap and mode.signal.rounds % 3 == 0 then
- tfm.exec.chatMessage(system.getTranslation("skip"))
- end
- ui.setMapName((mode.signal.isGeneratedMap and "<BL>@" .. mathrandom(999) or tfm.get.room.xmlMapInfo.author .. " <BL>- " .. tfm.get.room.currentMap) .. " <G>| <N>Round : <V>" .. mode.signal.rounds)
- for k,v in next,mode.signal.info do
- v.isMoving = {false,false,false,false}
- v.afk = true
- v.skipped = false
- v.canRev = true
- end
- mode.signal.sys = {0,1}
- mode.signal.update(mode.signal.sys[2])
- end,
- -- Keyboard
- eventKeyboard = function(n,k,d)
- if mode.signal.sys[2] == 3 and d and os.time() > mode.signal.discrepancy then
- tfm.exec.killPlayer(n)
- else
- mode.signal.info[n].isMoving[k + 1] = d
- end
- mode.signal.info[n].afk = false
- end,
- -- Loop
- eventLoop = function(currentTime,leftTime)
- if _G.currentTime > 8 then
- if os.time() > mode.signal.sys[1] then
- mode.signal.sys[2] = (mode.signal.sys[2] % 3) + 1
- mode.signal.sys[1] = os.time() + ({mathrandom(7,13),mathrandom(2,3),mathrandom(3,5)})[mode.signal.sys[2]] * 1000
- mode.signal.update(mode.signal.sys[2])
- mode.signal.discrepancy = os.time() + 520
- end
- end
- if _G.leftTime > 2 and system.players() > 0 then
- if mode.signal.sys[2] == 3 and os.time() > mode.signal.discrepancy then
- for k,v in next,mode.signal.info do
- for i,j in next,v.isMoving do
- if j then
- tfm.exec.killPlayer(k)
- break
- end
- end
- end
- end
- else
- mode.signal.loadMap()
- end
- end,
- -- TextAreaCallback
- eventTextAreaCallback = function(i,n,c)
- local p = stringsplit(c,"[^%.]+")
- if p[1] == "info" then
- mode.signal.displayInfo(n,tonumber(p[2]))
- elseif p[1] == "close" then
- tfm.exec.removeImage(mode.signal.info[n].imageId)
- for i = 1,3 do
- ui.removeTextArea(i,n)
- end
- end
- end,
- -- ChatCommand
- eventChatCommand = function(n,c)
- if c == "info" or c == "help" or c == "?" then
- eventTextAreaCallback(nil,n,"info." .. mode.signal.sys[2])
- elseif c == "skip" and _G.currentTime > 8 and not mode.signal.possible and not mode.signal.info[n].skipped and mode.signal.isGeneratedMap then
- mode.signal.skip = mode.signal.skip + 1
- tfm.exec.chatMessage(system.getTranslation("skipped"),n)
- local alive,total = system.players()
- if mode.signal.skip == mathceil(.5 * total) then
- tfm.exec.chatMessage("o/")
- mode.signal.loadMap()
- end
- end
- end,
- -- PlayerWon
- eventPlayerWon = function(n)
- mode.signal.possible = true
- mode.signal.info[n].canRev = false
- tfm.exec.setGameTime(40,false)
- 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
- tfm.exec.snow(0)
- 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 ]]--
- --[[ eventLoop ]]--
- events.eventLoop = function(currentTime,leftTime)
- _G.currentTime = normalizeTime(currentTime / 1e3)
- _G.leftTime = normalizeTime(leftTime / 1e3)
- end
- --[[ eventNewPlayer ]]--
- events.eventNewPlayer = function(n)
- tfm.exec.lowerSyncDelay(n)
- if system.officialMode[2] ~= "" then
- tfm.exec.chatMessage(system.officialMode[2],n)
- end
- if system.playerMessage ~= "" then
- tfm.exec.chatMessage("<J>" .. system.playerMessage,n)
- end
- end
- --[[ eventChatCommand ]]--
- events.eventChatCommand = function(n,c)
- if system.isPlayer(n) then
- system.disableChatCommandDisplay(c,true)
- local p = stringsplit(c,"[^%s]+",stringlower)
- disableChatCommand(p[1])
- if module._FREEACCESS[n] then
- if p[1] == "refresh" and (module._FREEACCESS[n] > 1 or not system.isRoom) then
- eventModeChanged()
- system.init(true)
- return
- end
- if p[1] == "room" and (module._FREEACCESS[n] > 1 or not system.isRoom) then
- local room = tonumber(p[2]) or 0
- if _G["eventChatCommand"] and system.roomNumber ~= room then
- system.roomNumber = room
- eventChatCommand(n,"refresh")
- end
- return
- end
- if p[1] == "setmisc" and p[2] and (module._FREEACCESS[n] > 1 or not system.isRoom) then
- system.miscAttrib = tonumber(p[2]) or 0
- system.miscAttrib = mathsetLim(system.miscAttrib,0,99)
- if p[3] == "true" then
- eventChatCommand(n,"refresh")
- end
- return
- end
- if p[1] == "load" and (module._FREEACCESS[n] > 2 or not system.isRoom) then
- if os.time() > system.modeChanged and os.time() > system.newGameTimer then
- if system.getGameMode(p[2],true) then
- system.init(system.isRoom)
- end
- end
- return
- end
- end
- if p[1] == "module" then
- p[2] = stringupper(p[2] or "")
- if module["_" .. p[2]] then
- if p[2] == "FREEACCESS" then
- if p[3] then
- p[3] = stringnick(p[3])
- tfm.exec.chatMessage(p[3] .. " ~> " .. (module._FREEACCESS[p[3]] or 0),n)
- else
- tfm.exec.chatMessage(p[2] .. " : ",n)
- for k,v in pairsByIndexes(module._FREEACCESS,function(a,b) return module._FREEACCESS[a] > module._FREEACCESS[b] end) do
- tfm.exec.chatMessage(stringformat("%s ~> %s",k,v),n)
- end
- end
- else
- tfm.exec.chatMessage(p[2] .. " : " .. tableconcat(tableturnTable(module["_" .. p[2]]),"\n",function(k,v)
- return v
- end),n)
- end
- 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
- return
- end
- if p[1] == "modes" then
- tfm.exec.chatMessage(tableconcat({tableunpack(system.submodes,2)},"\n",function(k,v)
- return stringformat("~> /room #%s%s@%s#%s",module._NAME,mathrandom(0,999),n,v)
- end),n)
- return
- end
- if p[1] == "stop" and system.roomAdmins[n] then
- system.exit()
- end
- if p[1] == "admin" then
- tfm.exec.chatMessage(tableconcat(system.roomAdmins,", ",tostring),n)
- return
- end
- if p[1] == "adm" and p[2] and (system.roomAdmins[n] or (module._FREEACCESS[n] and module._FREEACCESS[n] > 2)) then
- if tablefind({"true","false"},p[3]) then
- local pl = stringnick(p[2])
- system.roomAdmins[pl] = (module._FREEACCESS[pl] and true) or p[3] == "true" or nil
- end
- return
- end
- if p[1] == "setroomlanguage" and p[2] and (system.roomAdmins[n] or (module._FREEACCESS[n] and module._FREEACCESS[n] > 2)) then
- if mode[system.gameMode].translations[p[2]] then
- system.roomLanguage = p[2]
- mode[system.gameMode].langue = system.roomLanguage
- end
- return
- end
- if p[1] == "me" then
- local commands = {
- [0] = {},
- [1] = {"!refresh (tribe house)","!setMisc [number] [refresh] (tribe house)","!room [number] (tribe house)","!load [mode] (tribe house)"},
- [2] = {"!refresh","!setMisc [number] [refresh]","!room [number]","!load [mode] (tribe house)"},
- [3] = {"!refresh","!setMisc [number] [refresh]","!room [number]","!load [mode]"}
- }
- local access = module._FREEACCESS[n] or 0
- if system.roomAdmins[n] then
- for k,v in next,{"!stop","!adm [playerName] [true/false]","!setRoomLanguage [language]"} do
- commands[access][#commands[access] + 1] = v
- end
- end
- 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)
- return
- end
- end
- end
- --[[ RoomSettings ]]--
- system.roomSettings = {
- -- 0 = Only the first value
- -- 1 = All the text
- ["@"] = {0,function(n)
- if n and #n > 2 then
- system.roomAdmins[stringnick(n)] = true
- end
- end},
- ["*"] = {0,function(id)
- system.miscAttrib = tonumber(id) or 1
- system.miscAttrib = mathsetLim(system.miscAttrib,1,99)
- end},
- ["#"] = {0,function(name)
- if name then
- local game = system.getGameMode(name)
- if not game then
- system.gameMode = module._NAME
- end
- end
- end},
- [":"] = {1,function(text)
- if text and #text > 0 then
- system.playerMessage = stringsub(text,1,40)
- end
- end},
- ["!"] = {0,function(langue)
- if langue and #langue > 0 then
- system.roomLanguage = stringlower(langue)
- 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
- for k,v in next,system.roomSettings do
- if k == char then
- v[2](v[1] == 0 and stringmatch(value,"[^%s]+") or 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(stringlower(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
- normalizeTranslation()
- mode[system.gameMode].init()
- if _G["eventNewPlayer"] then
- tableforeach(tfm.get.room.playerList,eventNewPlayer)
- end
- end
- system.init()
Add Comment
Please, Sign In to add comment