kavaline Posted February 2, 2016 Share Posted February 2, 2016 I'm making a weapon that, if you haven't the tag "spiderwhisperer", you can't equip. I tried it: local function OnEquip(inst, owner) if owner:HasTag("spiderwhisperer") then owner.AnimState:OverrideSymbol("swap_object", "swap_web_a", "swap_web_a") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") else owner.components.inventory:DropItem(inst) owner.components.talker:Say("I don't have spider skills!") end end But the weapon remains in my weapon slot. Based on one reply of DarkXero, I tried it: local function getoff(inst) local player = inst:GetNearestPlayer(true) local loot = SpawnPrefab("web_a") player.components.inventory:GiveItem(loot) end local function OnEquip(inst, owner) if owner:HasTag("spiderwhisperer") then owner.AnimState:OverrideSymbol("swap_object", "swap_web_a", "swap_web_a") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") else getoff(inst) owner.components.talker:Say("I don't have spider skills!") end end But the weapon remains again in my weapon slot... Lots of others codes that I tried, give me texture error. My final objective is: others players can pickup the item, but can't equip or use him. I think the best option is put something in equipping event, but if someone have other idea, I accept. Link to comment https://forums.kleientertainment.com/forums/topic/63683-unequip-a-weapon-when-equipping/ Share on other sites More sharing options...
Muche Posted February 2, 2016 Share Posted February 2, 2016 Looking at Inventory:Equip, it seems that Equippable:Equip (which calls your function) is called before the item is actually in the inventory (so your dropping has no effect). You could try inst:DoTaskInTime(0, function() if owner and owner.components and owner.components.inventory then owner.components.inventory:DropItem(inst) if owner.components.talker then owner.components.talker:Say("I don't have spider skills!") end end end) Link to comment https://forums.kleientertainment.com/forums/topic/63683-unequip-a-weapon-when-equipping/#findComment-716662 Share on other sites More sharing options...
kavaline Posted February 2, 2016 Author Share Posted February 2, 2016 (edited) 27 minutes ago, Muche said: Looking at Inventory:Equip, it seems that Equippable:Equip (which calls your function) is called before the item is actually in the inventory (so your dropping has no effect). You could try inst:DoTaskInTime(0, function() if owner and owner.components and owner.components.inventory then owner.components.inventory:DropItem(inst) if owner.components.talker then owner.components.talker:Say("I don't have spider skills!") end end end) Awesome, work perfectly! Thanks so much! Now, when I pick the item with my weapon slot empty, the item is dropped. I'm trying some codes here, and after, will post all the the code. I think it will help other people. EDIT: The full code: local function OnEquip(inst, owner) if owner:HasTag("YourTag") then --Set your custom tag for configure who can use the item. owner.AnimState:OverrideSymbol("swap_object", "swap_your_item", "swap_your_item") --Adjust here owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") else inst:DoTaskInTime(0, function() if owner and owner.components and owner.components.inventory then owner.components.inventory:GiveItem(inst) if owner.components.talker then owner.components.talker:Say("Dropping quote.") end end end) end end Edited February 2, 2016 by kavaline update the information 1 Link to comment https://forums.kleientertainment.com/forums/topic/63683-unequip-a-weapon-when-equipping/#findComment-716668 Share on other sites More sharing options...
Muche Posted February 2, 2016 Share Posted February 2, 2016 That's because Pickup action checks if it's possible to equip it (i.e. hand is empty). If it's not possible, the item goes to the inventory. Link to comment https://forums.kleientertainment.com/forums/topic/63683-unequip-a-weapon-when-equipping/#findComment-716678 Share on other sites More sharing options...
kavaline Posted February 2, 2016 Author Share Posted February 2, 2016 1 hour ago, Muche said: That's because Pickup action checks if it's possible to equip it (i.e. hand is empty). If it's not possible, the item goes to the inventory. Yes, instead of drop the item, putting him in the inventory solves nicely =] Solving via Pickup method takes more time, and knowledge that I don't have now... The dropping option will solve my other problem Link to comment https://forums.kleientertainment.com/forums/topic/63683-unequip-a-weapon-when-equipping/#findComment-716734 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