forked from mtcontrib/factions
Merge pull request #5 from shamoanjac/master
Added convert function and command
This commit is contained in:
commit
a2d491d4f7
@ -443,12 +443,7 @@ factions.register_command("where", {
|
|||||||
infaction = false,
|
infaction = false,
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local chunk = factions.chunks[chunkpos]
|
local chunk = factions.chunks[chunkpos]
|
||||||
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos)
|
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos..", part of "..chunk or "Wilderness"..",")
|
||||||
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
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@ -458,18 +453,55 @@ factions.register_command("help", {
|
|||||||
infaction = false,
|
infaction = false,
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
factions_chat.show_help(player)
|
factions_chat.show_help(player)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
factions.register_command("spawn", {
|
factions.register_command("spawn", {
|
||||||
description = "Shows your faction's spawn",
|
description = "Shows your faction's spawn",
|
||||||
infaction = true,
|
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
if faction.spawn then
|
if faction.spawn then
|
||||||
minetest.chat_send_player(player, "Spawn is at ("..table.concat(faction.spawn, ", ")..")")
|
minetest.chat_send_player(player, "Spawn is at ("..table.concat(faction.spawn, ", ")..")")
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(player, "Your faction has no spawn set.")
|
minetest.chat_send_player(player, "Your faction has no spawn set.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("power", {
|
||||||
|
description = "Display your faction's power",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
minetest.chat_send_player(player, "Power: "..faction.power)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("setbanner", {
|
||||||
|
description = "Sets the banner you're on as the faction's banner.",
|
||||||
|
faction_permissions = {"banner"},
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local meta = minetest.get_meta({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||||
|
local banner = meta:get_string("banner")
|
||||||
|
if not banner then
|
||||||
|
minetest.chat_send_player(player, "No banner found.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
faction:set_banner(banner)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("convert", {
|
||||||
|
description = "Load factions in the old format",
|
||||||
|
infaction = false,
|
||||||
|
global_privileges = {"faction_admin"},
|
||||||
|
format = {"string"},
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
if factions.convert(args.strings[1]) then
|
||||||
|
minetest.chat_send_player(player, "Factions successfully converted.")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(player, "Error.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
58
factions.lua
58
factions.lua
@ -28,7 +28,7 @@ factions.players = {}
|
|||||||
factions.factions = {}
|
factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factions.lower_laimable_height = -512
|
factions.lower_laimable_height = -512
|
||||||
factions.power_per_chunk = 0.
|
factions.power_per_chunk = .5
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @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)
|
||||||
@ -50,7 +50,7 @@ function factions.Faction:new(faction)
|
|||||||
faction = {
|
faction = {
|
||||||
power = 0.,
|
power = 0.,
|
||||||
players = {},
|
players = {},
|
||||||
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn"},
|
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn", "banner"},
|
||||||
["moderator"] = {"claim", "playerslist", "build", "spawn"},
|
["moderator"] = {"claim", "playerslist", "build", "spawn"},
|
||||||
["member"] = {"build"}
|
["member"] = {"build"}
|
||||||
},
|
},
|
||||||
@ -62,7 +62,9 @@ function factions.Faction:new(faction)
|
|||||||
land = {},
|
land = {},
|
||||||
allies = {},
|
allies = {},
|
||||||
enemies = {},
|
enemies = {},
|
||||||
|
attacked_chunks = {},
|
||||||
join_free = false,
|
join_free = false,
|
||||||
|
banner = "bg_white.png",
|
||||||
} or faction
|
} or faction
|
||||||
setmetatable(faction, self)
|
setmetatable(faction, self)
|
||||||
return faction
|
return faction
|
||||||
@ -226,6 +228,11 @@ function factions.Faction.delete_rank(self, rank, newrank)
|
|||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.set_banner(self, newbanner)
|
||||||
|
self.banner = newbanner
|
||||||
|
self:on_new_banner()
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
-- callbacks for events --
|
-- callbacks for events --
|
||||||
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
||||||
@ -273,16 +280,11 @@ end
|
|||||||
function factions.Faction.on_delete_rank(self, rank, newrank)
|
function factions.Faction.on_delete_rank(self, rank, newrank)
|
||||||
--TODO: implement
|
--TODO: implement
|
||||||
end
|
end
|
||||||
|
function factions.Faction.on_new_banner(self)
|
||||||
|
--TODO: implement
|
||||||
|
end
|
||||||
|
|
||||||
--??????????????
|
--??????????????
|
||||||
function factions.fix_powercap(name)
|
|
||||||
factions.data.factions[name].powercap = #factions.dynamic_data.membertable[name] + 10
|
|
||||||
end
|
|
||||||
--??????????????
|
|
||||||
|
|
||||||
function factions.get_chunk(pos)
|
|
||||||
return factions.chunks[factions.get_chunkpos(pos)]
|
|
||||||
end
|
|
||||||
|
|
||||||
function factions.get_chunk_pos(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.)
|
||||||
@ -384,6 +386,42 @@ function factions.load()
|
|||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.convert(filename)
|
||||||
|
local file, error = io.open(factions_worldid .. "/" .. filename, "r")
|
||||||
|
if not file then
|
||||||
|
minetest.chat_send_all("Cannot load file "..filename..". "..error)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local raw_data = file:read("*a")
|
||||||
|
local data = minetest.deserialize(raw_data)
|
||||||
|
local factionsmod = data.factionsmod
|
||||||
|
local objects = data.objects
|
||||||
|
for faction, attrs in pairs(factionsmod) do
|
||||||
|
local newfac = factions.new_faction(faction)
|
||||||
|
newfac:add_player(attrs.owner, "leader")
|
||||||
|
for player, _ in pairs(attrs.adminlist) do
|
||||||
|
if not newfac.players[player] then
|
||||||
|
newfac:add_player(player, "moderator")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for player, _ in pairs(attrs.invitations) do
|
||||||
|
newfac:invite_player(player)
|
||||||
|
end
|
||||||
|
for i in ipairs(attrs.chunk) do
|
||||||
|
local chunkpos = table.concat(attrs.chunk[i],",")
|
||||||
|
newfac:claim_chunk(chunkpos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for player, attrs in pairs(objects) do
|
||||||
|
local facname = attrs.factionsmod
|
||||||
|
local faction = factions.factions[facname]
|
||||||
|
if faction then
|
||||||
|
faction:add_player(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_on_dieplayer(
|
minetest.register_on_dieplayer(
|
||||||
function(player)
|
function(player)
|
||||||
|
Loading…
Reference in New Issue
Block a user