mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-05 18:10:26 +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()
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user