Loading...   


sub EVENT_SPAWN {
	quest::SetRunning(1);
	$my_faction = $npc->GetNPCFactionID();
	#$npc->NPCSpecialAttacks("Hn", 0);
	#$npc->ModifyNPCStat("can_aggro", 0);
	$aggro_event_state = 0;
}


sub EVENT_HATE_LIST {
    my $my_faction = $npc->GetNPCFactionID();			#This NPC's current faction id.
	my $my_hatelist = $npc->GetHateList();
	my @nlist = $entity_list->GetNPCList();
	my $nearby_npc_counter = 0;
	if($hate_state) {
		foreach my $n (@nlist) {
			if($n) { #Check for pull pointers to prevent crash.
				$NPC_X = $n->GetX();
				$NPC_Y = $n->GetY();
				$NPC_Z = $n->GetZ();
				my $npc_faction = $n->GetNPCFactionID();
				$distance_check = $npc->CalculateDistance($NPC_X, $NPC_Y, $NPC_Z);
				if($npc_faction ne $my_faction && ( $npc_faction == 1289 || $npc_faction == 1288 )) {
					if($distance_check < 100) {
						$random_hate_range = plugin::RandomRange(1,100);
						#quest::say("Random Hatred = ".$random_hate_range);
						$npc->AddToHateList($n, $random_hate_range);
						#quest::say("Opposing NPC found that is  ".$distance_check."ft (max: 100) away. My Faction: ".$my_faction." and theirs is ".$npc_faction);
						$nearby_npc_counter++;
					}
				}
			}
			@hatelist = $npc->GetHateList();
			if($aggro_event_state == 0) {
				#quest::say("Wiping hate list.");
				$aggro_event_state = 1;
				quest::settimer("RunDiag", 0);
				$npc->WipeHateList();
				$npc->NPCSpecialAttacks("H", 0);
			}
		}
	} else {
		if($nearby_npc_counter == 0) {
			$aggro_event_state = 0;
			#quest::say("No npc'z nearby.");
			$npc->MoveTo($npc->GetX, $npc->GetY, $npc->GetZ, $npc->GetH, 0);
			quest::resume();
		} else {
			$nearby_npc_counter = 0;
		}
		#quest::say("I is be no longer in combatz");
	}
}
sub EVENT_TIMER {
	if($timer eq "RunDiag") {
		quest::stoptimer("RunDiag");
		quest::stop();
		$How_Far = 10;
		#Set Diagonal Pathing
		#$pos_h = quest::ChooseRandom(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);
		$pos_h = plugin::RandomRange(5,45);
		$neg_h = plugin::RandomRange(5,45);
		$neg_h = -($neg_h);
		#quest::say("Pos_H: ".$pos_h." and Neg_H: ".$neg_h);
		#$neg_h = quest::ChooseRandom(-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -6, -17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30);
		$linear_heading = quest::ChooseRandom($pos_h, $neg_h);
		if($h+$linear_heading < 1) {
			$DiagonalHeading = ($h+$linear_heading+30);
		}
		if($h+$linear_heading > 360) {
			$DiagonalHeading = ($h+$linear_heading-360);
		} else {
			$DiagonalHeading = ($h+$linear_heading);
		}
		my @DestArray = plugin::CalcDestFromHeading($DiagonalHeading, $How_Far);
		my $DestX = $DestArray[0];
		my $DestY = $DestArray[1];
		my $DestZ = $DestArray[2];
		#quest::say("Diagonal Heading = ".$DiagonalHeading." <Heading: ".$h." + ".$linear_heading.">");
		
		#quest::say("Moving diagonally.");
		$npc->MoveTo($DestX, $DestY, $DestZ, $h, 1);
		quest::settimer("StopRunDiag", 2);
		#$npc->MoveTo($DestX, $DestY, $DestZ);
		#$npc->GMMove($DestX, $DestY, $DestZ, $h);
		#END OF DIAGONAL PATHING (RANDOM-LY)
	}
	
	if($timer eq "StopRunDiag") {
		#quest::stoptimer("StopRunDiag");
		$npc->NPCSpecialAttacks("H", 0, 0, 1);
		foreach $ent (@hatelist)  {
			if($ent) {
				my $h_ent = $ent->GetEnt();
				my $h_dmg = $ent->GetDamage();
				my $Client_Check = $h_ent->IsClient();
				my $h_entID = $h_ent->GetID();
				$npc->AddToHateList($h_ent, $h_dmg);
			}
		}
	}
}

Raw Paste Data