This commit is contained in:
Coder12a 2018-10-16 21:58:15 -05:00
parent f73505fe87
commit bec629beb7
10 changed files with 228 additions and 131 deletions

View File

@ -704,6 +704,38 @@ factions.register_command("who", {
end
},false)
local parcel_size_center = factions.parcel_size / 2
factions.register_command("showparcel", {
description = "Shows parcel for six seconds.",
global_privileges = {"faction_user"},
on_success = function(player, faction, pos, parcelpos, args)
local parcel_faction = factions.get_parcel_faction(parcelpos)
if not parcel_faction then
send_error(player, "There is no claim here")
return false
end
local pscx = parcel_size_center
local pscy = parcel_size_center
local pscz = parcel_size_center
local fps = factions.parcel_size
if pos.x < 0 then
pscx = -pscx
end
if pos.y < 0 then
pscy = -pscy
end
if pos.z < 0 then
pscz = -pscz
end
local ppos = {x = (math.floor(pos.x / fps)*fps)+pscx,y = (math.floor(pos.y / fps)*fps)+pscy,z = (math.floor(pos.z / fps)*fps)+pscz}
minetest.add_entity(ppos, "factions:display")
return true
end
},false)
factions.register_command("newrank", {
description = "Add a new rank.",
format = {"string"},
@ -834,7 +866,7 @@ factions.register_command("power", {
description = "Display your faction's power",
global_privileges = {"faction_user"},
on_success = function(player, faction, pos, parcelpos, args)
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
minetest.chat_send_player(player, "Power: "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower)
return true
end
},false)

View File

@ -1,23 +1,29 @@
factions_config = {}
factions_config.protection_max_depth = tonumber(minetest.setting_get("protection_max_depth")) or -512
factions_config.power_per_parcel = tonumber(minetest.setting_get("power_per_parcel")) or 0.5
factions_config.power_per_death = tonumber(minetest.setting_get("power_per_death")) or 0.25
factions_config.power_per_tick = tonumber(minetest.setting_get("power_per_tick")) or 0.125
factions_config.tick_time = tonumber(minetest.setting_get("tick_time")) or 60
factions_config.power_per_attack = tonumber(minetest.setting_get("power_per_attack")) or 10
factions_config.faction_name_max_length = tonumber(minetest.setting_get("faction_name_max_length")) or 50
factions_config.rank_name_max_length = tonumber(minetest.setting_get("rank_name_max_length")) or 25
factions_config.maximum_faction_inactivity = tonumber(minetest.setting_get("maximum_faction_inactivity")) or 604800
factions_config.maximum_parcelless_faction_time = tonumber(minetest.setting_get("maximum_parcelless_faction_time")) or 10800
factions_config.power = tonumber(minetest.setting_get("power")) or 0
factions_config.maxpower = tonumber(minetest.setting_get("maxpower")) or 0
factions_config.power_per_player = tonumber(minetest.setting_get("power_per_player")) or 2.
local flip = minetest.settings:get("protection_max_depth") or 512
factions_config.protection_max_depth = -flip
factions_config.protection_max_height = minetest.settings:get("protection_max_height") or 10000
factions_config.power_per_parcel = minetest.settings:get("power_per_parcel") or 0.5
factions_config.power_per_death = minetest.settings:get("power_per_death") or 0.25
factions_config.power_per_tick = minetest.settings:get("power_per_tick") or 0.125
factions_config.tick_time = minetest.settings:get("tick_time") or 60
factions_config.power_per_attack = minetest.settings:get("power_per_attack") or 10
factions_config.faction_name_max_length = minetest.settings:get("faction_name_max_length") or 50
factions_config.rank_name_max_length = minetest.settings:get("rank_name_max_length") or 25
factions_config.maximum_faction_inactivity = minetest.settings:get("maximum_faction_inactivity") or 604800
factions_config.maximum_parcelless_faction_time = minetest.settings:get("maximum_parcelless_faction_time") or 10800
factions_config.power = minetest.settings:get("power") or 0
factions_config.maxpower = minetest.settings:get("maxpower") or 0
factions_config.power_per_player = minetest.settings:get("power_per_player") or 0.125
factions_config.powermax_per_player = minetest.settings:get("powermax_per_player") or 2
factions_config.parcel_size = minetest.settings:get("parcel_size") or 16
factions_config.protection_depth_height_limit = minetest.settings:get_bool("protection_depth_height_limit") or true
factions_config.enable_power_per_player = minetest.settings:get_bool("power_per_playerb") or true
factions_config.attack_parcel = minetest.settings:get_bool("attack_parcel") or false
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or true
factions_config.faction_diplomacy = minetest.settings:get_bool("faction_diplomacy") or false
factions_config.protection_style = minetest.settings:get("protection_style") or "classic"
--[[
factions_config.protection_max_depth = -512
factions_config.protection_max_height = 10000
factions_config.power_per_parcel = 0.5
factions_config.power_per_death = 0.25
factions_config.power_per_tick = 0.125
@ -29,8 +35,12 @@ factions_config.maximum_faction_inactivity = 604800
factions_config.maximum_parcelless_faction_time = 10800
factions_config.power = 0
factions_config.maxpower = 0
factions_config.power_per_player = 2
factions_config.power_per_player = 0.125
factions_config.powermax_per_player = 2
factions_config.parcel_size = 16
factions_config.protection_depth_height_limit = true
factions_config.enable_power_per_player = true
factions_config.attack_parcel = false
factions_config.faction_diplomacy = true
factions_config.faction_diplomacy = false
factions_config.protection_style = "classic"
--]]

View File

@ -0,0 +1 @@
default?

View File

@ -14,6 +14,7 @@ factions.players = {}
factions.factions = {}
--- settings
factions.protection_max_depth = factions_config.protection_max_depth
factions.protection_max_height = factions_config.protection_max_height
factions.power_per_parcel = factions_config.power_per_parcel
factions.power_per_death = factions_config.power_per_death
factions.power_per_tick = factions_config.power_per_tick
@ -26,10 +27,14 @@ factions.maximum_parcelless_faction_time = factions_config.maximum_parcelless_fa
factions.attack_parcel = factions_config.attack_parcel
factions.faction_diplomacy = factions_config.faction_diplomacy
factions.power_per_player = factions_config.power_per_player
factions.powermax_per_player = factions_config.powermax_per_player
factions.protection_depth_height_limit = factions_config.protection_depth_height_limit
factions.enable_power_per_player = factions_config.enable_power_per_player
factions.power = factions_config.power
factions.maxpower = factions_config.maxpower
factions.attack_parcel = factions_config.attack_parcel
factions.parcel_size = factions_config.parcel_size
factions.protection_style = factions_config.protection_style
-- clear mem.
factions_config = nil
@ -87,6 +92,10 @@ function factions.Faction:new(faction)
usedpower = 0.,
--! @brief list of player names
players = {},
--! @brief list of player names online
onlineplayers = {},
--! @brief list of player names offline
offlineplayers = {},
--! @brief table of ranks/permissions
ranks = {["leader"] = factions.permissions,
["moderator"] = {"claim", "playerslist", "build", "spawn"},
@ -143,42 +152,24 @@ function factions.Faction.increase_power(self, power)
if self.power > self.maxpower - self.usedpower then
self.power = self.maxpower - self.usedpower
end
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
factions.save()
end
function factions.Faction.decrease_power(self, power)
self.power = self.power - power
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
factions.save()
end
function factions.Faction.increase_maxpower(self, power)
self.maxpower = self.maxpower + power
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
factions.save()
end
@ -188,27 +179,15 @@ function factions.Faction.decrease_maxpower(self, power)
if self.maxpower < 0. then -- should not happen
self.maxpower = 0.
end
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
end
function factions.Faction.increase_usedpower(self, power)
self.usedpower = self.usedpower + power
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
end
@ -217,14 +196,8 @@ function factions.Faction.decrease_usedpower(self, power)
if self.usedpower < 0. then
self.usedpower = 0.
end
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
for player, _ in pairs(self.players) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
updateHudPower(realplayer,self)
end
end
for i in pairs(self.onlineplayers) do
updateHudPower(minetest.get_player_by_name(i),self)
end
end
@ -256,17 +229,21 @@ function factions.Faction.add_player(self, player, rank)
end
end
if notsame then
self:increase_maxpower(factions.power_per_player)
self:increase_power(factions.power_per_player)
self:increase_maxpower(factions.powermax_per_player)
self:decrease_usedpower(factions.power_per_player)
end
end
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
createHudFactionName(realplayer,self.name)
createHudPower(realplayer,self)
break
end
local pdata = minetest.get_player_by_name(player)
local ipc = pdata:is_player_connected(player)
if ipc then
createHudFactionName(pdata,self.name)
createHudPower(pdata,self)
self.offlineplayers[player] = nil
self.onlineplayers[player] = 1
else
self.offlineplayers[player] = 1
self.onlineplayers[player] = nil
end
factions.save()
end
@ -294,17 +271,17 @@ function factions.Faction.remove_player(self, player)
end
end
if notsame then
self:decrease_maxpower(factions.power_per_player)
self:decrease_maxpower(factions.powermax_per_player)
end
end
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
local realplayer = playerslist[i]
if realplayer:get_player_name() == player then
removeHud(realplayer,"factionName")
removeHud(realplayer,"powerWatch")
end
local pdata = minetest.get_player_by_name(player)
local ipc = pdata:is_player_connected(player)
if ipc then
removeHud(pdata,"factionName")
removeHud(pdata,"powerWatch")
end
self.offlineplayers[player] = nil
self.onlineplayers[player] = nil
factions.save()
end
@ -708,10 +685,12 @@ function factions.Faction.on_revoke_invite(self, player)
minetest.chat_send_player(player, "You are no longer invited to faction "..self.name)
end
--??????????????
function factions.get_parcel_pos(pos)
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
if factions.protection_style == "classic" then
return math.floor(pos.x / factions.parcel_size)..","..math.floor(pos.z / factions.parcel_size)
elseif factions.protection_style == "pb-style" then
return math.floor(pos.x / factions.parcel_size)..","..math.floor(pos.y / factions.parcel_size)..","..math.floor(pos.z / factions.parcel_size)
end
end
function factions.get_player_faction(playername)
@ -737,6 +716,10 @@ function factions.get_faction(facname)
end
function factions.get_faction_at(pos)
local y = pos.y
if factions.protection_depth_height_limit and (pos.y < factions.protection_max_depth or pos.y > factions.protection_max_height) then
return nil
end
local parcelpos = factions.get_parcel_pos(pos)
return factions.get_parcel_faction(parcelpos)
end
@ -910,27 +893,21 @@ end
)
factions.faction_tick = function()
function factions.faction_tick()
local now = os.time()
for facname, faction in pairs(factions.factions) do
if faction:is_online() then
if factions.enable_power_per_player then
local playerslist = minetest.get_connected_players()
for i in pairs(playerslist) do
local faction_name = factions.get_player_faction(playerslist[i])
if facname == faction_name then
increase_power(power_per_tick)
end
end
local t = faction.onlineplayers
local count = 0
for _ in pairs(t) do count = count + 1 end
faction:increase_power(factions.power_per_player*count)
else
faction:increase_power(factions.power_per_tick)
end
faction:increase_power(factions.power_per_tick)
end
if now - faction.last_logon > factions.maximum_faction_inactivity then
if now - faction.last_logon > factions.maximum_faction_inactivity or (faction.no_parcel ~= -1 and now - faction.no_parcel > factions.maximum_parcelless_faction_time) then
faction:disband()
else
if faction.no_parcel ~= -1 and now - faction.no_parcel > factions.maximum_parcelless_faction_time then
faction:disband()
end
end
end
end
@ -944,6 +921,9 @@ function(player)
faction.last_logon = os.time()
createHudFactionName(player,faction.name)
createHudPower(player,faction)
faction.offlineplayers[name] = nil
faction.onlineplayers[name] = 1
factions.save()
end
end
)
@ -951,8 +931,15 @@ end
minetest.register_on_leaveplayer(
function(player)
removeHud(player,"factionLand")
removeHud(player,"factionName")
removeHud(player,"powerWatch")
local name = player:get_player_name()
local faction = factions.get_player_faction(name)
if faction then
removeHud(player,"factionName")
removeHud(player,"powerWatch")
faction.offlineplayers[name] = 1
faction.onlineplayers[name] = nil
factions.save()
end
end
)
@ -976,7 +963,8 @@ minetest.register_on_respawnplayer(
local default_is_protected = minetest.is_protected
minetest.is_protected = function(pos, player)
if pos.y < factions.protection_max_depth then
local y = pos.y
if factions.protection_depth_height_limit and (pos.y < factions.protection_max_depth or pos.y > factions.protection_max_height) then
return false
end
if factions.disallow_edit_nofac and not player_faction then
@ -997,7 +985,7 @@ minetest.is_protected = function(pos, player)
end
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
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 and not parcel_faction.is_admin
end
-- no faction
if not parcel_faction then
@ -1015,5 +1003,13 @@ minetest.is_protected = function(pos, player)
end
end
hudUpdate()
function factionUpdate()
minetest.after(factions.tick_time,
function()
factions.faction_tick()
factionUpdate()
end)
end
hudUpdateClaimInfo()
factionUpdate()

26
hud.lua
View File

@ -1,6 +1,6 @@
hud_ids = {}
createHudfactionLand = function(player)
function createHudfactionLand(player)
local name = player:get_player_name()
hud_ids[name .. "factionLand"] = player:hud_add({
hud_elem_type = "text",
@ -13,7 +13,7 @@ createHudfactionLand = function(player)
})
end
createHudFactionName = function(player,factionname)
function createHudFactionName(player,factionname)
local name = player:get_player_name()
local id_name = name .. "factionName"
if not hud_ids[id_name] then
@ -30,7 +30,7 @@ createHudFactionName = function(player,factionname)
end
end
createHudPower = function(player,faction)
function createHudPower(player,faction)
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if not hud_ids[id_name] then
@ -39,7 +39,7 @@ createHudPower = function(player,faction)
name = "powerWatch",
number = 0xFFFFFF,
position = {x=0.9, y = .98},
text = "Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower,
text = "Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower,
scale = {x=1, y=1},
alignment = {x=-1, y=0},
offset = {x = 0, y = 0}
@ -47,15 +47,15 @@ createHudPower = function(player,faction)
end
end
updateHudPower = function(player,faction)
function updateHudPower(player,faction)
local name = player:get_player_name()
local id_name = name .. "powerWatch"
if hud_ids[id_name] then
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
player:hud_change(hud_ids[id_name],"text","Power "..faction.power.."/".. faction.usedpower .."/"..faction.maxpower)
end
end
removeHud = function(player,hudname)
function removeHud(player,hudname)
local name = player:get_player_name()
local id_name = name .. hudname
if hud_ids[id_name] then
@ -64,7 +64,7 @@ removeHud = function(player,hudname)
end
end
hudUpdate = function()
function hudUpdateClaimInfo()
minetest.after(3,
function()
local playerslist = minetest.get_connected_players()
@ -77,14 +77,6 @@ hudUpdate = function()
player:hud_change(hud_ids[id_name],"text",(faction and faction.name) or "Wilderness")
end
end
hudUpdate()
end)
end
factionUpdate = function()
minetest.after(factions.tick_time,
function()
factions.faction_tick()
factionUpdate()
hudUpdateClaimInfo()
end)
end

4
ip.lua
View File

@ -5,7 +5,7 @@ factions_ip.player_ips = {}
local factions_worldid = minetest.get_worldpath()
function factions_ip.save()
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.conf","w")
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.txt","w")
if file ~= nil then
file:write(minetest.serialize(factions_ip.player_ips))
@ -16,7 +16,7 @@ function factions_ip.save()
end
function factions_ip.load()
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.conf","r")
local file,error = io.open(factions_worldid .. "/" .. "factions_iplist.txt","r")
if file ~= nil then
local raw_data = file:read("*a")

View File

@ -69,3 +69,55 @@ minetest.register_craft({
recipe = {"default:chest_locked", "default:steel_ingot"}
})
-- Code below was copied from TenPlus1's protector mod(MIT) and changed up a bit.
local x = math.floor(factions.parcel_size / 2.1)
minetest.register_node("factions:display_node", {
tiles = {"factions_display.png"},
use_texture_alpha = true,
walkable = false,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
-- sides
{-(x+.55), -(x+.55), -(x+.55), -(x+.45), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), (x+.45), (x+.55), (x+.55), (x+.55)},
{(x+.45), -(x+.55), -(x+.55), (x+.55), (x+.55), (x+.55)},
{-(x+.55), -(x+.55), -(x+.55), (x+.55), (x+.55), -(x+.45)},
-- top
{-(x+.55), (x+.45), -(x+.55), (x+.55), (x+.55), (x+.55)},
-- bottom
{-(x+.55), -(x+.55), -(x+.55), (x+.55), -(x+.45), (x+.55)},
-- middle (surround parcel)
{-.55,-.55,-.55, .55,.55,.55},
},
},
selection_box = {
type = "regular",
},
paramtype = "light",
groups = {dig_immediate = 3, not_in_creative_inventory = 1},
drop = "",
})
minetest.register_entity("factions:display", {
physical = false,
collisionbox = {0, 0, 0, 0, 0, 0},
visual = "wielditem",
visual_size = {x = 1.0 / 1.5, y = 1.0 / 1.5},
textures = {"factions:display_node"},
timer = 0,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer > 6 then
self.object:remove()
end
end,
})
-- End

View File

@ -1,14 +1,16 @@
[ValueSettings]
# The max depth of protection from a parcel.
protection_max_depth (Protection max depth) float -512
protection_max_depth (Protection max depth) float 512
# The max height of protection from a parcel.
protection_max_height (Protection max height) float 10000
# Cost of power to claim a parcel of land.
power_per_parcel (Power-per-parcel) float 0.5
# Power lost on death.
power_per_death (Power-per-death) float 0.25
# Power regeneration rate.
power_per_tick (Power-per-tick) float 0.125
# Faction timer. This timer regenerates power if the faction members are online.
# Faction timer. This timer regenerates power.
tick_time (Faction timer) float 60
# Not in use.
power_per_attack (Power-per-attack) float 10
@ -21,11 +23,15 @@ maximum_faction_inactivity (Maximum faction inactivity) int 604800
# The maximum amount of time for a parcelless faction to disban.
maximum_parcelless_faction_time (Maximum parcelless faction time) int 10800
# Power of a starting faction (needed for parcel claiming).
power (Starting power) float 2
# Maximum power of a faction.
maxpower (Maximum power) float 2
power (Starting power) float 0
# Maximum power of a starting faction.
maxpower (Starting Maximum power) float 0
# How much power the players make.
power_per_player (power-per-player) float 10
power_per_player (power-per-player) float 0.125
# How much max power is created per new player.
powermax_per_player (powermax-per-player) float 2
# parcel size
parcel_size (parcel-size) float 16
[BoolSettings]
@ -34,4 +40,10 @@ power_per_playerb (Enable power-per-player) bool true
# Enable or disabled attack_parcel function.
attack_parcel (Enable attack parcel) bool false
# Enable or disabled faction diplomacy.
faction_diplomacy (Enable faction diplomacy) bool false
faction_diplomacy (Enable faction diplomacy) bool false
# Enable or disabled the max depth and height limit for a parcel
protection_depth_height_limit (Enable protection depth height limit) bool true
[StringSettings]
# Set the way that the parcel protection works (classic,pb-style).
protection_style (Protection style) string classic

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

2
textures/license.txt Normal file
View File

@ -0,0 +1,2 @@
following Textures created by Coder12a (CC BY-SA 3.0):
factions_display.png