Jump to content

Recommended Posts

Hi everyone,

 

In Don't Starve Together, I can add "companion" tag to prefabs to indicate that they are friendly entities, and force attack action should ignore them.

However, I cannot do that in Don't Starve. The force attack only ignores followers, but still picks companion target. 

Does anyone know how force attack chooses targets in Don't Starve? How can I make it ignore some entities?  

you can look into the combat.lua for the force attack target checking: 

 

function Combat:IsValidTarget(target)
    if not target 
	   or not target:IsValid()
       or not target.components
       or not target.components.combat
       or not target.entity:IsVisible()
       or not target.components.health
       or target == self.inst
       or target.components.health:IsDead()
       or (target:HasTag("shadow") and not self.inst.components.sanity)
       or Vector3(target.Transform:GetWorldPosition()).y > self.attackrange then
        return false
    else
		return true
	end
end

you could remove the combat component on your prefab or overwrite the force attack function

 

function Combat:ForceAttack()
    if self.target and self:TryAttack() then
        return true
    else
        self.inst:PushEvent("doattack")
    end
end

and add a special tag from your prefab to avoid attacking

  • Like 1

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