Goregonzola Posted June 29, 2022 Share Posted June 29, 2022 Hey there! I have a perk for one of my older characters that I wanted to revisit for a quick fix, but it seems like my programming skills hit another brick wall with logical thinking. I have three different consumables, and they're supposed to work like a coinflip when they're consumed: either double the consumer's corresponding stat (one consumables for each stat), or do absolutely nothing. It do works well with Sanity and Hunger, but it just never triggers for Health. Here's the Health version: Spoiler local function DoubleOrNothing(inst,eater) if eater then local success = math.random() < 0.5 if success then if eater.components.health then local old_max = eater.components.health.currenthealth eater.components.health.currenthealth = old_max * 2 end end end end inst.components.edible:SetOnEatenFn(DoubleOrNothing) and the Hunger Version: Spoiler local function DoubleONothing(inst,eater) if eater then local success = math.random() < 0.5 if success then if eater.components.hunger then local old_max = eater.components.hunger.current eater.components.hunger.current = old_max * 2 end end end end inst.components.edible:SetOnEatenFn(DoubleONothing) The solution is probably something truly trivial, but I just can't find it. Thanks in advance! Link to comment https://forums.kleientertainment.com/forums/topic/141312-perk-works-with-sanity-and-hunger-but-not-with-health/ Share on other sites More sharing options...
-LukaS- Posted June 29, 2022 Share Posted June 29, 2022 I tested out your code snippet and it worked for me. It's possible the error is somewhere else in the file. Link to comment https://forums.kleientertainment.com/forums/topic/141312-perk-works-with-sanity-and-hunger-but-not-with-health/#findComment-1580406 Share on other sites More sharing options...
Goregonzola Posted June 29, 2022 Author Share Posted June 29, 2022 I originally tested it with the stat values set to zero like this: Spoiler inst:AddComponent("edible") inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible.sanityvalue = 0 inst.components.edible:SetOnEatenFn(DoubleOrNothing) That way it didn't work at all, but once I removed the value lines above the SetOnEaten trigger, it do triggers the event, but without them, it also have a constant Hunger and Health value of 10, what I don't really want. What's the next step in this case? Link to comment https://forums.kleientertainment.com/forums/topic/141312-perk-works-with-sanity-and-hunger-but-not-with-health/#findComment-1580417 Share on other sites More sharing options...
-LukaS- Posted June 29, 2022 Share Posted June 29, 2022 Tried it with: inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible.sanityvalue = 0 And it still worked. There must be something else that causes it to not work Link to comment https://forums.kleientertainment.com/forums/topic/141312-perk-works-with-sanity-and-hunger-but-not-with-health/#findComment-1580428 Share on other sites More sharing options...
Goregonzola Posted July 22, 2022 Author Share Posted July 22, 2022 It's me! The Article Necromancer! I just can 't find the solution to the problem. I added the item's lua file and the whole character's package to whom the item belongs to. If somebody's able to identify the problem, I can thank it with a heart reaction. luck_health.lua magicienne4.rar Link to comment https://forums.kleientertainment.com/forums/topic/141312-perk-works-with-sanity-and-hunger-but-not-with-health/#findComment-1587663 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