mirror of
https://github.com/minetest-mods/towercrane.git
synced 2024-11-22 07:13:52 +01:00
Add player_monoids support (#15)
This commit is contained in:
parent
c0cd005c4b
commit
af87d6278c
39
control.lua
39
control.lua
@ -10,6 +10,7 @@
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
local DAYS_WITHOUT_USE = 72 * 5
|
local DAYS_WITHOUT_USE = 72 * 5
|
||||||
|
local mod_player_monoids = minetest.get_modpath("player_monoids")
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||||
@ -69,25 +70,30 @@ end
|
|||||||
|
|
||||||
local function set_operator_privs(player, pos)
|
local function set_operator_privs(player, pos)
|
||||||
local privs = minetest.get_player_privs(player:get_player_name())
|
local privs = minetest.get_player_privs(player:get_player_name())
|
||||||
local physics = player:get_physics_override()
|
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
-- Check access conflicts with other mods
|
-- Check access conflicts with other mods
|
||||||
if meta:get_int("player_physics_locked") == 0 then
|
if meta:get_int("player_physics_locked") == 0 then
|
||||||
if pos and meta and privs and physics then
|
if pos and meta and privs then
|
||||||
meta:set_string("towercrane_pos", P2S(pos))
|
meta:set_string("towercrane_pos", P2S(pos))
|
||||||
-- store the player privs default values
|
-- store the player privs default values
|
||||||
meta:set_string("towercrane_fast", privs["fast"] and "true" or "false")
|
meta:set_string("towercrane_fast", privs["fast"] and "true" or "false")
|
||||||
meta:set_string("towercrane_fly", privs["fly"] and "true" or "false")
|
meta:set_string("towercrane_fly", privs["fly"] and "true" or "false")
|
||||||
meta:set_int("towercrane_speed", physics.speed)
|
|
||||||
-- set operator privs
|
-- set operator privs
|
||||||
meta:set_int("towercrane_isoperator", 1)
|
meta:set_int("towercrane_isoperator", 1)
|
||||||
meta:set_int("player_physics_locked", 1)
|
meta:set_int("player_physics_locked", 1)
|
||||||
privs["fly"] = true
|
privs["fly"] = true
|
||||||
privs["fast"] = nil
|
privs["fast"] = nil
|
||||||
physics.speed = 0.7
|
|
||||||
-- write back
|
|
||||||
player:set_physics_override(physics)
|
|
||||||
minetest.set_player_privs(player:get_player_name(), privs)
|
minetest.set_player_privs(player:get_player_name(), privs)
|
||||||
|
|
||||||
|
if mod_player_monoids then
|
||||||
|
player_monoids.speed:add_change(player, 0.7, "towercrane:crane")
|
||||||
|
else
|
||||||
|
local physics = player:get_physics_override()
|
||||||
|
meta:set_int("towercrane_speed", physics.speed)
|
||||||
|
physics.speed = 0.7
|
||||||
|
-- write back
|
||||||
|
player:set_physics_override(physics)
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -96,24 +102,29 @@ end
|
|||||||
|
|
||||||
local function reset_operator_privs(player)
|
local function reset_operator_privs(player)
|
||||||
local privs = minetest.get_player_privs(player:get_player_name())
|
local privs = minetest.get_player_privs(player:get_player_name())
|
||||||
local physics = player:get_physics_override()
|
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
if meta and privs and physics then
|
if meta and privs then
|
||||||
meta:set_string("towercrane_pos", "")
|
meta:set_string("towercrane_pos", "")
|
||||||
-- restore the player privs default values
|
-- restore the player privs default values
|
||||||
meta:set_int("towercrane_isoperator", 0)
|
meta:set_int("towercrane_isoperator", 0)
|
||||||
meta:set_int("player_physics_locked", 0)
|
meta:set_int("player_physics_locked", 0)
|
||||||
privs["fast"] = meta:get_string("towercrane_fast") == "true" or nil
|
privs["fast"] = meta:get_string("towercrane_fast") == "true" or nil
|
||||||
privs["fly"] = meta:get_string("towercrane_fly") == "true" or nil
|
privs["fly"] = meta:get_string("towercrane_fly") == "true" or nil
|
||||||
physics.speed = meta:get_int("towercrane_speed")
|
minetest.set_player_privs(player:get_player_name(), privs)
|
||||||
if physics.speed == 0 then physics.speed = 1 end
|
|
||||||
-- delete stored default values
|
-- delete stored default values
|
||||||
meta:set_string("towercrane_fast", "")
|
meta:set_string("towercrane_fast", "")
|
||||||
meta:set_string("towercrane_fly", "")
|
meta:set_string("towercrane_fly", "")
|
||||||
meta:set_string("towercrane_speed", "")
|
|
||||||
-- write back
|
if mod_player_monoids then
|
||||||
player:set_physics_override(physics)
|
player_monoids.speed:del_change(player, "towercrane:crane")
|
||||||
minetest.set_player_privs(player:get_player_name(), privs)
|
else
|
||||||
|
local physics = player:get_physics_override()
|
||||||
|
physics.speed = meta:get_int("towercrane_speed")
|
||||||
|
meta:set_string("towercrane_speed", "")
|
||||||
|
if physics.speed == 0 then physics.speed = 1 end
|
||||||
|
-- write back
|
||||||
|
player:set_physics_override(physics)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
1
mod.conf
1
mod.conf
@ -1,3 +1,4 @@
|
|||||||
name = towercrane
|
name = towercrane
|
||||||
depends = default
|
depends = default
|
||||||
|
optional_depends = player_monoids
|
||||||
description = A crane for easier construction of buildings. The crane forms a working area in which the player gets fly privs.
|
description = A crane for easier construction of buildings. The crane forms a working area in which the player gets fly privs.
|
Loading…
Reference in New Issue
Block a user