From 5fd0c3dad3ad4ad7cf53b9e6861d936a0d0de01d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 30 Sep 2024 22:01:22 +0100 Subject: [PATCH] core/pos: implement set_multi as a convenient alternative to multiple set() calls /cc @VorTechnix & https://github.com/sbrl/Minetest-WorldEditAdditions/pull/112/files?diff=unified&w=1 --- worldeditadditions_core/core/pos.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/worldeditadditions_core/core/pos.lua b/worldeditadditions_core/core/pos.lua index 442fc57..77728d6 100644 --- a/worldeditadditions_core/core/pos.lua +++ b/worldeditadditions_core/core/pos.lua @@ -218,9 +218,20 @@ local function set2(player_name, pos) return set(player_name, 2, pos) end +--- Sets multiple positions for the given player. +-- @param player_name string The name of the player to set the positions for. +-- @param pos_list table A table of Vector3 positions to set, where the key is the index and the value is the position. +local function set_multi(player_name, pos_list) + for i,pos_new in pairs(pos_list) do + set(player_name, i, pos_new) + end +end --- Sets the all the positions for the given player. -- You probably want push_pos, not this function. +-- +-- WARNING: Will DELETE all points registered for the given player! +-- -- @param player_name string The name of the player to set the positions for. -- @param pos_list Vector3 The table of positions to set. -- @returns bool Whether the operation was successful or not (players aren't allowed more than positions_count_limit number of positions at a time). @@ -319,6 +330,7 @@ anchor = wea_c.EventEmitter.new({ set = set, set1 = set1, set2 = set2, + set_multi = set_multi, set_all = set_all, unmark = unmark, mark = mark,