here's code to find an npc by name from the database, and to summon that npc using it's npc id...
void Client::FindNPC(char* search_criteria)
{
int count=0;
int iSearchLen = strlen(search_criteria)+1;
char sName[36];
char sCriteria[255];
strcpy(sCriteria, search_criteria);
strupr(sCriteria);
NPCType* npc = 0;
char* pdest;
for (int i=0; i < database.max_npc_type; i++)
{
if (database.npc_type_array[i] != 0)
{
npc = (NPCType*)database.npc_type_array[i];
strcpy(sName, npc->name);
strupr(sName);
pdest = strstr(sName, sCriteria);
if (pdest != NULL)
{
Message(0, " %i: %s", (int) npc->npc_id, npc->name);
count++;
}
if (count == 20)
{
break;
}
}
}
if (count == 20)
Message(0, "20 npcs shown...too many results.");
else
Message(0, "%i npcs found", count);
}
//summonnpc from database by ID
void Client::SummonNPC(int16 npc_id) {
NPCType* npc_type = database.GetNPCType(npc_id);
if (npc_type == 0)
{
Message(0, "No such npc: %i", npc_id);
}
NPC* npc = new NPC(npc_type, 0, this->GetX(), this->GetY(), this->GetZ(), this->GetHeading());
entity_list.AddNPC(npc);
}
i just copied and modified #finditem and #summonitem.
