Page 1 of 1
How to trigger if-statement when in combat
Posted: Fri Sep 02, 2011 5:59 pm
by Caspy
I am trying to make a bot here that has to check if the target his hp is under 50% after each hit it does. And if it is under 50%, than it has to use an item.
The code atm looks like:
Code: Select all
<!-- # 59 --><waypoint x="2000" z="1700" y="399">
yrest(3500);
player:cast("ROGUE_INFORMER");
yrest(500);
player:cast("ROGUE_FERVENT_ATTACK");
yrest(500);
player:cast("ROGUE_EVASION");
yrest(500);
player:cast("ROGUE_ASSASSINS_RAGE");
yrest(500);
if( 50 > target.HP/target.MaxHP*100 ) then
player:findNearestNameOrId(102623);
player:target(102623);
player:update();
inventory:useItem(205836);
end;
</waypoint>
<!-- # 60 --><waypoint x="2030" z="1725" y="399">
yrest(4000);
</waypoint>
The problem here is, at waypoint 59 i don't have the boss as my target yet so he gives a global error at 'target'. But when I put the if-statement in waypoint 60 than I fight the boss and when I click on the Crystal ball (I used it manually), only afterwards he searches for my target (which also results in an error cause target is already down), once he has actually reached this waypoint 60. So I was thinking that I had to trigger this if-statement in between the waypoints (don't know if this is possible) , but there may be a smarter way.
I tried to get an answer to the problem on rompros aswell but got stuck there. I hope i have more luck here
Thank you in advance. Caspy.
Re: How to trigger if-statement when in combat
Posted: Fri Sep 02, 2011 8:45 pm
by lisa
you need to define "target" so target.HP actually returns a value.
Obviously I would need to understand exactly what you are trying to do to help with the rest of the coding. From what you have it seems you attack 1 mob and when it's hp is below 50% you target another mob and use an item. Which seems kind of weird to me. I thought you would use the item on the mob you had down to 50%. In that code you posted though there is no attacking skills, so when does it fight?
If that is the case then you need to make sure you have that mob as your target first before checking the hp %, unless there is only 1 mob in the area then it won't matter.
I think there is probably a much better way to do what you want but unless I know exactly what you need to do I can't help much more.
Re: How to trigger if-statement when in combat
Posted: Fri Sep 02, 2011 9:37 pm
by rock5
Also if you want to check the targets hp after every hit it does you would have to put it in the onSkillCast section of your profile.
Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 4:17 am
by Caspy
Yes, maybe I wasn't clear enough. I have to use the Crystal ball (item) when the boss (Lytfir) his HP is under 50%. 102623 is the ID of the boss and 205836 is the ID of the crystal ball.
I will upload my full waypoint file as it may make it easier for you to check what it needs to do.
So in this file you'll see the if-statement at waypoint 60. This is too late, since I don't reach 60 until after the fight. And when I put it at 59, it's too early.
Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 4:35 am
by lisa
Ok then you will need to put it in the onskillcast of your profile, as that code is done anytime you cast a skill, the code in the WP will only be done once and since the bosses HP starts at 100% then it won't ever do what you want.
Something like this in your profile.
Code: Select all
<onSkillCast><![CDATA[
target = player:getTarget();
if target ~= nil then
if target.Name == "Lytfir" then
if( 50 > target.HP/target.MaxHP*100 and _used ~= true) then
inventory:useItem(205836);
_used = true
end
end
end
]]></onSkillCast>
You could porobably use
it would atleast be usable with any language client then.
Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 4:58 am
by Caspy
This is awesome, works perfectly.
Only 1 more problem now ^^
When I fight this boss, my range of my skills is 50 but the distance is always bigger so my character always moves in. Is there a way around this?
In the cmd screen it shows: Moving in | Suggested range: 50 | Distance: (from 52 to 96).
I ask this because it gets a bit dangerous when I don't kill the boss fast enough and this moving in slows me down a lot.
Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 1:51 pm
by kanta
Hi there Caspy. I knew you would get the info you needed here.

Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 8:20 pm
by Mushroomstamp
You left your character name in the waypoint you posted... you'll want to change that.
If I'm understanding your post, your talking about the wasted time from when you cast your buffs to when you're actually close enough to attack. You could go with something like this to pull him;
Code: Select all
lf = player:findNearestNameOrId(102623)
if lf then
player:cast("ROGUE_INFORMER")
player:cast("ROGUE_FERVENT_ATTACK")
player:target(lf)
player:cast("ROGUE_COMBO_THROW")
player:cast("ROGUE_ASSASSINS_RAGE")
player:cast("ROGUE_EVASION")
end
Or probably better yet;
Code: Select all
lf = player:findNearestNameOrId(102623)
if lf then
player:cast("ROGUE_INFORMER")
player:cast("ROGUE_FERVENT_ATTACK")
player:cast("ROGUE_PREMEDITATION")
player:target(lf)
player:cast("ROGUE_SHADOW_STEP")
player:cast("ROGUE_BLIND_SPOT") --or sneak attack
player:cast("ROGUE_ASSASSINS_RAGE")
player:cast("ROGUE_EVASION")
end
Re: How to trigger if-statement when in combat
Posted: Sat Sep 03, 2011 8:37 pm
by lisa
Caspy wrote: Is there a way around this?
Code: Select all
changeProfileOption(COMBAT_DISTANCE, 60)
that will change it from 50 to 60, obviously you can set the number to what you want. The only issue is if you try to set it bigger then your MAX_TARGET_DIST
Re: How to trigger if-statement when in combat
Posted: Sun Sep 04, 2011 8:38 pm
by Caspy
I'm still experiencing some problems. I tried to change the profile options in all ways, but nothing seems to work.
Standard distances in my profile i have:
Code: Select all
<option name="COMBAT_DISTANCE" value="200" />
<option name="MAX_TARGET_DIST" value="225" />
But this gave me 'moving in' as result.
I tried changing
Code: Select all
changeProfileOption("COMBAT_DISTANCE",60);
like you suggested. But same problem.
I tried changing
Code: Select all
changeProfileOption("MAX_TARGET_DIST", 150);
changeProfileOption("COMBAT_DISTANCE", 255);
so the max_target_distance would be bigger which might result in problems like u said, but it changes nothing, still moving in after each hit. (This code is added in the waypoint before I engage in battle with the boss, should be fine right?)
I have added a printscreen of what the bot does while fighting the boss, maybe it helps to understand or solve the problem.
Re: How to trigger if-statement when in combat
Posted: Sun Sep 04, 2011 8:54 pm
by lisa
from that pic it seems they are mostly 54-55, it might be possible the bosses model keeps it at a distance off 55 as it melee's you in fight. I would try a value of 55 and see how it goes.
Code: Select all
changeProfileOption("COMBAT_DISTANCE",55);
Re: How to trigger if-statement when in combat
Posted: Sun Sep 04, 2011 9:49 pm
by Mushroomstamp
Caspy wrote:my range of my skills is 50 but the distance is always bigger so my character always moves in.
The bot moves to whatever range it needs to, in order to attack. If none of your skills have a farther range than 50, the bot HAS to move within a range of 50 to attack.
Did you try the code I posted above in your waypoint?
Re: How to trigger if-statement when in combat
Posted: Mon Sep 05, 2011 7:17 am
by Caspy
@ Lisa: I tried changing combat_distance to 45 - 50 - 55, nothing worked. But ok, problem solved after trying what Mushroomstamp suggested.
@ Mushroomstamp: Thank you for the help, this works.
1 new problem occured though. :p
I start the bot, go in combat with the boss for the 1st time. And all goes according to plan. I fight, use item, loot and leave party and rerun. But if I don't restart the bot, than when i'm fighting the boss for the 2nd time, it won't use the crystal ball anymore.
Any idea why it only works the 1st time I fight the boss and how I may be able to solve this?
Maybe with some code to automatically reload the bot? or is that even too far fetched? ^^
Re: How to trigger if-statement when in combat
Posted: Mon Sep 05, 2011 10:50 am
by rock5
Probably because you made
I'm not exactly sure why you use that but if you need it then you will have to reset it to false at some point so that the item can be used again.
Re: How to trigger if-statement when in combat
Posted: Mon Sep 05, 2011 11:38 am
by lisa
I added that in so it didnt just constantly spam the item. I didn't think it would be a fight done over and over again.
Just need to set _used to false at a waypoint coords before boss.
Re: How to trigger if-statement when in combat
Posted: Mon Sep 05, 2011 4:29 pm
by Caspy
Yea problem solved with rewriting the if-statement:
Code: Select all
<onSkillCast><![CDATA[
target = player:getTarget();
if target ~= nil then
if target.Name == "Lytfir" then
_used = false;
if( 50 > target.HP/target.MaxHP*100 and _used ~= true) then
inventory:useItem(205836);
_used = true
end
end
end
]]></onSkillCast>
So if anyone wants the water dragon waypoints, pm me.
Thanks to kanta, lisa, Mushroomstamp and rock5 for helping me finish this bot.
