1. getnearestnpcs() doesn't exist.
2. getareanpcs() doesn't exist clientside.
3. The following works... however... lags, would be the same for the player.
PHP Code:
function onNPC(tx,ty,w,h) {
for (i=0; i<npcs.size(); i++)
if (npcs[i].width>0 && npcs[i].height>0)
if (overlaps(tx,ty,w,h,npcs[i].x,npcs[i].y,npcs[i].width,npcs[i].height))
return 1;
return 0;
}
Now, if the array was a bit smaller, it wouldn't be so much of a lag problem. Thus, if 1 and/or 2 were available clientside, I wouldn't be having this problem. It's not such a problem on inside levels, but it's a HUGE problem on gmaps.
Oh, by the way, it's a bit less simple to check for the overlapping of an NPC onto the area being checked.
PHP Code:
function overlaps(x1,y1,w1,h1,x2,y2,w2,h2) {
if (x1 in |x2,x2+w2> && y1 in |y2,y2+h2>) return 1;
if (x1+w1 in <x2,x2+w2> && y1 in |y2,y2+h2>) return 1;
if (x1+w1 in <x2,x2+w2> && y1+h1 in <y2,y2+h2>) return 1;
if (x1 in |x2,x2+w2> && y1+h1 in <y2,y2+h2>) return 1;
if (x2 in |x1,x1+w1> && y2 in |y1,y1+h1>) return 1;
if (x2+w2 in <x1,x1+w1> && y2 in |y1,y1+h1>) return 1;
if (x2+w2 in <x1,x1+w1> && y2+h2 in <y1,y1+h1>) return 1;
if (x2 in |x1,x1+w1> && y2+h2 in <y1,y1+h1>) return 1;
return 0;
}
Unfortunately, the in operator has only so much functionality. I wish I could get rid of the last four lines at the least, but there's always the possibility of the first rectangle completely enclosing the second rectangle.