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 04-20-2019, 02:05 AM
t0neg0d
Fire Beetle
 
Join Date: Oct 2014
Posts: 25
Default Heading (LookAt x/y) and a bit more...

Couple functions and their usage...

The first (GetRandomPointAround) will get a random location around the destination coords and at the given min/max radius.

The second (LookAt) will return the correct heading to face any $mob towards a given x/y loc.

SomePlugin.pl
Code:
# PARAMS: x coord, y coord, min radius, max radius
sub GetRandomPointAround {
	my $x = shift;
	my $y = shift;
	my $minradius = shift;
	my $maxradius = shift;
	
	my $angle = rand(360);
	my $radius = $minradius+rand($maxradius-$minradius);
	
	my $ax = ($radius * sin($angle)) + $x;
	my $ay = ($radius * cos($angle)) + $y;
	
	my @ret = ($ax,$ay);
	return @ret;
}

# PARAMS: origin mob, lookat x coord, lookat y coord
sub LookAt {
	my $origin = shift;
	my $x2 = shift;
	my $y2 = shift;
	
	my $laa = atan2(($origin->GetX()-$x2),($origin->GetY()-$y2));
	$laa *= 180;
	$laa /= 3.14;
	$laa /= 360;
	$laa *= 512;
	$laa -= 256;
	
	return $laa;

	# Or comment out above from 'my $laa = ' and use:
#	return ((((atan2(($origin->GetX()-$x2),($origin->GetY()-$y2))*180)/3.14)/360)*512)-256;
}
Test case: SomeNPC.pl
Code:
my @baseloc = (1221.84, -530.34, 69.41, 172);
my @nextloc;

sub EVENT_SAY {
	if ($text=~/Hail/i) {
		@nextloc = ( plugin::GetRandomPointAround($baseloc[0],$baseloc[1],10,14) );
		
		quest::moveto(
			$nextloc[0],
			$nextloc[1],
			$baseloc[2]
		);
	}
}

sub EVENT_WAYPOINT_ARRIVE {
	$npc->SaveGuardSpot(
		$nextloc[0],
		$nextloc[1],
		$baseloc[2],
		plugin::LookAt($npc,$baseloc[0],$baseloc[1])
	);
}
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 03:23 AM.


 

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