PDA

View Full Version : Checking if a NPC is in combat?



Tog
11-30-2015, 10:57 AM
Hello, I have almost finished completed my first script!

Most of the major parts of the script are completed, but now I just want to make it a bit more polished :)

My current problem is that my bot tries to attack NPC's that are already fighting other players (This makes the bot obvious as all heck!) Is there a way to check if a NPC is in combat so I may avoid clicking that NPC?

Here is my current combat 'attacking' script (Code from the Reflection tutorial)



procedure AttackEnemy;
var
Guard: TReflectNpc;
Point: TPoint;
begin

if not isHealthy() then exit;

while not MyPlayer.IsUnderAttack do
begin
writeln('looking for Guard');
if Guard.Find('Guard') then
begin



writeln('Found guard! Clicking!');
Point := Guard.GetMsPoint;
Reflect.Mouse.Move(Point, 2, 2);
Reflect.Mouse.Click(MOUSE_LEFT);
wait(RandomRange(1000,2000));

While MyPlayer.IsMoving do
Wait(randomRange(300,600));
end;
end;
end;


Is what I'm asking possible? Would it be along the lines of using:
Guard.GetAnimation or Guard.GetCombatCycle?

Another method I've thought of would be to check the chatbox for 'that x is already under attack', but then how would I go about clicking a different guard? Is there a way to chose a particular guard to attack using Guard.Find('Guard')? Or is it just random?


Thanks for the help,
Tog.

Roflme
11-30-2015, 01:40 PM
function AttackEnemy: Boolean;
var
Guard: TReflectNpcArray;
Point: TPoint;
i: Integer;
begin
result := false;
if not isHealthy() then exit;

while not MyPlayer.IsUnderAttack do
begin
writeln('looking for Guard');
Guard.Get('Guard');
if length(Guard) > 0 then
begin
for i := 0 to high(Guard) do
begin
if not Guard[i].isUnderAttack then
begin
writeln('Found a free guard, attacking');
Point := Guard.GetMsPoint;
Reflect.Mouse.Move(Point, 2, 2);
Reflect.Mouse.Click(MOUSE_LEFT);
wait(RandomRange(1000,2000));
While MyPlayer.IsMoving do
Wait(randomRange(300,600));
if MyPlayer.isUnderAttack then
begin
result := True;
Exit;
end;
end;
end;
end;
end;


Could try that? Get an array of Guards instead and have it find one that isn't under attack. I like using functions for this to incorporate into other procedures/functions but you can change it back to a procedure if you want.