Jump to content

Recommended Posts

I'm trying to get the UnitID from my UnitObject to get the threat

public static int GetThreat(WoWUnit target)
{
	return Lua.LuaDoString<int>($"local _, _, threatpct, _, _ = UnitDetailedThreatSituation(\"player\", \"{target.Guid}\"); return threatpct;");
}

Hope someone can give me a clue what Guid means and BaseAddress.

Hello, sorry you cannot get Lua UnitId from WRobot WowObject.

I have found this UnitID:

none
player
pet
vehicle
target
focus
questnpc
mouseover
raid1
raid2
raid3
raid4
raid5
raid6
raid7
raid8
raid9
raid10
raid11
raid12
raid13
raid14
raid15
raid16
raid17
raid18
raid19
raid20
raid21
raid22
raid23
raid24
raid25
raid26
raid27
raid28
raid29
raid30
raid31
raid32
raid33
raid34
raid35
raid36
raid37
raid38
raid39
raid40
raidpet1
raidpet2
raidpet3
raidpet4
raidpet5
raidpet6
raidpet7
raidpet8
raidpet9
raidpet10
raidpet11
raidpet12
raidpet13
raidpet14
raidpet15
raidpet16
raidpet17
raidpet18
raidpet19
raidpet20
raidpet21
raidpet22
raidpet23
raidpet24
raidpet25
raidpet26
raidpet27
raidpet28
raidpet29
raidpet30
raidpet31
raidpet32
raidpet33
raidpet34
raidpet35
raidpet36
raidpet37
raidpet38
raidpet39
raidpet40
party1
party2
party3
party4
partypet1
partypet2
partypet3
partypet4
nameplate1
nameplate2
nameplate3
nameplate4
nameplate5
nameplate6
nameplate7
nameplate8
nameplate9
nameplate10
nameplate11
nameplate12
nameplate13
nameplate14
nameplate15
nameplate16
nameplate17
nameplate18
nameplate19
nameplate20
nameplate21
nameplate22
nameplate23
nameplate24
nameplate25
nameplate26
nameplate27
nameplate28
nameplate29
nameplate30
nameplate31
nameplate32
nameplate33
nameplate34
nameplate35
nameplate36
nameplate37
nameplate38
nameplate39
nameplate40
boss1
boss2
boss3
boss4
boss5
arena1
arena2
arena3
arena4
arena5
arenapet1
arenapet2
arenapet3
arenapet4
arenapet5
npc
spectateda1
spectateda2
spectateda3
spectateda4
spectateda5
spectateda6
spectateda7
spectateda8
spectateda9
spectateda10
spectateda11
spectateda12
spectateda13
spectateda14
spectateda15
spectatedb1
spectatedb2
spectatedb3
spectatedb4
spectatedb5
spectatedb6
spectatedb7
spectatedb8
spectatedb9
spectatedb10
spectatedb11
spectatedb12
spectatedb13
spectatedb14
spectatedb15
spectatedpeta1
spectatedpeta2
spectatedpeta3
spectatedpeta4
spectatedpeta5
spectatedpeta6
spectatedpeta7
spectatedpeta8
spectatedpeta9
spectatedpeta10
spectatedpeta11
spectatedpeta12
spectatedpeta13
spectatedpeta14
spectatedpeta15
spectatedpetb1
spectatedpetb2
spectatedpetb3
spectatedpetb4
spectatedpetb5
spectatedpetb6
spectatedpetb7
spectatedpetb8
spectatedpetb9
spectatedpetb10
spectatedpetb11
spectatedpetb12
spectatedpetb13
spectatedpetb14
spectatedpetb15
commentator

but you cannot found all mobs with this.

 

You can try to bypass problem with this code (not tested):

    public static int GetThreat(WoWUnit target)
    {
        int threatpct = 0;
        string luaCode = "local _, _, threatpct, _, _ = UnitDetailedThreatSituation('player', 'target'); return threatpct;";
        try
        {
            if (!target.IsValid)
                return 0;

            if (target.IsMyTarget)
            {
                threatpct = Lua.LuaDoString<int>(luaCode);
            }
            else
            {
                var currentTarget = ObjectManager.Target.GetBaseAddress;
                Memory.WowMemory.LockFrame();
                Interact.InteractGameObject(target.GetBaseAddress, !ObjectManager.Me.GetMove);
                threatpct = Lua.LuaDoString<int>(luaCode);
                if (currentTarget > 0)
                    Interact.InteractGameObject(currentTarget);
                else
                    Lua.LuaDoString("ClearTarget();");
            }

        }
        catch { }
        finally
        {
            Memory.WowMemory.UnlockFrame();
        }
        return threatpct;
    }

 

Wait next WRobot update and use this code:

    public static int GetThreat(WoWUnit target)
    {
        int threatpct = 0;
        string luaCode = "local _, _, threatpct = UnitDetailedThreatSituation('player', 'focus'); return threatpct;";
        try
        {
            if (!target.IsValid)
                return threatpct;

            if (target.IsMyTarget)
            {
                threatpct = Lua.LuaDoString<int>(luaCode.Replace("'focus'", "'target'"));
            }
            else if (target.Guid == ObjectManager.Me.FocusGuid)
            {
                threatpct = Lua.LuaDoString<int>(luaCode);
            }
            else
            {
                var currentFocus = ObjectManager.Me.FocusGuid;
                ObjectManager.Me.FocusGuid = target.Guid;
                threatpct = Lua.LuaDoString<int>(luaCode);
                ObjectManager.Me.FocusGuid = currentFocus;
            }

        }
        catch { }
        return threatpct;
    }

(this code not freeze wow)

This will be my first try ;) if someone has another idea just let me know

GetUnits(int range) is a method that returns a list of all mobs around you.


The goal is to check those mobs if we own 100% threat and if not we will interact with them if we still don't have them in the target.

        /// <summary>
        /// Switch to the target with the lowest threat
        /// </summary>
        /// <param name="range">The range we want to search for</param>
        public static void SwitchTargetByThread(int range)
        {
            Dictionary<WoWUnit, int> targets = GetUnits(range).ToDictionary(t => t, t => GetThreat(t));
            targets.OrderBy(t => t.Value);

            // Skip?
            if (targets.All(t => t.Value == 100))
            {
                return;
            }

            // Get target with the lowest threat
            KeyValuePair<WoWUnit, int> target = targets.FirstOrDefault();

            // Any target and is not our current target?
            if (target.Key != null && !target.Key.IsMyTarget)
            {
                Logging.WriteDebug($"Switching target: {target.Value}% threat.");

                // Target the mob
                Interact.InteractGameObject(target.Key.GetBaseAddress, !ObjectManager.Me.GetMove);
            }
        }

        /// <summary>
        /// Switch to the target with the lowest threat
        /// </summary>
        /// <param name="range">The range we want to search for</param>
        public static void SwitchTargetByThread(int range)
        {
            Dictionary<WoWUnit, int> targets = GetUnits(range).ToDictionary(t => t, t => GetThreat(t));
            targets.OrderBy(t => t.Value);

            // Skip?
            if (targets.All(t => t.Value == 100))
            {
                return;
            }

            // Get target with the lowest threat
            KeyValuePair<WoWUnit, int> target = targets.FirstOrDefault();

            // Any target and is not our current target?
            if (target.Key != null && !target.Key.IsMyTarget)
            {
                Logging.WriteDebug($"Switching target: {target.Value}% threat.");

                // Validate target
                if (target.Key.IsValid && !target.Key.IsDead)
                {
                    // Target the mob
                    Interact.InteractGameObject(target.Key.GetBaseAddress, !ObjectManager.Me.GetMove);
                }
            }
        }

 

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...