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 Give Items Multiple Uses In Baldi's Basics!

A Tutorial for Baldi's Basics

No ads for members. Membership is 100% free. Sign up!

Oh, hi! Welcome to my tutorial!

What You Need: OSB Decompile, MS Visual Studio, Some Coding/Script Knowledge (Recommended)

Hello, and welcome to this tutorial! Today, i'm going to show you how to give items multiple uses! This works for any item, and you can even make the amount of uses each time random! First, i'll show you how to do it normally, and then how to make it random. Enjoy this tutorial, hope it helps someone!

Step 1. First, go to the gamecontroller script. Then, scroll down to near the bottom. Under DespawnCrafters(), add this:

public int itemuses;
public int itemusesleft;

These two variables will control how many uses the item has, and if the number of uses left is equal to item uses (which will be 0), then the item will go away.

Step 2. Go back up to near the top of the gamecontroller script. In the start() function, under gameoverdelay, add this.

this.itemusesleft = 3;

This will determine how many uses the item has when the game is started (in my example, its 3, but if you wanted this to be a different number, just change the 3 to your own number.

Step 3. Now, go the item of your choice in the useitem() function. After choosing one, remove the this.resetitem() in the code, and replace it with this:

this.itemusesleft -= 1;
if (this.itemusesleft == this.itemuses)
                {
                    this.ResetItem();
                    this.ItemUsesReset();
                }

You will see an error come up, i will show you how to fix this.

Step 4. Go to under the useitem() function, and put in this code:

public void ItemUsesReset()
    {
        this.itemusesleft = 3;
    }

This will make it so when the itemusesleft reaches 0, it removes the item from the player's inventory, and resets the value back to its original, 3.

Step 5. Go back into unity and go to the gamecontroller gameobject. You should see 2 new values, each with 0, pop up. Set the values so they look like this:

itemuses = 0
itemusesleft = 3


Step 6. Now, play the game and find the item you applied the code to (in my example, its bsoda). When you use the item, the itemusesleft should go down by 1 each time you use it. After 3 uses, the item should dissapear from the inventory, and the itemusesleft should reset to 3 or whatever number you set, meaning next time you use the item, it will once again have 3 uses. It should look something like in the images below.


I've used the item 2 times, and the value is now at 1.

After 3 uses, the item is gone from my inventory, and the uses have reset.

If when you test the item, this is what happens, it means it worked! 

So, now you know how to make a multi-use item! But, what if you want to make the values (number of uses each time) random? Well, its easy! The next part will show you how to do this. Only do the next few steps if you want to make the values random! If you don't want to make it random, stop here.

How To Make The # Uses Random Each Time

Step 7. Go back into the gamecontroller script and go to the start() function. Remember that code we put there earlier? Now, go to the code and change it from:

this.itemusesleft = 3;
to
int itemusesrandom = Mathf.RoundToInt(UnityEngine.Random.Range(1f, 3f)); //Choose between 1,3
this.itemusesleft = itemusesrandom; //Use the random number just chosen

This will make it so when the game starts, a random number for the uses between 1 and 3 is chosen (you can change this to your own numbers if you want, like between 2 and 6 for an example)

Step 8. Now go to the ItemUsesReset() function we made earlier and change it from:
public void ItemUsesReset()
    {
        this.itemusesleft = 3;
    }
to
public void ItemUsesReset()
    {
        int itemusesrandomreset = Mathf.RoundToInt(UnityEngine.Random.Range(1f, 3f)); //Choose 1,3
        this.itemusesleft = itemusesrandomreset; //Use the random number just chosen
    }


This will make it so when the number of uses resets, it will be a random number between 1 and 3 (meaning it could reset to 1, 2, or 3 uses for next time).

Step 9. Go back into unity, start the game, and test to see if it worked! If it did, the values should be different for itemusesleft each time.


As you can see, when i started, the usesleft was 2, but after using the item, it reset to 1! This means it worked.

And that's how to make an item with multiple uses in baldi's basics! I hope you found this tutorial helpful, and if anyone wants to give me tutorial suggestions for the future, i would appreciate that. If you still have any questions about how to do this, or its not working for you, i can try and help.
Sign up to access this!

No comments yet

Embed

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

Credits

Original Authors
JohnsterSpaceProgram Johnster Space Studio Flag
Affiliation
Johnster Space Studio
Offline
1,762 points Ranked 21245th
25 medals 2 legendary 4 rare
  • 2019 Top Contributor Medal icon
  • Returned 5000 times Medal icon
  • Returned 1000 times Medal icon
  • 10 submissions featured Medal icon
  • Reached 50 subscribers Medal icon
  • Received thanks 50 times Medal icon
Made This Tutorial (First In A While)
Special Thanks
Paulor94
Paulor94 Joined 1y ago
Offline
1,299 points Ranked 22614th
15 medals 2 rare
  • Returned 1000 times Medal icon
  • Submitted 20 Gamefiles Medal icon
  • One month a member Medal icon
  • Submitted 5 Gamefiles Medal icon
  • Returned 100 times Medal icon
  • Submission featured Medal icon
Helped Me With Getting The Code Working

Submitter

Dynablocks Work
1,762 points Ranked 21245th
25 medals 2 legendary 4 rare
  • 2019 Top Contributor Medal icon
  • Returned 5000 times Medal icon
  • Returned 1000 times Medal icon
  • 10 submissions featured Medal icon
  • Reached 50 subscribers Medal icon
  • Received thanks 50 times Medal icon
JohnsterSpaceProgram Johnster Space Studio Flag
Affiliation
Johnster Space Studio

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
  • 627
  • 20d

More from Submitter

WiPs by Submitter

More Scripting Tutorials