WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Access protected functions? TargetUnit? (https://www.wowinterface.com/forums/showthread.php?t=57028)

wille480 02-24-19 05:46 PM

Access protected functions? TargetUnit?
 
How would i go about targeting a UnitId through a frame? Since the TargetUnit function from the wow api is protected. i have no work around through this. I tried to do a cheeky print("/target ".. UnitName("whatever")) but that did not work. Is there anything i have to do to unlock the protected function? or is there no way around this?

Kanegasi 02-24-19 06:38 PM

You cannot target anything using an addon. You have to click, manually type /target, or use /target in a macro you click. There is no way around this. If you find a way, it'll be fixed pretty fast.

wille480 02-24-19 06:48 PM

Quote:

Originally Posted by Kanegasi (Post 331583)
You cannot target anything using an addon. You have to click, manually type /target, or use /target in a macro you click. There is no way around this. If you find a way, it'll be fixed pretty fast.

Wow really? So i have to give up on my frame addon? :O
How do the people that writes elvUI or similar addons do it? with their frames?

Fizzlemizz 02-24-19 07:58 PM

It would be best if you actually describe what you are trying to do or what effect it is you see in ElvUI that you are trying to duplicate. As far as I know ElvUI doesn't have Target("Phred") function.

elcius 02-24-19 08:11 PM

you need to create your frame as a secure action button, and then bind it with either the "target" or "macro" actions.

https://wow.gamepedia.com/SecureActionButtonTemplate

wille480 02-25-19 12:14 AM

Quote:

Originally Posted by Fizzlemizz (Post 331585)
It would be best if you actually describe what you are trying to do or what effect it is you see in ElvUI that you are trying to duplicate. As far as I know ElvUI doesn't have Target("Phred") function.

I making sort of a group box window where members in a raid will lie inside as frames (buttons). When clicking on a frame, i am retreiving the GetName() function from the frame and then proceed to call that name ingame as a target. But since TargetUnit is peotected, i am not able to target this player in game. What could i do? Kind regards

wille480 02-25-19 12:16 AM

Quote:

Originally Posted by elcius (Post 331586)
you need to create your frame as a secure action button, and then bind it with either the "target" or "macro" actions.

https://wow.gamepedia.com/SecureActionButtonTemplate

That was something i was looking for! Appriciate it

Fizzlemizz 02-25-19 11:19 AM

This is done by the game where each of your "sub-frame" unit buttons is created by inheriting from the SecureUnitButtonTemplate. Once you've done that, when you click on a unit, the game will make it your target.

The basics of creating a unit button is:

Lua Code:
  1. --Create the unit button:
  2. local f = CreateFrame("Button", "wille480PlayerFrame", UIParent, "SecureUnitButtonTemplate")
  3.  
  4. -- Tell it which unit to represent (in this case "player":
  5. f:SetAttribute("unit", "player")
  6.  
  7. -- Tell the game to "look after it"
  8. RegisterUnitWatch(f)
  9.  
  10. -- Tell it to show the unit's vehicle when the unit is in one:
  11. f:SetAttribute("toggleForVehicle", true)
  12.  
  13. -- Give it the standard click actions:
  14. f:RegisterForClicks("AnyUp")
  15. f:SetAttribute("*type1", "target") -- Target unit on left click
  16. f:SetAttribute("*type2", "togglemenu") -- Toggle units menu on left click
  17. f:SetAttribute("*type3", "assist") -- On middle click, target the target of the clicked unit
  18.  
  19. -- Make it visible for testing purposes:
  20. f:SetPoint("CENTER")
  21. f:SetSize(100, 100)
  22. f:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8" })
  23. f:SetBackdropColor(0.3, 0.3, 0.3, 0.6)
  24.  
  25. -- Then add other objects (such as font strings and status bars), register events (such as UNIT_HEALTH), and add scripts to update the objects in response to the events.

Obviously it needs other "plumbing like health/power bars/texts etc. but that is all up to you as to what you add/leave out from each unit.

If you are looking for a simple (as can be) example of putting this together into a raid frame type configuration using secure group templates , take a loot at ShotGlass

Seerah 02-25-19 01:04 PM

If all you would like to accomplish is your own custom layout of unit frames, you can use the oUF framework rather than starting from scratch.


All times are GMT -6. The time now is 08:31 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI