Jump to content

Recommended Posts

Having trouble wrapping my head around tying an announcer after having a character eating a particular object.
I grabbed the code from the tallbird egg thinking it would help but sadly I'm getting no outcome.

local function OnEaten(inst, eater)
    if eater.components.talker ~= nil then
        eater.components.talker:Say(GetString(eater, "ANNOUNCERNAME") )
    end
end

Is there anything else that needs to be defined?

Edited by Eranthis

I am unsure how much the code differs for DST, but in Don't Starve I use this for my custom character:

    inst:ListenForEvent("oneat", function(inst, data)
 if data.food.prefab == "carrot" then
  inst.components.talker:Say("DELICIOUS!")
 end
end)

Just replace "carrot" with whatever you're eating, and "DELICIOUS!" with whatever you're saying.

If you're referencing the tallbird egg code in dst, you'll just need this line in your fn function of your item prefab:

 inst.components.edible:SetOnEatenFn(OnEaten)

If it's in your character.lua so it only happens for only that character then "if food.prefab == "youritem" then" in place of or above the "if eater.components.talker ~= nil" then should work fine!

A quick example of one in a character.lua like this:

local function OnEaten(inst, food)
    if food.prefab == "prefab" then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_EATQUOTE"))
    end
end

and a inst.components.eater:SetOnEatFn(OnEaten) in the master_postinit

Edited by CheeseNuggets101
Added example
2 hours ago, Aquafox333 said:

I am unsure how much the code differs for DST, but in Don't Starve I use this for my custom character:

    inst:ListenForEvent("oneat", function(inst, data)
 if data.food.prefab == "carrot" then
  inst.components.talker:Say("DELICIOUS!")
 end
end)

Just replace "carrot" with whatever you're eating, and "DELICIOUS!" with whatever you're saying.

Didn't seem to work.

2 hours ago, CheeseNuggets101 said:

If you're referencing the tallbird egg code in dst, you'll just need this line in your fn function of your item prefab:

 inst.components.edible:SetOnEatenFn(OnEaten)

If it's in your character.lua so it only happens for only that character then "if food.prefab == "youritem" then" in place of or above the "if eater.components.talker ~= nil" then should work fine!

A quick example of one in a character.lua like this:


local function OnEaten(inst, food)
    if food.prefab == "prefab" then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_EATQUOTE"))
    end
end

and a inst.components.eater:SetOnEatFn(OnEaten) in the master_postinit

And that did the trick, thanks!~

3 hours ago, Aquafox333 said:

I am unsure how much the code differs for DST, but in Don't Starve I use this for my custom character:

    inst:ListenForEvent("oneat", function(inst, data)
 if data.food.prefab == "carrot" then
  inst.components.talker:Say("DELICIOUS!")
 end
end)

Just replace "carrot" with whatever you're eating, and "DELICIOUS!" with whatever you're saying.

The code worked for me, just have to put it under master_postinit

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