View Single Post
  #9  
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