Thread Tools Display Modes
10-30-18, 03:49 PM   #1
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
Get UnitId of UnitIds target

Hello,

I am developing my own addon and I came to a place where I encountered the following problem:

1. I have NPC's UnitID
2. I want to compare that UnitIDs TARGET with player for example.
3. if UnitIsUnit(unitID-target, "player") then doesn't work unfortunately (I've tried all combinations of that).

Is there any way to achieve that?

Seems like there's no way to compare UnitID variable with some selector ("target", "player" etc). Am I right?

Thanks

Last edited by vectros : 10-31-18 at 12:10 AM.
  Reply With Quote
10-30-18, 03:54 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Every unit has a unique GUID. If you have a valid unitid you can query it.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-30-18, 04:46 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
You've tried all the combinations you thought of, but did you try
Code:
if UnitIsUnit("targettarget", "player" then
    -- do stuff
end
  Reply With Quote
10-31-18, 12:16 AM   #4
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
Thank you for your replies.

1. I do have valid stored in a variable: UID. I can see it, because with message(UID) it's displayed on my screen.

2. I did think about that and it works indeed. However that works only with my target. I would like to check if every UID stored is targeting me.

I think I need a method that allows to compare variables.

local player = UnitGUID("player") -- this is my GUID
local UID = ("unitData.name) -- this is variable stored in array for multiple creatures. I would need to get it's target somehow and compare it with my GUID.

The problem is:

How do I get UID's target?
If I have UID's target, how do I compare 2 variables?
  Reply With Quote
10-31-18, 01:38 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
You can't know if all enemies are targeting you. Only those with a valid unitid. That means you iterate over your group, over their targets and then their targets. Only those unitids are valid and can be checked. If nobody you know targets a unit you can't know it's target.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-31-18, 02:06 AM   #6
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
So let's say I have an array of various valid unitdIDs that are are not in my group, neither I target them and mousover them (I have not connection with them besides them being on the same server).

This means that I will not be able to check what's their target right?

That implicates that I will not be able to create my addon
  Reply With Quote
10-31-18, 02:14 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Yes, unfortunately, what you are asking is likely to be impossible within wow's allowed functionality. Addons can make suggestions and tell you what to do but only based on what information is available. So unit wise is raidx, player, partyx, target, pet, focus, mouseover and their equivalent targets. So your addon would have to assume your player is at lease monitoring the potential attackers in the area ( I know I do ) and would then allow them to either simply mouseover them one by one or target them, and on the indirect scenario of being in a group of some sort or having a pet then you can do similar tests that way.
__________________

Last edited by Xrystal : 10-31-18 at 02:20 AM.
  Reply With Quote
10-31-18, 02:22 AM   #8
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
Thanks for your help again.

I think mouseovertarget will partially solve my problem.

I will now have two variables:

UnitIDsTarget = ("mouseovertarget")
local player = UnitGUID("player")

is there a function that allows to compare variables not selectors?

Something like: UnitIsUnit(UnitIDsTarget, player). Because errors I've been getting with this make me think that this function is only for selectors.
  Reply With Quote
10-31-18, 03:07 AM   #9
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Keep in mind that there is no valid unitid for targets in a storage. The moment the unit that targets it changes its target the same unitid means another unit.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-31-18, 03:36 AM   #10
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
Sure. However I have an object, which one of it's property will be UnitIDsTarget

It will be

NPCData.UnitIDsTarget

and it will be saved in array. So I will have multiple UnitIDs. But the problem stays the same:

Which function should I check if two variables are the same.

UnitIsUnit(variable1, variable2).

Last edited by vectros : 10-31-18 at 05:44 AM.
  Reply With Quote
10-31-18, 08:50 AM   #11
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Only the GUID can handle this when there are units without a valid unitid.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-31-18, 05:20 PM   #12
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
For the sake of clarity, the term unitID specifically refers to unit tokens like target, mouseover, and player, and these are used by the various Unit functions to get information about them.

OP keeps using the term to refer to something that is not a unitID, and it's unclear what they do have and what exactly they're trying to do with it.

There are many ways to get information about what's targeting you, but how you do it depends on what you need it for. Are they players or npcs, are they in the open world or in a battleground, do they have nameplates, etc.

This is also almost the exact same question that was asked a week ago by someone trying to make a nameplate addon for a private server.

If you are the same person let me save you some time. Burning Crusade came out 10 years ago. The API has undergone drastic changes since then; nobody here can help you develop an addon for an outdated version of the game simply because the differences between the codebases are too great.

Last edited by semlar : 10-31-18 at 07:30 PM.
  Reply With Quote
11-01-18, 01:57 AM   #13
vectros
A Murloc Raider
Join Date: Oct 2018
Posts: 6
Hi,

Thank you for your replies.

If there's no way to compare variables like these tokens it means that I will not be able to develop the addon indeed.

I really appreciate your time.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get UnitId of UnitIds target

Thread Tools
Display Modes

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