From f902419d25f01adf124721c7577cb3c859a6fecf Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sat, 27 Oct 2018 23:14:52 -0500 Subject: [PATCH] Give is_admin purpose. If a faction is set as an admin faction it will never be disbanded. --- chatcommands.lua | 25 +++++++++++++++++++++++- factions.lua | 50 +++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/chatcommands.lua b/chatcommands.lua index 2f28924..b707b51 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -975,13 +975,36 @@ factions.register_command("setleader", { end },false) -factions.register_command("setadmin", { +factions.register_command("set_admin", { description = "Make a faction an admin faction", infaction = false, global_privileges = {"faction_admin"}, format = {"faction"}, on_success = function(player, faction, pos, parcelpos, args) + if not args.factions[1].is_admin then + minetest.chat_send_player(player,"faction " .. args.factions[1].name .. " is now an admin faction it can not be disband.") + else + minetest.chat_send_player(player,"faction " .. args.factions[1].name .. " is already an admin faction.") + end + args.factions[1].is_admin = true + factions.save() + return true + end +},false) + +factions.register_command("remove_admin", { + description = "Make a faction not an admin faction", + infaction = false, + global_privileges = {"faction_admin"}, + format = {"faction"}, + on_success = function(player, faction, pos, parcelpos, args) + if args.factions[1].is_admin then + minetest.chat_send_player(player,"faction " .. args.factions[1].name .. " is not an admin faction any more.") + else + minetest.chat_send_player(player,"faction " .. args.factions[1].name .. " is not an admin faction to begin with.") + end args.factions[1].is_admin = false + factions.save() return true end },false) diff --git a/factions.lua b/factions.lua index a7088fd..25f9e0c 100644 --- a/factions.lua +++ b/factions.lua @@ -356,33 +356,35 @@ end --! @brief disband faction, updates global players and parcels table function factions.Faction.disband(self, reason) - for i,v in pairs(factions.factions) do - if v.name ~= self.name then - if v.enemies[self.name] then - v:end_enemy(self.name) - end - if v.allies[self.name] then - v:end_alliance(self.name) - end - if v.neutral[self.name] then - v:end_neutral(self.name) + if not self.is_admin then + for i,v in pairs(factions.factions) do + if v.name ~= self.name then + if v.enemies[self.name] then + v:end_enemy(self.name) + end + if v.allies[self.name] then + v:end_alliance(self.name) + end + if v.neutral[self.name] then + v:end_neutral(self.name) + end end end + for k, _ in pairs(self.players) do -- remove players affiliation + factions.players[k] = nil + end + for k, v in pairs(self.land) do -- remove parcel claims + factions.parcels[k] = nil + end + self:on_disband(reason) + local playerslist = self.onlineplayers + for i,l in pairs(playerslist) do + removeHud(i,"factionName") + removeHud(i,"powerWatch") + end + factions.factions[self.name] = nil + factions.save() end - for k, _ in pairs(self.players) do -- remove players affiliation - factions.players[k] = nil - end - for k, v in pairs(self.land) do -- remove parcel claims - factions.parcels[k] = nil - end - self:on_disband(reason) - local playerslist = self.onlineplayers - for i,l in pairs(playerslist) do - removeHud(i,"factionName") - removeHud(i,"powerWatch") - end - factions.factions[self.name] = nil - factions.save() end --! @brief change the faction leader