Verify that faction exists

This commit is contained in:
Supergoat666 2020-07-29 10:00:47 +02:00
parent fae1dae051
commit 04961bee69
1 changed files with 12 additions and 4 deletions

View File

@ -288,9 +288,13 @@ if areas.factions_available then
minetest.register_chatcommand("area_faction_open", { minetest.register_chatcommand("area_faction_open", {
params = S("<ID> [faction_name]"), params = S("<ID> [faction_name]"),
description = S("Toggle an area open/closed for members in your faction."), description = S("Toggle an area open/closed for members in your faction."),
func = function(name, params) func = function(name, param)
local found, _, id, faction_name = params:find("(%d+)%s-(%S-)$") local params = {}
local id = tonumber(id) for p in string.gmatch(param, "[^%s]+") do
table.insert(params, p)
end
local id = tonumber(params[1])
if not id then if not id then
return false, S("Invalid usage, see /help @1.", "area_faction_open") return false, S("Invalid usage, see /help @1.", "area_faction_open")
end end
@ -307,6 +311,10 @@ if areas.factions_available then
return true, open and S("Area opened for faction members.") return true, open and S("Area opened for faction members.")
or S("Area closed for faction members.") or S("Area closed for faction members.")
else else
local faction_name = params[2]
if not factions.get_owner(faction_name) then
return false, S("Faction doesn't exists")
end
local fnames = areas.areas[id].factions_names local fnames = areas.areas[id].factions_names
if fnames == nil then if fnames == nil then
fnames = {} fnames = {}