Jump to content

Recommended Posts

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.

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)

 

 

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?

screenshot 3.jpg

screenshot 2.jpg

screenshot 1.jpg

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?

screenshot 3.jpg

screenshot 2.jpg

screenshot 1.jpg

Can you send modmain.lua and your character file?, I will fix it for you

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
×
  • Create New...