Jump to content

Need help with making my character have different sprites on low sanity


Chinken

Recommended Posts

local SANITY_THRESHOLD = 30 -- The amount of sanity the character needs to transform.

inst.tranformed = false

local function SanityTransform(inst)
      if inst.components.sanity
            if not inst.transformed and  inst.components.sanity.current <= SANITY_THRESHOLD
                inst.transformed = true
                -- Code to Tranform
            elseif  inst.transformed then
                inst.transformed = false
                -- Code to Untransform.
            end
      end
end
    
inst:ListenForEvent("sanitydelta",  SanityTransform)

Maybe this doesn't apply the transformation in world load, then you'll need to save the variable inst.transformed in the inst.OnSave fn and check it in the inst.OnLoad fn. Or simple call the SanityTransform fn in entity creation (below Listen to Event), and if it doesn't work, try call it in inst.OnLoadPostPast fn.

Link to comment
Share on other sites

3 hours ago, Leonidas IV said:

local SANITY_THRESHOLD = 30 -- The amount of sanity the character needs to transform.

inst.tranformed = false

local function SanityTransform(inst)
      if inst.components.sanity
            if not inst.transformed and  inst.components.sanity.current <= SANITY_THRESHOLD
                inst.transformed = true
                -- Code to Tranform
            elseif  inst.transformed then
                inst.transformed = false
                -- Code to Untransform.
            end
      end
end
    
inst:ListenForEvent("sanitydelta",  SanityTransform)

Maybe this doesn't apply the transformation in world load, then you'll need to save the variable inst.transformed in the inst.OnSave fn and check it in the inst.OnLoad fn. Or simple call the SanityTransform fn in entity creation (below Listen to Event), and if it doesn't work, try call it in inst.OnLoadPostPast fn.

Thank youu, although it's still unclear to me how do I make my character change textures after transforming, any help?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...