From 7d8b5f3760200f90defe0f7ea705e12f94d9934d Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Sat, 18 Apr 2015 15:23:05 -0400 Subject: [PATCH] Round home positions --- api.lua | 35 ++++++++++++++--------------------- 1 file 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