Page 1 of 1

Targetting problem

Posted: Sun Feb 19, 2012 11:47 am
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

Re: Targetting problem

Posted: Sun Feb 19, 2012 12:00 pm
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 =)

Re: Targetting problem

Posted: Sun Feb 19, 2012 12:32 pm
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

Re: Targetting problem

Posted: Sun Feb 19, 2012 1:59 pm
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.

Re: Targetting problem

Posted: Tue Feb 21, 2012 3:26 pm
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