How to trigger if-statement when in combat

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

How to trigger if-statement when in combat

#1 Post by Caspy » Fri Sep 02, 2011 5:59 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: How to trigger if-statement when in combat

#2 Post by lisa » Fri Sep 02, 2011 8:45 pm

you need to define "target" so target.HP actually returns a value.

Code: Select all

target = player:getTarget(); 
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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: How to trigger if-statement when in combat

#3 Post by rock5 » Fri Sep 02, 2011 9:37 pm

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

Re: How to trigger if-statement when in combat

#4 Post by Caspy » Sat Sep 03, 2011 4:17 am

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: How to trigger if-statement when in combat

#5 Post by lisa » Sat Sep 03, 2011 4:35 am

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

Code: Select all

if target.Id == 102623 then
it would atleast be usable with any language client then.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

Re: How to trigger if-statement when in combat

#6 Post by Caspy » Sat Sep 03, 2011 4:58 am

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.

kanta
Posts: 424
Joined: Thu Nov 11, 2010 4:08 pm

Re: How to trigger if-statement when in combat

#7 Post by kanta » Sat Sep 03, 2011 1:51 pm

Hi there Caspy. I knew you would get the info you needed here. :D
Scout/Knight/Rogue 70/66/66

Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

Re: How to trigger if-statement when in combat

#8 Post by Mushroomstamp » Sat Sep 03, 2011 8:20 pm

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

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: How to trigger if-statement when in combat

#9 Post by lisa » Sat Sep 03, 2011 8:37 pm

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
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

Re: How to trigger if-statement when in combat

#10 Post by Caspy » Sun Sep 04, 2011 8:38 pm

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.
Attachments
BossFight.png

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: How to trigger if-statement when in combat

#11 Post by lisa » Sun Sep 04, 2011 8:54 pm

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);
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

Re: How to trigger if-statement when in combat

#12 Post by Mushroomstamp » Sun Sep 04, 2011 9:49 pm

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?

Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

Re: How to trigger if-statement when in combat

#13 Post by Caspy » Mon Sep 05, 2011 7:17 am

@ 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? ^^

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: How to trigger if-statement when in combat

#14 Post by rock5 » Mon Sep 05, 2011 10:50 am

Probably because you made

Code: Select all

_used = true
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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: How to trigger if-statement when in combat

#15 Post by lisa » Mon Sep 05, 2011 11:38 am

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.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Caspy
Posts: 21
Joined: Fri Sep 02, 2011 5:32 pm

Re: How to trigger if-statement when in combat

#16 Post by Caspy » Mon Sep 05, 2011 4:29 pm

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. ;)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests