Correção mod storage

master
Bruno Borges 2022-01-04 11:34:44 -03:00
parent 0407673c1f
commit 9dcb4e65ba
1 changed files with 26 additions and 17 deletions

View File

@ -11,27 +11,35 @@
oficios.bd = {} oficios.bd = {}
-- Mod storage
local mod_storage = minetest.get_mod_storage()
-- Variavel de registros -- Variavel de registros
registros_oficios = {} registros_oficios = {}
-- Carregar registros de oficios salvos -- Carregar registros de oficios salvos
local path = minetest.get_worldpath() .. "/oficios" --local path = minetest.get_worldpath() .. "/oficios"
-- Cria o diretorio caso nao exista ainda -- Cria o diretorio caso nao exista ainda
local function mkdir(path) --local function mkdir(path)
if minetest.mkdir then -- if minetest.mkdir then
minetest.mkdir(path) -- minetest.mkdir(path)
else -- else
os.execute('mkdir "' .. path .. '"') -- os.execute('mkdir "' .. path .. '"')
end -- end
end --end
mkdir(path) --mkdir(path)
-- Carrega dados na tabela quando o jogador conecta
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local input = io.open(path .. "/oficios_"..name, "r")
if input then registros_oficios[name] = minetest.deserialize(mod_storage:get_string("player:"..name))
registros_oficios[name] = minetest.deserialize(input:read("*l"))
io.close(input) --local input = io.open(path .. "/oficios_"..name, "r")
end --if input then
-- registros_oficios[name] = minetest.deserialize(input:read("*l"))
-- io.close(input)
--end
end) end)
-- Retira da memoria quando o jogador sai -- Retira da memoria quando o jogador sai
@ -42,9 +50,10 @@ end)
-- Salvar registros de oficios -- Salvar registros de oficios
oficios.bd.salvar = function(name) oficios.bd.salvar = function(name)
local output = io.open(path .. "/oficios_"..name, "w") mod_storage:set_string("player:"..name, minetest.serialize(registros_oficios[name]))
output:write(minetest.serialize(registros_oficios[name])) --local output = io.open(path .. "/oficios_"..name, "w")
io.close(output) --output:write(minetest.serialize(registros_oficios[name]))
--io.close(output)
end end
-- Inserir registro -- Inserir registro