Eranthis Posted March 10, 2018 Share Posted March 10, 2018 (edited) 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 March 10, 2018 by Eranthis Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/ Share on other sites More sharing options...
FleurDuSoleil3 Posted March 10, 2018 Share Posted March 10, 2018 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. Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/#findComment-1013479 Share on other sites More sharing options...
Goat Slice Posted March 10, 2018 Share Posted March 10, 2018 (edited) 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 March 10, 2018 by CheeseNuggets101 Added example Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/#findComment-1013484 Share on other sites More sharing options...
Eranthis Posted March 10, 2018 Author Share Posted March 10, 2018 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!~ Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/#findComment-1013522 Share on other sites More sharing options...
nicknightyx Posted March 10, 2018 Share Posted March 10, 2018 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 Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/#findComment-1013540 Share on other sites More sharing options...
FleurDuSoleil3 Posted March 11, 2018 Share Posted March 11, 2018 @nicknightyx Ah, master_postinit is part of DST code and not DS, so thank you for clarifying that's how to properly integrate it. Link to comment https://forums.kleientertainment.com/forums/topic/88532-solved-announce-after-eating-item/#findComment-1013583 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now