EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Get All NPCs by NPCTypeID (https://www.eqemulator.org/forums/showthread.php?t=38221)

Hateborne 04-27-2014 03:20 PM

Get All NPCs by NPCTypeID
 
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.
Code:

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
Code:

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

Code:

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:

Code:

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



All times are GMT -4. The time now is 03:06 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.