Jump to content

[Help Needed] Sanity as Variable


Recommended Posts

I need some help with the codes for my character. I am trying to make a character that gets stronger the lower their sanity gets. I've been trying so many things that seemed logical to me while learning what the codes do in the process. This is as far as I could go with that:

local master_postinit = function(inst)
	-- choose which sounds this character will play
	inst.soundsname = "willow"
	
	-- Stats	
	inst.components.health:SetMaxHealth(150)
	inst.components.hunger:SetMax(150)
	inst.components.sanity:SetMax(10)
	
	local sanity_percent = inst.components.sanity.current -- Variation Test 2
	
	-- Damage variations
	local sanity_damage_var = sanity_percent / 10
	local sanity_damage_mult = 1.5 - sanity_damage_var
	
	-- Speed variations
	local sanity_speed_var = sanity_percent / 20
	local sanity_speed_mult = 1.25 - sanity_speed_var
	
    inst.components.combat.damagemultiplier = sanity_damage_mult -- Damage Multiplier
	inst.components.locomotor:SetExternalSpeedMultiplier(inst, "cuddlepuff_speed_mult", sanity_speed_mult) -- Speed Multiplier
	
	-- Hunger rate (optional)
	inst.components.hunger.hungerrate = 1 * TUNING.WILSON_HUNGER_RATE
	
	inst.OnLoad = onload
    inst.OnNewSpawn = onload
end

So I need some insights. Am I missing something? Am I doing it wrong? 

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