Jump to content

Recommended Posts

So, I've been trying my hand at making a character mod for dst and while messing around and trying to learn the code I thought I'd try something simple and give my character (Ahi) some custom speech for when he eats his favourite foods! However... this was not exactly that simple. In fact, I have no idea what's going on or how to get this to work. 

The first attempt I made was
 

EAT_FOOD =
    {
        TALLBIRDEGG_CRACKED = "Mmm. Beaky.",
        WINTERSFEASTFUEL = "Tastes like the holidays.",
        MEAT = "Don't get to eat this very often!",
        MONSTERMEAT = "Surprisingly tasty!",
        FROGLEGS = "A better chicken.",
    },

But this did not work and looking in Wilson's speech file I see at the top it mentions running something called "PropagateSpeech.bat" after adding new speech strings to Wilson's speech file and also add the context string to "speech_from_generic.lua". I cannot find either of these and "PropagateSpeech.bat" does not seem to come up when I search it online.

Worried about editing official files (Wilson's speech file), I tried looking for an alternative and came across a seemingly handy mod called DST Speech Template. Using this template, I pasted a line of code into Ahi's modmain.lua file right under the code for his speech file. 

GLOBAL.STRINGS.CHARACTERS.GENERIC.EAT_FOOD.MEAT = "Don't get to eat this very often!"

That also did not work. It never crashed, just wouldn't play the speech when he ate meat.

Other attempts I tried were

 

STRINGS.CHARACTERS.GENERIC.EAT_FOOD.MEAT = "Don't get to eat this very often!"
GLOBAL.STRINGS.CHARACTERS.AHI.EAT_FOOD.MEAT = "Don't get to eat this very often!"
STRINGS.CHARACTERS.AHI.EAT_FOOD.MEAT = "Don't get to eat this very often!"

Which... also did not work. I'm not sure if there's something I'm missing or maybe I'm putting this in the wrong file but I'm really stumped and would love to get this to work. It's a real shame characters don't announce a little snippet about their favourite food when they eat it! 

Any help is appreciated :3

I looked through the game's code (specifically cookie cutters) and found a function that calls for them to make a sound when eating/biting your boat

local function OnEatFn(inst)
	inst.SoundEmitter:PlaySound("saltydog/creatures/cookiecutter/bite")
end

and then later in the file:

    inst:AddComponent("eater")
    inst.components.eater:SetDiet({ FOODTYPE.WOOD }, { FOODTYPE.WOOD })
	inst.components.eater:SetOnEatFn(OnEatFn)

So using that I came up with this:

		local function OnEatFn(inst)
		if (item.prefab == "tallbirdegg_cracked") then
		inst.components.talker:Say("Mmm. Beaky.")
		end
		if (item.prefab == "wintersfeastfuel") then
		inst.components.talker:Say("Tastes like the holidays.")
		end
		if (item.prefab == "meat") then
		inst.components.talker:Say("Don't get to eat this very often!")
		end
		if (item.prefab == "monstermeat") then
		inst.components.talker:Say("Surprisingly tasty!")
		end
		if (item.prefab == "froglegs") then
		inst.components.talker:Say("A better chicken.")
		end
		
	inst:AddComponent("eater")
	inst.components.eater:SetOnEatFn(OnEatFn)
		
	end

Just put the code under master_postinit in your character's prefab file and it should work

2 hours ago, kyupita said:

So using that I came up with this:

Needs to be OnEatFn(inst, item).

Walter's oneat checks "food ~= nil and food:IsValid()". IDK if it's possible to eat nothing, but you'll error checking prefab if item is nil. So:

local function OnEatFn(inst, item)
  if item == nil or not item:IsValid() then
    return
  elseif (item.prefab == "tallbirdegg_cracked") then
    inst.components.talker:Say("Mmm. Beaky.")
  elseif (item.prefab == "wintersfeastfuel") then
    inst.components.talker:Say("Tastes like the holidays.")
...
Edited by Bumber64
  • Thanks 1

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