Fixed moar bugs including spawn

This commit is contained in:
shamoanjac 2016-08-08 16:31:11 +02:00
parent c678fd55e2
commit 169076e8fe
2 changed files with 45 additions and 6 deletions

View File

@ -408,7 +408,7 @@ factions.register_command("newrank", {
--TODO: rank already exists
return false
end
faction:new_rank(rank, args.other)
faction:add_rank(rank, args.other)
return true
end
})
@ -419,7 +419,7 @@ factions.register_command("delrank", {
faction_permissions = {"ranks"},
on_success = function(player, faction, pos, chunkpos, args)
local rank = args.strings[1]
local newrank = args.string[2]
local newrank = args.strings[2]
if not faction.ranks[rank] or not faction.ranks[rank] then
--TODO: error (one of either ranks do not exist)
return false
@ -461,6 +461,19 @@ factions.register_command("help", {
end
})
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, ", ")..")")
return true
else
minetest.chat_send_player(player, "Your faction has no spawn set.")
end
end
})
-------------------------------------------------------------------------------
-- name: cmdhandler(playername,parameter)
--

View File

@ -56,7 +56,8 @@ function factions.Faction:new(faction)
faction = {
power = 0.,
players = {},
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "edit", "ranks"},
ranks = {["leader"] = {"disband", "claim", "playerslist", "build", "description", "ranks", "spawn"},
["moderator"] = {"claim", "playerslist", "build", "spawn"},
["member"] = {"build"}
},
leader = nil,
@ -68,7 +69,6 @@ function factions.Faction:new(faction)
allies = {},
enemies = {},
join_free = false,
spawn = nil,
} or faction
setmetatable(faction, self)
return faction
@ -108,15 +108,24 @@ function factions.Faction.remove_player(self, player)
factions.save()
end
function factions.Faction.can_claim_chunk(self, chunkpos)
if factions.chunks[chunkpos] or self.power < factions.power_per_chunk then
return false
end
return true
end
function factions.Faction.claim_chunk(self, chunkpos)
factions.chunks[chunkpos] = self.name
self.land[chunkpos] = true
self.decrease_power(factions.power_per_chunk)
self:on_claim_chunk(chunkpos)
factions.save()
end
function factions.Faction.unclaim_chunk(self, chunkpos)
factions.chunks[chunkpos] = nil
self.land[chunkpos] = nil
self.increase_power(factions.power_per_chunk)
self:on_unclaim_chunk(chunkpos)
factions.save()
end
@ -203,13 +212,13 @@ function factions.Faction.end_enemy(self, faction)
factions.save()
end
function factions.Faction.set_spawn(self, pos)
self.spawn = pos
self.spawn = {x=pos.x, y=pos.y, z=pos.z}
self:on_set_spawn()
factions.save()
end
function factions.Faction.add_rank(self, rank, perms)
self.ranks[rank] = perms
self:on_new_rank(rank)
self:on_add_rank(rank)
factions.save()
end
function factions.Faction.delete_rank(self, rank, newrank)
@ -395,6 +404,23 @@ minetest.register_on_joinplayer(
function(player)
end
)
minetest.register_on_respawnplayer(
function(player)
local playername = player:get_player_name()
local faction = factions.players[playername]
if not faction then
return false
else
faction = factions.factions[faction]
if not faction.spawn then
return false
else
player:setpos(faction.spawn)
return true
end
end
end
)
local default_is_protected = minetest.is_protected