Advertisement
Bolodefchoco_LUAXML

[Script] Solar System

Apr 27th, 2017
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 89.33 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 06/02/2017
  3. --Last update: 06/08/2017
  4.  
  5. --[[ Module ]]--
  6. local module = {
  7.     _VERSION = "3.8",
  8.     _NAME = "universe",
  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. table.concat = 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 string.sub(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 or -1
  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(string.sub(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 = string.byte(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 = string.match(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 string.sub(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 string.gmatch(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 = string.format("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(string.gsub(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. math.isNegative = function(x,iN,iP)
  258.     iN = iN == nil and x or iN
  259.     iP = iP == nil and x or iP
  260.     return (x<0 and iN or iP)
  261. end
  262. math.percent = function(x,y,v)
  263.     v = (v or 100)
  264.     local m = x/y * v
  265.     return math.min(m,v)
  266. end
  267. math.pythag = function(x1,y1,x2,y2,range)
  268.     return (x1-x2)^2 + (y1-y2)^2 <= (range^2)
  269. end
  270. math.setLim = function(value,min,max)
  271.     return math.max(min,math.min(max,value))
  272. end
  273.  
  274.     -- String
  275. string.split = function(value,pattern,f)
  276.     local out = {}
  277.     for v in string.gmatch(value,pattern) do
  278.         out[#out + 1] = (f and f(v) or v)
  279.     end
  280.     return out
  281. end
  282. string.nick = function(player)
  283.     return string.gsub(string.lower(player),"%a",string.upper,1)
  284. end
  285.  
  286.     -- Table
  287. table.find = function(list,value,index,f)
  288.     for k,v in next,list do
  289.         local i = (type(v) == "table" and index and v[index] or v)
  290.         if (f and f(i) or i) == value then
  291.             return true,k
  292.         end
  293.     end
  294.     return false,0
  295. end
  296. table.turnTable = function(x)
  297.     return (type(x)=="table" and x or {x})
  298. end
  299. table.random = function(t)
  300.     return (type(t) == "table" and t[math.random(#t)] or math.random())
  301. end
  302. table.shuffle = function(t)
  303.     local randomized = {}
  304.     for v = 1,#t do
  305.         table.insert(randomized,math.random(#randomized),t[v])
  306.     end
  307.     return randomized
  308. end
  309.  
  310.     -- Others
  311. deactivateAccents=function(str)
  312.     local letters = {a = {"á","â","à","Ã¥","ã","ä"},e = {"é","ê","è","ë"},i = {"í","î","ì","ï"},o = {"ó","ô","ò","õ","ö"},u = {"ú","û","ù","ü"}}
  313.     for k,v in next,letters do
  314.         for i = 1,#v do
  315.             str = string.gsub(str,v[i],tostring(k))
  316.         end
  317.     end
  318.     return str
  319. end
  320. normalizeTime = function(time)
  321.     return math.floor(time) + ((time - math.floor(time)) >= .5 and .5 or 0)
  322. end
  323. disableChatCommand = function(command)
  324.     system.disableChatCommandDisplay(command,true)
  325.     system.disableChatCommandDisplay(string.lower(command),true)
  326.     system.disableChatCommandDisplay(string.upper(command),true)
  327. end
  328. normalizeTranslation = function()
  329.     local t = mode[system.gameMode].translations
  330.  
  331.     for k,v in next,t.en do
  332.         for i,j in next,t do
  333.             if i ~= "en" then
  334.                 if not j[k] then
  335.                     j[k] = v
  336.                 end
  337.             end
  338.         end
  339.     end
  340. end
  341. normalizeNumber = function(number)
  342.     number = tostring(math.floor(number))
  343.     number = string.gsub(number,"E(%d+)",function(cn) -- e5 = 00000
  344.         return string.rep("0",tonumber(cn))
  345.     end)
  346.     number = string.gsub(string.reverse(number),"(...)",function(c)
  347.         return c .. " "
  348.     end)
  349.     return string.reverse(number)
  350. end
  351.  
  352.     -- XML Dealer
  353. xml = {}
  354. xml.parse = function(currentXml)
  355.     currentXml = string.match(currentXml,"<P (.-)/>") or ""
  356.     local out = {}
  357.     for tag,_,value in string.gmatch(currentXml,"([%-%w]+)=([\"'])(.-)%2") do
  358.         out[tag] = value
  359.     end
  360.     return out
  361. end
  362. xml.attribFunc = function(currentXml,funcs)
  363.     local attributes = xml.parse(currentXml)
  364.     for k,v in next,funcs do
  365.         if attributes[v.attribute] then
  366.             v.func(attributes[v.attribute])
  367.         end
  368.     end
  369. end
  370. xml.addAttrib = function(currentXml,out,launch)
  371.     local parameters = string.match(currentXml,"<P (.-)/>") or ""
  372.     for k,v in next,out do
  373.         if not string.find(parameters,v.tag) then
  374.             currentXml = string.gsub(currentXml,"<P (.-)/>",function(attribs)
  375.                 return string.format("<P %s=\"%s\" %s/>",v.tag,v.value,attribs)
  376.             end)
  377.         end
  378.     end
  379.     if launch then
  380.         tfm.exec.newGame(currentXml)
  381.     else
  382.         return currentXml
  383.     end
  384. end
  385. xml.getCoordinates = function(s)
  386.     if string.find(s,";") then
  387.         local x,y
  388.         local axis,value = string.match(s,"(%a);(%d+)")
  389.         value = tonumber(value)
  390.         if value then
  391.             if axis == "x" then x = value else y = value end
  392.         end
  393.         return x or 0,y or 0
  394.     else
  395.         local pos = {}
  396.         for x,y in string.gmatch(s,"(%d+) ?, ?(%d+)") do
  397.             pos[#pos+1] = {x = x,y = y}
  398.         end
  399.         return pos
  400.     end
  401. end
  402.  
  403.     -- Colors
  404. color = {
  405.     hexToRgb = function(hex)
  406.         local h = string.format("%06x",hex)
  407.         return tonumber("0x"..string.sub(h,1,2)),tonumber("0x"..string.sub(h,3,4)),tonumber("0x"..string.sub(h,5,6))
  408.     end,
  409.     rgbToHsl = function(r,g,b)
  410.         r,g,b = r/255,g/255,b/255
  411.  
  412.         local max,min = math.max(r,g,b),math.min(r,g,b)
  413.         local h,s,l
  414.  
  415.         h = (max + min) / 2
  416.         s,l = h,h
  417.  
  418.         if max == min then
  419.             h,s = 0,0
  420.         else
  421.             local d = max - min
  422.            
  423.             local s = l > .5 and (d/(2 - max - min)) or (d/(max + min))
  424.            
  425.             if max == r then
  426.                 h = (g-b)/d
  427.                 if g < b then
  428.                     h = h + 6
  429.                 end
  430.             elseif max == g then
  431.                 h = (b-r)/d + 2
  432.             elseif max == b then
  433.                 h = (r-g)/d + 4
  434.             end
  435.             h = h/6
  436.         end
  437.  
  438.         return {h=h,s=s,l=l}
  439.     end,
  440.     hslToRgb = function(h,s,l,a)
  441.         local r,g,b
  442.  
  443.         if s == 0 then
  444.             r,g,b = l,l,l
  445.         else
  446.             local hueToRgb = function(p,q,t)
  447.                 if t < 0 then
  448.                     t = t + 1
  449.                 end
  450.                 if t > 1 then
  451.                     t = t - 1
  452.                 end
  453.                 if t < 1/6 then
  454.                     return p + (q - p) * 6 * t
  455.                 end
  456.                 if t < 1/2 then
  457.                     return q
  458.                 end
  459.                 if t < 2/3 then
  460.                     return p + (q - p) * (2/3 - t) * 6
  461.                 end
  462.                 return p
  463.             end
  464.  
  465.             local q = l < .5 and (l * (1 + s)) or (l + s - l * s)
  466.             local p = 2 * l - q
  467.  
  468.             r = hueToRgb(p,q,h + 1/3)
  469.             g = hueToRgb(p,q,h)
  470.             b = hueToRgb(p,q,h - 1/3)
  471.         end
  472.  
  473.         return r * 255,g * 255,b * 255
  474.     end,
  475.     rgbToHex = function(r,g,b)
  476.         return tonumber(string.format('%02x%02x%02x',r,g,b),16)
  477.     end,
  478.     YELLOW = 0xF9EC27,
  479.     RED = 0xF94226,
  480.     LIGHT_RED = 0xD1605D,
  481.     BLUE = 0x34A4E5,
  482.     DEEP_BLUE = 0x4F7F9A,
  483.     DARK_BLUE = 0x2D80AF,
  484.     GRAY = 0x969696,
  485.     SALMON = 0xAC6C64,
  486.     BROWN = 0x89635A,
  487.     BEIGE = 0x937A53,
  488.     TURQUOISE = 0x59D1C8,
  489.     ROSE = 0x816669,
  490.     MOSS_GREEN = 0x689636,
  491. }
  492.  
  493. --[[ GameMode ]]--
  494. system.submodes = {}
  495.  
  496. system.gameMode = module._NAME
  497. system.modeChanged = os.time() + 10e3
  498.  
  499. system.getGameMode = function(value,notFirst)
  500.     local found,submode = tablefind(system.submodes,stringlower(value),nil,stringlower)
  501.     if found then
  502.         system.gameMode = system.submodes[submode]
  503.        
  504.         if notFirst then
  505.             eventModeChanged()
  506.         end
  507.        
  508.         system.modeChanged = os.time() + 10e3
  509.     end
  510.     return found
  511. end
  512.  
  513. --[[ Modes ]]--
  514. mode = setmetatable({},{
  515.     __newindex = function(list,key,value)
  516.         rawset(list,key,value)
  517.         system.submodes[#system.submodes+1] = key
  518.     end
  519. })
  520.  
  521. --[[ Universe ]]--
  522. mode.universe = {
  523.     -- Translations
  524.     translations = {
  525.         en = {
  526.             -- Init
  527.             welcome = "Welcome to <font color='#BD5DC5'><B>#Universe</B></font>. Build your own solar system or just enjoy the art.\n\tReport bugs to Bolodefchoco.",
  528.             creator = "Now you are the creator of the universe! Press <B>O</B> and build it all!",
  529.            
  530.             -- Data
  531.             objects = {
  532.                 star = {
  533.                     "Yellow Dwarf",
  534.                     "Red Dwarf",
  535.                     "Red Giant",
  536.                     "Blue Giant",
  537.                     "Supergiant",
  538.                     "White Dwarf",
  539.                     "Brown Dwarf",
  540.                 },
  541.                 planet = {
  542.                     "Chthonian",
  543.                     "Gas Dwarf",
  544.                     "Gas Giant",
  545.                     "Ice Giant",
  546.                     "Iron",
  547.                     "Sillicate",
  548.                     "Telluric",
  549.                     "Dwarf",
  550.                 },
  551.                 moon = {
  552.                     "Asteroid",
  553.                     "Irregular Asteroid",
  554.                 },
  555.             },
  556.             menu = {
  557.                 class = "Class",
  558.                 type = "Type",
  559.                 name = "Name",
  560.                 color = "Color",
  561.                 size = "Size",
  562.                 temperature = "Temperature",
  563.                 satellite = "Satellite of",
  564.                 velocity = "Velocity",
  565.                 distance = "Distance",
  566.                 rings = "Rings",
  567.                 gravity = "Gravity",
  568.                 mass = "Mass",
  569.                 flow = "Flow",
  570.                 luminosity = "Luminosity",
  571.                 magnitude = "Magnitude",
  572.                 rotation = "Rotation",
  573.                 translation = "Translation",
  574.             },
  575.            
  576.             -- Interface
  577.             buttons = {
  578.                 keyboard = {
  579.                     "submit",
  580.                     "backspace",
  581.                     "clear"
  582.                 },
  583.                 classes = {
  584.                     "Star",
  585.                     "Planet",
  586.                     "Moon"
  587.                 },
  588.                 main = {
  589.                     create = "Create",
  590.                     reset = "Reset",
  591.                     destroy = "Destroy",
  592.                     recreate = "Recreate",
  593.                 },
  594.             },
  595.             color = {
  596.                 previous = "Previous Color",
  597.                 next = "Next Color"
  598.             },
  599.             profile = {
  600.                 profiles = "profiles",
  601.                 exTime = "Existence Time",
  602.                 information = "Information",
  603.                 main = "Main",
  604.                 planets = "Planets",
  605.                 life = "Life",
  606.                 periods = "Periods",
  607.                 orbit = "Orbit",
  608.                 satellites = "Satellites",
  609.             },
  610.             exit = "Exit",
  611.             choose = "Choose",
  612.             yes = "Yes",
  613.             no = "No",
  614.            
  615.             -- Warning
  616.             newObject = {
  617.                 "New <B>%s star</B> created!",
  618.                 "New <B>%s planet</B> created!",
  619.                 "New <B>%s moon</B> orbiting %s!",
  620.             },
  621.             checkProfile = "Check its profile using the command <B>!profile %s</B>",
  622.             fail = "The attributes %s are invalid!",
  623.             nameExist = "There's already an object named \"%s\"!",
  624.             destroyConfirm = "Are you sure you want to delete the %s \"%s\"?",
  625.             cantDestroy = "You cannot destroy this object!",
  626.             moonDestroyed = "All the moons of this planet were destroyed too!",
  627.             systemDestroyed = "This Solar System was destroyed!",
  628.             moonRecreated = "The moons of this planet were recreated!",
  629.             planetRecreated = "The planet which the recreated moon orbits was also recreated (also the other moons, if exists)!",
  630.             systemRecreated = "The System was recreated!",
  631.             sysName = {
  632.                 choose = "Set below a name for the Solar System. (20- characters)",
  633.                 new = "This Solar System has been renamed to \"%s\"! \o/",
  634.             },
  635.         },
  636.         br = {
  637.             welcome = "Bem-vindo ao <font color='#BD5DC5'><B>#Universe</B></font>. Construa seu próprio sistema solar or apenas aproveite a arte.\n\tReporte bugs a Bolodefchoco.",
  638.             creator = "Agora você é o criador do universo! Pressione <B>O</B> e construa isso tudo!",
  639.        
  640.             objects = {
  641.                 star = {
  642.                     "Anã Amarela",
  643.                     "Anã Vermelha",
  644.                     "Gigante Vermelha",
  645.                     "Gigante Azul",
  646.                     "Super Gigante",
  647.                     "Anã Branca",
  648.                     "Anã Marrom",
  649.                 },
  650.                 planet = {
  651.                     "Ctoniano",
  652.                     "Anão Gasoso",
  653.                     "Gigante Gasoso",
  654.                     "Gigante Gelado",
  655.                     "Ferro",
  656.                     "Silicato",
  657.                     "Telúrico",
  658.                     "Anão",
  659.                 },
  660.                 moon = {
  661.                     "Asteróide",
  662.                     "Asteróide Irregular",
  663.                 },
  664.             },
  665.             menu = {
  666.                 class = "Classe",
  667.                 type = "Tipo",
  668.                 name = "Nome",
  669.                 color = "Cor",
  670.                 size = "Tamanho",
  671.                 temperature = "Temperatura",
  672.                 satellite = "Satélite de",
  673.                 velocity = "Velocidade",
  674.                 distance = "Distância",
  675.                 rings = "Anéis",
  676.                 gravity = "Gravidade",
  677.                 mass = "Massa",
  678.                 flow = "Fluxo",
  679.                 luminosity = "Luminosidade",
  680.                 magnitude = "Magnitude",
  681.                 rotation = "Rotação",
  682.                 translation = "Translação",
  683.             },
  684.        
  685.             buttons = {
  686.                 keyboard = {
  687.                     "enviar",
  688.                     "apagar",
  689.                     "limpar"
  690.                 },
  691.                 classes = {
  692.                     "Estrela",
  693.                     "Planeta",
  694.                     "Lua"
  695.                 },
  696.                 main = {
  697.                     create = "Criar",
  698.                     reset = "Resetar",
  699.                     destroy = "Destruir",
  700.                     recreate = "Recriar",
  701.                 },
  702.             },
  703.             color = {
  704.                 previous = "Cor Anterior",
  705.                 next = "Próxima Cor"
  706.             },
  707.             profile = {
  708.                 profiles = "perfis",
  709.                 exTime = "Tempo de Existência",
  710.                 information = "Informação",
  711.                 main = "Principal",
  712.                 planets = "Planetas",
  713.                 life = "Vida",
  714.                 periods = "Período",
  715.                 orbit = "Órbita",
  716.                 satellites = "Satélites",
  717.             },
  718.             exit = "Sair",
  719.             choose = "Escolher",
  720.             yes = "Sim",
  721.             no = "Não",
  722.            
  723.             newObject = {
  724.                 "Nova <B>%s estrela</B> criada!",
  725.                 "Novo <B>%s planeta</B> criado!",
  726.                 "Nova <B>%s lua</B> orbitando %s!",
  727.             },
  728.             checkProfile = "Cheque seu perfil usando o comando <B>!profile %s</B>",
  729.             fail = "Os atributos %s são inválidos!",
  730.             nameExist = "Já existe um objeto nomeado \"%s\"!",
  731.             destroyConfirm = "Você tem certeza de que quer destruir a/o %s \"%s\"?",
  732.             cantDestroy = "Você não pode destruir este objeto!",
  733.             systemDestroyed = "Este Sistema Solar foi destruido!",
  734.             moonRecreated = "As luas deste planeta foram recriadas!",
  735.             planetRecreated = "O planeta do qual a lua recriada orbita também foi recriado (também as outras luas, se existirem)!",
  736.             systemRecreated = "O Sistema foi recriado!",
  737.             sysName = {
  738.                 choose = "Defina abaixo um nome para o Sistema Solar. (20- caracteres)",
  739.                 new = "Este Sistema Solar foi renomeado para \"%s\"! \o/",
  740.             },
  741.         },
  742.     },
  743.     langue = "en",
  744.     -- Data
  745.     info = {},
  746.     cosmos = {}, -- Objects
  747.     stuff = {},
  748.     orbit = {0,0,0,0}, -- All Stars, All Planets, All Moons, All Objects
  749.     star = false, -- Exist main star
  750.     tab = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;",
  751.     systemName = "Solar System",
  752.     images = {
  753.         background = {"15db9f4a44f","15db9f50264","15db9f54ea6","15db9f59aad","15db9f5efb4","15db9f64e66","15db9f6a13a","15db9f6ef03","15db9f7421f","15db9f7aaa8","15db9f80f07","15db9f87630","15db9f8d13b","15db9f93278","15db9f98bca","15db9f9d34d","15db9fa1d2f","15db9fa7ad3","15db9fae62e","15db9fb676f","15db9fbbdd5","15db9fc1b41","15db9fc709d","15db9fcc98d","15db9fd2208","15db9fd7961","15db9fde6ff","15db9fe6bb8","15db9fec6fa","15db9ff2ba4","15db9ff8560","15db9ffe293","15dba00379e","15dba008b05","15dba00f91c","15dba015ac7","15dba01a707","15dba01f8b7","15dba024274","15dba029d5b","15dba02d979","15dba032a4f","15dba0385b5","15dba03e3fc","15dba0424ef","15dba048372","15dba04cb9a","15dba04fd20","15dba053be1","15dba058fb2","15dba05d5ce","15dba063b0e","15dba06a0c7","15dba070036","15dba074e9d","15dba0799df","15dba07e421","15dba083354","15dba087775","15dba08bbba","15dba0914fd","15dba096cb2","15dba09c513","15dba0a1d3e"},
  754.         ufos = {"15dbf1c1b08","15dbf1c6f9d","15dbf1cb752","15dbf20a2c1","15dbf20e553"},
  755.     },
  756.     -- New Game Settings
  757.     canInsertBackground = false,
  758.     -- Other settings
  759.     ufoId = -1,
  760.     -- Objects
  761.     data = {
  762.         objects = {
  763.             star = {
  764.                 --[[
  765.                     Name;
  766.                     Color accuracy;
  767.                     Size range
  768.                 ]]
  769.                 {"Yellow Dwarf",{color.YELLOW},"40:100"},
  770.                 {"Red Dwarf",{color.RED},"40:100"},
  771.                 {"Red Giant",{color.RED},"80:160"},
  772.                 {"Blue Giant",{color.BLUE},"80:160"},
  773.                 {"Supergiant",{color.YELLOW,color.RED,color.BLUE},"80:160"},
  774.                 {"White Dwarf",{color.GRAY},"30:60"},
  775.                 {"Brown Dwarf",{color.BROWN},"30:60"},
  776.             },
  777.             planet = {
  778.                 --[[
  779.                     Name;
  780.                     Color accuracy;
  781.                     Size range;
  782.                     Lifeable;
  783.                     Queue Limit (where positive = not > x ; negative = not < abs(x) and 0 is free)
  784.                 ]]
  785.                 {"Chthonian",{color.BROWN,color.TURQUOISE,color.BEIGE},"15:35",false,2},
  786.                 {"Gas Dwarf",{color.GRAY,color.BEIGE,color.TURQUOISE,color.LIGHT_RED},"20:30",false,-2},
  787.                 {"Gas Giant",{color.GRAY,color.BEIGE,color.TURQUOISE,color.LIGHT_RED},"25:60",false,-2},
  788.                 {"Ice Giant",{color.DEEP_BLUE,color.TURQUOISE,color.DARK_BLUE},"20:45",false,-3},
  789.                 {"Iron",{color.GRAY,color.BEIGE,color.ROSE},"15:25",true,0},
  790.                 {"Sillicate",{color.BEIGE,color.ROSE,color.MOSS_GREEN,color.DARK_BLUE},"20:30",true,0},
  791.                 {"Telluric",{color.BEIGE,color.ROSE,color.MOSS_GREEN,color.DARK_BLUE},"15:35",true,0},
  792.                 {"Dwarf",{color.GRAY,color.BEIGE},"5:12",true,-1},             
  793.             },
  794.             moon = {
  795.                 --[[
  796.                     Name;
  797.                     Color accuracy;
  798.                     Size range
  799.                 ]]
  800.                 {"Asteroid",{color.GRAY},"5:8"},
  801.                 {"Irregular Asteroid",{color.GRAY,color.BEIGE},"2:6"},
  802.             },
  803.         },
  804.         classes = {
  805.        
  806.         },
  807.         menu = {
  808.  
  809.         },
  810.     },
  811.     -- Meta
  812.     meta = {
  813.         add = {
  814.             __add = function(listOne,listTwo) -- Link two tables in one
  815.                 local out = {}
  816.                 for k,v in next,{listOne,listTwo} do
  817.                     for i,j in next,v do
  818.                         out[(type(i) == "string" and i or #out+1)] = j
  819.                     end
  820.                 end
  821.                
  822.                 return setmetatable(out,getmetatable(listOne))
  823.             end
  824.         },
  825.     },
  826.     -- Keyboard system
  827.     keyboard = function()
  828.         local k = ""
  829.         local key = "<a href='event:keyboard.@.insert.%s'>%s</a> "
  830.         for i = string.byte("A"),string.byte("Z") do -- Letters
  831.             k = k .. string.format(key,i,string.char(i))
  832.         end
  833.        
  834.         k = k .. "\n"
  835.        
  836.         for i = string.byte("0"),string.byte("9") do -- Numbers
  837.             k = k .. string.format(key,i,string.char(i))
  838.         end
  839.        
  840.         k = k .. "\n"
  841.        
  842.         for i,j in next,{string.byte("-_",1,2)} do -- Characters
  843.             k = k .. string.format(key,j,string.char(j))
  844.         end
  845.    
  846.         return k
  847.     end,
  848.     -- Monochromatic System
  849.     paletteMonochromatic = function(hex,amount,period,reversed)
  850.         local hsl = color.rgbToHsl(color.hexToRgb(hex))
  851.        
  852.         local colors = {}
  853.        
  854.         local final = 1
  855.         if reversed then
  856.             final = hsl.l - amount
  857.             period = -period
  858.         end
  859.        
  860.         for i = hsl.l,final,period do
  861.             colors[#colors+1] = color.rgbToHex(color.hslToRgb(hsl.h,hsl.s,i))
  862.            
  863.             amount = amount - 1
  864.             if amount == 0 then
  865.                 break
  866.             end
  867.         end
  868.        
  869.         if reversed then
  870.             table.remove(colors,1)
  871.         end
  872.        
  873.         return colors
  874.     end,
  875.     -- UI
  876.     uinew = function(id,text,player,x,y,w,h,hasBg,color)
  877.         w,h = w or 100,h or 100
  878.         x,y = ((x or 400) - (w/2)),((y or 400) - (h/2))
  879.  
  880.         id = id>0 and id*5 or id
  881.         if hasBg then
  882.             ui.addTextArea(id,"",player,5,5,790,400,1,1,.5,true)
  883.         end
  884.  
  885.         ui.addTextArea(id+1,"",player,x,y,w,h,0x0C191C,0x0C191C,1,true)
  886.         ui.addTextArea(id+2,"",player,x+1,y+1,w-2,h-2,0x24474D,0x24474D,1,true)
  887.         ui.addTextArea(id+3,"",player,x+2,y+2,w-4,h-4,0x183337,0x183337,1,true)
  888.         ui.addTextArea(id+4,text,player,x+2,y+3,w-4,h-5,color or 0x122528,color or 0x122528,1,true)
  889.     end,
  890.     uiremove = function(id,player)
  891.         id = id>0 and id*5 or id
  892.         for i = id + 4,id,-1 do
  893.             ui.removeTextArea(i,player)
  894.         end
  895.     end,
  896.     -- UI Colors
  897.     uipaletteMono = function(hex,n)
  898.         mode.universe.info[n].settings.palette[1] = mode.universe.info[n].settings.palette[1] < 1 and #hex or mode.universe.info[n].settings.palette[1] > #hex and 1 or mode.universe.info[n].settings.palette[1]
  899.  
  900.         local darker = mode.universe.paletteMonochromatic(hex[mode.universe.info[n].settings.palette[1]],5,0.07,true)
  901.         local lighter = mode.universe.paletteMonochromatic(hex[mode.universe.info[n].settings.palette[1]],5,0.07,false)
  902.  
  903.         local colors = setmetatable(darker,mode.universe.meta.add)
  904.         colors = colors + lighter
  905.         table.sort(colors)
  906.  
  907.         local div = mode.universe.tab .. "<BL>|<V>" .. mode.universe.tab
  908.         mode.universe.uinew(10,string.format("<font size='11'><V><a href='event:palette.left'>« %s</a>%s<a href='event:palette.right'>%s »</a>%s<a href='event:palette.exit'>%s</a>",system.getTranslation("color.previous"),div,system.getTranslation("color.next"),div,system.getTranslation("exit")),n,400,200,450,80,true)
  909.         for i = 1,#colors do
  910.             local color = colors[i]
  911.             mode.universe.uinew(i + 10,color and ("<font size='7'>\n<p align='center'><font size='13' color='#"..string.format("%X",0xFFFFFF-color).."'><a href='event:item.color." .. color .. "'>â– </a>"),n,150 + (50*i) or "",215,40,40,false,color)
  912.         end
  913.     end,
  914.     -- UI Hrefs
  915.     uiitems = function(text,n,h)
  916.         mode.universe.uinew(10,text,n,400,200,180,h or 180,true)
  917.     end,
  918.     -- UI Keyboard
  919.     uikeyboard = function(id,str,n)
  920.         mode.universe.uinew(10,table.concat(system.getTranslation("buttons.keyboard"),"\n",function(k,v)
  921.             return string.format("<%s><a href='event:keyboard.%s.%s'>%s</a>",k==1 and "J" or "R",id,v,string.upper(v))
  922.         end) .. "\n\n<p align='center'><PT>" .. string.gsub(mode.universe.keyboard,"@",id) .. "\n\n<font size='15'><T>" .. table.concat(str),n,400,200,320,150,true)
  923.     end,
  924.     -- UI Conter
  925.     uicounter = function(id,range,n,limit,increment)
  926.         local min,max = string.match(range,"(%-?%d+):(%-?%d+)")
  927.         min,max = tonumber(min),tonumber(max)
  928.        
  929.         if mode.universe.info[n].settings[id][1] == -math.huge then
  930.             mode.universe.info[n].settings[id][1] = math.ceil((min+max)/2)
  931.         else
  932.             mode.universe.info[n].settings[id][1] = math.setLim(mode.universe.info[n].settings[id][1],min,max)
  933.         end
  934.        
  935.         limit = limit or 10
  936.         increment = string.gsub(tostring(increment or 1),"%.","%%s")
  937.         mode.universe.info[n].settings[id][2] = math.setLim(mode.universe.info[n].settings[id][2],.1,limit)
  938.  
  939.         mode.universe.uinew(10,"<p align='center'><font size='20'><V><B>"..string.upper(id).."</B><font size='7'>\n\n<font size='12'><p align='left'><J><a href='event:counter."..id..".submit'>SUBMIT</a>"..string.rep(mode.universe.tab,3).."<PT><a href='event:counter."..id..".add."..increment.."'><B>+</B></a>  <J>" .. mode.universe.info[n].settings[id][2] .. "  <R><a href='event:counter."..id..".sub."..increment.."'><B>-</B></a>\n\n\n<p align='center'><font size='16'><S><a href='event:item."..id..".add'>â–²</a>&nbsp;&nbsp;<PS>" ..  mode.universe.info[n].settings[id][1] .. "&nbsp;&nbsp;<S><a href='event:item."..id..".sub'>â–¼</a>",n,400,200,180,130,true)
  940.     end,
  941.     -- UI Close
  942.     uicloseSplash = function(n,close)
  943.         for i = 10,19 do
  944.             mode.universe.uiremove(i,n)
  945.         end
  946.        
  947.         if not close then
  948.             mode.universe.uicreator(n)
  949.         end
  950.     end,
  951.     -- UI Creator
  952.     uicreator = function(n)
  953.         mode.universe.uinew(0,table.concat(mode.universe.info[n].settings.create,"\n<font size='4'>\n</font>",function(k,v)
  954.             return string.format(v[1],tostring(v[2](n)))
  955.         end),n,400,200,540,300,true)
  956.        
  957.         mode.universe.uinew(1,"<p align='center'><VI><a href='event:main.create'>" .. system.getTranslation("buttons.main.create") .. "</a>",n,180,338,100,24,false)
  958.         mode.universe.uinew(2,"<p align='center'><VI><a href='event:main.recreate'>" .. system.getTranslation("buttons.main.recreate") .. "</a>",n,290,338,100,24,false)
  959.         mode.universe.uinew(3,"<p align='center'><R><a href='event:main.destroy'>" .. system.getTranslation("buttons.main.destroy") .. "</a>",n,400,338,100,24,false)
  960.         mode.universe.uinew(4,"<p align='center'><BV><a href='event:main.reset'>" .. system.getTranslation("buttons.main.reset") .. "</a>",n,510,338,100,24,false)
  961.         mode.universe.uinew(5,"<p align='center'><VP><a href='event:main.exit'>" .. system.getTranslation("exit") .. "</a>",n,620,338,100,24,false)
  962.         mode.universe.info[n].creatorOpen = true
  963.     end,
  964.     -- UI Clear Creator List
  965.     uiclearCreator = function(n,range)
  966.         for i = 1,#mode.universe.info[n].settings.create do
  967.             if i > (range or 1) then
  968.                 mode.universe.info[n].settings.create[i] = nil
  969.             end
  970.         end
  971.     end,
  972.     -- UI Clear Creator
  973.     uiresetCreator = function(n)
  974.         mode.universe.info[n].settings.palette = {1,{},1}
  975.         mode.universe.info[n].settings.size = {-math.huge,5}
  976.         mode.universe.info[n].settings.temperature = {-math.huge,5,true}
  977.         mode.universe.info[n].settings.velocity = {-math.huge,1,true}
  978.         mode.universe.info[n].settings.distance = {-math.huge,5,true}
  979.         mode.universe.info[n].settings.rings = false
  980.         mode.universe.info[n].settings.satellite = 0
  981.     end,
  982.     -- UI Menu Bar
  983.     infoBar =  function()
  984.         local out = {
  985.             {"<font color='#CF50DB'>%s",mode.universe.systemName},
  986.             {system.getTranslation("buttons.classes.1") .. " : <V>%s",mode.universe.orbit[1]},
  987.             {system.getTranslation("buttons.classes.2") .. " : <V>%s",mode.universe.orbit[2]},
  988.             {system.getTranslation("buttons.classes.3") .. " : <V>%s",mode.universe.orbit[3]},
  989.             {system.getTranslation("profile.exTime") .. " : <V>%s",(_G.currentTime / 25)},
  990.         }
  991.        
  992.         return table.concat(out,"   <G>|   <N>",function(k,v)
  993.             return string.format(v[1],v[2])
  994.         end) .. "<"
  995.     end,
  996.     -- Background
  997.     insertion = function(n)
  998.         local y = 0
  999.         for i = 0,63 do
  1000.             if i > 0 and i % 8 == 0 then
  1001.                 y = y + 1000
  1002.             end
  1003.             tfm.exec.addImage(mode.universe.images.background[i + 1] .. ".png","?" .. i,(i%8) * 1000,y,n)
  1004.  
  1005.             if i % 10 == 0 then
  1006.                 coroutine.yield()
  1007.             end
  1008.         end
  1009.         tfm.exec.addImage("15db9e67479.png","?64",3970,3973,n)
  1010.     end,
  1011.     setBackground = function(n)
  1012.         local timerId
  1013.         local insert = coroutine.create(mode.universe.insertion)
  1014.         timerId = system.newTimer(function()
  1015.             coroutine.resume(insert,n)
  1016.            
  1017.             if coroutine.status(insert) == "dead" then
  1018.                 system.removeTimer(timerId)
  1019.             end
  1020.         end,1000,true)
  1021.     end,
  1022.     -- Profiles
  1023.     profile = {
  1024.         uiprofile = function(n)
  1025.             mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(system.getTranslation("profile.profiles")) .. "</B><font size='12'>\n<a href='event:profile.exit'>" .. system.getTranslation("exit") .. "</a><p align='left'>\n\n<S>" .. table.concat(mode.universe.cosmos,"\n",function(k,v)
  1026.                 return string.format("%s <a href='event:profile.open.%s.%s'>%s</a>",(v.id == mode.universe.cosmos[1].id and "<a:active>★</a:active>" or "<CE>[" .. v.className .."]</CE>"),v.className,k,v.name)
  1027.             end),n,300)
  1028.         end,
  1029.         uiremoveprofile = function(n)
  1030.             for i = 1,41 do
  1031.                 ui.removeTextArea(-i,n)
  1032.             end
  1033.         end,
  1034.         profileStar = function(obj,n)
  1035.             mode.universe.profile.uiremoveprofile(n)
  1036.        
  1037.             obj = mode.universe.cosmos[tonumber(obj)]
  1038.  
  1039.             local objColor = string.upper(string.format("%x",obj.color))
  1040.            
  1041.             --tfm.exec.addImage("15d509ca726.png","?0",-110,-120,n)
  1042.            
  1043.             ui.addTextArea(-1,"",n,150,40,540,350,0x0F242E,0x0F242E,1,true)
  1044.  
  1045.             ui.addTextArea(-2,"",n,155,45,340,33,0x242F42,0x242F42,1,true)
  1046.             ui.addTextArea(-3,"<font size='16'><p align='center'><V>" .. (obj.id == mode.universe.cosmos[1].id and "<a:active>★</a:active>" or "") .. " <B>" .. obj.name .. "</B><font size='12'><p align='right'>\n<a href='event:profile.exit'>[" .. system.getTranslation("exit") .. "]</a>",n,158,42,340,45,1,1,0,true)
  1047.  
  1048.             ui.addTextArea(-4,"",n,170,127,122,23,0x242F42,0x242F42,1,true)
  1049.             ui.addTextArea(-5,"",n,180,100,102,20,0x242F42,0x242F42,1,true)
  1050.  
  1051.             ui.addTextArea(-6,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.class"),n,181,101,100,20,0x0F242E,0x0F242E,1,true)
  1052.             ui.addTextArea(-7,"<p align='center'><V>" .. obj.className,n,171,128,120,25,0x0F242E,0x0F242E,1,true)
  1053.  
  1054.             ui.addTextArea(-8,"",n,180,195,102,20,0x242F42,0x242F42,1,true)
  1055.             ui.addTextArea(-9,"",n,170,222,122,23,0x242F42,0x242F42,1,true)
  1056.  
  1057.             ui.addTextArea(-10,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.type"),n,181,196,100,20,0x0F242E,0x0F242E,1,true)
  1058.             ui.addTextArea(-11,"<p align='center'><V>" .. obj.typeName,n,171,223,120,25,0x0F242E,0x0F242E,1,true)
  1059.  
  1060.             ui.addTextArea(-12,"",n,180,305,102,20,0x242F42,0x242F42,1,true)
  1061.             ui.addTextArea(-13,"",n,170,332,122,23,0x242F42,0x242F42,1,true)
  1062.  
  1063.             ui.addTextArea(-14,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.exTime"),n,181,306,100,20,0x0F242E,0x0F242E,1,true)
  1064.             ui.addTextArea(-15,"<p align='center'><V>" .. obj.time / 1e7,n,171,333,120,25,0x0F242E,0x0F242E,1,true)
  1065.  
  1066.             ui.addTextArea(-16,"",n,360,100,102,20,0x242F42,0x242F42,1,true)
  1067.             ui.addTextArea(-17,"",n,350,127,122,143,0x242F42,0x242F42,1,true)
  1068.  
  1069.             ui.addTextArea(-18,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.information"),n,361,101,100,20,0x0F242E,0x0F242E,1,true)
  1070.             ui.addTextArea(-19,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.size") .. " : <V>" .. obj.size,n,351,128,120,20,0x0F242E,0x0F242E,1,true)
  1071.             ui.addTextArea(-20,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.color") .. " : <font color='#" ..  objColor.. "'>#" .. objColor,n,351,152,120,20,0x0F242E,0x0F242E,1,true)
  1072.             ui.addTextArea(-21,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.gravity") .. " : <V>" .. obj.gravity,n,351,177,120,20,0x0F242E,0x0F242E,1,true)
  1073.             ui.addTextArea(-22,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.mass") .. " : <V>" .. obj.mass / 1e8,n,351,202,120,20,0x0F242E,0x0F242E,1,true)
  1074.             ui.addTextArea(-23,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.temperature") .. " : <V>" .. obj.temperature .. "°C",n,351,227,120,20,0x0F242E,0x0F242E,1,true)
  1075.             ui.addTextArea(-24,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("profile.main") .. " : <V>" .. (obj.id == mode.universe.cosmos[1].id and system.getTranslation("yes") or system.getTranslation("no")),n,351,252,120,20,0x0F242E,0x0F242E,1,true)
  1076.  
  1077.             ui.addTextArea(-25,"",n,360,290,102,20,0x242F42,0x242F42,1,true)
  1078.             ui.addTextArea(-26,"",n,350,316,122,40,0x242F42,0x242F42,1,true)
  1079.  
  1080.             ui.addTextArea(-27,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.flow") .. " : <V>" .. obj.flow,n,361,291,100,20,0x0F242E,0x0F242E,1,true)
  1081.             ui.addTextArea(-28,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.luminosity") .. " : <V>" .. obj.luminosity,n,351,317,120,20,0x0F242E,0x0F242E,1,true)
  1082.             ui.addTextArea(-29,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.magnitude") .. " : <V>" .. obj.magnitude,n,351,342,120,20,0x0F242E,0x0F242E,1,true)
  1083.  
  1084.             ui.addTextArea(-30,"",n,550,46,102,20,0x242f42,0x242f42,1,true)
  1085.             ui.addTextArea(-31,"",n,540,72,122,288,0x242f42,0x242f42,1,true)
  1086.  
  1087.             ui.addTextArea(-32,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.planets"),n,551,47,100,20,0x0f242e,0x0f242e,1,true)
  1088.             ui.addTextArea(-33,"<p align='center'><V>" .. table.concat(mode.universe.cosmos,"",function(k,v)
  1089.                 return v.class == 2 and string.format("<a href='event:profile.open.Planet.%s'>%s</a>\n\n",k,v.name) or ""
  1090.             end),n,541,73,120,290,0x0f242e,0x0f242e,1,true)
  1091.         end,
  1092.         profilePlanet = function(obj,n)
  1093.             mode.universe.profile.uiremoveprofile(n)
  1094.            
  1095.             obj = mode.universe.cosmos[tonumber(obj)]
  1096.  
  1097.             local objColor = string.upper(string.format("%x",obj.color))
  1098.            
  1099.             --tfm.exec.addImage("15d509cc1ab.png","?0",-20,30,n)
  1100.            
  1101.             ui.addTextArea(-1,"",n,150,40,540,350,0x0F242E,0x0F242E,1,true)
  1102.  
  1103.             ui.addTextArea(-2,"",n,155,45,340,33,0x242F42,0x242F42,1,true)
  1104.             ui.addTextArea(-3,"<font size='16'><p align='center'><V><B>" .. obj.name .. "</B><font size='12'><p align='right'>\n<a href='event:profile.exit'>[" .. system.getTranslation("exit") .. "]</a>",n,158,42,340,45,1,1,0,true)
  1105.  
  1106.             ui.addTextArea(-4,"",n,180,100,102,20,0x242F42,0x242F42,1,true)
  1107.             ui.addTextArea(-5,"",n,170,127,122,23,0x242F42,0x242F42,1,true)
  1108.  
  1109.             ui.addTextArea(-6,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.class"),n,181,101,100,20,0x0F242E,0x0F242E,1,true)
  1110.             ui.addTextArea(-7,"<p align='center'><V>" .. obj.className,n,171,128,120,25,0x0F242E,0x0F242E,1,true)
  1111.  
  1112.             ui.addTextArea(-8,"",n,180,170,102,20,0x242F42,0x242F42,1,true)
  1113.             ui.addTextArea(-9,"",n,170,197,122,23,0x242F42,0x242F42,1,true)
  1114.  
  1115.             ui.addTextArea(-10,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.type"),n,181,171,100,20,0x0F242E,0x0F242E,1,true)
  1116.             ui.addTextArea(-11,"<p align='center'><V>" .. obj.typeName,n,171,198,120,25,0x0F242E,0x0F242E,1,true)
  1117.  
  1118.             ui.addTextArea(-12,"",n,180,240,102,20,0x242F42,0x242F42,1,true)
  1119.             ui.addTextArea(-13,"",n,170,267,122,23,0x242F42,0x242F42,1,true)
  1120.  
  1121.             ui.addTextArea(-14,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.life"),n,181,241,100,20,0x0F242E,0x0F242E,1,true)
  1122.             ui.addTextArea(-15,"<p align='center'><V>" .. obj.life .. "%",n,171,268,120,25,0x0F242E,0x0F242E,1,true)
  1123.  
  1124.             ui.addTextArea(-16,"",n,180,315,102,20,0x242F42,0x242F42,1,true)
  1125.             ui.addTextArea(-17,"",n,170,342,122,23,0x242F42,0x242F42,1,true)
  1126.  
  1127.             ui.addTextArea(-18,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.rings"),n,181,316,100,20,0x0F242E,0x0F242E,1,true)
  1128.             ui.addTextArea(-19,"<p align='center'><V>" .. (obj.rings and system.getTranslation("yes") or system.getTranslation("no")),n,171,343,120,25,0x0F242E,0x0F242E,1,true)
  1129.  
  1130.             ui.addTextArea(-20,"",n,360,100,102,20,0x242F42,0x242F42,1,true)
  1131.             ui.addTextArea(-21,"",n,350,127,122,143,0x242F42,0x242F42,1,true)
  1132.  
  1133.             ui.addTextArea(-22,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.information"),n,361,101,100,20,0x0F242E,0x0F242E,1,true)
  1134.             ui.addTextArea(-23,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.size") .. " : <V>" .. obj.size,n,351,128,120,20,0x0F242E,0x0F242E,1,true)
  1135.             ui.addTextArea(-24,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.color") .. " : <font color='#" ..  objColor.. "'>#" .. objColor,n,351,152,120,20,0x0F242E,0x0F242E,1,true)
  1136.             ui.addTextArea(-25,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.gravity") .. " : <V>" .. obj.gravity,n,351,177,120,20,0x0F242E,0x0F242E,1,true)
  1137.             ui.addTextArea(-26,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.mass") .. " : <V>" .. obj.mass / 1e8,n,351,202,120,20,0x0F242E,0x0F242E,1,true)
  1138.             ui.addTextArea(-27,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.temperature") .. " : <V>" .. obj.temperature .. "°C",n,351,227,120,20,0x0F242E,0x0F242E,1,true)
  1139.             ui.addTextArea(-28,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.velocity") .. " : <V>" .. obj.velocity,n,351,252,120,20,0x0F242E,0x0F242E,1,true)
  1140.  
  1141.             ui.addTextArea(-29,"",n,360,290,102,20,0x242F42,0x242F42,1,true)
  1142.             ui.addTextArea(-30,"",n,350,316,122,40,0x242F42,0x242F42,1,true)
  1143.  
  1144.             ui.addTextArea(-31,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.periods"),n,361,291,100,20,0x0F242E,0x0F242E,1,true)
  1145.             ui.addTextArea(-32,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.rotation") .. " : <V>" .. obj.period.rotation,n,351,317,120,20,0x0F242E,0x0F242E,1,true)
  1146.             ui.addTextArea(-33,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.translation") .. " : <V>" .. obj.period.translation / 1e10,n,351,342,120,20,0x0F242E,0x0F242E,1,true)
  1147.  
  1148.             ui.addTextArea(-34,"",n,550,41,102,20,0x242F42,0x242F42,1,true)
  1149.             ui.addTextArea(-35,"",n,540,67,122,23,0x242F42,0x242F42,1,true)
  1150.  
  1151.             ui.addTextArea(-36,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.orbit"),n,551,42,100,20,0x0F242E,0x0F242E,1,true)
  1152.             ui.addTextArea(-37,"<p align='center'><V>#" .. obj.planetPosition,n,541,68,120,25,0x0F242E,0x0F242E,1,true)
  1153.  
  1154.             ui.addTextArea(-38,"",n,550,116,102,20,0x242F42,0x242F42,1,true)
  1155.             ui.addTextArea(-39,"",n,540,142,122,214,0x242F42,0x242F42,1,true)
  1156.  
  1157.             ui.addTextArea(-40,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.satellites"),n,551,117,100,20,0x0F242E,0x0F242E,1,true)
  1158.             ui.addTextArea(-41,"<p align='center'><V>" .. table.concat(obj.moons,"",function(k,v)
  1159.                 return string.format("<a href='event:profile.open.Moon.%s'>%s</a>\n\n",mode.universe.cosmos[v].position,mode.universe.cosmos[v].name)
  1160.             end),n,541,143,120,216,0x0F242E,0x0F242E,1,true)
  1161.         end,
  1162.         profileMoon = function(obj,n)
  1163.             mode.universe.profile.uiremoveprofile(n)
  1164.            
  1165.             obj = mode.universe.cosmos[tonumber(obj)]
  1166.  
  1167.             local objColor = string.upper(string.format("%x",obj.color))
  1168.            
  1169.             --tfm.exec.addImage("15d41dcea87.png","?0",380,90,n)
  1170.            
  1171.             ui.addTextArea(-1,"",n,150,40,350,350,0x0F242E,0x0F242E,1,true)
  1172.  
  1173.             ui.addTextArea(-2,"",n,155,45,340,33,0x242F42,0x242F42,1,true)
  1174.             ui.addTextArea(-3,"<font size='16'><p align='center'><V><B>" .. obj.name .. "</B><font size='12'><p align='right'>\n<a href='event:profile.exit'>[" .. system.getTranslation("exit") .. "]</a>",n,158,42,340,45,1,1,0,true)
  1175.  
  1176.             ui.addTextArea(-4,"",n,170,127,122,23,0x242F42,0x242F42,1,true)
  1177.             ui.addTextArea(-5,"",n,180,100,102,20,0x242F42,0x242F42,1,true)
  1178.  
  1179.             ui.addTextArea(-6,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.class"),n,181,101,100,20,0x0F242E,0x0F242E,1,true)
  1180.             ui.addTextArea(-7,"<p align='center'><V>" .. obj.className,n,171,128,120,25,0x0F242E,0x0F242E,1,true)
  1181.  
  1182.             ui.addTextArea(-8,"",n,180,170,102,20,0x242F42,0x242F42,1,true)
  1183.             ui.addTextArea(-9,"",n,170,197,122,23,0x242F42,0x242F42,1,true)
  1184.  
  1185.             ui.addTextArea(-10,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.type"),n,181,171,100,20,0x0F242E,0x0F242E,1,true)
  1186.             ui.addTextArea(-11,"<p align='center'><V>" .. obj.typeName,n,171,198,120,25,0x0F242E,0x0F242E,1,true)
  1187.  
  1188.             ui.addTextArea(-12,"",n,180,240,102,20,0x242F42,0x242F42,1,true)
  1189.             ui.addTextArea(-13,"",n,170,267,122,23,0x242F42,0x242F42,1,true)
  1190.  
  1191.             ui.addTextArea(-14,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.life"),n,181,241,100,20,0x0F242E,0x0F242E,1,true)
  1192.             ui.addTextArea(-15,"<p align='center'><V>" .. obj.life .. "%",n,171,268,120,25,0x0F242E,0x0F242E,1,true)
  1193.  
  1194.             ui.addTextArea(-16,"",n,180,315,102,20,0x242F42,0x242F42,1,true)
  1195.             ui.addTextArea(-17,"",n,170,342,122,23,0x242F42,0x242F42,1,true)
  1196.  
  1197.             ui.addTextArea(-18,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("menu.satellite"),n,181,316,100,20,0x0F242E,0x0F242E,1,true)
  1198.             ui.addTextArea(-19,"<p align='center'><V><a href='event:profile.open.Planet." .. obj.satelliteOf .. "'>" .. mode.universe.cosmos[obj.satelliteOf].name,n,171,343,120,25,0x0F242E,0x0F242E,1,true)
  1199.  
  1200.             ui.addTextArea(-20,"",n,360,100,102,20,0x242F42,0x242F42,1,true)
  1201.             ui.addTextArea(-21,"",n,350,127,122,143,0x242F42,0x242F42,1,true)
  1202.  
  1203.             ui.addTextArea(-22,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.information"),n,361,101,100,20,0x0F242E,0x0F242E,1,true)
  1204.             ui.addTextArea(-23,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.size") .. " : <V>" .. obj.size,n,351,128,120,20,0x0F242E,0x0F242E,1,true)
  1205.             ui.addTextArea(-24,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.color") .. " : <font color='#" ..  objColor.. "'>#" .. objColor,n,351,152,120,20,0x0F242E,0x0F242E,1,true)
  1206.             ui.addTextArea(-25,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.gravity") .. " : <V>" .. obj.gravity,n,351,177,120,20,0x0F242E,0x0F242E,1,true)
  1207.             ui.addTextArea(-26,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.mass") .. " : <V>" .. obj.mass / 1e8,n,351,202,120,20,0x0F242E,0x0F242E,1,true)
  1208.             ui.addTextArea(-27,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.temperature") .. " : <V>" .. obj.temperature .. "°C",n,351,227,120,20,0x0F242E,0x0F242E,1,true)
  1209.             ui.addTextArea(-28,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.velocity") .. " : <V>" .. obj.velocity,n,351,252,120,20,0x0F242E,0x0F242E,1,true)
  1210.  
  1211.             ui.addTextArea(-29,"",n,360,290,102,20,0x242F42,0x242F42,1,true)
  1212.             ui.addTextArea(-30,"",n,350,316,122,40,0x242F42,0x242F42,1,true)
  1213.  
  1214.             ui.addTextArea(-31,"<p align='center'><font color='#32C3CC'>" .. system.getTranslation("profile.periods"),n,361,291,100,20,0x0F242E,0x0F242E,1,true)
  1215.             ui.addTextArea(-32,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.rotation") .. " : <V>" .. obj.period.rotation,n,351,317,120,20,0x0F242E,0x0F242E,1,true)
  1216.             ui.addTextArea(-33,"<p align='center'><font color='#31AAB2'>" .. system.getTranslation("menu.translation") .. " : <V>" .. obj.period.translation,n,351,342,120,20,0x0F242E,0x0F242E,1,true)
  1217.         end,
  1218.     },
  1219.     -- Get
  1220.     getID = coroutine.wrap(function(class)
  1221.         local id,i = 0
  1222.         while true do
  1223.             i = ({2,4,3})[class]
  1224.             class = coroutine.yield(id)
  1225.             id = id + i
  1226.         end
  1227.     end),
  1228.     -- Get all classes
  1229.     getGravity = function(class,orbit)
  1230.         -- G * M / r²
  1231.         -- 6.67e-11 * mass / (size/2)^2
  1232.        
  1233.         if class == 1 then
  1234.             return 6.67e-11 * ((orbit * .49) * 1.3e6)
  1235.         elseif class == 2 then
  1236.             -- g will be (orbit * 0.49), since the distance Star-Earth(1) = 20 and 20/9.8 (its gravity) = 0.49
  1237.             return (orbit * .49)
  1238.         elseif class == 3 then
  1239.             return (orbit * .15)
  1240.         end
  1241.     end,
  1242.     getMass = function(gravity,size)
  1243.         -- g * r² / G
  1244.         -- gravity * (size/2)^2 / 6.67e-11
  1245.  
  1246.         -- Size is improved
  1247.         size = size * 5
  1248.         return (gravity * (size/2)^2) / 6.67e-11
  1249.     end,
  1250.     getTemperature = function(class,orbit)
  1251.         -- Unknown Algorithm Method
  1252.         if class == 1 then
  1253.             return math.random(1e3,1e4)
  1254.         else
  1255.             return math.log(orbit,mode.universe.cosmos[1].luminosity)
  1256.         end
  1257.     end,
  1258.     -- Get star
  1259.     getLuminosity = function(size,temperature)
  1260.         -- 4Ï€R^2sT^4
  1261.         -- 4 * 3.14 * size^2 * 5.67e-8 * temperature^4
  1262.  
  1263.         return 4 * 3.14 * size^2 * 5.67e-8 * temperature^4
  1264.     end,
  1265.     getFlow = function(luminosity,size)
  1266.         -- L / 4Ï€r²
  1267.         -- luminosity / 4 * 3.14 * (size/2)^2
  1268.         return (luminosity / (4 * 3.14 * (size/2)^2))^.25
  1269.     end,
  1270.     getMagnitude = function(flow)
  1271.         local this = mode.universe.cosmos[id]
  1272.         -- –2.5 log(F1 / F2)
  1273.         -- -2.5 log(flow / -1.6)
  1274.  
  1275.         -- F2 will be –1.6 from Sirius, but it should be 0.00, from Vega
  1276.         return -2.5 * math.log(flow / -1.6)
  1277.     end,
  1278.     -- Get planet
  1279.     getVelocity = function(mass,size,orbit)
  1280.         -- sqrt (G * M) / R
  1281.         -- sqrt (6.67e-11 * mass) / R
  1282.  
  1283.         -- R will be (objectRadius * orbitRadius)
  1284.         return (((6.67e-11 * mass) / ((size/2) * (orbit/2)))^.5)^.25
  1285.     end,
  1286.     -- Get planet and moon
  1287.     getRotation = function(velocity)
  1288.         -- velocity * 365 * 24
  1289.         return velocity * 365 * 24
  1290.     end,
  1291.     getTranslation = function(mass,size)
  1292.         -- (4 * Ï€^2 / G * M) * r^3
  1293.         -- (4 * 9.85 / 6.67e-11 * mass) * (size/2)^3
  1294.        
  1295.         return ((4 * 9.85 / 6.67e-11 * mass) * ((size/2)^3))^.5
  1296.     end,
  1297.     getDistance = function(class,data,size)
  1298.         if class == 2 then
  1299.             local id = data
  1300.             if mode.universe.orbit[2] > 0 then
  1301.                 local current
  1302.                 repeat
  1303.                     id = id - 1
  1304.                     current = mode.universe.cosmos[id]
  1305.                 until current.class == 2
  1306.                
  1307.                 return current.distance + (#current.moons * 3.1) + size
  1308.             else
  1309.                 return size / 3
  1310.             end
  1311.         else -- Moon
  1312.             return mode.universe.cosmos[data].distance + mode.universe.cosmos[data].size/2 + #mode.universe.cosmos[data].moons * 2.3
  1313.         end
  1314.     end,
  1315.     getLifePossibility = function(this)
  1316.         local possibility = 0
  1317.        
  1318.         if this.class == 2 then
  1319.             if not mode.universe.data.objects[string.lower(this.className)][this.type][4] then
  1320.                 return 0
  1321.             else
  1322.                 possibility = possibility + 10
  1323.                
  1324.                 if #this.moons > 0 then
  1325.                     possibility = possibility + 10
  1326.                 end
  1327.                
  1328.                 if this.velocity > 0.7 and this.velocity < 2.4 then
  1329.                     possibility = possibility + 10
  1330.                 end
  1331.             end
  1332.         elseif this.class == 3 then
  1333.             if mode.universe.cosmos[this.satelliteOf].life >= 40 then
  1334.                 possibility = possibility + 5
  1335.             end
  1336.  
  1337.             if string.find(string.lower(mode.universe.cosmos[this.satelliteOf].typeName),"gas") then
  1338.                 possibility = possibility + 10
  1339.             end
  1340.            
  1341.             if this.velocity == 2.5 then
  1342.                 possibility = possibility + 10
  1343.             end
  1344.         end
  1345.        
  1346.         local dist = this.distance
  1347.         local starSize = mode.universe.cosmos[1].size / 100
  1348.        
  1349.         if dist > (10 * starSize) then
  1350.             if dist > (50 * starSize) then
  1351.                 if dist > (100 * starSize) then
  1352.                     if dist > (200 * starSize) then
  1353.                         if dist > (350 * starSize) then
  1354.                             possibility = possibility + 10
  1355.                         end
  1356.                     else
  1357.                         possibility = possibility + 45
  1358.                     end
  1359.                 else
  1360.                     possibility = possibility + 60
  1361.                 end
  1362.             else
  1363.                 possibility = possibility + 5
  1364.             end
  1365.         end
  1366.    
  1367.         return possibility
  1368.     end,
  1369.     -- Objects
  1370.     object = {
  1371.         new = function(self,info)
  1372.             mode.universe.orbit[4] = mode.universe.orbit[4] + 1
  1373.        
  1374.             local data = {
  1375.                 position = mode.universe.orbit[4],
  1376.                
  1377.                 name = #info.name>0 and info.name or "?",
  1378.                
  1379.                 class = info.class,
  1380.                 type = info.type,
  1381.                
  1382.                 size = info.size,
  1383.                 color = info.color,
  1384.                
  1385.                 display = false,
  1386.             }
  1387.            
  1388.             data.className = mode.universe.translations.en.buttons.classes[data.class] or "?"
  1389.             data.typeName = mode.universe.data.objects[string.lower(data.className)][data.type][1] or "?"
  1390.  
  1391.             data.gravity = mode.universe.getGravity(data.class,data.position)
  1392.             data.mass = mode.universe.getMass(data.gravity,data.size)
  1393.             data.temperature = (info.temperature == "auto" and mode.universe.getTemperature(data.class,data.position) or info.temperature)
  1394.            
  1395.             data.id = mode.universe.getID(data.class)
  1396.            
  1397.             if data.class == 1 then -- Star
  1398.                 data.luminosity = mode.universe.getLuminosity(data.size,data.temperature)
  1399.                 data.flow = mode.universe.getFlow(data.luminosity,data.size)
  1400.                 data.magnitude = mode.universe.getMagnitude(data.flow)
  1401.                
  1402.                 data.time = os.time()
  1403.                
  1404.                 if not mode.universe.star then
  1405.                     mode.universe.star = true
  1406.                 end
  1407.                
  1408.                 mode.universe.orbit[1] = mode.universe.orbit[1] + 1
  1409.             else
  1410.                 if data.class == 2 then -- Planet
  1411.                     data.moons = {}
  1412.                     data.rings = info.rings
  1413.                     data.orbit = mode.universe.orbit[2] + 1
  1414.                     data.distance = (info.distance == "auto" and math.ceil(mode.universe.getDistance(data.class,data.position,data.size)) or math.ceil(info.distance))
  1415.                     data.velocity = (info.velocity == "auto" and mode.universe.getVelocity(data.mass,data.size,data.orbit) or (info.velocity == 0 and .5 or info.velocity))
  1416.                 elseif data.class == 3 then -- Moon
  1417.                     data.satelliteOf = info.satelliteOf
  1418.                     data.distance = math.ceil(mode.universe.getDistance(data.class,data.satelliteOf))
  1419.                     data.velocity = 7 * table.random({.5,.3,.2,.1})
  1420.                    
  1421.                     mode.universe.cosmos[data.satelliteOf].moons[#mode.universe.cosmos[data.satelliteOf].moons + 1] = data.position
  1422.                 end
  1423.                
  1424.                 data.life = mode.universe.getLifePossibility(data)
  1425.                
  1426.                 data.period = {
  1427.                     rotation = mode.universe.getRotation(data.velocity),
  1428.                     translation = mode.universe.getTranslation(data.mass,data.size)
  1429.                 }
  1430.                
  1431.                 if data.class == 2 then
  1432.                     mode.universe.orbit[2] = mode.universe.orbit[2] + 1
  1433.                     data.planetPosition = mode.universe.orbit[2]
  1434.                 elseif data.class == 3 then
  1435.                     mode.universe.orbit[3] = mode.universe.orbit[3] + 1
  1436.                 end
  1437.             end
  1438.  
  1439.             mode.universe.cosmos[data.position] = data
  1440.             mode.universe.stuff[data.name] = true
  1441.  
  1442.             self.__index = self
  1443.             return setmetatable(data,self)         
  1444.         end,
  1445.         destroy = function(self)
  1446.             if self.class > 1 then
  1447.                 if self.class == 2 then -- Planet
  1448.                     if #self.moons > 0 then
  1449.                         for k,v in next,self.moons do
  1450.                             mode.universe.cosmos[v]:destroy()
  1451.                         end
  1452.                     end
  1453.                    
  1454.                     if self.rings then
  1455.                         tfm.exec.removeJoint(self.id + 3)
  1456.                     end
  1457.                 end
  1458.                
  1459.                 -- Below: Planet and Moon
  1460.                 tfm.exec.removeJoint(self.id + 2) -- Object's JR
  1461.             end
  1462.  
  1463.             tfm.exec.removeJoint(self.id + 1) -- Object's JD
  1464.             tfm.exec.removePhysicObject(self.id) -- Object
  1465.            
  1466.             self.display = false
  1467.         end,
  1468.         create = function(self)
  1469.             local x = 4e3
  1470.             local y = x - (mode.universe.star and (mode.universe.cosmos[1].id == self.id and 0 or (mode.universe.cosmos[1].size + (self.distance * 4))) or 0)
  1471.            
  1472.             local center = mode.universe.cosmos[1].id
  1473.             if self.class == 3 then -- Resets the satellite
  1474.                 center = mode.universe.cosmos[self.satelliteOf].id
  1475.             end
  1476.            
  1477.             tfm.exec.addPhysicObject(self.id,x,y,{ -- Object
  1478.                 type = 14, -- Used to be 13
  1479.                 color = 1,
  1480.                 width = 1,
  1481.                 groundCollision = false,
  1482.                 miceCollision = false,
  1483.                 mass = 1,
  1484.                 dynamic = (self.class ~= 1),
  1485.             })
  1486.            
  1487.             tfm.exec.addJoint(self.id + 1,self.id,self.id,{ -- JD (Color)
  1488.                 type = 0,
  1489.                 point1 = string.format("%s,%s",x,y),
  1490.                 point2 = string.format("%s,%s",x,y+1),
  1491.                 line = self.size,
  1492.                 color = self.color,
  1493.                 alpha = 1,
  1494.                 foreground = true,
  1495.             })
  1496.            
  1497.             if self.class ~= 1 then -- Rotation
  1498.                 tfm.exec.addJoint(self.id + 2,center,self.id,{
  1499.                     type = 3,
  1500.                     forceMotor = self.class == 3 and 10 or 9999,
  1501.                     speedMotor = self.velocity
  1502.                 })
  1503.             end
  1504.            
  1505.             if self.rings then
  1506.                 tfm.exec.addJoint(self.id + 3,self.id,self.id,{
  1507.                     type = 0,
  1508.                     point1 = string.format("%s,%s",x - self.size,y + math.floor(self.rings.inclination * 1.5)),
  1509.                     point2 = string.format("%s,%s",x + self.size,y - math.floor(self.rings.inclination * 1.5)),
  1510.                     line = self.rings.volume,
  1511.                     color = self.color,
  1512.                     alpha = .7,
  1513.                     foreground = 1
  1514.                 })
  1515.             end
  1516.             if self.moons then
  1517.                 for k,v in next,self.moons do
  1518.                     mode.universe.object.create(mode.universe.cosmos[v])
  1519.                 end
  1520.             end
  1521.            
  1522.             self.display = true
  1523.         end,
  1524.     },
  1525.     -- Set Admin
  1526.     newCreator = function(n)
  1527.         -- Data
  1528.         mode.universe.info[n] = {
  1529.             action = 0,
  1530.             creatorOpen = false,
  1531.             settings = {
  1532.                 palette = {1,{},1}, -- Current Page, Color List, Selected Color
  1533.                 -- For all bellow: [1]=Value,[2]=Counter,[[3] = isAutomatic]
  1534.                 size = {-math.huge,5},
  1535.                 temperature = {-math.huge,5,true},
  1536.                 velocity = {-math.huge,1,true},
  1537.                 distance = {-math.huge,5,true},
  1538.                 -- Settings
  1539.                 class = 0,
  1540.                 type = 0,
  1541.                 name = {},
  1542.                 rings = false,
  1543.                 satellite = 0,
  1544.                 -- List
  1545.                 create = setmetatable(
  1546.                     {
  1547.                         mode.universe.data.menu.class
  1548.                     },
  1549.                     mode.universe.meta.add
  1550.                 ),
  1551.             },
  1552.         }
  1553.        
  1554.         -- Controls
  1555.         system.bindKeyboard(n,string.byte("O"),true,true)
  1556.        
  1557.         -- Message
  1558.         tfm.exec.chatMessage("<font color='#CF50DB'>[•] " .. system.getTranslation("creator"),n)
  1559.     end,
  1560.     -- Set dataMenu
  1561.     getDataMenus = function()
  1562.         mode.universe.data.menu = {
  1563.             class = {
  1564.                 "<N2>" .. system.getTranslation("menu.class") .. " : <V><a href='event:newObject.class'>%s</a>",function(n)
  1565.                     if mode.universe.info[n].settings.class > 0 then
  1566.                         return mode.universe.data.classes[mode.universe.info[n].settings.class]
  1567.                     else
  1568.                         return system.getTranslation("choose")
  1569.                     end
  1570.                 end
  1571.             },
  1572.             type = {
  1573.                 "<N2>" .. system.getTranslation("menu.type") .. " : <V><a href='event:newObject.type'>%s</a>",function(n)
  1574.                     if mode.universe.info[n].settings.type > 0 then
  1575.                         return mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[mode.universe.info[n].settings.class])][mode.universe.info[n].settings.type][1]
  1576.                     else
  1577.                         return system.getTranslation("choose")
  1578.                     end
  1579.                 end
  1580.             },
  1581.             name = {
  1582.                 "<N2>" .. system.getTranslation("menu.name") .. " : <V><a href='event:newObject.name'>%s</a>",function(n)
  1583.                     if #mode.universe.info[n].settings.name > 0 then
  1584.                         return table.concat(mode.universe.info[n].settings.name)
  1585.                     else
  1586.                         return system.getTranslation("choose")
  1587.                     end
  1588.                 end
  1589.             },
  1590.             color = {
  1591.                 "<N2>" .. system.getTranslation("menu.color") .. " : <V><a href='event:newObject.color'>%s</a>",function(n)
  1592.                     if mode.universe.info[n].settings.palette[3] ~= 1 then
  1593.                         local color = string.format("%X",mode.universe.info[n].settings.palette[3])
  1594.                         return string.format("<font color='#%s'>#%s</font>",color,color)
  1595.                     else
  1596.                         return system.getTranslation("choose")
  1597.                     end
  1598.                 end
  1599.             },
  1600.             size = {
  1601.                 "<N2>" .. system.getTranslation("menu.size") .. " : <V><a href='event:newObject.size'>%s</a>",function(n)
  1602.                     if mode.universe.info[n].settings.size[1] > -math.huge then
  1603.                         return mode.universe.info[n].settings.size[1]
  1604.                     else
  1605.                         return system.getTranslation("choose")
  1606.                     end
  1607.                 end
  1608.             },
  1609.             temperature = {
  1610.                 "<N2>" .. system.getTranslation("menu.temperature") .. " : <V><a href='event:options.temperature'>%s</a>",function(n)
  1611.                     if mode.universe.info[n].settings.temperature[3] then
  1612.                         return "Auto"
  1613.                     else
  1614.                         return mode.universe.info[n].settings.temperature[1] .. " °C"
  1615.                     end
  1616.                 end
  1617.             },
  1618.             satellite = {
  1619.                 "<N2>" .. system.getTranslation("menu.satellite") .. " : <V><a href='event:newObject.moon'>%s</a>",function(n)
  1620.                     if mode.universe.info[n].settings.satellite > 0 and mode.universe.cosmos[mode.universe.info[n].settings.satellite].name then
  1621.                         return mode.universe.cosmos[mode.universe.info[n].settings.satellite].name
  1622.                     else
  1623.                         return system.getTranslation("choose")
  1624.                     end
  1625.                 end
  1626.             },
  1627.             velocity = {
  1628.                 "<N2>" .. system.getTranslation("menu.velocity") .. " : <V><a href='event:options.velocity'>%s</a>",function(n)
  1629.                     if mode.universe.info[n].settings.velocity[3] then
  1630.                         return "Auto"
  1631.                     else
  1632.                         return mode.universe.info[n].settings.velocity[1]
  1633.                     end
  1634.                 end
  1635.             },
  1636.             distance = {
  1637.                 "<N2>" .. system.getTranslation("menu.distance") .. " : <V><a href='event:options.distance'>%s</a>",function(n)
  1638.                     if mode.universe.info[n].settings.distance[3] then
  1639.                         return "Auto"
  1640.                     else
  1641.                         return mode.universe.info[n].settings.distance[1]
  1642.                     end
  1643.                 end
  1644.             },
  1645.             rings = {
  1646.                 "<N2>" .. system.getTranslation("menu.rings") .. " : <V><a href='event:alternate.rings'>%s</a>",function(n)
  1647.                     return mode.universe.info[n].settings.rings and system.getTranslation("yes") or system.getTranslation("no")
  1648.                 end
  1649.             }
  1650.         }
  1651.     end,
  1652.     -- Init
  1653.     reset = function()
  1654.         table.foreach(system.roomAdmins,mode.universe.newCreator)
  1655.     end,
  1656.     init = function()
  1657.         -- Translation
  1658.         mode.universe.translations.pt = mode.universe.translations.br
  1659.  
  1660.         if mode.universe.translations[tfm.get.room.community] then
  1661.             mode.universe.langue = tfm.get.room.community
  1662.         end
  1663.        
  1664.         -- Keyboard
  1665.         mode.universe.keyboard = mode.universe.keyboard()
  1666.        
  1667.         -- Translations
  1668.         -- Set object translated names
  1669.         if mode.universe.langue ~= "en" then
  1670.             for k,v in next,mode.universe.data.objects do
  1671.                 for i,j in next,v do
  1672.                     j[1] = system.getTranslation("objects." .. k .. "." .. i)
  1673.                 end
  1674.             end
  1675.         end
  1676.         -- Set class translations
  1677.         mode.universe.data.classes = system.getTranslation("buttons.classes")
  1678.        
  1679.         -- Menus
  1680.         mode.universe.getDataMenus()
  1681.        
  1682.         -- Loops
  1683.         system.newTimer(function()
  1684.             ui.setMapName(mode.universe.infoBar())
  1685.         end,1000,true)
  1686.        
  1687.         -- Admin
  1688.         if system.roomAttributes ~= 1 and system.roomNumber ~= 801 then
  1689.             table.foreach(system.roomAdmins,mode.universe.newCreator)
  1690.         end
  1691.        
  1692.         -- Settings
  1693.         tfm.exec.setRoomMaxPlayers(12)
  1694.         for _,f in next,{"AutoShaman","AutoNewGame","DebugCommand"} do
  1695.             tfm.exec["disable"..f]()
  1696.         end
  1697.        
  1698.         -- Map
  1699.         tfm.exec.newGame('<C><P L="8000" G="0," H="8000" /><Z><S><S P="1,,.3,.2,,,," L="3000" o="0" X="-1500" c="4" Y="-1000" T="12" H="3000" /><S H="3000" L="3000" o="0" X="-1500" c="4" Y="2000" T="12" P="1,,.3,.2,,,," /><S P="1,,.3,.2,,,," L="3000" o="0" X="-1500" c="4" Y="5000" T="12" H="3000" /><S H="3000" L="3000" o="0" X="1500" c="4" Y="9500" T="12" P="0,,.3,.2,,,," /><S P="1,,.3,.2,,,," L="3000" o="0" X="4500" c="4" Y="9500" T="12" H="3000" /><S H="3000" L="3000" o="0" X="9500" c="4" Y="5000" T="12" P="1,,.3,.2,,,," /><S H="3000" L="3000" o="0" X="7500" c="4" Y="9500" T="12" P="1,,.3,.2,,,," /><S P="1,,.3,.2,,,," L="3000" o="0" X="9500" c="4" Y="2000" T="12" H="3000" /><S H="3000" L="3000" o="0" X="9500" c="4" Y="-1000" T="12" P="1,,.3,.2,,,," /><S P="1,,.3,.2,,,," L="3000" o="0" X="-1500" c="4" Y="8000" T="12" H="3000" /><S P="1,,.3,.2,,,," L="3000" o="0" X="1500" c="4" Y="-1500" T="12" H="3000" /><S H="3000" L="3000" o="0" X="4500" c="4" Y="-1500" T="12" P="1,,.3,.2,,,," /><S P="1,,.3,.2,,,," L="3000" o="0" X="6500" c="4" Y="-1500" T="12" H="3000" /><S P="1,,.3,.2,,,," L="3000" o="0" X="9500" c="4" Y="8000" T="12" H="3000" /></S><D><DS Y="4000" X="4000" /></D><O /></Z></C>')
  1700.     end,
  1701.     -- NewPlayer
  1702.     eventNewPlayer = function(n)
  1703.         system.bindKeyboard(n,string.byte("P"),true,true)
  1704.         system.bindKeyboard(n,46,true,true) -- Delete
  1705.        
  1706.         tfm.exec.chatMessage("<font color='#CF50DB'>[•] " .. system.getTranslation("welcome"),n)
  1707.        
  1708.         ui.banner("15db5b6ab36",210,120,n,10)
  1709.        
  1710.         if system.roomAdmins[n] then
  1711.             mode.universe.newCreator(n)
  1712.         end
  1713.        
  1714.         tfm.exec.addImage("15db9e67479.png","&1",5,30,n)
  1715.        
  1716.         if mode.universe.canInsertBackground then
  1717.             tfm.exec.respawnPlayer(n)
  1718.             mode.universe.setBackground(n)
  1719.         end
  1720.     end,
  1721.     -- Keyboard
  1722.     eventKeyboard = function(n,k)
  1723.         if k == string.byte("O") and system.roomAdmins[n] then
  1724.             if mode.universe.info[n].creatorOpen then
  1725.                 mode.universe.eventTextAreaCallback(i,n,"main.exit")
  1726.             else
  1727.                 mode.universe.uicreator(n)
  1728.             end
  1729.             return
  1730.         elseif k == string.byte("P") then
  1731.             local allowed = true
  1732.             if mode.universe.info[n] and mode.universe.info[n].creatorOpen then
  1733.                 allowed = false
  1734.             end
  1735.             if allowed then
  1736.                 mode.universe.profile.uiprofile(n)
  1737.             end
  1738.             return
  1739.         elseif k == 46 then
  1740.             tfm.exec.respawnPlayer(n)
  1741.             --tfm.exec.killPlayer(n)
  1742.             return
  1743.         end
  1744.     end,
  1745.     -- Callback
  1746.     eventTextAreaCallback = function(i,n,c)
  1747.         local p = string.split(c,"[^%.]+")
  1748.         -- Keyboard
  1749.         if p[1] == "keyboard" then
  1750.             if p[2] == "name" then
  1751.                 if p[3] == "submit" then
  1752.                     mode.universe.uicloseSplash(n)
  1753.                 else
  1754.                     if p[3] == "backspace" then
  1755.                         table.remove(mode.universe.info[n].settings.name)
  1756.                     elseif p[3] == "clear" then
  1757.                         mode.universe.info[n].settings.name = {}
  1758.                     elseif p[3] == "insert" then
  1759.                         if #mode.universe.info[n].settings.name < 16 then
  1760.                             mode.universe.info[n].settings.name[#mode.universe.info[n].settings.name + 1] = string.char(p[4])
  1761.                         end
  1762.                     end
  1763.                     mode.universe.uikeyboard(p[2],mode.universe.info[n].settings.name,n)
  1764.                 end
  1765.             end
  1766.             return
  1767.         end
  1768.         -- Counter
  1769.         if p[1] == "counter" then
  1770.             if table.find({"size","temperature","velocity","distance"},p[2]) then
  1771.                 if p[3] == "submit" then
  1772.                     mode.universe.uicloseSplash(n)
  1773.                 else
  1774.                     local increment = tonumber(string.format(p[4],"."))
  1775.                     if p[3] == "add" then
  1776.                         mode.universe.info[n].settings[p[2]][2] = mode.universe.info[n].settings[p[2]][2] + increment
  1777.                     elseif p[3] == "sub" then
  1778.                         mode.universe.info[n].settings[p[2]][2] = mode.universe.info[n].settings[p[2]][2] - increment
  1779.                     end
  1780.                     mode.universe.eventTextAreaCallback(i,n,"newObject." .. p[2])
  1781.                 end
  1782.             end
  1783.             return
  1784.         end
  1785.         -- Palette
  1786.         if p[1] == "palette" then
  1787.             if p[2] == "exit" then
  1788.                 for i = 11,19 do
  1789.                     mode.universe.uiremove(i,n)
  1790.                 end
  1791.                 mode.universe.info[n].settings.palette[1] = 1
  1792.                 mode.universe.uicreator(n)
  1793.             else
  1794.                 if p[2] == "left" then
  1795.                     mode.universe.info[n].settings.palette[1] = mode.universe.info[n].settings.palette[1] - 1
  1796.                 elseif p[2] == "right" then
  1797.                     mode.universe.info[n].settings.palette[1] = mode.universe.info[n].settings.palette[1] + 1
  1798.                 end
  1799.                 mode.universe.eventTextAreaCallback(i,n,"newObject.color")
  1800.             end
  1801.             return
  1802.         end
  1803.         -- New Object
  1804.         if p[1] == "newObject" then
  1805.             -- Class
  1806.             if p[2] == "class" then
  1807.                 mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(p[2]) .. "</B><font size='12'><p align='left'>\n\n<S>" .. table.concat(mode.universe.data.classes,"\n",function(k,v)
  1808.                     local out = true
  1809.                     if k == 1 then
  1810.                         out = not mode.universe.star
  1811.                     end
  1812.                     if k == 2 then
  1813.                         out = mode.universe.star
  1814.                     end
  1815.                     if k == 3 then
  1816.                         if mode.universe.orbit[2] == 0 then
  1817.                             out = false
  1818.                         end
  1819.                     end
  1820.                     return out and string.format("%s<a href='event:item.class.%s'>%s</a>",mode.universe.tab,k,v) or string.format("%s<N2>%s</N2>",mode.universe.tab,v)
  1821.                 end),n)
  1822.                 return
  1823.             end
  1824.             -- Type
  1825.             if p[2] == "type" then
  1826.                 if mode.universe.info[n].settings.class > 0 then
  1827.                     mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(p[2]) .. "</B><font size='12'><p align='left'>\n\n<S>" .. table.concat(mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[mode.universe.info[n].settings.class])],"\n",function(k,v)
  1828.                         local out = true
  1829.                         if mode.universe.info[n].settings.class == 2 then
  1830.                             local orbit = mode.universe.orbit[2] + 1
  1831.                             if v[5] ~= 0 and not math.isNegative(v[5],orbit > math.abs(v[5]),orbit <= v[5]) then
  1832.                                 out = false
  1833.                             end
  1834.                         end
  1835.                         return out and string.format("%s<a href='event:item.type.%s'>%s</a>",mode.universe.tab,k,v[1]) or string.format("%s<N2>%s</N2>",mode.universe.tab,v[1])
  1836.                     end),n)
  1837.                 end
  1838.                 return
  1839.             end
  1840.             -- Name
  1841.             if p[2] == "name" then
  1842.                 mode.universe.uikeyboard(p[2],mode.universe.info[n].settings.name,n)
  1843.                 return
  1844.             end
  1845.             -- Size, Color, Temperature, Velocity, Distance, Moon, Respectively. [There must be a type]
  1846.             if mode.universe.info[n].settings.type > 0 then
  1847.                 if p[2] == "size" then
  1848.                     mode.universe.uicounter(p[2],mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[mode.universe.info[n].settings.class])][mode.universe.info[n].settings.type][3],n)
  1849.                 elseif p[2] == "color" then
  1850.                     mode.universe.uipaletteMono(mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[mode.universe.info[n].settings.class])][mode.universe.info[n].settings.type][2],n)
  1851.                 elseif p[2] == "temperature" then
  1852.                     mode.universe.uicounter(p[2],"-200:1000",n,100) -- Unknown, yet.
  1853.                 elseif p[2] == "velocity" then
  1854.                     mode.universe.uicounter(p[2],"-8:8",n,2,.1) -- Unknown, yet.
  1855.                 elseif p[2] == "distance" then
  1856.                     mode.universe.uicounter(p[2],"0:250",n,20) -- Unknown, yet.
  1857.                 elseif p[2] == "moon" then
  1858.                     mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(system.getTranslation("menu.satellite")) .. "</B><font size='12'><p align='left'>\n\n<S>" .. table.concat(mode.universe.cosmos,"\n",function(k,v)
  1859.                         return v.class == 2 and string.format("%s<a href='event:item.satellite.%s'>%s</a>",mode.universe.tab,k,v.name) or ""
  1860.                     end),n)
  1861.                 end
  1862.                 return
  1863.             end
  1864.             return
  1865.         end
  1866.         -- Items
  1867.         if p[1] == "item" then
  1868.             -- Class
  1869.             if p[2] == "class" then
  1870.                 mode.universe.info[n].settings.class = tonumber(p[3])
  1871.                 mode.universe.info[n].settings.type = 0
  1872.                
  1873.                 mode.universe.uiresetCreator(n)
  1874.                 mode.universe.uiclearCreator(n)
  1875.                
  1876.                 mode.universe.info[n].settings.create = mode.universe.info[n].settings.create + {mode.universe.data.menu.type,mode.universe.data.menu.name}
  1877.                
  1878.                 mode.universe.uicloseSplash(n)
  1879.                 return
  1880.             end
  1881.             -- Type
  1882.             if p[2] == "type" then
  1883.                 mode.universe.info[n].settings.type = tonumber(p[3])
  1884.                
  1885.                 mode.universe.uiresetCreator(n)
  1886.                 mode.universe.uiclearCreator(n,3)
  1887.                
  1888.                 mode.universe.info[n].settings.palette[2] = mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[mode.universe.info[n].settings.class])][mode.universe.info[n].settings.type][2]
  1889.                
  1890.                 local implement = setmetatable({
  1891.                     mode.universe.data.menu.color,
  1892.                     mode.universe.data.menu.size,
  1893.                     mode.universe.data.menu.temperature
  1894.                 },mode.universe.meta.add)
  1895.                 if mode.universe.info[n].settings.class == 2 then
  1896.                     implement = implement + {mode.universe.data.menu.velocity,mode.universe.data.menu.distance,mode.universe.data.menu.rings}
  1897.                 end
  1898.                 if mode.universe.info[n].settings.class == 3 then
  1899.                     implement = implement + {mode.universe.data.menu.satellite}
  1900.                 end
  1901.                
  1902.                 mode.universe.info[n].settings.create = mode.universe.info[n].settings.create + implement
  1903.                
  1904.                 mode.universe.uicloseSplash(n)
  1905.                 return
  1906.             end
  1907.             -- Size, Temperature, Velocity, Distance
  1908.             if table.find({"size","temperature","velocity","distance"},p[2]) then
  1909.                 if p[3] == "add" then
  1910.                     mode.universe.info[n].settings[p[2]][1] = mode.universe.info[n].settings[p[2]][1] + mode.universe.info[n].settings[p[2]][2]
  1911.                 elseif p[3] == "sub" then
  1912.                     mode.universe.info[n].settings[p[2]][1] = mode.universe.info[n].settings[p[2]][1] - mode.universe.info[n].settings[p[2]][2]
  1913.                 end
  1914.                 mode.universe.eventTextAreaCallback(i,n,"newObject." .. p[2])
  1915.                 return
  1916.             end
  1917.             -- Color
  1918.             if p[2] == "color" then
  1919.                 mode.universe.info[n].settings.palette[3] = tonumber(p[3])
  1920.                 mode.universe.eventTextAreaCallback(i,n,"palette.exit")
  1921.                
  1922.                 return
  1923.             end
  1924.             -- Satellite
  1925.             if p[2] == "satellite" then
  1926.                 mode.universe.info[n].settings.satellite = tonumber(p[3])
  1927.                 mode.universe.uicloseSplash(n)
  1928.                 return
  1929.             end
  1930.             return
  1931.         end
  1932.         -- Options
  1933.         if p[1] == "options" then
  1934.             if mode.universe.info[n].settings[p[2]][3] then
  1935.                 mode.universe.info[n].settings[p[2]][3] = false
  1936.                 mode.universe.eventTextAreaCallback(i,n,"newObject." .. p[2])
  1937.             else
  1938.                 mode.universe.info[n].settings[p[2]][3] = true
  1939.                 mode.universe.uicreator(n)
  1940.             end
  1941.             return
  1942.         end
  1943.         -- Alternate (Yes/No)
  1944.         if p[1] == "alternate" then
  1945.             if p[2] == "rings" then
  1946.                 mode.universe.info[n].settings[p[2]] = not mode.universe.info[n].settings[p[2]]
  1947.                 mode.universe.uicreator(n)
  1948.             end
  1949.             return
  1950.         end
  1951.         -- Close splash
  1952.         if p[1] == "closeSplash" then
  1953.             mode.universe.uicloseSplash(n)
  1954.         end
  1955.         -- Main
  1956.         if p[1] == "main" then
  1957.             -- Exit
  1958.             if p[2] == "exit" then
  1959.                 mode.universe.uicloseSplash(n)
  1960.                 for i = 0,9 do
  1961.                     mode.universe.uiremove(i,n)
  1962.                 end
  1963.                 mode.universe.info[n].creatorOpen = false
  1964.                 return
  1965.             end
  1966.             -- Reset
  1967.             if p[2] == "reset" then
  1968.                 mode.universe.info[n].settings.class = 0
  1969.                 mode.universe.info[n].settings.type = 0
  1970.                 mode.universe.info[n].settings.name = {}
  1971.                 mode.universe.uiresetCreator(n)
  1972.                 mode.universe.uiclearCreator(n)
  1973.                 if not p[3] then
  1974.                     mode.universe.uicreator(n)
  1975.                 end
  1976.                 return
  1977.             end
  1978.             -- Create
  1979.             if p[2] == "create" then
  1980.                 local fails = {}
  1981.                 if mode.universe.info[n].settings.class <= 0 then
  1982.                     fails[#fails + 1] = "class"
  1983.                 end
  1984.                 if #mode.universe.info[n].settings.name == 0 then
  1985.                     fails[#fails + 1] = "name"
  1986.                 end
  1987.                 if mode.universe.info[n].settings.type <= 0 then
  1988.                     fails[#fails + 1] = "type"
  1989.                 end
  1990.                 if mode.universe.info[n].settings.size[1] == -math.huge then
  1991.                     fails[#fails + 1] = "size"
  1992.                 end
  1993.                 if mode.universe.info[n].settings.palette[3] == 1 then
  1994.                     fails[#fails + 1] = "color"
  1995.                 end
  1996.                
  1997.                 if mode.universe.info[n].settings.class == 3 then
  1998.                     if mode.universe.info[n].settings.satellite == 0 then
  1999.                         fails[#fails + 1] = "satellite"
  2000.                     end
  2001.                 end
  2002.                
  2003.                 local create = #fails == 0
  2004.                
  2005.                 local concatenedName = table.concat(mode.universe.info[n].settings.name)
  2006.                
  2007.                 if not create then
  2008.                     tfm.exec.chatMessage("<R>" .. string.format(system.getTranslation("fail"),table.concat(fails,", ",function(k,v)
  2009.                         return system.getTranslation("menu." .. v)
  2010.                     end)),n)
  2011.                 end
  2012.                
  2013.                 if mode.universe.stuff[concatenedName] then
  2014.                     create = false
  2015.                     tfm.exec.chatMessage("<R>" .. string.format(system.getTranslation("nameExist"),concatenedName),n)
  2016.                 end
  2017.  
  2018.                 if create and (os.time() > mode.universe.info[n].action) then
  2019.                     mode.universe.info[n].action = os.time() + 2500
  2020.                
  2021.                     local this = mode.universe.object:new({
  2022.                         name = concatenedName,
  2023.                         class = mode.universe.info[n].settings.class,
  2024.                         type = mode.universe.info[n].settings.type,
  2025.                         size = mode.universe.info[n].settings.size[1],
  2026.                         color = mode.universe.info[n].settings.palette[3],
  2027.                         velocity = mode.universe.info[n].settings.velocity[3] and "auto" or mode.universe.info[n].settings.velocity[1],
  2028.                         temperature = mode.universe.info[n].settings.temperature[3] and "auto" or mode.universe.info[n].settings.temperature[1],
  2029.                         rings = mode.universe.info[n].settings.rings and {inclination = 6.5} or false,
  2030.                         distance = mode.universe.info[n].settings.distance[3] and "auto" or mode.universe.info[n].settings.distance[1],
  2031.                         satelliteOf = mode.universe.info[n].settings.satellite,        
  2032.                     })
  2033.  
  2034.                     if this.class == 3 then
  2035.                         mode.universe.object.destroy(mode.universe.cosmos[this.satelliteOf])
  2036.                         mode.universe.object.create(mode.universe.cosmos[this.satelliteOf])
  2037.                     else
  2038.                         this:create()
  2039.                     end
  2040.                    
  2041.                     local type = mode.universe.data.objects[string.lower(mode.universe.translations.en.buttons.classes[this.class])][this.type][1]
  2042.                     tfm.exec.chatMessage("<S>" .. string.format(system.getTranslation("newObject." .. this.class),type,(this.satelliteOf and mode.universe.cosmos[this.satelliteOf].name or "")) .. "\n\t" .. string.format(system.getTranslation("checkProfile"),this.name))
  2043.  
  2044.                     mode.universe.eventTextAreaCallback(i,n,"main.reset.not")
  2045.                     mode.universe.eventTextAreaCallback(i,n,"main.exit")
  2046.                 end
  2047.                 return
  2048.             end
  2049.             -- Destroy
  2050.             if p[2] == "destroy" then
  2051.                 if p[3] then
  2052.                     p[3] = tonumber(p[3])
  2053.                     ui.addPopup(p[3],1,"<p align='center'><font color='#2ECF73'>" .. string.format(system.getTranslation("destroyConfirm"),mode.universe.cosmos[p[3]].className,mode.universe.cosmos[p[3]].name),n,200,150,400,true)
  2054.                 else
  2055.                     mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(system.getTranslation("buttons.main.destroy")) .. "</B><font size='12'>\n<a href='event:closeSplash'>" .. system.getTranslation("exit") .. "</a><p align='left'>\n\n<S>" .. table.concat(mode.universe.cosmos,"",function(k,v)
  2056.                         return v.display and string.format("%s%s <a href='event:main.destroy.%s'>%s</a>\n",mode.universe.tab,(v.id == mode.universe.cosmos[1].id and "<a:active>★</a:active>" or "<CE>[" .. v.className .."]</CE>"),k,v.name) or ""
  2057.                     end),n,200)
  2058.                 end
  2059.                 return
  2060.             end
  2061.             -- Recreate
  2062.             if p[2] == "recreate" then
  2063.                 if p[3] then
  2064.                     p[3] = tonumber(p[3])
  2065.                     if mode.universe.cosmos[p[3]].id == mode.universe.cosmos[1].id then
  2066.                         for i = 1,mode.universe.orbit[4] do
  2067.                             if mode.universe.cosmos[p[3]].class < 3 then
  2068.                                 mode.universe.cosmos[i]:create()
  2069.                             end
  2070.                         end
  2071.                        
  2072.                         tfm.exec.chatMessage("<R>" .. system.getTranslation("systemRecreated"),n)
  2073.                     else
  2074.                         if mode.universe.cosmos[p[3]].class == 3 then
  2075.                             if mode.universe.cosmos[mode.universe.cosmos[p[3]].satelliteOf].display then
  2076.                                 mode.universe.cosmos[mode.universe.cosmos[p[3]].satelliteOf]:destroy()
  2077.                             else
  2078.                                 tfm.exec.chatMessage("<R>" .. system.getTranslation("planetRecreated"),n)
  2079.                             end
  2080.                            
  2081.                             mode.universe.cosmos[mode.universe.cosmos[p[3]].satelliteOf]:create()
  2082.                         else
  2083.                             mode.universe.cosmos[p[3]]:create()
  2084.                            
  2085.                             if mode.universe.cosmos[p[3]].class == 2 then
  2086.                                 if #mode.universe.cosmos[p[3]].moons > 0 then
  2087.                                     tfm.exec.chatMessage("<R>" .. system.getTranslation("moonRecreated"),n)
  2088.                                 end
  2089.                             end
  2090.                         end
  2091.                     end
  2092.                     mode.universe.uicloseSplash(n,true)
  2093.                 else
  2094.                     mode.universe.uiitems("<p align='center'><font size='20'><V><B>" .. string.upper(system.getTranslation("buttons.main.recreate")) .. "</B><font size='12'>\n<a href='event:closeSplash'>" .. system.getTranslation("exit") .. "</a><p align='left'>\n\n<S>" .. table.concat(mode.universe.cosmos,"",function(k,v)
  2095.                         return v.display and "" or string.format("%s%s <a href='event:main.recreate.%s'>%s</a>\n",mode.universe.tab,(v.id == mode.universe.cosmos[1].id and "<a:active>★</a:active>" or "<CE>[" .. v.className .."]</CE>"),k,v.name)
  2096.                     end),n,200)
  2097.                 end
  2098.                 return
  2099.             end
  2100.             return
  2101.         end
  2102.         -- Profile
  2103.         if p[1] == "profile" then
  2104.             local allowed = true
  2105.             if mode.universe.info[n] and mode.universe.info[n].creatorOpen then
  2106.                 allowed = false
  2107.             end
  2108.             if allowed then
  2109.                 -- Open, Exit, Respectively.
  2110.                 if p[2] == "open" then
  2111.                     mode.universe.profile.uiremoveprofile(n)
  2112.                     mode.universe.profile["profile" .. p[3]](p[4],n)
  2113.                 elseif p[2] == "exit" then
  2114.                     mode.universe.uicloseSplash(n,true)
  2115.                     mode.universe.profile.uiremoveprofile(n)
  2116.                 end
  2117.             end
  2118.             return
  2119.         end
  2120.     end,
  2121.     -- Chat Commands
  2122.     eventChatCommand = function(n,c)
  2123.         local p = string.split(c,"[^%s]+")
  2124.        
  2125.         if p[1] == "profile" then
  2126.             if p[2] then
  2127.                 p[2] = string.lower(p[2])
  2128.                 for k,v in next,mode.universe.cosmos do
  2129.                     if string.lower(v.name) == p[2] then
  2130.                         mode.universe.eventTextAreaCallback(nil,n,"profile.open." .. v.className .. "." .. k)
  2131.                         break
  2132.                     end
  2133.                 end
  2134.             else
  2135.                 mode.universe.eventKeyboard(n,string.byte("P"))
  2136.             end
  2137.             return
  2138.         end
  2139.        
  2140.         if system.roomAdmins[n] then
  2141.             if p[1] == "name" then
  2142.                 if p[2] then
  2143.                     mode.universe.eventPopupAnswer(0,n,table.concat(p," ",nil,2))
  2144.                 else
  2145.                     ui.addPopup(0,2,"<p align='center'><font color='#CF50DB'>" .. system.getTranslation("sysName.choose"),n,200,150,400,true)
  2146.                 end
  2147.                 return
  2148.             end
  2149.         end
  2150.     end,
  2151.     -- Popup Answer
  2152.     eventPopupAnswer = function(i,n,a)
  2153.         if i == 0 then
  2154.             if a ~= "" then
  2155.                 mode.universe.systemName = string.sub(a,1,20)
  2156.                 tfm.exec.chatMessage("<font color='#CF50DB'>" .. string.format(system.getTranslation("sysName.new"),mode.universe.systemName))
  2157.             end
  2158.         else
  2159.             if a == "yes" then
  2160.                 local destroyable,moonMessage = true,false
  2161.                 if mode.universe.cosmos[i].id == mode.universe.cosmos[1].id then
  2162.                     for id = 2,mode.universe.orbit[4] do
  2163.                         --[[if mode.universe.cosmos[id].class < 3 then
  2164.                             mode.universe.cosmos[id]:destroy()
  2165.                         end]]
  2166.                         if mode.universe.cosmos[id].display then
  2167.                             destroyable = false
  2168.                             break
  2169.                         end
  2170.                     end
  2171.                 else
  2172.                     if mode.universe.cosmos[i].class == 2 then
  2173.                         if #mode.universe.cosmos[i].moons > 0 then
  2174.                             moonMessage = true
  2175.                         end
  2176.                     end
  2177.                 end
  2178.                 if destroyable then
  2179.                     mode.universe.cosmos[i]:destroy()
  2180.                    
  2181.                     if moonMessage then
  2182.                         tfm.exec.chatMessage("<R>" .. system.getTranslation("moonDestroyed"),n)
  2183.                     end
  2184.                 else
  2185.                     tfm.exec.chatMessage("<R>" .. system.getTranslation("cantDestroy"),n)
  2186.                 end
  2187.             end
  2188.             mode.universe.uicloseSplash(n,true)
  2189.         end
  2190.     end,
  2191.     -- New Game
  2192.     eventNewGame = function()
  2193.         mode.universe.canInsertBackground = true
  2194.        
  2195.         mode.universe.setBackground()
  2196.    
  2197.         -- Solar System
  2198.         if system.roomNumber == 801 or not string.find(tfm.get.room.name,"@") then
  2199.             local system = {
  2200.                 [1] = {
  2201.                     name = "Sun",
  2202.                     class = 1,
  2203.                     className = "Star",
  2204.                     type = 1,
  2205.                     typeName = "Yellow Dwarf",
  2206.                     size = 90,
  2207.                     color = 0xF8B55F,
  2208.                     temperature = 5500,
  2209.                 },
  2210.                 [2] = {
  2211.                     name = "Mercury",
  2212.                     class = 2,
  2213.                     className = "Planet",
  2214.                     type = 5,
  2215.                     typeName = "Iron",
  2216.                     size = 18,
  2217.                     color = 0x929292,
  2218.                     velocity = 4,
  2219.                     temperature = 200,
  2220.                     rings = false,
  2221.                     distance = 1,
  2222.                 },
  2223.                 [3] = {
  2224.                     name = "Venus",
  2225.                     class = 2,
  2226.                     className = "Planet",
  2227.                     type = 5,
  2228.                     typeName = "Telluric",
  2229.                     size = 32,
  2230.                     color = 0xCFB181,
  2231.                     velocity = -.5,
  2232.                     temperature = 450,
  2233.                     rings = false,
  2234.                     distance = 20,
  2235.                 },
  2236.                 [4] = {
  2237.                     name = "Earth",
  2238.                     class = 2,
  2239.                     className = "Planet",
  2240.                     type = 5,
  2241.                     typeName = "Telluric",
  2242.                     size = 35,
  2243.                     color = 0x3E7B9D,
  2244.                     velocity = 1,
  2245.                     temperature = 20,
  2246.                     rings = false,
  2247.                     distance = 70,
  2248.                 },
  2249.                 [5] = {
  2250.                     name = "Moon",
  2251.                     class = 3,
  2252.                     className = "Moon",
  2253.                     type = 1,
  2254.                     typeName = "Asteroid",
  2255.                     size = 6.5,
  2256.                     color = 0x848484,
  2257.                     temperature = -30,
  2258.                     satelliteOf = 4
  2259.                 },
  2260.                 [6] = {
  2261.                     name = "Mars",
  2262.                     class = 2,
  2263.                     className = "Planet",
  2264.                     type = 6,
  2265.                     typeName = "Sillicate",
  2266.                     size = 24,
  2267.                     color = 0xEF6B3E,
  2268.                     velocity = .6,
  2269.                     temperature = -17,
  2270.                     rings = false,
  2271.                     distance = 120,
  2272.                 },
  2273.                 [7] = {
  2274.                     name = "Phobos",
  2275.                     class = 3,
  2276.                     className = "Moon",
  2277.                     type = 2,
  2278.                     typeName = "Irregular Asteroid",
  2279.                     size = 3.3,
  2280.                     color = 0x73572B,
  2281.                     temperature = -58,
  2282.                     satelliteOf = 6
  2283.                 },
  2284.                 [8] = {
  2285.                     name = "Deimos",
  2286.                     class = 3,
  2287.                     className = "Moon",
  2288.                     type = 2,
  2289.                     typeName = "Irregular Asteroid",
  2290.                     size = 2.2,
  2291.                     color = 0xB9B9B9,
  2292.                     temperature = -40,
  2293.                     satelliteOf = 6
  2294.                 },
  2295.                 [9] = {
  2296.                     name = "Jupiter",
  2297.                     class = 2,
  2298.                     className = "Planet",
  2299.                     type = 3,
  2300.                     typeName = "Gas Giant",
  2301.                     size = 55,
  2302.                     color = 0xE39492,
  2303.                     velocity = .4,
  2304.                     temperature = -170,
  2305.                     rings = {
  2306.                         inclination = .6,
  2307.                     },
  2308.                     distance = 185,
  2309.                 },
  2310.                 [10] = {
  2311.                     name = "Io",
  2312.                     class = 3,
  2313.                     className = "Moon",
  2314.                     type = 1,
  2315.                     typeName = "Asteroid",
  2316.                     size = 5.5,
  2317.                     color = 0xE7D587,
  2318.                     temperature = -100,
  2319.                     satelliteOf = 9
  2320.                 },
  2321.                 [11] = {
  2322.                     name = "Europa",
  2323.                     class = 3,
  2324.                     className = "Moon",
  2325.                     type = 1,
  2326.                     typeName = "Asteroid",
  2327.                     size = 4.5,
  2328.                     color = 0xB4BCBE,
  2329.                     temperature = -180,
  2330.                     satelliteOf = 9
  2331.                 },
  2332.                 [12] = {
  2333.                     name = "Ganymede",
  2334.                     class = 3,
  2335.                     className = "Moon",
  2336.                     type = 1,
  2337.                     typeName = "Asteroid",
  2338.                     size = 10,
  2339.                     color = 0x907E6D,
  2340.                     temperature = -150,
  2341.                     satelliteOf = 9
  2342.                 },
  2343.                 [13] = {
  2344.                     name = "Callisto",
  2345.                     class = 3,
  2346.                     className = "Moon",
  2347.                     type = 1,
  2348.                     typeName = "Asteroid",
  2349.                     size = 8,
  2350.                     color = 0xB9A89F,
  2351.                     temperature = -180,
  2352.                     satelliteOf = 9
  2353.                 },
  2354.                 [14] = {
  2355.                     name = "Saturn",
  2356.                     class = 2,
  2357.                     className = "Planet",
  2358.                     type = 3,
  2359.                     typeName = "Gas Giant",
  2360.                     size = 50,
  2361.                     color = 0xCAAB7B,
  2362.                     velocity = .3,
  2363.                     temperature = -170,
  2364.                     rings = {
  2365.                         inclination = .3,
  2366.                         volume = 7
  2367.                     },
  2368.                     distance = 280,
  2369.                 },
  2370.                 [15] = {
  2371.                     name = "Titan",
  2372.                     class = 3,
  2373.                     className = "Moon",
  2374.                     type = 1,
  2375.                     typeName = "Asteroid",
  2376.                     size = 9,
  2377.                     color = 0xCF892A,
  2378.                     temperature = -180,
  2379.                     satelliteOf = 14
  2380.                 },
  2381.                 [16] = {
  2382.                     name = "Enceladus",
  2383.                     class = 3,
  2384.                     className = "Moon",
  2385.                     type = 1,
  2386.                     typeName = "Asteroid",
  2387.                     size = 6.5,
  2388.                     color = 0xAEBBC3,
  2389.                     temperature = -200,
  2390.                     satelliteOf = 14
  2391.                 },
  2392.                 [17] = {
  2393.                     name = "Uranus",
  2394.                     class = 2,
  2395.                     className = "Planet",
  2396.                     type = 4,
  2397.                     typeName = "Ice Giant",
  2398.                     size = 36,
  2399.                     color = 0x57D2C9,
  2400.                     velocity = .2,
  2401.                     temperature = -216,
  2402.                     rings = {
  2403.                         inclination = 2,
  2404.                         volume = 1
  2405.                     },
  2406.                     distance = 360,
  2407.                 },
  2408.                 [18] = {
  2409.                     name = "Neptune",
  2410.                     class = 2,
  2411.                     className = "Planet",
  2412.                     type = 4,
  2413.                     typeName = "Ice Giant",
  2414.                     size = 30,
  2415.                     color = 0x183241,
  2416.                     velocity = .17,
  2417.                     temperature = -210,
  2418.                     rings = false,
  2419.                     distance = 430,
  2420.                 },
  2421.                 [19] = {
  2422.                     name = "Pluto",
  2423.                     class = 2,
  2424.                     className = "Planet",
  2425.                     type = 8,
  2426.                     typeName = "Dwarf",
  2427.                     size = 6,
  2428.                     color = 0x40181C,
  2429.                     velocity = .08,
  2430.                     temperature = -230,
  2431.                     rings = false,
  2432.                     distance = 500,
  2433.                 },
  2434.                 [20] = {
  2435.                     name = "Charon",
  2436.                     class = 3,
  2437.                     className = "Moon",
  2438.                     type = 1,
  2439.                     typeName = "Asteroid",
  2440.                     size = 3.8,
  2441.                     color = 0xA7A7A7,
  2442.                     temperature = -220,
  2443.                     satelliteOf = 19
  2444.                 },
  2445.             }
  2446.            
  2447.             for i = 1,#system do
  2448.                 mode.universe.object:new(system[i])
  2449.             end
  2450.             for i = 1,#mode.universe.cosmos do
  2451.                 if mode.universe.cosmos[i].class ~= 3 then
  2452.                     mode.universe.cosmos[i]:create()
  2453.                 end
  2454.             end
  2455.         end
  2456.     end,
  2457.     -- Loop
  2458.     eventLoop = function()
  2459.         if _G.currentTime % 5 == 0 then
  2460.             for k,v in next,system.players(true) do
  2461.                 tfm.exec.killPlayer(v)
  2462.             end
  2463.         end
  2464.        
  2465.         if _G.currentTime % 80 == 0 then
  2466.             if mode.universe.ufoId > -1 then
  2467.                 tfm.exec.removeImage(mode.universe.ufoId)
  2468.             end
  2469.  
  2470.             mode.universe.ufoId = tfm.exec.addImage(table.random(mode.universe.images.ufos) .. ".png","!65",math.random(200,7800),math.random(200,7800))
  2471.         end
  2472.     end
  2473. }
  2474.  
  2475. --[[ ModeChanged ]]--
  2476. system.objects = {
  2477.     image = {},
  2478.     textarea = {}
  2479. }
  2480. eventModeChanged = function()
  2481.     -- Remove content
  2482.     for k in next,system.objects.image do
  2483.         tfm.exec.removeImage(k)
  2484.     end
  2485.    
  2486.     for k in next,system.objects.textarea do
  2487.         ui.removeTextArea(k,nil)
  2488.     end
  2489.    
  2490.     system.objects = {
  2491.         image = {},
  2492.         textarea = {}
  2493.     }
  2494.    
  2495.     ui.addPopup(0,0,"",nil,-1500,-1500)
  2496.    
  2497.     -- Unbind keyboard and mouse, also normalize color name and scores
  2498.     for k in next,tfm.get.room.playerList do
  2499.         for i = 0,255 do
  2500.             for v = 0,1 do
  2501.                 system.bindKeyboard(k,i,v == 0,false)
  2502.             end
  2503.         end
  2504.        
  2505.         system.bindMouse(k,false)
  2506.        
  2507.         tfm.exec.setNameColor(k,-1)
  2508.         tfm.exec.setPlayerScore(k,0)
  2509.     end
  2510.    
  2511.     -- Set admin back
  2512.     system.roomAdmins = system.setAdmins()
  2513.    
  2514.     -- Reset settings
  2515.     for k,v in next,{"AutoScore","WatchCommand","AutoNewGame","AutoShaman","AllShamanSkills","MortCommand","DebugCommand","MinimalistMode","AfkDeath","PhysicalConsumables","AutoTimeLeft"} do
  2516.         tfm.exec["disable" .. v](false)
  2517.     end
  2518.     tfm.exec.setAutoMapFlipMode()
  2519.    
  2520.     tfm.exec.setRoomMaxPlayers(25)
  2521.     tfm.exec.setRoomPassword("")   
  2522. end
  2523.  
  2524. --[[ Events ]]--
  2525. events = {}
  2526.  
  2527. events.eventLoop = function(currentTime,leftTime)
  2528.     _G.currentTime = normalizeTime(currentTime / 1e3)
  2529.     _G.leftTime = normalizeTime(leftTime / 1e3)
  2530. end
  2531.  
  2532. events.eventChatCommand = function(n,c)
  2533.     disableChatCommand(c)
  2534.     if module._FREEACCESS[n] then
  2535.         if c == "refresh" and (not system.isRoom or module._FREEACCESS[n] > 1) then
  2536.             eventModeChanged()
  2537.             system.init(true)
  2538.         elseif stringsub(c,1,4) == "room" and (not system.isRoom or module._FREEACCESS[n] > 1) then
  2539.             system.roomNumber = tonumber(stringsub(c,6)) or 0
  2540.             if _G["eventChatCommand"] then
  2541.                 eventChatCommand(n,"refresh")
  2542.             end
  2543.         elseif stringsub(c,1,4) == "load" and (not system.isRoom or module._FREEACCESS[n] > 2) then
  2544.             if os.time() > system.modeChanged and os.time() > system.newGameTimer then
  2545.                 local newMode = system.getGameMode(stringsub(c,6),true)
  2546.                 if newMode then
  2547.                     system.init(system.isRoom)
  2548.                 end
  2549.             end
  2550.         end
  2551.     end
  2552.     if stringsub(c,1,6) == "module" then
  2553.         c = stringupper(stringsub(c,8))
  2554.         if module["_" .. c] then
  2555.             tfm.exec.chatMessage(c .. " : " .. tableconcat(tableturnTable(module["_" .. c]),"\n",function(k,v)
  2556.                 return (c == "FREEACCESS" and stringformat("%s(%s)",k,v) or v)
  2557.             end),n)
  2558.         else
  2559.             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)
  2560.         end
  2561.     elseif c == "modes" then
  2562.         tfm.exec.chatMessage(tableconcat(system.submodes,"\n",function(k,v)
  2563.             return "#" .. v
  2564.         end),n)
  2565.     elseif c == "admin" then
  2566.         tfm.exec.chatMessage(tableconcat(system.roomAdmins,", ",tostring),n)
  2567.     elseif c == "stop" and system.roomAdmins[n] then
  2568.         system.exit()
  2569.     elseif stringsub(c,1,3) == "adm" and (system.roomAdmins[n] or module._FREEACCESS[n] > 2) then
  2570.         system.roomAdmins[stringnick(stringsub(c,5))] = true
  2571.     end
  2572. end
  2573.  
  2574. events.eventNewPlayer = function(n)
  2575.     tfm.exec.lowerSyncDelay(n)
  2576.    
  2577.     if system.officialMode[2] ~= "" then
  2578.         tfm.exec.chatMessage(system.officialMode[2],n)
  2579.     end
  2580. end
  2581.  
  2582. --[[ RoomSettings ]]--
  2583. system.roomSettings = {
  2584.     ["@"] = function(n)
  2585.         system.roomAdmins[stringnick(n)] = true
  2586.     end,
  2587.     ["#"] = function(id)
  2588.         system.miscAttrib = tonumber(id) or 1
  2589.         system.miscAttrib = mathsetLim(system.miscAttrib,1,99) -- mathmax(1,mathmin(system.miscAttrib,99))
  2590.     end,
  2591.     ["*"] = function(name)
  2592.         local game = system.getGameMode(name)
  2593.         if not game then
  2594.             system.gameMode = module._NAME
  2595.         end
  2596.     end
  2597. }
  2598. system.setRoom = function()
  2599.     if system.isRoom and system.roomAttributes then
  2600.         local chars = ""
  2601.         for k in next,system.roomSettings do
  2602.             chars = chars .. k
  2603.         end
  2604.  
  2605.         for char,value in stringgmatch(system.roomAttributes,"(["..chars.."])([^"..chars.."]+)") do
  2606.             value = stringmatch(value,"[^%s]+")
  2607.             for k,v in next,system.roomSettings do
  2608.                 if k == char then
  2609.                     v(value)
  2610.                     break
  2611.                 end
  2612.             end
  2613.         end
  2614.        
  2615.         local officialModes = {
  2616.             {"vanilla","<VP>Enjoy your vanilla (: .. okno"},
  2617.             {"survivor","<R>Aw, you cannot play survivor on #grounds"},
  2618.             {"racing","<CH>Uh, racing? Good luck!"},
  2619.             {"music","<BV>Music? Nice choice! Why don't you try a rock'n'roll?"},
  2620.             {"bootcamp","<PT>Bootcamp? Ok. This is unfair and your data won't be saved out of the room."},
  2621.             {"defilante","<R>Aw, you cannot play defilante on #grounds"},
  2622.             {"village","<R>You cannot play village on #grounds. Please, change your room."},
  2623.         }
  2624.         for k,v in next,officialModes do
  2625.             if stringfind(system.roomAttributes,v[1] .. "$") then
  2626.                 system.officialMode = {v[1],v[2]}
  2627.                 break
  2628.             end
  2629.         end
  2630.     end
  2631. end
  2632.  
  2633. --[[ Initialize ]]--
  2634. execute = {}
  2635. system.setRoom()
  2636.  
  2637. system.init = function(refresh)
  2638.     normalizeTranslation()
  2639.     mode[system.gameMode].init()
  2640.    
  2641.     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
  2642.         local e = "event" .. event
  2643.        
  2644.         local found = false
  2645.         for k,v in next,mode[system.gameMode] do
  2646.             if k == e then
  2647.                 execute[e] = v
  2648.                 found = true
  2649.                 break
  2650.             end
  2651.         end
  2652.         if not found then
  2653.             execute[e] = function() end
  2654.         end
  2655.  
  2656.         _G[e] = function(...)
  2657.             if events[e] then
  2658.                 events[e](...)
  2659.             end
  2660.             execute[e](...)
  2661.         end
  2662.     end
  2663.  
  2664.     if refresh then
  2665.         if mode[system.gameMode].reset then
  2666.             mode[system.gameMode].reset()
  2667.         end
  2668.     end
  2669.    
  2670.     if _G["eventNewPlayer"] then
  2671.         tableforeach(tfm.get.room.playerList,eventNewPlayer)
  2672.     end
  2673. end
  2674. system.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement