Jump to content

Recommended Posts

I'm assuming at the moment your character is losing health when they lose sanity?

If you want it to be a linear loss of health, all you'd need to do is multiply the players max health by their sanity percentage. A script like this might work if you attach it to whatever the sanity delta event is called (I can't remember at the moment).

local function SanityGaming(inst) -- inst should be whatever entity your effecting, probably a character.
  	local NormalHP = 150 -- Replace 150 with whatever your characters HP would be at 100% sanity.
	local Sans = inst.components.sanity:GetPercent() -- This will be a decimal representative of your characters current sanity level. 
	
	inst.components.health:SetMaxHealth(NormalHP * Sans) -- This sets your characters max health to the max HP multiplied by the sanity level.
end

This isn't the most elegant solution, as using something like SetPenalty instead of SetMaxHealth would be a better visual indicator, I just don't know how to use it, so you may want to look into that instead.

Also this kind of kills your character if they drop to 0% sanity, as their max health gets set to MaxHP * 0.

Finally, this might crash since I didn't test this at all and I have a bad habit of forgetting small things, let me know if you need any help.

Basically, his max health will decrease if his sanity is less than certain thresholds. If his sanity is above those thresholds, then nothing will happen to his max health

Basically, his max health will decrease if his sanity is less than certain thresholds. If his sanity is above those thresholds, then nothing will happen to his max health. Here is some psuedocode as an example

 

If (sanity < 75 (not percent) ) then

Set max health to 125

Else:

Set Max Health to 175

-------------

This is hard to explain, but what I am concerned with is when my character loses MaxHealth when he respawns via florid postern/tell-tale heart, then he suffers for the sanity-health penalty but then he recovers from it. Would the maxhealth penalty from florid posterns be affected, or would they be porportional to how his maxhealth changes via sanity. 

On 1/6/2021 at 1:43 PM, TheSkylarr said:

I'm assuming at the moment your character is losing health when they lose sanity?

If you want it to be a linear loss of health, all you'd need to do is multiply the players max health by their sanity percentage. A script like this might work if you attach it to whatever the sanity delta event is called (I can't remember at the moment).


local function SanityGaming(inst) -- inst should be whatever entity your effecting, probably a character.
  	local NormalHP = 150 -- Replace 150 with whatever your characters HP would be at 100% sanity.
	local Sans = inst.components.sanity:GetPercent() -- This will be a decimal representative of your characters current sanity level. 
	
	inst.components.health:SetMaxHealth(NormalHP * Sans) -- This sets your characters max health to the max HP multiplied by the sanity level.
end

This isn't the most elegant solution, as using something like SetPenalty instead of SetMaxHealth would be a better visual indicator, I just don't know how to use it, so you may want to look into that instead.

Also this kind of kills your character if they drop to 0% sanity, as their max health gets set to MaxHP * 0.

Finally, this might crash since I didn't test this at all and I have a bad habit of forgetting small things, let me know if you need any help.

Sorry for late reply since I didn't get around to coding until today, but the code I created in specific crashes the game.


	--[[
	local function InsanityHealthPenalty
		if inst.components.sanity.current <= 11.25 then
		inst.components.health:SetMaxHealth(75)
		elseif inst.components.sanity.current <= 37.5 then
		inst.components.health:SetMaxHealth(125)
		elseif inst.components.sanity.current <= 75 then
		inst.components.health:SetMaxHealth(150)
		else
		inst.components.health:SetMaxHealth(175)
		end
	end
	]]--

Crash log said something about open parenthesis ( 

On 1/11/2021 at 7:07 PM, Earthyburt said:

Sorry for late reply since I didn't get around to coding until today, but the code I created in specific crashes the game.



	--[[
	local function InsanityHealthPenalty
		if inst.components.sanity.current <= 11.25 then
		inst.components.health:SetMaxHealth(75)
		elseif inst.components.sanity.current <= 37.5 then
		inst.components.health:SetMaxHealth(125)
		elseif inst.components.sanity.current <= 75 then
		inst.components.health:SetMaxHealth(150)
		else
		inst.components.health:SetMaxHealth(175)
		end
	end
	]]--

Crash log said something about open parenthesis ( 

Simple mistake, whenever you define a function, you need to put a parenthesis after you name it, with whatever variables you need to pass into it inside them, so instead of local function InsanityHealthPenalty, it should be local function InsanityHealthPenalty(inst). Keep in mind, it will only pull these variables, in this case inst, from the thing that called it, so if you just randomly call InsanityHealthPenalty, the game will probably crash.

Also, sorry for the late reply. I haven't been on the forums lately due to development burnout.

  • Thanks 1

@Earthyburt
I've done something like this.

if inst.components.Health:GetPercentWithPenalty() <= 0.25 then  --25%
	inst.components.Health:SetMaxHealth(###)
end

This may work, but you'll need to call it somehow:

inst.task = inst:DoPeriodicTask(0.5,change_max_health)  --Controls the player's health.

-and I suspect this will affect the player's current health value, maybe setting it to max, or stretching, as though it were a percent value.

Hope this helps!  I use code like this to adjust my player's speed.

Edited by FurryEskimo

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