Thread: Wandering NPC
View Single Post
  #4  
Old 10-04-2008, 11:32 PM
Neiv
Hill Giant
 
Join Date: May 2008
Location: Colorado
Posts: 238
Default

Okay, I think I have this working, but with one outstanding issue. Here's the code for the wanderer, placed in two different zones:

Code:
sub EVENT_SPAWN
	{
	quest::delglobal("wanderer");
	quest::shout("I'm in the zone now");
	quest::settimer("depop",300);
	}

sub EVENT_TIMER
	{
	if($timer eq "depop")
		{
		quest::shout("I'm leaving the zone now");
		quest::stoptimer("depop");
		quest::depop();
	
		quest::setglobal("wanderer", (quest::ChooseRandom(1, 2)), 7, "F");
		}
	}
Here's my watcher code that checks for the global, placed in one zone:

Code:
sub EVENT_WAYPOINT
	{
	if (defined($qglobals{wanderer})) 
		{

		my $x;
		my $y;
		my $z;
		my $h;

		$x = $npc->GetX();
		$y = $npc->GetY();
		$z = $npc->GetZ();
		$h = $npc->GetHeading();		

		if ($qglobals{wanderer} == 1)
			{	
			quest::spawn2(999228,0,0,$x+5,$y+5,$z,$h);
			}
		}
	}
And here is the watcher code placed in the other zone:

Code:
sub EVENT_WAYPOINT
	{
	if (defined($qglobals{wanderer})) 
		{

		my $x;
		my $y;
		my $z;
		my $h;

		$x = $npc->GetX();
		$y = $npc->GetY();
		$z = $npc->GetZ();
		$h = $npc->GetHeading();		

		if ($qglobals{wanderer} == 2)
			{	
			quest::spawn2(999228,0,0,$x+5,$y+5,$z,$h);
			}
		}
	}
The wanderer spawns in Zone A, then after 5 minutes depops and repops either in Zone A or Zone B. As you can see from the codes, the global sets a random number between 1 and 2. One Zone A's watcher looks for global setting 1, and Zone B's watcher looks for global setting 2. This works as far as it goes (when the wanderer depops from one Zone A I can find him in the Zone B, and vice versa). The problem is, when I find him in Zone B and then check his location in Zone A before the 5 minutes is up, I find he is also in Zone A (at his original spawn point before I introduced the "wandering" script).

His spawn limit is set to 1, so that's not the problem. I tried changing his spawn2 entry to 0% chance, but now he doesn;t spawn at all. I think the problem may be that Zone A is his original spawn zone (the loc where I find him is his original spawn point, not next to the Watcher like he should be); so I'm thinking if I remove him from Zone A it might work. But I wanted to get feedback on this first. Any better suggestions out there? What is the best command to remove him from the zone without removing him from the DB? Is it npcspawn remove?
Reply With Quote