Jump to content

Prevent birds from flying away


Recommended Posts

Hello! I'm working on a custom character mod and I need to find a way to stop birds from flying away when you approach them.

I've spent quite a lot of time at this point googling everything I can think of and rooting through the game's files to try and figure out a way to do this, but I've been unable to make it happen. So far, the closest thing I've been able to make work is removing the "scarytoprey" tag, but I want the player to still scare off other prey animals- just not the birds.

Any advice or tutorials people can point me toward would be GREATLY appreciated. I've already spent 5 hours trying to figure this out, but lua doesn't come easily to me for whatever reason.

Link to comment
Share on other sites

I haven't looked into this, but I'd recommend looking at the actual bird prefabs, and perhaps their brain and stategraph, and figure out where the "scarytoprey" tag is used, as see if there might be a way to intercept the code before that check is even done. For example, if there is a function called isScary(inst) which checks whether a particular entity is scary, then you can extend that function for the birds to always return false if it's your character. Similarly, if there is just a function called isScaryThingNearby() which checks in a radius whether entities without the "scarytoprey" tag on are within range, you might be able to extend that function instead.

Link to comment
Share on other sites

Ok, I tried constructing an AddBrainPostInit based on what I found in birdbrain.lua to add to modmain.lua, but I'm getting a repeat crash that I don't understand, and I'm also really not sure if this would actually work anyway. But here's what I came up with:

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 == "wren" then
				return threat false
				end
			return threat ~= nil or GetClock():IsNight
			end
		end
	end
end)

The crash log indicates the game wants an "end" after return threat false to close the "if" on the previous line, but I can't figure out how to resolve that (I thought the end on the next line would count, but it doesn't, and adding one on the same line right after return threat false doesn't work either). I'm pretty much just throwing spaghetti at the wall here.

Link to comment
Share on other sites

11 hours ago, BraveChicken said:

You can also try to copy-paste the birdbrain into your own mod and then simply modify it there.

It's generally bad practice to overwrite original game files in a mod. It'll break any other mods which alter the behavior of the code in the file.

Link to comment
Share on other sites

5 hours ago, Ultroman said:

It's generally bad practice to overwrite original game files in a mod. It'll break any other mods which alter the behavior of the code in the file.

Maybe, but that's for the mod's creator to decide if he or she wants to take that risk. I personally never encountered any issues with this.

However, if you know a working way to do that from modmain.lua then I would gladly learn that too. (As I usually find issues with the AddBrainPostInit)

Link to comment
Share on other sites

You're missing parentheses on this line

return threat ~= nil or GetClock():IsNight

It should be:

return threat ~= nil or GetClock():IsNight()

 

1 hour ago, BraveChicken said:

Maybe, but that's for the mod's creator to decide if he or she wants to take that risk. I personally never encountered any issues with this.

However, if you know a working way to do that from modmain.lua then I would gladly learn that too. (As I usually find issues with the AddBrainPostInit)

True, but unless you're absolutely sure there's no other way, you should refrain from doing so, and you should make sure to mention it in your mod description. Just because something is being difficult to work with, it doesn't mean you should break it for everyone else just so it works for your purpose. There will be problems, if another mod expects something to happen due to their changes to the code, and you just overwrite their changes afterwards.

AddBrainPostInit has always worked fine for me. Brains are just highly volatile, because they sort of tie together the prefab and the stategraph, so a lot can go wrong.

Link to comment
Share on other sites

6 hours ago, Ultroman said:

Just because something is being difficult to work with, it doesn't mean you should break it for everyone else just so it works for your purpose. There will be problems, if another mod expects something to happen due to their changes to the code, and you just overwrite their changes afterwards.

I am not really "Breaking it for anyone". It would just make my mod incompatible with some other ones and not break the ones which already exist. If someone sees that a mod is incompatible with the other ones, then they turn it off and everything works as before. You don't need to humiliate people for an attempt to help someone. You can just provide them with a solution which you consider better instead.
Anyways, nevermind it. I guess if you're that bothered I'll just erase it.

Have a good day. I'm ending my conversation here.

Link to comment
Share on other sites

BraveChicken- thank you very much for your comments! Adding my own brain file finally got it working. I couldn't get AddBrainPostInit to work no matter what I did (even after correcting the parentheses). Your help was invaluable.

Ultroman, thank you for your concern, but I'm not actually planning on making this mod public- it's for my own use- so I'm not worried about it interfering with other mods.

Link to comment
Share on other sites

4 hours ago, BraveChicken said:

I am not really "Breaking it for anyone". It would just make my mod incompatible with some other ones and not break the ones which already exist. If someone sees that a mod is incompatible with the other ones, then they turn it off and everything works as before. You don't need to humiliate people for an attempt to help someone. You can just provide them with a solution which you consider better instead.
Anyways, nevermind it. I guess if you're that bothered I'll just erase it.

Have a good day. I'm ending my conversation here.

I think you're reading more negativity into my wording than was intended. It was merely meant as an explanation as to why it's not preferable. Maybe it's because I used "you" in the sentences, and therefore you took that as me speaking directly about you. I meant "you" as in the general "you", like saying "one should refrain from doing that". I apologize if the wording made it sound harsh. It was meant as constructive criticism. I don't see how it was humiliating, though, but I guess we all read, and react to, things differently. It was definitely a misunderstanding.

You are right, that it only makes your mod incompatible with other mods editing that file, but in these instances it's common for the game to erroneously report the other mod as the culprit, which makes it that much harder to figure out which mod is at fault. If someone adds a slew of mods at the same time, and one reports an error, then they will remove that mod, when it was really the overwriting mod that was at fault.

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