Jump to content

Recommended Posts

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.

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)

 

 

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 by kavaline
update the information
  • Like 1
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

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