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!
Dice Roll winner out of 4 players
RPG Maker MV SupportIf 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.
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?
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.
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.
This is what the game looks like:
4 players are on pedestal/stage type things.
Player 1 (You) first pick a character (Just basic animals for now)
Then you roll the dice.
Once you're done it goes in a circle spawning the other 3 random players and rolling their dice.
Here's the variable for the Dice Roll probability.
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.
4 players are on pedestal/stage type things.
Player 1 (You) first pick a character (Just basic animals for now)
Then you roll the dice.
Once you're done it goes in a circle spawning the other 3 random players and rolling their dice.
Here's the variable for the Dice Roll probability.
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.
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. )
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. )
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.
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.
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.
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.
Sorry guys I'm working at the moment, but I'll check back tonight and try some of the suggestions.
Sorry I'm not familiar with any coding but I followed the advice and used a variable for each player:
And determined the winner this way:
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!
And determined the winner this way:
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!
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:
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.
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.
Original thread: https://forums.rpgmakerweb.com/threads/dice-roll-winner-out-of-4-players.163071/