Jump to content

How to stop gaining/losing sanity from certain actions?

Recommended Posts

Is there a way to stop the player from gaining sanity from picking up flowers? The only way my character is supposed to regain sanity is by killing, so I've made him an insomniac but the flowers are a problem.


Also, I have no idea on how to stop losing sanity from eating raw meat, as he should be allowed to eat raw meat without a problem, is there a way to do this too? Thanks, and sorry for the noobness.

Link to comment
Share on other sites

There are many ways to do that.

Editing values, overriding functions, or making a reverse function occur to counteract another.


For the flower:

AddPrefabPostInit("flower", function(inst)   local old = inst.components.pickable.onpickedfn   inst.components.pickable.onpickedfn = function(inst, picker)      if picker.prefab == "MyCharacter" then         inst:Remove()      else         old(inst, picker)      end   endend)

For meat:

AddComponentPostInit("edible", function(self)   local old = self.GetSanity   function self:GetSanity(eater)      if eater.prefab == "MyCharacter" and self.inst == "meat" then         if self.inst.components.perishable          and not self.inst.components.perishable:IsStale()         and not self.inst.components.perishable:IsSpoiled() then            self.ignoremeat = 0         end      end      return self.ignoremeat or old(self, eater)   endend)
Link to comment
Share on other sites

local function onpickedfn(inst, picker)	if picker and picker.components.sanity then		picker.components.sanity:DoDelta(TUNING.SANITY_TINY)	end			inst:Remove()endinst:AddComponent("pickable")inst.components.pickable.onpickedfn = onpickedfn

This is the code in the flower prefab that gives you sanity.


If you want to strictly attach code to the master_postinit of your character, you can do it like:

local function master_postinit(inst)   inst:ListenForEvent("picksomething", function(inst, data)      if data and data.object.prefab == "flower" and inst.components.sanity then         inst.components.sanity:DoDelta(-TUNING.SANITY_TINY)      end   endend
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

  • Create New...