Code: clean up part 0
This commit is contained in:
parent
6f953b27d4
commit
15d0d98937
376
chatcommands.lua
376
chatcommands.lua
File diff suppressed because it is too large
Load Diff
@ -2,16 +2,12 @@
|
||||
--! @return whether this faction can claim a parcelpos
|
||||
function factions.can_claim_parcel(name, parcelpos)
|
||||
local fn = factions.parcels.get(parcelpos)
|
||||
|
||||
if fn == nil then
|
||||
return true
|
||||
end
|
||||
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
if fn then
|
||||
local fac = factions.factions.get(fn.faction)
|
||||
|
||||
if fac.power < 0. and faction.power >= factions_config.power_per_parcel and not faction.allies[fn] and not faction.neutral[fn] then
|
||||
return true
|
||||
else
|
||||
@ -20,15 +16,12 @@ function factions.can_claim_parcel(name, parcelpos)
|
||||
elseif faction.power < factions_config.power_per_parcel then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.claim_parcel(name, parcelpos)
|
||||
-- check if claiming over other faction's territory
|
||||
local otherfac = factions.parcels.get(parcelpos)
|
||||
|
||||
if otherfac then
|
||||
local otherfac_name = otherfac.faction
|
||||
factions.unclaim_parcel(otherfac_name, parcelpos)
|
||||
@ -37,29 +30,20 @@ function factions.claim_parcel(name, parcelpos)
|
||||
local data = factions.create_parcel_table()
|
||||
data.faction = name
|
||||
factions.parcels.set(parcelpos, data)
|
||||
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.land[parcelpos] = true
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
|
||||
factions.decrease_power(name, factions_config.power_per_parcel)
|
||||
factions.increase_usedpower(name, factions_config.power_per_parcel)
|
||||
factions.on_claim_parcel(name, parcelpos)
|
||||
factions.parcelless_check(name)
|
||||
end
|
||||
|
||||
--! @brief claim a parcel, update power and update global parcels table
|
||||
function factions.unclaim_parcel(name, parcelpos)
|
||||
factions.remove_key(factions.parcels, parcelpos, nil, "faction", true)
|
||||
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.land[parcelpos] = nil
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
|
||||
factions.increase_power(name, factions_config.power_per_parcel)
|
||||
factions.decrease_usedpower(name, factions_config.power_per_parcel)
|
||||
factions.on_unclaim_parcel(name, parcelpos)
|
||||
@ -68,7 +52,6 @@ end
|
||||
|
||||
function factions.parcelless_check(name)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
if faction.land then
|
||||
local count = 0
|
||||
for index, value in pairs(faction.land) do
|
||||
@ -165,15 +148,11 @@ local parcel_size = factions_config.parcel_size
|
||||
function factions.claim_square(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
pos.x = pos.x - (parcel_size * (r - math.floor(r / 2)))
|
||||
pos.z = pos.z - (parcel_size * (r - math.floor(r / 2)))
|
||||
|
||||
local timer = 0
|
||||
|
||||
for i = 1, r do
|
||||
for l = 1, r do
|
||||
local p = {x = pos.x + (parcel_size * l), y = pos.y, z = pos.z + (parcel_size * i)}
|
||||
@ -183,9 +162,7 @@ function factions.claim_square(player, faction, r)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local auto_list = {}
|
||||
|
||||
local function _claim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
@ -194,7 +171,6 @@ local function _claim_auto(player, faction)
|
||||
minetest.after(0.1, _claim_auto, player, faction)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.claim_auto(player, faction)
|
||||
if auto_list[player] then
|
||||
auto_list[player] = nil
|
||||
@ -205,7 +181,6 @@ function factions.claim_auto(player, faction)
|
||||
_claim_auto(player, faction)
|
||||
end
|
||||
end
|
||||
|
||||
local function _claim_fill(player, faction, pos)
|
||||
if claim_helper(player, faction, factions.get_parcel_pos(pos), true) then
|
||||
local pos1 = {x = pos.x - parcel_size, y = pos.y, z = pos.z}
|
||||
@ -218,7 +193,6 @@ local function _claim_fill(player, faction, pos)
|
||||
minetest.after(math.random(0, 11) / 10, _claim_fill, player, faction, pos4)
|
||||
end
|
||||
end
|
||||
|
||||
function factions.claim_fill(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
@ -262,16 +236,13 @@ end
|
||||
function factions.claim_all(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
_claim_all(player, faction, pos)
|
||||
end
|
||||
|
||||
function factions.claim_help(player, func)
|
||||
local text = "All params for /f claim: <o,one, a,auto, f,fill, s,square, c,circle, all, l,list, h,help>, <none, number>"
|
||||
|
||||
if func == "o" or func == "one" then
|
||||
text = "/f claim o\n/f claim one\n Claim one parcel."
|
||||
elseif func == "a" or func == "auto" then
|
||||
@ -287,22 +258,17 @@ function factions.claim_help(player, func)
|
||||
elseif func == "all" then
|
||||
text = "/f claim all\nClaim all faction land."
|
||||
end
|
||||
|
||||
minetest.chat_send_player(player, text)
|
||||
end
|
||||
|
||||
function factions.unclaim_square(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
pos.x = pos.x - (parcel_size * (r - math.floor(r / 2)))
|
||||
pos.z = pos.z - (parcel_size * (r - math.floor(r / 2)))
|
||||
|
||||
local timer = 0
|
||||
|
||||
for i = 1, r do
|
||||
for l = 1, r do
|
||||
local p = {x = pos.x + (parcel_size * l), y = pos.y, z = pos.z + (parcel_size * i)}
|
||||
@ -349,10 +315,8 @@ end
|
||||
function factions.unclaim_fill(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
_unclaim_fill(player, faction, pos)
|
||||
end
|
||||
|
||||
@ -361,10 +325,8 @@ local parcel_size_center = parcel_size / 2
|
||||
function factions.unclaim_circle(player, faction, r)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = (math.floor(pos.x / parcel_size) * parcel_size) + parcel_size_center
|
||||
pos.z = (math.floor(pos.z / parcel_size) * parcel_size) + parcel_size_center
|
||||
|
||||
for i = 1, 360 do
|
||||
local angle = i * math.pi / 180
|
||||
local rpos = {x = pos.x + r * math.cos(angle), y = pos.y, z = pos.z + r * math.sin(angle)}
|
||||
@ -383,16 +345,13 @@ end
|
||||
function factions.unclaim_all(player, faction)
|
||||
local rplayer = minetest.get_player_by_name(player)
|
||||
local pos = vector.round(rplayer:get_pos())
|
||||
|
||||
pos.x = math.floor(pos.x / parcel_size) * parcel_size
|
||||
pos.z = math.floor(pos.z / parcel_size) * parcel_size
|
||||
|
||||
_unclaim_all(player, faction, pos)
|
||||
end
|
||||
|
||||
function factions.unclaim_help(player, func)
|
||||
local text = "All params for /f unclaim: <o,one, a,auto, f,fill, s,square, c,circle, all, l,list, h,help>, <none, number>"
|
||||
|
||||
if func == "o" or func == "one" then
|
||||
text = "/f unclaim o\n/f unclaim one\n Unclaim one parcel."
|
||||
elseif func == "a" or func == "auto" then
|
||||
@ -408,11 +367,9 @@ function factions.unclaim_help(player, func)
|
||||
elseif func == "all" then
|
||||
text = "/f unclaim all\nUnclaim all faction land."
|
||||
end
|
||||
|
||||
minetest.chat_send_player(player, text)
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
auto_list[player:get_player_name()] = nil
|
||||
end
|
||||
)
|
||||
auto_list[player:get_player_name()] = nil
|
||||
end)
|
||||
|
@ -38,7 +38,7 @@ function factions.create_faction_table()
|
||||
--! @brief maximum power of a faction
|
||||
maxpower = factions_config.maxpower,
|
||||
--! @brief power currently in use
|
||||
usedpower = 0.,
|
||||
usedpower = 0,
|
||||
--! @brief list of player names
|
||||
players = {},
|
||||
--! @brief table of ranks/permissions
|
||||
@ -119,29 +119,23 @@ function factions.remove_key(db, db_name, db_data, key, write)
|
||||
if not db_data then
|
||||
db_data = db.get(db_name)
|
||||
end
|
||||
|
||||
db_data[key] = nil
|
||||
|
||||
if factions.db_is_empty(db_data) then
|
||||
db.remove(db_name)
|
||||
return nil
|
||||
end
|
||||
|
||||
if write then
|
||||
db.set(db_name, db_data)
|
||||
end
|
||||
|
||||
return db_data
|
||||
end
|
||||
|
||||
-- faction data check on load
|
||||
local function update_data(db, db_name, db_data, empty_table, write)
|
||||
local needs_update = false
|
||||
|
||||
if not db_data then
|
||||
db_data = db.get(db_name)
|
||||
end
|
||||
|
||||
for k, v in pairs(empty_table) do
|
||||
if db_data[k] == nil then
|
||||
db_data[k] = v
|
||||
@ -149,11 +143,9 @@ local function update_data(db, db_name, db_data, empty_table, write)
|
||||
minetest.log("Adding property " .. k .. " to " .. db_name .. " file.")
|
||||
end
|
||||
end
|
||||
|
||||
if write and needs_update then
|
||||
db.set(db_name, db_data)
|
||||
end
|
||||
|
||||
return db_data
|
||||
end
|
||||
|
||||
@ -162,17 +154,14 @@ minetest.register_on_mods_loaded(function()
|
||||
for k, v in factions.factions.iterate() do
|
||||
update_data(factions.factions, k, nil, factions.create_faction_table(), true)
|
||||
end
|
||||
|
||||
minetest.log("Checking parcel files.")
|
||||
for k, v in factions.parcels.iterate() do
|
||||
update_data(factions.parcels, k, nil, factions.create_parcel_table(), true)
|
||||
end
|
||||
|
||||
minetest.log("Checking player files.")
|
||||
for k, v in factions.players.iterate() do
|
||||
update_data(factions.players, k, nil, factions.create_player_table(), true)
|
||||
end
|
||||
|
||||
minetest.log("Checking ip files.")
|
||||
for k, v in factions.player_ips.iterate() do
|
||||
update_data(factions.player_ips, k, nil, factions.create_ip_table(), true)
|
||||
|
@ -15,7 +15,6 @@ end
|
||||
|
||||
function factions.new_alliance(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.allies[faction] = true
|
||||
factions.on_new_alliance(name, faction)
|
||||
if bfaction.enemies[faction] then
|
||||
@ -24,24 +23,19 @@ function factions.new_alliance(name, faction)
|
||||
if bfaction.neutral[faction] then
|
||||
factions.end_neutral(name, faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_alliance(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.allies[faction] = nil
|
||||
factions.on_end_alliance(name, faction)
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.new_neutral(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.neutral[faction] = true
|
||||
|
||||
factions.on_new_neutral(name, faction)
|
||||
if bfaction.allies[faction] then
|
||||
factions.end_alliance(name, faction)
|
||||
@ -49,41 +43,32 @@ function factions.new_neutral(name, faction)
|
||||
if bfaction.enemies[faction] then
|
||||
factions.end_enemy(name, faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_neutral(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.neutral[faction] = nil
|
||||
factions.on_end_neutral(name, faction)
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.new_enemy(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.enemies[faction] = true
|
||||
factions.on_new_enemy(name, faction)
|
||||
|
||||
if bfaction.allies[faction] then
|
||||
factions.end_alliance(name, faction)
|
||||
end
|
||||
|
||||
if bfaction.neutral[faction] then
|
||||
factions.end_neutral(name, faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
||||
|
||||
function factions.end_enemy(name, faction)
|
||||
local bfaction = factions.factions.get(name)
|
||||
|
||||
bfaction.enemies[faction] = nil
|
||||
factions.on_end_enemy(name, faction)
|
||||
|
||||
factions.factions.set(name, bfaction)
|
||||
end
|
@ -1,36 +1,27 @@
|
||||
function factions.on_create(name) --! @brief called when the faction is added to the global faction list
|
||||
minetest.chat_send_all("Faction " .. name .. " has been created.")
|
||||
end
|
||||
|
||||
function factions.on_set_name(name, oldname)
|
||||
minetest.chat_send_all("Faction " .. oldname .. " has been changed its name to ".. name ..".")
|
||||
end
|
||||
|
||||
function factions.on_no_parcel(name)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
local now = os.time() - faction.no_parcel
|
||||
local l = factions_config.maximum_parcelless_faction_time
|
||||
|
||||
factions.broadcast(name, "This faction will disband in " .. l - now .. " seconds, because it has no parcels.")
|
||||
end
|
||||
|
||||
function factions.on_player_leave(name, player)
|
||||
factions.broadcast(name, player .. " has left this faction")
|
||||
end
|
||||
|
||||
function factions.on_player_join(name, player)
|
||||
factions.broadcast(name, player .. " has joined this faction")
|
||||
end
|
||||
|
||||
function factions.on_claim_parcel(name, pos)
|
||||
factions.broadcast(name, "Parcel (" .. pos .. ") has been claimed.")
|
||||
end
|
||||
|
||||
function factions.on_unclaim_parcel(name, pos)
|
||||
factions.broadcast(name, "Parcel ("..pos..") has been unclaimed.")
|
||||
end
|
||||
|
||||
function factions.on_disband(name, reason)
|
||||
local msg = "Faction " .. name .. " has been disbanded."
|
||||
if reason then
|
||||
@ -38,22 +29,18 @@ function factions.on_disband(name, reason)
|
||||
end
|
||||
minetest.chat_send_all(msg)
|
||||
end
|
||||
|
||||
function factions.on_new_leader(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, faction.leader .. " is now the leader of this faction")
|
||||
end
|
||||
|
||||
function factions.on_change_description(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "Faction description has been modified to: " .. faction.description)
|
||||
end
|
||||
|
||||
function factions.on_player_invited(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
minetest.chat_send_player(player, "You have been invited to faction " .. faction.name)
|
||||
end
|
||||
|
||||
function factions.on_toggle_join_free(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
if faction.join_free then
|
||||
@ -62,75 +49,58 @@ function factions.on_toggle_join_free(name, player)
|
||||
factions.broadcast(name, "This faction is no longer invite-free.")
|
||||
end
|
||||
end
|
||||
|
||||
function factions.on_new_alliance(name, faction)
|
||||
factions.broadcast(name, "This faction is now allied with " .. faction)
|
||||
end
|
||||
|
||||
function factions.on_end_alliance(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer allied with " .. faction .. "!")
|
||||
end
|
||||
|
||||
function factions.on_new_neutral(name, faction)
|
||||
factions.broadcast(name, "This faction is now neutral with ".. faction)
|
||||
end
|
||||
|
||||
function factions.on_end_neutral(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer neutral with " .. faction .. "!")
|
||||
end
|
||||
|
||||
function factions.on_new_enemy(name, faction)
|
||||
factions.broadcast(name, "This faction is now at war with " .. faction)
|
||||
end
|
||||
|
||||
function factions.on_end_enemy(name, faction)
|
||||
factions.broadcast(name, "This faction is no longer at war with " .. faction .. "!")
|
||||
end
|
||||
|
||||
function factions.on_set_spawn(name)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The faction spawn has been set to (" .. util.coords3D_string(faction.spawn) .. ").")
|
||||
end
|
||||
|
||||
function factions.on_add_rank(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The rank " .. rank .. " has been created with privileges: " .. table.concat(faction.ranks[rank], ", "))
|
||||
end
|
||||
|
||||
function factions.on_replace_privs(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been delete and changed to: " .. table.concat(faction.ranks[rank], ", "))
|
||||
end
|
||||
|
||||
function factions.on_remove_privs(name, rank, privs)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been revoked: " .. table.concat(privs, ", "))
|
||||
end
|
||||
|
||||
function factions.on_add_privs(name, rank, privs)
|
||||
factions.broadcast(name, "The privileges in rank " .. rank .. " have been added: " .. table.concat(privs, ", "))
|
||||
end
|
||||
|
||||
function factions.on_set_rank_name(name, rank,newrank)
|
||||
factions.broadcast(name, "The name of rank " .. rank .. " has been changed to " .. newrank)
|
||||
end
|
||||
|
||||
function factions.on_delete_rank(name, rank, newrank)
|
||||
factions.broadcast(name, "The rank " .. rank .. " has been deleted and replaced by " .. newrank)
|
||||
end
|
||||
|
||||
function factions.on_set_def_rank(name, rank)
|
||||
factions.broadcast(name, "The default rank given to new players has been changed to " .. rank)
|
||||
end
|
||||
|
||||
function factions.on_reset_ranks(name)
|
||||
factions.broadcast(name, "All of the faction's ranks have been reset to the default ones.")
|
||||
end
|
||||
|
||||
function factions.on_promote(name, member)
|
||||
local faction = factions.factions.get(name)
|
||||
minetest.chat_send_player(member, "You have been promoted to " .. faction.players[member])
|
||||
end
|
||||
|
||||
function factions.on_revoke_invite(name, player)
|
||||
minetest.chat_send_player(player, "You are no longer invited to faction " .. name)
|
||||
end
|
||||
|
46
factions.lua
46
factions.lua
@ -45,31 +45,40 @@ starting_ranks = {["leader"] = {"build", "door", "container", "name", "descripti
|
||||
-- ranks: create, edit, and delete ranks
|
||||
-- promote: set a player's rank
|
||||
-- diplomacy: be able to control the faction's diplomacy
|
||||
|
||||
factions.permissions = {"build", "pain_build", "door", "container", "name", "description", "motd", "invite", "kick"
|
||||
, "spawn", "with_draw", "territory", "claim", "access", "disband", "flags", "ranks", "promote"}
|
||||
factions.permissions_desc = {"dig and place nodes", "dig and place nodes but take damage doing so", "open/close or dig faction doors", "be able to use containers like chest", "set the faction's name"
|
||||
, "Set the faction description", "set the faction's message of the day", "(un)invite players to join the faction", "kick players off the faction", "set player titles", "set the faction's spawn"
|
||||
, "withdraw money from the faction's bank", "claim or unclaim territory", "(un)claim parcels of land", "manage access to territory and parcels of land to players or factions"
|
||||
, "disband the faction", "manage faction's flags", "create, edit, and delete ranks", "set a player's rank"}
|
||||
|
||||
factions.permissions = {}
|
||||
factions.permissions["build"] = "dig and place nodes"
|
||||
factions.permissions["pain_build"] = "dig and place nodes but take damage doing so"
|
||||
factions.permissions["door"] = "open, close, or dig faction doors"
|
||||
factions.permissions["container"] = "be able to interact with containers on claimed parcels"
|
||||
factions.permissions["name"] = "set the faction's name"
|
||||
factions.permissions["description"] = "Set the faction description"
|
||||
factions.permissions["motd"] = "set the faction's message of the day"
|
||||
factions.permissions["invite"] = "(un)invite players to join the faction"
|
||||
factions.permissions["kick"] = "kick players off the faction"
|
||||
factions.permissions["spawn"] = "set the faction's spawn"
|
||||
factions.permissions["with_draw"] = "withdraw money from the faction's bank"
|
||||
factions.permissions["territory"] = "claim or unclaim territory"
|
||||
factions.permissions["claim"] = "(un)claim parcels of land"
|
||||
factions.permissions["access"] = "manage access to territory and parcels of land to players or factions"
|
||||
factions.permissions["disband"] = "disband the faction"
|
||||
factions.permissions["flags"] = "manage the faction's flags"
|
||||
factions.permissions["ranks"] = "create, edit, or delete ranks"
|
||||
factions.permissions["promote"] = "set a player's rank"
|
||||
-- open: can the faction be joined without an invite?
|
||||
-- monsters: can monsters spawn on your land?
|
||||
-- tax_kick: will players be kicked for not paying tax?
|
||||
-- animals: can animals spawn on your land?
|
||||
factions.flags = {"open", "monsters", "tax_kick", "animals"}
|
||||
factions.flags_desc = {"can the faction be joined without an invite?", "can monsters spawn on your land?(unused)", "will players be kicked for not paying tax?(unused)", "can animals spawn on your land?(unused)"}
|
||||
|
||||
factions.flags = {}
|
||||
factions.flags["open"] = "can the faction be joined without an invite?"
|
||||
factions.flags["monsters"] = "can monsters spawn on your land?(unused)"
|
||||
factions.flags["tax_kick"] = "will players be kicked for not paying tax?(unused)"
|
||||
factions.flags["animals"] = "can animals spawn on your land?(unused)"
|
||||
if factions_config.faction_diplomacy == true then
|
||||
table.insert(factions.permissions, "diplomacy")
|
||||
|
||||
table.insert(factions.permissions_desc, "be able to control the faction's diplomacy")
|
||||
|
||||
factions.permissions["diplomacy"] = "be able to control the faction's diplomacy"
|
||||
local lt = starting_ranks["leader"]
|
||||
table.insert(lt, "diplomacy")
|
||||
starting_ranks["leader"] = lt
|
||||
end
|
||||
|
||||
--! @brief create a new empty faction
|
||||
function factions.new_faction(name)
|
||||
local faction = factions.create_faction_table()
|
||||
@ -327,7 +336,6 @@ end
|
||||
--! @return boolean indicating permissions. Players not in faction always receive false
|
||||
function factions.has_permission(name, player, permission)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
local p = faction.players[player]
|
||||
if not p then
|
||||
return false
|
||||
@ -346,20 +354,16 @@ end
|
||||
|
||||
function factions.set_description(name, new)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.description = new
|
||||
factions.on_change_description(name)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
--! @brief set faction openness
|
||||
function factions.toggle_join_free(name, bool)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.join_free = bool
|
||||
factions.on_toggle_join_free(name)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
|
3
hud.lua
3
hud.lua
@ -4,7 +4,6 @@ function createHudfactionLand(player)
|
||||
if player then
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "factionLand"
|
||||
|
||||
if not hud_ids[id_name] then
|
||||
hud_ids[id_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
@ -23,7 +22,6 @@ function createHudFactionName(player, factionname)
|
||||
if player and factionname then
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "factionName"
|
||||
|
||||
if not hud_ids[id_name] then
|
||||
hud_ids[id_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
@ -43,7 +41,6 @@ function createHudPower(player, faction)
|
||||
if player and faction then
|
||||
local name = player:get_player_name()
|
||||
local id_name = name .. "powerWatch"
|
||||
|
||||
if not hud_ids[id_name] then
|
||||
hud_ids[id_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
|
2
init.lua
2
init.lua
@ -1,6 +1,5 @@
|
||||
--!path of mod
|
||||
factions_modpath = minetest.get_modpath("factions")
|
||||
|
||||
dofile (factions_modpath .. "/config.lua")
|
||||
dofile (factions_modpath .. "/storagedb.lua")
|
||||
dofile (factions_modpath .. "/databases.lua")
|
||||
@ -16,6 +15,5 @@ dofile (factions_modpath .. "/claim_events.lua")
|
||||
dofile (factions_modpath .. "/factions.lua")
|
||||
dofile (factions_modpath .. "/chatcommands.lua")
|
||||
dofile (factions_modpath .. "/nodes.lua")
|
||||
|
||||
minetest.after(1, hudUpdateClaimInfo)
|
||||
minetest.after(factions_config.tick_time, factionUpdate)
|
||||
|
@ -1,19 +1,15 @@
|
||||
--! @brief places player in invite list
|
||||
function factions.invite_player(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.invited_players[player] = true
|
||||
factions.on_player_invited(name, player)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
--! @brief removes player from invite list (can no longer join via /f join)
|
||||
function factions.revoke_invite(name, player)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.invited_players[player] = nil
|
||||
factions.on_revoke_invite(name, player)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
10
nodes.lua
10
nodes.lua
@ -17,7 +17,6 @@ minetest.register_on_mods_loaded(function()
|
||||
if minetest.registered_nodes["default:chest"] then
|
||||
local dc = minetest.registered_nodes["default:chest"]
|
||||
local def_on_rightclick = dc.on_rightclick
|
||||
|
||||
local after_place_node = function(pos, placer)
|
||||
local parcel_faction = factions.get_faction_at(pos)
|
||||
if parcel_faction then
|
||||
@ -28,14 +27,12 @@ minetest.register_on_mods_loaded(function()
|
||||
name .. ")")
|
||||
end
|
||||
end
|
||||
|
||||
local can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main") and
|
||||
factions.can_use_node(pos, player:get_player_name(), "container")
|
||||
end
|
||||
|
||||
local allow_metadata_inventory_move
|
||||
local def_allow_metadata_inventory_move = dc.allow_metadata_inventory_move
|
||||
if def_allow_metadata_inventory_move then
|
||||
@ -55,7 +52,6 @@ minetest.register_on_mods_loaded(function()
|
||||
return count
|
||||
end
|
||||
end
|
||||
|
||||
local allow_metadata_inventory_put
|
||||
local def_allow_metadata_inventory_put = dc.allow_metadata_inventory_put
|
||||
if def_allow_metadata_inventory_put then
|
||||
@ -73,7 +69,6 @@ minetest.register_on_mods_loaded(function()
|
||||
return stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
local allow_metadata_inventory_take
|
||||
local def_allow_metadata_inventory_take = dc.allow_metadata_inventory_take
|
||||
if def_allow_metadata_inventory_take then
|
||||
@ -91,14 +86,12 @@ minetest.register_on_mods_loaded(function()
|
||||
return stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
local on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
if not factions.can_use_node(pos, clicker:get_player_name(), "container") and not minetest.check_player_privs(clicker, "protection_bypass") then
|
||||
return itemstack
|
||||
end
|
||||
return def_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||
end
|
||||
|
||||
minetest.override_item("default:chest", {after_place_node = after_place_node,
|
||||
can_dig = can_dig,
|
||||
allow_metadata_inventory_move = allow_metadata_inventory_move,
|
||||
@ -123,11 +116,8 @@ minetest.register_on_mods_loaded(function()
|
||||
|
||||
-- Edit default doors and trapdoors to make them require the door permission.
|
||||
local doors = {}
|
||||
|
||||
local all_items = {}
|
||||
|
||||
local item_count = 1
|
||||
|
||||
local old_i = 0
|
||||
|
||||
for i, l in ipairs(door_items) do
|
||||
|
@ -5,7 +5,6 @@ minetest.register_on_prejoinplayer(function(name, ip)
|
||||
data.ip = ip
|
||||
factions.player_ips.set(name, data)
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
minetest.after(5, createHudfactionLand, player)
|
||||
@ -14,15 +13,11 @@ minetest.register_on_joinplayer(function(player)
|
||||
if factions.onlineplayers[facname] == nil then
|
||||
factions.onlineplayers[facname] = {}
|
||||
end
|
||||
|
||||
factions.onlineplayers[facname][name] = true
|
||||
faction.last_logon = os.time()
|
||||
|
||||
factions.factions.set(facname, faction)
|
||||
|
||||
minetest.after(5, createHudFactionName, player, facname)
|
||||
minetest.after(5, createHudPower, player, faction)
|
||||
|
||||
if faction.no_parcel ~= -1 then
|
||||
local now = os.time() - faction.no_parcel
|
||||
local l = factions_config.maximum_parcelless_faction_time
|
||||
@ -37,38 +32,30 @@ minetest.register_on_joinplayer(function(player)
|
||||
minetest.chat_send_player(name, faction.message_of_the_day)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
local id_name1 = name .. "factionLand"
|
||||
|
||||
if hud_ids[id_name1] then
|
||||
hud_ids[id_name1] = nil
|
||||
end
|
||||
|
||||
if faction then
|
||||
faction.last_logon = os.time()
|
||||
factions.factions.set(facname, faction)
|
||||
factions.onlineplayers[facname][name] = nil
|
||||
|
||||
hud_ids[name .. "factionName"] = nil
|
||||
hud_ids[name .. "powerWatch"] = nil
|
||||
else
|
||||
factions.remove_key(factions.player_ips, name, nil, "ip", true)
|
||||
end
|
||||
|
||||
on_death[name] = nil
|
||||
local name = player:get_player_name()
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
local id_name1 = name .. "factionLand"
|
||||
if hud_ids[id_name1] then
|
||||
hud_ids[id_name1] = nil
|
||||
end
|
||||
)
|
||||
if faction then
|
||||
faction.last_logon = os.time()
|
||||
factions.factions.set(facname, faction)
|
||||
factions.onlineplayers[facname][name] = nil
|
||||
|
||||
hud_ids[name .. "factionName"] = nil
|
||||
hud_ids[name .. "powerWatch"] = nil
|
||||
else
|
||||
factions.remove_key(factions.player_ips, name, nil, "ip", true)
|
||||
end
|
||||
on_death[name] = nil
|
||||
end)
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local faction, facname = factions.get_player_faction(name)
|
||||
|
||||
if not faction then
|
||||
return false
|
||||
else
|
||||
|
@ -1,81 +1,62 @@
|
||||
function factions.increase_power(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.power = faction.power + power
|
||||
|
||||
if faction.power > faction.maxpower - faction.usedpower then
|
||||
faction.power = faction.maxpower - faction.usedpower
|
||||
end
|
||||
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_power(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.power = faction.power - power
|
||||
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.increase_maxpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.maxpower = faction.maxpower + power
|
||||
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_maxpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.maxpower = faction.maxpower - power
|
||||
|
||||
if faction.maxpower < 0. then -- should not happen
|
||||
faction.maxpower = 0.
|
||||
if faction.maxpower < 0 then -- should not happen
|
||||
faction.maxpower = 0
|
||||
end
|
||||
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.increase_usedpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.usedpower = faction.usedpower + power
|
||||
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.decrease_usedpower(name, power)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.usedpower = faction.usedpower - power
|
||||
if faction.usedpower < 0. then
|
||||
faction.usedpower = 0.
|
||||
if faction.usedpower < 0 then
|
||||
faction.usedpower = 0
|
||||
end
|
||||
for i in pairs(factions.onlineplayers[name]) do
|
||||
updateHudPower(minetest.get_player_by_name(i), faction)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
@ -4,22 +4,17 @@ minetest.is_protected = function(pos, player)
|
||||
if minetest.check_player_privs(player, "protection_bypass") then
|
||||
return default_is_protected(pos, player)
|
||||
end
|
||||
|
||||
local y = pos.y
|
||||
|
||||
if factions_config.protection_depth_height_limit and (pos.y < factions_config.protection_max_depth or pos.y > factions_config.protection_max_height) then
|
||||
return default_is_protected(pos, player)
|
||||
end
|
||||
|
||||
local parcelpos = factions.get_parcel_pos(pos)
|
||||
local parcel_faction, parcel_fac_name = factions.get_parcel_faction(parcelpos)
|
||||
local player_faction
|
||||
local player_fac_name
|
||||
|
||||
if player then
|
||||
player_faction, player_fac_name = factions.get_player_faction(player)
|
||||
end
|
||||
|
||||
-- no faction
|
||||
if not parcel_faction then
|
||||
return default_is_protected(pos, player)
|
||||
|
@ -3,10 +3,8 @@
|
||||
--! @param rank a list with the permissions of the new rank
|
||||
function factions.add_rank(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.ranks[rank] = perms
|
||||
factions.on_add_rank(name, rank)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
@ -15,108 +13,85 @@ end
|
||||
--! @param add or remove permissions to the rank
|
||||
function factions.replace_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.ranks[rank] = perms
|
||||
factions.on_replace_privs(name, rank)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.remove_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
local revoked = false
|
||||
local p = faction.ranks[rank]
|
||||
|
||||
for index, perm in pairs(p) do
|
||||
if table_Contains(perms, perm) then
|
||||
revoked = true
|
||||
table.remove(p, index)
|
||||
end
|
||||
end
|
||||
|
||||
faction.ranks[rank] = p
|
||||
|
||||
if revoked then
|
||||
factions.on_remove_privs(name, rank, perms)
|
||||
else
|
||||
factions.broadcast(name, "No privilege was revoked from rank " .. rank .. ".")
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.add_privs(name, rank, perms)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
local added = false
|
||||
local p = faction.ranks[rank]
|
||||
|
||||
for index, perm in pairs(perms) do
|
||||
if not table_Contains(p, perm) then
|
||||
added = true
|
||||
table.insert(p, perm)
|
||||
end
|
||||
end
|
||||
|
||||
faction.ranks[rank] = p
|
||||
|
||||
if added then
|
||||
factions.on_add_privs(name, rank, perms)
|
||||
else
|
||||
factions.broadcast(name, "The rank " .. rank .. " already has these privileges.")
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.set_rank_name(name, oldrank, newrank)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
local copyrank = faction.ranks[oldrank]
|
||||
|
||||
faction.ranks[newrank] = copyrank
|
||||
faction.ranks[oldrank] = nil
|
||||
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == oldrank then
|
||||
faction.players[player] = newrank
|
||||
end
|
||||
end
|
||||
|
||||
if oldrank == faction.default_leader_rank then
|
||||
faction.default_leader_rank = newrank
|
||||
factions.broadcast(name, "The default leader rank has been set to " .. newrank)
|
||||
end
|
||||
|
||||
if oldrank == faction.default_rank then
|
||||
faction.default_rank = newrank
|
||||
factions.broadcast(name, "The default rank given to new players is set to " .. newrank)
|
||||
end
|
||||
|
||||
factions.on_set_rank_name(name, oldrank, newrank)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.set_def_rank(name, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == rank or r == nil or not faction.ranks[r] then
|
||||
faction.players[player] = rank
|
||||
end
|
||||
end
|
||||
|
||||
faction.default_rank = rank
|
||||
factions.on_set_def_rank(name, rank)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
function factions.reset_ranks(name)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.ranks = starting_ranks
|
||||
faction.default_rank = "member"
|
||||
faction.default_leader_rank_rank = "leader"
|
||||
@ -128,7 +103,6 @@ function factions.reset_ranks(name)
|
||||
end
|
||||
end
|
||||
factions.on_reset_ranks(name)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
@ -137,7 +111,6 @@ end
|
||||
--! @param newrank the rank given to players who were previously "rank"
|
||||
function factions.delete_rank(name, rank, newrank)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
for player, r in pairs(faction.players) do
|
||||
if r == rank then
|
||||
faction.players[player] = newrank
|
||||
@ -153,16 +126,13 @@ function factions.delete_rank(name, rank, newrank)
|
||||
faction.default_rank = newrank
|
||||
factions.broadcast(name, "The default rank given to new players is set to "..newrank)
|
||||
end
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
||||
--! @brief set a player's rank
|
||||
function factions.promote(name, member, rank)
|
||||
local faction = factions.factions.get(name)
|
||||
|
||||
faction.players[member] = rank
|
||||
factions.on_promote(name, member)
|
||||
|
||||
factions.factions.set(name, faction)
|
||||
end
|
||||
|
@ -47,6 +47,8 @@ factions.protection_depth_height_limit (Enable protection depth height limit) bo
|
||||
factions.spawn_teleport (Enable spawn teleport) bool false
|
||||
# Enable or disabled the need for faction_user priv
|
||||
factions.faction_user_priv (Enable faction user priv) bool false
|
||||
# Enable or disabled Store player ips to prevent players from gaining more max power from alts
|
||||
factions.store_ip bool true
|
||||
|
||||
[StringSettings]
|
||||
# Set the way that the parcel protection works (2d, 3d).
|
||||
|
Loading…
Reference in New Issue
Block a user