commit
4049c1aed7
|
@ -250,12 +250,12 @@ factions.register_command("kick", {
|
||||||
description = "Kick a player from your faction.",
|
description = "Kick a player from your faction.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local victim = args.players[1]
|
local victim = args.players[1]
|
||||||
if factions.players[victim.name] == faction.name
|
if factions.players[victim:get_player_name()] == faction.name
|
||||||
and victim.name ~= faction.leader then -- can't kick da king
|
and victim:get_player_name() ~= faction.leader then -- can't kick da king
|
||||||
faction:remove_player(player)
|
faction:remove_player(player)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
send_error(player, "Cannot kick player "..victim.name)
|
send_error(player, "Cannot kick player "..victim:get_player_name())
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -403,8 +403,12 @@ factions.register_command("newrank", {
|
||||||
faction_permissions = {"ranks"},
|
faction_permissions = {"ranks"},
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
local rank = args.strings[1]
|
local rank = args.strings[1]
|
||||||
|
if #rank > factions.rank then
|
||||||
|
send_error(player, "Go away Todd")
|
||||||
|
return false
|
||||||
|
end
|
||||||
if faction.ranks[rank] then
|
if faction.ranks[rank] then
|
||||||
--TODO: rank already exists
|
send_error(player, "Rank already exists")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
faction:add_rank(rank, args.other)
|
faction:add_rank(rank, args.other)
|
||||||
|
|
58
factions.lua
58
factions.lua
|
@ -33,12 +33,16 @@ factions.power_per_death = .25
|
||||||
factions.power_per_tick = .125
|
factions.power_per_tick = .125
|
||||||
factions.tick_time = 60.
|
factions.tick_time = 60.
|
||||||
factions.power_per_attack = 2.
|
factions.power_per_attack = 2.
|
||||||
|
factions.faction_name_max_length = 50
|
||||||
|
factions.rank_name_max_length = 25
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @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)
|
||||||
--! @param name String containing the faction's name
|
--! @param name String containing the faction's name
|
||||||
factions.can_create_faction = function(name)
|
factions.can_create_faction = function(name)
|
||||||
if factions.factions[name] then
|
if #name > factions.faction_name_max_length then
|
||||||
|
return false
|
||||||
|
elseif factions.factions[name] then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
|
@ -107,6 +111,8 @@ function factions.Faction:new(faction)
|
||||||
join_free = false,
|
join_free = false,
|
||||||
--! @brief banner texture string
|
--! @brief banner texture string
|
||||||
banner = "bg_white.png",
|
banner = "bg_white.png",
|
||||||
|
--! @brief gives certain privileges
|
||||||
|
is_admin = false
|
||||||
} or faction
|
} or faction
|
||||||
setmetatable(faction, self)
|
setmetatable(faction, self)
|
||||||
return faction
|
return faction
|
||||||
|
@ -493,6 +499,33 @@ function factions.get_parcel_pos(pos)
|
||||||
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
|
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.get_player_faction(playername)
|
||||||
|
local facname = factions.players[playername]
|
||||||
|
if facname then
|
||||||
|
local faction = factions.factions[facname]
|
||||||
|
return faction
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.get_parcel_faction(parcelpos)
|
||||||
|
local facname = factions.parcels[parcelpos]
|
||||||
|
if facname then
|
||||||
|
local faction = factions.factions[facname]
|
||||||
|
return faction
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.get_faction(facname)
|
||||||
|
return factions.factions[facname]
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.get_faction_at(pos)
|
||||||
|
local parcelpos = factions.get_parcel_pos(pos)
|
||||||
|
return factions.get_parcel_faction(parcelpos)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: add_faction(name)
|
-- name: add_faction(name)
|
||||||
|
@ -598,6 +631,9 @@ function factions.load()
|
||||||
if not faction.usedpower then
|
if not faction.usedpower then
|
||||||
faction.usedpower = faction:count_land() * factions.power_per_parcel
|
faction.usedpower = faction:count_land() * factions.power_per_parcel
|
||||||
end
|
end
|
||||||
|
if #faction.name > factions.faction_name_max_length then
|
||||||
|
faction:disband()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
@ -641,11 +677,10 @@ end
|
||||||
|
|
||||||
minetest.register_on_dieplayer(
|
minetest.register_on_dieplayer(
|
||||||
function(player)
|
function(player)
|
||||||
local faction = factions.players[player:get_player_name()]
|
local faction = factions.get_player_faction(player:get_player_name())
|
||||||
if not faction then
|
if not faction then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
faction = factions.factions[faction]
|
|
||||||
faction:decrease_power(factions.power_per_death)
|
faction:decrease_power(factions.power_per_death)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -672,15 +707,14 @@ minetest.register_globalstep(
|
||||||
local playerslist = minetest.get_connected_players()
|
local playerslist = minetest.get_connected_players()
|
||||||
for i in pairs(playerslist) do
|
for i in pairs(playerslist) do
|
||||||
local player = playerslist[i]
|
local player = playerslist[i]
|
||||||
local parcelpos = factions.get_parcel_pos(player:getpos())
|
local faction = factions.get_faction_at(player:getpos())
|
||||||
local faction = factions.parcels[parcelpos]
|
|
||||||
player:hud_remove("factionLand")
|
player:hud_remove("factionLand")
|
||||||
player:hud_add({
|
player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
name = "factionLand",
|
name = "factionLand",
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
position = {x=0.1, y = .98},
|
position = {x=0.1, y = .98},
|
||||||
text = faction or "Wilderness",
|
text = (faction and faction.name) or "Wilderness",
|
||||||
scale = {x=1, y=1},
|
scale = {x=1, y=1},
|
||||||
alignment = {x=0, y=0},
|
alignment = {x=0, y=0},
|
||||||
})
|
})
|
||||||
|
@ -699,12 +733,10 @@ minetest.register_on_joinplayer(
|
||||||
)
|
)
|
||||||
minetest.register_on_respawnplayer(
|
minetest.register_on_respawnplayer(
|
||||||
function(player)
|
function(player)
|
||||||
local playername = player:get_player_name()
|
local faction = factions.get_player_faction(player:get_player_name())
|
||||||
local faction = factions.players[playername]
|
|
||||||
if not faction then
|
if not faction then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
faction = factions.factions[faction]
|
|
||||||
if not faction.spawn then
|
if not faction.spawn then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
|
@ -727,8 +759,8 @@ minetest.is_protected = function(pos, player)
|
||||||
end
|
end
|
||||||
|
|
||||||
local parcelpos = factions.get_parcel_pos(pos)
|
local parcelpos = factions.get_parcel_pos(pos)
|
||||||
local parcel_faction = factions.parcels[parcelpos]
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
||||||
local player_faction = factions.players[player]
|
local player_faction = factions.get_player_faction(player)
|
||||||
-- check if wielding death banner
|
-- check if wielding death banner
|
||||||
local player_info = minetest.get_player_by_name(player)
|
local player_info = minetest.get_player_by_name(player)
|
||||||
if not player_info then
|
if not player_info then
|
||||||
|
@ -740,14 +772,12 @@ minetest.is_protected = function(pos, player)
|
||||||
end
|
end
|
||||||
local player_wield = player_info:get_wielded_item()
|
local player_wield = player_info:get_wielded_item()
|
||||||
if player_wield:get_name() == "banners:death_banner" and player_faction then --todo: check for allies, maybe for permissions
|
if player_wield:get_name() == "banners:death_banner" and player_faction then --todo: check for allies, maybe for permissions
|
||||||
player_faction = factions.factions[player_faction]
|
return not player_faction:has_permission(player, "claim") and player_faction.power > 0. and not parcel_faction.is_admin
|
||||||
return not player_faction:has_permission(player, "claim") and player_faction.power > 0.
|
|
||||||
end
|
end
|
||||||
-- no faction
|
-- no faction
|
||||||
if not parcel_faction then
|
if not parcel_faction then
|
||||||
return default_is_protected(pos, player)
|
return default_is_protected(pos, player)
|
||||||
else
|
else
|
||||||
parcel_faction = factions.factions[parcel_faction]
|
|
||||||
if parcel_faction.name == player_faction then
|
if parcel_faction.name == player_faction then
|
||||||
return not parcel_faction:has_permission(player, "build")
|
return not parcel_faction:has_permission(player, "build")
|
||||||
elseif parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked
|
elseif parcel_faction.attacked_parcels[parcelpos] then -- chunk is being attacked
|
||||||
|
|
Loading…
Reference in New Issue
Block a user