Jump to content

[SOLVED] How to make character unequip backpack when insane?


Recommended Posts

Hello, I need help :).

So, when my character goes insane i'd like him to unequip any backpack he currently has equipped.

I already have code for him not to equip any backpacks

local packs = {
	icepack = true,
	backpack = true,
	piggyback = true,
	krampus_sack = true,
	}
inst:ListenForEvent("equip", function(inst, data) 
if packs[data.item.prefab] and not inst.components.sanity:IsSane() then 
inst:DoTaskInTime(0, function(inst)
inst.components.inventory:GiveItem(data.item)
end)
inst.components.talker:Say("BaGs Be FoR bAbIeS!!!")
end
end)

I just need if someone can help me make him unequip any backpacks when he goes insane because this code just prevents him from equipping backpacks when he's already insane. I would really appreciate any kind of help, thanks a lot for reading my problem :D!!

Edited by SuperDavid
Link to comment
Share on other sites

Try

inst.components.inventory:Unequip(EQUIPSLOTS.BACK or EQUIPSLOTS.BODY)

or

local backpack --We will save here link to backpack.
if EQUIPSLOTS.BACK then --Extra Equip Slots mod
    backpack = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BACK)
    -- inst == player
else
    --Get the link:
	local try_backpack = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
    --It may be just an armor. Check it using tags:
    backpack = try_backpack and try_backpack:HasTag("backpack") and try_backpack
end
if backpack then --Found it!
    inst.components.inventory:DropItem(backpack) --Drop it!
end

 

Link to comment
Share on other sites

17 minutes ago, Maris said:

inst.components.inventory:Unequip(EQUIPSLOTS.BACK or EQUIPSLOTS.BODY)

This code would just delete the backpack

 

.This code worked great, thank you very, very much :D:D!!!!

local backpack --We will save here link to backpack.
if EQUIPSLOTS.BACK then --Extra Equip Slots mod
    backpack = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BACK)
    -- inst == player
else
    --Get the link:
	local try_backpack = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
    --It may be just an armor. Check it using tags:
    backpack = try_backpack and try_backpack:HasTag("backpack") and try_backpack
end
if backpack then --Found it!
    inst.components.inventory:DropItem(backpack) --Drop it!
end

 

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