Jump to content

How do you get the game to check your sanity level?


Recommended Posts

Hello, currently I am trying to create a mechanic for a character that, the more insane the character the more damage, and past a certain level of sanity will start emitting an insanity aura.

local function getstrength(inst)
    local dmgmult = 0.5
    if currentsanity <= 50 then
        dmgmult = 4
    elseif currentsanity <= 100 then
        dmgmult = 2.5
    elseif currentsanity <= 175 then
        dmgmult = 1.5
    elseif currentsanity <= 225  then
        dmgmult = 1
    end
[--] 
end

local sanityaura_radius = 10

local function sanityaura(inst)
    if current <= 50 then
        inst:AddComponent("sanityaura") 
        inst.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE
    elseif current <= 100 then
        inst:AddComponent("sanityaura")
        inst.components.sanityaura.aura = -TUNING.SANITYAURA_MED
    elseif current <= 175 then
        inst:AddComponent("sanityaura")
        inst.components.sanityaura.aura = -TUNING.SANITYAURA_SMALL
    elseif sanity <= 225 then
        inst.RemoveComponent("sanityaura")
    end

end

While I am not sure about the sanity aura functioning or not yet (haven't tested it with friends) the code for the damage multiplier doesn't seem to work. Can anyone point out why? I've tried "sanity" "current" "currentsanity" but none of them work

Link to comment
Share on other sites

should be inst.components.sanity.current, or is that not what ur looknig for?

under local dmgmult = 0.5 do

local currentsanity = inst.components.sanity.current

also, I reworked ur sanityaura function to check for things

 local function sanityaura(inst)
	local auratuning = 0
	local currentsanity = inst.components.sanity.current
	local hasaura = inst.components.sanityaura
    if currentsanity <= 50 then
        auratuning = -TUNING.SANITYAURA_LARGE
    elseif currentsanity <= 100 then
        auratuning = -TUNING.SANITYAURA_MED
    elseif currentsanity <= 175 then
        auratuning = -TUNING.SANITYAURA_SMALL
    elseif currentsanity <= 225 then
        auratuning = 0
    end
	if auratuning ~= 0 then
		if not hasaura then
			inst:AddComponent("sanityaura") 
		end
		inst.components.sanityaura.aura = auratuning
	elseif hasaura then
		inst:RemoveComponent("sanityaura")
	end
end 

 

Edited by Aquaterion
Link to comment
Share on other sites

I tested out the

local function getstrength(inst)
    local dmgmult = 0.5
    local currentsanity = inst.components.sanity.current
    if currentsanity <= 50 then
        dmgmult = 4
    elseif currentsanity <= 100 then
        dmgmult = 2.5
    elseif currentsanity <= 175 then
        dmgmult = 1.5
    elseif currentsanity <= 225  then
        dmgmult = 1
    end
    inst.components.combat.damagemultiplier = dmgmult 

by using a killer bee and a spear, at no matter at what level of sanity it took 6 hits to kill the bee.

Link to comment
Share on other sites

1 minute ago, Digidragon said:

I tested out the

local function getstrength(inst)
    local dmgmult = 0.5
    local currentsanity = inst.components.sanity.current
    if currentsanity <= 50 then
        dmgmult = 4
    elseif currentsanity <= 100 then
        dmgmult = 2.5
    elseif currentsanity <= 175 then
        dmgmult = 1.5
    elseif currentsanity <= 225  then
        dmgmult = 1
    end
    inst.components.combat.damagemultiplier = dmgmult 

by using a killer bee and a spear, at no matter at what level of sanity it took 6 hits to kill the bee.

where are u calling the getstrength function?

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