Targetting problem

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
romaniac
Posts: 79
Joined: Sat Feb 04, 2012 8:25 am

Targetting problem

#1 Post by romaniac »

Hi!

I am trying to build an assist script, similar to PartyHealer, for a strong char to protect a weaker one.

I have the following piece of code to attack any mobs that attack the protected char:

Code: Select all

			local tgt = player:findEnemy(nil,nil,attacksPartner,nil)
			if( tgt ~= nil) then
				print( "attacking " .. tgt.Name );
				player:target( tgt );
				if player:haveTarget() then
					player:fight();
				else
					print( "no tgt" );
				end
attacksPartner() checks the target of all mobs and returns true if their target is the protected char.

This code does work nicely if both chars are in a party.

It fails if there is no party. findEnemy successfully returns the mob, but haveTarget() returns false.

Why?

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

Re: Targetting problem

#2 Post by lisa »

player:haveTarget() isn't for checking if you have a target at all, it is for checking if you have a viable target and part of the checks is if the target is targeting character or party member,

So let's look at how that affects your code.

Code: Select all

 local tgt = player:findEnemy(nil,nil,attacksPartner,nil)
this will either find a target or won't.

Code: Select all

    if( tgt ~= nil) then
This will check if you found a target and tgt is the pawn info for that target if it exists.

Code: Select all

print( "attacking " .. tgt.Name );
simple print to tell you there is a target.

Code: Select all

   player:target( tgt );
tells the bot to target the pawn/mob.

Code: Select all

    if player:haveTarget() then
checks if target is viable according to the rules of rombot which factors in everything, including profile settings.

Code: Select all

 player:fight();
attack mob

Code: Select all

else
Ok so here you have already decided there is something to target because tgt ~= nil, so this is the else for if target is viable according to rombot rules.


So because you know target ~= nil then you don't need the check for player:haveTarget() unless you are worried about anitKS, since you obviously have a function to check for mobs targeting partners then no need.

Code: Select all

        local tgt = player:findEnemy(nil,nil,attacksPartner,nil)
         if( tgt ~= nil) then
            print( "attacking " .. tgt.Name );
            player:target( tgt );
            player:fight();
That will do what you wanted =)
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
romaniac
Posts: 79
Joined: Sat Feb 04, 2012 8:25 am

Re: Targetting problem

#3 Post by romaniac »

lisa wrote:So because you know target ~= nil then you don't need the check for player:haveTarget() unless you are worried about anitKS, since you obviously have a function to check for mobs targeting partners then no need.

Code: Select all

        local tgt = player:findEnemy(nil,nil,attacksPartner,nil)
         if( tgt ~= nil) then
            print( "attacking " .. tgt.Name );
            player:target( tgt );
            player:fight();
That will do what you wanted =)
Not really. The first thing player:fight() does is call haveTarget(). So player:fight() does nothing.

Code: Select all

from player.lua:

function CPlayer:fight()
	self:update();
	if( not self:haveTarget() ) then
		return false;
	end
I did call haveTarget() myself so I could tell that the problem is within that function: With a party, it returns true, without a party, it returns false. Unfortunately, I did not understand the code in haveTarget() well enough to tell where the dependency on a party kicks in.

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

Re: Targetting problem

#4 Post by rock5 »

I think the check that is causing you problems is the anti ks check. Basically it says, if the mob has someone else targeted then it's not a viable target. But it makes exceptions for party members. Thats why it works when in a party.

You could try setting ANTI_KS to false. Then it would skip that check. It might cause it to try to steal other people kills though. Not sure. Maybe as an assist bot you wont have that issue.
  • 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
romaniac
Posts: 79
Joined: Sat Feb 04, 2012 8:25 am

Re: Targetting problem

#5 Post by romaniac »

rock5 wrote:I think the check that is causing you problems is the anti ks check. Basically it says, if the mob has someone else targeted then it's not a viable target. But it makes exceptions for party members. Thats why it works when in a party.

You could try setting ANTI_KS to false. Then it would skip that check. It might cause it to try to steal other people kills though. Not sure. Maybe as an assist bot you wont have that issue.
Right. After disabling KS (and for some reason only after restarting micromacro) it works.

Kills stealing should not become an issue as it only looks at mobs already attacking the protectee.

maniac
Post Reply