Added convert function and command

This commit is contained in:
shamoanjac 2016-08-08 18:51:17 +02:00
parent 4d28033aa2
commit bacec849db
2 changed files with 51 additions and 15 deletions

View File

@ -443,12 +443,7 @@ factions.register_command("where", {
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
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos..", part of "..chunk or "Wilderness"..",")
return true
end
})
@ -463,7 +458,6 @@ factions.register_command("help", {
factions.register_command("spawn", {
description = "Shows your faction's spawn",
infaction = true,
on_success = function(player, faction, pos, chunkpos, args)
if faction.spawn then
minetest.chat_send_player(player, "Spawn is at ("..table.concat(faction.spawn, ", ")..")")
@ -474,6 +468,20 @@ factions.register_command("spawn", {
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
})
-------------------------------------------------------------------------------
-- name: cmdhandler(playername,parameter)
--

View File

@ -275,14 +275,6 @@ function factions.Faction.on_delete_rank(self, rank, newrank)
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)
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
@ -385,6 +377,42 @@ function factions.load()
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(
function(player)
end