Add tardis.count to serialization.

entity
Benrob0329 2017-07-27 19:13:28 -04:00
parent fbae8636b4
commit eb63ad96fd
2 changed files with 20 additions and 6 deletions

View File

@ -17,9 +17,9 @@ end
-- Spawn a TARDIS and set the controls/doors meta with relative coordinates
function tardis:spawn_interior (pos, owner)
local place_pos = {
x = tardis.count * 12 ,
y = 30000 ,
z = 0 ,
x = tardis.count * 12,
y = 30000,
z = 0,
}
tardis.count = tardis.count + 1
local interior_doors_pos = {
@ -58,9 +58,13 @@ function tardis:spawn_interior (pos, owner)
minetest.log("info", minetest.pos_to_string (tardis.tardises [owner]["interior"] ))
local file = io.open (worldpath .. "/tardis.tardises", "w+")
file:write ( minetest.serialize (tardis.tardises) )
file:close()
local count_file = io.open (worldpath .. "/tardis.tardises", "w+")
count_file:write ( minetest.serialize (tardis.count) )
count_file:close()
local count_file = io.open(worldpath .. "/tardis.count", "w+")
count_file:write(minetest.serialize(tardis.count))
count_file:close()
end

View File

@ -14,6 +14,7 @@ dofile (modpath .. "/nodes.lua")
-- Open TARDIS index from file
local file = io.open (worldpath .. "/tardis.tardises", "r")
local count_file = io.open (worldpath .. "/tardis.count", "r")
-- If file exists, write into current index
if file then
@ -21,6 +22,11 @@ if file then
file:close()
end
if count_file then
tardis.count = minetest.deserialize (count_file:read("*all"))
count_file:close()
end
-- Register chatcommand to set navigation, return a help message if user doe not own a TARDIS
minetest.register_chatcommand ("set_nav", {
description = "Sets the navigation coordinates for your TARDIS.",
@ -41,4 +47,8 @@ minetest.register_on_shutdown( function()
local file = io.open (worldpath .. "/tardis.tardises", "w+")
file:write(minetest.serialize (tardis.tardises) )
file:close()
local count_file = io.open(worldpath .. "/tardis.count", "w+")
count_file:write(minetest.serialize(tardis.count))
count_file:close()
end )