it looks like you are trying to do something like:
Code: Select all
<!-- # 11 --><waypoint x="-128" z="-1009" y="1254">
yrest(500)
local target = player:findNearestNameOrId(targetname);
while ((target) and (target.Id > 0) and (target.HP > 1)) do
player:cast("MAGE_FLAME");
player:cast("MAGE_FIREBALL");
yrest(500)
player:cast("PRIEST_RISING_TIDE");
target:update();
player:update();
end;
if (target == nil) then __WPL:setDirection(WPT_BACKWARD); end;
</waypoint>
note, I used findNearestNameOrId as this takes a name or Id argument and will find (and return) that specific entity, so the
target variable will either be
nil indicating it couldn't find the target or it will be the pawn for the target you are looking for.
I used a while loop, as the while loop checks the condition BEFORE executing its code. So, it checks to see if target is not nil (thats the (target) bit), that its Id is not 0 (this can happen if the target no longer exists) and that its HP is > 0 to ensure it is not dead. Then it runs your combat code and then does the part you were missing:
Code: Select all
target:update();
player:update();
these two lines will (1) update the target pawn with the latest details (including its HP after your attacks, otherwise from the bots point of view, the HP will never change as you never call target:update() !!! ) and (2) update the players details.
I assume that you know categorically that the character will kill the enemy every time using the combination you specify (even if it has to perform that combination multiple times). Otherwise, the danger is that the bot will never heal your character as it will be stuck in your while loop.