mirror of
https://github.com/minetest-mods/player_monoids.git
synced 2025-01-09 17:10:19 +01:00
Make monoids remove players from themselves on leave
This commit is contained in:
parent
3b3904d1d6
commit
a5c5184933
19
init.lua
19
init.lua
@ -4,10 +4,9 @@
|
||||
-- Any documentation here are internal details, please avoid using them in your
|
||||
-- mod.
|
||||
|
||||
player_monoids = {}
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
-- Needed for removing players from monoid lists when they leave.
|
||||
local player_maps = {}
|
||||
player_monoids = {}
|
||||
|
||||
local mon_meta = {}
|
||||
|
||||
@ -22,14 +21,22 @@ mon_meta.__index = mon_meta
|
||||
local function monoid(def)
|
||||
local mon = {}
|
||||
|
||||
local player_map = {}
|
||||
mon.players = player_map
|
||||
table.insert(player_maps, player_map)
|
||||
local p_map = {}
|
||||
mon.player_map = p_map
|
||||
|
||||
mon.next_id = 1
|
||||
|
||||
local v_cache = {}
|
||||
mon.value_cache = v_cache
|
||||
|
||||
setmetatable(mon, mon_methods)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local p_name = player:get_player_name()
|
||||
p_map[p_name] = nil
|
||||
v_cache[p_name] = nil
|
||||
end)
|
||||
|
||||
return mon
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user