save when a faction is disband, change the value of area.faction_open with the old playerfactions version to facilitate the switch into the new one
This commit is contained in:
parent
8c98db4da4
commit
7a4c992499
|
@ -304,7 +304,7 @@ if areas.factions_available then
|
||||||
.." or is not owned by you.", id)
|
.." or is not owned by you.", id)
|
||||||
end
|
end
|
||||||
if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then
|
if factions.version == nil or factions.version < 2 or factions.mode_unique_faction then
|
||||||
local open = not areas.areas[id].faction_open and factions.get_player_faction(name)
|
local open = not areas.areas[id].faction_open and {factions.get_player_faction(name)}
|
||||||
-- Save false as nil to avoid inflating the DB.
|
-- Save false as nil to avoid inflating the DB.
|
||||||
areas.areas[id].faction_open = open or nil
|
areas.areas[id].faction_open = open or nil
|
||||||
areas:save()
|
areas:save()
|
||||||
|
@ -322,8 +322,8 @@ if areas.factions_available then
|
||||||
local removed = false
|
local removed = false
|
||||||
for i, fac_name in ipairs(fnames) do
|
for i, fac_name in ipairs(fnames) do
|
||||||
if faction_name == fac_name then
|
if faction_name == fac_name then
|
||||||
removed = true
|
|
||||||
table.remove(fnames,i)
|
table.remove(fnames,i)
|
||||||
|
removed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not removed then
|
if not removed then
|
||||||
|
@ -332,7 +332,7 @@ if areas.factions_available then
|
||||||
if #fnames == 0 then
|
if #fnames == 0 then
|
||||||
fnames = nil
|
fnames = nil
|
||||||
end
|
end
|
||||||
-- Save false as nil to avoid inflating the DB.
|
-- Save {} as nil to avoid inflating the DB.
|
||||||
areas.areas[id].faction_open = fnames
|
areas.areas[id].faction_open = fnames
|
||||||
areas:save()
|
areas:save()
|
||||||
return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", "))
|
return true, fnames and S("Area is open for members of: @1",table.concat(fnames,", "))
|
||||||
|
|
6
hud.lua
6
hud.lua
|
@ -25,17 +25,23 @@ minetest.register_globalstep(function(dtime)
|
||||||
if factions.version == nil or factions.version < 2 then
|
if factions.version == nil or factions.version < 2 then
|
||||||
faction_info = factions.get_player_faction(area.owner)
|
faction_info = factions.get_player_faction(area.owner)
|
||||||
else
|
else
|
||||||
|
-- Verify that every displayed faction still exists
|
||||||
|
local faction_open_changed = false
|
||||||
for i, fac_name in ipairs(area.faction_open) do
|
for i, fac_name in ipairs(area.faction_open) do
|
||||||
if not factions.get_owner(fac_name) then
|
if not factions.get_owner(fac_name) then
|
||||||
table.remove(area.faction_open, i)
|
table.remove(area.faction_open, i)
|
||||||
|
faction_open_changed = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #area.faction_open == 0 then
|
if #area.faction_open == 0 then
|
||||||
area.faction_open = nil
|
area.faction_open = nil
|
||||||
faction_info = nil
|
faction_info = nil
|
||||||
|
faction_open_changed = true
|
||||||
else
|
else
|
||||||
faction_info = table.concat(area.faction_open, ", ")
|
faction_info = table.concat(area.faction_open, ", ")
|
||||||
end
|
end
|
||||||
|
-- Save areas if a faction was disband
|
||||||
|
if faction_open_changed then areas:save() end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue