PDA

View Full Version : Plugin::RandomRange()


trevius
01-27-2010, 06:07 AM
Here is another very simple plugin I made that others might find useful. It works similar to the quest::ChooseRandom() command, accept this selects randomly from a range of numbers instead of a list. It is useful if you want to select a random from 1-100 or something. You can easily do exactly what this script does just by using the perl rand() command, but I think this make selecting a range a tad bit easier.

Here are the steps to add this plugin to your server:

1. Open notepad, or whatever text editor you prefer.

2. Copy and paste the following code into Notepad:
(Note: Edited in the updated version)
#Usage: plugin::RandomRange(minvalue, maxvalue);

sub RandomRange {

my $MinRandom = $_[0];
my $MaxRandom = $_[1];

my $RandomResult = int(rand(($MaxRandom + 1) - $MinRandom)) + $MinRandom;
if ($RandomResult > $MaxRandom)
{
return $MaxRandom;
}
return $RandomResult;

}

return 1; #This line is required at the end of every plugin file in order to use it

3. Save that file to your server /plugins/ folder and name it "randomrange.pl".

4. Do a #questreload and the new plugin should be ready for use :D

To use it, just do something like this in your script:
my $randomnumber = plugin::RandomRange(10, 100);

Secrets
01-27-2010, 01:30 PM
I think I love you trevius.

I've wanted something like this forever, thanks!

trevius
07-11-2010, 06:23 PM
Minor correction for this plugin, since it always rounds down:

#Usage: plugin::RandomRange(minvalue, maxvalue);

sub RandomRange {

my $MinRandom = $_[0];
my $MaxRandom = $_[1];

my $RandomResult = int(rand(($MaxRandom + 1) - $MinRandom)) + $MinRandom;
if ($RandomResult > $MaxRandom)
{
return $MaxRandom;
}
return $RandomResult;

}

Without the + 1 there, the old way wasn't able to reach the max random number.

revloc02c
11-08-2010, 03:06 PM
4. Do a #questreload and the new plugin should be ready for use :D


Hey, I am new and learning the ropes here. Just wondering if the command "#questreload" is a GM command that you use in game (instead of shutting down EQEmu and then restarting it again, which is what I always do to test changes I made), or have I misunderstood?

Thanks

trevius
11-09-2010, 04:16 AM
Yeah, that is a GM command you use from in-game. You can always do a #help to see a list of all of the commands your account has access to. In order to get access to all commands, your account status should be 250. You can do "#help quest" to see all of the commands that contain "quest" in them as well.

revloc02c
12-13-2010, 06:41 AM
Wow. Works like a charm. Thank you, I am rolling now.

Akkadius
12-13-2010, 07:09 AM
Wow. Works like a charm. Thank you, I am rolling now.


Just a little delayed response I think.