Hi
can someone give me a hint how to get all the players that are attacking me when I am in combat? I think there might be something in the objects descriptors, maybe a field like current target?
Hi
can someone give me a hint how to get all the players that are attacking me when I am in combat? I think there might be something in the objects descriptors, maybe a field like current target?
References to GetThreatSituation are scattered all over the forum, as well as GetUnitReaction.Code:public IEnumerable<IWoWUnit> Attackers { get { if (!_objectManager.Me.IsInCombat) return new IWoWUnit[0]; return _objectManager.Objects.OfType<IWoWUnit>() .Where(u => !u.IsMe && !u.IsDead && _objectManager.Me.GetUnitReaction(u) < WoWUnitReaction.Friendly && WantsToHarm(u) && _objectManager.Me.IsInLineOfSight(u)); } } private bool WantsToHarm(IWoWUnit u) { return (u.TargetGuid == _objectManager.Me.Guid || u.GetThreatSituation(_objectManager.Me).ThreatStatus > WoWThreatStatus.NoThreatRelation); }
Note that this is not exhaustive, iirc if you aggro another unit by pulling your current target through a mob group, that new unit will not have threat with you until it hits you the first time.
Thanks,
for the snippet. Im doing it like you do now. Though I realized that:
- Enumerate WoWObjects
-Check TargetGuid = PlayerGUID
is way easier? LOL
btw, for interested readers:
Code:// returns 1, 2, 3 = hamrful // 4, 5, 6, 7 = no harm typedef __int32 (__thiscall* GetUnitReaction_t)(__int32* TargetObj, __int32* DestObj); // returns ThreatLevel, 0 = no threat, 1 = main threat? // usage: ObjectGUID = PlayerGUID, pWoWObject to get threat to. typedef __int32 (__thiscall* GetThreat_t)(__int32* pWoWObject, __int64* ObjectGUID, __int32* unknown1, __int32 zero1, __int32 zero2, __int32 zero3);
Last edited by kingdeking; 08-09-2012 at 10:54 AM.
Hey,
one more question: How can I set my current target? I tried writing the GUID to the PlayerObjects current TargetGUID field, but nothing really happens.
edit: Okay dumb question, i forgot that i have UseAction Lol
Last edited by kingdeking; 08-09-2012 at 01:49 PM.
To target something, I use the Target Last Target GUID. I just write the Unit GUID there and send the Target Last Target Key. Without sending a key, it won't target anything... More or less like this:
But I'm pretty sure there are easier ways out thereCode:WriteProcessMemory(Handle, reinterpret_cast<void*>(reinterpret_cast<unsigned int>(module.modBaseAddr) + LastTargetGUID), &target, sizeof(target), NULL); sendKey(hwnd, lasttarkey);
I'm currently seeking to improve Combat in my bot... Not the AI itself but to detect which mobs are attacking you and which should be looted after combat is done. Right now, for example, while farming fishing pools, if the bot enters in combat, it won't do anything until a certain "timer" or a number of fishing attempts is reached... after that, the bot loops and theeen detects there's something in his "CurrentTargetGUID", therefore, indicating something is attacking him.
I wonder if just scanning the memory for units targetting me should be enough to solve this "issue". But I don't know how I'm going to do to stop the "main job/task", to then kill a certain mob and return back to where it was and finish what he was doing...
That sounds completely ass-backwards, do you even have a proper logic system in place?
You should always prioritize combat over fishing the pool; the fishing pool will remain there, but chances are, you won't. I would suggest looking up behaviour trees or even (finite) state machines and implementing either before you attempt to even update your combat; you're going to need proper logic before then.
Oh and regarding the targeting; I'd prefer a function call over a plain memory write - just let the game handle it for you.
Last edited by Seifer; 08-10-2012 at 04:05 PM.
Btw, do you know a function to rotate the character? I am trying to face a mob and using ClickToMove to rotate the player is crappy.. oO
edit: ow thank god, click to move doesnt have a min range on attacking mobs^^
Last edited by kingdeking; 08-10-2012 at 04:30 PM.
If you pass 0x2 as the CTM action, you can rotate without moving.
Also, for your earlier question, if you look at the xrefs for CGGameUI::Target, you'll find:
Which tells us that CGGameUI::Target takes the GUID of the target we're after as its sole argument, should be easy to figure how to apply that to your project.Code:.text:008D7B8C 50 push eax .text:008D7B8D 51 push ecx .text:008D7B8E E8 AD E6 FF FF call CGGameUI__Target
Last edited by Seifer; 08-10-2012 at 05:06 PM.
Are you serious? I remember trying that and I'm not exactly sure what happened, but I think it just changed the camera's view or something... I gotta test it out again. I'm really looking for a better way to implement rotation because mine is just a huge function that does tons of calculation with atan2() and spams the rotatekey until my character's rot is close to the one I want...
Regarding prioritizing combat... I do it in my code by checking every time if there's something in the CurrentTargetGUID. If there's, then go ahead and kill whatever is attacking you. If there isn't, then proceed to fishing the fishing pool. And here is the problem, because while fishing, the bot can enter in combat, for example, if a mob passes near. If that happens, the bot will try to fish for a couple attempts and then if he can't, he will just leave that loop and come back to the "start" where it would check if there's something in the CurrentTargetGUID. What I want would be a way to pause my fishing, kill whatever and then get back to fishing exactly where it stopped. For that, the only way I think of would be putting a detectCombat() function running in a thread and then once it detects, the bot would kill the mob and the fishing function would run again... but from the start, since I basically "killed" its thread.
Finally, I'm not that experienced with calling functions via memory... which is why I'm just dealing with reading and writingI guess I will search around for ways to do like you are saying because it seems that it will ease my work a lot.
Currently I have
Which were based on tests I did a while back (~half a year). I use 0x1 for facing a unit. 0x2 I supposed was for facing a certain position, but it always faced north upon testing.Code:public enum ClickToMoveType { FaceGuid = 0x1, // works FaceNorth = 0x2, // runs forward and faces angle too... doesn't care for guid and destination /// <summary> /// Will throw a UI error. Have not figured out how to avoid it! /// </summary> Stop_ThrowsException = 0x3, Move = 0x4, NpcInteract = 0x5, Loot = 0x6, // Does not auto-loot regardless of CVar, does not work when already in loot range ObjInteract = 0x7, FaceAngle = 0x8, // and run or sth, with facing angle as approximation Skin = 0x9, AttackPosition = 0xA, // not autorangedcombatspell, see OnClickAutomoveAndAttack AttackGuid = 0xB, // autorangedcombatspell RunAndFaceUnit = 0xC, None = 0xD, }
Thanks man, I think you solved my issue of calculating the facing. I will test this out
Use Apoc's FSM post to get started: http://www.ownedcore.com/forums/gene...your-bots.html ([Bot Developers]A simple, but effective FSM for your bots.)
Using an FSM would already be a great improvement over just using a bunch of if/else/whatever statements really, and should make your work a lot easier. On a side note, check the unit flags; it contains a flag for InCombat.