commit
e1dbcbf473
|
@ -316,7 +316,6 @@ factions.register_command("close", {
|
||||||
description = "Make your faction invite-only.",
|
description = "Make your faction invite-only.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:toggle_join_free(false)
|
faction:toggle_join_free(false)
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -326,7 +325,6 @@ factions.register_command("open", {
|
||||||
description = "Allow any player to join your faction.",
|
description = "Allow any player to join your faction.",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:toggle_join_free(true)
|
faction:toggle_join_free(true)
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -336,7 +334,6 @@ factions.register_command("description", {
|
||||||
description = "Set your faction's description",
|
description = "Set your faction's description",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
faction:set_description(table.concat(args.other," "))
|
faction:set_description(table.concat(args.other," "))
|
||||||
--TODO: message
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -479,7 +476,7 @@ factions.register_command("promote", {
|
||||||
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 faction.ranks[rank] then
|
if faction.ranks[rank] then
|
||||||
faction:promote(args.players[1], rank)
|
faction:promote(args.players[1]:get_player_name(), rank)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
send_error(player, "The specified rank does not exist.")
|
send_error(player, "The specified rank does not exist.")
|
||||||
|
@ -491,7 +488,7 @@ factions.register_command("promote", {
|
||||||
factions.register_command("power", {
|
factions.register_command("power", {
|
||||||
description = "Display your faction's power",
|
description = "Display your faction's power",
|
||||||
on_success = function(player, faction, pos, parcelpos, args)
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
minetest.chat_send_player(player, "Power: "..faction.power)
|
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -548,6 +545,14 @@ factions.register_command("chat", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
factions.register_command("forceupdate", {
|
||||||
|
description = "Forces an update tick.",
|
||||||
|
global_privileges = {"faction_admin"},
|
||||||
|
on_success = function(player, faction, pos, parcelpos, args)
|
||||||
|
factions.faction_tick()
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: cmdhandler(playername,parameter)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
|
|
66
factions.lua
66
factions.lua
|
@ -29,6 +29,9 @@ factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factions.protection_max_depth = -512
|
factions.protection_max_depth = -512
|
||||||
factions.power_per_parcel = .5
|
factions.power_per_parcel = .5
|
||||||
|
factions.power_per_death = .25
|
||||||
|
factions.power_per_tick = .125
|
||||||
|
factions.tick_time = 60.
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @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)
|
||||||
|
@ -119,6 +122,9 @@ end
|
||||||
|
|
||||||
function factions.Faction.increase_power(self, power)
|
function factions.Faction.increase_power(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
|
if self.power > self.maxpower then
|
||||||
|
self.power = self.maxpower
|
||||||
|
end
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -127,6 +133,18 @@ function factions.Faction.decrease_power(self, power)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function factions.Faction.increase_maxpower(self, power)
|
||||||
|
self.maxpower = self.maxpower + power
|
||||||
|
factions.save()
|
||||||
|
end
|
||||||
|
|
||||||
|
function factions.Faction.decrease_maxpower(self, power)
|
||||||
|
self.maxpower = self.maxpower - power
|
||||||
|
if self.maxpower < 0. then -- should not happen
|
||||||
|
self.maxpower = 0.
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function factions.Faction.add_player(self, player, rank)
|
function factions.Faction.add_player(self, player, rank)
|
||||||
self:on_player_join(player)
|
self:on_player_join(player)
|
||||||
self.players[player] = rank or self.default_rank
|
self.players[player] = rank or self.default_rank
|
||||||
|
@ -169,6 +187,7 @@ function factions.Faction.claim_parcel(self, parcelpos)
|
||||||
factions.parcels[parcelpos] = self.name
|
factions.parcels[parcelpos] = self.name
|
||||||
self.land[parcelpos] = true
|
self.land[parcelpos] = true
|
||||||
self:decrease_power(factions.power_per_parcel)
|
self:decrease_power(factions.power_per_parcel)
|
||||||
|
self:decrease_maxpower(factions.power_per_parcel)
|
||||||
self:on_claim_parcel(parcelpos)
|
self:on_claim_parcel(parcelpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
@ -178,6 +197,7 @@ function factions.Faction.unclaim_parcel(self, parcelpos)
|
||||||
factions.parcels[parcelpos] = nil
|
factions.parcels[parcelpos] = nil
|
||||||
self.land[parcelpos] = nil
|
self.land[parcelpos] = nil
|
||||||
self:increase_power(factions.power_per_parcel)
|
self:increase_power(factions.power_per_parcel)
|
||||||
|
self:increase_maxpower(factions.power_per_parcel)
|
||||||
self:on_unclaim_parcel(parcelpos)
|
self:on_unclaim_parcel(parcelpos)
|
||||||
factions.save()
|
factions.save()
|
||||||
end
|
end
|
||||||
|
@ -330,6 +350,16 @@ function factions.Faction.broadcast(self, msg, sender)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--! @brief checks whether a faction has at least one connected player
|
||||||
|
function factions.Faction.is_online(self)
|
||||||
|
for playername, _ in pairs(self.players) do
|
||||||
|
if minetest.get_player_by_name(playername) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
-- callbacks for events --
|
-- callbacks for events --
|
||||||
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
function factions.Faction.on_create(self) --! @brief called when the faction is added to the global faction list
|
||||||
|
@ -493,8 +523,6 @@ function factions.load()
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
factions.factions = minetest.deserialize(raw_data)
|
factions.factions = minetest.deserialize(raw_data)
|
||||||
for facname, faction in pairs(factions.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
faction.attacked_parcels = {}
|
|
||||||
faction.maxpower = 0.
|
|
||||||
minetest.log("action", facname..","..faction.name)
|
minetest.log("action", facname..","..faction.name)
|
||||||
for player, rank in pairs(faction.players) do
|
for player, rank in pairs(faction.players) do
|
||||||
minetest.log("action", player..","..rank)
|
minetest.log("action", player..","..rank)
|
||||||
|
@ -505,6 +533,9 @@ function factions.load()
|
||||||
end
|
end
|
||||||
setmetatable(faction, factions.Faction)
|
setmetatable(faction, factions.Faction)
|
||||||
-- compatiblity and later additions
|
-- compatiblity and later additions
|
||||||
|
if not faction.maxpower or faction.maxpower == 0. then
|
||||||
|
faction.maxpower = faction.power
|
||||||
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
@ -548,15 +579,34 @@ end
|
||||||
|
|
||||||
minetest.register_on_dieplayer(
|
minetest.register_on_dieplayer(
|
||||||
function(player)
|
function(player)
|
||||||
|
local faction = factions.players[player:get_player_name()]
|
||||||
|
if not faction then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
faction = factions.factions[faction]
|
||||||
|
faction:decrease_power(factions.power_per_death)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
local lastUpdate = 0.
|
|
||||||
|
factions.faction_tick = function()
|
||||||
|
for facname, faction in pairs(factions.factions) do
|
||||||
|
if faction:is_online() then
|
||||||
|
faction:increase_power(factions.power_per_tick)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local hudUpdate = 0.
|
||||||
|
local factionUpdate = 0.
|
||||||
|
|
||||||
|
|
||||||
minetest.register_globalstep(
|
minetest.register_globalstep(
|
||||||
function(dtime)
|
function(dtime)
|
||||||
lastUpdate = lastUpdate + dtime
|
hudUpdate = hudUpdate + dtime
|
||||||
if lastUpdate > .5 then
|
factionUpdate = factionUpdate + dtime
|
||||||
|
if hudUpdate > .5 then
|
||||||
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]
|
||||||
|
@ -573,6 +623,11 @@ minetest.register_globalstep(
|
||||||
alignment = {x=0, y=0},
|
alignment = {x=0, y=0},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
hudUpdate = 0.
|
||||||
|
end
|
||||||
|
if factionUpdate > factions.tick_time then
|
||||||
|
factions.faction_tick()
|
||||||
|
factionUpdate = 0.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -599,6 +654,7 @@ minetest.register_on_respawnplayer(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local default_is_protected = minetest.is_protected
|
local default_is_protected = minetest.is_protected
|
||||||
minetest.is_protected = function(pos, player)
|
minetest.is_protected = function(pos, player)
|
||||||
local parcelpos = factions.get_parcel_pos(pos)
|
local parcelpos = factions.get_parcel_pos(pos)
|
||||||
|
|
2
init.lua
2
init.lua
|
@ -12,7 +12,7 @@
|
||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
factions_version = "0.7.0"
|
factions_version = "0.8.0"
|
||||||
|
|
||||||
core.log("action", "MOD: factions (by sapier) loading ...")
|
core.log("action", "MOD: factions (by sapier) loading ...")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user