SenL Posted February 21, 2016 Share Posted February 21, 2016 (edited) 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 February 21, 2016 by SenL Link to comment https://forums.kleientertainment.com/forums/topic/64585-need-help-with-follower-combat-behavior/ Share on other sites More sharing options...
SenL Posted February 21, 2016 Author Share Posted February 21, 2016 (edited) 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 February 21, 2016 by SenL Link to comment https://forums.kleientertainment.com/forums/topic/64585-need-help-with-follower-combat-behavior/#findComment-725102 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now