mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-25 18:20:36 +01:00
fix tsm_pyramids error on load file if file corrupted
This commit is contained in:
parent
0984104080
commit
25a876e788
@ -35,13 +35,20 @@ code["t"] = "trap"
|
|||||||
|
|
||||||
function loadchests()
|
function loadchests()
|
||||||
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","r")
|
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","r")
|
||||||
if not file or file:read() == nil then return end
|
if file then
|
||||||
file:seek("set",0)
|
local saved_chests = minetest.deserialize(file:read())
|
||||||
pyramids.saved_chests = minetest.deserialize(file:read())
|
|
||||||
io.close(file)
|
io.close(file)
|
||||||
|
if savetable and type(saved_chests) == "table" then
|
||||||
minetest.log("action","[tsm_pyramids] Chest loaded")
|
minetest.log("action","[tsm_pyramids] Chest loaded")
|
||||||
|
return saved_chests
|
||||||
|
else
|
||||||
|
minetest.log("error","[tsm_pyramids] Loading Chest failed")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function savechests()
|
function savechests()
|
||||||
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","w")
|
local file = io.open(minetest.get_worldpath().."/pyramids_chests.txt","w")
|
||||||
if not file then return end -- should not happen
|
if not file then return end -- should not happen
|
||||||
@ -50,7 +57,7 @@ function savechests()
|
|||||||
minetest.log("action","[tsm_pyramids] Chests saved")
|
minetest.log("action","[tsm_pyramids] Chests saved")
|
||||||
end
|
end
|
||||||
|
|
||||||
loadchests()
|
pyramids.saved_chests = loadchests()
|
||||||
minetest.register_on_shutdown(function()
|
minetest.register_on_shutdown(function()
|
||||||
savechests()
|
savechests()
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user