Browse Source

initialize player status on join

main
Hendrik Langer 3 years ago
parent
commit
0a5b736f23
  1. 11
      init.lua
  2. 5
      player.lua

11
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

5
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)

Loading…
Cancel
Save