View Single Post
Old 21/09/2018, 05:13 PM   #10
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,688
Reputation: 568
Default Re: NPC chase the nearest player

Quote:
Originally Posted by matje View Post
Holy fuck you are my hero
Thank you so much, it works!

I've used

Code:
foreach(Player, i)
{
    //stuff
}
Instead of

Code:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        //stuff
    }
}
because (I think) foreach loops only through players, not NPCS.

Also thank you for the great tips.
By default there are Iterators for Players and NPCs. Check the foreach include, there should be definitions for both (also defines).
But even if there aren't you can always declare your own Iterator and add your Zombie NPCs to it Especially if not all NPCs on the server are Zombies.

Last edited by NaS; 21/09/2018 at 07:05 PM.
NaS is offline   Reply With Quote