Bolodefchoco_LUAXML

[Learning] Module Event Basis

Apr 1st, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.04 KB | None | 0 0
  1. --[[ Title ]]--
  2. title = {
  3.     [1] = "titre_Title name",
  4. }
  5.  
  6. --[[ Translations ]]--
  7. system.translation = {
  8.     -- At least EN, BR, ES, FR are needed, complementarily AR, PL, TR, RO, DE, RU
  9.     en = {
  10.         dataTry = "Wait! Your data is loading...",
  11.         dataFail = "Impossible to load your data :( Try again in the next map.",
  12.         dataSuccess = "Data loaded!",
  13.     },
  14.     br = {
  15.         dataTry = "Aguarde! Seus dados estão carregando...",
  16.         dataFail = "Impossível carregar seus dados :( Tente novamente no próximo mapa.",
  17.         dataSuccess = "Dados carregados!",
  18.     },
  19.     es = {
  20.         dataTry = "¡Espera! Tus datos se están cargando...",
  21.         dataFail = "No se pudieron cargar tus datos :( Prueba de nuevo en el siguiente mapa.",
  22.         dataSuccess = "¡Datos cargados!",
  23.     },
  24.     fr = {
  25.         dataTry = "Attends ! Tes données sont en train de charger...",
  26.         dataFail = "Impossible de charger vos données :( Essayez encore lors de la prochaine map.",
  27.         dataSuccess = "Données chargées !",
  28.     },
  29. }
  30. system.translation.pt = system.translation.br
  31.  
  32. system.community = tfm.get.room.community
  33. if not system.translation[system.community] then
  34.     system.community = "en"
  35. end
  36. system.community = system.translation[system.community]
  37.  
  38. --[[ Thanks ]]--
  39. system.staff = {
  40.     dev = {"Developer 1"},
  41.     translator = {"Translator 1"},
  42.     artist = {"Artist 1"},
  43. }
  44. for k,v in next,system.staff do
  45.     table.sort(v)
  46. end
  47.  
  48. --[[ Functions ]]--
  49.     --[[ Data ]]--
  50. serialization = function(x)
  51.     if type(x) == "table" then
  52.         local str = {}
  53.  
  54.         for index,value in next,x do
  55.             local v = type(value)
  56.  
  57.             local prefix = (v == "string" and "@" or v == "boolean" and "!" or v == "number" and "#" or v == "table" and "%" or "")
  58.             if prefix then
  59.                 local data
  60.                 if prefix == "@" then
  61.                     data = table.concat({string.byte(value,1,#value)},".")
  62.                 elseif prefix == "!" then
  63.                     data = (value and 1 or 0)
  64.                 elseif prefix == "#" then
  65.                     data = tostring(value)
  66.                 elseif prefix == "%" then
  67.                     data = string.format("{%s}",serialization(value):gsub(";","?"))
  68.                 end
  69.  
  70.                 str[#str + 1] = string.format(":%s%s%s;",index,prefix,data)
  71.             end
  72.         end
  73.  
  74.         return table.concat(str)
  75.     elseif type(x) == "string" then
  76.         local list = {}
  77.        
  78.         for str in x:gmatch("(.-);") do
  79.             local index,vtype,value = str:match(":(.-)(%p)(.+)")
  80.             if index and vtype and value then
  81.                 index = tonumber(index) or index
  82.  
  83.                 if vtype == "@" then
  84.                     local sub = {}
  85.                     for i in value:gmatch("[^%.]+") do
  86.                         sub[#sub+1] = i
  87.                     end
  88.                     list[index] = string.char(table.unpack(sub))
  89.                 elseif vtype == "!" then
  90.                     list[index] = (value == "1")
  91.                 elseif vtype == "#" then
  92.                     list[index] = tonumber(value)
  93.                 elseif vtype == "%" then
  94.                     list[index] = serialization(value:gsub("{",""):gsub("}",""):gsub("%?",";"))
  95.                 end
  96.             end
  97.         end
  98.  
  99.         return list
  100.     end
  101. end
  102. eventPlayerDataLoading = function(n,tentative)
  103.     -- Avoids data replacement and error
  104.     if tentative < 4 then
  105.         local loadingData = system.loadPlayerData(n)
  106.         if loadingData then
  107.             tfm.exec.chatMessage("<G>" .. system.community.dataTry,n)
  108.         else
  109.             eventPlayerDataLoading(n,tentative + 1)
  110.         end
  111.     else
  112.         tfm.exec.killPlayer(n)
  113.         tfm.exec.chatMessage("<G>" .. system.community.dataFail,n)
  114.     end
  115. end
  116. eventPlayerDataLoaded = function(n,data)
  117.     if data ~= "" and data:find(":allowTitle") then -- ":allowTitle" refers to the info[playerName].db.allowTitle var
  118.         info[n].db = serialization(data)
  119.     else
  120.         system.savePlayerData(n,serialization(info[n].db))
  121.     end
  122.    
  123.     info[n].dataLoaded = true
  124.     tfm.exec.chatMessage("<G>" .. system.community.dataSuccess,n)
  125.    
  126.     -- TODO Data Loaded
  127. end
  128. system.giveTitle = function(n,id)
  129.     -- Use system.giveTitle instead of system.giveEventGift
  130.     if title[id] and info[n] then
  131.         if info[n].dataLoaded and info[n].db.allowTitle then
  132.             system.giveEventGift(n,title[id])
  133.             info[n].db.allowTitle = false
  134.             system.savePlayerData(n,serialization(info[n].db))
  135.             return true
  136.         end
  137.         return false
  138.     end
  139.     return false
  140. end
  141.            
  142.  
  143.     --[[ Others ]]--
  144. os.normalizedTime = function(time)
  145.     return math.floor(time) + ((time - math.floor(time)) >= .5 and .5 or 0)
  146. end
  147.  
  148. --[[ New Game ]]--
  149. info = {} -- Hosts the data of the players
  150. eventNewGame = function()
  151.     -- TODO New Game
  152.     for k,v in next,tfm.get.room.playerList do
  153.         info[k] = {
  154.             -- TODO Data
  155.             dataLoaded = false,
  156.  
  157.             db = {
  158.                 -- TODO Data to Save
  159.                 allowTitle = true,
  160.             }
  161.         }
  162.        
  163.         eventPlayerDataLoading(k,1)
  164.     end
  165. end
  166.  
  167. --[[ Loop ]]--
  168. eventLoop = function(currentTime,timeLeft)
  169.     _G.currentTime = os.normalizedTime(currentTime/1000) -- [Global] Current time in seconds; 0.5 by 0.5
  170.     _G.timeLeft = os.normalizedTime(timeLeft/1000) -- [Global] Time left in seconds; 0.5 by 0.5
  171.     -- TODO Loop
  172. end
  173.  
  174. --[[ Left ]]--
  175. eventPlayerLeft = function(n)
  176.     if info[n] then
  177.         system.savePlayerData(n,serialization(info[n].db))
  178.     end
  179. end
  180.  
  181. --[[ Init ]]--
  182. for i,f in next,{"AutoShaman","AfkDeath","AutoTimeLeft","MortCommand","PhysicalConsumables","DebugCommand"} do
  183.     -- Edit the functions
  184.     tfm.exec["disable"..f]()
  185. end
  186.  
  187. system.map = '<C><P /><Z><S /><D /><O /></Z></C>'
  188. tfm.exec.newGame(system.map)
Add Comment
Please, Sign In to add comment