PDA

View Full Version : Get npc to follow another npc


Randymarsh9
08-02-2009, 08:17 PM
I have been trying to figure out how to get some npcs to follow another one when they spawn, but I am not having any luck. The closest I got was when I did quest::settarget(npctype, 1412) but that just made them attack. None of my other ideas have come close so I won't bother posting them.

Dibalamin
08-03-2009, 07:24 AM
sub EVENT_SAY {
if($text=~/Hail/i){
quest::emote("holds a cracked monocle up to his squinty eye. 'I say!! A talking bear!! Squire Fuzzmin, come and take a gander at this rare find. The wonders never cease in the land of Kunark!!' ");
quest::unique_spawn(84312,0,0,1985,-2243,-75); # Spawn Squire_Fuzzmin for Wurmslayer quest
quest::delglobal("hobble");
quest::setglobal("hobble",$npc->GetID(),"3","F"); # Set global $hobble with Sir_Hobble's NPC ID so Squire_Fuzzmin can follow
$hobble=undef;
}
}


and


sub EVENT_SPAWN {
quest::follow($hobble);
}


Only complaint I have about follow is that in some instances it is too close and I couldn't figure a way to control the distance... (POM My Finger/Not Yours for example and it will repeat again on Derakor)

trevius
08-03-2009, 07:20 PM
You can do this:

sub EVENT_SPAWN {

#Set this to the NPCID you want the NPC to follow
my $OpponentID = 1010101;

#Get Target NPC
my $getmobbynpctype = $entity_list->GetMobByNpcTypeID($OpponentID);
#Get the NPC's Entity ID
my $follow_target = $getmobbynpctype->GetID();

quest::follow($follow_target);

}

By getting the NPC this way, you can set follow to happen from any event type including EVENT_TIMER and EVENT_SIGNAL. If you need anything else, feel free to ask.

And yeah, follow distance would be something awesome to be able to adjust. I could really use an adjustable setting for distance in the scripted event I have been working on lately.

Dibalamin
08-03-2009, 07:48 PM
Damnit >< I was so close to gettin this to work that way and just missed it by a smidge.

Thanks Trev!

trevius
08-04-2009, 07:08 AM
Added a Distance option for quest::follow(entity_id, distance) to allow setting the distance for the NPC to follow at. Seems to work really well. I think this should make the follow command a bit more useful :)

Randymarsh9
08-04-2009, 11:49 AM
I tried using the quest you put and just changed the ID, but the mob still won't follow the other npc.

Dibalamin
08-04-2009, 02:20 PM
Hmm, worked for me... I used mine with a signal however.

trevius
08-04-2009, 02:46 PM
Make sure that the npc you are spawning is not on a grid. The follow command won't work for npcs that are on a grid.

Randymarsh9
08-04-2009, 10:21 PM
Wait, they can't follow a mob on a grid?

trevius
08-04-2009, 10:57 PM
They can follow an NPC that is on a grid, they just can't be assigned to a grid themselves (the followers), which also includes a temporary grid. I think even if you use the quest::moveto command and try to make them follow something while they are on the way to that point still, it will fail because essentially it is treated like a grid with a single point in it.

Maybe you should post the whole script you are trying to make for one of these NPCs. It should be fairly easy to get it working.

Randymarsh9
08-05-2009, 12:27 PM
This is the monster that spawns the other npcs

sub EVENT_SPAWN{
quest::settimer("go", 5);
quest::spawn(1412,0,0,-635,4,-10);
quest::spawn(1412,0,0,-635,11,-10);
quest::spawn(1412,0,0,-635,21,-10);
}
sub EVENT_COMBAT{
if($combat_state ==1){
quest::stop(19);
}
if ($combat_state ==0){
quest::resume(19);
}
}
sub EVENT_TIMER{
if ($timer eq "go"){
quest::start(19);
quest::stoptimer("go");
}
}

and this is the npc I am trying to get to follow the first one

sub EVENT_SPAWN {
my $OpponentID = 1411;
my $getmobbynpctype = $entity_list->GetMobByNpcTypeID($OpponentID);
my $follow_target = $getmobbynpctype->GetID();
quest::follow($follow_target);
}

trevius
08-05-2009, 07:26 PM
EVENT_SPAWN can sometimes be a bit flaky, because it is occurring while somethings are still being set on the spawn itself. For instance, EVENT_SPAWN cannot get the entity ID of the NPC that is being spawned, because it hasn't fully been set yet. At least that is my experience with it.

So, to get around possible issues with that, you could just use a timer like this for your spawned NPCs:

sub EVENT_SPAWN {
quest::settimer("follow", 1);
}

sub EVENT_TIMER{
if ($timer eq "follow"){
my $OpponentID = 1411;
my $getmobbynpctype = $entity_list->GetMobByNpcTypeID($OpponentID);
my $follow_target = $getmobbynpctype->GetID();
quest::follow($follow_target);
quest::stoptimer("follow");
}
}

Let me know if that works for you.

Also, if you are running the latest source code, you can play with the new follow distance setting to adjust how far/close they follow the NPC. Here is an example:

quest::follow($follow_target, 25);

The default distance is 10, so this would make them follow a bit further away. Not sure if you need this or not for what you are doing, but it definitely helps make the event I am currently working on much better looking :)

Randymarsh9
08-06-2009, 02:41 PM
Thanks Trev, that worked.