forked from mtcontrib/factions
Added convert function and command
This commit is contained in:
parent
4d28033aa2
commit
bacec849db
@ -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
|
||||||
})
|
})
|
||||||
@ -463,7 +458,6 @@ factions.register_command("help", {
|
|||||||
|
|
||||||
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, ", ")..")")
|
||||||
@ -474,6 +468,20 @@ factions.register_command("spawn", {
|
|||||||
end
|
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)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
|
44
factions.lua
44
factions.lua
@ -275,14 +275,6 @@ function factions.Faction.on_delete_rank(self, rank, newrank)
|
|||||||
end
|
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 +376,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