Schulliya Posted September 17, 2021 Share Posted September 17, 2021 (edited) I'm having a hard time trying to figure out how do I make armor get dropped when a weapon is equipped. I could drop the armor in the OnEquip function of the weapon, but what about when the weapon is already equipped and the player tries to equip an armor? The code is like this, inside myweapon.lua : local function UnequipArmor(inst) local itemEquipado = inst.components.inventoryitem.owner.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if inst:HasTag("GunEquipped") and itemEquipado and not itemEquipado:HasTag("backpack") then inst.components.inventoryitem.owner.components.inventory:DropItem(itemEquipado) end end and inside OnEquip, I call this function. Everything is working fine. I just need to know: how do I make the armor drop while the weapon is equipped, not just while equipping the weapon? Thanks in advance! Edited September 17, 2021 by Schulliya Link to comment https://forums.kleientertainment.com/forums/topic/133737-how-do-i-make-a-weapon-identify-when-an-armor-is-equipped/ Share on other sites More sharing options...
Monti18 Posted September 18, 2021 Share Posted September 18, 2021 I think in this case it's better to go with a ListenForEvent that your character receives. local function CheckIfUnequipArmor(inst,data) if data and inst.components.inventory then if data.eslot == EQUIPSLOTS.BODY and not data.item:HasTag("backpack") then inst.components.inventory:Unequip(EQUIPSLOTS.BODY) end end end --onequip function inst:ListenForEvent("equip",CheckIfUnequipArmor,owner) --onunequip function inst:RemoveEventCallback("equip",CheckIfUnequipArmor,owner) If you add this to your weapon prefab it should work as you want it to By adding the argument owner at the end of the listenforevent, we add the listenforevent to the owner, so your character. That means each time you will equip something, this function will run and unequip it if it's an armor. 1 Link to comment https://forums.kleientertainment.com/forums/topic/133737-how-do-i-make-a-weapon-identify-when-an-armor-is-equipped/#findComment-1496127 Share on other sites More sharing options...
Schulliya Posted September 19, 2021 Author Share Posted September 19, 2021 17 hours ago, Monti18 said: I think in this case it's better to go with a ListenForEvent that your character receives. local function CheckIfUnequipArmor(inst,data) if data and inst.components.inventory then if data.eslot == EQUIPSLOTS.BODY and not data.item:HasTag("backpack") then inst.components.inventory:Unequip(EQUIPSLOTS.BODY) end end end --onequip function inst:ListenForEvent("equip",CheckIfUnequipArmor,owner) --onunequip function inst:RemoveEventCallback("equip",CheckIfUnequipArmor,owner) If you add this to your weapon prefab it should work as you want it to By adding the argument owner at the end of the listenforevent, we add the listenforevent to the owner, so your character. That means each time you will equip something, this function will run and unequip it if it's an armor. thanks! Link to comment https://forums.kleientertainment.com/forums/topic/133737-how-do-i-make-a-weapon-identify-when-an-armor-is-equipped/#findComment-1496302 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