How can I check if a creature has already been summoned

I have been trying a few things with no success…

For example in MapScripts (as an example only) if I wanted to check if there is already a creature (same entry) in a particular range I tried the following but it is always returning null even though I have other creatures with that entry in that range.

Can anyone point me to the right direction?


case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE:
            {
                // Source must be WorldObject.
                if (WorldObject* pSummoner = _GetScriptWorldObject(source, true, step.script))
                {
                    if (!step.script->TempSummonCreature.CreatureEntry)
                        TC_LOG_ERROR("scripts", "%s creature entry (datalong) is not specified.", step.script->GetDebugInfo().c_str());
                    else
                    {
                        float x = step.script->TempSummonCreature.PosX;
                        float y = step.script->TempSummonCreature.PosY;
                        float z = step.script->TempSummonCreature.PosZ;
                        float o = step.script->TempSummonCreature.Orientation;

                        Creature* creature = pSummoner->FindNearestCreature(step.script->TempSummonCreature.CreatureEntry, 50.0f);

                        if (!creature)
                        {

                            if (!pSummoner->SummonCreature(step.script->TempSummonCreature.CreatureEntry, x, y, z, o, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, step.script->TempSummonCreature.DespawnDelay))
                                TC_LOG_ERROR("scripts", "%s creature was not spawned (entry: %u).", step.script->GetDebugInfo().c_str(), step.script->TempSummonCreature.CreatureEntry);
                        }
                    }
                }
                break;
            }

— Canned message start —
This thread is not related to the official Trinity codebase and was moved to the Custom Code section.
Please read the stickies next time.
— Canned message end —