From db932e676c687b32386077c20f273171ad2a8d10 Mon Sep 17 00:00:00 2001 From: TenPlus1 Date: Sat, 25 Apr 2020 09:02:46 +0100 Subject: [PATCH] added playerfactions support, protecor_hud_interval and settings update --- README.md | 1 + depends.txt | 1 + hud.lua | 6 +++++- init.lua | 29 +++++++++++++++++++++++++++++ settingtypes.txt | 26 ++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 settingtypes.txt diff --git a/README.md b/README.md index 9c79d39..009779e 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Change log: - 2.7 - Remove protection field entity when protector has been dug - 2.8 - Added 'protector_show_interval' setting to minetest.conf [default is 5], make protection field glow in dark. - 2.9 - Added MineClone2 recipes for protection block but no official support as yet +- 3.0 - Added PlayerFactions support, 'protector_hud_interval' setting and listing in advanced settings for mod values. Lucky Blocks: 10 diff --git a/depends.txt b/depends.txt index f1e9655..5b09c28 100644 --- a/depends.txt +++ b/depends.txt @@ -2,3 +2,4 @@ default? intllib? lucky_block? mesecons_mvps? +playerfactions? diff --git a/hud.lua b/hud.lua index 7a334f3..6b70e71 100644 --- a/hud.lua +++ b/hud.lua @@ -3,12 +3,14 @@ local S = protector.intllib local radius = (tonumber(minetest.setting_get("protector_radius")) or 5) local hud = {} local hud_timer = 0 +local hud_interval = (tonumber(minetest.setting_get("protector_hud_interval")) or 5) +if hud_interval > 0 then minetest.register_globalstep(function(dtime) -- every 5 seconds hud_timer = hud_timer + dtime - if hud_timer < 5 then + if hud_timer < hud_interval then return end hud_timer = 0 @@ -57,3 +59,5 @@ end) minetest.register_on_leaveplayer(function(player) hud[player:get_player_name()] = nil end) + +end diff --git a/init.lua b/init.lua index f8b8e21..22bff1f 100644 --- a/init.lua +++ b/init.lua @@ -13,6 +13,8 @@ local MP = minetest.get_modpath(minetest.get_current_modname()) local S = dofile(MP .. "/intllib.lua") local F = minetest.formspec_escape +-- Load support for factions +local factions_available = minetest.global_exists("factions") protector = { mod = "redo", @@ -58,6 +60,15 @@ end -- check for member name local is_member = function (meta, name) + if factions_available + and meta:get_int("faction_members") == 1 + and factions.get_player_faction(name) ~= nil + and factions.get_player_faction(meta:get_string("owner")) == + factions.get_player_faction(name) then + + return true + end + for _, n in pairs(get_member_list(meta)) do if n == name then @@ -129,6 +140,19 @@ local protector_formspec = function(meta) local npp = protector_max_share_count -- max users added to protector list local i = 0 + if factions_available + and factions.get_player_faction(meta:get_string("owner")) then + + formspec = formspec .. "checkbox[0,5;faction_members;" + .. F(S("Allow faction access")) + .. ";" .. (meta:get_int("faction_members") == 1 and + "true" or "false") .. "]" + + if npp > 8 then + npp = 8 + end + end + for n = 1, #members do if i < npp then @@ -613,6 +637,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) return end + -- add faction members + if factions_available then + meta:set_int("faction_members", fields.faction_members == "true" and 1 or 0) + end + -- add member [+] if add_member_input then diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..cbdc11b --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,26 @@ +# Size of protected area around protection node limiting player interaction +protector_radius (Protector Radius) int 5 + +# Flips player around when accessing protected area to stop lag griefing +protector_flip (Protector Flip) bool false + +# Hurts player by amount entered when accessing protected area, 0 to disable +protector_hurt (Protector Hurt) int 0 + +# Sets a protected area around spawn by node radius given +protector_spawn (Protector Spawn) int 0 + +# Enables PVP inside of protected areas +protector_pvp (Protector PVP) bool false + +# When true will allow PVP inside protected spawn area +protector_pvp_spawn (Protector PVP Spawn) int 0 + +# When true will allow PVP inside all protected areas at night time only +protector_night_pvp (Protector Night PVP) bool false + +# Interval in seconds that protection field is shown +protector_show_interval (Protector Show Interval) int 5 + +# Interval in seconds that HUD ownership text is updated, 0 to disable +protector_hud_interval (Protector HUD Interval) int 5