Check if any player is near NPC in NPC Mode?
#1

Hi,

How can I check if a player is near a NPC?
I want to stop moving a NPC if the player gets closer to a NPC.
But if a NPC is to close to another NPC, they both stops forever.
IsPlayerNPC is just working in a filter script or the game mode...


Is it possible?
Reply
#2

I want to know too =]
Reply
#3

pawn Код:
public onplayerupdate(playerid)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerNPC(i)
            {
                new Float:X, Float:Y, Float:Z;
                GetPlayerPos(i, X, Y, Z);
                if(IsPlayerInRangeOfPoint(playerid, 5.0, X, Y, Z))
                {
                    //Your function here when a player is near a npc
                }
            }
        }
    }
    return 1;
}

sorry for report this topic
Reply
#4

You should be using foreach and not OnPlayerUpdate.

Include YSI\y_timers and foreach and make a new timer

pawn Код:
Timer:UpdatePlayer[250]() {
    foreach(Player, playerid) {
        if(!IsPlayerNPC(playerid)) {
            foreach(Player, npcid) {
                if(IsPlayerNPC(npcid)) {
                    new Float:rPos[3];
                    GetPlayerPos(npcid, rPos[0], rPos[1], rPos[2]);
                    if(IsPlayerInRangeOfPoint(playerid, 8.0, rPos[0], rPos[1], rPos[2])) {
                        OnPlayerNearNPC(playerid, npcid);
                    }
                }
             }
         }
    }
}
After you do that, create a new function called OnPlayerNearNPC.

pawn Код:
OnPlayerNearNPC(playerid, npcid)
{
    // Code inside here
}
Enjoy. This is faster than the one above me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)