Let a random team member speak

I would like to know if there is an easy way to let a random team member speak. For example reacting on the hero of the squad.
Background: My hero can assemble his squad using more than 14 different characters. Of course you can use a nested "if else", but that's not very charming if you want to use this feature often. If there is no easy way I will think of a solution myself.
There is an easy way. In this forum section there is a stickied thread showing script call list - among others it also shows the Show message. With a little bit of javascript it should be easy.
Thanks. Hm, I could use math.random to select and random member, maybe referring to the id. I will see what I can find out. If I have a solution I will post it.
$gameParty.members()[x, where first member == 0] will only select party members.
Also, RMMV has Math.randInt (low number, high number) specifically defined, so you can use that 🙂
For example assuming you want to choose a random member from party except for leader, this is the code.
Math.randInt (1, $gameParty.members().length - 1).
I can provide two solutions for everyone who is interested in this topic:

1. This will select a random picture of the image container (here Actor1). In the example I skip the first one (+1) and pick a random picture of the next three in Actor1. This could be used for showing a random face expression or feeling for an avatar, as well as a random team member if they are all located in the same file.

var x;

x = Math.floor((Math.random() * 3) + 1);

$gameMessage.setFaceImage('Actor1',x)

$gameMessage.add("Show Text Script Call")


2. Will follow. See several messages below.
Thanks again Poryg.
Let's say it's not "that easy" that you can handle it with "some javascript". As you have to access JSON. Usually you have to parse JSON to make it accessible with Javascript. I admit I haven't used jQuery for a while, but even jQuery has to follow that logic. After 5 days of using RPG Maker I know absolutely nothing about the structure and how to use scripts within the software. For now this too big for me at the current state of knowledge. I will have to solve this later. For the current chapter I have a workaround (if then / while).

Even so Math.randInt (1, $gameParty.members().length - 1) is a way better approach than mine, it will just work in theory, as $gameParty.members isn't defined. So you can not use it. As I spent 1-3 hours at late night to make this running, I'm quite out of motivation. Nevertheless, thank you for your help Poryg!

For the rest of you. The above solution works (#1). If you plan accordingly you can make a characterset with your teammembers in one file e.g. "team.png" with the portraits and than address them at random with the simple script above.
I have to apologize. It is not $gameParty.members(), that is not defined. It is randInt. I mistook randInt, which is my function from a completely different project. The correct function is randomInt... And for some reason it accepts only one parameter, the maximum.

So I will provide the solution as a consolation.
Code:
var rndInt = Math.randomInt ($gameParty.members().length - 1)
while (rndInt == 0) rndInt = Math.randomInt ($gameParty.members().length - 1)
$gameMessage.setFaceImage ($gameParty.members()[rndInt]._faceName, 0) - you may want to find a method to replace the 0 with another number if you need face image index.
$gameMessage.add ("random text")

If you want to separate it to several messages, use \n several times. When there are five lines, it separates it to two messages. Nine lines - three messages. And so on. There is no automatic word wrap, so you have to do it manually.
But as you can see, no json parsing, no nothing... Just a simple javascript 😀

And sorry once more for the mistake.
Many thanks, kind stranger ☺️!

yeah its a new field for me, you never know how a software reacts, when using scripts.

Oh! It's faceName!? I used characterName and characterIndex instead as I couldn't find the gameParty.json!
Other than that I almost used the same approach. ;_; The while loop and the little riddle were funny, thanks.

To the others: This is the complete code, also known as the "Poryg Solution".
Please like Porygs post above, if you like it:

var rndInt = Math.randomInt ($gameParty.members().length - 1)

while (rndInt == 0) rndInt = Math.randomInt ($gameParty.members().length - 1)

$gameMessage.setFaceImage ($gameParty.members()[rndInt]._faceName, $gameParty.members()[rndInt]._faceIndex)

$gameMessage.add ("My legs hurt and I'm hungry!")


As a reward i will add a reference to the "Poryg Solution" to my game.
Maybe it's the solution for the "warp drive" or something :popcorn:.

Have a nice day
Haha, you too 😀
Maybe you'd like to check my console mv school lesson, it will teach you the ropes of javascripting inside RMMV a bit. since you can find a lot of information through just use of the console. You can find the link in my signature.
Thank you, I will.
I'd like to add a little problem with the code above. In case you don't have any team members in your squad, the while loop will run forever. This will cause the game to stuck. If you want to use this piece of code in your own game, you should use this code instead (it's not super awesome, but it fixes the problem):

if ($gameParty.members().length > 1){

var rndInt = Math.randomInt ($gameParty.members().length - 1)

while (rndInt == 0) rndInt = Math.randomInt ($gameParty.members().length - 1)

$gameMessage.setFaceImage ($gameParty.members()[rndInt]._faceName, $gameParty.members()[rndInt]._faceIndex)

$gameMessage.add ("My legs hurt and I'm hungry!")

}


It will check if there are team members in your team and will only than fire the dialogues or whatever you did with it.
I kind of did not expect you would ever want to run a dialogue with no other party members present 😀
You never know: In my game you can assemble a squad freely. So you can kick party-members out and add new ones. So far I blocked the possibility in-game by forcing the player to assemble a squad before he can leave the headquarter. I stumbled upon this mistake during testing, as my starting squad is just one hero.
I see. Although yes, errors like these are my most frequent errors 😀
Well, that happens. You can not always foresee every action a player does. Unfortunately I like to give players ultimate freedom and to make their own choices 😀. In Strange Legacy, one of biggest projects so far (Some kind of elder scrolls/rings of medusa rpg), this ended up in 50-100 of reported bugs last years. That's why I was a little absent here. Currently I'm working on my maker project again, so we will see what the next episode will bring. Probably a book called the Poryg principle, as promised. You are already mentioned in the credits 😛.

Original thread: https://forums.rpgmakerweb.com/threads/let-a-random-team-member-speak.85452/