Get NPCs around player

Hello,

i want to write a custom script (my first script) where npcs are talking to players.

My idea is to use the cleverbot for the npc brain, so if a player writes a normal message (say or yell), and the npc stands in front of him in a specific distance, that means, that the text is wrote to the npc and this npc uses the clever bot to answer to the player (over say).

class test : public PlayerScript
{
public:
test() : PlayerScript(“test”) {}

void OnChat(Player *player, uint32 type, uint32 lang, std::string& msg)
{
    if(type == 1 || type == 6) //Say, Yell
    {
        
        ChatHandler(player->GetSession()).PSendSysMessage("lang: %u, Msg: %s", lang, msg.c_str());
    }
}

};

this is, how my script is looking. How can i find the NPCs arround the player with the npc faction id etc. ?

You can use methods like [FONT=courier new ]GetCreatureListWithEntryInGrid[/FONT][FONT=arial] and stuff like[/FONT]

Trinity::AnyUnitInObjectRangeCheck go_check(object, radius);
Trinity::CreatureListSearcherTrinity::AnyUnitInObjectRangeCheck go_search(object, creatureList, go_check);
TypeContainerVisitor<Trinity::CreatureListSearcherTrinity::AnyUnitInObjectRangeCheck, GridTypeMapContainer> go_visit(go_search) [FONT=arial] [/FONT][FONT=arial]You can find many examples in the existing creature scripts.[/FONT]

I have tryed it, bit there is an error when i run the game and write a normal say message.

My Code:

void OnChat(Player *player, uint32 type, uint32 lang, std::string& msg)
    {
        
        if(type == 1 || type == 6) //Say, Yell
        {
            WorldObject *obj = player->GetViewpoint();
            
            const float range = 5.0;
            std::list<Creature*> list;
            
            obj->GetCreatureListWithEntryInGrid(list, player->GetGUID(), range);
            
            for (std::list<Creature*>::const_iterator it = list.begin(); it != list.end(); ++it)
            {
                (*it)->Say("Test", (Language)lang);
            }
            
            
            ChatHandler(player->GetSession()).PSendSysMessage("lang: %u, Msg: %s", lang, msg.c_str());
        }
    }


//Somewhere here: obj->GetCreatureListWithEntryInGrid(list, player->GetGUID(), range); it crashes wiith the console message: Segmentation fault

The method signature is [FONT=‘courier new’]void GetCreatureListWithEntryInGrid(std::list<Creature*>& lList, uint32 uiEntry, float fMaxSearchRange) const;[/FONT]

[FONT=arial]The 2nd parameter is the creature entry, not the player guid.[/FONT]

Ah ok, is there an id that says ‘All creatures’ ?