PDA

View Full Version : Get All NPCs by NPCTypeID


Hateborne
04-27-2014, 03:20 PM
Hilariously stupid quest, maybe I'm just hungry.

Is there any easy way to pull all the NPCs by npc_type id?

I thought the below bit would work, but it seems to only pull one. I have 11 of npc_type id 12345 in the zone, but it seems to only select one of them.
my @creatures = $entity_list->GetNPCByNPCTypeID(12345);

I am using this in the default.pl for the zone and I'm trying to select three of them to start on a grid.

Pre-emptive thank you!
-Hate

sorvani
04-27-2014, 03:55 PM
It is returning once it finds the first one. So it is working as intended.


entity.cpp line 856
NPC *EntityList::GetNPCByNPCTypeID(uint32 npc_id)
{
if (npc_id == 0 || npc_list.empty())
return nullptr;

auto it = npc_list.begin();
while (it != npc_list.end()) {
if (it->second->GetNPCTypeID() == npc_id)
return it->second;
++it;
}

return nullptr;
}

sorvani
04-27-2014, 03:57 PM
As much as I hate signals, that is the only thing that would work here

quest::signal(npc_id, wait=0 ) # cause an EVENT_SIGNAL on all mobs in the zone with this NPC type, with $signalid = 0. wait is an optional time to wait in ms before sending signal.
quest::signalwith(npc_id,signal_id, wait=0) # same as signal(), except it sets $signal to the supplied signal_id. wait is an optional time to wait in ms before sending signal.

Akkadius
04-27-2014, 04:42 PM
Can do it via signals or very simply:

my @nlist $entity_list->GetNPCList();
foreach my $n (@nlist){
if($n->GetNPCTypeID() == ID){
DoStuff();
}
}