Kooby Posted August 25, 2016 Share Posted August 25, 2016 (edited) I want to make a character that gets increasing healing from Sweet Foods (Taffy, Berries etc.) I have the script in my character's code as local function oneat(inst, food) if food and food.components.edible and food.prefab == "food" then inst.components.health:DoDelta(amounthealed) Taffy normally deals 3 damage when eaten, so i scripted it as if food and food.components.edible and food.prefab == "taffy" then inst.components.health:DoDelta(13) So it heals by 10, and the extra 3 to counteract the health loss, however i tried eating Taffy, and didn't seem to heal me at all, is there something i did wrong? Edited August 25, 2016 by Kooby Link to comment Share on other sites More sharing options...
Serpens Posted August 25, 2016 Share Posted August 25, 2016 (edited) no, this code snippet should be correct. I think you should add some print statements all over you code. print("test test, is this code even called?") if food print("testing the food with prefab "..tostring(food.prefab)) if food and food.components.edible and food.prefab == "taffy" then inst.components.health:DoDelta(13) print("taffy should do health now") end and after that take a look at you client_log, or do "Ctrl + L " while running the game, to see the print statements. After you found out, which part is not called and you fixed it, of course you can remove the prints. Edited August 25, 2016 by Serpens Link to comment Share on other sites More sharing options...
. . . Posted August 25, 2016 Share Posted August 25, 2016 (edited) 12 hours ago, Kooby said: I want to make a character that gets increasing healing from Sweet Foods (Taffy, Berries etc.) inst:ListenForEvent("oneat", function(inst, data) if data.food.prefab == "berries" then -- berries. inst.components.health:DoDelta(5) -- Change number to what you want. inst.components.talker:Say("Berries are so nice!") elseif data.food.prefab == "taffy" then -- taffy. inst.components.health:DoDelta(13) inst.components.talker:Say("Mmm!I love taffy~!") end end) Put this code in your master_postinit. Edited August 25, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Lumina Posted August 25, 2016 Share Posted August 25, 2016 18 minutes ago, SuperDavid said: elseif data.food.prefab == "humanmeat" then -- taffy. Theses taffies look strange. Not sure i want to eat them. Link to comment Share on other sites More sharing options...
. . . Posted August 25, 2016 Share Posted August 25, 2016 2 hours ago, Lumina said: Theses taffies look strange. Not sure i want to eat them. Oops, forgot to change that xD... Link to comment 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