View Full Version : Check if any player is near NPC in NPC Mode?

10/03/2010, 06:53 PM

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. :D
IsPlayerNPC is just working in a filter script or the game mode...

Is it possible?

11/03/2010, 09:24 PM
I want to know too =]

28/09/2011, 12:54 PM
public onplayerupdate(playerid)
for(new i = 0; i < MAX_PLAYERS; 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

28/09/2011, 02:38 PM
You should be using foreach and not OnPlayerUpdate.

Include YSI\y_timers and foreach and make a new timer

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.

OnPlayerNearNPC(playerid, npcid)
// Code inside here

Enjoy. This is faster than the one above me.