KBID1 Posted July 22, 2023 Share Posted July 22, 2023 I'm working on a character and I want him to have a perk where his max health raises when his sanity is below 50%. I've tried searching for anything that could help and I haven't been able to find anything, I'd like to ask for some help if anyone knows how to help me. Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/ Share on other sites More sharing options...
Haruhi Kawaii Posted July 24, 2023 Share Posted July 24, 2023 On 7/22/2023 at 10:22 AM, KBID1 said: I'm working on a character and I want him to have a perk where his max health raises when his sanity is below 50%. I've tried searching for anything that could help and I haven't been able to find anything, I'd like to ask for some help if anyone knows how to help me. This code may have many problems but at least it still works Modmain Spoiler AddComponentPostInit("health", function(self) function self:Custommaxhealth(amount) if self.maxhealth ~= amount then self.maxhealth = amount self:ForceUpdateHUD(true) end end end) Yourcharacter Spoiler local function OnSanityDelta(inst, data) local sanityPercent = inst.components.sanity:GetPercent() local healthComponent = inst.components.health if not healthComponent:IsDead() then if sanityPercent < 0.5 then healthComponent:Custommaxhealth(500)---Max Health else healthComponent:Custommaxhealth(200) ---Can use TUNING here end end end ----- In the master_postinit for your character ----- inst:ListenForEvent("sanitydelta", OnSanityDelta) Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/#findComment-1653903 Share on other sites More sharing options...
KBID1 Posted July 25, 2023 Author Share Posted July 25, 2023 12 hours ago, Haruhi Kawaii said: This code may have many problems but at least it still works Modmain Hide contents AddComponentPostInit("health", function(self) function self:Custommaxhealth(amount) if self.maxhealth ~= amount then self.maxhealth = amount self:ForceUpdateHUD(true) end end end) Yourcharacter Hide contents local function OnSanityDelta(inst, data) local sanityPercent = inst.components.sanity:GetPercent() local healthComponent = inst.components.health if not healthComponent:IsDead() then if sanityPercent < 0.5 then healthComponent:Custommaxhealth(500)---Max Health else healthComponent:Custommaxhealth(200) ---Can use TUNING here end end end ----- In the master_postinit for your character ----- inst:ListenForEvent("sanitydelta", OnSanityDelta) Small issue, when I implement the code into the scripts the game seems to not work. ex: not generating a world, getting a lua error, or the character just not showing up on the character select screen at all. I have all of the code correctly implemented but the game just won't work, sorry to bother you but could you tell me what i'm doing wrong that's making this happen? Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/#findComment-1654082 Share on other sites More sharing options...
Haruhi Kawaii Posted July 25, 2023 Share Posted July 25, 2023 1 hour ago, KBID1 said: Small issue, when I implement the code into the scripts the game seems to not work. ex: not generating a world, getting a lua error, or the character just not showing up on the character select screen at all. I have all of the code correctly implemented but the game just won't work, sorry to bother you but could you tell me what i'm doing wrong that's making this happen? Can you send modmain.lua and your character file?, I will fix it for you Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/#findComment-1654095 Share on other sites More sharing options...
KBID1 Posted July 25, 2023 Author Share Posted July 25, 2023 15 minutes ago, Haruhi Kawaii said: Can you send modmain.lua and your character file?, I will fix it for you Sure here you go, and thanks a lot! modmain.lua classic.lua Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/#findComment-1654101 Share on other sites More sharing options...
Haruhi Kawaii Posted July 25, 2023 Share Posted July 25, 2023 15 minutes ago, KBID1 said: Sure here you go, and thanks a lot! modmain.lua 2.69 kB · 0 downloads classic.lua 2.87 kB · 0 downloads Here modmain.lua classic.lua Link to comment https://forums.kleientertainment.com/forums/topic/149713-raising-max-health-with-lower-sanity/#findComment-1654113 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