summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-04-18 15:23:05 -0400
committerShadowNinja <shadowninja@minetest.net>2015-04-18 15:23:54 -0400
commit7d8b5f3760200f90defe0f7ea705e12f94d9934d (patch)
tree3b34101c1eac4ab47492b67fd9e7d4a4f38018d6
parent8bb1c8288b45182ed8e1496d1ecc322ed84854a9 (diff)
Round home positions
-rw-r--r--api.lua35
1 files changed, 14 insertions, 21 deletions
diff --git a/api.lua b/api.lua
index d9e85e3..5f74ea7 100644
--- a/api.lua
+++ b/api.lua
@@ -68,43 +68,36 @@ end)
-- load_home
local function load_home()
local input = io.open(unified_inventory.home_filename, "r")
- if input then
- while true do
- 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")
- unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
- end
- io.close(input)
- else
+ if not input then
unified_inventory.home_pos = {}
+ return
end
+ while true do
+ local x = input:read("*n")
+ if not x then break end
+ local y = input:read("*n")
+ local z = input:read("*n")
+ local name = input:read("*l")
+ unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
+ end
+ io.close(input)
end
load_home()
function unified_inventory.set_home(player, pos)
local player_name = player:get_player_name()
- unified_inventory.home_pos[player_name] = pos
+ unified_inventory.home_pos[player_name] = vector.round(pos)
-- save the home data from the table to the file
local output = io.open(unified_inventory.home_filename, "w")
for k, v in pairs(unified_inventory.home_pos) do
- if v ~= nil then
- output:write(math.floor(v.x).." "
- ..math.floor(v.y).." "
- ..math.floor(v.z).." "
- ..k.."\n")
- end
+ output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
end
io.close(output)
end
function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()]
- if pos ~= nil then
+ if pos then
player:setpos(pos)
end
end