PDA

View Full Version : Plugin::RandomRoam()


trevius
01-27-2010, 06:03 AM
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:
#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 :D


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:

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);
}
}

Secrets
01-27-2010, 02:05 PM
Saw you talking on IRC about this, looks good to me. It's highly CPU efficient too, from what you were telling me. Nice.

trevius
01-27-2010, 06:10 PM
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!) :)

trevius
01-28-2010, 09:58 AM
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"

#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

cavedude
01-28-2010, 11:41 AM
This is really top notch work. I added both plugins to PEQ's repo and will play around with it in overthere I think :)

trevius
01-28-2010, 06:01 PM
Thanks CD, I thought you might like it :D 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.

nilbog
01-28-2010, 06:19 PM
Thank you Trevius!

Akkadius
01-29-2010, 05:05 AM
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.

trevius
01-31-2010, 04:39 AM
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:

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

plugin::RandomRoam(100, 100);

or

plugin::StraightPath(100, 100);

trevius
02-09-2010, 10:35 PM
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:

#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.

Lillu
03-21-2010, 12:19 PM
Trev mucho <3 !

dreamseer
04-03-2010, 05:14 AM
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

trevius
04-03-2010, 06:11 AM
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:

#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.

Meged
04-19-2010, 07:04 AM
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

trevius
04-19-2010, 08:23 AM
It requires that you are running server code of revision 1175 or later to have access to the new quest objects.

Shiny151
04-19-2010, 01:37 PM
So Trev, does this plugin work on any zone with mobs that already have designated paths? What about NPCs that are supposed to be static?

Meged
04-19-2010, 04:32 PM
Thanks Trevius, I'm only running v1048 so will have to update.

Thanks again

trevius
04-19-2010, 05:21 PM
So Trev, does this plugin work on any zone with mobs that already have designated paths? What about NPCs that are supposed to be static?

This plugin only works on NPCs you specifically set it on in the quest script for them as I mentioned in the first post with an example. So, if you don't want them to use random roaming, just don't add it to their quest file. That goes for non-roaming NPCs and NPCs with pathing that you don't want them to be moving other than what they may already be set for.

If you just try it out using the example I posted, it should be pretty easy to see what is going on and how to use it.

trevius
07-17-2010, 05:07 PM
Here is my latest modifications to these path tools. The main change is that RandomRoam now allows for an optional Z variance setting as well as an optional LoS mob size setting.

#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);
}
}
}
}
}

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

trevius
07-26-2010, 06:59 PM
I added a new plugin to the original post. It is CalcDestFromHeading and basically lets you calculate a destination X and Y based on a heading and distance. It is really nice for projectiles and also handy if you want to surround something with a circle of spawns or whatever.

Here is the description, but for the actual code, see the first post in this thread:

#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];

Randymarsh9
03-24-2012, 09:40 PM
I copied the example quest given at the beginning of the thread directly, but I still cannot get the random roaming to work. I have the globals.pl and path_tools.pl in my plugins folder, and I've even tried renaming path_tools to randomroam and RandomRoam. I have my source code up to date and everything, so I'm really not sure why I cannot get this working. Anyone have any thoughts?

Randymarsh9
03-24-2012, 11:37 PM
Nevermind, I found the problem

wolfwalkereci
07-17-2013, 04:54 PM
Anyone with a up to date server able to get this plugin to work?

KLS
07-17-2013, 07:24 PM
We use it on PEQ in crescent reach cause Cavedude was too lazy to go make grids and it appears to still work.

wolfwalkereci
07-17-2013, 09:21 PM
We use it on PEQ in crescent reach cause Cavedude was too lazy to go make grids and it appears to still work.
Hmm not sure whats happening then. Does not work at all for me but I have not used it in some time so I have no clue why.
Roam box is terrible in zones where the Z varies and I hate making grids but guess thats the only thing left to do. /cry
Anyways thanks for letting me know its working as is on PEQ. Helps reaffirm that I noobed something up and should just try again until it works.

Mariomario
07-18-2013, 10:38 PM
Ive had problems with this plugin myself. Mainly when I create a new quest folder for a zone that doesn't already have a folder created. I can zone into Crescent Reach and see the script working correctly on the bears, snakes, spiders etc from the original PEQ quests directly from the SVN. However when I copy the exact same script and move it into a newly created folder for say Elddar Forest, the plugin does not work even though it is working in Crescent Reach.

Other scripts work correctly in the newly created elddar folder, even other plugins, but not the randomroam for some strange reason. Even scripts from the global_player and global_npc work in the zone, just not this particular plugin, yet the plugin does work in other default zone folders that come with the SVN. Hopefully this narrows down the problem.

wolfwalkereci
07-19-2013, 12:39 AM
Thanks for that feedback Mariomario, it may be the cause of my issue.
I am using zones that are not used yet on peq so I have to create their quest folder. Everything else I am doing is working except this plugin.
It's frustrating because I want to be lazy and not create nice pathing via grids.

trevius
07-19-2013, 03:52 AM
Keep in mind that for this plugin to work, you need to have LoS working in the zone! I suspect this is the issue you guys are having with this plugin. This means that you need a map file for the zone, and many of the newer expansion zones don't have map files yet. You can create your own map files using Azone2 for every map up to current, I believe.

You can easily test if LoS is working in your zone by trying to cast a spell on a nearby NPC, or by using the "#los" command if you have access to that command (GMs do). If #los shows you do not have Line of Sight to an NPC you are standing right next to, then you are almost certainly missing the map file for that zone and will need to create one yourself. The zone won't be functional for playing in until you get a map file anyway, as you won't be able to cast detrimental spells in there on targets other than yourself. Also KoS mobs will not have LoS to be able to aggro on anyone as they should.

Akkadius
07-19-2013, 11:21 AM
As Trevius stated, if you don't have map files for that zone, the plugin will not work correctly because it uses LoS checks based on the map files.

If you want to create your own, azone.exe can be downloaded on the links in the menu to the left of the forums. You would generate a map file by command line and running it against one of your EverQuest client zone files and it will spit out a .map file.

Here is an example I just ran:

E:\Software\HoT EQEmu>Azone2.exe elddar
AZONE2: EQEmu .MAP file generator with placeable object support.
Attempting to load EQG elddar
Unable to open takish.tog
There are 3502716 vertices and 1167572 faces.
EQG V4 Placeable Zone Support
ObjectGroupCount = 728
azone.ini not found in current directory. Including default models.
After processing placeable objects, there are 7397901 vertices and 2465967 faces.
Bounding box: -1937.14 < x < 2240.00, -2288.77 < y < 2271.11
Building quadtree.
Done building quad tree...
Match counters: 15263979 easy in, 44575009 easy out, 26248 hard in, 0 hard out.
Writing map file.
Map header: Version: 0x01000000. 2465967 faces, 4435 nodes, 2768624 facelists
Done writing map (132.96MB).


Should result in a .map file that as stated above is 132.96MB titled 'elddar.map'

wolfwalkereci
07-19-2013, 12:38 PM
Oh man I had forgot about the LOS but I swear to god I already made the .map files for all these zones I am using. Oh well better just remake, but Trevius and Akkadius thanks for chiming in and clearing that up.
Server "10" -- wolf "-1"

NatedogEZ
07-19-2013, 02:02 PM
Hmm.. tried to do this.. and any time i ran Azone.exe with any zone that OBJ files it would always crash...

I moved out the OBJ file and then it would create the map file correctly

wolfwalkereci
07-19-2013, 02:19 PM
Nate - I just pulled source and compiled azone and had no issues at all.