Jump to content

Little help needed on a few script things!


Recommended Posts

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 by Kooby
Link to comment
Share on other sites

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 by Serpens
Link to comment
Share on other sites

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