Round home positions

This commit is contained in:
ShadowNinja 2015-04-18 15:23:05 -04:00
parent 8bb1c8288b
commit 7d8b5f3760

35
api.lua
View File

@ -68,43 +68,36 @@ end)
-- load_home -- load_home
local function load_home() local function load_home()
local input = io.open(unified_inventory.home_filename, "r") local input = io.open(unified_inventory.home_filename, "r")
if input then if not 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
unified_inventory.home_pos = {} unified_inventory.home_pos = {}
return
end 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 end
load_home() load_home()
function unified_inventory.set_home(player, pos) function unified_inventory.set_home(player, pos)
local player_name = player:get_player_name() 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 -- save the home data from the table to the file
local output = io.open(unified_inventory.home_filename, "w") local output = io.open(unified_inventory.home_filename, "w")
for k, v in pairs(unified_inventory.home_pos) do for k, v in pairs(unified_inventory.home_pos) do
if v ~= nil then output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
output:write(math.floor(v.x).." "
..math.floor(v.y).." "
..math.floor(v.z).." "
..k.."\n")
end
end end
io.close(output) io.close(output)
end end
function unified_inventory.go_home(player) function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()] local pos = unified_inventory.home_pos[player:get_player_name()]
if pos ~= nil then if pos then
player:setpos(pos) player:setpos(pos)
end end
end end