Page 1 of 1

using onLeaveCombat during an onLoad only waypoint?

Posted: Thu Jul 16, 2015 11:46 am
by noobbotter
Hi guys. I have a waypoint file that I use to manually enable speed() with my spacebar... I typically use it aftermounting or after using a speed pot, or whenever I want to manually be able to enable faster speed.

So I thought I'd try to add some functionality to it to allow myself to auto-hide (as a rogue) when leaving combat, and to be able to turn that function on and off.

So I have the following code. The speed part still works properly. The part for enabling and disabling autohide, it recognizes the keypress but the onLeaveCombat section doesn't seem to run, even with no conditions put on it (you can see I commented out the condition check) it doesn't even do a print during the onLeaveCombat. Here's my code:

Code: Select all

<?xml version="1.0" encoding="utf-8"?><waypoints type="TRAVEL">
<onLoad><![CDATA[
	
	autoHide = false
	
	for k,v in pairs(settings.profile.skills) do
		v.AutoUse = false
		yrest(50)
	end
	
	function settings.profile.events.onLeaveCombat()
		print("AutoHiding ")
		--if autoHide == true then
			yrest(500)
			sendMacro("/cast Hide")
			cprintf(cli.red, "Auto Hiding after Combat!!!\n")
		--end
	end
	
	
	--============= Function to show button controls ===================
	function SKM_ShowButtons()
		cprintf(cli.green, "SPACEBAR - - > Set Speed.\n")
		cprintf(cli.green, "VK_HOME - - > Disable Autohide.\n")
		cprintf(cli.green, "VK_INSERT - - > Enable Autohide.\n")
	end
   
	--============= main routine starting: =====================
	local delay = 1 -- time between key presses.
	local time = os.time()
	SKM_ShowButtons();
	while(true) do
		--================== Enable speed() ======================
		if keyPressed(key.VK_SPACE) and (os.time() - time > delay ) then
			speed()
			cprintf(cli.yellow, "HIGH SPEED ENABLEED!!!\n")
			SKM_ShowButtons();
			time = os.time()
		end
		--================== Enable Auto Hide after leaving combat =============
		if keyPressed(key.VK_INSERT) and (os.time() - time > delay ) then
			autoHide = true
			cprintf(cli.yellow, "Auto Hide ENABLEED!!!\n")
			SKM_ShowButtons();
			time = os.time()
		end
		--================== Disable Auto Hide after leaving combat =============
		if keyPressed(key.VK_HOME) and (os.time() - time > delay ) then
			autoHide = false
			cprintf(cli.yellow, "Auto Hide disabled!!!\n")
			SKM_ShowButtons();
			time = os.time()
		end
		yrest(10)
	end
]]></onLoad>
</waypoints>
If I had to guess, I'd say It never calls the onLeaveCombat function because the bot isn't doing the combat because it's too busy keeping track of whether there was a keypress? Any way I can make this work? I am stumped.

Re: using onLeaveCombat during an onLoad only waypoint?

Posted: Thu Jul 16, 2015 12:15 pm
by rock5
It's pretty simple really. The bot never takes control to attack because it's stuck in a loop in the onload. onLeaveCombat only goes into effect after a bot initiated combat sequence. If you want your code to do something after you manually kill something then you will have to test for combat yourself in your loop. Something like

Code: Select all

player:updateBattling()
if lastBattling == true and player.Battling == false then
    -- Put onLeaveCombat code here
end
lastBattling = player.Battling

Re: using onLeaveCombat during an onLoad only waypoint?

Posted: Thu Jul 16, 2015 12:22 pm
by noobbotter
Awesome. I was thinking it had something to do with the loop it was in. Thanks. I'll try implementing that tonight and see what I come up with.

**Update:
Yep, that worked. I updated my code to have it detect battling within the loop and it worked. It's not always 100% accurate as far as detecting "leaving battle" and entering hide, but works most the time.