From 3ffc31f8f265a42c4c2fd0214c20367276ea93e5 Mon Sep 17 00:00:00 2001 From: shamoanjac Date: Sat, 27 Aug 2016 22:34:09 +0200 Subject: [PATCH] Added /f setleader --- chatcommands.lua | 18 ++++++++++++++++++ factions.lua | 3 +++ 2 files changed, 21 insertions(+) diff --git a/chatcommands.lua b/chatcommands.lua index 31ae5ea..9fd9ade 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -574,6 +574,24 @@ factions.register_command("which", { end }) +factions.register_command("setleader", { + description = "Set a player as a faction's leader", + infaction = false, + global_privileges = {"faction_admin"}, + format = {"faction", "player"}, + on_success = function(player, faction, pos, parcelpos, args) + local playername = args.players[1]:get_player_name() + local playerfaction = factions.get_player_faction(playername) + local targetfaction = args.factions[1] + if playerfaction.name ~= targetfaction.name then + send_error(player, "Player "..playername.." is not in faction "..targetfaction.name..".") + return false + end + targetfaction:set_leader(playername) + return true + end +}) + ------------------------------------------------------------------------------- -- name: cmdhandler(playername,parameter) -- diff --git a/factions.lua b/factions.lua index 51aed47..77e27be 100644 --- a/factions.lua +++ b/factions.lua @@ -248,6 +248,9 @@ end --! @brief change the faction leader function factions.Faction.set_leader(self, player) + if self.leader then + self.players[self.leader] = self.default_rank + end self.leader = player self.players[player] = self.default_leader_rank self:on_new_leader()