[HELP]Making a NPC follow a Player!
#1

Hello.
I was thinking about, making some NPC's that follow players once they spot them.
But, i don't know how to and i would like someone to show me the codes required to make this happen.
So far, i think that i will need a GetPlayerPos and to put a public OnPlayerStreamIn(playerid) in the NPC Script.
Please don't post links to others filterscripts, that can do this or to other websites.
I only want codes here, so i can understand how it fully works and so later (once i learn it)i can make a [TuT] showing how to and give credits to the person(s) that helped me.
Thanks.
Reply
#2

Try a timer for getting the player's pos.
Then set the NPC's pos according to the distance.

Like this:

Код:
new timer; // At the top

timer = SetTimerEx("NPCFollow", 100, true, "d", playerid); // where you want to start the NPC to follow.

forward NPCFollow(playerid);
public NPCFollow(playerid)
{
   new Float:x, Float:y, Float:z, pName[50];
   if(!IsPlayerNPC(playerid))
   {
     GetPlayerPos(playerid, x, y, z);
   }
   for(new i=0; i<MAX_PLAYERS; i++)
   {
     if(IsPlayerConnected(i) && IsPlayerNPC(i))
     {
        if(GetDistanceBetweenPlayers(playerid, i)<15)
        {
          SetPlayerPos(i, x-2, y, z);
        }
     }
   }
   return 1;
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)