Help whit script calls in the RPG Maker language

I won't beat around the bush and get straight to the point.

I want that in my game, when the character dies, the player loses their gold, items, and armor.
I can do that easily using the script call "$gameParty.initAllItems();" but this, first of all, also deletes key items, and nobody wants that to happen. Also, this does not include the items that the player has equipped.

What I want to know is if there is a way to add an "if" statement in that code or something similar to generate an exception with specific items and not have to delete each object one by one using "$gameParty.loseItem($dataItems[12], 1);" for example.

I tryed this but it doesnt work IDK why:

$game_party.items.each do |item|
next if $data_items[item.id].key_item?
$game_party.lose_item(item, item.quantity)
end

$game_party.weapons.each do |weapon|
next if $data_weapons[weapon.id].key_item?
$game_party.lose_item(weapon, weapon.quantity)
end

$game_party.armors.each do |armor|
next if $data_armors[armor.id].key_item?
$game_party.lose_item(armor, armor.quantity)
end

I need some help 🙁
Not sure if this helps a little, but you can discard all party's equipment by this:
Code:
"$gameParty.members().forEach(function(actor) {
  actor.equips().forEach(function(item) {
    actor.discardEquip(item);
  });
});"
EDIT: The immediate reason why the snippet you posted isn't working is because that script isn't JavaScript, it's Ruby for VX/Ace/XP. MV uses JavaScript. The syntax is wrong, the function names are wrong, the variable names are wrong.

I find the best way to find which functions you need to call is actually to take a look at how the event commands do it.

All the code for the event commands is in Game_Interpreter (you can see its code in the rpg_objects.js in your project's js folder). The functions for Change Gold, Change Items and Change Armors are Game_Interpreter.prototype.command125, command126 and command128 respectively (you can Ctrl-F for the command name, the functions are commented with the names above them).

These functions in turn call $gameParty.gainGold() and $gameParty.gainItem(). Although they are called "gainX", if you check the code you will realize they actually remove gold/items if you use a negative number as the amount (in fact, there is a "$gameParty.loseItem()" function that does nothing except call "$gameParty.gainItem()" with a negative amount).

If you want to make the party drop all their items or armor, you should set up a for-loop on all the items/armor in your database. As you can probably tell when you look at the event command126 and 128, the database data for useable items is loaded into the "$dataItems" variable and for armors, into the "$dataArmors" variable.

If you loop through every ID in those arrays subtracting the maximum possible amount, that will clear out everything in the party's item/armor inventory.
I'm working on some Rogue-like Plugins to enable the seizing of Exp, Gold, and Equip. Maybe it helps you:

I will also add that, unlike VX/Ace/XP, there is no 'key_item?" function existing in MV/MZ.

If you need to check whether some $dataItems[x] is a key item, you will need to check its "itypeID" property instead. I can tell you that "itypeId" will be 1 for regular items, 2 for key items (and I assume would be 3 and 4 for "Hidden Item" A/B, though I haven't checked).
You can use what @fizzly posted to get rid of the actors' equipment (although for some reason there are quotation marks around it, you'll need to delete those).

For getting rid of non-key items, you can try this:
Code:
$gameParty.items().forEach(item => item.itypeId>1 ? 0 : $gameParty.gainItem(item, 0-$gameParty._items[item.id], true));
Key Items are characterised as Items with an item type ID (itypeId) of 2. $gameParty.items() returns a list of database records for each unique inventory item. So you can remove all non-key items like this:
JavaScript:
for (var item of $gameParty.items())
  if (item.itypeId !== 2)
    $gameParty.loseItem(item, 99);
I.e. "for each item in inventory, if its item type ID is not 2, then remove 99 of it".

(If necessary you can use $gameParty.numItems(item) for the quantity to remove, instead of 99. Might be helpful if you run into plugin-related problems with it.)

To remove all weapons & armors (true => include equipment):
JavaScript:
for (var weapon of $gameParty.weapons())
  $gameParty.loseItem(weapon, 99, true);
for (var armor of $gameParty.armors())
  $gameParty.loseItem(armor, 99, true);
If you want to keep the weapons, then just omit the first couple of lines here.

[Edit 2: just realised this will only remove an equipped armor/weapon if there's an unequipped copy in the inventory. So you'd want to use the script call fizzly mentioned as well.]

To remove all gold you can just use the event command: Change Gold -999999.

[Edit: ninja'd!]
EDIT: The immediate reason why the snippet you posted isn't working is because that script isn't JavaScript, it's Ruby for VX/Ace/XP. MV uses JavaScript. The syntax is wrong, the function names are wrong, the variable names are wrong.

I find the best way to find which functions you need to call is actually to take a look at how the event commands do it.

All the code for the event commands is in Game_Interpreter (you can see its code in the rpg_objects.js in your project's js folder). The functions for Change Gold, Change Items and Change Armors are Game_Interpreter.prototype.command125, command126 and command128 respectively (you can Ctrl-F for the command name, the functions are commented with the names above them).

These functions in turn call $gameParty.gainGold() and $gameParty.gainItem(). Although they are called "gainX", if you check the code you will realize they actually remove gold/items if you use a negative number as the amount (in fact, there is a "$gameParty.loseItem()" function that does nothing except call "$gameParty.gainItem()" with a negative amount).

If you want to make the party drop all their items or armor, you should set up a for-loop on all the items/armor in your database. As you can probably tell when you look at the event command126 and 128, the database data for useable items is loaded into the "$dataItems" variable and for armors, into the "$dataArmors" variable.

If you loop through every ID in those arrays subtracting the maximum possible amount, that will clear out everything in the party's item/armor inventory.
Oh I didn't know that, thank you very much! This makes things even easier! Also, I think the others solved my problem. I'll try tomorrow and I'll tell you how it went and I'll tell you how the problem was resolved. Thank you

Key Items are characterised as Items with an item type ID (itypeId) of 2. $gameParty.items() returns a list of database records for each unique inventory item. So you can remove all non-key items like this:
JavaScript:
for (var item of $gameParty.items())
  if (item.itypeId !== 2)
    $gameParty.loseItem(item, 99);
I.e. "for each item in inventory, if its item type ID is not 2, then remove 99 of it".

(If necessary you can use $gameParty.numItems(item) for the quantity to remove, instead of 99. Might be helpful if you run into plugin-related problems with it.)

To remove all weapons & armors (true => include equipment):
JavaScript:
for (var weapon of $gameParty.weapons())
  $gameParty.loseItem(weapon, 99, true);
for (var armor of $gameParty.armors())
  $gameParty.loseItem(armor, 99, true);
If you want to keep the weapons, then just omit the first couple of lines here.

To remove all gold you can just use the event command: Change Gold -999999.

[Edit: ninja'd!]
Oh okay, according to my knowledge of javascript that should work. Anyway, I'll try it when I'm home and I'll let you know if that solved the problem or not, for future people who have problems with something similar. Thank you very much

I'm working on some Rogue-like Plugins to enable the seizing of Exp, Gold, and Equip. Maybe it helps you:

Wow thats amazing. I will check that after for sure!
Great, hope it all works out! 👋

(I'm guessing fizzly copied that from the MV/MZ Script Call List: Google Sheets puts "quotes" around the result - and turns all " into "" - when copying a cell with multi-line content.)
Well, after trying a few different alternatives according to what my game needed, I used the following code:
"$gameParty.members().forEach(function(actor) { actor.equips().forEach(function(item) { actor.discardEquip(item); }); });"
I used this code to discard all items the player has equipped (key items cannot be equipped so, this is enough).


With that done, I used these codes to remove weapons, armor and non-key items from inventory.
for (var item of $gameParty.items()) if (item.itypeId !== 2) $gameParty.loseItem(item, 99);
for (var weapon of $gameParty.weapons()) $gameParty.loseItem(weapon, 99, true); for (var armor of $gameParty.armors()) $gameParty.loseItem(armor, 99, true);

This works in my game. What I haven't tried yet is what will happen if I have the same item, one equipped and the other in inventory. I haven't tried it yet with those codes.

Anyway, now what I want to add is an exception to X object if possible and I'll explain why:

In my game, if the player returns to his "town" without losing, he keeps ONLY the items, but loses weapons and armor (so when he goes back out he is not overpowered). This is solved using less code than mentioned above.

The problem is, in my game, each character has a specific weapon (which in the case of death he can lose it, so it's solved with the previous code), but in the case of winning, I would like the character to still keep only his specific weapon.

I think this would not only be useful for me but for many people in the future. I tried but I don't know the exact nomenclature used for RPG maker so I couldn't figure it out.

Also, thank you all.
The problem is, in my game, each character has a specific weapon (which in the case of death he can lose it, so it's solved with the previous code), but in the case of winning, I would like the character to still keep only his specific weapon.
Let's say actor ID 3 is using weapon ID 25. Is that their "specific weapon", and why?

Original thread: https://forums.rpgmakerweb.com/threads/help-whit-script-calls-in-the-rpg-maker-language.157529/