From 7cb2f688a6004f6cad0bb03224d3cc642a81b8b9 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sun, 5 May 2019 13:41:24 -0500 Subject: [PATCH 1/6] Put: depends and description in mod.conf --- depends.txt | 5 ----- description.txt | 1 - mod.conf | 3 +++ 3 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 depends.txt delete mode 100644 description.txt diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 2446a29..0000000 --- a/depends.txt +++ /dev/null @@ -1,5 +0,0 @@ -default? -doors? -xdecor? -colddb -ts_doors? diff --git a/description.txt b/description.txt deleted file mode 100644 index 0ccb54c..0000000 --- a/description.txt +++ /dev/null @@ -1 +0,0 @@ -Mod for handling in game factions and reputation. \ No newline at end of file diff --git a/mod.conf b/mod.conf index fc2cf80..28d1621 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,4 @@ name = factions +description = Mod for handling in game factions and reputation. +depends = colddb +optional_depends = default, doors, xdecor, ts_doors From 1d57b3d0afe3f6a1cdc8df848c68b2579ab5db81 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sun, 5 May 2019 17:23:45 -0500 Subject: [PATCH 2/6] Return: default metadata on move, take, put --- chatcommands.lua | 2 +- config.lua | 29 -------------------- factions.lua | 2 +- hud.lua | 4 +-- nodes.lua | 69 ++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 59 insertions(+), 47 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 0a96c24..07d5406 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -109,7 +109,7 @@ factions.register_command = function(cmd_name, cmd, ignore_param_count, or_perm, end -- get some more data - local pos = minetest.get_player_by_name(player):getpos() + local pos = minetest.get_player_by_name(player):get_pos() local parcelpos = factions.get_parcel_pos(pos) return self.on_success(player, player_faction, pos, parcelpos, args) end, diff --git a/config.lua b/config.lua index 6656b0f..a1c4cac 100644 --- a/config.lua +++ b/config.lua @@ -1,6 +1,4 @@ factions_config = {} --- If you want to hardcode the config settings just delete settingstypes.txt, and the line up to END. And then uncomment the hardcoded settings below and change it to whatever you want. --- settingstypes local flip = tonumber(minetest.settings:get("protection_max_depth")) or 512 factions_config.protection_max_depth = -flip factions_config.protection_max_height = tonumber(minetest.settings:get("protection_max_height")) or 10000 @@ -25,30 +23,3 @@ factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomac factions_config.spawn_teleport = minetest.settings:get_bool("spawn_teleport") or false factions_config.protection_style = minetest.settings:get("protection_style") or "2d" factions_config.faction_user_priv = minetest.settings:get("faction_user_priv") or false --- END ---[[ --- hardcoded config settings -factions_config.protection_max_depth = -512 -factions_config.protection_max_height = 10000 -factions_config.power_per_parcel = 1 -factions_config.power_per_death = 1 -factions_config.power_per_tick = 2 -factions_config.tick_time = 60 -factions_config.power_per_attack = 10 -factions_config.faction_name_max_length = 50 -factions_config.rank_name_max_length = 25 -factions_config.maximum_faction_inactivity = 604800 -factions_config.maximum_parcelless_faction_time = 10800 -factions_config.power = 12 -factions_config.maxpower = 0 -factions_config.power_per_player = 1 -factions_config.powermax_per_player = 12 -factions_config.parcel_size = 16 -factions_config.protection_depth_height_limit = true -factions_config.enable_power_per_player = true -factions_config.attack_parcel = false -factions_config.faction_diplomacy = true -factions_config.spawn_teleport = false -factions_config.protection_style = "2d" -factions_config.faction_user_priv = false ---]] \ No newline at end of file diff --git a/factions.lua b/factions.lua index 95ab891..2f5cf27 100644 --- a/factions.lua +++ b/factions.lua @@ -489,7 +489,7 @@ end function factions.get_faction_at(pos) local y = pos.y if factions_config.protection_depth_height_limit and (pos.y < factions_config.protection_max_depth or pos.y > factions_config.protection_max_height) then - return nil + return nil end local parcelpos = factions.get_parcel_pos(pos) return factions.get_parcel_faction(parcelpos) diff --git a/hud.lua b/hud.lua index 8feb527..567b71f 100644 --- a/hud.lua +++ b/hud.lua @@ -112,7 +112,7 @@ function hudUpdateClaimInfo() for i in pairs(playerslist) do local player = playerslist[i] local name = player:get_player_name() - local faction, facname = factions.get_faction_at(player:getpos()) + local faction, facname = factions.get_faction_at(player:get_pos()) local id_name = name .. "factionLand" if hud_ids[id_name] then @@ -124,4 +124,4 @@ function hudUpdateClaimInfo() end end minetest.after(3, hudUpdateClaimInfo) -end \ No newline at end of file +end diff --git a/nodes.lua b/nodes.lua index 467f3d5..b31ec20 100644 --- a/nodes.lua +++ b/nodes.lua @@ -30,6 +30,7 @@ if minetest.registered_nodes["default:chest"] then end end }) + local dc = minetest.registered_nodes["default:chest"] local def_on_rightclick = dc.on_rightclick @@ -43,37 +44,77 @@ if minetest.registered_nodes["default:chest"] then name .. ")") end end + local can_dig = function(pos, player) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("main") and factions.can_use_node(pos, player:get_player_name(), "container") end - local allow_metadata_inventory_move = function(pos, from_list, from_index, - to_list, to_index, count, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + + local allow_metadata_inventory_move + local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move + if def_allow_metadata_inventory_move then + allow_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) end - return count - end - local allow_metadata_inventory_put = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + else + allow_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return count end - return stack:get_count() end - local allow_metadata_inventory_take = function(pos, listname, index, stack, player) - if not factions.can_use_node(pos, player:get_player_name(), "container") then - return 0 + + local allow_metadata_inventory_put + local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put + if def_allow_metadata_inventory_put then + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_put(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_put = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return stack:get_count() end - return stack:get_count() end + + local allow_metadata_inventory_take + local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take + if def_allow_metadata_inventory_take then + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return def_allow_metadata_inventory_take(pos, listname, index, stack, player) + end + else + allow_metadata_inventory_take = function(pos, listname, index, stack, player) + if not factions.can_use_node(pos, player:get_player_name(), "container") then + return 0 + end + return stack:get_count() + end + end + local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not factions.can_use_node(pos, clicker:get_player_name(), "container") then return itemstack end return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing) end + minetest.override_item("default:chest", {after_place_node = after_place_node, can_dig = can_dig, allow_metadata_inventory_move = allow_metadata_inventory_move, From 5b4eee252fb64cb8a94b6eb964256d59929cf8df Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Mon, 6 May 2019 12:30:44 -0500 Subject: [PATCH 3/6] Do: not change the sign of max_depth --- config.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config.lua b/config.lua index a1c4cac..4a5aee9 100644 --- a/config.lua +++ b/config.lua @@ -1,6 +1,5 @@ factions_config = {} -local flip = tonumber(minetest.settings:get("protection_max_depth")) or 512 -factions_config.protection_max_depth = -flip +factions_config.protection_max_depth = tonumber(minetest.settings:get("protection_max_depth")) or -512 factions_config.protection_max_height = tonumber(minetest.settings:get("protection_max_height")) or 10000 factions_config.power_per_parcel = tonumber(minetest.settings:get("power_per_parcel")) or 1 factions_config.power_per_death = tonumber(minetest.settings:get("power_per_death")) or 1 From 21a854e5221cc7327776587cd7f2809e0582b3c6 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Mon, 6 May 2019 14:30:17 -0500 Subject: [PATCH 4/6] Remove: factions_config from attack_parcel --- settingtypes.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settingtypes.txt b/settingtypes.txt index ad44b53..f638a14 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -37,8 +37,8 @@ parcel_size (parcel-size) float 16 # Enable or disabled power-per-player. power_per_playerb (Enable power-per-player) bool true -# Enable or disabled factions_config.attack_parcel function. -factions_config.attack_parcel (Enable attack parcel) bool false +# Enable or disabled attack_parcel function. +attack_parcel (Enable attack parcel) bool false # Enable or disabled faction diplomacy. faction_diplomacy (Enable faction diplomacy) bool true # Enable or disabled the max depth and height limit for a parcel From 8e98bf8b62f014d4bb2dec54495d1c92efbef5ad Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Mon, 6 May 2019 14:41:09 -0500 Subject: [PATCH 5/6] Make: 2d the default protection style --- factions.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/factions.lua b/factions.lua index 2f5cf27..2fdf980 100644 --- a/factions.lua +++ b/factions.lua @@ -466,10 +466,10 @@ function factions.is_online(name) end function factions.get_parcel_pos(pos) - if factions_config.protection_style == "2d" then - return math.floor(pos.x / parcel_size) * parcel_size .. "," .. math.floor(pos.z / parcel_size) * parcel_size - elseif factions_config.protection_style == "3d" then + if factions_config.protection_style == "3d" then return math.floor(pos.x / parcel_size) * parcel_size .. "," .. math.floor(pos.y / parcel_size) * parcel_size .. "," .. math.floor(pos.z / parcel_size) * parcel_size + else + return math.floor(pos.x / parcel_size) * parcel_size .. "," .. math.floor(pos.z / parcel_size) * parcel_size end end From a1cebc3a240ba773de28adc8dccac4f224e5db3d Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Tue, 7 May 2019 10:35:42 -0500 Subject: [PATCH 6/6] Fix: who cmd crashes on invaild faction name --- chatcommands.lua | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 07d5406..df56a21 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -942,19 +942,9 @@ factions.register_command("who", { if str then local f = factions.get_faction(str) - - if not f and not f.players then - f = factions.get_player_faction(player) - if not f or not f.players then - minetest.chat_send_player(player, "Your not in a faction.") - return - else - minetest.chat_send_player(player, "Players in faction " .. f.name .. ": ") - for p, rank in pairs(f.players) do - minetest.chat_send_player(player, p .." (" .. rank .. ")") - end - return true - end + if not f or not f.players then + minetest.chat_send_player(player, "Faction " .. str .. " does not exist.") + return else minetest.chat_send_player(player, "Players in faction " .. f.name .. ": ") for p, rank in pairs(f.players) do