factions/chatcommands.lua

1529 lines
48 KiB
Lua
Raw Normal View History

local send_error = function(player, message)
minetest.chat_send_player(player, message)
end
2016-08-07 19:31:11 +02:00
factions_chat = {}
2016-07-30 05:02:22 +02:00
2016-08-07 19:36:56 +02:00
factions.commands = {}
factions.register_command = function(cmd_name, cmd, ignore_param_count,or_perm)
2016-08-07 19:31:11 +02:00
factions.commands[cmd_name] = { -- default command
2016-08-07 15:17:33 +02:00
name = cmd_name,
faction_permissions = {},
global_privileges = {},
format = {},
infaction = true,
2016-08-07 15:17:33 +02:00
description = "This command has no description.",
run = function(self, player, argv)
if self.global_privileges then
2016-08-08 13:46:42 +02:00
local tmp = {}
for i in ipairs(self.global_privileges) do
tmp[self.global_privileges[i]] = true
end
local bool, missing_privs = minetest.check_player_privs(player, tmp)
if not bool then
2016-08-08 13:46:42 +02:00
send_error(player, "Unauthorized.")
return false
end
2016-08-08 13:46:42 +02:00
end
2016-08-07 15:17:33 +02:00
-- checks argument formats
local args = {
factions = {},
players = {},
strings = {},
2018-10-15 17:24:58 +02:00
unknowns = {},
2016-08-07 15:17:33 +02:00
other = {}
}
if not ignore_param_count then
if #argv < #(self.format) then
send_error(player, "Not enough parameters.")
return false
end
else
if self.format[1] then
local fm = self.format[1]
for i in ipairs(argv) do
if #argv > #(self.format) then
table.insert(self.format, fm)
else
break
end
end
end
end
for i in ipairs(self.format) do
local argtype = self.format[i]
2016-08-07 15:17:33 +02:00
local arg = argv[i]
if argtype == "faction" then
2016-08-20 00:47:35 +02:00
local fac = factions.get_faction(arg)
2016-08-07 15:17:33 +02:00
if not fac then
send_error(player, "Specified faction "..arg.." does not exist")
2016-08-07 15:17:33 +02:00
return false
else
table.insert(args.factions, fac)
end
elseif argtype == "player" then
local pl = minetest.get_player_by_name(arg)
2016-08-25 18:31:02 +02:00
if not pl and not factions.players[arg] then
2016-08-08 13:46:42 +02:00
send_error(player, "Player is not online.")
2016-08-07 15:17:33 +02:00
return false
else
table.insert(args.players, pl)
end
elseif argtype == "string" then
table.insert(args.strings, arg)
else
2018-10-15 17:24:58 +02:00
table.insert(args.unknowns, arg)
--minetest.log("error", "Bad format definition for function "..self.name)
--send_error(player, "Internal server error")
--return false
2016-08-07 15:17:33 +02:00
end
end
for i=2, #argv do
if argv[i] then
table.insert(args.other, argv[i])
end
2016-08-07 15:17:33 +02:00
end
-- checks permissions
2019-01-26 07:21:05 +01:00
local player_faction, facname = factions.get_player_faction(player)
if self.infaction and not player_faction then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "This command is only available within a faction")
2016-08-07 15:17:33 +02:00
return false
end
local one_p = false
2016-08-08 13:46:42 +02:00
if self.faction_permissions then
for i in ipairs(self.faction_permissions) do
2018-10-31 22:15:08 +01:00
local perm = self.faction_permissions[i]
2019-01-26 07:21:05 +01:00
if not or_perm and not factions.has_permission(facname, player, perm) then
send_error(player, "You do not have the faction permission " .. perm)
return false
2019-01-26 07:21:05 +01:00
elseif or_perm and factions.has_permission(facname, player, perm) then
one_p = true
break
end
end
2016-08-07 15:17:33 +02:00
end
if or_perm and one_p == false then
send_error(player, "You do not have any of faction permissions required.")
return false
end
2016-08-07 15:17:33 +02:00
-- get some more data
local pos = minetest.get_player_by_name(player):getpos()
2016-08-14 15:53:40 +02:00
local parcelpos = factions.get_parcel_pos(pos)
return self.on_success(player, player_faction, pos, parcelpos, args)
2016-08-07 15:17:33 +02:00
end,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-07 15:17:33 +02:00
minetest.chat_send_player(player, "Not implemented yet!")
end
}
-- override defaults
for k, v in pairs(cmd) do
2016-08-07 19:31:11 +02:00
factions.commands[cmd_name][k] = v
2016-08-07 15:17:33 +02:00
end
end
local init_commands
init_commands = function()
2018-10-31 22:15:08 +01:00
if factions_config.faction_user_priv == true then
minetest.register_privilege("faction_user",
{
description = "this user is allowed to interact with faction mod",
give_to_singleplayer = true,
}
)
end
2018-10-31 22:15:08 +01:00
2016-07-30 05:02:22 +02:00
minetest.register_privilege("faction_admin",
{
2016-08-07 19:31:11 +02:00
description = "this user is allowed to create or delete factions",
2016-07-30 05:02:22 +02:00
give_to_singleplayer = true,
}
)
2018-10-28 02:57:15 +01:00
local def_privs = { interact=true}
2018-10-31 22:15:08 +01:00
if factions_config.faction_user_priv == true then
2018-10-28 02:57:15 +01:00
def_privs.faction_user = true
end
2016-08-07 19:31:11 +02:00
minetest.register_chatcommand("factions",
2016-07-30 05:02:22 +02:00
{
2018-10-31 22:15:08 +01:00
params = "<command> parameters",
description = "Factions commands. Type /factions help for available commands.",
2018-10-28 02:57:15 +01:00
privs = def_privs,
2016-08-07 19:31:11 +02:00
func = factions_chat.cmdhandler,
2016-07-30 05:02:22 +02:00
}
)
minetest.register_chatcommand("f",
{
params = "<command> parameters",
description = "Factions commands. Type /f help for available commands.",
2018-10-28 02:57:15 +01:00
privs = def_privs,
func = factions_chat.cmdhandler,
2016-07-30 05:02:22 +02:00
}
)
end
2016-08-07 15:17:33 +02:00
2016-07-30 05:02:22 +02:00
2016-08-07 15:17:33 +02:00
-------------------------------------------
-- R E G I S T E R E D C O M M A N D S |
-------------------------------------------
2016-07-30 05:02:22 +02:00
2018-10-28 02:57:15 +01:00
local def_global_privileges = nil
2018-10-31 22:15:08 +01:00
if factions_config.faction_user_priv == true then
2018-10-28 02:57:15 +01:00
minetest.register_on_newplayer(function(player)
local name = player:get_player_name()
local privs = minetest.get_player_privs(name)
privs.faction_user = true
minetest.set_player_privs(name, privs)
end
)
def_global_privileges = {"faction_user"}
end
factions.register_command ("set_name", {
faction_permissions = {"name"},
format = {"string"},
description = "Change the faction's name.",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
local factionname = args.strings[1]
if factions.can_create_faction(factionname) then
2019-01-26 07:21:05 +01:00
factions.set_name(faction.name, factionname)
return true
else
send_error(player, "Faction cannot be renamed.")
return false
end
end
},false)
2016-08-07 19:31:11 +02:00
factions.register_command ("claim", {
2016-08-07 15:17:33 +02:00
faction_permissions = {"claim"},
description = "Claim the plot of land you're on.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local p = parcelpos
2019-01-26 07:21:05 +01:00
local can_claim = factions.can_claim_parcel(faction.name, p)
if can_claim then
minetest.chat_send_player(player, "Claming parcel " .. p)
2019-01-26 07:21:05 +01:00
factions.claim_parcel(faction.name, p)
2016-08-07 15:17:33 +02:00
return true
2016-08-07 02:11:17 +02:00
else
local parcel_faction = factions.get_parcel_faction(p)
2019-01-26 07:21:05 +01:00
if parcel_faction and parcel_name == faction.name then
send_error(player, "This parcel already belongs to your faction")
2018-10-23 06:03:11 +02:00
return false
2019-01-26 07:21:05 +01:00
elseif parcel_faction and parcel_name ~= faction.name then
send_error(player, "This parcel belongs to another faction")
return false
elseif faction.power <= factions_config.power_per_parcel then
send_error(player, "Not enough power.")
2016-08-07 15:17:33 +02:00
return false
2016-08-07 02:11:17 +02:00
else
send_error(player, "Your faction cannot claim any (more) parcel(s).")
2016-08-07 15:17:33 +02:00
return false
2016-08-07 02:11:17 +02:00
end
end
2016-08-07 15:17:33 +02:00
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("unclaim", {
2016-08-07 15:17:33 +02:00
faction_permissions = {"claim"},
description = "Unclaim the plot of land you're on.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-20 00:47:35 +02:00
local parcel_faction = factions.get_parcel_faction(parcelpos)
if not parcel_faction then
send_error(player, "This parcel does not exist.")
return false
end
2019-01-26 07:21:05 +01:00
if parcel_name ~= name then
2016-08-14 15:53:40 +02:00
send_error(player, "This parcel does not belong to you.")
2016-08-07 15:17:33 +02:00
return false
2016-08-07 02:11:17 +02:00
else
2019-01-26 07:21:05 +01:00
factions.unclaim_parcel(faction.name, parcelpos)
2016-08-07 15:17:33 +02:00
return true
2016-08-07 02:11:17 +02:00
end
2016-08-07 15:17:33 +02:00
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 15:17:33 +02:00
--list all known factions
2016-08-07 19:31:11 +02:00
factions.register_command("list", {
2016-08-07 15:17:33 +02:00
description = "List all registered factions.",
infaction = false,
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-07 19:31:11 +02:00
local list = factions.get_faction_list()
local tosend = "Existing factions:"
2016-08-07 15:17:33 +02:00
for i,v in ipairs(list) do
if i ~= #list then
tosend = tosend .. " " .. v .. ","
2016-08-07 02:11:17 +02:00
else
2016-08-07 15:17:33 +02:00
tosend = tosend .. " " .. v
2016-08-07 02:11:17 +02:00
end
2019-01-26 07:21:05 +01:00
end
2016-08-07 15:17:33 +02:00
minetest.chat_send_player(player, tosend, false)
return true
2016-08-07 02:11:17 +02:00
end
},false)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
--show factions mod version
factions.register_command("version", {
2016-08-07 15:17:33 +02:00
description = "Displays mod version.",
infaction = false,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "factions: version 0.8.4", false)
2016-08-07 02:11:17 +02:00
end
},false)
2016-07-30 06:22:28 +02:00
2018-10-15 17:24:58 +02:00
--show description of faction
2016-08-07 19:31:11 +02:00
factions.register_command("info", {
2016-08-07 15:17:33 +02:00
format = {"faction"},
description = "Shows a faction's description.",
infaction = false,
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-07 15:17:33 +02:00
minetest.chat_send_player(player,
2016-08-07 19:31:11 +02:00
"factions: " .. args.factions[1].name .. ": " ..
2016-08-07 15:17:33 +02:00
args.factions[1].description, false)
return true
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("leave", {
2019-01-26 07:21:05 +01:00
description = "Leave your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.remove_player(faction.name, player)
return true
2016-08-07 02:11:17 +02:00
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("kick", {
2018-10-31 22:15:08 +01:00
faction_permissions = {"kick"},
2016-08-07 15:17:33 +02:00
format = {"player"},
2019-01-26 07:21:05 +01:00
description = "Kick a player from your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-07 15:17:33 +02:00
local victim = args.players[1]
2019-01-26 07:21:05 +01:00
local name = victim:get_player_name()
local victim_faction, facname = factions.get_player_faction(name)
local kicker_faction, kicker_facname = factions.get_player_faction(player)
if victim_faction and kicker_facname == facname and name ~= victim_faction.leader then -- can't kick da king
factions.remove_player(facname, name)
2016-08-07 15:17:33 +02:00
return true
2019-01-26 07:21:05 +01:00
elseif not victim_faction or kicker_facname ~= facname then
send_error(player, name .. " is not in your faction")
2016-08-20 00:47:35 +02:00
return false
2016-08-07 02:11:17 +02:00
else
2019-01-26 07:21:05 +01:00
send_error(player, name .. " cannot be kicked from your faction")
2016-08-07 15:17:33 +02:00
return false
2016-08-07 02:11:17 +02:00
end
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 15:17:33 +02:00
--create new faction
2016-08-07 19:31:11 +02:00
factions.register_command("create", {
2016-08-07 15:17:33 +02:00
format = {"string"},
infaction = false,
2019-01-26 07:21:05 +01:00
description = "Create a new faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-07 15:17:33 +02:00
if faction then
2019-01-26 07:21:05 +01:00
send_error(player, "You are already in a faction")
2016-08-07 15:17:33 +02:00
return false
end
2019-01-26 07:21:05 +01:00
local factionname = args.strings[1]
2019-01-26 07:21:05 +01:00
2016-08-07 19:31:11 +02:00
if factions.can_create_faction(factionname) then
2019-01-26 07:21:05 +01:00
local new_faction = factions.new_faction(factionname)
factions.add_player(factionname, player, new_faction.default_leader_rank)
new_faction.leader = player
factions.start_diplomacy(factionname, new_faction)
2016-08-07 15:17:33 +02:00
return true
2016-08-07 02:11:17 +02:00
else
send_error(player, "Faction cannot be created.")
2016-08-07 15:17:33 +02:00
return false
2016-08-07 02:11:17 +02:00
end
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 19:36:56 +02:00
factions.register_command("join", {
2016-08-07 15:17:33 +02:00
format = {"faction"},
2019-01-26 07:21:05 +01:00
description = "Join a faction",
infaction = false,
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
if faction ~= nil or faction then
send_error(player, "You need to leave your current faction in order to join this one.")
return false
end
2019-01-26 07:21:05 +01:00
local new_faction = args.factions[1]
2019-01-26 07:21:05 +01:00
if new_faction and factions.can_join(new_faction.name, player) then
factions.add_player(new_faction.name, player)
elseif new_faction then
2019-01-26 07:21:05 +01:00
send_error(player, "You cannot join this faction")
2016-08-07 15:17:33 +02:00
return false
else
send_error(player, "Enter the right faction name.")
return false
2016-08-07 02:11:17 +02:00
end
2019-01-26 07:21:05 +01:00
2016-08-07 15:17:33 +02:00
return true
2016-08-07 02:11:17 +02:00
end
},false)
2016-08-07 02:11:17 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("disband", {
2016-08-07 15:17:33 +02:00
faction_permissions = {"disband"},
2019-01-26 07:21:05 +01:00
description = "Disband your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.disband(faction.name)
2016-08-07 15:17:33 +02:00
return true
2016-08-07 02:11:17 +02:00
end
},false)
2016-08-07 02:11:17 +02:00
2018-10-31 22:15:08 +01:00
factions.register_command("flag", {
faction_permissions = {"flags"},
description = "Manage the faction's flags.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-31 22:15:08 +01:00
format = {"string"},
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2018-10-31 22:15:08 +01:00
--"Make your faction invite-only."
2019-01-26 07:21:05 +01:00
--"Allow any player to join your "
2018-10-31 22:15:08 +01:00
--faction:toggle_join_free(false)
local flag_name = args.strings[1]
local bool = args.strings[2]
if (flag_name == "help" or flag_name == "flags") or not bool then
for i, k in pairs(factions.flags) do
minetest.chat_send_player(player, k..": ".. factions.flags_desc[i] .. "\n")
end
return true
end
if flag_name and bool then
local yes = false
if bool == "yes" then
yes = true
elseif bool == "no" then
yes = false
else
send_error(player, "Set the flags only to yes or no.")
return false
end
if flag_name == "open" then
2019-01-26 07:21:05 +01:00
factions.toggle_join_free(faction.name, yes)
2018-10-31 22:15:08 +01:00
elseif flag_name == "monsters" then
elseif flag_name == "tax_kick" then
elseif flag_name == "animals" then
else
send_error(player, flag_name.." is not an flag.")
end
end
2016-08-07 15:17:33 +02:00
return true
end
2018-10-31 22:15:08 +01:00
},true)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("description", {
format = {"string"},
2016-08-07 15:17:33 +02:00
faction_permissions = {"description"},
description = "Set your faction's description",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.set_description(faction.name, table.concat(args.strings," "))
2016-08-07 15:17:33 +02:00
return true
end
},true)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("invite", {
2016-08-07 15:17:33 +02:00
format = {"player"},
2018-10-31 22:15:08 +01:00
faction_permissions = {"invite"},
2019-01-26 07:21:05 +01:00
description = "Invite a player to your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
if args.players and args.players[1] then
2019-01-26 07:21:05 +01:00
factions.invite_player(faction.name, args.players[1]:get_player_name())
end
2016-08-07 15:17:33 +02:00
return true
end
},false)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("uninvite", {
2016-08-07 15:17:33 +02:00
format = {"player"},
2018-10-31 22:15:08 +01:00
faction_permissions = {"invite"},
2016-08-07 15:17:33 +02:00
description = "Revoke a player's invite.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.revoke_invite(faction.name, args.players[1]:get_player_name())
2016-08-07 15:17:33 +02:00
return true
end
},false)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("delete", {
2016-08-07 15:17:33 +02:00
global_privileges = {"faction_admin"},
format = {"faction"},
infaction = false,
2019-01-26 07:21:05 +01:00
description = "Delete a faction",
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.disband(args.factions[1].name)
2016-08-07 15:17:33 +02:00
return true
end
},false)
2016-08-07 15:17:33 +02:00
2016-08-07 19:31:11 +02:00
factions.register_command("ranks", {
description = "List ranks within your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
for rank, permissions in pairs(faction.ranks) do
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, rank .. ": " .. table.concat(permissions, " "))
end
return true
end
},false)
2018-10-15 17:24:58 +02:00
factions.register_command("rank_privileges", {
description = "List available rank privileges.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
infaction = false,
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
minetest.chat_send_player(player, "Privileges available:\n")
for i, k in pairs(factions.permissions) do
2018-10-31 22:15:08 +01:00
minetest.chat_send_player(player, k .. ": " .. factions.permissions_desc[i] .. "\n")
2018-10-15 17:24:58 +02:00
end
return true
end
},false)
2018-10-25 07:21:42 +02:00
factions.register_command("set_message_of_the_day", {
format = {"string"},
2018-10-31 22:15:08 +01:00
faction_permissions = {"motd"},
2018-10-25 07:21:42 +02:00
description = "Sets the message that shows up every time a faction member logs-in.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-25 07:21:42 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local s = ""
for i,l in pairs(args.strings) do
s = s .. l .. " "
end
2019-01-26 07:21:05 +01:00
factions.set_message_of_the_day(faction.name, "Message of the day: " .. s)
2018-10-25 07:21:42 +02:00
return true
end
},true)
2018-10-31 22:15:08 +01:00
if factions_config.faction_diplomacy == true then
2018-10-15 17:24:58 +02:00
factions.register_command("send_alliance", {
2019-01-26 07:21:05 +01:00
description = "Send an alliance request to another faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if target_faction then
if not target_faction.request_inbox[faction.name] then
if faction.allies[target_name] then
2018-10-31 22:15:08 +01:00
send_error(player, "You are already allys.")
return false
end
2019-01-26 07:21:05 +01:00
if faction.enemies[target_name] then
2018-10-31 22:15:08 +01:00
send_error(player, "You need to be neutral in-order to send an alliance request.")
return false
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
if target_name == faction.name then
send_error(player, "You can not send an alliance to your own faction")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if faction.request_inbox[target_name] then
send_error(player, "Faction " .. target_name .. "has already sent a request to you.")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
target_faction.request_inbox[faction.name] = "alliance"
factions.broadcast(target_faction.name, "An alliance request from faction " .. faction.name .. " has been sent to you.")
factions.broadcast(faction.name, "An alliance request was sent to faction " .. target_name)
factions.factions.set(target_name, target_faction)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "You have already sent a request.")
2018-10-15 17:24:58 +02:00
end
else
2019-01-26 07:21:05 +01:00
send_error(player, target_name .. " is not a name of a faction")
2018-10-15 17:24:58 +02:00
end
end
},false)
2018-10-18 07:15:26 +02:00
factions.register_command("send_neutral", {
2019-01-26 07:21:05 +01:00
description = "Send neutral to another faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if target_faction then
if not target_faction.request_inbox[faction.name] then
if faction.allies[target_name] then
send_error(player, "You are already allys.")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if faction.neutral[target_name] then
send_error(player, "You are already neutral with this faction")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if target_name == faction.name then
send_error(player, "You can not send a neutral request to your own faction")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if faction.request_inbox[target_name] then
send_error(player, "Faction " .. target_name .. "has already sent a request to you.")
2018-10-31 22:15:08 +01:00
return false
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
target_faction.request_inbox[faction.name] = "neutral"
factions.broadcast(target_faction.name, "A neutral request from faction " .. faction.name .. " has been sent to you.")
factions.broadcast(faction.name, "A neutral request was sent to faction " .. target_name)
factions.factions.set(target_name, target_faction)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "You have already sent a request.")
2018-10-15 17:24:58 +02:00
end
else
2019-01-26 07:21:05 +01:00
send_error(player, target_name .. " is not a name of a faction")
2018-10-15 17:24:58 +02:00
end
end
},false)
factions.register_command("accept", {
2019-01-26 07:21:05 +01:00
description = "accept an request from another faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if faction.request_inbox[target_name] then
if target_name == faction.name then
send_error(player, "You can not accept an request from own faction")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if faction.request_inbox[target_name] == "alliance" then
factions.new_alliance(faction.name, target_name)
factions.new_alliance(target_name, faction.name)
2018-10-15 17:24:58 +02:00
else
2019-01-26 07:21:05 +01:00
if faction.request_inbox[target_name] == "neutral" then
factions.new_neutral(faction.name, target_name)
factions.new_neutral(target_name, faction.name)
end
2018-10-31 22:15:08 +01:00
end
2019-01-26 07:21:05 +01:00
faction.request_inbox[target_name] = nil
factions.factions.set(faction.name, faction)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "No request was sent to you.")
2018-10-15 17:24:58 +02:00
end
end
},false)
factions.register_command("refuse", {
2019-01-26 07:21:05 +01:00
description = "refuse an request from another faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if faction.request_inbox[target_name] then
if target_name == faction.name then
send_error(player, "You can not refuse an request from your own faction")
2018-10-31 22:15:08 +01:00
return false
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
faction.request_inbox[target_name] = nil
factions.broadcast(target_name, "Faction " .. faction.name .. " refuse to be your ally.")
factions.broadcast(faction.name, "Refused an request from faction " .. target_name)
factions.factions.set(faction.name, faction)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "No request was sent to you.")
2018-10-15 17:24:58 +02:00
end
end
},false)
2019-01-15 00:16:28 +01:00
factions.register_command("declare_war", {
2019-01-26 07:21:05 +01:00
description = "Declare war on a faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if not faction.enemies[target_name] then
if target_name == faction.name then
send_error(player, "You can not declare war on your own faction")
2018-10-31 22:15:08 +01:00
return false
end
2019-01-26 07:21:05 +01:00
if faction.allies[target_name] then
factions.end_alliance(faction.name, target_name)
factions.end_alliance(target_name, faction.name)
2018-10-31 22:15:08 +01:00
end
2019-01-26 07:21:05 +01:00
if faction.neutral[target_name] then
factions.end_neutral(faction.name, target_name)
factions.end_neutral(target_name, faction.name)
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
factions.new_enemy(faction.name, target_name)
factions.new_enemy(target_name, faction.name)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "You are already at war.")
2018-10-15 17:24:58 +02:00
end
end
},false)
factions.register_command("break", {
description = "Break an alliance.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
format = {"string"},
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local target_name = args.strings[1]
local target_faction = factions.factions.get(target_name)
if faction.allies[target_name] then
if target_name == faction.name then
send_error(player, "You can not break an alliance from your own faction")
2018-10-31 22:15:08 +01:00
return false
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
factions.end_alliance(faction.name, target_name)
factions.end_alliance(target_name, faction.name)
factions.new_neutral(faction.name, target_name)
factions.new_neutral(target_name, faction.name)
2018-10-15 17:24:58 +02:00
else
2018-10-31 22:15:08 +01:00
send_error(player, "You where not allies to begin with.")
2018-10-15 17:24:58 +02:00
end
end
},false)
factions.register_command("inbox", {
description = "Check your diplomacy request inbox.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2019-01-05 01:31:30 +01:00
faction_permissions = {"diplomacy"},
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2018-10-31 22:15:08 +01:00
local empty = true
2019-01-26 07:21:05 +01:00
for i, k in pairs(faction.request_inbox) do
2018-10-31 22:15:08 +01:00
if k == "alliance" then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Alliance request from faction " .. i .. "\n")
2018-10-31 22:15:08 +01:00
else
2019-01-26 07:21:05 +01:00
if k == "neutral" then
minetest.chat_send_player(player, "neutral request from faction " .. i .. "\n")
end
2018-10-15 17:24:58 +02:00
end
2019-01-26 07:21:05 +01:00
2018-10-31 22:15:08 +01:00
empty = false
end
2019-01-26 07:21:05 +01:00
2018-10-31 22:15:08 +01:00
if empty then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "none:")
2018-10-15 17:24:58 +02:00
end
end
},false,true)
2018-10-15 17:24:58 +02:00
factions.register_command("allies", {
description = "Shows the factions that are allied to you.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local empty = true
2019-01-26 07:21:05 +01:00
for i, k in pairs(faction.allies) do
minetest.chat_send_player(player, i .. "\n")
2018-10-15 17:24:58 +02:00
empty = false
end
2019-01-26 07:21:05 +01:00
2018-10-15 17:24:58 +02:00
if empty then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "none:")
2018-10-15 17:24:58 +02:00
end
end
},false)
2018-10-18 07:15:26 +02:00
factions.register_command("neutral", {
description = "Shows the factions that are neutral with you.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local empty = true
2019-01-26 07:21:05 +01:00
for i, k in pairs(faction.neutral) do
minetest.chat_send_player(player, i .. "\n")
2018-10-15 17:24:58 +02:00
empty = false
end
2019-01-26 07:21:05 +01:00
2018-10-15 17:24:58 +02:00
if empty then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "none:")
2018-10-15 17:24:58 +02:00
end
end
},false)
factions.register_command("enemies", {
2019-01-26 07:21:05 +01:00
description = "Shows enemies of your faction",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2018-10-15 17:24:58 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local empty = true
2019-01-26 07:21:05 +01:00
for i, k in pairs(faction.enemies) do
minetest.chat_send_player(player, i .. "\n")
2018-10-15 17:24:58 +02:00
empty = false
end
2019-01-26 07:21:05 +01:00
2018-10-15 17:24:58 +02:00
if empty then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "none:")
2018-10-15 17:24:58 +02:00
end
end
},false)
end
2016-08-07 19:31:11 +02:00
factions.register_command("who", {
description = "List players in your faction, and their ranks.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
if not faction.players then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "There is nobody in this faction (" .. faction.name .. ")")
return true
end
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Players in faction " .. faction.name .. ": ")
2016-08-14 23:55:42 +02:00
for p, rank in pairs(faction.players) do
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, p .." (" .. rank .. ")")
end
2019-01-26 07:21:05 +01:00
return true
end
},false)
2018-10-18 04:04:46 +02:00
local parcel_size_center = factions_config.parcel_size / 2
2018-10-17 04:58:15 +02:00
2018-10-31 22:15:08 +01:00
factions.register_command("show_parcel", {
2018-10-17 04:58:15 +02:00
description = "Shows parcel for six seconds.",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
infaction = false,
2018-10-17 04:58:15 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local parcel_faction = factions.get_parcel_faction(parcelpos)
2019-01-26 07:21:05 +01:00
2018-10-17 04:58:15 +02:00
if not parcel_faction then
send_error(player, "There is no claim here")
return false
end
2019-01-26 07:21:05 +01:00
2018-10-18 04:52:27 +02:00
local psc = parcel_size_center
2018-10-18 04:04:46 +02:00
local fps = factions_config.parcel_size
2018-10-18 04:52:27 +02:00
2019-01-26 07:21:05 +01:00
local ppos = {x = (math.floor(pos.x / fps) * fps) + psc, y = (math.floor(pos.y / fps) * fps) + psc, z = (math.floor(pos.z / fps) * fps) + psc}
2018-10-17 04:58:15 +02:00
minetest.add_entity(ppos, "factions:display")
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("new_rank", {
description = "Add a new rank.",
format = {"string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if args.strings[1] then
local rank = args.strings[1]
if faction.ranks[rank] then
send_error(player, "Rank already exists")
return false
end
local success = false
local failindex = -1
for _, f in pairs(args.strings) do
if f then
for q, r in pairs(factions.permissions) do
if f == r then
success = true
break
2018-12-27 08:09:41 +01:00
else
success = false
end
end
if not success and _ ~= 1 then
failindex = _
break
end
end
end
if not success then
if args.strings[failindex] then
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
2018-10-31 22:15:08 +01:00
else
send_error(player, "No permission was given.")
end
return false
end
2019-01-26 07:21:05 +01:00
factions.add_rank(faction.name, rank, args.other)
return true
end
send_error(player, "No rank was given.")
return false
end
},true)
2018-10-31 22:15:08 +01:00
factions.register_command("replace_privs", {
description = "Deletes current permissions and replaces them with the ones given.",
format = {"string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if args.strings[1] then
local rank = args.strings[1]
if not faction.ranks[rank] then
send_error(player, "Rank does not exist")
return false
end
local success = false
local failindex = -1
for _, f in pairs(args.strings) do
if f then
for q, r in pairs(factions.permissions) do
if f == r then
success = true
break
2018-12-27 08:09:41 +01:00
else
success = false
2018-10-31 22:15:08 +01:00
end
end
if not success and _ ~= 1 then
failindex = _
break
end
end
end
if not success then
if args.strings[failindex] then
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
else
send_error(player, "No permission was given.")
end
return false
end
2019-01-26 07:21:05 +01:00
factions.replace_privs(faction.name, rank, args.other)
2018-10-31 22:15:08 +01:00
return true
end
send_error(player, "No rank was given.")
return false
end
},true)
factions.register_command("remove_privs", {
description = "Remove permissions from a rank.",
format = {"string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if args.strings[1] then
local rank = args.strings[1]
if not faction.ranks[rank] then
send_error(player, "Rank does not exist")
return false
end
local success = false
local failindex = -1
for _, f in pairs(args.strings) do
if f then
for q, r in pairs(factions.permissions) do
if f == r then
success = true
break
2018-12-27 08:09:41 +01:00
else
success = false
2018-10-31 22:15:08 +01:00
end
end
if not success and _ ~= 1 then
failindex = _
break
end
end
end
if not success then
if args.strings[failindex] then
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
else
send_error(player, "No permission was given.")
end
return false
end
2019-01-26 07:21:05 +01:00
factions.remove_privs(faction.name, rank, args.other)
2018-10-31 22:15:08 +01:00
return true
end
send_error(player, "No rank was given.")
return false
end
},true)
factions.register_command("add_privs", {
description = "add permissions to a rank.",
format = {"string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if args.strings[1] then
local rank = args.strings[1]
if not faction.ranks[rank] then
send_error(player, "Rank does not exist")
return false
end
local success = false
local failindex = -1
for _, f in pairs(args.strings) do
if f then
for q, r in pairs(factions.permissions) do
if f == r then
success = true
break
2018-12-27 08:09:41 +01:00
else
success = false
2018-10-31 22:15:08 +01:00
end
end
if not success and _ ~= 1 then
failindex = _
break
end
end
end
if not success then
if args.strings[failindex] then
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
else
send_error(player, "No permission was given.")
end
return false
end
2019-01-26 07:21:05 +01:00
factions.add_privs(faction.name, rank, args.other)
2018-10-31 22:15:08 +01:00
return true
end
send_error(player, "No rank was given.")
return false
end
},true)
factions.register_command("set_rank_name", {
description = "Change the name of given rank.",
format = {"string","string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
local rank = args.strings[1]
local newrank = args.strings[2]
if not faction.ranks[rank] then
send_error(player, "The rank does not exist.")
return false
end
if faction.ranks[newrank] then
send_error(player, "This rank name was already taken.")
return false
end
2019-01-26 07:21:05 +01:00
factions.set_rank_name(faction.name, rank, newrank)
2018-10-31 22:15:08 +01:00
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("del_rank", {
description = "Replace and delete a rank.",
format = {"string", "string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local rank = args.strings[1]
2016-08-08 16:31:11 +02:00
local newrank = args.strings[2]
2016-08-16 21:05:41 +02:00
if not faction.ranks[rank] or not faction.ranks[newrank] then
2018-10-31 22:15:08 +01:00
send_error(player, "One of the specified ranks does not exist.")
return false
end
2019-01-26 07:21:05 +01:00
factions.delete_rank(faction.name, rank, newrank)
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("set_def_rank", {
2019-01-26 07:21:05 +01:00
description = "Change the default rank given to new players and also replace rankless players in this faction",
2018-10-30 01:36:46 +01:00
format = {"string"},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-30 01:36:46 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
local rank = args.strings[1]
if not faction.ranks[rank] then
send_error(player, "This rank does not exist.")
return false
end
2019-01-26 07:21:05 +01:00
factions.set_def_rank(faction.name, rank)
2018-10-31 22:15:08 +01:00
return true
end
},false)
factions.register_command("reset_ranks", {
description = "Reset's all of the factions rankings back to the default ones.",
format = {},
2018-12-27 08:09:41 +01:00
faction_permissions = {"ranks"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.reset_ranks(faction.name)
2018-10-30 01:36:46 +01:00
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("set_spawn", {
description = "Set the faction's spawn",
2018-12-27 08:09:41 +01:00
faction_permissions = {"spawn"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.set_spawn(faction.name, pos)
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("del_spawn", {
description = "Set the faction's spawn to zero",
2018-12-27 08:09:41 +01:00
faction_permissions = {"spawn"},
2018-10-31 22:15:08 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
factions.set_spawn(faction.name, {x = 0, y = 0, z = 0})
2018-10-31 22:15:08 +01:00
return true
end
},false)
if factions_config.spawn_teleport == true then
local tip = {}
2018-10-31 22:15:08 +01:00
factions.register_command("tp_spawn", {
description = "Teleport to the faction's spawn",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if player then
if tip[player] then
minetest.chat_send_player(player, "Your already being teleported!")
return false
end
2018-10-31 22:15:08 +01:00
minetest.chat_send_player(player, "Teleporting in five seconds.")
minetest.after(5,
2019-01-26 07:21:05 +01:00
function(faction, player)
factions.tp_spawn(faction.name, player)
tip[player] = nil
end, faction, player)
tip[player] = true
2018-10-31 22:15:08 +01:00
return true
end
return false
end
},false)
minetest.register_on_leaveplayer(
function(player)
local name = player:get_player_name()
tip[name] = nil
end
)
2018-10-31 22:15:08 +01:00
end
factions.register_command("where", {
2018-10-15 17:24:58 +02:00
description = "See whose parcel you stand on.",
infaction = false,
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
local parcel_faction, facname = factions.get_parcel_faction(parcelpos)
local place_name = facname or "Wilderness"
minetest.chat_send_player(player, "You are standing on parcel " .. parcelpos .. ", part of " .. place_name)
return true
end
},false)
factions.register_command("help", {
description = "Shows help for commands.",
infaction = false,
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
factions_chat.show_help(player)
2016-08-08 21:09:10 +02:00
return true
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("get_spawn", {
2016-08-08 16:31:11 +02:00
description = "Shows your faction's spawn",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-28 12:07:44 +02:00
local spawn = faction.spawn
if spawn then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Spawn is at (" .. spawn.x .. ", " .. spawn.y .. ", " .. spawn.z .. ")")
2016-08-08 16:31:11 +02:00
return true
else
minetest.chat_send_player(player, "Your faction has no spawn set.")
2016-08-08 21:09:10 +02:00
return false
end
end
},false)
2016-08-08 21:09:10 +02:00
factions.register_command("promote", {
2018-10-15 17:24:58 +02:00
description = "Promotes a player to a rank",
format = {"player", "string"},
faction_permissions = {"promote"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local rank = args.strings[1]
if faction.ranks[rank] then
2019-01-26 07:21:05 +01:00
factions.promote(faction.name, args.players[1]:get_player_name(), rank)
return true
else
send_error(player, "The specified rank does not exist.")
return false
end
end
},false)
2016-08-08 21:09:10 +02:00
factions.register_command("power", {
description = "Display your faction's power",
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local pps = 0
if factions_config.enable_power_per_player then
2019-01-26 07:21:05 +01:00
if factions.onlineplayers[faction.name] == nil then
factions.onlineplayers[faction.name] = {}
end
local t = factions.onlineplayers[faction.name]
local count = 0
for _ in pairs(t) do count = count + 1 end
pps = factions_config.power_per_player * count
else
2019-01-26 07:21:05 +01:00
pps = factions_config.power_per_tick
end
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Power: " .. faction.power .. " / " .. faction.maxpower - faction.usedpower .. "\nPower per " .. factions_config.tick_time .. " seconds: " .. pps .. "\nPower per death: -" .. factions_config.power_per_death)
2016-08-08 23:42:20 +02:00
return true
end
},false)
2018-10-15 17:24:58 +02:00
2016-08-08 23:42:20 +02:00
factions.register_command("free", {
2016-08-14 15:53:40 +02:00
description = "Forcefully frees a parcel",
2016-08-08 23:42:20 +02:00
infaction = false,
global_privileges = {"faction_admin"},
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
2016-08-20 00:47:35 +02:00
local parcel_faction = factions.get_parcel_faction(parcelpos)
if not parcel_faction then
2016-08-08 23:42:20 +02:00
send_error(player, "No claim at this position")
return false
2016-08-20 00:47:35 +02:00
else
2019-01-26 07:21:05 +01:00
factions.unclaim_parcel(parcel_faction.name, parcelpos)
2016-08-20 00:47:35 +02:00
return true
2016-08-08 23:42:20 +02:00
end
2016-08-08 18:51:17 +02:00
end
},false)
2016-08-08 18:51:17 +02:00
2016-08-12 17:18:09 +02:00
factions.register_command("chat", {
description = "Send a message to your faction's members",
format = {"string"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
2016-08-14 15:53:40 +02:00
on_success = function(player, faction, pos, parcelpos, args)
local msg = table.concat(args.strings, " ")
2019-01-26 07:21:05 +01:00
factions.broadcast(faction.name, msg, player)
2016-08-12 11:34:39 +02:00
end
},true)
2016-08-12 11:34:39 +02:00
factions.register_command("forceupdate", {
description = "Forces an update tick.",
global_privileges = {"faction_admin"},
on_success = function(player, faction, pos, parcelpos, args)
factions.faction_tick()
end
},false)
factions.register_command("which", {
description = "Gets a player's faction",
infaction = false,
format = {"string"},
2018-10-28 02:57:15 +01:00
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
local playername = args.strings[1]
2019-01-26 07:21:05 +01:00
local faction1, facname = factions.get_player_faction(playername)
if not faction1 then
send_error(player, "Player " .. playername .. " does not belong to any faction")
return false
else
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "player " .. playername .. " belongs to faction " .. faction1.name)
return true
end
end
},false)
2018-10-31 22:15:08 +01:00
factions.register_command("set_leader", {
2016-08-27 22:34:09 +02:00
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()
2019-01-26 07:21:05 +01:00
local playerfaction, facname = factions.get_player_faction(playername)
2016-08-27 22:34:09 +02:00
local targetfaction = args.factions[1]
2019-01-26 07:21:05 +01:00
if playername ~= targetname then
send_error(player, "Player " .. playername .. " is not in faction " .. targetname .. ".")
2016-08-27 22:34:09 +02:00
return false
end
2019-01-26 07:21:05 +01:00
factions.set_leader(targetfaction.name, playername)
2016-08-27 22:34:09 +02:00
return true
end
},false)
2016-08-27 22:34:09 +02:00
factions.register_command("set_admin", {
2016-08-27 23:16:11 +02:00
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
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player,"faction " .. args.factions[1].name .. " is already an admin ")
end
2019-01-26 07:21:05 +01:00
args.factions[1].is_admin = true
2019-01-26 07:21:05 +01:00
factions.factions.set(args.factions[1].name, args.factions[1])
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
2016-08-27 23:16:11 +02:00
args.factions[1].is_admin = false
2019-01-26 07:21:05 +01:00
factions.factions.set(args.factions[1].name, args.factions[1])
2016-08-27 23:16:11 +02:00
return true
end
},false)
2016-08-27 23:16:11 +02:00
2018-10-31 22:15:08 +01:00
factions.register_command("reset_power", {
2016-08-28 11:37:14 +02:00
description = "Reset a faction's power",
infaction = false,
global_privileges = {"faction_admin"},
format = {"faction"},
on_success = function(player, faction, pos, parcelpos, args)
2016-08-28 11:55:16 +02:00
args.factions[1].power = 0
2019-01-26 07:21:05 +01:00
factions.factions.set(args.factions[1].name, args.factions[1])
2016-08-28 11:37:14 +02:00
return true
end
},false)
2016-08-28 11:37:14 +02:00
2016-08-28 11:55:16 +02:00
factions.register_command("obliterate", {
description = "Remove all factions",
infaction = false,
global_privileges = {"faction_admin"},
on_success = function(player, faction, pos, parcelpos, args)
2019-01-26 07:21:05 +01:00
for i, facname in pairs(factions.get_faction_list()) do
factions.disband(facname, "obliterated")
2016-08-28 11:55:16 +02:00
end
2016-08-28 11:59:51 +02:00
return true
2016-08-28 11:55:16 +02:00
end
},false)
2016-08-28 11:55:16 +02:00
2018-10-31 22:15:08 +01:00
factions.register_command("get_factions_spawn", {
2016-08-28 11:55:16 +02:00
description = "Get a faction's spawn",
infaction = false,
global_privileges = {"faction_admin"},
format = {"faction"},
on_success = function(player, faction, pos, parcelpos, args)
local spawn = args.factions[1].spawn
if spawn then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, spawn.x .. "," .. spawn.y .. "," .. spawn.z)
2016-08-28 11:55:16 +02:00
return true
else
send_error(player, "Faction has no spawn set.")
return false
end
end
},false)
2016-08-28 11:55:16 +02:00
2016-08-28 11:59:51 +02:00
factions.register_command("whoin", {
2019-01-26 07:21:05 +01:00
description = "Get all members of a faction",
2016-08-28 11:59:51 +02:00
infaction = false,
global_privileges = def_global_privileges,
2016-08-28 11:59:51 +02:00
format = {"faction"},
on_success = function(player, faction, pos, parcelpos, args)
local msg = {}
for player, _ in pairs(args.factions[1].players) do
table.insert(msg, player)
end
minetest.chat_send_player(player, table.concat(msg, ", "))
return true
end
},false)
2016-08-28 11:59:51 +02:00
2016-08-28 12:03:12 +02:00
factions.register_command("stats", {
2019-01-26 07:21:05 +01:00
description = "Get stats of a faction",
2016-08-28 12:03:12 +02:00
infaction = false,
global_privileges = def_global_privileges,
2016-08-28 12:03:12 +02:00
format = {"faction"},
on_success = function(player, faction, pos, parcelpos, args)
local f = args.factions[1]
2018-11-01 06:22:39 +01:00
local pps = 0
if factions_config.enable_power_per_player then
2019-01-26 07:21:05 +01:00
if factions.onlineplayers[faction.name] == nil then
factions.onlineplayers[faction.name] = {}
end
local t = factions.onlineplayers[faction.name]
2018-11-01 06:22:39 +01:00
local count = 0
for _ in pairs(t) do count = count + 1 end
pps = factions_config.power_per_player * count
else
2019-01-26 07:21:05 +01:00
pps = factions_config.power_per_tick
2018-11-01 06:22:39 +01:00
end
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Power: " .. f.power .. " / " .. f.maxpower - f.usedpower .. "\nPower per " .. factions_config.tick_time .. " seconds: " .. pps .. "\nPower per death: -" .. factions_config.power_per_death)
2016-08-28 12:03:12 +02:00
return true
end
},false)
2016-08-28 12:03:12 +02:00
2016-08-28 12:19:58 +02:00
factions.register_command("seen", {
description = "Check the last time a faction had a member logged in",
infaction = false,
global_privileges = def_global_privileges,
2016-08-28 12:19:58 +02:00
format = {"faction"},
on_success = function(player, faction, pos, parcelpos, args)
local lastseen = args.factions[1].last_logon
local now = os.time()
local time = now - lastseen
local minutes = math.floor(time / 60)
local hours = math.floor(minutes / 60)
local days = math.floor(hours / 24)
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(player, "Last seen " .. days .. " day(s), " ..
hours % 24 .. " hour(s), " .. minutes % 60 .. " minutes, " .. time % 60 .. " second(s) ago.")
2016-08-28 12:19:58 +02:00
return true
end
},false)
2016-08-28 12:19:58 +02:00
2016-08-07 15:17:33 +02:00
-------------------------------------------------------------------------------
-- name: cmdhandler(playername,parameter)
--
--! @brief chat command handler
2016-08-07 19:31:11 +02:00
--! @memberof factions_chat
2016-08-07 15:17:33 +02:00
--! @private
--
--! @param playername name
--! @param parameter data supplied to command
-------------------------------------------------------------------------------
factions_chat.cmdhandler = function (playername,parameter)
2016-08-07 15:17:33 +02:00
local player = minetest.env:get_player_by_name(playername)
local params = parameter:split(" ")
2019-01-26 07:21:05 +01:00
local player_faction, facname = factions.get_player_faction(playername)
2016-08-07 15:17:33 +02:00
if parameter == nil or
parameter == "" then
if player_faction then
2019-01-26 07:21:05 +01:00
minetest.chat_send_player(playername, "You are in faction "..player_name..". Type /f help for a list of commands.")
2016-08-07 02:11:17 +02:00
else
minetest.chat_send_player(playername, "You are part of no faction")
2016-08-07 02:11:17 +02:00
end
2016-08-07 15:17:33 +02:00
return
end
2016-08-07 19:31:11 +02:00
local cmd = factions.commands[params[1]]
2016-08-07 15:17:33 +02:00
if not cmd then
send_error(playername, "Unknown command.")
return false
2016-08-07 15:17:33 +02:00
end
local argv = {}
for i=2, #params, 1 do
table.insert(argv, params[i])
2016-08-07 02:11:17 +02:00
end
2016-07-30 05:02:22 +02:00
cmd:run(playername, argv)
2016-07-30 05:02:22 +02:00
end
function table_Contains(t,v)
for k, a in pairs(t) do
if a == v then
return true
end
end
return false
end
2016-07-30 05:02:22 +02:00
-------------------------------------------------------------------------------
-- name: show_help(playername,parameter)
--
--! @brief send help message to player
2016-08-07 19:31:11 +02:00
--! @memberof factions_chat
2016-07-30 05:02:22 +02:00
--! @private
--
--! @param playername name
-------------------------------------------------------------------------------
2016-08-07 19:31:11 +02:00
function factions_chat.show_help(playername)
2016-07-30 05:02:22 +02:00
local MSG = function(text)
minetest.chat_send_player(playername,text,false)
end
2016-08-07 19:31:11 +02:00
MSG("factions mod")
2016-07-30 05:02:22 +02:00
MSG("Usage:")
local has, missing = minetest.check_player_privs(playername, {
faction_admin = true})
2016-08-07 19:31:11 +02:00
for k, v in pairs(factions.commands) do
2016-08-07 15:17:33 +02:00
local args = {}
if has or not table_Contains(v.global_privileges,"faction_admin") then
for i in ipairs(v.format) do
table.insert(args, v.format[i])
end
MSG("\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description)
end
2016-08-07 15:17:33 +02:00
end
2016-07-30 22:33:10 +02:00
end
2016-08-07 02:11:17 +02:00
init_commands()