How to run random variables for mini game

Hello all,

I've had a mini game idea, and it was to work a restaurant.
And it got me thinking of how it would work.
Random NPC wandering around.

Player accepts mission -

Random NPC's then display - random balloon icons.
When player picks up - say a fish and walks over to the NPC with the fish icon = reward.
now this in it's self is easy however i want to randomize which balloon ID pops up and then NPC can randomize again.

Do this say 3 x per NPC and then mission/game complete.

How would i be able to do this ?

I tried setting a variable ( No idea what I'm doing ) food 1 and food 2 started by a switch conditioned it kinda worked but i couldn't quite get it down or the randomization.

thanks.
It's one of the basic functions with variables, so I'd suggest you look up a tutorial that explains it in-depth. But basically, you just set the variable's Operand to 'Random' and then set the range (for example, setting it between a 1 and 4 means it'll have a 25% to land on a specific outcome).
in case it wasn't obvious - you use conditional branch to chec which result the variable got from the random operation.
Random NPC's then display - random balloon icons.
Do you have the yanfly plugins? There are a plugins that can permanently or temporarily show an icon above their head.

  • YEP_IconsOnEvents.js
  • YEP_IconBalloons.js
  • YEP_EventMiniLabel.js
I personally like the last one best, and just show \i[314] instead of text in the label to show icon for gold, which in my case is icon 314.

Place an event that represents a costumer
  • 1. On the first page of the event, make only the next command: "Control variable: var#0001 = random 1~3"
  • 2. On the second page, you put "var#0001 ≥ 1" in the condition.
  • 3. On the third page, you put "var#0001 ≥ 2" in the condition.
  • 4. On the fourth page, you put "var#0001 ≥ 3" in the condition.
Now on the second page, you put the first possible item in the minilabel, like "\i[265]" for an apple, if the first option is an apple.

Repeat this for page 2 and 3 with different items.

When player picks up - say a fish and walks over to the NPC with the fish icon = reward.
now this in it's self is easy however i want to randomize which balloon ID pops up and then NPC can randomize again.

Now you can event what happens when the player interacts. Here you can split the event in 2 with a conditional branche: "Party has item: Apple" (make sure you activate the "Or else" option in the bottom"

Now in the upper half of the event you write what happens if you come to the table with an apple (succeed), and in the bottom half you write what happens if you come with any other item (failed).

Do the same thing with page 3 and 4, but with different items.

At the end of the succesful part, you can change var#0001 back to 0, and the whole thing will start over, or you can flip self-switch A after bringing the item and make a new, 5th page in the event:

  • 5. On the last page, "self switch A is on" in the condition
you write what happens if you approach a costumer again after giving them the right dish. Here you could ask if the costumer wants something else. Then turn off the self switch and set var#0001 to 0. This will reset the whole thing.

To work this way, you should use a different variable to for each costumer. That could be annoying if you have many costumers in the restaurant at the same time. Yanfly has a plugin to solve this too:
  • YEP_SelfSwVar.js

Do this say 3 x per NPC and then mission/game complete.
In above example, put a "control variable: var#0002 + 1" every time you deliver the right dish and "control variable: var#0002 = 0" when brought the wrong dish. Make sure to do this for all dishes.

Then make a new last page:
  • 6. On the sixth page, you put "var#0002 ≥ 3" in the condition.
On this page you can write what happens when you have brought the 3× the right dishes to that table in a row. (I added the in a row part...) At the end of this eventpage, make the customer leave the restaurant, so you can't interact with it this round no more. Because on this page, you collect your reward for completing this events order.

Also on the 6th page, when collecting the rewards, put: "control variable: var#0003 + 1"

Now make a new event without image somewhere in the corner of your map, where the player can't reach, with one page:

  • 1. On the first page, you put "var#0003 ≥ 5" in the condition.
Here you can write what happens when 5 happy costumers left the restaurant, probably game complete.

How would i be able to do this ?

I hope my idea above would be of any help. I just made it up while writing, so I hope I didn't miss an essential step, but I am quite confident this would work quite well.

Bonus idea:
Put: "control variable: var#0004 = playtime" and right after put: "control variable: var#0004 * -1" in the event that starts the whole mini game. (multiplying by -1 makes the value negative)

And when completing the whole mini game put: "control variable: var#0004 + playtime" in the event that closes the minigame.

Now, var#0004 + contains the seconds it took to complete the minigame. Great to make a score board with high scores.

(Ps. Sorry for talking to you as if you're a noob. I just want to explain it as clear as possible. It's not because I think you're a noob.)
Hello Sparky89!

I have a free tutorial about variables that you can play in the browser for free and free of charge. Check the Variables lesson for more information. You will play a Horse mini-game there and another mini-game for finding the right value to finish the lesson.

For what you want to do, all you need is to create your variables and assign a random value for them with the Variable command. It's very intuitive and easy to find. For the NPCs, you use the same variable for displaying them and for the balloons, the Conditional Branch with another variable.

Using plugins, like the one suggested by @JohnDoeNews is also a good idea, this way you need to keep only the variable for the random NPCs. 😉
This looks to me like a very nested Mechanic and the Solution can depend greatly on the details.

Here is a Scriptline to make it easier to show different Balloon Icons on Events.
The Value of Variable 2 determines the Balloon Showed on that Event NPC.

Code:
$gameMap.event(1).requestBalloon($gameVariables.value(2));

The Link in this Thread helps alot:
Do you have the yanfly plugins? There are a plugins that can permanently or temporarily show an icon above their head.

  • YEP_IconsOnEvents.js
  • YEP_IconBalloons.js
  • YEP_EventMiniLabel.js
I personally like the last one best, and just show \i[314] instead of text in the label to show icon for gold, which in my case is icon 314.

Place an event that represents a costumer
  • 1. On the first page of the event, make only the next command: "Control variable: var#0001 = random 1~3"
  • 2. On the second page, you put "var#0001 ≥ 1" in the condition.
  • 3. On the third page, you put "var#0001 ≥ 2" in the condition.
  • 4. On the fourth page, you put "var#0001 ≥ 3" in the condition.
Now on the second page, you put the first possible item in the minilabel, like "\i[265]" for an apple, if the first option is an apple.

Repeat this for page 2 and 3 with different items.



Now you can event what happens when the player interacts. Here you can split the event in 2 with a conditional branche: "Party has item: Apple" (make sure you activate the "Or else" option in the bottom"

Now in the upper half of the event you write what happens if you come to the table with an apple (succeed), and in the bottom half you write what happens if you come with any other item (failed).

Do the same thing with page 3 and 4, but with different items.

At the end of the succesful part, you can change var#0001 back to 0, and the whole thing will start over, or you can flip self-switch A after bringing the item and make a new, 5th page in the event:

  • 5. On the last page, "self switch A is on" in the condition
you write what happens if you approach a costumer again after giving them the right dish. Here you could ask if the costumer wants something else. Then turn off the self switch and set var#0001 to 0. This will reset the whole thing.

To work this way, you should use a different variable to for each costumer. That could be annoying if you have many costumers in the restaurant at the same time. Yanfly has a plugin to solve this too:
  • YEP_SelfSwVar.js


In above example, put a "control variable: var#0002 + 1" every time you deliver the right dish and "control variable: var#0002 = 0" when brought the wrong dish. Make sure to do this for all dishes.

Then make a new last page:
  • 6. On the sixth page, you put "var#0002 ≥ 3" in the condition.
On this page you can write what happens when you have brought the 3× the right dishes to that table in a row. (I added the in a row part...) At the end of this eventpage, make the customer leave the restaurant, so you can't interact with it this round no more. Because on this page, you collect your reward for completing this events order.

Also on the 6th page, when collecting the rewards, put: "control variable: var#0003 + 1"

Now make a new event without image somewhere in the corner of your map, where the player can't reach, with one page:

  • 1. On the first page, you put "var#0003 ≥ 5" in the condition.
Here you can write what happens when 5 happy costumers left the restaurant, probably game complete.



I hope my idea above would be of any help. I just made it up while writing, so I hope I didn't miss an essential step, but I am quite confident this would work quite well.

Bonus idea:
Put: "control variable: var#0004 = playtime" and right after put: "control variable: var#0004 * -1" in the event that starts the whole mini game. (multiplying by -1 makes the value negative)

And when completing the whole mini game put: "control variable: var#0004 + playtime" in the event that closes the minigame.

Now, var#0004 + contains the seconds it took to complete the minigame. Great to make a score board with high scores.

(Ps. Sorry for talking to you as if you're a noob. I just want to explain it as clear as possible. It's not because I think you're a noob.)
Amazing reply btw ! very helpful.
I am struggling a little bit i do have the plugins i haven't used them before though.

here are my events based on the first section of your post.

but doesn't seem to work well.

Spoiler: Images
1669371038998.png

page 1 just as you said = random one to three.
1669371085483.png

then i tried the plugin on the second page didn't work too well..
1669371134085.png

Then on the third page i tried this - it kinda works.

4th page is the same. i'm also aware of the balloon being on actor not event just testing.


EDIT: i have managed to get the pop ups to work and the original mechanic !! thank you all so much !

Now I just need to get around how when player presses enter on event 1 you can see him twicth ( because no movement ) this is the engine going through the first page. i will play around and fine tune it. abit and get back to this post.

EDIT: @JohnDoeNews youre a genuis ! I've done it 😀 I understood NOTHING! but after playing around and seeing what works yeah i have the core mechanics. now trying to do the timer thing.
The first page needs to have trigger parallel or autorun.

Then the comment is not valid. I think it needs to be <label:\i[20]>

Look in the help section of the plugin for the exact tag.
@JohnDoeNews here we go! made a short video demonstrating it i have since refined it alot ! I still need to add timers in though.
instead of variables on different pages, you can check the variable
in a condional branch on page 1 as well, and use switch A, B, C, D.

you could use SS A and parallel to turn that one off after x waitframes
to shorten and simplify the event page, D if it has 3 or more consumes done
or compleeted.

they way JohnDoeNews do can have its downside (at least on my end) which
can somehow stack the events in a weird way (not sure what can cause that).

so I rather avoid variable on different event pages as I control them on 1 page.
instead of variables on different pages, you can check the variable
in a condional branch on page 1 as well, and use switch A, B, C, D.

you could use SS A and parallel to turn that one off after x waitframes
to shorten and simplify the event page, D if it has 3 or more consumes done
or compleeted.

they way JohnDoeNews do can have its downside (at least on my end) which
can somehow stack the events in a weird way (not sure what can cause that).

so I rather avoid variable on different event pages as I control them on 1 page.
Yeah a friend of mine does it this way also - typically use 1 event to control all events. Variables aren't my strong suite and I had the biggiest of headaches to get those boulders to function so you can jump on them and not walk off them XD so following his post was good for now 😀 clean up begins ! thank you everyone I learned alot today!.
instead of variables on different pages, you can check the variable
in a condional branch on page 1 as well, and use switch A, B, C, D.

you could use SS A and parallel to turn that one off after x waitframes
to shorten and simplify the event page, D if it has 3 or more consumes done
or compleeted.

they way JohnDoeNews do can have its downside (at least on my end) which
can somehow stack the events in a weird way (not sure what can cause that).

so I rather avoid variable on different event pages as I control them on 1 page.
The variable is meant to select the pages. And you need a new page per dish cause you can't have more labels on 1 page.

Not sure what you mean by staking the events in a weird way, though.

Yeah a friend of mine does it this way also - typically use 1 event to control all events. Variables aren't my strong suite and I had the biggiest of headaches to get those boulders to function so you can jump on them and not walk off them XD so following his post was good for now 😀 clean up begins ! thank you everyone I learned alot today!.
You could use 1 event to control the others, but that would complicated everything when you want to use the self variables plugin.
like 4 pages an each page has an image, it somehow stacks it.

the label part can be controlled by selfswitches, A, B, C, D ,E, F, G etc which
works better in my way than variables as I tested something.

even on 3 events, same variable, and on 3, the last event somehow stacked
with the other images, so it can be messy.

the icons balloons might work for it or comments, but I rather control it by
selfswitch for pages than with variables (personal way), I dont say your way
is bad at all, as it can work nicely, but not so much with images though.
Why not with a variable? You can't by default do: "flip random self switch" but you can do: "variable = random 1~5" and it won't stack.

Each their own, but I never had any problems using variables in conditions.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-run-random-variables-for-mini-game.152880/