valerieplanets

Regular
Regular
Joined
Jul 9, 2021
Messages
45
Reaction score
7
First Language
English
Primarily Uses
RMMV
okay so... this is a little complex so i haven't been able to figure it out on my own. but basically i want a script that creates a random party based on who you've unlocked. it would go something like this

when you unlock a party member, it changes a variable assigned to them. so, say you unlock harold, a variable (with the ID of 1) named harold would now be equal to 1. assume the same can be said for therese, marsha and lucius (IDs 2, 3 and 4 respectively). variable ID 5 is Reid, who you haven't unlocked, so his variable is set to 0.
So, a random variable is generated from 1 to 5. when that number is generated, i want it to check if the variable with the ID equal to the number generated is equal to 0 or 1. if it's 0, generate another number. if it's 1, then do it again for the next party slot.
(obviously the numbers and party members used here are just an example)
what i'm asking for is if anyone would be able to put this into javascript that would be awesome, since i don't think you can do this kind of thing with the event options in MV.

hopefully that all makes sense. i can explain better if i need to.
 

Aerosys

Regular
Regular
Joined
Apr 23, 2019
Messages
997
Reaction score
1,038
First Language
German
Primarily Uses
RMMZ
I would do that with a shuffle; I pick the code from there: https://stackoverflow.com/a/2450976

Code:
function shuffle(array) {
  let currentIndex = array.length,  randomIndex;

  // While there remain elements to shuffle.
  while (currentIndex != 0) {

    // Pick a remaining element.
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex--;

    // And swap it with the current element.
    [array[currentIndex], array[randomIndex]] = [
      array[randomIndex], array[currentIndex]];
  }

  return array;
}

var options = [ ];
if ($gameSwitches.value(1)) options.push(1) // Switch 1 --> Actor Id 1
if ($gameSwitches.value(2)) options.push(2) // Switch 2 --> Actor Id 2
/* ADD MORE HEROES */

shuffle(options)

// clear Party
$gameParty.members().forEach(actor => this.removeActor(member))

// add Actors
for (let i = 0; i < 4 && i < options.length; i++) {
    const actor = $gameActors.actor(options[i]);
    $gameParty.addActor(actor);
}

Once you call this code in a "Call Script" your Party is populated with 4 randomly chosen actors.

You need to set Switches for your Actors.

Let me know whether it's working for you!
 

ZombieKidzRule

Shh! My Zombiekids & I are playing BG3 right now.
Regular
Joined
Jan 9, 2022
Messages
1,136
Reaction score
2,140
First Language
English
Primarily Uses
RMMZ
I can't help with the Java Script part, but I wanted to respond to the Event options part. I don't see why you couldn't do this with an Event. I just wouldn't give each unlocked character the same value. Instead, as you unlocked characters, you could assign them a value and store that value in an array. Then, when you wanted to randomly select a party, you would randomly pull values out of that array and use conditional branches to add the appropriate party member based on the value you pulled.

I am sure there are other methods, but I think this should be pretty easy to do with Events.

Also, I clicked on this thread because of your Avatar. It was the first time I had seen it. Snorlax is my Spirit Pokemon and the official mascot of all the classes that I teach.

Hopefully someone else can give you a script or plugin option if that is was you prefer.

Ninja'd by the post above.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
11,283
Reaction score
9,283
First Language
English
Primarily Uses
RMMV
i don't think you can do this kind of thing with the event options in MV.
Why not? (although I don't see the point of using variables if you're just doing 0 and 1, that's what switches are for)

But I would use a variable to track how many party members you have unlocked.

@ZombieKidzRule has a bit of a hybrid method, using event commands and an array, but you can do this with zero script and it's not particularly difficult.

Code:
◆Control Variables:#0002 PartySize = Unlocked
◆If:PartySize > 3
  ◆Control Variables:#0002 PartySize = 3
  ◆
:End
◆Loop
  ◆Label:Loop Start
  ◆If:PartySize = 0
    ◆Break Loop
    ◆
  :End
  ◆Control Variables:#0003 RandActor = Random 1..4
  ◆If:RandActor = 1
    ◆If:ThereseUnlocked is ON
      ◆If:Therese is in the party
        ◆Jump to Label:Loop Start
        ◆
      :Else
        ◆Change Party Member:Add Therese
        ◆Control Variables:#0002 PartySize -= 1
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆If:RandActor = 2
    ◆If:MarshaUnlocked is ON
      ◆If:Marsha is in the party
        ◆Jump to Label:Loop Start
        ◆
      :Else
        ◆Change Party Member:Add Marsha
        ◆Control Variables:#0002 PartySize -= 1
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆If:RandActor = 3
    ◆If:LuciusUnlocked is ON
      ◆If:Lucius is in the party
        ◆Jump to Label:Loop Start
        ◆
      :Else
        ◆Change Party Member:Add Lucius
        ◆Control Variables:#0002 PartySize -= 1
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆If:RandActor = 4
    ◆If:JulieUnlocked is ON
      ◆If:Julie is in the party
        ◆Jump to Label:Loop Start
        ◆
      :Else
        ◆Change Party Member:Add Julie
        ◆Control Variables:#0002 PartySize -= 1
        ◆
      :End
      ◆
    :End
    ◆
  :End
  ◆
:Repeat Above

Now the more actors you unlock, the more efficient it is to use code like Aerosys posted above. But it's absolutely doable with events - I just wanted to post this example so that you get a bit of a better understanding of what you can do with event commands.
 

Latest Threads

Latest Posts

Latest Profile Posts


Time to wake him up again.
*Sigh* I guess I'll actually do something now ''puts on lofi hip hop radio''
Just a little public service announcement, for all the users in the USA, that at 2:20 p.m. EDT FEMA's testing their broadcast system. Mainly because I'm probably going to forget and then have a heart attack
Just learned that Egg Cream contains neither egg nor cream. :kaoback:

Forum statistics

Threads
135,040
Messages
1,253,223
Members
178,012
Latest member
Granpirata
Top