Destroy currently equipped item

Hi! 


Is it possible to destroy currently equipped item from pre-defined slot?


What I am trying to do: Player is traveling through the cave and he steps on trap. Trap deal damage and additionally destroys currently equipped item, let's say boots. 


I'm using Yanfly Engine Ace - Ace Equip Engine v1.06 script, which makes multiple equip slots. And I need script line similiar to this:


$game_party.members[0].change_equip(0,$data_nil)


But instead of taking off item from slot 0 I need it to permanently destroy it. Like in Event commands/Party/change armor - decrease by 1. 


Is it possible via scripts? I checked script calls list but this one is missing...


It's too much work to do this via events and variables for every item out there. 


Thank you, and sorry for my bad english.
Of course you can do it via script call.



First of all check which item is equipped in a specific slot using this:

Spoiler
@item_to_remove = $game_actors[number].equips[slot].id

number is your actor id and slot is the equip slot containing the item you want to remove.



Then remove it using this:

Spoiler
$game_party.gain_item(@item_to_remove, -1, true)

This will delete the item stored before even if it is equipped. If you want to be sure that your player's equipment gets destroyed then remove it from your equipped items first. You can do that using:

Spoiler
$game_actors[number].equips[slot].object = nil


Your final event should look like this:

Spoiler
@item_stored = $game_actors[numbers].equips[slot]

#use this if you want to remove an armor
@item_to_remove = $data_armors[@item_stored.id]

#use this one if you want to remove a weapon
@item_to_remove = $data_weapons[@item_stored.id]

@item_stored.object = nil
$game_party.gain_item(@item_to_remove, -1, true)



NOTE: I didn't test it and I won't be able to do it until tomorrow. Let me know if there are problems.


EDIT: I modified the code in the last spoiler. It should now work without errors.
Thank you, It works. 


However I need to put it in conditional branch to check if slot is not empty. Because if it is, we got an error. 


Also I don't think your de-equipping works. This line:

Spoiler
$game_actors[number].equips[slot].object = nil

I don't have an idea why yours not working, maybe someone can fix it for future generations?


It gives this error:

Spoiler
Script 'Game_Interpreter' line 1411: NoMethodError occurred.


undefined method `object=' for nil:NilClass
 

It's okay for me as I can use this: (Well, it's a bit confusing as party members id's starts with 0 and actors starts with 1)

Spoiler
$game_party.members[0].change_equip(6,$data_nil)







So the whole thing looks like this:

Spoiler
Conditional Branch: Script: !$game_actors[1].equips[6].nil?


Script: 



@item_stored = $game_actors[1].equips[6]
@item_to_remove = $data_armors[@item_stored.id]
$game_party.gain_item(@item_to_remove, -1, true)
$game_party.members[0].change_equip(6,$data_nil)
$game_actors[1].equips[6].object = nil
@item_stored = nil


Branch End



So big thanks to you for answering my question and helping me! Thank you! 
It is not working because I was too sleepy and I put it in the wrong place XD You have to move it at the beginning of the code, otherwise if you removed the item from player's inventory already ofc there won't be anything in that slot. I am not sure you get the same error if the player has one of those items in his inventory and one equipped but moving that line to the top is safer anyway. I'lll edit the previous post

Original thread: https://forums.rpgmakerweb.com/threads/destroy-currently-equipped-item.71670/