Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

How to make random events in Baldi's basics

A Tutorial for Baldi's Basics in Education and Learning

No ads for members. Membership is 100% free. Sign up!
This is another requested tutorial, I'm not trying to milk my tutorials in any way.

Also this is a decompile tutorial to remind you

1. Make a new script and open it in Visual Studio (or whatever you use, it's recommened to use Visual Studio though) this script will be the event script.

2. Make 4 new variables, the first one will be a timer for when your event will start. The next one will be how many events you have,  the next one will be the timer for your event, and the final one will reference the GameControllerScript

for the timer variable mine will be timer

for the event tracker variable mine will be events

for the GameControllerScript reference variable mine will be gc

for the event timer variable mine will be eventTimer

3.  Now in the Start Method set the timer variable with a random amount. To do this

simply code "this.timer = Mathf.RoundToInt(UnityEngine.Random.Range(your minimum time, your miximum time));"

this will make a number between the lowest and highest number

4. Now make a new void that shows the event(s). This will make more sense during the tutorial. Mine will be called "TriggerEvent"

5. Also while you are at it, in the update method paste this code in 

"if ((this.gc.spoopMode) && (this.eventTimer < 0))
{
this.timer -= "Time.deltaTime;
}
if (this.timer  <= 0)
{
this.TriggerEvent();
}
if (this.eventTimer < 0)
{
this.eventTimer -= Time.deltaTime;
}"

Time.deltaTime if you don't already know is how much time it took to draw the last frame. This is good for not having fixed results, and also helps for different types of computers. For example if it took 20 seconds to draw a frame Time.deltaTime would be 1/20 because 1 is the one frame and 20 is the amount of seconds. It's a bit confusing but you'll understand it better if you use it more.

6. Now in your new Event method or void.

randomize the event number using UnityEngine.Random.Range

for me the randomizer will be from 0 to 4

after that make an if statement like

"if (this.events == 0)

{

//Code for your first event

}

else if (this.events == 1)

{

//Code for your next event

}

else if (this.events == 2)

{

//Code for your next event

}

if (this.events == 3)

{

//Code for your next event

}

if (this.events == 4)

{

//Code for your next event

}
this.eventTimer = 15f; (You don't need to do 15 seconds, this is an example)
"

You can also play audio to indicate that an event has started then simply put the audio code before the if statements

7. Now reset the variable the events by however you do it (I don't know any code for events so it's on you).

8. Now reset the timer for your timer variable after the if statements with this

this.timer = Mathf.RoundToInt(UnityEngine.Random.Range(your minimum time, your miximum time));

And that's it!

Sign up to access this!

Embed

menu
Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Key Authors
RealT5mpler
RealT5mpler Joined 7mo ago
Offline
2,336 points Ranked 20336th
13 medals 2 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
  • 1 post awarded Exemplary Feedback Medal icon
  • 5 posts awarded Exemplary Feedback Medal icon

Submitter

RealT5mpler avatar
RealT5mpler Joined 7mo ago
Not on right ok
2,336 points Ranked 20336th
13 medals 2 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
  • 1 post awarded Exemplary Feedback Medal icon
  • 5 posts awarded Exemplary Feedback Medal icon
RealT5mpler
Creator
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

Details

Difficulty Level
Intermediate

Attributes

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • 1
  • 1.2k
  • 11
  • 2mo

More from Submitter

menu

WiPs by Submitter

menu

More Decompile Tutorials