Major update 2

This commit is contained in:
Coder12a 2018-10-31 16:15:08 -05:00
parent 9dd577e699
commit a419cd6c17
11 changed files with 807 additions and 313 deletions

View File

@ -19,10 +19,6 @@ More claim and unclaim commands.
faction access manage command.
More permissions.
faction flags(Not to replace parcels).
Maybe expand on diplomacy.
Write the forum topic better.

View File

@ -94,8 +94,9 @@ factions.register_command = function(cmd_name, cmd, ignore_param_count)
end
if self.faction_permissions then
for i in ipairs(self.faction_permissions) do
if not player_faction:has_permission(player, self.faction_permissions[i]) then
send_error(player, "You don't have permissions to do that.")
local perm = self.faction_permissions[i]
if not player_faction:has_permission(player, perm) then
send_error(player, "You do not have the faction permission "..perm)
return false
end
end
@ -120,7 +121,7 @@ end
local init_commands
init_commands = function()
if factions_config.faction_user_priv then
if factions_config.faction_user_priv == true then
minetest.register_privilege("faction_user",
{
description = "this user is allowed to interact with faction mod",
@ -129,6 +130,7 @@ init_commands = function()
)
end
minetest.register_privilege("faction_admin",
{
description = "this user is allowed to create or delete factions",
@ -137,20 +139,19 @@ init_commands = function()
)
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
end
minetest.register_chatcommand("factions",
{
params = "<cmd> <parameter 1> .. <parameter n>",
description = "faction administration functions",
params = "<command> parameters",
description = "Factions commands. Type /factions help for available commands.",
privs = def_privs,
func = factions_chat.cmdhandler,
}
)
minetest.register_chatcommand("f",
{
params = "<command> parameters",
@ -168,7 +169,7 @@ end
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)
local name = player:get_player_name()
local privs = minetest.get_player_privs(name)
@ -208,6 +209,23 @@ factions.register_command ("claim", {
end
},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", {
faction_permissions = {"claim"},
description = "Unclaim the plot of land you're on.",
@ -280,7 +298,7 @@ factions.register_command("leave", {
},false)
factions.register_command("kick", {
faction_permissions = {"playerslist"},
faction_permissions = {"kick"},
format = {"player"},
description = "Kick a player from your faction.",
global_privileges = def_global_privileges,
@ -354,25 +372,45 @@ factions.register_command("disband", {
end
},false)
factions.register_command("close", {
faction_permissions = {"playerslist"},
description = "Make your faction invite-only.",
factions.register_command("flag", {
faction_permissions = {"flags"},
description = "Manage the faction's flags.",
global_privileges = def_global_privileges,
format = {"string"},
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
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
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
end
},false)
factions.register_command("open", {
faction_permissions = {"playerslist"},
description = "Allow any player to join your faction.",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
faction:toggle_join_free(true)
return true
end
},false)
},true)
factions.register_command("description", {
format = {"string"},
@ -387,7 +425,7 @@ factions.register_command("description", {
factions.register_command("invite", {
format = {"player"},
faction_permissions = {"playerslist"},
faction_permissions = {"invite"},
description = "Invite a player to your faction.",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
@ -398,7 +436,7 @@ factions.register_command("invite", {
factions.register_command("uninvite", {
format = {"player"},
faction_permissions = {"playerslist"},
faction_permissions = {"invite"},
description = "Revoke a player's invite.",
global_privileges = def_global_privileges,
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)
minetest.chat_send_player(player, "Privileges available:\n")
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
return true
end
@ -443,7 +481,7 @@ factions.register_command("rank_privileges", {
factions.register_command("set_message_of_the_day", {
format = {"string"},
faction_permissions = {"playerslist"},
faction_permissions = {"motd"},
description = "Sets the message that shows up every time a faction member logs-in.",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
@ -456,43 +494,40 @@ factions.register_command("set_message_of_the_day", {
end
},true)
if factions_config.faction_diplomacy then
if factions_config.faction_diplomacy == true then
factions.register_command("send_alliance", {
description = "Send an alliance request to another faction.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"alliance"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if factions.factions[args.strings[1]] then
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
if faction.allies[args.strings[1]] then
send_error(player, "You are already allys.")
return false
end
if faction.enemies[args.strings[1]] then
send_error(player, "You need to be neutral in-order to send an alliance request.")
return false
end
if args.strings[1] == faction.name then
send_error(player, "You can not send an alliance to your own faction.")
return false
end
if faction.request_inbox[args.strings[1]] then
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
return false
end
factions.factions[args.strings[1]].request_inbox[faction.name] = "alliance"
factions.factions[args.strings[1]]:broadcast("An alliance request from faction " .. faction.name .. " has been sent to you.")
faction:broadcast("An alliance request was sent to faction " .. args.strings[1])
factions.save()
else
send_error(player, "You have already sent a request.")
if factions.factions[args.strings[1]] then
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
if faction.allies[args.strings[1]] then
send_error(player, "You are already allys.")
return false
end
if faction.enemies[args.strings[1]] then
send_error(player, "You need to be neutral in-order to send an alliance request.")
return false
end
if args.strings[1] == faction.name then
send_error(player, "You can not send an alliance to your own faction.")
return false
end
if faction.request_inbox[args.strings[1]] then
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
return false
end
factions.factions[args.strings[1]].request_inbox[faction.name] = "alliance"
factions.factions[args.strings[1]]:broadcast("An alliance request from faction " .. faction.name .. " has been sent to you.")
faction:broadcast("An alliance request was sent to faction " .. args.strings[1])
factions.save()
else
send_error(player, args.strings[1] .. " is not a name of a faction.")
send_error(player, "You have already sent a request.")
end
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, args.strings[1] .. " is not a name of a faction.")
end
end
},false)
@ -501,38 +536,35 @@ if factions_config.faction_diplomacy then
description = "Send neutral to another faction.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"neutral"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if factions.factions[args.strings[1]] then
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
if faction.allies[args.strings[1]] then
send_error(player, "You are allys.")
return false
end
if faction.neutral[args.strings[1]] then
send_error(player, "You are already neutral with this faction.")
return false
end
if args.strings[1] == faction.name then
send_error(player, "You can not send a neutral request to your own faction.")
return false
end
if faction.request_inbox[args.strings[1]] then
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
return false
end
factions.factions[args.strings[1]].request_inbox[faction.name] = "neutral"
factions.factions[args.strings[1]]:broadcast("A neutral request from faction " .. faction.name .. " has been sent to you.")
faction:broadcast("A neutral request was sent to faction " .. args.strings[1])
factions.save()
else
send_error(player, "You have already sent a request.")
if factions.factions[args.strings[1]] then
if not factions.factions[args.strings[1]].request_inbox[faction.name] then
if faction.allies[args.strings[1]] then
send_error(player, "You are allys.")
return false
end
if faction.neutral[args.strings[1]] then
send_error(player, "You are already neutral with this faction.")
return false
end
if args.strings[1] == faction.name then
send_error(player, "You can not send a neutral request to your own faction.")
return false
end
if faction.request_inbox[args.strings[1]] then
send_error(player, "Faction " .. args.strings[1] .. "has already sent a request to you.")
return false
end
factions.factions[args.strings[1]].request_inbox[faction.name] = "neutral"
factions.factions[args.strings[1]]:broadcast("A neutral request from faction " .. faction.name .. " has been sent to you.")
faction:broadcast("A neutral request was sent to faction " .. args.strings[1])
factions.save()
else
send_error(player, args.strings[1] .. " is not a name of a faction.")
send_error(player, "You have already sent a request.")
end
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, args.strings[1] .. " is not a name of a faction.")
end
end
},false)
@ -541,29 +573,26 @@ if factions_config.faction_diplomacy then
description = "accept an request from another faction.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"accept_treaty"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if faction.request_inbox[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not accept an request from own faction.")
return false
end
if faction.request_inbox[args.strings[1]] == "alliance" then
faction:new_alliance(args.strings[1])
factions.factions[args.strings[1]]:new_alliance(faction.name)
else
if faction.request_inbox[args.strings[1]] == "neutral" then
faction:new_neutral(args.strings[1])
factions.factions[args.strings[1]]:new_neutral(faction.name)
end
end
faction.request_inbox[args.strings[1]] = nil
factions.save()
else
send_error(player, "No request was sent to you.")
if faction.request_inbox[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not accept an request from own faction.")
return false
end
if faction.request_inbox[args.strings[1]] == "alliance" then
faction:new_alliance(args.strings[1])
factions.factions[args.strings[1]]:new_alliance(faction.name)
else
if faction.request_inbox[args.strings[1]] == "neutral" then
faction:new_neutral(args.strings[1])
factions.factions[args.strings[1]]:new_neutral(faction.name)
end
end
faction.request_inbox[args.strings[1]] = nil
factions.save()
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, "No request was sent to you.")
end
end
},false)
@ -572,22 +601,19 @@ if factions_config.faction_diplomacy then
description = "refuse an request from another faction.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"refuse_treaty"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if faction.request_inbox[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not refuse an request from your own faction.")
return false
end
faction.request_inbox[args.strings[1]] = nil
factions.factions[args.strings[1]]:broadcast("Faction " .. faction.name .. " refuse to be your ally.")
faction:broadcast("Refused an request from faction " .. args.strings[1])
factions.save()
else
send_error(player, "No request was sent to you.")
if faction.request_inbox[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not refuse an request from your own faction.")
return false
end
faction.request_inbox[args.strings[1]] = nil
factions.factions[args.strings[1]]:broadcast("Faction " .. faction.name .. " refuse to be your ally.")
faction:broadcast("Refused an request from faction " .. args.strings[1])
factions.save()
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, "No request was sent to you.")
end
end
},false)
@ -596,29 +622,26 @@ if factions_config.faction_diplomacy then
description = "Delcare war on a faction.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"declare_war"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if not faction.enemies[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not delcare war on your own faction.")
return false
end
if faction.allies[args.strings[1]] then
faction:end_alliance(args.strings[1])
factions.factions[args.strings[1]]:end_alliance(faction.name)
end
if faction.neutral[args.strings[1]] then
faction:end_neutral(args.strings[1])
factions.factions[args.strings[1]]:end_neutral(faction.name)
end
faction:new_enemy(args.strings[1])
factions.factions[args.strings[1]]:new_enemy(faction.name)
factions.save()
else
send_error(player, "You are already at war.")
if not faction.enemies[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not delcare war on your own faction.")
return false
end
if faction.allies[args.strings[1]] then
faction:end_alliance(args.strings[1])
factions.factions[args.strings[1]]:end_alliance(faction.name)
end
if faction.neutral[args.strings[1]] then
faction:end_neutral(args.strings[1])
factions.factions[args.strings[1]]:end_neutral(faction.name)
end
faction:new_enemy(args.strings[1])
factions.factions[args.strings[1]]:new_enemy(faction.name)
factions.save()
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, "You are already at war.")
end
end
},false)
@ -627,23 +650,20 @@ if factions_config.faction_diplomacy then
description = "Break an alliance.",
global_privileges = def_global_privileges,
format = {"string"},
faction_permissions = {"alliance"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
if faction.allies[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not break an alliance from your own faction.")
return false
end
faction:end_alliance(args.strings[1])
factions.factions[args.strings[1]]:end_alliance(faction.name)
faction:new_neutral(args.strings[1])
factions.factions[args.strings[1]]:new_neutral(faction.name)
factions.save()
else
send_error(player, "You where not allies to begin with.")
if faction.allies[args.strings[1]] then
if args.strings[1] == faction.name then
send_error(player, "You can not break an alliance from your own faction.")
return false
end
faction:end_alliance(args.strings[1])
factions.factions[args.strings[1]]:end_alliance(faction.name)
faction:new_neutral(args.strings[1])
factions.factions[args.strings[1]]:new_neutral(faction.name)
factions.save()
else
send_error(player, "You do not have the diplomacy privilege.")
send_error(player, "You where not allies to begin with.")
end
end
},false)
@ -651,24 +671,21 @@ if factions_config.faction_diplomacy then
factions.register_command("inbox", {
description = "Check your diplomacy request inbox.",
global_privileges = def_global_privileges,
faction_permissions = {"accept_treaty","refuse_treaty","alliance","neutral","declare_war"},
on_success = function(player, faction, pos, parcelpos, args)
if faction:has_permission(player, "diplomacy") then
local empty = true
for i,k in pairs(faction.request_inbox) do
if k == "alliance" then
minetest.chat_send_player(player,"Alliance request from faction " .. i .. "\n")
else
if k == "neutral" then
minetest.chat_send_player(player,"neutral request from faction " .. i .. "\n")
end
end
empty = false
local empty = true
for i,k in pairs(faction.request_inbox) do
if k == "alliance" then
minetest.chat_send_player(player,"Alliance request from faction " .. i .. "\n")
else
if k == "neutral" then
minetest.chat_send_player(player,"neutral request from faction " .. i .. "\n")
end
if empty then
minetest.chat_send_player(player,"none:")
end
else
send_error(player, "You do not have the diplomacy privilege.")
empty = false
end
if empty then
minetest.chat_send_player(player,"none:")
end
end
},false)
@ -737,7 +754,7 @@ factions.register_command("who", {
local parcel_size_center = factions_config.parcel_size / 2
factions.register_command("showparcel", {
factions.register_command("show_parcel", {
description = "Shows parcel for six seconds.",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
@ -755,10 +772,10 @@ factions.register_command("showparcel", {
end
},false)
factions.register_command("newrank", {
factions.register_command("new_rank", {
description = "Add a new rank.",
format = {"string"},
faction_permissions = {"ranks"},
faction_permissions = {"create_ranks"},
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
if args.strings[1] then
@ -786,7 +803,7 @@ factions.register_command("newrank", {
if not success then
if args.strings[failindex] then
send_error(player, "Permission " .. args.strings[failindex] .. " is invalid.")
else
else
send_error(player, "No permission was given.")
end
return false
@ -799,16 +816,169 @@ factions.register_command("newrank", {
end
},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.",
format = {"string", "string"},
faction_permissions = {"ranks"},
faction_permissions = {"delete_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] 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
end
faction:delete_rank(rank, newrank)
@ -816,10 +986,10 @@ factions.register_command("delrank", {
end
},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.",
format = {"string"},
faction_permissions = {"ranks"},
faction_permissions = {"set_def_ranks"},
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
local rank = args.strings[1]
@ -827,15 +997,25 @@ factions.register_command("change_def_rank", {
send_error(player, "This rank does not exist.")
return false
end
faction:change_def_rank(rank)
faction.rankless = false
faction:set_def_rank(rank)
return true
end
},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",
faction_permissions = {"spawn"},
faction_permissions = {"set_spawn"},
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
faction:set_spawn(pos)
@ -843,6 +1023,35 @@ factions.register_command("setspawn", {
end
},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", {
description = "See whose parcel you stand on.",
infaction = false,
@ -865,7 +1074,7 @@ factions.register_command("help", {
end
},false)
factions.register_command("spawn", {
factions.register_command("get_spawn", {
description = "Shows your faction's spawn",
global_privileges = def_global_privileges,
on_success = function(player, faction, pos, parcelpos, args)
@ -974,7 +1183,7 @@ factions.register_command("which", {
end
},false)
factions.register_command("setleader", {
factions.register_command("set_leader", {
description = "Set a player as a faction's leader",
infaction = false,
global_privileges = {"faction_admin"},
@ -1026,7 +1235,7 @@ factions.register_command("remove_admin", {
end
},false)
factions.register_command("resetpower", {
factions.register_command("reset_power", {
description = "Reset a faction's power",
infaction = false,
global_privileges = {"faction_admin"},
@ -1050,7 +1259,7 @@ factions.register_command("obliterate", {
end
},false)
factions.register_command("getspawn", {
factions.register_command("get_factions_spawn", {
description = "Get a faction's spawn",
infaction = false,
global_privileges = {"faction_admin"},

View File

@ -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_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.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.powermax_per_player = tonumber(minetest.settings:get("powermax_per_player")) or 12
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.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
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.faction_user_priv = minetest.settings:get("faction_user_priv") or false
-- END
@ -39,7 +40,7 @@ factions_config.rank_name_max_length = 25
factions_config.maximum_faction_inactivity = 604800
factions_config.maximum_parcelless_faction_time = 10800
factions_config.power = 0
factions_config.maxpower = 0
factions_config.maxpower = 12
factions_config.power_per_player = 1
factions_config.powermax_per_player = 12
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.attack_parcel = false
factions_config.faction_diplomacy = true
factions_config.spawn_teleport = false
factions_config.protection_style = "2d"
factions_config.faction_user_priv = false
--]]

View File

@ -1 +1,2 @@
default
default?
doors?

View File

@ -35,26 +35,95 @@ util = {
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:
--
-- disband: disband the faction
-- claim: (un)claim parcels
-- playerslist: invite/kick players and open/close the faction
-- build: dig and place nodes
-- description: set the faction's description
-- ranks: create and delete ranks
-- spawn: set the faction's spawn
-- pain_build: dig and place nodes but take damage doing so
-- door: open/close or dig doors
-- 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
-- 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 then
table.insert(factions.permissions,"diplomacy")
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")
end
function factions.Faction:new(faction)
faction = {
name = "",
--! @brief power of a faction (needed for parcel claiming)
power = factions_config.power,
--! @brief maximum power of a faction
@ -68,12 +137,11 @@ function factions.Faction:new(faction)
--! @brief list of player names offline
offlineplayers = {},
--! @brief table of ranks/permissions
ranks = {["leader"] = factions.permissions,
["moderator"] = {"claim", "playerslist", "build", "spawn"},
["member"] = {"build"}
},
ranks = starting_ranks,
--! @brief name of the leader
leader = nil,
--! @brief spawn of the faction
spawn = {x=0, y=0, z=0},
--! @brief default joining rank for new members
default_rank = "member",
--! @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
attacked_parcels = {},
--! @brief whether faction is closed or open (boolean)
join_free = true,
join_free = false,
--! @brief gives certain privileges
is_admin = false,
--! @brief if a player on the faction has a nil rank
@ -113,7 +181,7 @@ end
--! @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)
faction.name = name
factions.factions[name] = faction
@ -122,18 +190,57 @@ function factions.new_faction(name)
function(f)
f:on_no_parcel()
end,faction)
factions.save()
if not do_not_save then
factions.save()
end
return faction
end
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
faction:new_enemy(i)
fac:new_enemy(name)
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)
self.power = self.power + power
if self.power > self.maxpower - self.usedpower then
@ -236,7 +343,6 @@ function factions.Faction.add_player(self, player, rank)
end
if notsame then
self:increase_maxpower(factions_config.powermax_per_player)
--self:increase_power(factions_config.power_per_player)
end
end
local pdata = minetest.get_player_by_name(player)
@ -378,8 +484,7 @@ function factions.Faction.disband(self, reason)
factions.parcels[k] = nil
end
self:on_disband(reason)
local playerslist = self.onlineplayers
for i,l in pairs(playerslist) do
for i,l in pairs(self.onlineplayers) do
removeHud(i,"factionName")
removeHud(i,"powerWatch")
end
@ -519,6 +624,13 @@ function factions.Faction.set_spawn(self, pos)
factions.save()
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
--! @param rank the name 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()
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
if r == rank or r == nil or not self.ranks[r] then
self.players[player] = rank
end
end
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()
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.")
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)
local now = os.time() - self.no_parcel
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], ", "))
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)
self:broadcast("The rank "..rank.." has been deleted and replaced by "..newrank)
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)
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)
minetest.chat_send_player(member, "You have been promoted to "..self.players[member])
end
@ -908,14 +1127,13 @@ function factions.load()
if faction:count_land() > 0 then
faction.no_parcel = -1
end
if faction.onlineplayers and faction.offlineplayers then
for i, _ in pairs(faction.onlineplayers) do
faction.onlineplayers = {}
faction.offlineplayers = {}
if faction.players then
for i, _ in pairs(faction.players) do
faction.offlineplayers[i] = _
end
else
faction.offlineplayers = {}
end
faction.onlineplayers = {}
end
misc_mod_data.data.factions_version = current_version
misc_mod_data.save()
@ -968,7 +1186,10 @@ function factions.convert(filename)
end
local raw_data = file:read("*a")
file:close()
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
local newfac = factions.new_faction(facname,true)
for oi, ol in pairs(faction) do
@ -980,7 +1201,7 @@ function factions.convert(filename)
newfac.players = faction.players
end
if faction.land then
newfac.land = faction.land
newfac.land = faction.land
end
if faction.ranks then
newfac.ranks = faction.ranks
@ -990,6 +1211,35 @@ function factions.convert(filename)
else
newfac.rankless = false
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)
newfac:check_power()
end
@ -1020,7 +1270,6 @@ function(player)
end
)
function factions.faction_tick()
local now = os.time()
for facname, faction in pairs(factions.factions) do
@ -1056,12 +1305,12 @@ function(player)
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.")
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
end
if faction:has_permission(name, "ranks") 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
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
faction.offlineplayers[name] = 1
faction.onlineplayers[name] = nil
factions.save()
end
end
)
@ -1127,9 +1377,17 @@ minetest.is_protected = function(pos, player)
return default_is_protected(pos, player)
elseif player_faction 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
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
return not parcel_faction:parcel_is_attacked_by(parcelpos, player_faction)
end

32
hud.lua
View File

@ -56,14 +56,6 @@ function createHudPower(player,faction)
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)
local name = ""
local p = {}
@ -81,6 +73,30 @@ function removeHud(player,hudname)
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()
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do

170
nodes.lua
View File

@ -1,93 +1,103 @@
function factions.get_chest_formspec(pos)
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)
function factions.can_use_node(pos, player,permission)
if not player then
return false
end
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
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
minetest.register_node("factions:chest", {
tiles = {"factions_chest_top.png", "factions_chest_top.png",
"factions_chest_side.png", "factions_chest_side.png",
"factions_chest_side.png", "factions_chest_front.png"},
groups = {choppy = 2},
description = "Faction chest",
paramtype2 = "facedir",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Faction Chest")
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 "")
-- Make default chest the faction chest.
if minetest.registered_nodes["default:chest"] then
minetest.register_lbm({
label = "Replace faction chest with default one.",
name = "factions:replace_factions_chest",
nodenames = {"factions:chest"},
action = function(pos, node)
minetest.swap_node(pos, {name="default:chest"})
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,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and
factions.can_use_chest(pos, player:get_player_name())
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if factions.can_use_chest(pos, player:get_player_name()) then
return count
else
return 0
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()
else
return 0
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()
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
return itemstack
end
})
minetest.register_craft({
output = "factions:chest",
type = "shapeless",
recipe = {"default:chest_locked", "default:steel_ingot"}
})
end
})
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 inv = meta:get_inventory()
return inv:is_empty("main") and
factions.can_use_node(pos, player:get_player_name(),"container")
end
clonenode.allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if not factions.can_use_node(pos, player:get_player_name(),"container") then
return 0
end
return count
end
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
end
return stack:get_count()
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
end
return stack:get_count()
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
end
def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
end
minetest.register_node(":default:chest",clonenode)
end
-- Edit default doors and trapdoors to make them require the door permission.
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.
local x = math.floor(factions_config.parcel_size / 2.1)

View File

@ -25,7 +25,7 @@ maximum_parcelless_faction_time (Maximum parcelless faction time) int 10800
# Power of a starting faction (needed for parcel claiming).
power (Starting power) float 0
# Maximum power of a starting faction.
maxpower (Starting Maximum power) float 0
maxpower (Starting Maximum power) float 12
# How much power the players make.
power_per_player (power-per-player) float 1
# 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
# Enable or disabled the max depth and height limit for a parcel
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
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