Help| Looping through gameobject

Greetings

I’m pretty much trying to loop through all the gameobjects who’s in a certain distance and change their phase. as result the script crashed my server. I can post a debug report, if needed.

http://pastebin.com/nX11TX98

Thanks.

You’re trying to find object and use it immediately without checking if it exists (not NULL)

Added isspawned() before each executive loop and it still crashes.

Pretty much I’m trying to look for the object id of : 539717 and 535203 and change it’s phases.

It crashes because this gameobject is not found (NULL). As I said before you need to check this before doing anything with it. Read more carefully next time

Any chance to see a visual demonstration?

Thanks!

Compare this with your code and see what you missed. I think you can code the rest

void Reset()

{      
    std::list<GameObject*> list1;
    std::list<GameObject*> list2;
    if (GameObject* E = me->FindNearestGameObject(535203, 1000.0f))
    {
        E->GetGameObjectListWithEntryInGrid(list1, 535203, 1000.0f);
        list1.push_back(E);
    }
    if (GameObject* D = me->FindNearestGameObject(539717, 1000.0f))
    {
        D->GetGameObjectListWithEntryInGrid(list2, 539717, 1000.0f);
        list2.push_back(D);
    }

    for (std::list<GameObject*>::const_iterator it = list1.begin(); it != list1.end(); ++it)
        (*it)->SetPhaseMask(4, true);
    for (std::list<GameObject*>::const_iterator it = list2.begin(); it != list2.end(); ++it)
        (*it)->SetPhaseMask(4, true);

 }

BTW I would recommend you to do it like this:

void Reset()

{      
    std::list<GameObject*> list;
    me->GetGameObjectListWithEntryInGrid(list, 535203, 1000.0f);
    if (!list.empty())
        for (std::list<GameObject*>::const_iterator it = list.begin(); it != list.end(); ++it)
            (*it)->SetPhaseMask(4, true);


    me->GetGameObjectListWithEntryInGrid(list2, 539717, 1000.0f);
    if (!list.empty())
        for (std::list<GameObject*>::const_iterator it = list.begin(); it != list.end(); ++it)
            (*it)->SetPhaseMask(4, true);

 }