Thread Tools Display Modes
03-22-24, 11:08 PM   #1
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
tag on target by ID

Hello everyone, I took the macro as a basis
Lua Code:
  1. /cleartarget
  2. /targetexact Webbed Guest
  3. /stopmacro [noexists]
  4. /run if GetRaidTargetIndex("target") == nil then if llRI == null then llRI = 0 end llRI = (llRI % 8) + 1 SetRaidTarget("target", llRI) PlaySound(SOUNDKIT.GM_CHAT_WARNING) end

It is necessary that an automatic tag be placed on NPS ID 205089

Lua Code:
  1. local addonName, addon = ...
  2. TargetUnit("npc=205089")
  3. if GetRaidTargetIndex("target") == nil then if llRI == null then llRI = 0 end llRI = (llRI % 8) + 1 SetRaidTarget("target", llRI) PlaySound(SOUNDKIT.GM_CHAT_WARNING) end
  Reply With Quote
03-23-24, 01:43 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
TargetUnit() is a protected function and can't be called autonomously. Additionally, it only accepts a name or valid UnitID (same goes for the /target commands).
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-23-24, 02:01 AM   #3
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by SDPhantom View Post
TargetUnit() is a protected function and can't be called autonomously. Additionally, it only accepts a name or valid UnitID (same goes for the /target commands).
Hello. Is it possible to not put a label on the ID?
  Reply With Quote
03-23-24, 07:39 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
No, unitID is a variable that has to hold one of the predefined unit values such as player, target, focus, pet etc. As the unit id link posted by SDPhantom explains.

But as was said, you can target by name such as /target Fel Reaver - although you might have to put quotes around the name. I've never used named targetting in macros so can't be 100% sure there.

Maybe you can explain what you are hoping to achieve with this project.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-23-24, 08:37 AM   #5
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Xrystal View Post
No, unitID is a variable that has to hold one of the predefined unit values such as player, target, focus, pet etc. As the unit id link posted by SDPhantom explains.

But as was said, you can target by name such as /target Fel Reaver - although you might have to put quotes around the name. I've never used named targetting in macros so can't be 100% sure there.

Maybe you can explain what you are hoping to achieve with this project.
Hello. It is necessary to place a mark on the target according to the ID of the NPC (all NPCs have the same names but different IDs).

ID NPC 205089
  Reply With Quote
03-23-24, 12:22 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Ah, then nope, not possible to do that.

Not sure where that ID you are talking about comes from as the GUID value which is a short term unique id for everything in the game is much longer than a single number.

"Creature-0-1465-0-2105-448-000043F59F"
Which is an example provided on https://warcraft.wiki.gg/wiki/API_UnitGUID page.

Unless you have already extracted the ID element from the GUID.
The ID for that creature is 448 with the three immediately before referencing the server, instance and zone they are in.

I cannot see a reverse equivalent except for players (https://warcraft.wiki.gg/wiki/API_GetPlayerInfoByGUID).

So, the nearest you could get ( assuming it is the GUID you are talking about ) is to cycle through all the possible targets via the /target ( or more precisely in this case /targetenemy) command or tab target and use the PLAYER_CHANGED_TARGET or UNIT_TARGET events to identify a target switch or
use the UPDATE_MOUSEOVER_UNIT event to identify an entity under the mouse when you move it.

see the following pages for more info:
https://warcraft.wiki.gg/wiki/UNIT_TARGET
https://warcraft.wiki.gg/wiki/PLAYER_TARGET_CHANGED
https://warcraft.wiki.gg/wiki/UPDATE_MOUSEOVER_UNIT

and use UnitGUID to get their unique ID and check it against the one(s) you want.

Once you have identified the correct target you could then use ( https://warcraft.wiki.gg/wiki/API_SetRaidTargetIcon ) to set an icon on that entity so people can see it.

I am assuming this is so that everyone targets the same entity.


I obviously haven't tried this myself, but it would be my first steps in attempting such a task.

There is no way to do this without you utilising a hardware action ( keypress, slash command, mousemove etc ) for each target change.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 03-23-24 at 12:37 PM.
  Reply With Quote
03-23-24, 10:07 PM   #7
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Originally Posted by Xrystal View Post
Ah, then nope, not possible to do that.

Not sure where that ID you are talking about comes from as the GUID value which is a short term unique id for everything in the game is much longer than a single number.

"Creature-0-1465-0-2105-448-000043F59F"
Which is an example provided on https://warcraft.wiki.gg/wiki/API_UnitGUID page.

Unless you have already extracted the ID element from the GUID.
The ID for that creature is 448 with the three immediately before referencing the server, instance and zone they are in.

I cannot see a reverse equivalent except for players (https://warcraft.wiki.gg/wiki/API_GetPlayerInfoByGUID).

So, the nearest you could get ( assuming it is the GUID you are talking about ) is to cycle through all the possible targets via the /target ( or more precisely in this case /targetenemy) command or tab target and use the PLAYER_CHANGED_TARGET or UNIT_TARGET events to identify a target switch or
use the UPDATE_MOUSEOVER_UNIT event to identify an entity under the mouse when you move it.

see the following pages for more info:
https://warcraft.wiki.gg/wiki/UNIT_TARGET
https://warcraft.wiki.gg/wiki/PLAYER_TARGET_CHANGED
https://warcraft.wiki.gg/wiki/UPDATE_MOUSEOVER_UNIT

and use UnitGUID to get their unique ID and check it against the one(s) you want.

Once you have identified the correct target you could then use ( https://warcraft.wiki.gg/wiki/API_SetRaidTargetIcon ) to set an icon on that entity so people can see it.

I am assuming this is so that everyone targets the same entity.


I obviously haven't tried this myself, but it would be my first steps in attempting such a task.

There is no way to do this without you utilising a hardware action ( keypress, slash command, mousemove etc ) for each target change.

I found another macro that determines the NPC by ID (based on the example of achievement Something's Not Quite Right....).


Lua Code:
  1. /run local guid = UnitGUID("target");local type, _, _, _, _, npc_id, _ = strsplit("-",guid);if type == "Creature" and tonumber(npc_id) == 205089 then print("\124cFF00FF00YES\124r") else print("\124cFFFF0000NO\124r") end

Is this how it will work?

Lua Code:
  1. local addonName, addon = ...
  2. local guid = UnitGUID("target");local type, _, _, _, _, npc_id, _ = strsplit("-",guid);if type == "Creature" and tonumber(npc_id) == 205089
  3. if GetRaidTargetIndex("target") == nil then if llRI == null then llRI = 0 end llRI = (llRI % 8) + 1 SetRaidTarget("target", llRI) PlaySound(SOUNDKIT.GM_CHAT_WARNING) end
  Reply With Quote
03-24-24, 05:46 AM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
It won't work exactly like that. This, theoretically, is what you want to use. You might have to tweak it but I think it's coded up the way you need it to be.



Lua Code:
  1. local addonName, addon = ...
  2. local llRI = nil
  3. local npcToWatch = 205089
  4.  
  5. local function OnEvent(self,event,...)
  6.    if event == "PLAYER_TARGET_CHANGED" then
  7.  
  8.       local guid = UnitGUID("target")
  9.       if guid == nil then return end
  10.  
  11.       local guidType, _, _, _, _, npc_id, _ = strsplit("-",guid)
  12.       if guidType == "Creature" and tonumber(npc_id) == npcToWatch then      
  13.          if GetRaidTargetIndex("target") == nil then
  14.             if llRI == nil then
  15.                llRI = 0
  16.             end
  17.             llRI = (llRI % 8) + 1
  18.             if GetRaidTargetIndex("target") ~= llRI then
  19.                SetRaidTarget("target", llRI)
  20.                PlaySound(SOUNDKIT.GM_CHAT_WARNING)
  21.             end
  22.          end
  23.       end
  24.    end
  25. end
  26.  
  27. local f = CreateFrame("Frame")
  28. f:RegisterEvent("PLAYER_TARGET_CHANGED")
  29. f:SetScript("OnEvent",OnEvent)

UnitGUID("target") will only return a value if you have physically targetted a mob - I mentioned PLAYER_TARGET_CHANGED event being the one to watch for that happening to do your work.

Unless you are only ever going to need that one single creature then you will have to edit your addon, reload your UI so you can do it again for the next target of interest. And when they rebuild the GUIDs you will likely have to change the numbers again. It depends on whether these are special entities that keep their GUID permanently like players.

However, you could add in a slash command that allows you to type in the id of the next npc if you will need to repeat this for each npc you will be going after and to cater for GUID changes. I will leave that task up to you, but all you will need to do in that block of code is grab the id you typed and set that to the variable set up for it.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 03-24-24 at 05:49 AM.
  Reply With Quote
03-24-24, 09:47 PM   #9
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Hello thank you very much. You helped me.


Is it possible to remake the code in which it is not necessary to target NPCs? Like, for example, in a number of addons for scanning rare monsters (they put a mark even if you didn’t target the NPC).
  Reply With Quote
03-24-24, 10:38 PM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
You might be able to use "mouseover" instead of "target" and the event "UPDATE_MOUSEOVER_UNIT" but it is still reliant on the mouse moving over the mob and will trigger whenever you mouse over anything with a 3d model.

https://warcraft.wiki.gg/wiki/UPDATE_MOUSEOVER_UNIT

nUI uses mouseover if I remember rightly. At least I remember the odd rare message pop up as I moved around the world with my mouse.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-24-24, 11:47 PM   #11
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Thanks for the tip. I'm a beginner in this business. Will that work?

Lua Code:
  1. local addonName, addon = ...
  2. local llRI = nil
  3. local npcToWatch = 205089
  4.  
  5. local function OnEvent(self,event,...)
  6.    if event == "PLAYER_TARGET_CHANGED" then
  7.  
  8.       local guid = UnitGUID("UPDATE_MOUSEOVER_UNIT")
  9.       if guid == nil then return end
  10.  
  11.       local guidType, _, _, _, _, npc_id, _ = strsplit("-",guid)
  12.       if guidType == "Creature" and tonumber(npc_id) == npcToWatch then      
  13.          if GetRaidTargetIndex("UPDATE_MOUSEOVER_UNIT") == nil then
  14.             if llRI == nil then
  15.                llRI = 0
  16.             end
  17.             llRI = (llRI % 8) + 1
  18.             if GetRaidTargetIndex("UPDATE_MOUSEOVER_UNIT") ~= llRI then
  19.                SetRaidTarget("UPDATE_MOUSEOVER_UNIT", llRI)
  20.                PlaySound(SOUNDKIT.GM_CHAT_WARNING)
  21.             end
  22.          end
  23.       end
  24.    end
  25. end
  26.  
  27. local f = CreateFrame("Frame")
  28. f:RegisterEvent("PLAYER_TARGET_CHANGED")
  29. f:SetScript("OnEvent",OnEvent)
  Reply With Quote
03-25-24, 04:48 AM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Not quite, give this a go. Hopefully despite the functions having the word target in them they will work on mouseover too.


Lua Code:
  1. local addonName, addon = ...
  2. local llRI = nil
  3. local npcToWatch = 205089
  4.  
  5. local function OnEvent(self,event,...)
  6.    if event == "UPDATE_MOUSEOVER_UNIT" then
  7.  
  8.       local guid = UnitGUID("mouseover")
  9.       if guid == nil then return end
  10.  
  11.       local guidType, _, _, _, _, npc_id, _ = strsplit("-",guid)
  12.       if guidType == "Creature" and tonumber(npc_id) == npcToWatch then      
  13.          if GetRaidTargetIndex("mouseover") == nil then
  14.             if llRI == nil then
  15.                llRI = 0
  16.             end
  17.             llRI = (llRI % 8) + 1
  18.             if GetRaidTargetIndex("mouseover") ~= llRI then
  19.                SetRaidTarget("mouseover", llRI)
  20.                PlaySound(SOUNDKIT.GM_CHAT_WARNING)
  21.             end
  22.          end
  23.       end
  24.    end
  25. end
  26.  
  27. local f = CreateFrame("Frame")
  28. f:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
  29. f:SetScript("OnEvent",OnEvent)
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
03-25-24, 10:04 PM   #13
Hubb777
A Flamescale Wyrmkin
 
Hubb777's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2024
Posts: 112
Thank you very much, I will test this code today.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » tag on target by ID


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off