Earthyburt Posted May 2, 2021 Share Posted May 2, 2021 This is a bit of an extension of a previous post, but I cannot get these two functions to run. I think I am not setting up the functions properly, but I cannot find out how to set them up right. local function setHealing(owner) if self.owner ~= nil then local sanity = owner.components.sanity and owner.components.sanity.GetPercent() or 0 local currentHealth = owner.components.health and owner.components.health.current or 0 local maxHealth = owner.components.health and owner.components.health.maxhealth or 0 local self = inst.components.inventoryitem healing = sanity * (maxHealth - currentHealth) self.components.healer:SetHealthAmount(healing) end end -- I am not sure if I am doing the code above properly, so I need help. I created a post before, as stated, but I have not gotten any help at all. local function onputininventoryfn(owner) print("PickedUp") owner:ListenForEvent("sanitydelta", setHealing) end local function ondropfn(inst) owner:RemoveEventCallback("sanitydelta", setHealing) end Link to comment https://forums.kleientertainment.com/forums/topic/129538-onputininventory-function-and-ondrop-function-not-running/ Share on other sites More sharing options...
Monti18 Posted May 5, 2021 Share Posted May 5, 2021 I'm not sure if this will work for you, at least when I did a quick test, my print was run. instead of local function onputininventoryfn(owner) owner:ListenForEvent("sanitydelta", setHealing) use local function onputininventoryfn(inst, owner) inst:ListenForEvent("sanitydelta", setHealing, owner) See also this post to understand why: Spoiler This is my code that I used that worked: inst.components.inventoryitem.onputininventoryfn = function(inst, player) inst:ListenForEvent("healthdelta", function() print("onputininventoryfn") end, player) end 1 Link to comment https://forums.kleientertainment.com/forums/topic/129538-onputininventory-function-and-ondrop-function-not-running/#findComment-1456404 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now