Jump to content

Coding - character not scared by specific monsters


Recommended Posts

So, I am creating a DST character and I want for him, not to be scared (sanity drain near monsters) of only hounds. I tried something but it didn't work out well so I am asking for help.

Edited by Veketh
Link to comment
Share on other sites

Copying my answer from the other post, so people searching for something similar can easily find it.

You should create an aurafn for the hounds, extending any existing aurafn on them. Granted, the hounds do not have an aurafn, but you don't know whether another mod adds one, so for added compatibility we want to make sure to call any existing aurafn in the event that it's not your character. This also works for DST. Add this to your modmain.lua and change the "character tag" text to a tag that is unique to your character.

local entitiesThatShouldGiveCharacterNoSanityAura = {
	"hound",
	"firehound",
	"icehound",
	"moonhound",
	"clayhound",
	"mutatedhound",
}

for i,v in ipairs(entitiesThatShouldGiveCharacterNoSanityAura) do
	AddPrefabPostInit(v, function(inst)
		local origAura = inst.components.sanityaura.aurafn
		local function CalcSanityAura(inst, observer)
			return observer:HasTag("character tag") and 0 or origAura ~= nil and origAura(inst, observer) or inst.components.sanityaura.aura
		end
		
		inst.components.sanityaura.aurafn = CalcSanityAura
	end)
end
Link to comment
Share on other sites

9 minutes ago, Veketh said:

Thank you so much... again... and just to confirm, I can make a completely new tag for it right?

Man... you are like a blessing for me. 

You are very welcome. Just happy to help :)

And yes, you can make a new tag. However, you can only have 63 tags on an entity and the game code makes plenty use of them already, so try to use as few custom tags as you can. If you ever run into the problem with having too many tags, you can instead just say inst.myuniquevariable = true in your master_postinit or fn of your prefab, and then check that variable instead of checking for a tag. But I doubt you're hitting that tag limit, so just make a new tag.

Link to comment
Share on other sites

Errmm.. "only 63 tags" huh? I wonder if it's that small amount.. but I don't question anything, maybe it is a small amount in big projects, but I am just some stupid kid who wants his own character in-game so yeah... Thanks again for your help.

Link to comment
Share on other sites

Well, the limit was 31 at one time and I believe the game applies 23+ tags for a standard character or something, so complex characters, with a lot of tags getting added and removed, would hit this limit.

Edited by Ultroman
Link to comment
Share on other sites

No need to make custom tags if you need tags only on server.

Tags are networked. And if you don't use it, it's just useless usage of network traffic and CPU for sending packets.

Just use inst.mytag=true and that's it.

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