Dark Vapor Posted November 21, 2021 Share Posted November 21, 2021 (edited) I’m making a bird character and I want birds & gobblers to not run away from it (the player will lose sanity from killing birds though). I found this forum post from 2019, describing my exact idea; as well as this one. I can’t figure it out because in the first forum post, the code given has a weird bug, as if there is no “end” aftern an “if”, even if there actually is one. No matter how I attempted to change the code, it still shows that stupid error. The poster said they couldn’t figure it out, but eventually created a new birdbrain file and it worked. Problem is, I have no idea how to do that or where. Please help me out, I can’t figure this out for the life of me. Edited November 21, 2021 by Dark Vapor Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/ Share on other sites More sharing options...
Pinkamena11FazP Posted November 21, 2021 Share Posted November 21, 2021 Hm maybe you can try looking for that bird hat's code to see if you can copy it to the character. I know it lets you have birds appear or not be afraid. Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1515802 Share on other sites More sharing options...
Dark Vapor Posted November 22, 2021 Author Share Posted November 22, 2021 (edited) 9 hours ago, Pinkamena11FazP said: Hm maybe you can try looking for that bird hat's code to see if you can copy it to the character. I know it lets you have birds appear or not be afraid. Thanks, I already did that for my character. However, the hat just makes more birds spawn near you. They still fly away when you approach them. The point in my mod is for them to stay near you, since you’re a bird - so you can easily hunt them if you want to, but you’ll lose sanity for it (the sanity part, I’ve already implemented in my character.lua file) Everything works except this part. Edited November 22, 2021 by Dark Vapor Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1515910 Share on other sites More sharing options...
-LukaS- Posted November 22, 2021 Share Posted November 22, 2021 What You're trying to do would probably require you to modify birdbrain.lua and override the function responsible for birds to fly away. You would need to add another tag to the entity check so birds would ignore your character. 1 Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1515968 Share on other sites More sharing options...
Dark Vapor Posted November 22, 2021 Author Share Posted November 22, 2021 11 minutes ago, -t- said: What You're trying to do would probably require you to modify birdbrain.lua and override the function responsible for birds to fly away. You would need to add another tag to the entity check so birds would ignore your character. I see. Well, I'll try to do that, but I started learning modding yesterday so I've not much idea how to do that. Thanks for giving me a hint in the right direction though This code, in the master_postinit of the beakey.lua file, gives an error when entering the testing server. It says that an "end" is missing for the "if", which makes no sense for me. Can't seem to fix this. AddBrainPostInit("birdbrain", function(self) local function ShouldFlyAway(inst) local busy = inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") or inst.sg:HasStateTag("flying") if not busy then local threat = FindEntity(inst, 5, nil, nil, {'notarget'}, {'player', 'monster', 'scarytoprey'}) if GetPlayer().prefab == "beakey" then -- error at this "if" return threat false end --there is clearly an "end" here return threat ~= nil or GetClock():IsNight() end end end end) Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1515970 Share on other sites More sharing options...
Dark Vapor Posted November 23, 2021 Author Share Posted November 23, 2021 Alright, I guess I’ll just try to make it so that the character is not a threat to prey (using tags). That means rabbits will also not run away, which makes no sense in my mod, but at least neither will birds. Until I can find another solution, this will have to do. Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1516322 Share on other sites More sharing options...
-LukaS- Posted November 23, 2021 Share Posted November 23, 2021 Sorry for not replying before, I must've missed your reply. You need to override the behaviour tree of the brain to implement the change. local SHOULDFLYAWAY_MUST_TAGS = { "notarget", "INLIMBO", "beakey" } local SHOULDFLYAWAY_CANT_TAGS = { "player", "monster", "scarytoprey" } local function ShouldFlyAway(inst) return not (inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") or inst.sg:HasStateTag("flight")) and (GLOBAL.TheWorld.state.isnight or (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or GLOBAL.FindEntity(inst, inst.flyawaydistance, nil, nil, SHOULDFLYAWAY_MUST_TAGS, SHOULDFLYAWAY_CANT_TAGS) ~= nil) end local function FlyAway(inst) inst:PushEvent("flyaway") end AddBrainPostInit("birdbrain", function(brain) print("BRAIN INITIATED!") local root = GLOBAL.PriorityNode({ GLOBAL.WhileNode(function() return brain.inst.components.hauntable ~= nil and brain.inst.components.hauntable.panic end, "PanicHaunted", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.IfNode(function() return ShouldFlyAway(brain.inst) end, "Threat Near", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.EventNode(brain.inst, "threatnear", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.EventNode(brain.inst, "gohome", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), }, 0.25) brain.bt = GLOBAL.BT(brain.inst, root) end) Putting this into your modmain.lua should work. 1 Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1516338 Share on other sites More sharing options...
Dark Vapor Posted November 24, 2021 Author Share Posted November 24, 2021 17 hours ago, -t- said: Sorry for not replying before, I must've missed your reply. You need to override the behaviour tree of the brain to implement the change. local SHOULDFLYAWAY_MUST_TAGS = { "notarget", "INLIMBO", "beakey" } local SHOULDFLYAWAY_CANT_TAGS = { "player", "monster", "scarytoprey" } local function ShouldFlyAway(inst) return not (inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") or inst.sg:HasStateTag("flight")) and (GLOBAL.TheWorld.state.isnight or (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or GLOBAL.FindEntity(inst, inst.flyawaydistance, nil, nil, SHOULDFLYAWAY_MUST_TAGS, SHOULDFLYAWAY_CANT_TAGS) ~= nil) end local function FlyAway(inst) inst:PushEvent("flyaway") end AddBrainPostInit("birdbrain", function(brain) print("BRAIN INITIATED!") local root = GLOBAL.PriorityNode({ GLOBAL.WhileNode(function() return brain.inst.components.hauntable ~= nil and brain.inst.components.hauntable.panic end, "PanicHaunted", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.IfNode(function() return ShouldFlyAway(brain.inst) end, "Threat Near", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.EventNode(brain.inst, "threatnear", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), GLOBAL.EventNode(brain.inst, "gohome", GLOBAL.ActionNode(function() return FlyAway(brain.inst) end)), }, 0.25) brain.bt = GLOBAL.BT(brain.inst, root) end) Putting this into your modmain.lua should work. Thanks a lot dude! It's finally working as it should! Your help was priceless. Link to comment https://forums.kleientertainment.com/forums/topic/135502-how-to-make-birds-not-afraid-of-custom-character/#findComment-1516603 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