Remove all actor 2's inventory items except the latest obtained item?

Is there any script or ways to remove all actor 2's inventory items except the latest obtained item?

Thanks in advance
Do you already have a way of tracking separate inventories by Actor? Or do you mean to remove all equipped items on a particular Actor except their most recently obtained item? By most recently obtained, do you mean most recently equipped? Or do you mean the most recent item that Actor 2 could equip?
Do you already have a way of tracking separate inventories by Actor? Or do you mean to remove all equipped items on a particular Actor except their most recently obtained item? By most recently obtained, do you mean most recently equipped? Or do you mean the most recent item that Actor 2 could equip?
I have no tracking separate inventories by actor. I mean to remove all items actor 2 has, if possible all item, equipments, and skills. and then only keep the most recent obtained item (from a chest). could equip or already equipped, whichever way is easier
So, to make sure I understand what you're asking, you want an event where the player comes upon a chest, and Actor 2 has the following happen:

1. All equipment is removed - weapons and armor
2. All skills are unlearned
3. The item retrieved from the chest is now in the player's inventory

I'm still not quite clear what you mean by removing the items that Actor 2 has and only keep the most recent one, it seems to imply that you want a separate inventory from the main one. As an example, let's say the party's inventory has 99 potions, 99 stimulants, and 99 magic water. When you open this chest, should all 99 potions, stimulants, and magic water disappear?
So, to make sure I understand what you're asking, you want an event where the player comes upon a chest, and Actor 2 has the following happen:

1. All equipment is removed - weapons and armor
2. All skills are unlearned
3. The item retrieved from the chest is now in the player's inventory

I'm still not quite clear what you mean by removing the items that Actor 2 has and only keep the most recent one, it seems to imply that you want a separate inventory from the main one. As an example, let's say the party's inventory has 99 potions, 99 stimulants, and 99 magic water. When you open this chest, should all 99 potions, stimulants, and magic water disappear?

the 99 potions , 99 stimulants, and 99 magic water will still be in other actors inventory, but not actor 2's
@manck there is no "actor inventory" by default.
There is only a party inventory usable by everyone.
So if you remove 99 potions, then no one will have potions left to use.

Do you want the actor 2 to be unable to use items from the party inventory? because it sounds like that, but this is something entirely different from what you asked before.
I think part of my confusion is that, by default, there's only one inventory in the game. The entire party shares one inventory, so the other Actors can't really have their own inventory unless you're using a Plugin of some sort or using some sort of eventing system to create different inventories.

If I understand your ask correctly, it seems like you'd need to use the following steps:

1. Unequipping All Items Without Adding Them To The Inventory
If you're using RMMV 1.6 or above, you could run the following in a script call:
Code:
const actor = $gameParty.members().find(member => member._actorId === x); // replace x with the ID of the actor you want to target
actor._equips = actor._equips.map(() => new Game_Item());

If you're using an older version, try:
Code:
var actor = $gameParty.members().filter(function(member) { return member._actorId === x; })[0];
actor._equips = actor._equips.map(function() { return new Game_Item(); });

This should unequip all items without adding them to the inventory.

2. Removing all skills
This is probably best handled by changing the actor's class to something that doesn't have any skills assigned to it. However, you could also use the "Change Skill" option from the event UI to have the actor forget every skill they could possibly have learned.

Alternatively, you could try the following code, referencing the same "actor" variable you used in the previous script (so include it in the same script call):
Code:
actor._skills = [];

3. Adding the last obtained item to the inventory
Since it sounds like you know what the last obtained item would be, because this is all happening in an event, you would then just use the normal "add item to inventory" event control.
I think part of my confusion is that, by default, there's only one inventory in the game. The entire party shares one inventory, so the other Actors can't really have their own inventory unless you're using a Plugin of some sort or using some sort of eventing system to create different inventories.

If I understand your ask correctly, it seems like you'd need to use the following steps:

1. Unequipping All Items Without Adding Them To The Inventory
If you're using RMMV 1.6 or above, you could run the following in a script call:
Code:
const actor = $gameParty.members().find(member => member._actorId === x); // replace x with the ID of the actor you want to target
actor._equips = actor._equips.map(() => new Game_Item());

If you're using an older version, try:
Code:
var actor = $gameParty.members().filter(function(member) { return member._actorId === x; })[0];
actor._equips = actor._equips.map(function() { return new Game_Item(); });

This should unequip all items without adding them to the inventory.

2. Removing all skills
This is probably best handled by changing the actor's class to something that doesn't have any skills assigned to it. However, you could also use the "Change Skill" option from the event UI to have the actor forget every skill they could possibly have learned.

Alternatively, you could try the following code, referencing the same "actor" variable you used in the previous script (so include it in the same script call):
Code:
actor._skills = [];

3. Adding the last obtained item to the inventory
Since it sounds like you know what the last obtained item would be, because this is all happening in an event, you would then just use the normal "add item to inventory" event control.

Thank you!
To get rid of all of the actor's current equipment and skills, it would be easier to do this:

Code:
$gameActors.actor(id)._equips = [];
$gameActors.actor(id)._skills = [];

where id is the actor id, without any leading zeros. This is the code used to first add them to the party with no equipment/skills.

Then do whatever you're already doing to add back the last-obtained item (this would be on the assumption that the "last-obtained" means the "last-equipped", as if they obtained an item but didn't equip it, and you add it back, then they'll have one more than they actually obtained).
To get rid of all of the actor's current equipment and skills, it would be easier to do this:

Code:
$gameActors.actor(id)._equips = [];
$gameActors.actor(id)._skills = [];

Definitely agree on the $gameActors.actor() call being easier than using a .find method. However, when I set an Actor's _equips to an empty array, I get undefined Exceptions. I think you have to change their equips to new Game_Item instances to prevent that. So:
Code:
$gameActors.actor(id)._equips = $gameActors.actor(id)._equips.map(() => new Game_Item());
That's interesting - that code came straight from the Game_Actor.initialize method.
Maybe I'm wrong? Are you able to recreate the error in a new project on your end?

My steps are:
1. Start a new game
2. Run $gameActors.actor(1)._equips = [];
3. Open up the menu
4. Select Equip
5. Target Harold (Actor 1)
6. Scene_Equip opens, Harold has no items
7. Select Equip
8. Select Weapon
9. Get this error:
Spoiler: Undefined screenshot
rgR5zco.png

But when I change all of Harold's equips to new Game_Item() instances instead, everything works fine (at first glance, anyway).
No, you're right. After setting to [], it calls another method during initialization that fills the slots with new Game_Item().

Original thread: https://forums.rpgmakerweb.com/threads/remove-all-actor-2s-inventory-items-except-the-latest-obtained-item.104631/