View Single Post
  #1  
Old 01-27-2010, 06:07 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default Plugin::RandomRange()

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)
Code:
#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

To use it, just do something like this in your script:
Code:
my $randomnumber = plugin::RandomRange(10, 100);
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 11-29-2010 at 08:20 AM..
Reply With Quote