forked from mtcontrib/factions
Major update 2
This commit is contained in:
parent
9dd577e699
commit
a419cd6c17
@ -19,10 +19,6 @@ More claim and unclaim commands.
|
|||||||
|
|
||||||
faction access manage command.
|
faction access manage command.
|
||||||
|
|
||||||
More permissions.
|
|
||||||
|
|
||||||
faction flags(Not to replace parcels).
|
|
||||||
|
|
||||||
Maybe expand on diplomacy.
|
Maybe expand on diplomacy.
|
||||||
|
|
||||||
Write the forum topic better.
|
Write the forum topic better.
|
||||||
|
351
chatcommands.lua
351
chatcommands.lua
@ -94,8 +94,9 @@ factions.register_command = function(cmd_name, cmd, ignore_param_count)
|
|||||||
end
|
end
|
||||||
if self.faction_permissions then
|
if self.faction_permissions then
|
||||||
for i in ipairs(self.faction_permissions) do
|
for i in ipairs(self.faction_permissions) do
|
||||||
if not player_faction:has_permission(player, self.faction_permissions[i]) then
|
local perm = self.faction_permissions[i]
|
||||||
send_error(player, "You don't have permissions to do that.")
|
if not player_faction:has_permission(player, perm) then
|
||||||
|
send_error(player, "You do not have the faction permission "..perm)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -120,7 +121,7 @@ end
|
|||||||
local init_commands
|
local init_commands
|
||||||
init_commands = function()
|
init_commands = function()
|
||||||
|
|
||||||
if factions_config.faction_user_priv then
|
if factions_config.faction_user_priv == true then
|
||||||
minetest.register_privilege("faction_user",
|
minetest.register_privilege("faction_user",
|
||||||
{
|
{
|
||||||
description = "this user is allowed to interact with faction mod",
|
description = "this user is allowed to interact with faction mod",
|
||||||
@ -129,6 +130,7 @@ init_commands = function()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_privilege("faction_admin",
|
minetest.register_privilege("faction_admin",
|
||||||
{
|
{
|
||||||
description = "this user is allowed to create or delete factions",
|
description = "this user is allowed to create or delete factions",
|
||||||
@ -137,20 +139,19 @@ init_commands = function()
|
|||||||
)
|
)
|
||||||
|
|
||||||
local def_privs = { interact=true}
|
local def_privs = { interact=true}
|
||||||
if factions_config.faction_user_priv then
|
if factions_config.faction_user_priv == true then
|
||||||
def_privs.faction_user = true
|
def_privs.faction_user = true
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("factions",
|
minetest.register_chatcommand("factions",
|
||||||
{
|
{
|
||||||
params = "<cmd> <parameter 1> .. <parameter n>",
|
params = "<command> parameters",
|
||||||
description = "faction administration functions",
|
description = "Factions commands. Type /factions help for available commands.",
|
||||||
privs = def_privs,
|
privs = def_privs,
|
||||||
func = factions_chat.cmdhandler,
|
func = factions_chat.cmdhandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("f",
|
minetest.register_chatcommand("f",
|
||||||
{
|
{
|
||||||
params = "<command> parameters",
|
params = "<command> parameters",
|
||||||
@ -168,7 +169,7 @@ end
|
|||||||
|
|
||||||
local def_global_privileges = nil
|
local def_global_privileges = nil
|
||||||
|
|
||||||
if factions_config.faction_user_priv then
|
if factions_config.faction_user_priv == true then
|
||||||
minetest.register_on_newplayer(function(player)
|
minetest.register_on_newplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local privs = minetest.get_player_privs(name)
|
local privs = minetest.get_player_privs(name)
|
||||||
@ -208,6 +209,23 @@ factions.register_command ("claim", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
|
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
|
||||||
|
faction:set_name(factionname)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
send_error(player, "Faction cannot be renamed.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
},false)
|
||||||
|
|
||||||
factions.register_command("unclaim", {
|
factions.register_command("unclaim", {
|
||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Unclaim the plot of land you're on.",
|
description = "Unclaim the plot of land you're on.",
|
||||||
@ -280,7 +298,7 @@ factions.register_command("leave", {
|
|||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("kick", {
|
factions.register_command("kick", {
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"kick"},
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
description = "Kick a player from your faction.",
|
description = "Kick a player from your faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
@ -354,25 +372,45 @@ factions.register_command("disband", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("close", {
|
factions.register_command("flag", {
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"flags"},
|
||||||
description = "Make your faction invite-only.",
|
description = "Manage the faction's flags.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
|
format = {"string"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:toggle_join_free(false)
|
--"Make your faction invite-only."
|
||||||
|
--"Allow any player to join your faction."
|
||||||
|
--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
|
return true
|
||||||
end
|
end
|
||||||
},false)
|
if flag_name and bool then
|
||||||
|
local yes = false
|
||||||
factions.register_command("open", {
|
if bool == "yes" then
|
||||||
faction_permissions = {"playerslist"},
|
yes = true
|
||||||
description = "Allow any player to join your faction.",
|
elseif bool == "no" then
|
||||||
global_privileges = def_global_privileges,
|
yes = false
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
else
|
||||||
faction:toggle_join_free(true)
|
send_error(player, "Set the flags only to yes or no.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if flag_name == "open" then
|
||||||
|
faction:toggle_join_free(yes)
|
||||||
|
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
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
},false)
|
},true)
|
||||||
|
|
||||||
factions.register_command("description", {
|
factions.register_command("description", {
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
@ -387,7 +425,7 @@ factions.register_command("description", {
|
|||||||
|
|
||||||
factions.register_command("invite", {
|
factions.register_command("invite", {
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"invite"},
|
||||||
description = "Invite a player to your faction.",
|
description = "Invite a player to your faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
@ -398,7 +436,7 @@ factions.register_command("invite", {
|
|||||||
|
|
||||||
factions.register_command("uninvite", {
|
factions.register_command("uninvite", {
|
||||||
format = {"player"},
|
format = {"player"},
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"invite"},
|
||||||
description = "Revoke a player's invite.",
|
description = "Revoke a player's invite.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
@ -435,7 +473,7 @@ factions.register_command("rank_privileges", {
|
|||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
minetest.chat_send_player(player, "Privileges available:\n")
|
minetest.chat_send_player(player, "Privileges available:\n")
|
||||||
for i, k in pairs(factions.permissions) do
|
for i, k in pairs(factions.permissions) do
|
||||||
minetest.chat_send_player(player, k .. "\n")
|
minetest.chat_send_player(player, k .. ": " .. factions.permissions_desc[i] .. "\n")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -443,7 +481,7 @@ factions.register_command("rank_privileges", {
|
|||||||
|
|
||||||
factions.register_command("set_message_of_the_day", {
|
factions.register_command("set_message_of_the_day", {
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
faction_permissions = {"playerslist"},
|
faction_permissions = {"motd"},
|
||||||
description = "Sets the message that shows up every time a faction member logs-in.",
|
description = "Sets the message that shows up every time a faction member logs-in.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
@ -456,13 +494,13 @@ factions.register_command("set_message_of_the_day", {
|
|||||||
end
|
end
|
||||||
},true)
|
},true)
|
||||||
|
|
||||||
if factions_config.faction_diplomacy then
|
if factions_config.faction_diplomacy == true then
|
||||||
factions.register_command("send_alliance", {
|
factions.register_command("send_alliance", {
|
||||||
description = "Send an alliance request to another faction.",
|
description = "Send an alliance request to another faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"alliance"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if factions.factions[args.strings[1]] then
|
if factions.factions[args.strings[1]] then
|
||||||
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
||||||
if faction.allies[args.strings[1]] then
|
if faction.allies[args.strings[1]] then
|
||||||
@ -491,9 +529,6 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -501,8 +536,8 @@ if factions_config.faction_diplomacy then
|
|||||||
description = "Send neutral to another faction.",
|
description = "Send neutral to another faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"neutral"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if factions.factions[args.strings[1]] then
|
if factions.factions[args.strings[1]] then
|
||||||
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
|
||||||
if faction.allies[args.strings[1]] then
|
if faction.allies[args.strings[1]] then
|
||||||
@ -531,9 +566,6 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
send_error(player, args.strings[1] .. " is not a name of a faction.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -541,8 +573,8 @@ if factions_config.faction_diplomacy then
|
|||||||
description = "accept an request from another faction.",
|
description = "accept an request from another faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"accept_treaty"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if faction.request_inbox[args.strings[1]] then
|
if faction.request_inbox[args.strings[1]] then
|
||||||
if args.strings[1] == faction.name then
|
if args.strings[1] == faction.name then
|
||||||
send_error(player, "You can not accept an request from own faction.")
|
send_error(player, "You can not accept an request from own faction.")
|
||||||
@ -562,9 +594,6 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, "No request was sent to you.")
|
send_error(player, "No request was sent to you.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -572,8 +601,8 @@ if factions_config.faction_diplomacy then
|
|||||||
description = "refuse an request from another faction.",
|
description = "refuse an request from another faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"refuse_treaty"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if faction.request_inbox[args.strings[1]] then
|
if faction.request_inbox[args.strings[1]] then
|
||||||
if args.strings[1] == faction.name then
|
if args.strings[1] == faction.name then
|
||||||
send_error(player, "You can not refuse an request from your own faction.")
|
send_error(player, "You can not refuse an request from your own faction.")
|
||||||
@ -586,9 +615,6 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, "No request was sent to you.")
|
send_error(player, "No request was sent to you.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -596,8 +622,8 @@ if factions_config.faction_diplomacy then
|
|||||||
description = "Delcare war on a faction.",
|
description = "Delcare war on a faction.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"declare_war"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if not faction.enemies[args.strings[1]] then
|
if not faction.enemies[args.strings[1]] then
|
||||||
if args.strings[1] == faction.name then
|
if args.strings[1] == faction.name then
|
||||||
send_error(player, "You can not delcare war on your own faction.")
|
send_error(player, "You can not delcare war on your own faction.")
|
||||||
@ -617,9 +643,6 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, "You are already at war.")
|
send_error(player, "You are already at war.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -627,8 +650,8 @@ if factions_config.faction_diplomacy then
|
|||||||
description = "Break an alliance.",
|
description = "Break an alliance.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
|
faction_permissions = {"alliance"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
if faction.allies[args.strings[1]] then
|
if faction.allies[args.strings[1]] then
|
||||||
if args.strings[1] == faction.name then
|
if args.strings[1] == faction.name then
|
||||||
send_error(player, "You can not break an alliance from your own faction.")
|
send_error(player, "You can not break an alliance from your own faction.")
|
||||||
@ -642,17 +665,14 @@ if factions_config.faction_diplomacy then
|
|||||||
else
|
else
|
||||||
send_error(player, "You where not allies to begin with.")
|
send_error(player, "You where not allies to begin with.")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("inbox", {
|
factions.register_command("inbox", {
|
||||||
description = "Check your diplomacy request inbox.",
|
description = "Check your diplomacy request inbox.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
|
faction_permissions = {"accept_treaty","refuse_treaty","alliance","neutral","declare_war"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if faction:has_permission(player, "diplomacy") then
|
|
||||||
local empty = true
|
local empty = true
|
||||||
for i,k in pairs(faction.request_inbox) do
|
for i,k in pairs(faction.request_inbox) do
|
||||||
if k == "alliance" then
|
if k == "alliance" then
|
||||||
@ -667,9 +687,6 @@ if factions_config.faction_diplomacy then
|
|||||||
if empty then
|
if empty then
|
||||||
minetest.chat_send_player(player,"none:")
|
minetest.chat_send_player(player,"none:")
|
||||||
end
|
end
|
||||||
else
|
|
||||||
send_error(player, "You do not have the diplomacy privilege.")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
@ -737,7 +754,7 @@ factions.register_command("who", {
|
|||||||
|
|
||||||
local parcel_size_center = factions_config.parcel_size / 2
|
local parcel_size_center = factions_config.parcel_size / 2
|
||||||
|
|
||||||
factions.register_command("showparcel", {
|
factions.register_command("show_parcel", {
|
||||||
description = "Shows parcel for six seconds.",
|
description = "Shows parcel for six seconds.",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
@ -755,10 +772,10 @@ factions.register_command("showparcel", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("newrank", {
|
factions.register_command("new_rank", {
|
||||||
description = "Add a new rank.",
|
description = "Add a new rank.",
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"create_ranks"},
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
if args.strings[1] then
|
if args.strings[1] then
|
||||||
@ -799,16 +816,169 @@ factions.register_command("newrank", {
|
|||||||
end
|
end
|
||||||
},true)
|
},true)
|
||||||
|
|
||||||
factions.register_command("delrank", {
|
factions.register_command("replace_privs", {
|
||||||
|
description = "Deletes current permissions and replaces them with the ones given.",
|
||||||
|
format = {"string"},
|
||||||
|
faction_permissions = {"edit_ranks"},
|
||||||
|
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
|
||||||
|
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
|
||||||
|
faction:replace_privs(rank, args.other)
|
||||||
|
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"},
|
||||||
|
faction_permissions = {"edit_ranks"},
|
||||||
|
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
|
||||||
|
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
|
||||||
|
faction:remove_privs(rank, args.other)
|
||||||
|
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"},
|
||||||
|
faction_permissions = {"edit_ranks"},
|
||||||
|
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
|
||||||
|
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
|
||||||
|
faction:add_privs(rank, args.other)
|
||||||
|
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"},
|
||||||
|
faction_permissions = {"edit_ranks"},
|
||||||
|
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
|
||||||
|
faction:set_rank_name(rank, newrank)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
},falsw)
|
||||||
|
|
||||||
|
factions.register_command("del_rank", {
|
||||||
description = "Replace and delete a rank.",
|
description = "Replace and delete a rank.",
|
||||||
format = {"string", "string"},
|
format = {"string", "string"},
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"delete_ranks"},
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local rank = args.strings[1]
|
local rank = args.strings[1]
|
||||||
local newrank = args.strings[2]
|
local newrank = args.strings[2]
|
||||||
if not faction.ranks[rank] or not faction.ranks[newrank] then
|
if not faction.ranks[rank] or not faction.ranks[newrank] then
|
||||||
send_error(player, "One of the specified ranks do not exist.")
|
send_error(player, "One of the specified ranks does not exist.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
faction:delete_rank(rank, newrank)
|
faction:delete_rank(rank, newrank)
|
||||||
@ -816,10 +986,10 @@ factions.register_command("delrank", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("change_def_rank", {
|
factions.register_command("set_def_rank", {
|
||||||
description = "Change the default rank given to new players and also replace rankless players in this faction.",
|
description = "Change the default rank given to new players and also replace rankless players in this faction.",
|
||||||
format = {"string"},
|
format = {"string"},
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"set_def_ranks"},
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local rank = args.strings[1]
|
local rank = args.strings[1]
|
||||||
@ -827,15 +997,25 @@ factions.register_command("change_def_rank", {
|
|||||||
send_error(player, "This rank does not exist.")
|
send_error(player, "This rank does not exist.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
faction:change_def_rank(rank)
|
faction:set_def_rank(rank)
|
||||||
faction.rankless = false
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("setspawn", {
|
factions.register_command("reset_ranks", {
|
||||||
|
description = "Reset's all of the factions rankings back to the default ones.",
|
||||||
|
format = {},
|
||||||
|
faction_permissions = {"reset_ranks"},
|
||||||
|
global_privileges = def_global_privileges,
|
||||||
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
|
faction:reset_ranks()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
},false)
|
||||||
|
|
||||||
|
factions.register_command("set_spawn", {
|
||||||
description = "Set the faction's spawn",
|
description = "Set the faction's spawn",
|
||||||
faction_permissions = {"spawn"},
|
faction_permissions = {"set_spawn"},
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:set_spawn(pos)
|
faction:set_spawn(pos)
|
||||||
@ -843,6 +1023,35 @@ factions.register_command("setspawn", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
|
factions.register_command("del_spawn", {
|
||||||
|
description = "Set the faction's spawn to zero",
|
||||||
|
faction_permissions = {"unset_spawn"},
|
||||||
|
global_privileges = def_global_privileges,
|
||||||
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
|
faction:set_spawn({x=0,y=0,z=0})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
},false)
|
||||||
|
|
||||||
|
if factions_config.spawn_teleport == true then
|
||||||
|
factions.register_command("tp_spawn", {
|
||||||
|
description = "Teleport to the faction's spawn",
|
||||||
|
faction_permissions = {"spawn"},
|
||||||
|
global_privileges = def_global_privileges,
|
||||||
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
|
if player then
|
||||||
|
minetest.chat_send_player(player, "Teleporting in five seconds.")
|
||||||
|
minetest.after(5,
|
||||||
|
function(faction,player)
|
||||||
|
faction:tp_spawn(player)
|
||||||
|
end,faction,player)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
},false)
|
||||||
|
end
|
||||||
|
|
||||||
factions.register_command("where", {
|
factions.register_command("where", {
|
||||||
description = "See whose parcel you stand on.",
|
description = "See whose parcel you stand on.",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
@ -865,7 +1074,7 @@ factions.register_command("help", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("spawn", {
|
factions.register_command("get_spawn", {
|
||||||
description = "Shows your faction's spawn",
|
description = "Shows your faction's spawn",
|
||||||
global_privileges = def_global_privileges,
|
global_privileges = def_global_privileges,
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
@ -974,7 +1183,7 @@ factions.register_command("which", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("setleader", {
|
factions.register_command("set_leader", {
|
||||||
description = "Set a player as a faction's leader",
|
description = "Set a player as a faction's leader",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
@ -1026,7 +1235,7 @@ factions.register_command("remove_admin", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("resetpower", {
|
factions.register_command("reset_power", {
|
||||||
description = "Reset a faction's power",
|
description = "Reset a faction's power",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
@ -1050,7 +1259,7 @@ factions.register_command("obliterate", {
|
|||||||
end
|
end
|
||||||
},false)
|
},false)
|
||||||
|
|
||||||
factions.register_command("getspawn", {
|
factions.register_command("get_factions_spawn", {
|
||||||
description = "Get a faction's spawn",
|
description = "Get a faction's spawn",
|
||||||
infaction = false,
|
infaction = false,
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
|
@ -14,7 +14,7 @@ factions_config.rank_name_max_length = tonumber(minetest.settings:get("rank_name
|
|||||||
factions_config.maximum_faction_inactivity = tonumber(minetest.settings:get("maximum_faction_inactivity")) or 604800
|
factions_config.maximum_faction_inactivity = tonumber(minetest.settings:get("maximum_faction_inactivity")) or 604800
|
||||||
factions_config.maximum_parcelless_faction_time = tonumber(minetest.settings:get("maximum_parcelless_faction_time")) or 10800
|
factions_config.maximum_parcelless_faction_time = tonumber(minetest.settings:get("maximum_parcelless_faction_time")) or 10800
|
||||||
factions_config.power = tonumber(minetest.settings:get("power")) or 0
|
factions_config.power = tonumber(minetest.settings:get("power")) or 0
|
||||||
factions_config.maxpower = tonumber(minetest.settings:get("maxpower")) or 0
|
factions_config.maxpower = tonumber(minetest.settings:get("maxpower")) or 12
|
||||||
factions_config.power_per_player = tonumber(minetest.settings:get("power_per_player")) or 1
|
factions_config.power_per_player = tonumber(minetest.settings:get("power_per_player")) or 1
|
||||||
factions_config.powermax_per_player = tonumber(minetest.settings:get("powermax_per_player")) or 12
|
factions_config.powermax_per_player = tonumber(minetest.settings:get("powermax_per_player")) or 12
|
||||||
factions_config.parcel_size = tonumber(minetest.settings:get("parcel_size")) or 16
|
factions_config.parcel_size = tonumber(minetest.settings:get("parcel_size")) or 16
|
||||||
@ -22,6 +22,7 @@ factions_config.protection_depth_height_limit = minetest.settings:get_bool("prot
|
|||||||
factions_config.enable_power_per_player = minetest.settings:get_bool("power_per_playerb") or true
|
factions_config.enable_power_per_player = minetest.settings:get_bool("power_per_playerb") or true
|
||||||
factions_config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
factions_config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
||||||
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or true
|
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or true
|
||||||
|
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.protection_style = minetest.settings:get("protection_style") or "2d"
|
||||||
factions_config.faction_user_priv = minetest.settings:get("faction_user_priv") or false
|
factions_config.faction_user_priv = minetest.settings:get("faction_user_priv") or false
|
||||||
-- END
|
-- END
|
||||||
@ -39,7 +40,7 @@ factions_config.rank_name_max_length = 25
|
|||||||
factions_config.maximum_faction_inactivity = 604800
|
factions_config.maximum_faction_inactivity = 604800
|
||||||
factions_config.maximum_parcelless_faction_time = 10800
|
factions_config.maximum_parcelless_faction_time = 10800
|
||||||
factions_config.power = 0
|
factions_config.power = 0
|
||||||
factions_config.maxpower = 0
|
factions_config.maxpower = 12
|
||||||
factions_config.power_per_player = 1
|
factions_config.power_per_player = 1
|
||||||
factions_config.powermax_per_player = 12
|
factions_config.powermax_per_player = 12
|
||||||
factions_config.parcel_size = 16
|
factions_config.parcel_size = 16
|
||||||
@ -47,6 +48,7 @@ factions_config.protection_depth_height_limit = true
|
|||||||
factions_config.enable_power_per_player = true
|
factions_config.enable_power_per_player = true
|
||||||
factions_config.attack_parcel = false
|
factions_config.attack_parcel = false
|
||||||
factions_config.faction_diplomacy = true
|
factions_config.faction_diplomacy = true
|
||||||
|
factions_config.spawn_teleport = false
|
||||||
factions_config.protection_style = "2d"
|
factions_config.protection_style = "2d"
|
||||||
factions_config.faction_user_priv = false
|
factions_config.faction_user_priv = false
|
||||||
--]]
|
--]]
|
@ -1 +1,2 @@
|
|||||||
default
|
default?
|
||||||
|
doors?
|
324
factions.lua
324
factions.lua
@ -35,26 +35,95 @@ util = {
|
|||||||
|
|
||||||
factions.Faction.__index = factions.Faction
|
factions.Faction.__index = factions.Faction
|
||||||
|
|
||||||
|
starting_ranks = {["leader"] = {"build","door","container","name","description","motd","invite","kick"
|
||||||
|
,"title","set_spawn","unset_spawn","with_draw","territory","claim","access","disband","flags","create_ranks","edit_ranks","delete_ranks","set_def_ranks","reset_ranks","promote"},
|
||||||
|
["moderator"] = {"claim","door","build","set_spawn","invite","kick","promote"},
|
||||||
|
["member"] = {"build","container","door"}
|
||||||
|
}
|
||||||
|
|
||||||
-- Faction permissions:
|
-- Faction permissions:
|
||||||
--
|
--
|
||||||
-- disband: disband the faction
|
|
||||||
-- claim: (un)claim parcels
|
|
||||||
-- playerslist: invite/kick players and open/close the faction
|
|
||||||
-- build: dig and place nodes
|
-- build: dig and place nodes
|
||||||
-- description: set the faction's description
|
-- pain_build: dig and place nodes but take damage doing so
|
||||||
-- ranks: create and delete ranks
|
-- door: open/close or dig doors
|
||||||
-- spawn: set the faction's spawn
|
-- container: be able to use containers like chest
|
||||||
|
-- name: set the faction's name
|
||||||
|
-- description: Set the faction description
|
||||||
|
-- motd: set the faction's message of the day
|
||||||
|
-- invite: (un)invite players to join the faction
|
||||||
|
-- kick: kick players off the faction
|
||||||
|
-- title: set territory titles
|
||||||
|
-- set_spawn: set the faction's spawn
|
||||||
|
-- unset_spawn: delete the faction's spawn
|
||||||
|
-- with_draw: withdraw money from the faction's bank
|
||||||
|
-- spawn: be able to teleport to the faction's spawn
|
||||||
|
-- territory: claim or unclaim territory
|
||||||
|
-- claim: (un)claim parcels of land
|
||||||
|
-- access: manage access to territory and parcels of land to players or factions
|
||||||
|
-- disband: disband the faction
|
||||||
|
-- flags: manage faction's flags
|
||||||
|
-- create_ranks: create new ranks
|
||||||
|
-- edit_ranks: edit rank name and permissions
|
||||||
|
-- delete_ranks: delete ranks
|
||||||
|
-- set_def_ranks: set the default rank given to new players
|
||||||
|
-- reset_ranks: reset the ranks back to the default ones
|
||||||
-- promote: set a player's rank
|
-- promote: set a player's rank
|
||||||
-- diplomacy: make war, or an alliance with other teams.
|
-- declare_war: be able to declare war with another faction
|
||||||
|
-- neutral: be able to send a neutral request to another faction
|
||||||
|
-- alliance: be able to send a alliance request to another faction and break alliance treaties too
|
||||||
|
-- accept_treaty: be able to accept a treaty request from another faction
|
||||||
|
-- refuse_treaty: be able to refuse a treaty request from another faction
|
||||||
|
|
||||||
factions.permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "promote"}
|
factions.permissions = {"build","pain_build","door","container","name","description","motd","invite","kick"
|
||||||
|
,"title","set_spawn","unset_spawn","with_draw","territory","claim","access","disband","flags","create_ranks","edit_ranks","delete_ranks","set_def_ranks","reset_ranks","promote"}
|
||||||
|
factions.permissions_desc = {"dig and place nodes","dig and place nodes but take damage doing so","open/close or dig","be able to use containers like chest","set the faction's name"
|
||||||
|
,"Set the faction description","set the faction's message of the day","(un)invite players to join the faction","kick players off the faction","set territory titles","set the faction's spawn"
|
||||||
|
,"delete the faction's spawn","withdraw money from the faction's bank","claim or unclaim territory","(un)claim parcels of land","manage access to territory and parcels of land to players or factions"
|
||||||
|
,"disband the faction","manage faction's flags","create new ranks","edit rank permissions","delete ranks","set the default rank given to new players","reset the ranks back to the default ones","set a player's rank"}
|
||||||
|
|
||||||
|
-- open: can the faction be joined without an invite?
|
||||||
|
-- monsters: can monsters spawn on your land?
|
||||||
|
-- tax_kick: will players be kicked for not paying tax?
|
||||||
|
-- animals: can animals spawn on your land?
|
||||||
|
factions.flags = {"open","monsters","tax_kick","animals"}
|
||||||
|
factions.flags_desc = {"can the faction be joined without an invite?","can monsters spawn on your land?(unused)","will players be kicked for not paying tax?(unused)","can animals spawn on your land?(unused)"}
|
||||||
|
|
||||||
|
if factions_config.faction_diplomacy == true then
|
||||||
|
table.insert(factions.permissions,"declare_war")
|
||||||
|
table.insert(factions.permissions,"neutral")
|
||||||
|
table.insert(factions.permissions,"alliance")
|
||||||
|
table.insert(factions.permissions,"accept_treaty")
|
||||||
|
table.insert(factions.permissions,"refuse_treaty")
|
||||||
|
|
||||||
|
table.insert(factions.permissions_desc,"be able to declare war with another faction")
|
||||||
|
table.insert(factions.permissions_desc,"be able to send a neutral request to another faction")
|
||||||
|
table.insert(factions.permissions_desc,"be able to send a alliance request to another faction and break alliance treaties too")
|
||||||
|
table.insert(factions.permissions_desc,"be able to accept a treaty request from another faction")
|
||||||
|
table.insert(factions.permissions_desc,"be able to refuse a treaty request from another faction")
|
||||||
|
|
||||||
|
local lt = starting_ranks["leader"]
|
||||||
|
table.insert(lt,"declare_war")
|
||||||
|
table.insert(lt,"neutral")
|
||||||
|
table.insert(lt,"alliance")
|
||||||
|
table.insert(lt,"accept_treaty")
|
||||||
|
table.insert(lt,"refuse_treaty")
|
||||||
|
starting_ranks["leader"] = lt
|
||||||
|
end
|
||||||
|
|
||||||
|
if factions_config.spawn_teleport == true then
|
||||||
|
table.insert(factions.permissions,"spawn")
|
||||||
|
|
||||||
|
table.insert(factions.permissions_desc,"be able to teleport to the faction's spawn")
|
||||||
|
|
||||||
|
table.insert(starting_ranks["leader"],"spawn")
|
||||||
|
table.insert(starting_ranks["moderator"],"spawn")
|
||||||
|
table.insert(starting_ranks["member"],"spawn")
|
||||||
|
|
||||||
if factions_config.faction_diplomacy then
|
|
||||||
table.insert(factions.permissions,"diplomacy")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.Faction:new(faction)
|
function factions.Faction:new(faction)
|
||||||
faction = {
|
faction = {
|
||||||
|
name = "",
|
||||||
--! @brief power of a faction (needed for parcel claiming)
|
--! @brief power of a faction (needed for parcel claiming)
|
||||||
power = factions_config.power,
|
power = factions_config.power,
|
||||||
--! @brief maximum power of a faction
|
--! @brief maximum power of a faction
|
||||||
@ -68,12 +137,11 @@ function factions.Faction:new(faction)
|
|||||||
--! @brief list of player names offline
|
--! @brief list of player names offline
|
||||||
offlineplayers = {},
|
offlineplayers = {},
|
||||||
--! @brief table of ranks/permissions
|
--! @brief table of ranks/permissions
|
||||||
ranks = {["leader"] = factions.permissions,
|
ranks = starting_ranks,
|
||||||
["moderator"] = {"claim", "playerslist", "build", "spawn"},
|
|
||||||
["member"] = {"build"}
|
|
||||||
},
|
|
||||||
--! @brief name of the leader
|
--! @brief name of the leader
|
||||||
leader = nil,
|
leader = nil,
|
||||||
|
--! @brief spawn of the faction
|
||||||
|
spawn = {x=0, y=0, z=0},
|
||||||
--! @brief default joining rank for new members
|
--! @brief default joining rank for new members
|
||||||
default_rank = "member",
|
default_rank = "member",
|
||||||
--! @brief default rank assigned to the leader
|
--! @brief default rank assigned to the leader
|
||||||
@ -97,7 +165,7 @@ function factions.Faction:new(faction)
|
|||||||
--! @brief table of parcels/factions that are under attack
|
--! @brief table of parcels/factions that are under attack
|
||||||
attacked_parcels = {},
|
attacked_parcels = {},
|
||||||
--! @brief whether faction is closed or open (boolean)
|
--! @brief whether faction is closed or open (boolean)
|
||||||
join_free = true,
|
join_free = false,
|
||||||
--! @brief gives certain privileges
|
--! @brief gives certain privileges
|
||||||
is_admin = false,
|
is_admin = false,
|
||||||
--! @brief if a player on the faction has a nil rank
|
--! @brief if a player on the faction has a nil rank
|
||||||
@ -113,7 +181,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--! @brief create a new empty faction
|
--! @brief create a new empty faction
|
||||||
function factions.new_faction(name)
|
function factions.new_faction(name,do_not_save)
|
||||||
local faction = factions.Faction:new(nil)
|
local faction = factions.Faction:new(nil)
|
||||||
faction.name = name
|
faction.name = name
|
||||||
factions.factions[name] = faction
|
factions.factions[name] = faction
|
||||||
@ -122,18 +190,57 @@ function factions.new_faction(name)
|
|||||||
function(f)
|
function(f)
|
||||||
f:on_no_parcel()
|
f:on_no_parcel()
|
||||||
end,faction)
|
end,faction)
|
||||||
|
if not do_not_save then
|
||||||
factions.save()
|
factions.save()
|
||||||
|
end
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.start_diplomacy(name,faction)
|
function factions.start_diplomacy(name,faction)
|
||||||
for i in pairs(factions.factions) do
|
for i,fac in pairs(factions.factions) do
|
||||||
if i ~= name and not (faction.neutral[i] or faction.allies[i] or faction.enemies[i]) then
|
if i ~= name and not (faction.neutral[i] or faction.allies[i] or faction.enemies[i]) then
|
||||||
faction:new_enemy(i)
|
faction:new_enemy(i)
|
||||||
|
fac:new_enemy(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.set_name(self, name)
|
||||||
|
local oldname = self.name
|
||||||
|
local oldfaction = factions.factions[oldname]
|
||||||
|
self.name = name
|
||||||
|
for i,fac in pairs(factions.factions) do
|
||||||
|
if i ~= oldname then
|
||||||
|
if fac.neutral[oldname] then
|
||||||
|
fac.neutral[oldname] = nil
|
||||||
|
fac.neutral[name] = true
|
||||||
|
end
|
||||||
|
if fac.allies[oldname] then
|
||||||
|
fac.allies[oldname] = nil
|
||||||
|
fac.allies[name] = true
|
||||||
|
end
|
||||||
|
if fac.enemies[oldname] then
|
||||||
|
fac.enemies[oldname] = nil
|
||||||
|
fac.enemies[name] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for parcel in pairs(self.land) do
|
||||||
|
factions.parcels[parcel] = self.name
|
||||||
|
end
|
||||||
|
for playername in pairs(self.players) do
|
||||||
|
factions.players[playername] = self.name
|
||||||
|
end
|
||||||
|
factions.factions[oldname] = nil
|
||||||
|
factions.factions[name] = oldfaction
|
||||||
|
factions.factions[name].name = name
|
||||||
|
for playername in pairs(self.onlineplayers) do
|
||||||
|
updateFactionName(playername,name)
|
||||||
|
end
|
||||||
|
self:on_set_name(oldname)
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.increase_power(self, power)
|
function factions.Faction.increase_power(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
if self.power > self.maxpower - self.usedpower then
|
if self.power > self.maxpower - self.usedpower then
|
||||||
@ -236,7 +343,6 @@ function factions.Faction.add_player(self, player, rank)
|
|||||||
end
|
end
|
||||||
if notsame then
|
if notsame then
|
||||||
self:increase_maxpower(factions_config.powermax_per_player)
|
self:increase_maxpower(factions_config.powermax_per_player)
|
||||||
--self:increase_power(factions_config.power_per_player)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local pdata = minetest.get_player_by_name(player)
|
local pdata = minetest.get_player_by_name(player)
|
||||||
@ -378,8 +484,7 @@ function factions.Faction.disband(self, reason)
|
|||||||
factions.parcels[k] = nil
|
factions.parcels[k] = nil
|
||||||
end
|
end
|
||||||
self:on_disband(reason)
|
self:on_disband(reason)
|
||||||
local playerslist = self.onlineplayers
|
for i,l in pairs(self.onlineplayers) do
|
||||||
for i,l in pairs(playerslist) do
|
|
||||||
removeHud(i,"factionName")
|
removeHud(i,"factionName")
|
||||||
removeHud(i,"powerWatch")
|
removeHud(i,"powerWatch")
|
||||||
end
|
end
|
||||||
@ -519,6 +624,13 @@ function factions.Faction.set_spawn(self, pos)
|
|||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.tp_spawn(self, playername)
|
||||||
|
player = minetest.get_player_by_name(playername)
|
||||||
|
if player then
|
||||||
|
player:moveto(self.spawn, false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--! @brief create a new rank with permissions
|
--! @brief create a new rank with permissions
|
||||||
--! @param rank the name of the new rank
|
--! @param rank the name of the new rank
|
||||||
--! @param rank a list with the permissions of the new rank
|
--! @param rank a list with the permissions of the new rank
|
||||||
@ -528,14 +640,97 @@ function factions.Faction.add_rank(self, rank, perms)
|
|||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.Faction.change_def_rank(self, rank)
|
--! @brief replace an rank's permissions
|
||||||
|
--! @param rank the name of the rank to edit
|
||||||
|
--! @param add or remove permissions to the rank
|
||||||
|
function factions.Faction.replace_privs(self, rank, perms)
|
||||||
|
self.ranks[rank] = perms
|
||||||
|
self:on_replace_privs(rank)
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.remove_privs(self, rank, perms)
|
||||||
|
local revoked = false
|
||||||
|
local p = self.ranks[rank]
|
||||||
|
for index, perm in pairs(p) do
|
||||||
|
if table_Contains(perms,perm) then
|
||||||
|
revoked = true
|
||||||
|
table.remove(p,index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.ranks[rank] = p
|
||||||
|
if revoked then
|
||||||
|
self:on_remove_privs(rank,perms)
|
||||||
|
else
|
||||||
|
self:broadcast("No privilege was revoked from rank "..rank..".")
|
||||||
|
end
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.add_privs(self, rank, perms)
|
||||||
|
local added = false
|
||||||
|
local p = self.ranks[rank]
|
||||||
|
for index, perm in pairs(perms) do
|
||||||
|
if not table_Contains(p,perm) then
|
||||||
|
added = true
|
||||||
|
table.insert(p,perm)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.ranks[rank] = p
|
||||||
|
if added then
|
||||||
|
self:on_add_privs(rank,perms)
|
||||||
|
else
|
||||||
|
self:broadcast("The rank "..rank.." already has these privileges.")
|
||||||
|
end
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.set_rank_name(self, oldrank, newrank)
|
||||||
|
local copyrank = self.ranks[oldrank]
|
||||||
|
self.ranks[newrank] = copyrank
|
||||||
|
self.ranks[oldrank] = nil
|
||||||
|
for player, r in pairs(self.players) do
|
||||||
|
if r == oldrank then
|
||||||
|
self.players[player] = newrank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if oldrank == self.default_leader_rank then
|
||||||
|
self.default_leader_rank = newrank
|
||||||
|
self:broadcast("The default leader rank has been set to "..newrank)
|
||||||
|
end
|
||||||
|
if oldrank == self.default_rank then
|
||||||
|
self.default_rank = newrank
|
||||||
|
self:broadcast("The default rank given to new players is set to "..newrank)
|
||||||
|
end
|
||||||
|
self:on_set_rank_name(oldrank, newrank)
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.set_def_rank(self, rank)
|
||||||
for player, r in pairs(self.players) do
|
for player, r in pairs(self.players) do
|
||||||
if r == rank or r == nil or not self.ranks[r] then
|
if r == rank or r == nil or not self.ranks[r] then
|
||||||
self.players[player] = rank
|
self.players[player] = rank
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.default_rank = rank
|
self.default_rank = rank
|
||||||
self:on_change_def_rank(rank, rank)
|
self:on_set_def_rank(rank)
|
||||||
|
self.rankless = false
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.reset_ranks(self)
|
||||||
|
self.ranks = starting_ranks
|
||||||
|
self.default_rank = "member"
|
||||||
|
self.default_leader_rank_rank = "leader"
|
||||||
|
for player, r in pairs(self.players) do
|
||||||
|
if not player == leader and (r == nil or not self.ranks[r]) then
|
||||||
|
self.players[player] = self.default_rank
|
||||||
|
elseif player == leader then
|
||||||
|
self.players[player] = self.default_leader_rank_rank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self:on_reset_ranks()
|
||||||
|
self.rankless = false
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -639,6 +834,10 @@ function factions.Faction.on_create(self) --! @brief called when the faction is
|
|||||||
minetest.chat_send_all("Faction "..self.name.." has been created.")
|
minetest.chat_send_all("Faction "..self.name.." has been created.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_set_name(self,oldname)
|
||||||
|
minetest.chat_send_all("Faction "..oldname.." has been changed its name to "..self.name..".")
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.on_no_parcel(self)
|
function factions.Faction.on_no_parcel(self)
|
||||||
local now = os.time() - self.no_parcel
|
local now = os.time() - self.no_parcel
|
||||||
local l = factions_config.maximum_parcelless_faction_time
|
local l = factions_config.maximum_parcelless_faction_time
|
||||||
@ -721,14 +920,34 @@ function factions.Faction.on_add_rank(self, rank)
|
|||||||
self:broadcast("The rank "..rank.." has been created with privileges: "..table.concat(self.ranks[rank], ", "))
|
self:broadcast("The rank "..rank.." has been created with privileges: "..table.concat(self.ranks[rank], ", "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_replace_privs(self, rank)
|
||||||
|
self:broadcast("The privileges in rank "..rank.." have been delete and changed to: "..table.concat(self.ranks[rank], ", "))
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_remove_privs(self, rank,privs)
|
||||||
|
self:broadcast("The privileges in rank "..rank.." have been revoked: "..table.concat(privs, ", "))
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_add_privs(self, rank,privs)
|
||||||
|
self:broadcast("The privileges in rank "..rank.." have been added: "..table.concat(privs, ", "))
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_set_rank_name(self, rank,newrank)
|
||||||
|
self:broadcast("The name of rank "..rank.." has been changed to "..newrank)
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.on_delete_rank(self, rank, newrank)
|
function factions.Faction.on_delete_rank(self, rank, newrank)
|
||||||
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
|
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.Faction.on_change_def_rank(self, rank)
|
function factions.Faction.on_set_def_rank(self, rank)
|
||||||
self:broadcast("The default rank given to new players has been changed to "..rank)
|
self:broadcast("The default rank given to new players has been changed to "..rank)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.on_reset_ranks(self)
|
||||||
|
self:broadcast("All of the faction's ranks have been reset to the default ones.")
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.on_promote(self, member)
|
function factions.Faction.on_promote(self, member)
|
||||||
minetest.chat_send_player(member, "You have been promoted to "..self.players[member])
|
minetest.chat_send_player(member, "You have been promoted to "..self.players[member])
|
||||||
end
|
end
|
||||||
@ -908,14 +1127,13 @@ function factions.load()
|
|||||||
if faction:count_land() > 0 then
|
if faction:count_land() > 0 then
|
||||||
faction.no_parcel = -1
|
faction.no_parcel = -1
|
||||||
end
|
end
|
||||||
if faction.onlineplayers and faction.offlineplayers then
|
faction.onlineplayers = {}
|
||||||
for i, _ in pairs(faction.onlineplayers) do
|
faction.offlineplayers = {}
|
||||||
|
if faction.players then
|
||||||
|
for i, _ in pairs(faction.players) do
|
||||||
faction.offlineplayers[i] = _
|
faction.offlineplayers[i] = _
|
||||||
end
|
end
|
||||||
else
|
|
||||||
faction.offlineplayers = {}
|
|
||||||
end
|
end
|
||||||
faction.onlineplayers = {}
|
|
||||||
end
|
end
|
||||||
misc_mod_data.data.factions_version = current_version
|
misc_mod_data.data.factions_version = current_version
|
||||||
misc_mod_data.save()
|
misc_mod_data.save()
|
||||||
@ -968,7 +1186,10 @@ function factions.convert(filename)
|
|||||||
end
|
end
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
file:close()
|
file:close()
|
||||||
|
|
||||||
local data = minetest.deserialize(raw_data)
|
local data = minetest.deserialize(raw_data)
|
||||||
|
local old_permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "promote","diplomacy"}
|
||||||
|
|
||||||
for facname,faction in pairs(data) do
|
for facname,faction in pairs(data) do
|
||||||
local newfac = factions.new_faction(facname,true)
|
local newfac = factions.new_faction(facname,true)
|
||||||
for oi, ol in pairs(faction) do
|
for oi, ol in pairs(faction) do
|
||||||
@ -990,6 +1211,35 @@ function factions.convert(filename)
|
|||||||
else
|
else
|
||||||
newfac.rankless = false
|
newfac.rankless = false
|
||||||
end
|
end
|
||||||
|
for rank,perm in pairs(faction.ranks) do
|
||||||
|
for index,value in pairs(perm) do
|
||||||
|
if value == "playerslist" then
|
||||||
|
table.remove(faction.ranks[rank],index)
|
||||||
|
table.insert(faction.ranks[rank],"kick")
|
||||||
|
table.insert(faction.ranks[rank],"invite")
|
||||||
|
elseif value == "ranks" then
|
||||||
|
table.remove(faction.ranks[rank],index)
|
||||||
|
table.insert(faction.ranks[rank],"create_ranks")
|
||||||
|
table.insert(faction.ranks[rank],"edit_ranks")
|
||||||
|
table.insert(faction.ranks[rank],"delete_ranks")
|
||||||
|
table.insert(faction.ranks[rank],"set_def_ranks")
|
||||||
|
table.insert(faction.ranks[rank],"reset_ranks")
|
||||||
|
elseif value == "diplomacy" then
|
||||||
|
table.remove(faction.ranks[rank],index)
|
||||||
|
table.insert(faction.ranks[rank],"declare_war")
|
||||||
|
table.insert(faction.ranks[rank],"neutral")
|
||||||
|
table.insert(faction.ranks[rank],"alliance")
|
||||||
|
table.insert(faction.ranks[rank],"accept_treaty")
|
||||||
|
table.insert(faction.ranks[rank],"refuse_treaty")
|
||||||
|
elseif value == "spawn" then
|
||||||
|
if not factions_config.spawn_teleport == true then
|
||||||
|
table.remove(faction.ranks[rank],index)
|
||||||
|
end
|
||||||
|
table.insert(faction.ranks[rank],"set_spawn")
|
||||||
|
table.insert(faction.ranks[rank],"unset_spawn")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
factions.start_diplomacy(facname,newfac)
|
factions.start_diplomacy(facname,newfac)
|
||||||
newfac:check_power()
|
newfac:check_power()
|
||||||
end
|
end
|
||||||
@ -1020,7 +1270,6 @@ function(player)
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
function factions.faction_tick()
|
function factions.faction_tick()
|
||||||
local now = os.time()
|
local now = os.time()
|
||||||
for facname, faction in pairs(factions.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
@ -1056,12 +1305,12 @@ function(player)
|
|||||||
local l = factions_config.maximum_parcelless_faction_time
|
local l = factions_config.maximum_parcelless_faction_time
|
||||||
minetest.chat_send_player(name,"This faction will disband in "..l-now.." seconds, because it has no parcels.")
|
minetest.chat_send_player(name,"This faction will disband in "..l-now.." seconds, because it has no parcels.")
|
||||||
end
|
end
|
||||||
if faction:has_permission(name, "diplomacy") then
|
if faction:has_permission(name, "accept_treaty") or faction:has_permission(name, "refuse_treaty") then
|
||||||
for _ in pairs(faction.request_inbox) do minetest.chat_send_player(name,"You have diplomatic requests in the inbox.") break end
|
for _ in pairs(faction.request_inbox) do minetest.chat_send_player(name,"You have diplomatic requests in the inbox.") break end
|
||||||
end
|
end
|
||||||
if faction:has_permission(name, "ranks") then
|
if faction:has_permission(name, "ranks") then
|
||||||
if faction.rankless then
|
if faction.rankless then
|
||||||
minetest.chat_send_player(name,"You need to reset the default rank because there are rankless players in this faction. type /f change_def_rank")
|
minetest.chat_send_player(name,"You need to reset the default rank because there are rankless players in this faction. reset all the ranks back to default using /f reset_ranks (You will lose all of your custom ranks) or use /f change_def_rank")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if faction.message_of_the_day and (faction.message_of_the_day ~= "" or faction.message_of_the_day ~= " ") then
|
if faction.message_of_the_day and (faction.message_of_the_day ~= "" or faction.message_of_the_day ~= " ") then
|
||||||
@ -1090,6 +1339,7 @@ minetest.register_on_leaveplayer(
|
|||||||
end
|
end
|
||||||
faction.offlineplayers[name] = 1
|
faction.offlineplayers[name] = 1
|
||||||
faction.onlineplayers[name] = nil
|
faction.onlineplayers[name] = nil
|
||||||
|
factions.save()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
@ -1127,9 +1377,17 @@ minetest.is_protected = function(pos, player)
|
|||||||
return default_is_protected(pos, player)
|
return default_is_protected(pos, player)
|
||||||
elseif player_faction then
|
elseif player_faction then
|
||||||
if parcel_faction.name == player_faction.name then
|
if parcel_faction.name == player_faction.name then
|
||||||
return not parcel_faction:has_permission(player, "build")
|
if parcel_faction:has_permission(player, "pain_build") then
|
||||||
|
local p = minetest.get_player_by_name(player)
|
||||||
|
p:set_hp(p:get_hp() - 0.5)
|
||||||
|
end
|
||||||
|
return not (parcel_faction:has_permission(player, "build") or parcel_faction:has_permission(player, "pain_build"))
|
||||||
elseif parcel_faction.allies[player_faction.name] then
|
elseif parcel_faction.allies[player_faction.name] then
|
||||||
return not player_faction:has_permission(player, "build")
|
if player_faction:has_permission(player, "pain_build") then
|
||||||
|
local p = minetest.get_player_by_name(player)
|
||||||
|
p:set_hp(p:get_hp() - 0.5)
|
||||||
|
end
|
||||||
|
return not (player_faction:has_permission(player, "build") or player_faction:has_permission(player, "pain_build"))
|
||||||
else
|
else
|
||||||
return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction)
|
return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction)
|
||||||
end
|
end
|
||||||
|
32
hud.lua
32
hud.lua
@ -56,14 +56,6 @@ function createHudPower(player,faction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function updateHudPower(player,faction)
|
|
||||||
local name = player:get_player_name()
|
|
||||||
local id_name = name .. "powerWatch"
|
|
||||||
if hud_ids[id_name] then
|
|
||||||
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function removeHud(player,hudname)
|
function removeHud(player,hudname)
|
||||||
local name = ""
|
local name = ""
|
||||||
local p = {}
|
local p = {}
|
||||||
@ -81,6 +73,30 @@ function removeHud(player,hudname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function updateHudPower(player,faction)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local id_name = name .. "powerWatch"
|
||||||
|
if hud_ids[id_name] then
|
||||||
|
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function updateFactionName(player,factionname)
|
||||||
|
local name = ""
|
||||||
|
local p = {}
|
||||||
|
if type(player) ~= "string" then
|
||||||
|
name = player:get_player_name()
|
||||||
|
p = player
|
||||||
|
else
|
||||||
|
name = player
|
||||||
|
p = minetest.get_player_by_name(player)
|
||||||
|
end
|
||||||
|
local id_name = name .. "factionName"
|
||||||
|
if hud_ids[id_name] then
|
||||||
|
p:hud_change(hud_ids[id_name],"text","Faction "..factionname)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function hudUpdateClaimInfo()
|
function hudUpdateClaimInfo()
|
||||||
local playerslist = minetest.get_connected_players()
|
local playerslist = minetest.get_connected_players()
|
||||||
for i in pairs(playerslist) do
|
for i in pairs(playerslist) do
|
||||||
|
140
nodes.lua
140
nodes.lua
@ -1,93 +1,103 @@
|
|||||||
function factions.get_chest_formspec(pos)
|
function factions.can_use_node(pos, player,permission)
|
||||||
local spos = pos.x..","..pos.y..","..pos.z
|
|
||||||
return "size[8,9]" ..
|
|
||||||
default.gui_bg ..
|
|
||||||
default.gui_bg_img ..
|
|
||||||
default.gui_slots ..
|
|
||||||
"list[nodemeta:"..spos..";main;0,0.3;8,4;]" ..
|
|
||||||
"list[current_player;main;0,4.85;8,1;]"..
|
|
||||||
"list[current_player;main;0,6.08;8,3;8]"..
|
|
||||||
"listring[nodemeta:"..spos..";main]"..
|
|
||||||
"listring[current_player;main]"..
|
|
||||||
default.get_hotbar_bg(0, 4.85)
|
|
||||||
end
|
|
||||||
|
|
||||||
function factions.can_use_chest(pos, player)
|
|
||||||
if not player then
|
if not player then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local parcel_faction = factions.get_faction_at(pos)
|
local parcel_faction = factions.get_faction_at(pos)
|
||||||
local player_faction = factions.get_player_faction(player)
|
|
||||||
if not parcel_faction then
|
if not parcel_faction then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return player_faction and (parcel_faction.name == player_faction.name or parcel_faction.allies[player_faction.name])
|
local player_faction = factions.get_player_faction(player)
|
||||||
|
if player_faction and (parcel_faction.name == player_faction.name or parcel_faction.allies[player_faction.name]) and player_faction:has_permission(player, permission) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
-- Make default chest the faction chest.
|
||||||
minetest.register_node("factions:chest", {
|
if minetest.registered_nodes["default:chest"] then
|
||||||
tiles = {"factions_chest_top.png", "factions_chest_top.png",
|
minetest.register_lbm({
|
||||||
"factions_chest_side.png", "factions_chest_side.png",
|
label = "Replace faction chest with default one.",
|
||||||
"factions_chest_side.png", "factions_chest_front.png"},
|
name = "factions:replace_factions_chest",
|
||||||
groups = {choppy = 2},
|
nodenames = {"factions:chest"},
|
||||||
description = "Faction chest",
|
action = function(pos, node)
|
||||||
paramtype2 = "facedir",
|
minetest.swap_node(pos, {name="default:chest"})
|
||||||
on_construct = function(pos)
|
local parcel_faction = factions.get_faction_at(pos)
|
||||||
|
if parcel_faction then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
meta:set_string("infotext", "Faction Chest")
|
meta:set_string("faction", parcel_faction.name or "")
|
||||||
meta:set_string("faction", "")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
inv:set_size("main", 8*4)
|
|
||||||
end,
|
|
||||||
after_place_node = function(pos, placer)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local cf = factions.get_player_faction(placer:get_player_name())
|
|
||||||
if cf ~= nil then
|
|
||||||
meta:set_string("faction", cf.name or "")
|
|
||||||
meta:set_string("infotext", "Faction Chest (owned by faction " ..
|
meta:set_string("infotext", "Faction Chest (owned by faction " ..
|
||||||
meta:get_string("faction") .. ")")
|
meta:get_string("faction") .. ")")
|
||||||
end
|
end
|
||||||
end,
|
end
|
||||||
can_dig = function(pos,player)
|
})
|
||||||
|
local dc = minetest.registered_nodes["default:chest"]
|
||||||
|
local def_on_rightclick = dc.on_rightclick
|
||||||
|
local clonenode = {}
|
||||||
|
for k,v in pairs(minetest.registered_nodes["default:chest"]) do clonenode[k] = v end
|
||||||
|
clonenode.after_place_node = function(pos, placer)
|
||||||
|
local parcel_faction = factions.get_faction_at(pos)
|
||||||
|
if parcel_faction then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_string("faction", parcel_faction.name or "")
|
||||||
|
meta:set_string("infotext", "Faction Chest (owned by faction " ..
|
||||||
|
meta:get_string("faction") .. ")")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
clonenode.can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return inv:is_empty("main") and
|
return inv:is_empty("main") and
|
||||||
factions.can_use_chest(pos, player:get_player_name())
|
factions.can_use_node(pos, player:get_player_name(),"container")
|
||||||
end,
|
end
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
clonenode.allow_metadata_inventory_move = function(pos, from_list, from_index,
|
||||||
if factions.can_use_chest(pos, player:get_player_name()) then
|
to_list, to_index, count, player)
|
||||||
|
if not factions.can_use_node(pos, player:get_player_name(),"container") then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
return count
|
return count
|
||||||
else
|
end
|
||||||
|
clonenode.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
|
return 0
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
||||||
if factions.can_use_chest(pos, player:get_player_name()) then
|
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
else
|
end
|
||||||
|
clonenode.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
|
return 0
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
||||||
if factions.can_use_chest(pos, player:get_player_name()) then
|
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
else
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
|
||||||
if factions.can_use_chest(pos, clicker:get_player_name()) then
|
|
||||||
minetest.show_formspec(clicker:get_player_name(), "factions:chest", factions.get_chest_formspec(pos))
|
|
||||||
end
|
end
|
||||||
|
clonenode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
if not factions.can_use_node(pos, clicker:get_player_name(),"container") then
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
})
|
def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
end
|
||||||
minetest.register_craft({
|
minetest.register_node(":default:chest",clonenode)
|
||||||
output = "factions:chest",
|
end
|
||||||
type = "shapeless",
|
-- Edit default doors and trapdoors to make them require the door permission.
|
||||||
recipe = {"default:chest_locked", "default:steel_ingot"}
|
local doors = {"doors:door_wood_a","doors:door_wood_b","doors:door_steel_a","doors:door_steel_b","doors:door_glass_a","doors:door_glass_b"
|
||||||
})
|
,"doors:door_obsidian_glass_a","doors:door_obsidian_glass_b","doors:trapdoor","doors:trapdoor_open","doors:trapdoor_steel","doors:trapdoor_steel_open"}
|
||||||
|
for i,k in ipairs(doors) do
|
||||||
|
if minetest.registered_nodes[k] then
|
||||||
|
local dw = minetest.registered_nodes[k]
|
||||||
|
local def_after_place_node = dw.on_rightclick
|
||||||
|
local can_dig = dw.can_dig
|
||||||
|
local clonenode = {}
|
||||||
|
for k,v in pairs(minetest.registered_nodes[k]) do clonenode[k] = v end
|
||||||
|
clonenode.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
if factions.can_use_node(pos, clicker:get_player_name(),"door") then
|
||||||
|
def_after_place_node(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
clonenode.can_dig = function(pos, digger)
|
||||||
|
if factions.can_use_node(pos, digger:get_player_name(),"door") then
|
||||||
|
return can_dig(pos, digger)
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
minetest.register_node(":"..k,clonenode)
|
||||||
|
end
|
||||||
|
end
|
||||||
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.
|
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.
|
||||||
|
|
||||||
local x = math.floor(factions_config.parcel_size / 2.1)
|
local x = math.floor(factions_config.parcel_size / 2.1)
|
||||||
|
@ -25,7 +25,7 @@ maximum_parcelless_faction_time (Maximum parcelless faction time) int 10800
|
|||||||
# Power of a starting faction (needed for parcel claiming).
|
# Power of a starting faction (needed for parcel claiming).
|
||||||
power (Starting power) float 0
|
power (Starting power) float 0
|
||||||
# Maximum power of a starting faction.
|
# Maximum power of a starting faction.
|
||||||
maxpower (Starting Maximum power) float 0
|
maxpower (Starting Maximum power) float 12
|
||||||
# How much power the players make.
|
# How much power the players make.
|
||||||
power_per_player (power-per-player) float 1
|
power_per_player (power-per-player) float 1
|
||||||
# How much max power is created per new player.
|
# How much max power is created per new player.
|
||||||
@ -43,6 +43,8 @@ factions_config.attack_parcel (Enable attack parcel) bool false
|
|||||||
faction_diplomacy (Enable faction diplomacy) bool true
|
faction_diplomacy (Enable faction diplomacy) bool true
|
||||||
# Enable or disabled the max depth and height limit for a parcel
|
# Enable or disabled the max depth and height limit for a parcel
|
||||||
protection_depth_height_limit (Enable protection depth height limit) bool true
|
protection_depth_height_limit (Enable protection depth height limit) bool true
|
||||||
|
# Enable or disabled faction spawn teleport
|
||||||
|
spawn_teleport (Enable spawn teleport) bool false
|
||||||
# Enable or disabled the need for faction_user priv
|
# Enable or disabled the need for faction_user priv
|
||||||
faction_user_priv (Enable faction user priv) bool false
|
faction_user_priv (Enable faction user priv) bool false
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 719 B |
Binary file not shown.
Before Width: | Height: | Size: 646 B |
Binary file not shown.
Before Width: | Height: | Size: 705 B |
Loading…
Reference in New Issue
Block a user