From a69d18e72e05eb39e5423896ba060b2463c043c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Sun, 29 May 2016 20:01:08 +0200 Subject: Fixed spawning --- spawns.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 spawns.lua (limited to 'spawns.lua') diff --git a/spawns.lua b/spawns.lua new file mode 100644 index 0000000..a05891b --- /dev/null +++ b/spawns.lua @@ -0,0 +1,47 @@ +local world_path = minetest.get_worldpath() +local org_file = world_path .. "/banish_spawns" +local file = world_path .. "/banish_spawns" +local bkwd = false + + +function banish.read_spawns() + local spawns = banish.spawn + local input = io.open(file, "r") + if input then + repeat + local x = input:read("*n") + if x == nil then + break + end + local y = input:read("*n") + local z = input:read("*n") + local name = input:read("*l") + spawns[name:sub(2)] = {x = x, y = y, z = z} + until input:read(0) == nil + io.close(input) + else + spawns = {} + end +end + +function banish.save_spawns() + if not banish.spawn then + return + end + local data = {} + local output = io.open(org_file, "w") + for k, v in pairs(banish.spawn) do + table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k)) + end + output:write(table.concat(data)) + io.close(output) +end + +function banish.set_spawns() + for name,_ in pairs(banish.player) do + local player = minetest.get_player_by_name(name) + local p = beds.spawn[name] + banish.spawn[name] = p + end + banish.save_spawns() +end -- cgit v1.2.3