Jump to content

Beefalo/Brain Logic Help


Faerl

Recommended Posts

Hi All,

Working on my first character/object mod. I've been pretty happy so far, updated art, got most of the logic. Definately hit my head into the desk a few times but it's coming along. Anyway, I'm hitting into a small issue I'm hoping someone can help with.

 

The character has a (usable item) that I want to effectively make beefalo ignore him (especially when in heat). So the first thing I did was add a tag of 'beefalo' when he has it and that seemed to work. Except that anytime he walks up to the beefalo they raise their head and freeze. They do this normally when not in heat but what I'd really like is them to do this then go back to wandering. Otherwise it looks strange that they're just freezing until he walks away.

 

The reason for this behavior appears to be that their base brain behavior goes through a priority set of decisions and GetFaceTarget/KeepFaceTarget (below) are decided above wander.

 

function BeefaloBrain:OnStart()
    local root = PriorityNode(
    {
       ..... stuff removed...
        FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn),
        Wander(self.inst, function() return self.inst.components.knownlocations:GetLocation("herd") end, GetWanderDistFn)
    }, .25)
... stuff removed....
end

 

Looking at the KeepFaceTarget function (below) it looks like it ignores this if the character has the notarget tag. I did a quick test giving my usable item that tag and it gives the correct result (but of course then NO creatures can target it so it won't work long term).

 

local function KeepFaceTargetFn(inst, target)
    return inst ~= nil
        and target ~= nil
        and inst:IsValid()
        and target:IsValid()
        and not (target:HasTag("notarget") or
                target:HasTag("playerghost"))
        and inst:IsNear(target, KEEP_FACE_DIST)
end

 

So, what I think I want/need to do to make this work is override/modify the KeepFaceTargetFn function in my mod main to add an extra "not HasTag" for some custom tag that my item possesses. So when the beefalo sees the tag it acts just like it does when I set notarget but no other creatures care.

 

That would imply a AddBrainPostInit is needed but I don't know how to do that properly. Any ideas? or anyone know a better way of accomplishing the same?

 

Link to comment
Share on other sites

I did try this (added to my modmain) hoping that I could just override the function and only chaning the one tag but it didn't seem to do anything. Can't even get a print on it.

 

local function KeepFaceTargetFn(inst, target)
print("test")
    return inst ~= nil
        and target ~= nil
        and inst:IsValid()
        and target:IsValid()
        and not (target:HasTag("notarget") or
                target:HasTag("playerghost") or
        target:HasTag("beefalofriend"))
        and inst:IsNear(target, KEEP_FACE_DIST)
end

AddBrainPostInit("beefalobrain", KeepFaceTargetfn)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...