From 9dcb4e65ba1b579c75bc9603e404e9cb47a34f58 Mon Sep 17 00:00:00 2001 From: Bruno Borges Date: Tue, 4 Jan 2022 11:34:44 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20mod=20storage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- oficios/banco_de_dados.lua | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/oficios/banco_de_dados.lua b/oficios/banco_de_dados.lua index 0ed0246..d035ec1 100644 --- a/oficios/banco_de_dados.lua +++ b/oficios/banco_de_dados.lua @@ -11,27 +11,35 @@ oficios.bd = {} +-- Mod storage +local mod_storage = minetest.get_mod_storage() + -- Variavel de registros registros_oficios = {} -- Carregar registros de oficios salvos -local path = minetest.get_worldpath() .. "/oficios" +--local path = minetest.get_worldpath() .. "/oficios" -- Cria o diretorio caso nao exista ainda -local function mkdir(path) - if minetest.mkdir then - minetest.mkdir(path) - else - os.execute('mkdir "' .. path .. '"') - end -end -mkdir(path) +--local function mkdir(path) +-- if minetest.mkdir then +-- minetest.mkdir(path) +-- else +-- os.execute('mkdir "' .. path .. '"') +-- end +--end +--mkdir(path) + +-- Carrega dados na tabela quando o jogador conecta minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - local input = io.open(path .. "/oficios_"..name, "r") - if input then - registros_oficios[name] = minetest.deserialize(input:read("*l")) - io.close(input) - end + + registros_oficios[name] = minetest.deserialize(mod_storage:get_string("player:"..name)) + + --local input = io.open(path .. "/oficios_"..name, "r") + --if input then + -- registros_oficios[name] = minetest.deserialize(input:read("*l")) + -- io.close(input) + --end end) -- Retira da memoria quando o jogador sai @@ -42,9 +50,10 @@ end) -- Salvar registros de oficios oficios.bd.salvar = function(name) - local output = io.open(path .. "/oficios_"..name, "w") - output:write(minetest.serialize(registros_oficios[name])) - io.close(output) + mod_storage:set_string("player:"..name, minetest.serialize(registros_oficios[name])) + --local output = io.open(path .. "/oficios_"..name, "w") + --output:write(minetest.serialize(registros_oficios[name])) + --io.close(output) end -- Inserir registro