Jump to content

Tag shelter and custom speech ?


Recommended Posts

I use the tag "shelter" on a custom structure. The tag do exactly what i want (protection against heat and rain), but it's associated with a speech, often about tree, depending of the character.

(Like "Wolfgang hide under tree." for wolfgang).

Is there an easy way to have a custom speech for the sheltering part, for this specific structure ?

Link to comment
Share on other sites

AddPrefabPostInit("flower", function(inst)
	inst:AddTag("shelter")
end)

local function GetCustomShelterString(character, shelter)
	if shelter.prefab == "flower" then
		if character.prefab == "wilson" then
			return "Thanks, flower."
		end
	end
end

AddComponentPostInit("sheltered", function(self)
	local _SetSheltered = self.SetSheltered
	self.SetSheltered = function(self, issheltered)
		local cooldown_before = self.announcecooldown
		_SetSheltered(self, issheltered)
		local cooldown_after = self.announcecooldown
		if cooldown_before ~= cooldown_after then
			local shelter = GLOBAL.GetClosestInstWithTag("shelter", self.inst, 2)
			local custom_string = shelter and GetCustomShelterString(self.inst, shelter)
			if custom_string then
				self.inst.components.talker:ShutUp()
				self.inst.components.talker:Say(custom_string)
			end
		end
	end
end)

 

Link to comment
Share on other sites

6 hours ago, Lumina said:

Is there a way to make a generic line ?

Remove the character.prefab check and everybody will spout it.

local function GetCustomShelterString(character, shelter)
	if shelter.prefab == "flower" then
		return "Everybody says this."
	end
end

 

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