Page 1 of 1
Running away from a fight
Posted: Sat Apr 28, 2012 7:32 am
by rock5
Has anyone ever written some code to run away from a fight? Maybe if your hp gets too low? I chaven't been able to do it. If there is no way, I'll have to add some code for it in the bot.
I tried clearing target, targeting myself, setting waypoint type to travel. Nothing works. It breaks from the fight but reengages the mob.
Re: Running away from a fight
Posted: Sat Apr 28, 2012 8:17 am
by lisa
Since the mob would be targeting you and not 100% hp then you will probably have to add it to the ignore list for the bot to not defend itself against it.
Code: Select all
local target = player:getTarget();
player.IgnoreTarget = target.Address;
__WPL:setForcedWaypointType("TRAVEL")
player:clearTarget()
Re: Running away from a fight
Posted: Sat Apr 28, 2012 8:49 am
by rock5
Thanks I'll try that.
Re: Running away from a fight
Posted: Sun Apr 29, 2012 4:43 am
by rock5
Still can't do it.
This is what I had in the onload secion of my waypoint.
Code: Select all
if oldOnSkillCast == nil then oldOnSkillCast = settings.profile.events.onSkillCast end
function settings.profile.events.onSkillCast()
if 80 > (player.HP/player.MaxHP*100) then -- escape
local target = player:getTarget();
player.IgnoreTarget = target.Address;
player:clearTarget()
__WPL:setWaypointIndex(__WPL:findWaypointTag(finished))
__WPL:setForcedWaypointType("TRAVEL")
player:mount(nil,true)
else
return oldOnSkillCast()
end
end
Note: I've modified mount so if you put "true" as the second argument it doesn't fight before tring to mount.
After manually finding a Copper Guardener and making sure my hp went below 80% then resuming, this is what happened.
Code: Select all
Moving to waypoint #100, (7618, 2476)
Resting for 5 seconds.
Paused. (Home) to continue, (CTRL+L) exit to shell, (CTRL+C) quit
Resumed.
Clearing target.
Stop resting because of aggro.
Forced waypoint type 'TRAVEL' set by user.
Waiting on aggressive enemies.
Use MACRO: Executing RoMScript "CancelPlayerBuff(2);".
Engaging enemy [Copper Gardener] in combat.
Use MACRO: MAGE_FIREBALL => Copper Gardener (18672/18672)
Clearing target.
Forced waypoint type 'TRAVEL' set by user.
Use MACRO: MAGE_FLAME => Copper Gardener (11927/18672)
Clearing target.
Forced waypoint type 'TRAVEL' set by user.
Use MACRO: MAGE_FIREBALL => Copper Gardener (0/18672)
Clearing target.
Forced waypoint type 'TRAVEL' set by user.
Fight finished. Killed 2 Copper Gardener. (fight #4 / runtime 13 minutes)
I even tried adding
Code: Select all
player.Current_waypoint_type = WPT_TRAVEL
I really thought that would work. But I got similar results.
Re: Running away from a fight
Posted: Sun Apr 29, 2012 5:42 am
by lisa
you might also need to add in a
Code: Select all
player.Fighting = false
unregisterTimer("timedAttack");
I have a feeling the clear target isn't good enough, it is kind of like clicking away from target but then mob hits you and it becomes target again.
Maybe add a few prints inside player:fight() and see if you can work out what is happening?
I would definately add a print the first line of player:fight() to see if the function is being called after you try to disengage.
Also you might need a couple of " " in this line
Code: Select all
__WPL:setWaypointIndex(__WPL:findWaypointTag(finished))
Re: Running away from a fight
Posted: Sun Apr 29, 2012 8:58 am
by rock5
I forgot to say, I think IgnoreTarget didn't work because if it is attacking you it will ignore IgnoreTarget. That's only when it's looking for targets.
Putting a print statement at the beginning of fight was a good idea as it confirmed what I suspected and that is that it doesn't exit the fight function. After a closer look at the loop in the fight function, the only way I could see to make it break was to make it think it was taking to long to damage the target. I did this with
Code: Select all
player.lastHitTime = player.lastHitTime - (settings.profile.options.MAX_FIGHT_TIME *2)
Also I had to move the mount to the onleavecombat section and I decided to switch to onpreSkillCast. So in the end it looks somethin like this.
Code: Select all
if oldOnPreSkillCast == nil then oldOnPreSkillCast = settings.profile.events.onPreSkillCast end
function settings.profile.events.onPreSkillCast()
if 80 > (player.HP/player.MaxHP*100) then -- escape
__WPL:setForcedWaypointType("TRAVEL")
player.Current_waypoint_type = WPT_TRAVEL
player.lastHitTime = player.lastHitTime - (settings.profile.options.MAX_FIGHT_TIME *2)
-- Code to pick right waypoint
-- Or maybe load an escape waypoint file
return false -- So it doesn't waste time casting the skill
else
return oldOnPreSkillCast()
end
end
if oldOnLeaveCombat == nil then oldOnLeaveCombat = settings.profile.events.onLeaveCombat end
function settings.profile.events.onLeaveCombat()
if player.Current_waypoint_type == WPT_TRAVEL then
player:mount(nil,true)
else
oldOnLeaveCombat()
end
end
I wonder if I should add a variable and maybe a function to break from a fight and maybe a function to set everything up to escape. It could be as little as just one variable for the user to change to break from a fight and they would have to do the other commands or a full function that breaks from the fight and maybe sets the waypoint type to travel. Hm... I'm not sure.
Just had an idea. Don't need a second argument for mount. Just check if player.Current_waypoint_type = WPT_TRAVEL. If so don't fight back.
Re: Running away from a fight
Posted: Sun Apr 29, 2012 6:41 pm
by lisa
I find it interesting it doesn't leave the function but when you clear target it doesn't leave the while loop, I guess that is the reaquiring target when you get hit I mentioned.
I have been thinking about it since you posted this topic and I do like options and disengaging from fight "could" be a good option but it comes down to what happens after you break the fight.
Where do you run to?
How far do you run to get away from mob?
Do you still use heal skills/potions when you run?
Do you try to mount before running?
It brings so many questions to mind and the trouble is that you would want to do different things in different situations.
Re: Running away from a fight
Posted: Sun Apr 29, 2012 11:55 pm
by rock5
Yeah, you would think that if the loop starts
then clearing the target should break from the loop. The only thing after checkskills is gettarget but that just returns player.TargetPtr. That means, somewhere in checkskills and assocciated functions, it reaquires the target but I can't find it.
I actually tested starting a fight then clearing the target. It didn't fight back again so I thought that wasn't the problem. But on second thought, it did retarget the mob which is all the bot needs. That would have to be the problem then.
As to the options, I think I'll just make it so you can disengage and leave it to the user what they want to do with it. All it realy needs is this in the while loop.
Code: Select all
if somevariable == true then
break_fight = true;
break;
end
Then a function such as
Code: Select all
function CPlayer:breakFight()
somevariable = true
end
Then a user can do something like this in their onpreskillcast or onskillcast
Code: Select all
if some condition then
player:breakFight()
__WPL:setForcedWaypointType("TRAVEL")
loadPaths("escape")
end
But you are right, there are too many variables to do an escape function. I think I'll just provide the means to break from the fight.