common player physics lockout mechanism added

This commit is contained in:
Joachim Stolberg 2020-06-23 17:33:45 +02:00
parent 1e4f161738
commit a5cfe4302d

@ -71,6 +71,8 @@ local function set_operator_privs(player, pos)
local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override()
local meta = player:get_meta()
-- Check access conflicts with other mods
if meta:get_int("player_physics_locked") == 0 then
if pos and meta and privs and physics then
meta:set_string("towercrane_pos", P2S(pos))
-- store the player privs default values
@ -79,14 +81,18 @@ local function set_operator_privs(player, pos)
meta:set_int("towercrane_speed", physics.speed)
-- set operator privs
meta:set_int("towercrane_isoperator", 1)
meta:set_int("player_physics_locked", 1)
privs["fly"] = true
privs["fast"] = nil
physics.speed = 0.7
-- write back
player:set_physics_override(physics)
minetest.set_player_privs(player:get_player_name(), privs)
return true
end
end
return false
end
local function reset_operator_privs(player)
local privs = minetest.get_player_privs(player:get_player_name())
@ -96,6 +102,7 @@ local function reset_operator_privs(player)
meta:set_string("towercrane_pos", "")
-- restore the player privs default values
meta:set_int("towercrane_isoperator", 0)
meta:set_int("player_physics_locked", 0)
privs["fast"] = meta:get_string("towercrane_fast") == "true" or nil
privs["fly"] = meta:get_string("towercrane_fly") == "true" or nil
physics.speed = meta:get_int("towercrane_speed")
@ -275,11 +282,12 @@ minetest.register_node("towercrane:mast_ctrl_off", {
on_rightclick = function (pos, node, clicker)
if is_my_crane(pos, clicker) and not is_operator(clicker) then
start_crane(pos, clicker)
set_operator_privs(clicker, pos)
if set_operator_privs(clicker, pos) then
local pos1, pos2 = calc_construction_area(pos)
-- control player every second
minetest.after(1, control_player, pos, pos1, pos2, clicker:get_player_name())
end
end
end,
on_construct = function(pos)