Jump to content

[Solved] Get no sanity from picking flowers


Recommended Posts

This is probably one of the most asked questions on forum, but I have no idea how to do it except copypaste flower.lua & edit the code (which I think's not good)...since I don't think it's possible to edit local functions with prefabpostinit or is it? And I can't find anything with the search tool...

Edited by SuperDavid
Link to comment
Share on other sites

Put this in modmain.lua:

AddPrefabPostInit("flower", function(inst)
	local ic = inst.components
	
	local _OnPickedFn = ic.pickable.onpickedfn
	ic.pickable.onpickedfn = function(self, picker)
		-- 'do things here'
		
		return _OnPickedFn(self, picker)
	end
	
end)

...or alternatively...

AddPrefabPostInit("flower", function(inst)
	local ic = inst.components
	
	local _Pick = ic.pickable.Pick
	ic.pickable.Pick = function(self, picker)
		-- 'do things here'
		
		return _Pick(self, picker)
	end
	
end)
Edited by JohnWatson
Link to comment
Share on other sites

edit: whoops didn't see JohnWatson's reply - didn't load on my browser ^^'

Could adjust the function through this hypothetically:

  Hide contents

local function cust_onpickedfn()

-- change this bit for all characters or encapsulate in "if statement" to check for a specific character/list 
-- or value
    if picker and picker.components.sanity then
        picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end

-- [[ e.g pseudo code

if prefab ~= "charactername/value_name" then

    if picker and picker.components.sanity then
        picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
    end

end

]]

    if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    if not inst.planted then
        TheWorld:PushEvent("beginregrowth", inst)
    end

    inst:Remove()
end

prefabpostinit(flower)

    inst.components.pickable.onpickedfn = cust_onpickedfn

end

-- same for "flower_rose"

-- same for "planted_flower"

 

 

Edited by MorickClive
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...