Page 1 of 1

Add timeout

Posted: Mon Oct 17, 2011 1:41 pm
by ichmagbotsyay
Hi,
my cyclops bot doesn't actually target enemies, it attacks them using the following command:

Code: Select all

	player:cast("MAGE_PURGATORY_FIRE");
	repeat
		if 12000 > player.HP and not player:hasBuff("500469") then
			player:cast("PRIEST_REGENERATE");
		end;
		if 6000 > player.HP then
			player:cast("PRIEST_URGENT_HEAL");
		end;
		player:cast("MAGE_PURGATORY_FIRE");
	until not player.Battling;
	yrest(50);
	player:lootAll();
	if inventory:itemTotalCount(0) == 0 then	
		yrest(1000);
		sendMacro("ViewDistanceSlider_SetValue(400)");
		sendMacro("LeaveParty()");
		waitForLoadingScreen();
		yrest(3000);
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Zumhaendler"));
	end
Obviously that code is packed into an userfunction so it doesn't cram the waypoint file. Now what sometimes happens is that the bot lags for a second (because I'm running several clients) and accidentally walks too far. Then the enemies go into the wall and are invincible. Then the bot just stucks there, continuously casting purgatory fire and sometimes healing himself. Sometimes, when I'm lucky, it runs out of mana and can't heal itself and dies, but sometimes it stucks there for hours.

So here's my question:
How do I add a timeout into that function? I want the bot to try for a while, but stop and go to the next waypoint after a couple of minutes.
Any ideas?

Re: Add timeout

Posted: Mon Oct 17, 2011 4:41 pm
by Tooney
No idea what you are doing with your script but os.date() will give you a time value which by getting a difference would effectively give you a way of monitoring how long you did something.
If os.date() doesn't work then install the d303Fix from Curse.com

Or GetTime() will give you how many mSec it's been since the PC was switched on. Again a difference calc will tell you if you've waited too long.

Thx to Lisa for the d303Fix heads up.

Re: Add timeout

Posted: Mon Oct 17, 2011 7:16 pm
by rock5
os.date() gives a formated time that is hard to work with. You can use "getTime()" but because it's saved as a table, you would have to use the deltaTime function to get the difference eg. deltaTime(getTime(), starttime). I find it easieast to just use os.clock() which just gives you an easy to use number in seconds so.

Code: Select all

local starttime = os.clock()
before the 'repeat' loop then

Code: Select all

   until not player.Battling or (os.clock()- starttime > 15) -- No more than 15s
You could try and do what the bot would do if it was controling the fight and have it back step or something.

Re: Add timeout

Posted: Tue Oct 18, 2011 9:56 am
by ichmagbotsyay
rock5 wrote:os.date() gives a formated time that is hard to work with. You can use "getTime()" but because it's saved as a table, you would have to use the deltaTime function to get the difference eg. deltaTime(getTime(), starttime). I find it easieast to just use os.clock() which just gives you an easy to use number in seconds so.

Code: Select all

local starttime = os.clock()
before the 'repeat' loop then

Code: Select all

   until not player.Battling or (os.clock()- starttime > 15) -- No more than 15s
You could try and do what the bot would do if it was controling the fight and have it back step or something.
ok thank you
i will try this when the bot is up and running again

edit: works great, thank you