Jump to content

Issue with "Can cure Debuff" function always returning false


Evaexe

Recommended Posts

 

Hello Wrobot community,

I'm having an issue with the CanPurify function in my code, and I was hoping someone could help me figure out what's going on. Currently, no matter what, the function always returns false, even when the player has a debuff that should be able to be purified.

Here is the current code for the function:

    public bool CanPurify(string playerName)
    {
        var lua = $@"
    canPurify = false
    for i = 1, 40 do
        local name, _, _, debuffAuraType, _, _, _, _, _ = UnitDebuff(""{playerName}"", i);
        if (name and debuffAuraType) and (debuffAuraType == 'Magic' or debuffAuraType == 'Disease' or debuffAuraType == 'Poison') then
            canPurify = true
            break
        end
    end
    return canPurify
";
        Logging.Write($"Checking if {playerName} can be purified...");
        bool result = Lua.LuaDoString<bool>(lua);
        Logging.Write($"Result: {result}");
        return result;

 

If anyone has any idea what might be causing this issue, or any suggestions for how I can fix it, I would really appreciate it. Thank you in advance for your help!

Best regards,

Link to comment
Share on other sites

Hello,

In "playerName" argument you should pass arguments like "player", "target", "focus", "party1", "raid1" (if you pass real player/unit name that will no work).

Your code should look like that if you want to use playerName (not tested) :

    public bool CanPurify(string playerName)
    {
        var units = ObjectManager.GetObjectWoWUnit();
        units.AddRange(ObjectManager.GetObjectWoWPlayer());

        var unitsByName = ObjectManager.GetWoWUnitByName(units, playerName);

        return CanPurify(unitsByName.FirstOrDefault());
    }
    public bool CanPurify(WoWUnit wowUnit)
    {
        if (wowUnit == null || !wowUnit.IsValid)
            return false;

        string unit;
        long currentFocus;
        if (wowUnit.IsLocalPlayer)
            unit = "player";
        else if (wowUnit.IsMyTarget)
            unit = "target";
        else
        {
            currentFocus = ObjectManager.Me.FocusGuid;
            ObjectManager.Me.FocusGuid = wowUnit.Guid;
            unit = "focus";
        }

        var lua = $@"
    canPurify = false
    for i = 1, 40 do
        local name, _, _, debuffAuraType, _, _, _, _, _ = UnitDebuff(""{unit}"", i);
        if (name and debuffAuraType) and (debuffAuraType == 'Magic' or debuffAuraType == 'Disease' or debuffAuraType == 'Poison') then
            canPurify = true
            break
        end
    end
    return canPurify
";

        if (unit == "focus")
            ObjectManager.Me.FocusGuid = currentFocus;

        Logging.Write($"Checking if {wowUnit} can be purified...");
        bool result = Lua.LuaDoString<bool>(lua);
        Logging.Write($"Result: {result}");
        return result;
    }

 

Link to comment
Share on other sites

Thank you very much! I will try your code later.

Regarding your code, my fightclass already has a priority list established based on the people in my party or raid. So, I will not use the first part of your code, as I understand it is trying to find a wowUnit to dispel.

Instead, I will pass a Wowunit player to the second function, rather than just the pseudo.

Thanks!

Link to comment
Share on other sites

Hello Droidz,

Unfortunately, the code is not working. I am playing on WoW 3.3.5a.

At the moment, I have added some print statements:

 
csharp
 
var lua = $@" canPurify = false for i = 1, 40 do local name, _, _, debuffAuraType, _, _, _, _, _ = UnitDebuff(""{unit}"", i); print(""{unit}"") print(name) print(debuffAuraType) if (name and debuffAuraType) and (debuffAuraType == 'Magic' or debuffAuraType == 'Disease' or debuffAuraType == 'Poison') then canPurify = true break end end return canPurify ";

 

Here is the output:

image.png.905de3bd6c53cec0b4d01e1e2a1d6cdf.png

Thank you.

 
Link to comment
Share on other sites

I would like to thank the Wholsome Discord for their help. It turns out that my debuffAuraType was in the third position, when it should have been in the fourth position in UnitDebuff.

Here is the modified code:

 

public bool CanPurify(string playerName)
{
    var lua = $@"
canPurify = false
for i = 1, 40 do
    local name, _, _, _, debuffAuraType, _, _, _, _ = UnitDebuff(""{playerName}"", i);
    print(""{playerName}"")
    print(name)
    print(debuffAuraType)
    if (name and debuffAuraType) and (debuffAuraType == 'Magic' or debuffAuraType == 'Disease' or debuffAuraType == 'Poison') then
        canPurify = true
        break
    end
end
return canPurify
";
    Logging.Write($"Checking if {playerName} can be purified...");
    bool result = Lua.LuaDoString<bool>(lua);
    Logging.Write($"Result: {result}");
    return result;
}

public void Purify(WoWUnit p)
{
    while (CanPurify(p.Name) && CastHeal(Cleanse, p, 100))
    {
        SpellManager.CastSpellByNameOn("Holy Light", p.Name);
    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...