Kylecox011

Villager
Member
Joined
Oct 3, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMV
I'm working on a Monopoly style game, at the beginning there are 4 players who roll dice to go first. I have a variable set up for the dice roll and it's working great but I need RPG Maker to recognize who won the dice roll. Any help is much appreciated!
 

TobyYasha

Spaghetti & Coding go hand in hand.
Regular
Joined
Sep 11, 2019
Messages
194
Reaction score
304
First Language
English
Primarily Uses
RMMZ
If you have a way to keep track of who's turn it is currently you could store the result in a variable corresponding to that player.
Example:
Player 1 Dice Roll Result
Player 2 Dice Roll Result
Player 3 Dice Roll Result
Player 4 Dice Roll Result
After which you can try this script in a "script call" which will give you the index of the player who won.
Example: If the highest roll was 12 and player 2 rolled that then you will get index 2.

JavaScript:
// Change the following variable ids (9, 10, 11, 12, 13)
// to the variable ids of your choice.

const diceRolls = [
  $gameVariables.value(9),  // player 1 dice roll result
  $gameVariables.value(10), // player 2 dice roll result
  $gameVariables.value(11), // player 3 dice roll result
  $gameVariables.value(12), // player 4 dice roll result
]

const highestRoll = Math.max(...diceRolls);
const playerIndex = diceRolls.indexOf(highestRoll) + 1;

// Afterwards you can store the index of the player
// who won in a variable and use it in a conditional branch.

$gameVariables.setValue(13, playerIndex);
 

Kylecox011

Villager
Member
Joined
Oct 3, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMV
If you have a way to keep track of who's turn it is currently you could store the result in a variable corresponding to that player.
Example:
Player 1 Dice Roll Result
Player 2 Dice Roll Result
Player 3 Dice Roll Result
Player 4 Dice Roll Result
After which you can try this script in a "script call" which will give you the index of the player who won.
Example: If the highest roll was 12 and player 2 rolled that then you will get index 2.

JavaScript:
// Change the following variable ids (9, 10, 11, 12, 13)
// to the variable ids of your choice.

const diceRolls = [
  $gameVariables.value(9),  // player 1 dice roll result
  $gameVariables.value(10), // player 2 dice roll result
  $gameVariables.value(11), // player 3 dice roll result
  $gameVariables.value(12), // player 4 dice roll result
]

const highestRoll = Math.max(...diceRolls);
const playerIndex = diceRolls.indexOf(highestRoll) + 1;

// Afterwards you can store the index of the player
// who won in a variable and use it in a conditional branch.

$gameVariables.setValue(13, playerIndex);


I don't currently have a way to keep track of who's turn it is. Not sure how to go about figuring it out either. Do you think if I added an invisible item to the player's inventory depending on the dice roll, like you roll a 6 so you get 6 of the item. You could just tell who won by who has the most of that item?
 

TobyYasha

Spaghetti & Coding go hand in hand.
Regular
Joined
Sep 11, 2019
Messages
194
Reaction score
304
First Language
English
Primarily Uses
RMMZ
I'm not sure how your game works so maybe i should get a bit more familiar with it first to better help you.
So how do you exactly start the "dice rolling" part ?
Are you doing this in an eventing way where each player gets its turn one by one?
It's also important knowing if you are doing this in battle or on the map scene.
 

Kylecox011

Villager
Member
Joined
Oct 3, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMV
This is what the game looks like:


ceo.PNG

4 players are on pedestal/stage type things.

Player 1 (You) first pick a character (Just basic animals for now)

character.PNG

Then you roll the dice.

Once you're done it goes in a circle spawning the other 3 random players and rolling their dice.

1.PNG

Here's the variable for the Dice Roll probability.

var.PNG


Once it goes back to Player 1 I'm not sure how to signify who won.


It is one person at a time and it's not in battle, just on the map. Also thank you so much for the responses and the help.
 

TG22

Villager
Member
Joined
Mar 19, 2019
Messages
16
Reaction score
9
First Language
French
Primarily Uses
RMMZ
The result of the roll is stored in the variable 1. Is there a reason why you cannot access it later?
You should probably show us the code of the moment you try to use it.

(off topic but using random 2-12 is the same as 1d11+1, the repartition of the probability is very different than 2d6, e.g. P(2)=1/11 in your case where P(2)=1/36 for 2d6. )
 

TobyYasha

Spaghetti & Coding go hand in hand.
Regular
Joined
Sep 11, 2019
Messages
194
Reaction score
304
First Language
English
Primarily Uses
RMMZ
You mentioned that once the player is done rolling then the other 3 players get their turn, that means there must be a turn system of sorts in place.
If you aren't already doing this already you could use a variable to keep track of the player index(basically if it's player 1 turn then you set the variable value to 1, if player 2 then set the variable value..etc), and based on this player index variable you can save each player's roll in the probability event after they are done rolling.
You check what is the current player index and store the result like so:
if: Player Index = 1 then save this in the player 1 dice roll result variable.
if: Player Index = 2 then save this in the player 2 dice roll result variable.
etc.
Not sure if this ended up being the best explanation, but maybe i ended up giving you an idea on how to proceed further.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,643
Reaction score
11,146
First Language
English
Primarily Uses
RMMV
Just a couple of thoughts.

I think you'd be best off sticking to non-script solutions for this, given your apparent level with MV's eventing. There's nothing in here you can't do with event commands.

As mentioned above, 2-12 is not the same range of probabilities as 2d6.

All you have to do is put each person's roll into a different variable. If variable 1 is the player's roll, then use 3 other variables for the other opponents. Then you use Conditional Branches to see which is the highest.

Is there a reason your event is Parallel? It looks like you're controlling player movement so you don't want them doing other things while this is happening, so it should be Autorun. It's important to know the differences between those.
 

Kylecox011

Villager
Member
Joined
Oct 3, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMV
Sorry guys I'm working at the moment, but I'll check back tonight and try some of the suggestions.
 

Kylecox011

Villager
Member
Joined
Oct 3, 2021
Messages
10
Reaction score
0
First Language
English
Primarily Uses
RMMV
Sorry I'm not familiar with any coding but I followed the advice and used a variable for each player:


dice roll - var.PNG



And determined the winner this way:

dice roll - win.PNG

I haven't gotten to actually determining the player who won, so for now I just did "You win/Lose" but I should be able to figure that out later. I appreciate all the help on this one!
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,643
Reaction score
11,146
First Language
English
Primarily Uses
RMMV
There's no reason for you to have those extensive, nested Conditional Branches. If you mouse over the text box in the Show Text event command, it shows a list of escape codes, the first of which is:
1701063857277.png

So you can simply do "\V[1]!"

There are a number of ways you can logic which player won. I would probably use a 5th variable.
- Do player 1's roll
- Set variable 5 to 1
- Do player 2's roll
- Conditional Branch -> variable 2 > variable 1
-- set variable 5 to 2
repeat for 3 and 4. Then at the end variable 5 will be the player number that had the highest roll.
 

Latest Threads

Latest Posts

Latest Profile Posts

Off to LEGOLAND today! Yes, my wife and I are in our 50s and going to LEGOLAND without any small children. Stop judging us! Apparently, there are places you can't go without being accompanied by a child in LEGOLAND. Which is kind of the opposite of what is usual. But our kids are all grown and we have never been. LEGO KRAMPUS here I come!
I decided that for the video game i will work next year i will use characters from my TCG as main characters for the RPGMAKER game, so expand the universe, that will be a cool :CoOoOL: Here some of my characters :

Ah also yes I'm accepting commission in case tat you ask for haha.
Some people shouldn't be parents. Someone put their toddler in the hallway of the apartment building I live in at 11 p.m.... and let her wander. The heck is wrong with people?!
Twitch! Strean is currently live with some more gamedev! Feel free to drop by~
If you need some maps done, but don't like mapping or just want to focus on other areas of your gamedev, my workshop is alway open! Hit me up!

Forum statistics

Threads
136,756
Messages
1,269,598
Members
180,505
Latest member
rpplayer158
Top