Jump to content

How to have an item that detects your sanity and gives/deducts sanity based on it?


Recommended Posts

I'm attempting to make an item for my character where in it can detect my characters sanity, in such that if the sanity of the character is above 50%, it will give a small amount of sanity (similar to the garland and parasol),  but if the character's sanity is below 50%, then it will reduce a small amount of sanity (similar to the sanity loss at night)

so far I've tried:

local function sanitycheck(inst)

  if owner.sanity = >= 50 then
    inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
  else
	inst.components.equippable.dapperness = TUNING.CRAZINESS_MED
  end
end

and putting it under local function Onequip:

local function OnEquip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "swap_ella", "swap_ella")
    owner.AnimState:Show("ARM_carry")
    owner.AnimState:Hide("ARM_normal")

    if owner.sanity = >= 50 then
    inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL
  else
	inst.components.equippable.dapperness = TUNING.CRAZINESS_MED
  end
end

but neither works.

 Could anyone give some advice on how to fix this please? Thank you

Link to comment
Share on other sites

What I would suggest try taking a look at the onemanband.lua script and see how they use equippable.dapperfn, since it calculates how much sanity you lose based on how many followers you currently have. You can just make a similar function but instead of checking for followers, check for sanity levels instead and return the intended values accordingly. In the equippable component, dapperfn overrides dapperness, so all you have to worry about is returning the proper value with your custom dapperfn and you should be good.

Hope this helps :) 

EDIT: And yeah, @ptr is 100% right in that it should be "owner.components.sanity.current >= 50"

Edited by w00tyd00d
Link to comment
Share on other sites

I think from what w00t said, it should go like:

local function CalcDapperness(inst, owner)
   if owner.components.sanity:GetPercent() > .5 then
     return TUNING.DAPPERNESS_SMALL
   elseif owner.components.sanity:GetPercent() <= .5 then
     return -TUNING.DAPPERNESS_SMALL
   
end
end

--then in the local fn
inst.components.equippable.dapperfn = CalcDapperness --this is how its implemented in the onemanband.lua, basically you can assign any "name" to the 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...