Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Plugins & Mods

Quests::Plugins & Mods Completed plugins for public use as well as modifications.

Reply
 
Thread Tools Display Modes
  #1  
Old 01-27-2010, 06:03 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default Plugin::RandomRoam()

For anyone interested, I created a new plugin to play with on my server that I thought others might like to try out. It requires that you are running server code of revision 1175 or later to have access to the new quest objects I recently added.

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:
Code:
#NOTE: These functions require the globals.pl file for use of the val() plugin

#Usage: plugin::RandomRoam(MaxXVariance, MaxYVariance, MaxZVariance, LoSMobSize);
# MaxXVariance - Sets the max X variance to travel 
# MaxYVariance - Sets the max Y variance to travel 
# MaxZVariance - Sets the max Z variance to travel.  This field is optional and default is 15.
# LoSMobSize - Sets the size of the mob LoS check.  This field is optional and default is 5.
# The LoS check basically looks from your NPC to an imaginary NPC of the LoSMobSize size to see if LoS exists

sub RandomRoam {

	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	my $MaxZVariance = $_[2];
	my $LoSMobSize = $_[3];

	#Set the Max Z Variance to 15 if no 3rd argument is set
	if(!$MaxZVariance){
		$MaxZVariance = 15;
	}
	
	#Set the LoS Check Mob Size to 5 if no 4th argument is set
	if(!$LoSMobSize){
		$LoSMobSize = 5;
	}
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX);
			my $NewY = quest::ChooseRandom($PosY, $NegY);
			
			#Check for LoS and Z issues before moving to the new Loc
			my $NewZ = $npc->FindGroundZ($NewX,$NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
			if ($NewZ > -999999 && $OrigZ > ($NewZ - $MaxZVariance + 1) && $OrigZ < ($NewZ + $MaxZVariance - 1)) {
				my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY, $NewZ, $LoSMobSize);
				#Check LoS to the new random Loc
				if ($LoS_Check) {
					quest::moveto($NewX, $NewY, $NewZ, -1, 1);
				}
			}
		}
	}
}

#Usage: plugin::StraightPath(MaxXVariance, MaxYVariance);

sub StraightPath {
	
	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {	

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX, $OrigX, $OrigX);
			
			if ($NewX == $OrigX) {	# If we are using the orignal X, then chose a random Y to go to
				if ($CurX == $OrigX) {	# If they are moving on the same Axis they are currently on
					my $NewY = quest::ChooseRandom($PosY, $NegY);
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewY > $OrigY) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY + 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY - 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
			else {	# If we are not using the orignal X, then use the original Y instead
				if ($CurY == $OrigY) {	# If they are moving on the same Axis they are currently on
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $OrigY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewX > $OrigX) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX + 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls						
							my $LoS_Check = $npc->CheckLoSToLoc($NewX - 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {

								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
		}
	}
}


#Usage: plugin::RandomSwim(MaxXVariance, MaxYVariance, WaterSurfaceZ);

sub RandomSwim {

	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	my $WaterSurfaceZ = $_[2];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX);
			my $NewY = quest::ChooseRandom($PosY, $NegY);
			
			#Check for LoS and Z issues before moving to the new Loc
			my $NewZ = $npc->FindGroundZ($NewX,$NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
			if ($NewZ > -999999 && $NewZ < $WaterSurfaceZ) {
				my $SwimZ = plugin::RandomRange($NewZ, $WaterSurfaceZ);
				my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY, $SwimZ, 5);
				#Check LoS to the new random Loc
				if ($LoS_Check) {
					#if($npc->GetFlyMode() != 1) {
					#	$npc->SetFlyMode(1);
					#}
					quest::moveto($NewX, $NewY, $SwimZ, -1, 1);
				}
			}
		}
	}
}

#Usage: my @DestArray = plugin::CalcDestFromHeading(Heading, Distance, [Mob, MaxZDiff]);
# This plugin calculates the destination X and Y loc based on heading and distance
# Heading is the heading you want to calculate destination X Y Z from
# Distance is the distance you want for the destination X and Y from the source
# Mob is an optional field to allow any mob to be set, but $npc is default
# MaxZDiff is the max height difference from the source mob's Z you want to calculate the destination from.
#
# The output array can be used as follows:
# my $DestX = $DestArray[0];
# my $DestY = $DestArray[1];
# my $DestZ = $DestArray[2];

sub CalcDestFromHeading {

	my $npc = plugin::val('$npc');
	my $Heading = $_[0];
	my $Distance = $_[1];
	my $Mob = $_[2];
	my $MaxZDiff = $_[3];
	
	if (!$Distance) { return; }
	if (!$Mob) { $Mob = $npc; }
	if (!$MaxZDiff) { $MaxZDiff = 50; }
	
		my $ReverseHeading = 256 - $Heading;
		my $ConvertAngle = $ReverseHeading * 1.40625;
		if ($ConvertAngle <= 270) {
			$ConvertAngle = $ConvertAngle + 90;
		}
		else {
			$ConvertAngle = $ConvertAngle - 270;
		}
		my $Radian = $ConvertAngle * (3.1415927 / 180);

		my $CircleX = $Distance * cos($Radian);
		my $CircleY = $Distance * sin($Radian);
		my $DestX = $CircleX + $Mob->GetX();
		my $DestY = $CircleY + $Mob->GetY();
		my $DestZ = $Mob->FindGroundZ($DestX, $DestY, $MaxZDiff);
		my @DestArray = ($DestX, $DestY, $DestZ);
		return @DestArray;
}

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 "randomroam.pl".

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


What this plugin does is to pick a random location around the NPC's Spawn Point, and if it has LoS to that spot, it will path there. This works similar to the roambox stuff, but it doesn't require that you get actual locs around the NPC(s) that you want to use it. It also does LoS checks, so it knows if it can move there or not. This means that it should work for random roaming just about anywhere. It would be ideal in open outdoor areas, but should technically work indoors as well.

Here is an example script of an NPC using the RandomRoam() plugin:

Code:
sub EVENT_SPAWN {
	#Set a random timer between 5 and 30
	my $StartMove = int(rand(25)) + 5;
	quest::settimer("roam", $StartMove);
}

sub EVENT_TIMER {
	if ($timer eq "roam") {
		quest::stoptimer("roam");
		plugin::RandomRoam(100, 100);
		my $NextMove = int(rand(25)) + 5;
		quest::settimer("roam", $NextMove);
	}
}
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!

Last edited by trevius; 08-31-2010 at 11:13 PM..
Reply With Quote
  #2  
Old 01-27-2010, 02:05 PM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,447
Default

Saw you talking on IRC about this, looks good to me. It's highly CPU efficient too, from what you were telling me. Nice.
Reply With Quote
  #3  
Old 01-27-2010, 06:10 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Yeah, I have probably 100+ NPCs running this in the new Hills of Shade zone I am working on currently, and I see no CPU utilization increase when they are active. My CPU stays around 2-3%, so it seems like it could be used pretty freely without much concern.

It might be nice to add something that does this into the source to be set similar to how roam boxes are, so you don't need to add anything to the script. I might try to add something like that in at some point if someone doesn't do it before then.

Anyone with SoF can check this script out in action by starting a char on Storm Haven and going to Temple of Marr, and then using the portal there (walk onto the pad labeled "Hills of Shade Portal"). The zone is under development now, but I am leaving access to it up while it is being developed. There is some actual pathing mobs in the zone, but almost everything other than the Mushroom section of the zone is currently using this plugin to handle pathing. I am pretty impressed with how good it works so far. Instead of having to manually create random grids or roamboxes for a hundred or so spawn points, I was able to add this plugin to them and turn hours of work into a few minutes (not counting the time it took to write this plugin and the new quest Objects, of course!)
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #4  
Old 01-28-2010, 09:58 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Here is another slightly more complicated plugin similar to the random roam, accept this one will only go in straight lines, North, South, East, or West. It also checks the LoS slightly further than how far it actually plans to move, to help keep NPCs away from walls a little. The main use for this one is indoor areas that line up well with the X Y axis. It still isn't nearly as good as real pathing in indoors, but it can give your NPCs a little life without too much work and without looking too buggy.

To install this plugin, just follow the steps for the previous plugin and name this one's file "straightpath.pl"

Code:
#Usage: plugin::StraightPath(MaxXVariance, MaxYVariance);

sub StraightPath {
	
	my $npc = $_[0];
	my $MaxXVariance = $_[1];
	my $MaxYVariance = $_[2];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {
		#my $AtGuardSpot = 0;	

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc
			#$AtGuardSpot = 1;

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX, $OrigX, $OrigX);
			
			if ($NewX == $OrigX) {	# If we are using the orignal X, then chose a random Y to go to
				if ($CurX == $OrigX) {	# If they are moving on the same Axis they are currently on
					my $NewY = quest::ChooseRandom($PosY, $NegY);
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewY > $OrigY) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY + 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY - 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
			else {	# If we are not using the orignal X, then use the original Y instead
				if ($CurY == $OrigY) {	# If they are moving on the same Axis they are currently on
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $OrigY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewX > $OrigX) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX + 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls						
							my $LoS_Check = $npc->CheckLoSToLoc($NewX - 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {

								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
		}

		#Bool Return option to see the result of if the NPC is at it's new loc or not
		#return $AtGuardSpot;
	}
}

return 1;	#This line is required at the end of every plugin file in order to use it
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #5  
Old 01-28-2010, 11:41 AM
cavedude's Avatar
cavedude
The PEQ Dude
 
Join Date: Apr 2003
Location: -
Posts: 1,988
Default

This is really top notch work. I added both plugins to PEQ's repo and will play around with it in overthere I think
Reply With Quote
  #6  
Old 01-28-2010, 06:01 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Thanks CD, I thought you might like it I am pretty impressed with how well it works, myself.

I was thinking again about putting something like this into the source, and I think it might be fairly easy. Instead of adding more stuff to NPC settings, I think it makes more sense to just add a command that will automatically create a roambox around an NPC spawn point based on Max X and Y variances from the spawn point. So, you would just target the NPC you want to add a roambox for and type something like "#autoroambox 100 100", and that would set it to update the database for that spawn group to use a roam box with a 100 variance for X and Y.

Unless anyone objects, I can probably just add LoS and Z checks into the roam box code. I don't see any reason not to add it. I haven't really looked into the roam box code much yet, so it might already do it as far as I know, but I doubt it.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #7  
Old 01-28-2010, 06:19 PM
nilbog
Hill Giant
 
Join Date: Nov 2007
Posts: 198
Default

Thank you Trevius!
Reply With Quote
  #8  
Old 01-29-2010, 05:05 AM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,071
Default

This is phenominal, I'm already using this for a very unique but closer to the beginning part of the project which was kind of a similar situation, except for I dont have to create waypoints. Awesome, thank you once again Trevius.
Reply With Quote
  #9  
Old 01-31-2010, 04:39 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

No problem. Glad you guys are liking it

After looking into the plugins Shendare created and shared a while back, I see that passing $npc into the plugin is no longer required if you have the globals.pl file by Shendare already. So, for people who already have that file, you can use this version of the roam plugins:

Code:
#NOTE: These functions require the globals.pl file for use of the val() plugin

#Usage: plugin::RandomRoam(MaxXVariance, MaxYVariance);

sub RandomRoam {

	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {
		#my $AtGuardSpot = 0;	

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc
			#$AtGuardSpot = 1;

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX);
			my $NewY = quest::ChooseRandom($PosY, $NegY);
			
			#Check for LoS and Z issues before moving to the new Loc
			my $NewZ = $npc->FindGroundZ($NewX,$NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
			if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
				my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY, $NewZ, 5);
				#Check LoS to the new random Loc
				if ($LoS_Check) {
					quest::moveto($NewX, $NewY, $NewZ, -1, 1);
				}
			}
		}

		#Bool Return option to see the result of if the NPC is at it's new loc or not
		#return $AtGuardSpot;
	}
}

#Usage: plugin::StraightPath(MaxXVariance, MaxYVariance);

sub StraightPath {
	
	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {
		#my $AtGuardSpot = 0;	

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc
			#$AtGuardSpot = 1;

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX, $OrigX, $OrigX);
			
			if ($NewX == $OrigX) {	# If we are using the orignal X, then chose a random Y to go to
				if ($CurX == $OrigX) {	# If they are moving on the same Axis they are currently on
					my $NewY = quest::ChooseRandom($PosY, $NegY);
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewY > $OrigY) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY + 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY - 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
			else {	# If we are not using the orignal X, then use the original Y instead
				if ($CurY == $OrigY) {	# If they are moving on the same Axis they are currently on
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $OrigY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewX > $OrigX) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX + 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls						
							my $LoS_Check = $npc->CheckLoSToLoc($NewX - 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {

								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
		}

		#Bool Return option to see the result of if the NPC is at it's new loc or not
		#return $AtGuardSpot;
	}
}

return 1;	#This line is required at the end of every plugin file in order to use it
Just save that as whatever you want to call it. Something like "path_tools.pl" would work fine. Then, remove the files with the old versions (randomroam.pl and straightpath.pl). I combined the 2 into a single file, since they are both related.

The usage on these is simply:

Code:
plugin::RandomRoam(100, 100);
or

Code:
plugin::StraightPath(100, 100);
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #10  
Old 02-09-2010, 10:35 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I added another pathing plugin named RandomSwim.

Usage - plugin::RandomSwim(MaxXVariance, MaxYVariance, WaterSurfaceZ);

It works just like the RandomRoam plugin, but won't let the NPC go to any point higher than the water surface Z you put into the plugin command. It will swim to a random X, Y and Z in water. This makes them swim a bit choppy if there isn't a water map for the zone, but if there is, I think they should swim pretty nicely.

Here is the current whole path_tools.pl file that I use:

Code:
#NOTE: These functions require the globals.pl file for use of the val() plugin

#Usage: plugin::RandomRoam(MaxXVariance, MaxYVariance);

sub RandomRoam {

	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX);
			my $NewY = quest::ChooseRandom($PosY, $NegY);
			
			#Check for LoS and Z issues before moving to the new Loc
			my $NewZ = $npc->FindGroundZ($NewX,$NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
			if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
				my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY, $NewZ, 5);
				#Check LoS to the new random Loc
				if ($LoS_Check) {
					quest::moveto($NewX, $NewY, $NewZ, -1, 1);
				}
			}
		}
	}
}

#Usage: plugin::StraightPath(MaxXVariance, MaxYVariance);

sub StraightPath {
	
	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX, $OrigX, $OrigX);
			
			if ($NewX == $OrigX) {	# If we are using the orignal X, then chose a random Y to go to
				if ($CurX == $OrigX) {	# If they are moving on the same Axis they are currently on
					my $NewY = quest::ChooseRandom($PosY, $NegY);
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewY > $OrigY) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY + 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY - 2, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $NewY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
			else {	# If we are not using the orignal X, then use the original Y instead
				if ($CurY == $OrigY) {	# If they are moving on the same Axis they are currently on
					#Check for LoS and Z issues before moving to the new Loc
					my $NewZ = $npc->FindGroundZ($NewX, $OrigY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
					if ($NewZ > -999999 && $OrigZ > ($NewZ - 16) && $OrigZ < ($NewZ + 14)) {
						if ($NewX > $OrigX) {	# Checking which direction we are moving in
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls
							my $LoS_Check = $npc->CheckLoSToLoc($NewX + 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {
								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
						else {
							# Adjust the LoS Check to check further than how far we are traveling so we stay away from walls						
							my $LoS_Check = $npc->CheckLoSToLoc($NewX - 2, $OrigY, $NewZ, 5);
							#Check LoS to the new random Loc
							if ($LoS_Check) {

								quest::moveto($NewX, $OrigY, $NewZ, -1, 1);
							}
						}
					}
				}
				else {	# If not moving on the same Axis they are already on, just return them to their Spawn Point
					quest::moveto($OrigX, $OrigY, $OrigZ, -1, 1);
				}
			}
		}
	}
}

#Usage: plugin::RandomSwim(MaxXVariance, MaxYVariance, WaterSurfaceZ);

sub RandomSwim {

	my $npc = plugin::val('$npc');
	my $MaxXVariance = $_[0];
	my $MaxYVariance = $_[1];
	my $WaterSurfaceZ = $_[2];
	
	# Don't try to roam if already engaged in combat!
	if ($npc->IsEngaged() != 1) {

		#Get needed Locs
		my $CurX = $npc->GetX();
		my $CurY = $npc->GetY();
		#my $CurZ = $npc->GetZ();	#Not currently required by this plugin
		my $OrigX = $npc->GetSpawnPointX();
		my $OrigY = $npc->GetSpawnPointY();
		my $OrigZ = $npc->GetSpawnPointZ();
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();

		if ($CurX == $GuardX && $CurY == $GuardY) {	#If the NPC has finished walking to the previous given Loc

			#Get a random X and Y within the set range
			my $RandomX = int(rand($MaxXVariance - 1)) + 1;
			my $RandomY = int(rand($MaxYVariance - 1)) + 1;
			my $PosX = $OrigX + $RandomX;
			my $PosY = $OrigY + $RandomY;
			my $NegX = $OrigX - $RandomX;
			my $NegY = $OrigY - $RandomY;
			my $NewX = quest::ChooseRandom($PosX, $NegX);
			my $NewY = quest::ChooseRandom($PosY, $NegY);
			
			#Check for LoS and Z issues before moving to the new Loc
			my $NewZ = $npc->FindGroundZ($NewX,$NewY, 5) + 1;	#Add 1 to the new Z to prevent hopping issue when they arrive
			if ($NewZ > -999999 && $NewZ < $WaterSurfaceZ) {
				my $SwimZ = int(rand($WaterSurfaceZ - $NewZ)) + $NewZ;	#Use a random Z between water surface and floor
				my $LoS_Check = $npc->CheckLoSToLoc($NewX, $NewY, $SwimZ, 5);
				#Check LoS to the new random Loc
				if ($LoS_Check) {
					quest::moveto($NewX, $NewY, $SwimZ, -1, 1);
				}
			}
		}
	}
}

return 1;	#This line is required at the end of every plugin file in order to use it
Make sure that if you use all of these plugins combined into a single file (like I do now), that you remove the old randomroam.pl and straightpath.pl files from your plugins folder.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #11  
Old 03-21-2010, 12:19 PM
Lillu
Hill Giant
 
Join Date: Sep 2008
Posts: 204
Default

Trev mucho <3 !
__________________
Reply With Quote
  #12  
Old 04-03-2010, 05:14 AM
dreamseer
Fire Beetle
 
Join Date: Feb 2010
Location: York
Posts: 22
Default

I was wondering this is such a monumental idea, would it be possible to have a group of mobs randomly roaming?

Perhaps one mob does the random roam and the other "follow" or something.

My thinking is:
Pack of Wolves Hunting.
Small detachment of soldiers on random partol.
Group of Marauding Bandits
Reply With Quote
  #13  
Old 04-03-2010, 06:11 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Yeah, it is completely possible, if you know the formation you want them in. Here is a snippet of a script I made that does just that and has 4 NPCs that follow surrounding the boss mob this script is on:

Code:
#Random Roamer Group Script

my $SpawnDist = 10;

#Save NPC Entity IDs here (4 total)
my $NPCPlusX = 0;
my $NPCMinusX = 0;
my $NPCPlusY = 0;
my $NPCMinusY = 0;

sub EVENT_SPAWN {

	my $StartMove = plugin::RandomRange(10, 30);
	quest::settimer("roam", $StartMove);
	quest::settimer("spawn_guards", 5);
	
}

sub EVENT_TIMER {

	if ($timer eq "roam") {
		quest::stoptimer("roam");
		plugin::RandomRoam(100,100);
		my $GuardX = $npc->GetGuardPointX();
		my $GuardY = $npc->GetGuardPointY();
		my $GuardZ = $npc->GetGuardPointZ();
		my $NPC1 = $entity_list->GetNPCByID($NPCPlusX);
		my $NPC2 = $entity_list->GetNPCByID($NPCMinusX);
		my $NPC3 = $entity_list->GetNPCByID($NPCPlusY);
		my $NPC4 = $entity_list->GetNPCByID($NPCMinusY);
		
		if ($NPC1) {
			$NPC1->MoveTo($GuardX + $SpawnDist, $GuardY, $GuardZ, 0, 1);
		}
		if ($NPC2) {
			$NPC2->MoveTo($GuardX - $SpawnDist, $GuardY, $GuardZ, 0, 1);
		}
		if ($NPC3) {
			$NPC3->MoveTo($GuardX, $GuardY + $SpawnDist, $GuardZ, 0, 1);
		}
		if ($NPC4) {
			$NPC4->MoveTo($GuardX, $GuardY - $SpawnDist, $GuardZ, 0, 1);
		}
		my $NextMove = plugin::RandomRange(5, 30);
		quest::settimer("roam", $NextMove);
	}
	
	if ($timer eq "spawn_guards") {
		quest::stoptimer("spawn_guards");
		my $MyX = $npc->GetSpawnPointX();
		my $MyY = $npc->GetSpawnPointY();
		my $MyZ = $npc->GetSpawnPointZ();
		quest::spawn(2701558,0,0,$MyX + $SpawnDist, $MyY, $MyZ);	#NPCPlusX
		quest::spawn(2701558,0,0,$MyX - $SpawnDist, $MyY, $MyZ);	#NPCMinusX
		quest::spawn(2701558,0,0,$MyX, $MyY + $SpawnDist, $MyZ);	#NPCPlusY
		quest::spawn(2701558,0,0,$MyX, $MyY - $SpawnDist, $MyZ);	#NPCMinusY
		quest::settimer("SetNPCVars", 2);
	}
	
	if ($timer eq "SetNPCVars") {
		quest::stoptimer("SetNPCVars");
		my $MySpawnedX = $npc->GetSpawnPointX();
		my $MySpawnedY = $npc->GetSpawnPointY();

		my @npclist = $entity_list->GetNPCList();
		foreach $ent (@npclist)
		{
			if($ent->GetNPCTypeID() == 2701558) {
				my $GuardianX = $ent->GetX();
				my $GuardianY = $ent->GetY();
				
				if($GuardianX > $MySpawnedX + $SpawnDist - 2) {
					$NPCPlusX = $ent->GetID();
				}
				if($GuardianX < $MySpawnedX - $SpawnDist + 2) {
					$NPCMinusX = $ent->GetID();
				}
				if($GuardianY > $MySpawnedY + $SpawnDist - 2) {
					$NPCPlusY = $ent->GetID();
				}
				if($GuardianY < $MySpawnedY - $SpawnDist + 2) {
					$NPCMinusY = $ent->GetID();
				}
			}
		}
	}

}
There is actually a lot more to my script, but not directly related to moving a group of mobs. This script here should give you the basic idea of what to do.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #14  
Old 04-19-2010, 07:04 AM
Meged
Fire Beetle
 
Join Date: Dec 2007
Posts: 8
Default

I'm getting this error in the zone log when I use this plugin.

Script error: qst67030::EVENT_TIMER - Perl runtime error: Can't locate object method "GetSpawnPointX" via package "NPC" at plugins/randomroam.pl line 16.

Using the latest axclassic repack.

Any ideas? Perl version? I'm running 5.1.0. (I think)

Thanks
Reply With Quote
  #15  
Old 04-19-2010, 08:23 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

It requires that you are running server code of revision 1175 or later to have access to the new quest objects.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 10:34 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3