clean up after players who left

This commit is contained in:
whosit 2021-05-18 10:15:44 +03:00
parent bc9040d551
commit 3ee54fb685

View File

@ -1,4 +1,3 @@
local player_waypoints = {}
local update_interval = 1.31415
local compass_precision = 10 -- set to 1 to show whole number or 10 for 1 decimal
local default_waypoint_color = 0xFFFFFF
@ -7,10 +6,10 @@ local point_to_objects = false -- unimplemented
local point_to_liquids = true
local compass_range = 180
-- lua metatables? what is that? :P
-- local function get_compass_meta_id(meta)
-- return meta:get_string("waypoint_compass:id") ~= "" or "default_id"
-- end
-- internal mod state
local player_waypoints = {} -- store a current player waypoint to see if it needs to be updated
local compass_dialog_context = {} -- store a compass item that player is editing via dialog
local function set_compass_meta_label(meta, label)
@ -188,6 +187,16 @@ minetest.register_globalstep(function(dtime)
end)
minetest.register_on_leaveplayer(function(player, timed_out)
local player_name = player:get_player_name()
if player_name ~= "" then
-- delete info about players that are left
player_waypoints[player_name] = nil
compass_dialog_context[player_name] = nil
end
end)
local function coords_to_string(pos)
-- strip "()"
if not pos then
@ -210,8 +219,6 @@ local function coords_from_string(str)
end
local compass_dialog_context = {}
local function show_basic_dialog(itemstack, player)
local meta = itemstack:get_meta()
-- set focus to "close" button to preven accidental edting