From d612f8697d4b5863f0060e8250d0276ecd9b1ee6 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Mon, 31 May 2021 20:11:57 +0200 Subject: [PATCH] Prevent adding waypoint at same pos --- init.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index b4284e0..f865125 100644 --- a/init.lua +++ b/init.lua @@ -74,7 +74,7 @@ local min, max, floor, ceil, random = local pairs, ipairs, next, type, setmetatable, tonum, unpack, select = pairs, ipairs, next, type, setmetatable, tonumber, unpack, select -local vec_add, vec_mul = vector.add, vector.multiply +local vec_add, vec_mul, vec_eq, vec_round = vector.add, vector.multiply, vector.equals, vector.round local MAX_FAVS = 6 local ITEM_BTN_SIZE = 1.1 @@ -2676,6 +2676,14 @@ i3.new_tab { return elseif fields.waypoint_add then + local pos = player:get_pos() + + for _, v in ipairs(data.waypoints) do + if vec_eq(vec_round(pos), vec_round(v.pos)) then + return msg(name, "You already set a waypoint at this position") + end + end + local waypoint = fields.waypoint_name if fields.waypoint_name == "" then @@ -2683,7 +2691,6 @@ i3.new_tab { end local color = random(0xffffff) - local pos = player:get_pos() local id = player:hud_add { hud_elem_type = "waypoint",