# Random Loot Using Random Values

2
• 37 favourites

### Attached Files

The following files have been attached to this tutorial:

.capx

### Stats

5,073 visits, 7,530 views

### Translations

• Spanish

Ever play a game that had a random loot when you searched something or killed an enemy? Of course you have, it's a nice feature to have in a game. I'll teach you how I do it in a few simple steps.

-

## The Condition

-

There are many things you could have spawn random loot, I'm going to teach you my method using a chest you click to open. You can see the 3 items it will spawn to the left, and the opened chest to the right.

-

-

## Looting Parameters

-

My poor decision to name the global variable "Loot" I'll be using the word often so to avoid confusion, if Loot is capitalized than I'm referring to the global variable.

-

You want to add a Global Variable named Loot. When the condition that would activate the loot is met, Loot needs to be set to a random value to determine the loot. But a random value on its own generates decimals so to to avoid that we round it. So Loot would be set to [round(random(1,3)] My condition is that when the chest is clicked if it's set to "default" animation it will open and set Loot to a random value.

-

-

==NOTE== in the original pictures I made a mistake and put a "-" where a "," should have been in between the numbers. You can see the proper way to do it under Loose Loot

-

### Strict Loot

-

Say you want it to have an equal chance of looting each item without an "empty" loot. You want to set the parameters to be the amount of items there are, in my case I have three items, each item has a number, so its random 1,3.

-

-

You can see when I click on the chests now it spawns a random item.

-

-

### Loose Loot

-

If you want some items to be more common than others and have times where you could possibly loot nothing, all you would do would be extend the parameter and have more than one number spawn the same item for the common items.

-

-

You can see here I've given the coin a 3/10 chance to be loot, the goblet a 2/10 chance to be loot, the crown 1/10 chance and even left 4/10 numbers for the unlucky empty loot.

-

## Summary

-

So we've effectively learned a way how to make a random loot that's easy to use and very easy to adjust and set up common items verses rare items and even the unlucky no loot at all. I have attached my .capx to this tutorial.

.CAPX