From 0a5b736f23d18cfb4a4a7eaf4bb421fdcf7261bf Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 26 Nov 2021 17:46:12 +0100 Subject: [PATCH] initialize player status on join --- init.lua | 11 ++++++++--- player.lua | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index 000335e..181f6b4 100644 --- a/init.lua +++ b/init.lua @@ -22,7 +22,7 @@ dofile(creative_regions.modpath.."/arena.lua") dofile(creative_regions.modpath.."/vehicles.lua") -function creative_regions:update_player(player) +function creative_regions:update_player(player, initialize) local name = player:get_player_name() local pos = vector.round(player:get_pos()) @@ -35,6 +35,7 @@ function creative_regions:update_player(player) local areas_guest = false local areas_open = false local areas_individual_override = false + initialize = initialize or 0 -- skip for players with protection_bypass if minetest.check_player_privs(name, { protection_bypass=true }) then @@ -98,8 +99,8 @@ function creative_regions:update_player(player) -- did the regions change? update -- ToDo: Update on privileges changed local player_last_active_region_str = pmeta:get_string("creative_regions.active_regions") or "" - if player_active_region_str ~= player_last_active_region_str then - creative_regions:player_enter_region(player, new_privs_table) + if player_active_region_str ~= player_last_active_region_str or initialize then + creative_regions:player_enter_region(player, new_privs_table, initialize) pmeta:set_string("creative_regions.active_regions", player_active_region_str) end @@ -109,6 +110,10 @@ end creative_regions.load_regions() +minetest.register_on_joinplayer(function(player) + creative_regions:update_player(player, 1) +end) + local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime diff --git a/player.lua b/player.lua index 115b266..41a3b51 100644 --- a/player.lua +++ b/player.lua @@ -56,10 +56,11 @@ function creative_regions:restore_player_inventory(player, listname) end end -function creative_regions:player_enter_region(player, new_privs_table) +function creative_regions:player_enter_region(player, new_privs_table, initialize) local name = player:get_player_name() local has_creative = minetest.check_player_privs(name, {creative=true}) local has_arena = minetest.check_player_privs(name, {arena=true}) + initialize = initialize or 0 local old_mode = nil if has_arena then @@ -96,7 +97,7 @@ function creative_regions:player_enter_region(player, new_privs_table) end end - if new_mode ~= old_mode then + if new_mode ~= old_mode or initialize then if old_mode == "arena" then -- leaving arena (alive)