From edf0be9dbb534dbb5beb9cb5a692369c013831a6 Mon Sep 17 00:00:00 2001 From: MarcelineVQ Date: Sat, 7 Mar 2026 11:27:14 -0800 Subject: [PATCH] Distinguish placement failure from permission denied in WorldMarker DLL now returns -1 for placement failures (no terrain, unit not found) instead of nil. Lua side shows a throttled (2s cooldown) failure message separate from the permission denied message. --- src/markers/addon/Markers.lua | 14 ++++++++++++++ src/markers/markers.zig | 19 ++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/markers/addon/Markers.lua b/src/markers/addon/Markers.lua index 524bec8..74f9fd3 100644 --- a/src/markers/addon/Markers.lua +++ b/src/markers/addon/Markers.lua @@ -139,6 +139,16 @@ local function showDenyMessage() end end +local failLastTime = 0 +local FAIL_COOLDOWN = 2 + +local function showFailMessage() + local now = GetTime() + if now - failLastTime < FAIL_COOLDOWN then return end + failLastTime = now + DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Unable to create World Marker at that location.|r") +end + -- ============================================================================= -- Wrap DLL functions to broadcast on group placement/clear -- ============================================================================= @@ -150,6 +160,10 @@ function WorldMarker(index, ...) showDenyMessage() return end + if ok < 0 then + showFailMessage() + return + end denyCount = 0 local ch = getChannel() if ch then diff --git a/src/markers/markers.zig b/src/markers/markers.zig index a0174b3..4a83f4a 100644 --- a/src/markers/markers.zig +++ b/src/markers/markers.zig @@ -526,24 +526,26 @@ fn clearAllMarkers() void { // ============================================================================= /// Lua: local ok = WorldMarker(index [, x, y, z | "unitId"]) -/// Returns 1 on success, nil on permission denied. +/// Returns 1 on success, nil on permission denied, -1 on placement failure. pub fn luaWorldMarker(L: lua.State) callconv(.c) u32 { if (!canSetMarkers()) { con.print("[worldmarkers] WorldMarker: no permission\n"); - return 0; // nil - addon shows user message + return 0; // nil - addon shows permission message } const nargs = lua.gettop(L); if (nargs < 1 or !lua.isnumber(L, 1)) { con.print("[worldmarkers] WorldMarker: expected index (1-5)\n"); - return 0; + lua.pushnumber(L, -1.0); + return 1; } const raw_index = @as(i32, @intFromFloat(lua.tonumber(L, 1))); if (raw_index < 1 or raw_index > NUM_MARKERS) { con.print("[worldmarkers] WorldMarker: index must be 1-5\n"); - return 0; + lua.pushnumber(L, -1.0); + return 1; } const index: usize = @intCast(raw_index - 1); @@ -555,17 +557,20 @@ pub fn luaWorldMarker(L: lua.State) callconv(.c) u32 { } else if (nargs >= 2 and lua.isstring(L, 2)) { const unit_id = lua.tostring(L, 2) orelse { con.print("[worldmarkers] WorldMarker: invalid unit string\n"); - return 0; + lua.pushnumber(L, -1.0); + return 1; }; const pos = resolveUnitPosition(unit_id) orelse { con.fmt("[worldmarkers] WorldMarker: unit '{s}' not found\n", .{std.mem.span(unit_id)}); - return 0; + lua.pushnumber(L, -1.0); + return 1; }; _ = placeMarker(index, pos); } else { const pos = getCursorTerrainPosition() orelse { con.print("[worldmarkers] no terrain under cursor\n"); - return 0; + lua.pushnumber(L, -1.0); + return 1; }; _ = placeMarker(index, pos); }