Jump to content

Help making birds friendly?


Recommended Posts

I seem to have reached my limit as to what I can figure out on my own just doing research, so I'm here to hopefully enlist someone who knows what they're doing.

I've put together a custom character who happens to be a bird, and I thought it would be cute to make catcoons attack her, and birds not fly away from her. I managed to get the catcoons to agro but it seems that modifying brains postInit is different that modifying prefabs.

I'm looking at the "ShouldFlyAway" function in the bird brain, and I think the most simple solution would be to simply add a custom "birdgirl" tag to the list of things to ignore when searching for threats, but I can't for the life of me figure out how to modify this brain function from inside my modmain file.

Can anyone tell me how to modify an existing function within a brain? Or offer a better solution to making birds not fly away from my specific character?

Link to comment
Share on other sites

local function ShouldFlyAway(inst)
    return not (inst.sg:HasStateTag("sleeping") or
                inst.sg:HasStateTag("busy") or
                inst.sg:HasStateTag("flight"))
        and (TheWorld.state.isnight or
            (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or
            FindEntity(inst, SEE_THREAT_DIST, nil, nil, { "notarget", "INLIMBO" }, { "player", "monster", "scarytoprey" }) ~= nil)
end

this is coding from the bird brain code, at the bottom it says the the things that could cause it to run it says there player you can change that or rewrite an exception    

Edited by thomas4845
Link to comment
Share on other sites

Yeah that's exactly the function I'm looking at, sorry I should have posted that in a quote.

I created a custom tag called "birdgirl" that I simply added onto the exceptions there; so it reads:

{ "notarget", "INLIMBO", "birdgirl" }

but I'm just not familiar enough with how lua works to create this modification to the birdbrain from within my character's modmain.lua

This is what I attempted here;

Quote

local function ShouldFlyAway(inst)
    return not (inst.sg:HasStateTag("sleeping") or
                inst.sg:HasStateTag("busy") or
                inst.sg:HasStateTag("flight"))
        and (TheWorld.state.isnight or
            (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or
            FindEntity(inst, SEE_THREAT_DIST, nil, nil, { "notarget", "INLIMBO", "birdgirl" }, { "player", "monster", "scarytoprey" }) ~= nil)
end
AddBrainPostInit("birdbrain", ShouldFlyAway)

I thought I could re-define the function and then insert it into birdbrain with that last line but this isn't the case, so I need help figuring out the proper way to modify a brain from within modmain.lua

Thanks for the reply

Link to comment
Share on other sites

Yeah the code works, but maybe I'm wrong; I don't think I can just include my own version of birdbrain in my mod right? I need to modify the existing one? so the code I listed is in my modmain, for the purposes of modifying the existing birdbrain. Unless there's a way to just make my own version of birdbrain in the character mod and have it overwrite the existing one, I don't know.

Link to comment
Share on other sites

i'm pretty sure all you have to do is create an extra file in scripts called brains and recreate(copy paste) the bird brain file there with your adjustments, and that's what i usually do

sorry i'm not too good at coding 

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...