Jump to content

Help: I want Health and Hungry affect Sanity


Recommended Posts

Hello, I'm new in this.
ok. I want my character to lose his sanity and run faster when he is hungry or low on health. If you have both low, both effects are more intense.
For this I made the following function:

local function XSanity (inst, data ,forceilent)
     if inst.components.hunger.current< 50 then
        if inst.components.health.current< 75 then
		   inst.components.locomotor:SetExternalSpeedMultiplier(inst, "X_speed_mod", 2)
		   inst.components.sanity.dapperness = -6
		else inst.components.health.current> 75 then
		   inst.components.locomotor:SetExternalSpeedMultiplier(inst, "X_speed_mod", 1.5)
	   	   inst.components.sanity.dapperness = -3
		end
    elseif inst.components.hunger.current> 50 then
	    if inst.components.health.current< 75 then
		   inst.components.locomotor:SetExternalSpeedMultiplier(inst, "X_speed_mod", 1.5)
		   inst.components.sanity.dapperness = -3
		else inst.components.health.current> 75 then
		   inst.components.locomotor:SetExternalSpeedMultiplier(inst, "X_speed_mod", 1)
		   inst.components.sanity.dapperness = 0.3
		end
    end
end

This was the easiest way I had to put together the code, I don't know if it can be optimized.
On the other hand, this generates a problem for me and I have my suspicions in the part of Master_postinit.

inst: ListenForEvent ("hungerdelta" , XSanity)

I would appreciate any help to fix this problem. Thanks

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