Jump to content

Recommended Posts

Hi,

I'm trying to make custom follower join combat only if leader's target's HP% is below x (let's say 50%).

I have below code but follower attacks no matter what. What am I missing?

 

combat component:

 

Spoiler

 

inst:AddComponent("combat")
    inst.components.combat:SetKeepTargetFunction(KeepTarget)
    inst.components.combat:SetRetargetFunction(3, NormalRetargetFn)

 

 

 

SetRetargetFunction (NormalRetargetFn):

 

Spoiler

 

local function NormalRetargetFn(inst)

local myleader = inst.components.follower.leader

return inst.components.combat:CanTarget(guy)
            and guy.components.health:GetPercent() <= .5
            --and (guy.components.combat.target == myleader or
            --    myleader.components.combat.target == guy)

 

 

Yes, I commented out the last two lines for testing. The follower still attacks when enemy is full hp.

 

SetKeepTargetFunction (KeepTarget):

 

Spoiler

 

local function KeepTarget(isnt, target)
    return target and target:IsValid() and
        (target.components.health and not target.components.health:IsDead())
end

 

 

 

Thanks.

Edited by SenL

I think I fixed it. It was also using KeepTarget function when leader gets attacked. Don't know why.

Also I had to put parenthesis on the return. Ie:

 

Spoiler

 

return (inst.components.combat:CanTarget(guy)
            and guy.components.health:GetPercent() <= .5)

 

 

NOPE not fixed. Sigh.

Edit:

It works but the follower performs other attacks outside of these two functions. What am I missing?

 

 

Another question is that when a spider_warrior (probably any hostile) gets attacked by leader (me), it sometimes attacks my follower instead. Why?

Edited by SenL

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...