target.HP fails?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
dr-nuker
Posts: 145
Joined: Sun Oct 09, 2011 7:33 am

target.HP fails?

#1 Post by dr-nuker » Wed Oct 17, 2012 5:21 pm

hello there!

Since you`ve been helping me last time so nicely I kindly ask for some more advice...

Here is my problem:

I made a waypoint to farm an instance`s first boss. It`s nasty and the code is ugly but it gets the job done.

But when it comes to bossfight it messes around. So here is what i do:

Code: Select all

	<!-- # 11 --><waypoint x="-128" z="-1009" y="1254">	
yrest(500)
	player:findTarget(targetname);
	local target = player:getTarget();

    if target and target.Name == targetname then

repeat
	player:cast("MAGE_FLAME");
	player:cast("MAGE_FIREBALL");
	yrest(500)
	player:cast("PRIEST_RISING_TIDE");
until 1 > target.HP 

else
__WPL:setDirection(WPT_BACKWARD);
	end
</waypoint> 
So i thought the bot should find the boss and shoot in a loop until the evil thingy dies... but it gets stuck in an endless loop trying to shot. SO the boss dies but then i`m stuck on burning a dead body...

What do i do wrong? How can i leave the loop and go on with looting?

Thanks in advance!

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: target.HP fails?

#2 Post by BillDoorNZ » Wed Oct 17, 2012 5:49 pm

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.

BillDoorNZ
Posts: 446
Joined: Wed Aug 03, 2011 7:37 pm

Re: target.HP fails?

#3 Post by BillDoorNZ » Wed Oct 17, 2012 5:53 pm

the main reason I used the while loop, is that it gets rid of the:

Code: Select all

	if target and target.Name == targetname then
line (and the corresponding end), thus reducing your linecount by 1 ;)

it also ensure that all of those checks occur every time :)

In your version, it would only ever check to see if the target existed the first time and then it assumes the target always exists.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 38 guests