WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with non working unit check (https://www.wowinterface.com/forums/showthread.php?t=40449)

Sauerkraut 06-09-11 01:10 PM

Help with non working unit check
 
I don't really know how to explain this, but I am trying to fix an addon that allows either all units or a specified list of units. The all units part is working fine however when specific units are selected nothing is output to the game. There is no error it just does nothing.

From the addon

Code:

local function UnitisAllowed(unit)
        for key, val in pairs(addon.CONFIG.units) do
                if UnitIsUnit(unit, val) then return true end
        end
        return false
end

Code:

if eventType == "SPELL_AURA_APPLIED" and addon.BUFF_SPELLS[spellname] and isEnemy(destFlags) and (addon.CONFIG.allunits or UnitisAllowed(destName)) then
from the config

Code:

addon.CONFIG = {
        allunits = false,
        units = {
                "target",
                "focus",
        },
}

Am I using the correct syntax for the check? I'm just not sure why it is failing.

Lombra 06-11-11 09:43 PM

What immediately strikes me is that you're using destName in the UnitIsUnit check. I don't think that'll work unless dest is a group member.

You could try doing UnitisAllowed(destGUID)) instead, and then doing something like this instead:
Code:

local function UnitisAllowed(guid)
        for key, val in pairs(addon.CONFIG.units) do
                if UnitGUID(val) == guid then return true end
        end
        return false
end


Sauerkraut 06-12-11 07:09 AM

Thanks, I had actually already changed UnitisAllowed(destGUID) after reading through some of the wowprogramming.com documents. I'll try it out and see if it works. Thank you again.

Sauerkraut 06-15-11 03:26 PM

Sadly I still haven't been able to get this working. If anyone has any ideas they would be greatly appreciated.

Xinhuan 06-15-11 07:50 PM

UnitIsUnit only works on UnitIDs. Like UnitIsUnit("target", "focustarget"). Using guids will not work and using player names will only work if they are in your party or raid.

You should just compare their GUIDs directly instead (string compare).

Sauerkraut 06-16-11 02:39 PM

I'm sorry if these are dumb questions, I'm really trying. I'm not overly familiar with lua or any other programming language for that matter and I think I may be in over my head here.

Following (I hope) your advise I've gone to

Code:

local function UnitisAllowed(unit)
        if not addon.CONFIG.allunits then
                if UnitID == "target" or UnitID == "focus" or UnitID == "mouseover" then return true end
        end
        else
        return false
end

Code:

if eventType == "SPELL_AURA_APPLIED" and addon.BUFF_SPELLS[spellname] and isEnemy(destFlags) and (addon.CONFIG.allunits or UnitisAllowed(destID)) then
???:confused:

Sauerkraut 06-27-11 06:18 PM

Still unable to solve this. Any and all input is appreciated.

Dridzt 06-27-11 06:33 PM

There's an obvious error in the last snippet of code you posted.
The function is passed a 'unit' parameter but in the code you're checking against 'UnitID'.

Apart from that, we need more code.
Which addon is it, can you post a pastey of the full code?

Sauerkraut 06-28-11 07:49 AM

Here is the pastey

http://pastebin.com/Ez2MTqrE

I think that code was leftover from the first bit before I started trying to fix the check. I had replaced unit with guid.

suicidalkatt 06-28-11 12:01 PM

Combat log events don't use the general 'UnitID' like "target" and "focus" things like that. Instead it uses 'UnitGUID' which is a specific string of numbers that is unique to that unit.

What you would ultimately have to do is determine the UnitGUID of all the parameters in your table there, and attempt to match them with the combat log UnitGUID.

Something like this:

Code:

local function isallowedunit(guid)
        for key, val in pairs(ncSpellalertDB.CONFIG.units) do
                local currentID = UnitGUID(val)
                if guid == currentID then
                        return true
                end
        end
        return false
end


Sauerkraut 06-28-11 12:12 PM

Thank you suicidalkatt! I'll try that as soon as the servers come back up.


All times are GMT -6. The time now is 06:34 PM.

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