Jump to content

Recommended Posts

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 by Dark Vapor
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 by Dark Vapor

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.

  • Like 1
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 :-D

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)

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.

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.

  • Like 1
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.

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