forked from mtcontrib/factions
Upload from hard disk.
This upload contains many bug fixes.
This commit is contained in:
parent
aaaa3886a1
commit
0cfba002dc
227
chatcommands.lua
227
chatcommands.lua
@ -5,8 +5,8 @@
|
||||
--
|
||||
--! @file chatcommnd.lua
|
||||
--! @brief factions chat interface
|
||||
--! @copyright Sapier, agrecascino, shamoanjac
|
||||
--! @author Sapier, agrecascino, shamoanjac
|
||||
--! @copyright Sapier, agrecascino, shamoanjac, Coder12a
|
||||
--! @author Sapier, agrecascino, shamoanjac, Coder12a
|
||||
--! @date 2016-08-12
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
@ -20,7 +20,7 @@ factions_chat = {}
|
||||
|
||||
factions.commands = {}
|
||||
|
||||
factions.register_command = function(cmd_name, cmd)
|
||||
factions.register_command = function(cmd_name, cmd, ignore_param_count)
|
||||
factions.commands[cmd_name] = { -- default command
|
||||
name = cmd_name,
|
||||
faction_permissions = {},
|
||||
@ -47,10 +47,24 @@ factions.register_command = function(cmd_name, cmd)
|
||||
strings = {},
|
||||
other = {}
|
||||
}
|
||||
if #argv < #(self.format) then
|
||||
send_error(player, "Not enough parameters.")
|
||||
return false
|
||||
end
|
||||
if not ignore_param_count then
|
||||
if #argv < #(self.format) then
|
||||
send_error(player, "Not enough parameters.")
|
||||
return false
|
||||
end
|
||||
else
|
||||
if self.format[1] then
|
||||
local fm = self.format[1]
|
||||
for i in ipairs(argv) do
|
||||
if #argv > #(self.format) then
|
||||
table.insert(self.format, fm)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for i in ipairs(self.format) do
|
||||
local argtype = self.format[i]
|
||||
local arg = argv[i]
|
||||
@ -78,8 +92,10 @@ factions.register_command = function(cmd_name, cmd)
|
||||
return false
|
||||
end
|
||||
end
|
||||
for i=#self.format, #argv, 1 do
|
||||
table.insert(args.other, argv[i])
|
||||
for i=2, #argv do
|
||||
if argv[i] then
|
||||
table.insert(args.other, argv[i])
|
||||
end
|
||||
end
|
||||
|
||||
-- checks permissions
|
||||
@ -123,6 +139,7 @@ init_commands = function()
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_privilege("faction_admin",
|
||||
{
|
||||
description = "this user is allowed to create or delete factions",
|
||||
@ -134,7 +151,7 @@ init_commands = function()
|
||||
{
|
||||
params = "<cmd> <parameter 1> .. <parameter n>",
|
||||
description = "faction administration functions",
|
||||
privs = { interact=true },
|
||||
privs = { interact=true,faction_user=true },
|
||||
func = factions_chat.cmdhandler,
|
||||
}
|
||||
)
|
||||
@ -144,7 +161,7 @@ init_commands = function()
|
||||
{
|
||||
params = "<command> parameters",
|
||||
description = "Factions commands. Type /f help for available commands.",
|
||||
privs = { interact=true},
|
||||
privs = { interact=true,faction_user=true},
|
||||
func = factions_chat.cmdhandler,
|
||||
}
|
||||
)
|
||||
@ -158,6 +175,7 @@ end
|
||||
factions.register_command ("claim", {
|
||||
faction_permissions = {"claim"},
|
||||
description = "Claim the plot of land you're on.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local can_claim = faction:can_claim_parcel(parcelpos)
|
||||
if can_claim then
|
||||
@ -178,13 +196,18 @@ factions.register_command ("claim", {
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("unclaim", {
|
||||
faction_permissions = {"claim"},
|
||||
description = "Unclaim the plot of land you're on.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||
if not parcel_faction then
|
||||
send_error(player, "This parcel does not exist.")
|
||||
return false
|
||||
end
|
||||
if parcel_faction.name ~= faction.name then
|
||||
send_error(player, "This parcel does not belong to you.")
|
||||
return false
|
||||
@ -193,12 +216,13 @@ factions.register_command("unclaim", {
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
--list all known factions
|
||||
factions.register_command("list", {
|
||||
description = "List all registered factions.",
|
||||
infaction = false,
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local list = factions.get_faction_list()
|
||||
local tosend = "Existing factions:"
|
||||
@ -213,7 +237,7 @@ factions.register_command("list", {
|
||||
minetest.chat_send_player(player, tosend, false)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
--show factions mod version
|
||||
factions.register_command("version", {
|
||||
@ -221,32 +245,35 @@ factions.register_command("version", {
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player, "factions: version " .. factions_version , false)
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
--show description of faction
|
||||
factions.register_command("info", {
|
||||
format = {"faction"},
|
||||
description = "Shows a faction's description.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player,
|
||||
"factions: " .. args.factions[1].name .. ": " ..
|
||||
args.factions[1].description, false)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("leave", {
|
||||
description = "Leave your faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:remove_player(player)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("kick", {
|
||||
faction_permissions = {"playerslist"},
|
||||
format = {"player"},
|
||||
description = "Kick a player from your faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local victim = args.players[1]
|
||||
local victim_faction = factions.get_player_faction(victim:get_player_name())
|
||||
@ -261,13 +288,14 @@ factions.register_command("kick", {
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
--create new faction
|
||||
factions.register_command("create", {
|
||||
format = {"string"},
|
||||
infaction = false,
|
||||
description = "Create a new faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if faction then
|
||||
send_error(player, "You are already in a faction.")
|
||||
@ -283,12 +311,13 @@ factions.register_command("create", {
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("join", {
|
||||
format = {"faction"},
|
||||
description = "Join a faction.",
|
||||
infaction = false,
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local new_faction = args.factions[1]
|
||||
if new_faction:can_join(player) then
|
||||
@ -302,63 +331,69 @@ factions.register_command("join", {
|
||||
end
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("disband", {
|
||||
faction_permissions = {"disband"},
|
||||
description = "Disband your faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:disband()
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("close", {
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Make your faction invite-only.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:toggle_join_free(false)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("open", {
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Allow any player to join your faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:toggle_join_free(true)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("description", {
|
||||
faction_permissions = {"description"},
|
||||
description = "Set your faction's description",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:set_description(table.concat(args.other," "))
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("invite", {
|
||||
format = {"player"},
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Invite a player to your faction.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:invite_player(args.players[1]:get_player_name())
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("uninvite", {
|
||||
format = {"player"},
|
||||
faction_permissions = {"playerslist"},
|
||||
description = "Revoke a player's invite.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:revoke_invite(args.players[1]:get_player_name())
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("delete", {
|
||||
global_privileges = {"faction_admin"},
|
||||
@ -369,20 +404,22 @@ factions.register_command("delete", {
|
||||
args.factions[1]:disband()
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("ranks", {
|
||||
description = "List ranks within your faction",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
for rank, permissions in pairs(faction.ranks) do
|
||||
minetest.chat_send_player(player, rank..": "..table.concat(permissions, " "))
|
||||
end
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("who", {
|
||||
description = "List players in your faction, and their ranks.",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
if not faction.players then
|
||||
minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")")
|
||||
@ -394,31 +431,57 @@ factions.register_command("who", {
|
||||
end
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("newrank", {
|
||||
description = "Add a new rank.",
|
||||
format = {"string"},
|
||||
faction_permissions = {"ranks"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
if #rank > factions.rank then
|
||||
send_error(player, "Go away Todd")
|
||||
return false
|
||||
end
|
||||
if faction.ranks[rank] then
|
||||
send_error(player, "Rank already exists")
|
||||
return false
|
||||
end
|
||||
faction:add_rank(rank, args.other)
|
||||
return true
|
||||
if args.strings[1] then
|
||||
local rank = args.strings[1]
|
||||
if faction.ranks[rank] then
|
||||
send_error(player, "Rank already exists")
|
||||
return false
|
||||
end
|
||||
local success = false
|
||||
local failindex = -1
|
||||
for _, f in pairs(args.strings) do
|
||||
if f then
|
||||
for q, r in pairs(factions.permissions) do
|
||||
if f == r then
|
||||
success = true
|
||||
break
|
||||
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_rank(rank, args.other)
|
||||
return true
|
||||
end
|
||||
send_error(player, "No rank was given.")
|
||||
return false
|
||||
end
|
||||
})
|
||||
},true)
|
||||
|
||||
factions.register_command("delrank", {
|
||||
description = "Replace and delete a rank.",
|
||||
format = {"string", "string"},
|
||||
faction_permissions = {"ranks"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
local newrank = args.strings[2]
|
||||
@ -429,39 +492,43 @@ factions.register_command("delrank", {
|
||||
faction:delete_rank(rank, newrank)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("setspawn", {
|
||||
description = "Set the faction's spawn",
|
||||
faction_permissions = {"spawn"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
faction:set_spawn(pos)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("where", {
|
||||
description = "See whose parcel you stand on.",
|
||||
infaction = false,
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||
local place_name = (parcel_faction and parcel_faction.name) or "Wilderness"
|
||||
minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..place_name)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("help", {
|
||||
description = "Shows help for commands.",
|
||||
infaction = false,
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
factions_chat.show_help(player)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("spawn", {
|
||||
description = "Shows your faction's spawn",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local spawn = faction.spawn
|
||||
if spawn then
|
||||
@ -473,12 +540,13 @@ factions.register_command("spawn", {
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("promote", {
|
||||
description = "Promotes a player to a rank",
|
||||
format = {"player", "string"},
|
||||
faction_permissions = {"promote"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local rank = args.strings[1]
|
||||
if faction.ranks[rank] then
|
||||
@ -489,16 +557,17 @@ factions.register_command("promote", {
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("power", {
|
||||
description = "Display your faction's power",
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
},false)
|
||||
--[[
|
||||
factions.register_command("setbanner", {
|
||||
description = "Sets the banner you're on as the faction's banner.",
|
||||
faction_permissions = {"banner"},
|
||||
@ -511,8 +580,9 @@ factions.register_command("setbanner", {
|
||||
end
|
||||
faction:set_banner(banner)
|
||||
end
|
||||
})
|
||||
|
||||
},false)
|
||||
--]]
|
||||
--[[
|
||||
factions.register_command("convert", {
|
||||
description = "Load factions in the old format",
|
||||
infaction = false,
|
||||
@ -526,8 +596,8 @@ factions.register_command("convert", {
|
||||
end
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
},false)
|
||||
--]]
|
||||
factions.register_command("free", {
|
||||
description = "Forcefully frees a parcel",
|
||||
infaction = false,
|
||||
@ -542,15 +612,17 @@ factions.register_command("free", {
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("chat", {
|
||||
description = "Send a message to your faction's members",
|
||||
format = {"string"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local msg = table.concat(args.other, " ")
|
||||
local msg = table.concat(args.strings, " ")
|
||||
faction:broadcast(msg, player)
|
||||
end
|
||||
})
|
||||
},true)
|
||||
|
||||
factions.register_command("forceupdate", {
|
||||
description = "Forces an update tick.",
|
||||
@ -558,12 +630,13 @@ factions.register_command("forceupdate", {
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
factions.faction_tick()
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("which", {
|
||||
description = "Gets a player's faction",
|
||||
infaction = false,
|
||||
format = {"string"},
|
||||
global_privileges = {"faction_user"},
|
||||
on_success = function(player, faction, pos, parcelpos, args)
|
||||
local playername = args.strings[1]
|
||||
local faction = factions.get_player_faction(playername)
|
||||
@ -575,7 +648,7 @@ factions.register_command("which", {
|
||||
return true
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("setleader", {
|
||||
description = "Set a player as a faction's leader",
|
||||
@ -593,7 +666,7 @@ factions.register_command("setleader", {
|
||||
targetfaction:set_leader(playername)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("setadmin", {
|
||||
description = "Make a faction an admin faction",
|
||||
@ -604,7 +677,7 @@ factions.register_command("setadmin", {
|
||||
args.factions[1].is_admin = false
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("resetpower", {
|
||||
description = "Reset a faction's power",
|
||||
@ -615,7 +688,7 @@ factions.register_command("resetpower", {
|
||||
args.factions[1].power = 0
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
|
||||
factions.register_command("obliterate", {
|
||||
@ -628,7 +701,7 @@ factions.register_command("obliterate", {
|
||||
end
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("getspawn", {
|
||||
description = "Get a faction's spawn",
|
||||
@ -645,7 +718,7 @@ factions.register_command("getspawn", {
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("whoin", {
|
||||
description = "Get all members of a faction.",
|
||||
@ -660,7 +733,7 @@ factions.register_command("whoin", {
|
||||
minetest.chat_send_player(player, table.concat(msg, ", "))
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("stats", {
|
||||
description = "Get stats of a faction.",
|
||||
@ -672,7 +745,7 @@ factions.register_command("stats", {
|
||||
minetest.chat_send_player(player, "Power: "..f.power.."/"..f.maxpower - f.usedpower.."/"..f.maxpower)
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
factions.register_command("seen", {
|
||||
description = "Check the last time a faction had a member logged in",
|
||||
@ -690,7 +763,7 @@ factions.register_command("seen", {
|
||||
hours % 24 .." hour(s), "..minutes % 60 .." minutes, "..time % 60 .." second(s) ago.")
|
||||
return true
|
||||
end
|
||||
})
|
||||
},false)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: cmdhandler(playername,parameter)
|
||||
@ -733,6 +806,15 @@ factions_chat.cmdhandler = function (playername,parameter)
|
||||
|
||||
end
|
||||
|
||||
function table_Contains(t,v)
|
||||
for k, a in pairs(t) do
|
||||
if a == v then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: show_help(playername,parameter)
|
||||
--
|
||||
@ -750,12 +832,17 @@ function factions_chat.show_help(playername)
|
||||
|
||||
MSG("factions mod")
|
||||
MSG("Usage:")
|
||||
local has, missing = minetest.check_player_privs(playername, {
|
||||
faction_admin = true})
|
||||
|
||||
for k, v in pairs(factions.commands) do
|
||||
local args = {}
|
||||
for i in ipairs(v.format) do
|
||||
table.insert(args, v.format[i])
|
||||
end
|
||||
MSG("\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description)
|
||||
if has or not table_Contains(v.global_privileges,"faction_admin") then
|
||||
for i in ipairs(v.format) do
|
||||
table.insert(args, v.format[i])
|
||||
end
|
||||
MSG("\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
28
config.lua
Normal file
28
config.lua
Normal file
@ -0,0 +1,28 @@
|
||||
-------------------------------------------------------------------------------
|
||||
-- factions Mod by Sapier
|
||||
--
|
||||
-- License WTFPL
|
||||
--
|
||||
--! @file config.lua
|
||||
--! @brief settings file
|
||||
--! @copyright Coder12a
|
||||
--! @author Coder12a
|
||||
--! @date 2018-03-13
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
config = {}
|
||||
config.protection_max_depth = tonumber(minetest.setting_get("protection_max_depth")) or -512
|
||||
config.power_per_parcel = tonumber(minetest.setting_get("power_per_parcel")) or 0.5
|
||||
config.power_per_death = tonumber(minetest.setting_get("power_per_death")) or 0.25
|
||||
config.power_per_tick = tonumber(minetest.setting_get("power_per_tick")) or 0.125
|
||||
config.tick_time = tonumber(minetest.setting_get("tick_time")) or 60
|
||||
config.power_per_attack = tonumber(minetest.setting_get("power_per_attack")) or 10
|
||||
config.faction_name_max_length = tonumber(minetest.setting_get("faction_name_max_length")) or 50
|
||||
config.rank_name_max_length = tonumber(minetest.setting_get("rank_name_max_length")) or 25
|
||||
config.maximum_faction_inactivity = tonumber(minetest.setting_get("maximum_faction_inactivity")) or 604800
|
||||
config.power = tonumber(minetest.setting_get("power")) or 2
|
||||
config.maxpower = tonumber(minetest.setting_get("maxpower")) or 2
|
||||
config.power_per_banner = minetest.settings:get_bool("power_per_banner") or 10.
|
||||
config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
|
1
depends.txt
Normal file
1
depends.txt
Normal file
@ -0,0 +1 @@
|
||||
default?
|
@ -1,5 +1 @@
|
||||
Version 1.1.5
|
||||
|
||||
Mod for handling in game factions and reputation
|
||||
|
||||
|
||||
Mod for handling in game factions and reputation.
|
264
factions.lua
264
factions.lua
@ -5,8 +5,8 @@
|
||||
--
|
||||
--! @file factions.lua
|
||||
--! @brief factions core file
|
||||
--! @copyright Sapier, agrecascino, shamoanjac
|
||||
--! @author Sapier, agrecascino, shamoanjac
|
||||
--! @copyright Sapier, agrecascino, shamoanjac, Coder12a
|
||||
--! @author Sapier, agrecascino, shamoanjac, Coder12a
|
||||
--! @date 2016-08-12
|
||||
--
|
||||
-- Contact sapier a t gmx net
|
||||
@ -27,15 +27,15 @@ factions.players = {}
|
||||
|
||||
factions.factions = {}
|
||||
--- settings
|
||||
factions.protection_max_depth = -512
|
||||
factions.power_per_parcel = .5
|
||||
factions.power_per_death = .25
|
||||
factions.power_per_tick = .125
|
||||
factions.tick_time = 60.
|
||||
factions.power_per_attack = 10.
|
||||
factions.faction_name_max_length = 50
|
||||
factions.rank_name_max_length = 25
|
||||
factions.maximum_faction_inactivity = 604800 -- 1 week
|
||||
factions.protection_max_depth = config.protection_max_depth
|
||||
factions.power_per_parcel = config.power_per_parcel
|
||||
factions.power_per_death = config.power_per_death
|
||||
factions.power_per_tick = config.power_per_tick
|
||||
factions.tick_time = config.tick_time
|
||||
factions.power_per_attack = config.power_per_attack
|
||||
factions.faction_name_max_length = config.faction_name_max_length
|
||||
factions.rank_name_max_length = config.rank_name_max_length
|
||||
factions.maximum_faction_inactivity = config.maximum_faction_inactivity
|
||||
|
||||
---------------------
|
||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||
@ -62,7 +62,6 @@ util = {
|
||||
|
||||
factions.Faction.__index = factions.Faction
|
||||
|
||||
|
||||
-- Faction permissions:
|
||||
--
|
||||
-- disband: disband the faction
|
||||
@ -75,12 +74,14 @@ factions.Faction.__index = factions.Faction
|
||||
-- banner: set the faction's banner
|
||||
-- promote: set a player's rank
|
||||
|
||||
factions.permissions = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner", "promote"}
|
||||
|
||||
function factions.Faction:new(faction)
|
||||
faction = {
|
||||
--! @brief power of a faction (needed for parcel claiming)
|
||||
power = 0.,
|
||||
power = config.power,
|
||||
--! @brief maximum power of a faction
|
||||
maxpower = 0.,
|
||||
maxpower = config.maxpower,
|
||||
--! @brief power currently in use
|
||||
usedpower = 0.,
|
||||
--! @brief list of player names
|
||||
@ -137,16 +138,43 @@ function factions.Faction.increase_power(self, power)
|
||||
if self.power > self.maxpower - self.usedpower then
|
||||
self.power = self.maxpower - self.usedpower
|
||||
end
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.decrease_power(self, power)
|
||||
self.power = self.power - power
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.increase_maxpower(self, power)
|
||||
self.maxpower = self.maxpower + power
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
@ -155,10 +183,28 @@ function factions.Faction.decrease_maxpower(self, power)
|
||||
if self.maxpower < 0. then -- should not happen
|
||||
self.maxpower = 0.
|
||||
end
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.increase_usedpower(self, power)
|
||||
self.usedpower = self.usedpower + power
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.decrease_usedpower(self, power)
|
||||
@ -166,6 +212,15 @@ function factions.Faction.decrease_usedpower(self, power)
|
||||
if self.usedpower < 0. then
|
||||
self.usedpower = 0.
|
||||
end
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
for player, _ in pairs(self.players) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
updateHudPower(realplayer,self)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.count_land(self)
|
||||
@ -181,13 +236,38 @@ function factions.Faction.add_player(self, player, rank)
|
||||
self.players[player] = rank or self.default_rank
|
||||
factions.players[player] = self.name
|
||||
self.invited_players[player] = nil
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
createHudFactionName(realplayer,self.name)
|
||||
createHudPower(realplayer,self)
|
||||
break
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
function factions.Faction.check_players_in_faction(self)
|
||||
local players = #self.players
|
||||
if players < 1 then
|
||||
self:disband("Zero players on faction.")
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.remove_player(self, player)
|
||||
self.players[player] = nil
|
||||
factions.players[player] = nil
|
||||
self:on_player_leave(player)
|
||||
self:check_players_in_faction(self)
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local realplayer = playerslist[i]
|
||||
if realplayer:get_player_name() == player then
|
||||
removeHud(realplayer,"1")
|
||||
removeHud(realplayer,"2")
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
@ -235,7 +315,8 @@ end
|
||||
|
||||
--! @brief disband faction, updates global players and parcels table
|
||||
function factions.Faction.disband(self, reason)
|
||||
for k, _ in pairs(self.players) do -- remove players affiliation
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for k, _ in pairs(factions.players) do -- remove players affiliation
|
||||
factions.players[k] = nil
|
||||
end
|
||||
for k, v in pairs(self.land) do -- remove parcel claims
|
||||
@ -243,6 +324,14 @@ function factions.Faction.disband(self, reason)
|
||||
end
|
||||
self:on_disband(reason)
|
||||
factions.factions[self.name] = nil
|
||||
for i in pairs(playerslist) do
|
||||
local realplayer = playerslist[i]
|
||||
local faction = factions.get_player_faction(realplayer:get_player_name())
|
||||
if not faction then
|
||||
removeHud(realplayer,"1")
|
||||
removeHud(realplayer,"2")
|
||||
end
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
|
||||
@ -395,21 +484,22 @@ function factions.Faction.is_online(self)
|
||||
end
|
||||
|
||||
function factions.Faction.attack_parcel(self, parcelpos)
|
||||
--[[ local attacked_faction = factions.get_parcel_faction(parcelpos)
|
||||
if attacked_faction then
|
||||
self.power = self.power - factions.power_per_attack
|
||||
if attacked_faction.attacked_parcels[parcelpos] then
|
||||
attacked_faction.attacked_parcels[parcelpos][self.name] = true
|
||||
else
|
||||
attacked_faction.attacked_parcels[parcelpos] = {[self.name] = true}
|
||||
end
|
||||
attacked_faction:broadcast("Parcel ("..parcelpos..") is being attacked by "..self.name.."!!")
|
||||
if self.power < 0. then -- punish memers
|
||||
minetest.chat_send_all("Faction "..self.name.." has attacked too much and has now negative power!")
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
]]
|
||||
if config.attack_parcel then
|
||||
local attacked_faction = factions.get_parcel_faction(parcelpos)
|
||||
if attacked_faction then
|
||||
self.power = self.power - factions.power_per_attack
|
||||
if attacked_faction.attacked_parcels[parcelpos] then
|
||||
attacked_faction.attacked_parcels[parcelpos][self.name] = true
|
||||
else
|
||||
attacked_faction.attacked_parcels[parcelpos] = {[self.name] = true}
|
||||
end
|
||||
attacked_faction:broadcast("Parcel ("..parcelpos..") is being attacked by "..self.name.."!!")
|
||||
if self.power < 0. then -- punish memers
|
||||
minetest.chat_send_all("Faction "..self.name.." has attacked too much and has now negative power!")
|
||||
end
|
||||
factions.save()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function factions.Faction.stop_attack(self, parcelpos)
|
||||
@ -723,11 +813,10 @@ factions.faction_tick = function()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local hudUpdate = 0.
|
||||
local factionUpdate = 0.
|
||||
|
||||
|
||||
minetest.register_globalstep(
|
||||
function(dtime)
|
||||
hudUpdate = hudUpdate + dtime
|
||||
@ -756,14 +845,120 @@ function(dtime)
|
||||
end
|
||||
end
|
||||
)
|
||||
--]]
|
||||
|
||||
hud_ids = {}
|
||||
|
||||
createHudFactionName = function(player,factionname)
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "1"
|
||||
if not hud_ids[id_name] then
|
||||
hud_ids[id_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "factionName",
|
||||
number = 0xFFFFFF,
|
||||
position = {x=1, y = 0},
|
||||
text = "Faction "..factionname,
|
||||
scale = {x=1, y=1},
|
||||
alignment = {x=-1, y=0},
|
||||
offset = {x = -20, y = 20}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
createHudPower = function(player,faction)
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "2"
|
||||
if not hud_ids[id_name] then
|
||||
hud_ids[id_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "powerWatch",
|
||||
number = 0xFFFFFF,
|
||||
position = {x=0.9, y = .98},
|
||||
text = "Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower,
|
||||
scale = {x=1, y=1},
|
||||
alignment = {x=-1, y=0},
|
||||
offset = {x = 0, y = 0}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
updateHudPower = function(player,faction)
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "2"
|
||||
if hud_ids[id_name] then
|
||||
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
|
||||
end
|
||||
end
|
||||
|
||||
removeHud = function(player,numberString)
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. numberString
|
||||
if hud_ids[id_name] then
|
||||
player:hud_remove(hud_ids[id_name])
|
||||
hud_ids[id_name] = nil
|
||||
end
|
||||
end
|
||||
|
||||
hudUpdate = function()
|
||||
minetest.after(.5,
|
||||
function()
|
||||
local playerslist = minetest.get_connected_players()
|
||||
for i in pairs(playerslist) do
|
||||
local player = playerslist[i]
|
||||
local name = player:get_player_name()
|
||||
local faction = factions.get_faction_at(player:getpos())
|
||||
local id_name = name .. "0"
|
||||
if hud_ids[id_name] then
|
||||
player:hud_change(hud_ids[id_name],"text",(faction and faction.name) or "Wilderness")
|
||||
end
|
||||
end
|
||||
hudUpdate()
|
||||
end)
|
||||
end
|
||||
|
||||
factionUpdate = function()
|
||||
minetest.after(factions.tick_time,
|
||||
function()
|
||||
factions.faction_tick()
|
||||
factionUpdate()
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(
|
||||
function(player)
|
||||
local faction = factions.get_player_faction(player:get_player_name())
|
||||
local name = player:get_player_name()
|
||||
hud_ids[name .. "0"] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
name = "factionLand",
|
||||
number = 0xFFFFFF,
|
||||
position = {x=0.1, y = .98},
|
||||
text = "Wilderness",
|
||||
scale = {x=1, y=1},
|
||||
alignment = {x=0, y=0},
|
||||
})
|
||||
local faction = factions.get_player_faction(name)
|
||||
if faction then
|
||||
faction.last_logon = os.time()
|
||||
createHudFactionName(player,faction.name)
|
||||
createHudPower(player,faction)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_leaveplayer(
|
||||
function(player)
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "0"
|
||||
if hud_ids[id_name] then
|
||||
player:hud_remove(hud_ids[id_name])
|
||||
hud_ids[id_name] = nil
|
||||
end
|
||||
removeHud(player,"1")
|
||||
removeHud(player,"2")
|
||||
end
|
||||
)
|
||||
|
||||
minetest.register_on_respawnplayer(
|
||||
function(player)
|
||||
local faction = factions.get_player_faction(player:get_player_name())
|
||||
@ -782,7 +977,6 @@ minetest.register_on_respawnplayer(
|
||||
|
||||
|
||||
|
||||
|
||||
local default_is_protected = minetest.is_protected
|
||||
minetest.is_protected = function(pos, player)
|
||||
if pos.y < factions.protection_max_depth then
|
||||
@ -822,3 +1016,5 @@ minetest.is_protected = function(pos, player)
|
||||
end
|
||||
end
|
||||
|
||||
hudUpdate()
|
||||
factionUpdate()
|
8
init.lua
8
init.lua
@ -5,21 +5,21 @@
|
||||
--
|
||||
--! @file init.lua
|
||||
--! @brief factions mod to be used by other mods
|
||||
--! @copyright Sapier
|
||||
--! @author Sapier
|
||||
--! @copyright Sapier, Coder12a
|
||||
--! @author Sapier, Coder12a
|
||||
--! @date 2013-05-08
|
||||
--!
|
||||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
factions_version = "0.8.0"
|
||||
factions_version = "0.8.1"
|
||||
|
||||
core.log("action", "MOD: factions (by sapier) loading ...")
|
||||
|
||||
--!path of mod
|
||||
factions_modpath = minetest.get_modpath("factions")
|
||||
|
||||
|
||||
dofile (factions_modpath .. "/config.lua")
|
||||
dofile (factions_modpath .. "/factions.lua")
|
||||
dofile (factions_modpath .. "/chatcommands.lua")
|
||||
dofile (factions_modpath .. "/nodes.lua")
|
||||
|
31
settingtypes.txt
Normal file
31
settingtypes.txt
Normal file
@ -0,0 +1,31 @@
|
||||
[ValueSettings]
|
||||
|
||||
# The max depth of protection from a parcel.
|
||||
protection_max_depth (Protection max depth) float -512
|
||||
# Cost of power to claim a parcel of land.
|
||||
power_per_parcel (Power-per-parcel) float 0.5
|
||||
# Power lost on death.
|
||||
power_per_death (Power-per-death) float 0.25
|
||||
# Power regeneration rate.
|
||||
power_per_tick (Power-per-tick) float 0.125
|
||||
# Faction timer. This timer regenerates power if the faction members are online.
|
||||
tick_time (Faction timer) float 60
|
||||
# Not in use.
|
||||
power_per_attack (Power-per-attack) float 10
|
||||
# Limit how long a faction name can be.
|
||||
faction_name_max_length (Faction name max) int 50
|
||||
# Limit how long a rank name can be.
|
||||
rank_name_max_length (Rank name max length) int 25
|
||||
# The maximum amount of inactivity before disbanning a faction.
|
||||
maximum_faction_inactivity (Maximum faction inactivity) int 604800
|
||||
# Power of a starting faction (needed for parcel claiming).
|
||||
power (Starting power) float 2
|
||||
# Maximum power of a faction.
|
||||
maxpower (Maximum power) float 2
|
||||
# How much power the banners make.
|
||||
power_per_banner (power-per-banner) float 10
|
||||
|
||||
[BoolSettings]
|
||||
|
||||
# Enable or disabled attack_parcel function.
|
||||
attack_parcel (Enable attack parcel) bool false
|
Loading…
Reference in New Issue
Block a user