Let a random team member speak

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
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.
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
$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).
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 
Last edited:

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
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 :D

And sorry once more for the mistake.
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
Many thanks, kind stranger :cutesmile:!

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
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
Haha, you too :D
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.
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
Thank you, I will.
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
I kind of did not expect you would ever want to run a dialogue with no other party members present :D
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,038
Reaction score
10,258
First Language
Czech
Primarily Uses
RMMV
I see. Although yes, errors like these are my most frequent errors :D
 

Heindal

Villager
Member
Joined
Oct 10, 2017
Messages
27
Reaction score
9
First Language
German
Primarily Uses
RMMV
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 :D. 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 :p.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I have tried, several times to understand how Markiplier is popular. You can't deny his popularity. I can only get through a few minutes of his vids, though. He's cringier than ANY cringe comp I've ever watched. When I was a kid, if you acted like that, 0 friends and 100% no dates for you. Times have changed XD
Sometimes you may feel helpless and defeated. But everyone loses from time to time. It's okay to be tired. Take a breather. Have a good cry if you need to. You gotta take breaks from your workout, or you'll collapse before you can get stronger.
So, my roommates wrote a news article in English, translated it into Bengali with google translate and now I'm helping them fix the monstrosity which was the result. Making English the medium of education is fine... but not to an extent that we forget how to write properly in our own language :")
Stream will be live shortly with some more Minecraft spriting! Feel free to drop by~

Forum statistics

Threads
93,542
Messages
913,320
Members
123,067
Latest member
SehoraX
Top