Jump to content

SW Character: Item shows in handslot after being force-removed


Recommended Posts

So a Shipwrecked character I'm currently working on is unable to equip poison weapons. Here's the code I'm using in the character's .lua prefab:

local disallowed_equipment = {
    "blowdart_poison",
    "speargun_poison",
	"spear_poison",
	}

local function RefusePoison (inst, data)
    local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
    if table.contains(disallowed_equipment, item.prefab) then
		inst.components.inventory:Unequip(EQUIPSLOTS.HANDS)
		inst.components.inventory:GiveItem(item)
    end
end

This is called by:

inst:ListenForEvent("equip", RefusePoison)

It works, it'll automatically unequip any of the listed items after equipping them and put them back in the character's inventory. But the problem I'm having is that, when it does so, some leftover duplicate of the item remains in their hand slot and has the "right-click to equip" indicator when hovered over. But it's not an actual item, it's not actually held by the character, can't be used or clicked to move it or unequip it, it's just... an image, I think? Here's what I mean.

fzpUsQ2.jpg

You can see the spear has been moved into the character's inventory, and the character's not holding anything in their hands. And yet the poison spear shows up in the hand slot for some reason. Anyone have any idea what might be causing this? Am I doing something wrong? The code works as intended, functionally, but I'd very much like to have this little bit fixed as well.

Link to comment
Share on other sites

you do have:

inst.components.inventory:Unequip(EQUIPSLOTS.HANDS)
inst.components.inventory:GiveItem(item)

which means ur item is getting unequipped in the first line

but you're also giving urself the item again in the second line. if you remove the second line, i think it should work fine.

Link to comment
Share on other sites

Just double checked to see if that fixed it, but that line is there because if I remove it, the spear (or other poison equipment) just vanishes from existence when trying to equip it, but the image still remains in the hand slot with or without that line. That line isn't re-equipping the item, it's just putting it back in the inventory so it doesn't disappear.

Link to comment
Share on other sites

2 hours ago, MaiTerra said:

Just double checked to see if that fixed it, but that line is there because if I remove it, the spear (or other poison equipment) just vanishes from existence when trying to equip it, but the image still remains in the hand slot with or without that line. That line isn't re-equipping the item, it's just putting it back in the inventory so it doesn't disappear.

Are you sure? I think giving an item automatically equips it...

Link to comment
Share on other sites

On 5/2/2016 at 11:26 AM, Mobbstar said:

Are you sure? I think giving an item automatically equips it...

Just tried testing it to double check. I changed the line and added the variable so it would give the player an axe after unequipping the poison weapon. The result is that the poison weapon is unequipped, vanishes from existence but an image of it still remains in the hand slot, and an axe is added to the player's inventory but is not equipped. So I'm very certain that line isn't the cause, plus like I mentioned above, the issue still happens if I remove the line entirely but the item that tried to equip disappears.

Link to comment
Share on other sites

4 hours ago, Aquaterion said:

 add this


item:PushEvent("imagechange")

below this


inst.components.inventory:Unequip(EQUIPSLOTS.HANDS)
inst.components.inventory:GiveItem(item)

it should work.

Doesn't seem to have any effect after testing it out, the issue still occurs.

Link to comment
Share on other sites

local disallowed_equipment = {
	"blowdart_poison",
	"speargun_poison",
	"spear_poison",
}

local function RefusePoison(inst, data)
	local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if table.contains(disallowed_equipment, item.prefab) then
		inst:DoTaskInTime(0, function(inst)
			inst.components.inventory:Unequip(EQUIPSLOTS.HANDS)
			inst.components.inventory:GiveItem(item)
		end)
	end
end

 

Link to comment
Share on other sites

6 hours ago, DarkXero said:

local disallowed_equipment = {
	"blowdart_poison",
	"speargun_poison",
	"spear_poison",
}

local function RefusePoison(inst, data)
	local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if table.contains(disallowed_equipment, item.prefab) then
		inst:DoTaskInTime(0, function(inst)
			inst.components.inventory:Unequip(EQUIPSLOTS.HANDS)
			inst.components.inventory:GiveItem(item)
		end)
	end
end

 

Heyy, that works, problem solved. Awesome, thanks!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...