From ffe8d5f8c0914e0fece942085d9cfdcf29aabe63 Mon Sep 17 00:00:00 2001 From: paly2 Date: Fri, 9 Dec 2016 15:09:15 +0100 Subject: [PATCH] Adjustable player detector and entity detector: make the user able to use a coma-separated list for the names --- moremesecons_adjustable_player_detector/init.lua | 15 +++++++++++---- moremesecons_entity_detector/init.lua | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/moremesecons_adjustable_player_detector/init.lua b/moremesecons_adjustable_player_detector/init.lua index 7f7bd04..acc7b34 100644 --- a/moremesecons_adjustable_player_detector/init.lua +++ b/moremesecons_adjustable_player_detector/init.lua @@ -4,7 +4,7 @@ local function make_formspec(meta) meta:set_string("formspec", "size[9,5]" .. - "field[0.3, 0;9,2;scanname;Name of player to scan for (empty for any):;${scanname}]".. + "field[0.3, 0;9,2;scanname;Coma-separated list of the names of players to scan for (empty for any):;${scanname}]".. "field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]".. "field[0.3,3;2,2;radius;Detection radius:;${radius}]".. "button_exit[3.5,3.5;2,3;;Save]") @@ -35,15 +35,22 @@ local object_detector_scan = function (pos) local meta = minetest.get_meta(pos) local scanname = meta:get_string("scanname") local scan_all = scanname == "" + local scan_names = scanname:split(',') local radius = meta:get_int("radius") if radius == 0 then radius = 6 end for _,obj in pairs(minetest.get_objects_inside_radius(pos, radius)) do local isname = obj:get_player_name() -- "" is returned if it is not a player; "" ~= nil! - if isname ~= "" - and (scan_all or isname == scanname) then -- player with scanname found or not scanname specified - return true + if isname ~= "" then + if scan_all then + return true + end + for _, name in ipairs(scan_names) do + if isname == name then + return true + end + end end end return false diff --git a/moremesecons_entity_detector/init.lua b/moremesecons_entity_detector/init.lua index bc09b97..0aacfe2 100644 --- a/moremesecons_entity_detector/init.lua +++ b/moremesecons_entity_detector/init.lua @@ -4,7 +4,7 @@ local function make_formspec(meta) meta:set_string("formspec", "size[9,5]" .. - "field[0.3, 0;9,2;scanname;Name (itemstring) of entity to scan for (empty for any):;${scanname}]".. + "field[0.3, 0;9,2;scanname;Coma-separated list of the names (itemstring) of entities to scan for (empty for any):;${scanname}]".. "field[0.3,1.5;4,2;digiline_channel;Digiline Channel (optional):;${digiline_channel}]".. "field[0.3,3;2,2;radius;Detection radius:;${radius}]".. "button_exit[3.5,3.5;2,3;;Save]") @@ -35,6 +35,7 @@ local object_detector_scan = function (pos) local meta = minetest.get_meta(pos) local scanname = meta:get_string("scanname") local scan_all = scanname == "" + local scan_names = scanname:split(',') local radius = meta:get_int("radius") if radius == 0 then radius = 6 @@ -43,9 +44,15 @@ local object_detector_scan = function (pos) if not obj:is_player() then local luaentity = obj:get_luaentity() local isname = luaentity.name - if isname - and (scan_all or isname == scanname or (isname == "__builtin:item" and luaentity.itemstring == scanname)) then -- entity with scanname found or not scanname specified - return true + if isname then + if scan_all then + return true + end + for _, name in ipairs(scan_names) do + if isname == name or (isname == "__builtin:item" and luaentity.itemstring == name) then + return true + end + end end end end