Lousy_Todah Posted June 5, 2024 Share Posted June 5, 2024 Hello friends, I'm trying to make a couple of custom items for my mod that give the owner some sort of buff or debuff by just having them in their inventory, I was able to do stuff like health regen or damage multipliers pretty easily by using inst.components.inventoryitem.owner:DoWhatever, but now I'm trying to make an item that basically gives you lifesteal, and I can't figure out how. I think that the problem is that I don't know how to make the item trigger its effect when a specific action is happening, i've tried putting inst:ListenForEvent("onattack", lifesteal) in the item's fn but the lifesteal function never gets called. (I tried changing ''onattack'' with ''onputininventory'' and it works, so I know that the function is working fine.) In short I want to make an item that sits in your inventory and makes you heal by a certain amount everytime you attack something. Thank you for your help! Link to comment https://forums.kleientertainment.com/forums/topic/156532-how-to-make-passive-item-interact-with-owners-actions/ Share on other sites More sharing options...
Haruhi Kawaii Posted June 7, 2024 Share Posted June 7, 2024 On 6/5/2024 at 4:10 PM, Lousy_Todah said: Hello friends, I'm trying to make a couple of custom items for my mod that give the owner some sort of buff or debuff by just having them in their inventory, I was able to do stuff like health regen or damage multipliers pretty easily by using inst.components.inventoryitem.owner:DoWhatever, but now I'm trying to make an item that basically gives you lifesteal, and I can't figure out how. I think that the problem is that I don't know how to make the item trigger its effect when a specific action is happening, i've tried putting inst:ListenForEvent("onattack", lifesteal) in the item's fn but the lifesteal function never gets called. (I tried changing ''onattack'' with ''onputininventory'' and it works, so I know that the function is working fine.) In short I want to make an item that sits in your inventory and makes you heal by a certain amount everytime you attack something. Thank you for your help! Try inst:ListenForEvent("onhitother", lifesteal) Link to comment https://forums.kleientertainment.com/forums/topic/156532-how-to-make-passive-item-interact-with-owners-actions/#findComment-1720444 Share on other sites More sharing options...
Lousy_Todah Posted June 7, 2024 Author Share Posted June 7, 2024 (edited) @Haruhi Kawaii I tried, but still nothing, i've also tried with a couple other ListenForEvent that I found in vanilla prefabs, but anything related to attacking refuses to work! Any other idea? Edited June 7, 2024 by Lousy_Todah Link to comment https://forums.kleientertainment.com/forums/topic/156532-how-to-make-passive-item-interact-with-owners-actions/#findComment-1720999 Share on other sites More sharing options...
Haruhi Kawaii Posted June 8, 2024 Share Posted June 8, 2024 9 hours ago, Lousy_Todah said: @Haruhi Kawaii I tried, but still nothing, i've also tried with a couple other ListenForEvent that I found in vanilla prefabs, but anything related to attacking refuses to work! Any other idea? I have an idea but don't know how to do it because I'm not good at coding, it would be something like this local function lifesteal(inst) print("123") end local function topocket(inst, owner) if owner ~= nil and not owner.lifesteal then owner:ListenForEvent("onhitother", lifesteal) owner.lifesteal = true end end AddPrefabPostInit("abcde", function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:ListenForEvent("onputininventory", topocket) end) local function UpdateLifesteal(inst, data) local items = inst.components.inventory:GetItemsWithTag("abcde") if not items or #items == 0 then inst:RemoveEventCallback("onhitother", lifesteal) inst.lifesteal = false end end AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst.lifesteal = false inst:ListenForEvent("dropitem", UpdateLifesteal) UpdateLifesteal(inst) end) Link to comment https://forums.kleientertainment.com/forums/topic/156532-how-to-make-passive-item-interact-with-owners-actions/#findComment-1721272 Share on other sites More sharing options...
Lousy_Todah Posted June 8, 2024 Author Share Posted June 8, 2024 @Haruhi Kawaii Hey man! I managed to make it work! Splitting the lifesteal part of the code in two different functions was a great idea, also I figured out that why I couldn't reference the health component by using inst:ListenForEvent:onhitother, as this spefically needs you to use the combat component instead. Thank you for your help, I'll put you in the credits for my mod once it's done Link to comment https://forums.kleientertainment.com/forums/topic/156532-how-to-make-passive-item-interact-with-owners-actions/#findComment-1721356 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