diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 58a7381b..b5d569af 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -1222,6 +1222,34 @@ static int lua_UnitCreatureType(lua_State* L) { return 1; } +// GetSpellLink(spellIdOrName) → "|cFFxxxxxx|Hspell:ID|h[Name]|h|r" +static int lua_GetSpellLink(lua_State* L) { + auto* gh = getGameHandler(L); + if (!gh) { lua_pushnil(L); return 1; } + + uint32_t spellId = 0; + if (lua_isnumber(L, 1)) { + spellId = static_cast(lua_tonumber(L, 1)); + } else if (lua_isstring(L, 1)) { + const char* name = lua_tostring(L, 1); + if (!name || !*name) { lua_pushnil(L); return 1; } + std::string nameLow(name); + for (char& c : nameLow) c = static_cast(std::tolower(static_cast(c))); + for (uint32_t sid : gh->getKnownSpells()) { + std::string sn = gh->getSpellName(sid); + for (char& c : sn) c = static_cast(std::tolower(static_cast(c))); + if (sn == nameLow) { spellId = sid; break; } + } + } + if (spellId == 0) { lua_pushnil(L); return 1; } + std::string name = gh->getSpellName(spellId); + if (name.empty()) { lua_pushnil(L); return 1; } + char link[256]; + snprintf(link, sizeof(link), "|cff71d5ff|Hspell:%u|h[%s]|h|r", spellId, name.c_str()); + lua_pushstring(L, link); + return 1; +} + // IsUsableSpell(spellIdOrName) → usable, noMana static int lua_IsUsableSpell(lua_State* L) { auto* gh = getGameHandler(L); @@ -1685,6 +1713,7 @@ void LuaEngine::registerCoreAPI() { {"UnitIsEnemy", lua_UnitIsEnemy}, {"UnitCreatureType", lua_UnitCreatureType}, {"UnitClassification", lua_UnitClassification}, + {"GetSpellLink", lua_GetSpellLink}, {"IsUsableSpell", lua_IsUsableSpell}, {"IsInInstance", lua_IsInInstance}, {"GetInstanceInfo", lua_GetInstanceInfo},