forked from mtcontrib/factions
Fixed moar bugs including spawn
This commit is contained in:
parent
c678fd55e2
commit
169076e8fe
|
@ -408,7 +408,7 @@ factions.register_command("newrank", {
|
||||||
--TODO: rank already exists
|
--TODO: rank already exists
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
faction:new_rank(rank, args.other)
|
faction:add_rank(rank, args.other)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -419,7 +419,7 @@ factions.register_command("delrank", {
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"ranks"},
|
||||||
on_success = function(player, faction, pos, chunkpos, args)
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
local rank = args.strings[1]
|
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
|
if not faction.ranks[rank] or not faction.ranks[rank] then
|
||||||
--TODO: error (one of either ranks do not exist)
|
--TODO: error (one of either ranks do not exist)
|
||||||
return false
|
return false
|
||||||
|
@ -461,6 +461,19 @@ factions.register_command("help", {
|
||||||
end
|
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)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
|
|
34
factions.lua
34
factions.lua
|
@ -56,7 +56,8 @@ function factions.Faction:new(faction)
|
||||||
faction = {
|
faction = {
|
||||||
power = 0.,
|
power = 0.,
|
||||||
players = {},
|
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"}
|
["member"] = {"build"}
|
||||||
},
|
},
|
||||||
leader = nil,
|
leader = nil,
|
||||||
|
@ -68,7 +69,6 @@ function factions.Faction:new(faction)
|
||||||
allies = {},
|
allies = {},
|
||||||
enemies = {},
|
enemies = {},
|
||||||
join_free = false,
|
join_free = false,
|
||||||
spawn = nil,
|
|
||||||
} or faction
|
} or faction
|
||||||
setmetatable(faction, self)
|
setmetatable(faction, self)
|
||||||
return faction
|
return faction
|
||||||
|
@ -108,15 +108,24 @@ function factions.Faction.remove_player(self, player)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
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)
|
function factions.Faction.claim_chunk(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = self.name
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
|
self.decrease_power(factions.power_per_chunk)
|
||||||
self:on_claim_chunk(chunkpos)
|
self:on_claim_chunk(chunkpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
function factions.Faction.unclaim_chunk(self, chunkpos)
|
function factions.Faction.unclaim_chunk(self, chunkpos)
|
||||||
factions.chunks[chunkpos] = nil
|
factions.chunks[chunkpos] = nil
|
||||||
self.land[chunkpos] = nil
|
self.land[chunkpos] = nil
|
||||||
|
self.increase_power(factions.power_per_chunk)
|
||||||
self:on_unclaim_chunk(chunkpos)
|
self:on_unclaim_chunk(chunkpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
@ -203,13 +212,13 @@ function factions.Faction.end_enemy(self, faction)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
function factions.Faction.set_spawn(self, pos)
|
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()
|
self:on_set_spawn()
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
function factions.Faction.add_rank(self, rank, perms)
|
function factions.Faction.add_rank(self, rank, perms)
|
||||||
self.ranks[rank] = perms
|
self.ranks[rank] = perms
|
||||||
self:on_new_rank(rank)
|
self:on_add_rank(rank)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
function factions.Faction.delete_rank(self, rank, newrank)
|
function factions.Faction.delete_rank(self, rank, newrank)
|
||||||
|
@ -395,6 +404,23 @@ minetest.register_on_joinplayer(
|
||||||
function(player)
|
function(player)
|
||||||
end
|
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
|
local default_is_protected = minetest.is_protected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user