Jump to content

Recommended Posts

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 by Eranthis
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

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?

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 by popitup
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.

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

 

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?

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 by Eranthis

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...