RevelHalcyon Posted May 29, 2019 Share Posted May 29, 2019 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 More sharing options...
Thomas Die Posted May 29, 2019 Share Posted May 29, 2019 (edited) 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 May 29, 2019 by thomas4845 Link to comment Share on other sites More sharing options...
RevelHalcyon Posted May 29, 2019 Author Share Posted May 29, 2019 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 More sharing options...
Thomas Die Posted May 30, 2019 Share Posted May 30, 2019 tbh i just started coding not too long ago and it's just all trial and error but i think the code should work without having to change the modmain but i suggest asking more experienced coders Link to comment Share on other sites More sharing options...
RevelHalcyon Posted May 30, 2019 Author Share Posted May 30, 2019 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 More sharing options...
Thomas Die Posted May 31, 2019 Share Posted May 31, 2019 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 More sharing options...
RevelHalcyon Posted June 1, 2019 Author Share Posted June 1, 2019 Ah yes that was exactly what I was talking about. That thought never occurred to me, so that works for my purposes. Thanks. Link to comment 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