Eranthis Posted March 4, 2018 Share Posted March 4, 2018 (edited) Not sure how applicable this will be but basically, I have a backpack item that I'd like to also be usable as a healing item. I understand that if the backpack is carrying items and is used with said items, the items will disappear with the backpack and I was wondering how to have the items spill out when the bag is used. Right now, the template I've used is your standard backpack. The only difference so far is that the item can be stored in inventory. Edited March 5, 2018 by Eranthis Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/ Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 1 hour ago, Eranthis said: I was wondering how to have the items spill out when the bag is used. AddPrefabPostInit("healthkit", function(inst) inst:ListenForEvent("onremove", function(inst) inst.components.container:DropEverything() end) end) Not tested, but should work Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011078 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 4 minutes ago, popitup said: AddPrefabPostInit("healthkit", function(inst) inst:ListenForEvent("onremove", function(inst) inst.components.container:DropEverything() end) end) Not tested, but should work Where should this be applied? The prefab lua starts off every string set with a "local function" Or is this applied to modmain? Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011084 Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 (edited) Actually you can paste this inst:ListenForEvent("onremove", function(inst) inst.components.container:DropEverything() end) into the end of "local function fn()" function (in healthkit.lua) before "return inst" Edited March 5, 2018 by popitup Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011087 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 16 minutes ago, popitup said: Actually you can paste this inst:ListenForEvent("onremove", function(inst) inst.components.container:DropEverything() end) into the end of "local function fn()" function before "return inst" Sadly it had no effect. Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011096 Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 How you tested? Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011098 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 2 minutes ago, popitup said: How you tested? I added one grass into the backpack slot, used the item, and produced nothing. Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011100 Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 Do you use healer component? Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011103 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 2 minutes ago, popitup said: Do you use healer component? Yes Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011105 Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 Insert this in healthkit.lua before "return inst" inst.components.healer.oldHeal=inst.components.healer.Heal inst.components.healer.Heal=function(self,target) self.inst.components.container:DropEverything() return self:oldHeal(target) end Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011110 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 6 minutes ago, popitup said: Insert this in healthkit.lua before "return inst" inst.components.healer.oldHeal=inst.components.healer.Heal inst.components.healer.Heal=function(self,target) self.inst.components.container:DropEverything() return self:oldHeal(target) end That did the trick! You're a miracle worker my man. 7 minutes ago, popitup said: Insert this in healthkit.lua before "return inst" inst.components.healer.oldHeal=inst.components.healer.Heal inst.components.healer.Heal=function(self,target) self.inst.components.container:DropEverything() return self:oldHeal(target) end Although just a quick question, will this still function when the kit is being used on another player? Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011112 Share on other sites More sharing options...
Hunger Artist Posted March 5, 2018 Share Posted March 5, 2018 2 minutes ago, Eranthis said: Although just a quick question, will this still function when the kit is being used on another player? Yes, it should Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011116 Share on other sites More sharing options...
Eranthis Posted March 5, 2018 Author Share Posted March 5, 2018 (edited) 4 hours ago, Hunger Artist said: Yes, it should Sorry to pry on this issue further but for some reason my game crashes whenever I put on the item. I'll redirect you to the forum here if you're curious: Edited March 5, 2018 by Eranthis Link to comment https://forums.kleientertainment.com/forums/topic/88302-solved-coding-help-healing-item-drops-items/#findComment-1011200 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