Jump to content
Existing user? Sign In

Sign In



Sign Up

[Ruse] Improved Random Item[] Selection


Flub

Recommended Posts

Hey everyone.

I bet all of you have come across the need to select a random item from a group before.

You'll see this in many areas of your server. Most prominently in your mystery / donator box files, raid rewards and crystal chest too!

An example of an item group is:

Item[] items = {new Item(113, 1) , newI Item(333,4)};

Now, we have a group that includes two items. The most common way of selecting a random reward (You'll see this EVERYWHERE) is;

Item reward = (items[Misc.getRandom(items.length - 1)], 1);

This will work. However, it's ugly! There are always ways to improve.

Here is a new method for you.. I've added mine into Misc.java. 

public static Item randomItem(final Item[] collection) {
        return collection[random(collection.length - 1)];
    }

Now, lets select a random item from our group using this new method!

(If added in Misc.java)

Item reward = Misc.randomItem(Items);

How much cleaner is that!

You can then use the item however you want. 

E.g.

player.getInventory().add(item);


Thank you!

 

Link to comment
Share on other sites

  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Contact

ltlimes

RSPS Partners

RedemptionRSPS

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

oldschoolrsps Runewild RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex, rune-server and runelocus in any way & exists solely for educational purposes.

×
×
  • Create New...