Randomizing Equipment via an Event

Hello there, I'm trying to make it so that when a certain event runs, it will randomize the equipment of all party members.
The party members are all static, but the event takes into account what class would be and changes the loadout accordingly. I think I know the answer, but it never hurts to ask, so, my question is: Is there anyway to do this besides "the long way" via conditional branches. Like, is there a shortcut? Only asking because I'm planning on having like, 35 classes, each with 3 different weapons and 3 of each armour type, so it'll be a bit of a slog to do.
Thanks in advance.
yes and no

it can't be done with events alone, but if you add a few script commands it is much easier.
However script commands have their own limitations, and it depends on how your equipment is organised to make the scripts easy or difficult.


first, search for the topic that contains the script equivalents of the event commands for whatever maker you're using - there is a different one for each of the makers.
In the script for the equip command, you can replace the ID of the equipment with a random function.

and that is where your database makes or breaks it. If for example all your swords are one after another (like weapon ID 20 to 34), then you can make a single command randombetween20and34 to get a random sword.
If your swords are scattered through the ID list (like 1,8,13,17,25,...) then it will require a much more complex function to find a random sword.
It could be done a bit more efficiently by outsourcing it to a JavaScript function, but that's still tedious. I guess the question is...is it really necessary to do, gameplay-wise? As opposed to simply starting all of the characters with generic equipment that any class can use...or giving them money for a shop, or something.

Is your idea of this random choice of equipment actively adding anything to the game for the player?
Thanks, Andar. I'll try that. Might save a bit of time. Yeah, all of the stuff is grouped together by what I want to equip on them, so it's probably easier to go that route.

I wouldn't say it's vital to my game, or even necessary, or heck, probably won't even be noticed, if I'm gonna be honest. But, I feel that it would be a benefit to include it, so I'll keep it in, but I appreciate the concern.

Thanks for the help.
Okay, my first question: is every database slot an actual item of equipment, or do you have any placeholders/dividers/things that wouldn't be good if they were chosen at random?
Nah, there's separators, I could take them out, I guess.
Do the separators all have the same name? It doesn't really matter either way, I have a solution that'll work if not.
I'm too lazy for tedious work, so if it were me, instead of making a huge Conditional Branch for 35 classes, I'd make a script. The script would work more or less like this:

  1. Group equipment by classes that can wear them (the same piece of equipment can be featured in multiple groups, if it can be equipped by multiple classes).
  2. Subdivide your equipment by slot (weapon, helmet, armor, gauntlet, etc.).
  3. For each member of the party, replace their equipment in each slot by a random piece of equipment selected from the proper group and slot.

For this code to work, you'd need a way to filter out any piece of equipment that isn't, in fact, a piece of equipment (such as a separator item in your database). This can be as easy as removing any piece of equipment that has an empty name, or a name starting with a hyphen (-). Of course, that means sanitizing your database to ensure that you don't actually have a legitimate piece of equipment whose name starts with a hypen, like "-10 sword of misfortune" or similar, and that you don't have a separator item that follows a different convention, like "======= Endgame Gear =======".

You might find the following post about random rewards interesting: https://forums.rpgmakerweb.com/index.php?threads/random-reward.135879/
Actually, Nolonar just reminded me that I thought of an addition that means it doesn't even matter if you have dividers. Gimme a sec.

Here you go.

JavaScript:
$gameParty.members().forEach(member => {
    const allEquipment = $dataWeapons.concat($dataArmors).filter(equip => equip && equip.name.length > 0 && equip.description.length > 0 && member.canEquip(equip))
    member.equipSlots().forEach(slot => {
        const slotEquipment = allEquipment.filter(sequip => sequip.etypeId === slot)
        const randomEquip = slotEquipment[Math.randomInt(slotEquipment.length - 1)]
        member.forceChangeEquip(slot - 1, randomEquip)
        })
})
That doesn't seem to work, thanks for trying though. I think I'll just end up doing it the long way.
It does work, I literally did it in my test project before I posted the code. 😛 But I can certainly work with you to figure out why it doesn't seem to work for you. What do you mean by it doesn't work, exactly?
Well, it pops up with an error in another plugin when I run it. If I remove that plugin, the error goes to the next one.
The error is... "SyntaxError: Unexpected Token =>" When I call it from an event (Which is what I was assuming I did with it, wasn't 100% sure).

Even if I remove all the other Plugins I have, it still gives me that error.

Wasn't implying that it didn't work, btw. I just assumed I was using it wrong.
What version of MV do you have? If it's saying => is an unexpected token that sounds like your version of node.js doesn't support arrow functions, meaning it's likely out of date.
You know that's probably it. I haven't used MV in a while. I'll check that and give it another shot. Thanks for reminding me about that.

EDIT: Yep, that was it. Just needed to update. The script is working great. Just a question, if there's some equipment I don't want to randomize, would I just change the -1 in "const randomEquip = slotEquipment[Math.randomInt(slotEquipment.length - 1)]" to a bigger number? Assuming all the stuff I don't want randomized is at the bottom of the list?
You know that's probably it. I haven't used MV in a while. I'll check that and give it another shot. Thanks for reminding me about that.

EDIT: Yep, that was it. Just needed to update. The script is working great. Just a question, if there's some equipment I don't want to randomize, would I just change the -1 in "const randomEquip = slotEquipment[Math.randomInt(slotEquipment.length - 1)]" to a bigger number? Assuming all the stuff I don't want randomized is at the bottom of the list?
Do you mean there are specific items you don't want to be used as a random choice, or that there are slots you don't want to replace with a random item?
There was, but I managed to figure it out.
I just added:
Code:
&& equip.id < 384
to the second line. Seems to work fine.

Thanks again for your help. Saved me a ton of time.
Any time!

Original thread: https://forums.rpgmakerweb.com/threads/randomizing-equipment-via-an-event.136961/