forked from mtcontrib/factions
Fixed a shitton of bugs + added command "where" to check chunk ownership
This commit is contained in:
parent
a52fe6a6bf
commit
55fe191cfd
148
chatcommands.lua
148
chatcommands.lua
@ -12,20 +12,14 @@
|
|||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
--! @class factions_chat
|
local send_error = function(player, message)
|
||||||
--! @brief chat interface class
|
minetest.chat_send_player(player, message)
|
||||||
|
end
|
||||||
|
|
||||||
factions_chat = {}
|
factions_chat = {}
|
||||||
|
|
||||||
factions.commands = {}
|
factions.commands = {}
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
-- name: init()
|
|
||||||
--
|
|
||||||
--! @brief initialize chat interface
|
|
||||||
--! @memberof factions_chat
|
|
||||||
--! @public
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
factions.register_command = function(cmd_name, cmd)
|
factions.register_command = function(cmd_name, cmd)
|
||||||
factions.commands[cmd_name] = { -- default command
|
factions.commands[cmd_name] = { -- default command
|
||||||
name = cmd_name,
|
name = cmd_name,
|
||||||
@ -35,16 +29,14 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
infaction = true,
|
infaction = true,
|
||||||
description = "This command has no description.",
|
description = "This command has no description.",
|
||||||
run = function(self, player, argv)
|
run = function(self, player, argv)
|
||||||
-- check global privileges
|
--[[ check global privileges
|
||||||
local global_privs = {}
|
if self.global_privileges then
|
||||||
for i in ipairs(global_privileges) do
|
local bool, missing_privs = minetest.check_player_privs(player, self.global_privileges)
|
||||||
global_privs[global_privileges] = true
|
if not bool then
|
||||||
end
|
send_error(player, "Missing global privileges: "..table.concat(missing_privs, ", "))
|
||||||
local can, missing = minetest.check_player_privs(player, global_privs)
|
return false
|
||||||
if not can then
|
end
|
||||||
--TODO: error (show missing privs?)
|
end]]
|
||||||
return false
|
|
||||||
end
|
|
||||||
-- checks argument formats
|
-- checks argument formats
|
||||||
local args = {
|
local args = {
|
||||||
factions = {},
|
factions = {},
|
||||||
@ -52,13 +44,17 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
strings = {},
|
strings = {},
|
||||||
other = {}
|
other = {}
|
||||||
}
|
}
|
||||||
for i in ipairs(format) do
|
if #argv < #(self.format) then
|
||||||
local argtype = format[i]
|
send_error(player, "Not enough parameters.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for i in ipairs(self.format) do
|
||||||
|
local argtype = self.format[i]
|
||||||
local arg = argv[i]
|
local arg = argv[i]
|
||||||
if argtype == "faction" then
|
if argtype == "faction" then
|
||||||
local fac = factions.factions[arg]
|
local fac = factions.factions[arg]
|
||||||
if not fac then
|
if not fac then
|
||||||
--TODO: error (faction required)
|
send_error(player, "Specified faction "..arg.." does not exist")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
table.insert(args.factions, fac)
|
table.insert(args.factions, fac)
|
||||||
@ -66,7 +62,8 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
elseif argtype == "player" then
|
elseif argtype == "player" then
|
||||||
local pl = minetest.get_player_by_name(arg)
|
local pl = minetest.get_player_by_name(arg)
|
||||||
if not pl then
|
if not pl then
|
||||||
--TODO: error (player is not connected) --TODO: track existing players for offsync invites and the like
|
send_error(player, "Player is not invited.")
|
||||||
|
--TODO: track existing players for offsync invites and the like
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
table.insert(args.players, pl)
|
table.insert(args.players, pl)
|
||||||
@ -74,26 +71,29 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
elseif argtype == "string" then
|
elseif argtype == "string" then
|
||||||
table.insert(args.strings, arg)
|
table.insert(args.strings, arg)
|
||||||
else
|
else
|
||||||
--TODO: error (badly formatted command definition, log to admin)
|
minetest.log("error", "Bad format definition for function "..self.name)
|
||||||
|
send_error(player, "Internal server error")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=#format, #argv, 1 do
|
for i=#self.format, #argv, 1 do
|
||||||
table.insert(args.other, argv[i])
|
table.insert(args.other, argv[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- checks if player in faction
|
-- checks permissions
|
||||||
local player_faction = factions.players[faction]
|
local player_faction = factions.players[player]
|
||||||
if not player_faction and self.infaction then
|
if self.infaction and not player_faction then
|
||||||
--TODO: error message
|
minetest.chat_send_player(player, "This command is only available within a faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
player_faction = factions.factions[player_faction]
|
||||||
-- checks permissions
|
if faction_permissions then
|
||||||
if #faction_permissions > 1 and not player_faction then
|
for i in ipairs(self.faction_permissions) do
|
||||||
minetest.chat_send_player(player, "You are not part of any faction")
|
if not player_faction:has_permission(player, self.faction_permissions[i]) then
|
||||||
return false
|
send_error(player, "You don't have permissions to do that.")
|
||||||
elseif #faction_permissions > 1 then
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get some more data
|
-- get some more data
|
||||||
@ -112,8 +112,8 @@ factions.register_command = function(cmd_name, cmd)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local init_commands
|
||||||
function factions_chat.init()
|
init_commands = function()
|
||||||
|
|
||||||
minetest.register_privilege("faction_user",
|
minetest.register_privilege("faction_user",
|
||||||
{
|
{
|
||||||
@ -144,7 +144,7 @@ function factions_chat.init()
|
|||||||
params = "<factionname> text",
|
params = "<factionname> text",
|
||||||
description = "send message to a specific faction",
|
description = "send message to a specific faction",
|
||||||
privs = { faction_user=true },
|
privs = { faction_user=true },
|
||||||
func = factions_chat.chathandler,
|
func = factions_chat.cmdhandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@ -158,17 +158,17 @@ factions.register_command ("claim", {
|
|||||||
faction_permissions = {"claim"},
|
faction_permissions = {"claim"},
|
||||||
description = "Claim the plot of land you're on.",
|
description = "Claim the plot of land you're on.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local chunk = factions.chunk[chunkpos]
|
local chunk = factions.chunks[chunkpos]
|
||||||
if not chunk then
|
if not chunk then
|
||||||
--TODO: success message
|
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
||||||
player_faction:claim_chunk(chunkpos)
|
faction:claim_chunk(chunkpos)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
if chunk == player_faction.name then
|
if chunk == faction.name then
|
||||||
--TODO: error (chunk already claimed by faction)
|
send_error(player, "This chunk already belongs to your faction.")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
--TODO: error (chunk claimed by another faction)
|
send_error(player, "This chunk belongs to another faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -193,9 +193,10 @@ factions.register_command("unclaim", {
|
|||||||
--list all known factions
|
--list all known factions
|
||||||
factions.register_command("list", {
|
factions.register_command("list", {
|
||||||
description = "List all registered factions.",
|
description = "List all registered factions.",
|
||||||
|
infaction = false,
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local list = factions.get_faction_list()
|
local list = factions.get_faction_list()
|
||||||
local tosend = "factions: current available factionsmod:"
|
local tosend = "Existing factions:"
|
||||||
|
|
||||||
for i,v in ipairs(list) do
|
for i,v in ipairs(list) do
|
||||||
if i ~= #list then
|
if i ~= #list then
|
||||||
@ -213,7 +214,7 @@ factions.register_command("list", {
|
|||||||
factions.register_command("version", {
|
factions.register_command("version", {
|
||||||
description = "Displays mod version.",
|
description = "Displays mod version.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
minetest.chat_send_player(player, "factions: version " .. factionsmod_version , false)
|
minetest.chat_send_player(player, "factions: version " .. factions_version , false)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -263,17 +264,16 @@ factions.register_command("create", {
|
|||||||
description = "Create a new faction.",
|
description = "Create a new faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
if faction then
|
if faction then
|
||||||
--TODO: error (cannot create faction while in faction)
|
send_error(player, "You are already in a faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local factioname = args.strings[1]
|
local factionname = args.strings[1]
|
||||||
if factions.can_create_faction(factionname) then
|
if factions.can_create_faction(factionname) then
|
||||||
new_faction = factions.create_faction(faction)
|
new_faction = factions.new_faction(factionname)
|
||||||
new_faction:add_player(player)
|
new_faction:add_player(player, new_faction.default_leader_rank)
|
||||||
new_faction:set_leader(player)
|
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
--TODO: error (cannot create faction)
|
send_error(player, "Faction cannot be created.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -292,7 +292,7 @@ factions.register_command("join", {
|
|||||||
end
|
end
|
||||||
new_faction:add_player(player)
|
new_faction:add_player(player)
|
||||||
else
|
else
|
||||||
--TODO: error (could not join faction)
|
send_error(player, "You cannot join this faction.")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@ -304,7 +304,6 @@ factions.register_command("disband", {
|
|||||||
description = "Disband your faction.",
|
description = "Disband your faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
faction:disband()
|
faction:disband()
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -364,6 +363,7 @@ factions.register_command("uninvite", {
|
|||||||
factions.register_command("delete", {
|
factions.register_command("delete", {
|
||||||
global_privileges = {"faction_admin"},
|
global_privileges = {"faction_admin"},
|
||||||
format = {"faction"},
|
format = {"faction"},
|
||||||
|
infaction = false,
|
||||||
description = "Delete a faction.",
|
description = "Delete a faction.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
args.factions[1]:disband()
|
args.factions[1]:disband()
|
||||||
@ -380,7 +380,7 @@ factions.register_command("ranks", {
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
for rank, permissions in pairs(faction.ranks) do
|
for rank, permissions in pairs(faction.ranks) do
|
||||||
minetest.chat_send_player(player:get_player_name(), rank..": "..table.concat(permissions, " "))
|
minetest.chat_send_player(player, rank..": "..table.concat(permissions, " "))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -389,12 +389,12 @@ factions.register_command("ranks", {
|
|||||||
factions.register_command("who", {
|
factions.register_command("who", {
|
||||||
description = "List players in your faction, and their ranks.",
|
description = "List players in your faction, and their ranks.",
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
if not faction then
|
if not faction.players then
|
||||||
--TODO: error message
|
minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")")
|
||||||
return false
|
return true
|
||||||
end
|
end
|
||||||
for player, rank in ipairs(faction.players) do
|
for player, rank in pairs(faction.players) do
|
||||||
minetest.chat_send_player(player:get_player_name(), player.." ("..rank..")")
|
minetest.chat_send_player(player, player.." ("..rank..")")
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -440,6 +440,21 @@ factions.register_command("setspawn", {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
factions.register_command("where", {
|
||||||
|
description = "See whose chunk you stand on",
|
||||||
|
infaction = false,
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local chunk = factions.chunks[chunkpos]
|
||||||
|
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos)
|
||||||
|
if not chunk then
|
||||||
|
minetest.chat_send_player(player, "This chunk is free.")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(player, "This chunk belongs to "..chunk)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: cmdhandler(playername,parameter)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
@ -450,7 +465,7 @@ factions.register_command("setspawn", {
|
|||||||
--! @param playername name
|
--! @param playername name
|
||||||
--! @param parameter data supplied to command
|
--! @param parameter data supplied to command
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factions_chat.cmdhandler(playername,parameter)
|
factions_chat.cmdhandler = function (playername,parameter)
|
||||||
|
|
||||||
local player = minetest.env:get_player_by_name(playername)
|
local player = minetest.env:get_player_by_name(playername)
|
||||||
local params = parameter:split(" ")
|
local params = parameter:split(" ")
|
||||||
@ -461,14 +476,15 @@ function factions_chat.cmdhandler(playername,parameter)
|
|||||||
if player_faction then
|
if player_faction then
|
||||||
minetest.chat_send_player(playername, player_faction.description)
|
minetest.chat_send_player(playername, player_faction.description)
|
||||||
else
|
else
|
||||||
--TODO: message, no faction
|
minetest.chat_send_player(playername, "You are part of no faction")
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local cmd = factions.commands[params[1]]
|
local cmd = factions.commands[params[1]]
|
||||||
if not cmd then
|
if not cmd then
|
||||||
--TODO: error (unknown command)
|
send_error(player, "Unknown command.")
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local argv = {}
|
local argv = {}
|
||||||
@ -476,7 +492,7 @@ function factions_chat.cmdhandler(playername,parameter)
|
|||||||
table.insert(argv, params[i])
|
table.insert(argv, params[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
cmd.run(player, argv)
|
cmd:run(playername, argv)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -506,3 +522,5 @@ function factions_chat.show_help(playername)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
init_commands()
|
||||||
|
|
||||||
|
86
factions.lua
86
factions.lua
@ -28,13 +28,13 @@ factions.print = function(text)
|
|||||||
print("factions: " .. dump(text))
|
print("factions: " .. dump(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
factions.dbg_lvl1 = function() end --factionsmod.print -- errors
|
factions.dbg_lvl1 = function() end --factions.print -- errors
|
||||||
factions.dbg_lvl2 = function() end --factionsmod.print -- non cyclic trace
|
factions.dbg_lvl2 = function() end --factions.print -- non cyclic trace
|
||||||
factions.dbg_lvl3 = function() end --factionsmod.print -- cyclic trace
|
factions.dbg_lvl3 = function() end --factions.print -- cyclic trace
|
||||||
|
|
||||||
factions.factions = {}
|
factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factions.lower_claimable_height = -512
|
factions.lower_laimable_height = -512
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||||
@ -71,62 +71,81 @@ factions.new_faction = function(name)
|
|||||||
-- methods
|
-- methods
|
||||||
increase_power = function(self, power)
|
increase_power = function(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
decrease_power = function(self, power)
|
decrease_power = function(self, power)
|
||||||
self.power = self.power - power
|
self.power = self.power - power
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
add_player = function(self, player, rank)
|
add_player = function(self, player, rank)
|
||||||
self.players[player] = rank or self.default_rank
|
self.players[player] = rank or self.default_rank
|
||||||
|
factions.players[player] = self.name
|
||||||
self:on_player_join(player)
|
self:on_player_join(player)
|
||||||
self.invited_players[player] = nil
|
self.invited_players[player] = nil
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
remove_player = function(self, player)
|
remove_player = function(self, player)
|
||||||
self.players[player] = nil
|
self.players[player] = nil
|
||||||
|
factions.players[player] = nil
|
||||||
self:on_player_leave(player)
|
self:on_player_leave(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
claim_chunk = function(self, chunkpos)
|
claim_chunk = function(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = self.name
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
self:on_claim_chunk(chunkpos)
|
self:on_claim_chunk(chunkpos)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
unclaim_chunk = function(self, chunkpos)
|
unclaim_chunk = function(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = nil
|
factions.chunks[chunkpos] = nil
|
||||||
self.land[chunkpos] = nil
|
self.land[chunkpos] = nil
|
||||||
self:on_unclaim_chunks(chunkpos)
|
self:on_unclaim_chunks(chunkpos)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
disband = function(self)
|
disband = function(self)
|
||||||
factions.factions[self.name] = nil
|
|
||||||
for i in ipairs(self.players) do -- remove players affiliation
|
for i in ipairs(self.players) do -- remove players affiliation
|
||||||
factions.players[self.players[i]] = nil
|
factions.players[self.players[i]] = nil
|
||||||
end
|
end
|
||||||
for k, v in self.land do -- remove chunk claims
|
for k, v in pairs(self.land) do -- remove chunk claims
|
||||||
factions.chunks[v] = nil
|
factions.chunks[v] = nil
|
||||||
end
|
end
|
||||||
self:on_disband()
|
self:on_disband()
|
||||||
|
factions.factions[self.name] = nil
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
set_leader = function(self, player)
|
set_leader = function(self, player)
|
||||||
self.leader = player
|
self.leader = player
|
||||||
self.players[player] = self.default_leader_rank
|
self.players[player] = self.default_leader_rank
|
||||||
self:on_new_leader()
|
self:on_new_leader()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
has_permission = function(self, player, permission)
|
has_permission = function(self, player, permission)
|
||||||
local p = self.players[player]
|
local p = self.players[player]
|
||||||
if not p then
|
if not p then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return table.contains(self.groups[p], permission)
|
local perms = self.ranks[p]
|
||||||
|
for i in ipairs(perms) do
|
||||||
|
if perms[i] == permission then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end,
|
end,
|
||||||
set_description = function(self, new)
|
set_description = function(self, new)
|
||||||
self.description = new
|
self.description = new
|
||||||
self:on_change_description()
|
self:on_change_description()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
invite_player = function(self, player)
|
invite_player = function(self, player)
|
||||||
self.invited_players[player] = true
|
self.invited_players[player] = true
|
||||||
self:on_player_invited(player)
|
self:on_player_invited(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
revoke_invite = function(self, player)
|
revoke_invite = function(self, player)
|
||||||
self.invited_player[player] = nil
|
self.invited_players[player] = nil
|
||||||
self:on_revoke_invite(player)
|
self:on_revoke_invite(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
is_invited = function(self, player)
|
is_invited = function(self, player)
|
||||||
return table.contains(self.invited_players, player)
|
return table.contains(self.invited_players, player)
|
||||||
@ -134,9 +153,10 @@ factions.new_faction = function(name)
|
|||||||
toggle_join_free = function(self, bool)
|
toggle_join_free = function(self, bool)
|
||||||
self.join_free = bool
|
self.join_free = bool
|
||||||
self:on_toggle_join_free()
|
self:on_toggle_join_free()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
can_join = function(self, player)
|
can_join = function(self, player)
|
||||||
return self.join_free or invited_players[player]
|
return self.join_free or self.invited_players[player]
|
||||||
end,
|
end,
|
||||||
new_alliance = function(self, faction)
|
new_alliance = function(self, faction)
|
||||||
self.allies[faction] = true
|
self.allies[faction] = true
|
||||||
@ -144,10 +164,12 @@ factions.new_faction = function(name)
|
|||||||
if self.enemies[faction] then
|
if self.enemies[faction] then
|
||||||
self:end_enemy(faction)
|
self:end_enemy(faction)
|
||||||
end
|
end
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
end_alliance = function(self, faction)
|
end_alliance = function(self, faction)
|
||||||
self.allies[faction] = nil
|
self.allies[faction] = nil
|
||||||
self:on_end_alliance(faction)
|
self:on_end_alliance(faction)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
new_enemy = function(self, faction)
|
new_enemy = function(self, faction)
|
||||||
self.enemies[faction] = true
|
self.enemies[faction] = true
|
||||||
@ -155,18 +177,22 @@ factions.new_faction = function(name)
|
|||||||
if self.allies[faction] then
|
if self.allies[faction] then
|
||||||
self:end_alliance(faction)
|
self:end_alliance(faction)
|
||||||
end
|
end
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
end_enemy = function(self, faction)
|
end_enemy = function(self, faction)
|
||||||
self.enemies[faction] = nil
|
self.enemies[faction] = nil
|
||||||
self:on_end_enemy(faction)
|
self:on_end_enemy(faction)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
set_spawn = function(self, pos)
|
set_spawn = function(self, pos)
|
||||||
self.spawn = pos
|
self.spawn = pos
|
||||||
self:on_set_spawn()
|
self:on_set_spawn()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
add_rank = function(self, rank, perms)
|
add_rank = function(self, rank, perms)
|
||||||
self.ranks[rank] = perms
|
self.ranks[rank] = perms
|
||||||
self:on_new_rank(rank)
|
self:on_new_rank(rank)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
delete_rank = function(self, rank, newrank)
|
delete_rank = function(self, rank, newrank)
|
||||||
for player, r in pairs(self.players) do
|
for player, r in pairs(self.players) do
|
||||||
@ -176,10 +202,11 @@ factions.new_faction = function(name)
|
|||||||
end
|
end
|
||||||
self.ranks[rank] = nil
|
self.ranks[rank] = nil
|
||||||
self:on_delete_rank(rank, newrank)
|
self:on_delete_rank(rank, newrank)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----------------------
|
--------------------------
|
||||||
-- callbacks for events
|
-- callbacks for events --
|
||||||
on_create = function(self) --! @brief called when the faction is added to the global faction list
|
on_create = function(self) --! @brief called when the faction is added to the global faction list
|
||||||
--TODO: implement
|
--TODO: implement
|
||||||
end,
|
end,
|
||||||
@ -227,21 +254,22 @@ factions.new_faction = function(name)
|
|||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
factions.factions[name] = faction
|
factions.factions[name] = faction
|
||||||
|
factions.save()
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
|
|
||||||
--??????????????
|
--??????????????
|
||||||
function factions.fix_powercap(name)
|
function factions.fix_powercap(name)
|
||||||
factions.data.factionsmod[name].powercap = #factionsmod.dynamic_data.membertable[name] + 10
|
factions.data.factions[name].powercap = #factions.dynamic_data.membertable[name] + 10
|
||||||
end
|
end
|
||||||
--??????????????
|
--??????????????
|
||||||
|
|
||||||
function factions.get_chunk(pos)
|
function factions.get_chunk(pos)
|
||||||
return factions.chunks[factionsmod.get_chunkpos(pos)]
|
return factions.chunks[factions.get_chunkpos(pos)]
|
||||||
end
|
end
|
||||||
|
|
||||||
function factions.get_chunkpos(pos)
|
function factions.get_chunk_pos(pos)
|
||||||
return {math.floor(pos.x / 16.), math.floor(pos.z / 16.)}
|
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -300,13 +328,13 @@ function factions.save()
|
|||||||
--all data is saved here
|
--all data is saved here
|
||||||
--this implies data needs to be cleant up on load
|
--this implies data needs to be cleant up on load
|
||||||
|
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factionsmod.conf","w")
|
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write(minetest.serialize(factions.factions))
|
file:write(minetest.serialize(factions.factions))
|
||||||
file:close()
|
file:close()
|
||||||
else
|
else
|
||||||
minetest.log("error","MOD factions: unable to save factionsmod world specific data!: " .. error)
|
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -321,24 +349,25 @@ end
|
|||||||
--! @return true/false
|
--! @return true/false
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factions.load()
|
function factions.load()
|
||||||
local file,error = io.open(factions_worldid .. "/" .. "factionsmod.conf","r")
|
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
factions.factions = minetest.deserialize(raw_data)
|
factions.factions = minetest.deserialize(raw_data)
|
||||||
for facname, faction in pairs(factions.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
for i in ipairs(faction.players) do
|
minetest.log("action", facname..","..faction.name)
|
||||||
factions.players[faction.players[i]] = facname
|
for player, rank in pairs(faction.players) do
|
||||||
|
minetest.log("action", player..","..rank)
|
||||||
|
factions.players[player] = facname
|
||||||
end
|
end
|
||||||
for chunkpos, val in pairs(faction.land) do
|
for chunkpos, val in pairs(faction.land) do
|
||||||
factions.chunks[chunkpos] = val
|
factions.chunks[chunkpos] = facname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--autojoin players to faction players
|
|
||||||
minetest.register_on_dieplayer(
|
minetest.register_on_dieplayer(
|
||||||
function(player)
|
function(player)
|
||||||
end
|
end
|
||||||
@ -353,3 +382,16 @@ minetest.register_on_joinplayer(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
local default_is_protected = minetest.is_protected
|
||||||
|
minetest.is_protected = function(pos, player)
|
||||||
|
local chunkpos = factions.get_chunk_pos(pos)
|
||||||
|
local faction = factions.chunks[chunkpos]
|
||||||
|
if not faction then
|
||||||
|
return default_is_protected(pos, player)
|
||||||
|
else
|
||||||
|
faction = factions.factions[faction]
|
||||||
|
return not faction:has_permission(player, "build")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
1
init.lua
1
init.lua
@ -24,6 +24,5 @@ dofile (factions_modpath .. "/factions.lua")
|
|||||||
dofile (factions_modpath .. "/chatcommands.lua")
|
dofile (factions_modpath .. "/chatcommands.lua")
|
||||||
|
|
||||||
factions.load()
|
factions.load()
|
||||||
factions_chat.init()
|
|
||||||
|
|
||||||
core.log("action","MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
core.log("action","MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
||||||
|
Loading…
Reference in New Issue
Block a user