1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-06-29 15:20:19 +02:00

fix tsm_pyramids error on load file if file corrupted

This commit is contained in:
crabman77 2015-08-06 00:26:00 +02:00
parent 0984104080
commit 25a876e788

View File

@ -35,13 +35,20 @@ code["t"] = "trap"
function loadchests()
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","r")
if not file or file:read() == nil then return end
file:seek("set",0)
pyramids.saved_chests = minetest.deserialize(file:read())
io.close(file)
minetest.log("action","[tsm_pyramids] Chest loaded")
if file then
local saved_chests = minetest.deserialize(file:read())
io.close(file)
if savetable and type(saved_chests) == "table" then
minetest.log("action","[tsm_pyramids] Chest loaded")
return saved_chests
else
minetest.log("error","[tsm_pyramids] Loading Chest failed")
end
end
return {}
end
function savechests()
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","w")
if not file then return end -- should not happen
@ -50,7 +57,7 @@ function savechests()
minetest.log("action","[tsm_pyramids] Chests saved")
end
loadchests()
pyramids.saved_chests = loadchests()
minetest.register_on_shutdown(function()
savechests()
end)