1. #1

    WeakAura for tracking distance to target

    Hello, I´m working on WeakAura which will show me if I´m in range with another player. I know that since 7.1 UnitDistanceSquared() doesnt work in party, so I tried IsItemInRange() and that one doesnt work for friendly units (even with "focus" unit). Is there any way to see range? Because DBM Radar still shows people in certain range.

    Update:
    UnitPosition() function for target doesn't work either. Even in a questing zone.

    Code:
    function()
        local playerX, playerY = UnitPosition("player")
        local targetX, targetY = UnitPosition("target")
        return string.format("x_coord(player): %d\ny_coord(player): %d\nx_coord(target): %d\ny_coord(target): %d",
        playerX, playerY, targetX, targetY)
    end
    Last edited by Draculla; 2017-12-18 at 12:27 PM.

  2. #2

  3. #3
    This doesnt work with friendly units. It returns empty result instead of boolean

  4. #4
    Code:
    function ComputeDistance(unit1, unit2)
      local y1, x1, _, instance1 = UnitPosition(unit1)
      local y2, x2, _, instance2 = UnitPosition(unit2)
      return instance1 == instance2 and ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
    end
    You can try http://wowwiki.wikia.com/wiki/API_CheckInteractDistance or https://wow.gamepedia.com/API_UnitDistanceSquared (need calculating in this case) OR you need to figure out which items work on friendly targets

  5. #5
    Quote Originally Posted by Draculla View Post
    This doesnt work with friendly units. It returns empty result instead of boolean
    Position API does not work in instances. As the above reply states, you need to work out a complicated mess of friendly spells to check with friendly targets to get an estimated range.
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  6. #6
    Taking a guess but if this is for tanks range check on Varimathras you can try this: https://wago.io/By43UqZWz

    Gershuun @ Borean Tundra US - Interface & Macros Moderator

  7. #7
    Quote Originally Posted by Kanegasi View Post
    Position API does not work in instances. As the above reply states, you need to work out a complicated mess of friendly spells to check with friendly targets to get an estimated range.
    Problem is that UnitPosition() doesnt work in normal zones. I was in Stormheim and I targeted enemy target and it says x = 0 y = 0. Only player coords changed while i moved.

  8. #8
    isn't /range X sufficient for your purposes?

  9. #9
    UnitPosition() works only for friendly group members. You can't just raget NPC and get its position
    unit
    String - The unitId for which the position is returned. Does not work with all unit types. Works with "player", "partyN" or "raidN" as unit type. In particular, it does not work on pets or any unit not in your group.

  10. #10
    Quote Originally Posted by zox2 View Post
    isn't /range X sufficient for your purposes?
    I´m working on WA, which will show text if player is in a radius of raid member with Soulburst on Argus.

  11. #11

  12. #12
    Ok, my WA works. I have one question. Is there global variable in weakaura? I need to save string in custom function in Display and use it in "Action" section to send it to chat. Because Display has refresh rate every frame after WA is triggered so it spams chat if SendChatMessage() function is used. Custom function returns string and its text on a screen, but i need to return similar string with different data in it to chat - For example "Player with name " .. GetUnitName("raid".. i) .. " is in my range!"
    Last edited by Draculla; 2017-12-18 at 08:10 PM.

  13. #13
    aura_env.something

  14. #14
    Field Marshal
    10+ Year Old Account
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    64
    https://wago.io/rJ1yPhUGM


    not my work but it works

  15. #15

    Range Check Group Members...

    Since the return of group auras in BfA, I wanted to see if someone in the group was missing my buff...

    While tinkering with the UnitPosition code above (in the WeakAura2 addon), things appeared to be working, and then I entered a raid group - the code started generating errors.

    Reading up on this, Blizzard prevented UnitPosition from working in "competitive content" in 7.1 - or something along those lines. As such, I had to go another route...

    Now personally, I only care about living units that are 1) in range and 2) missing the aura that I am able to apply to them; thus, I came up with the following Custom Trigger:

    Code:
    function()
        -- cycle through group members
        for unit in WA_IterateGroupMembers() do
            -- check if unit exists and is not dead
            if UnitExists(unit) and not UnitIsDead(unit) then
                -- check if unit is in range of spell
                if IsSpellInRange("your_spell_name", unit) then
                    -- check to see if the unit has the aura already
                    local spellID = select(10, AuraUtil.FindAuraByName("your_spell_name", unit)) 
                    if spellID == nil then --unit does not have the buff
                        -- let me know by displaying this weakaura (return true) 
                        return true
                    end
                end
            end
        end
    end
    For the most part, this trigger works well. The only issue I'm having now is whether the unit is in my Line of Sight (LoS).
    If anybody has a suggestion for checking LoS, I'm all ears.

    Cheers!

  16. #16
    The AuraUtil is slower than you just Interating Buffs with UnitBuff. You can't check LoS without attempting to cast a spell on that player and checking the error message it generates. All that said, there are ones already on wago that have done all the work for you and found the best events for it to run on

    Edit; UnitPosition can still be used to get the InstanceID to ensure players are in the same instance
    Last edited by Rehok; 2019-01-16 at 11:24 AM.

  17. #17
    Thank you for replying. Given what I am trying to accomplish, checking LoS might be overkill then - so I won't bother. As for finding the efficiency comparison info between a UnitBuff loop and AuraUtil - I could not. So for now I'm still using AuraUtil; but I am definitely interested in seeing those results. If you could point me in that general direction, that'd be great!

    As for comparing unit instance info, that's a good idea! As such, I have updated my code to look like this:


    Code:
    function()
        -- cycle through group members
        for unit in WA_IterateGroupMembers() do
            -- check if unit exists and is not dead
            if UnitExists(unit) and not UnitIsDead(unit) then
                -- determine player and unit instanceID
                local playerInstance = select(4, UnitPosition("player"))
                local unitInstance = select(4, UnitPosition(unit))
                -- determine if unit and player are in the same instance
                if unitInstance == playerInstance then
                    -- check if unit is in range of spell
                    if IsSpellInRange("Power Word: Fortitude", unit) then
                        -- check to see if unit has the aura from the spell
                        local spellID = select(10, AuraUtil.FindAuraByName("Power Word: Fortitude", unit))
                        -- if unit does not have the buff, display this weakaura (return true)
                        if spellID == nil then
                            return true
                        end
                    end
                end
            end
        end
    end

  18. #18
    There's a pin about it in the WeakAuras Discord in the wa-discussion channel. Don't think the actual speed result is in a public channel. You can just use WA_GetUnitBuff which works as the old api did but its doing the loop for you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •