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
- })
- --[[ File Modules Aqui doesn't exist. ]]--
- --[[ 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