Local chat alternative (IsPlayerInRangeOfPoint())
#1

I'm currently working on a SAMP Roleplay script. I'm trying to build it from scratch, just to get familiar with the Pawn-language and stuff. When creating a local chat function, I did some searches to see how it's usually done. I found this:

Quote:
Originally Posted by SilentHuntR
Посмотреть сообщение
pawn Код:
stock SendLocalChat(playerid,color,msg[],Float:radius)
{
  new Float:x,Float:y,Float:z;
  GetPlayerPos(playerid,x,y,z);
  for(new ply;ply<MAX_PLAYERS;ply++)
  {
    if(IsPlayerInRangeOfPoint(ply,radius,x,y,z))SendClientMessage(ply,color,msg);
  }
  return 1;
}
But... wouldn't it be much better to keep track of the highest player id in the server, and implement this in the IsPlayerInRangeOfPoint function? This would be a huge performance boost. Best case scenario is one step instead of 500. This is how I did it:

pawn Код:
new Hid = -1; // Hid stores the largest known playerid, value -1 when 0 players

public OnPlayerConnect(playerid) {
    if (playerid > Hid) Hid = playerid; // Updating highest playerid
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    // When player with playerid hid leaves, update hid value //
    if (playerid == Hid) {
        while (Hid > -1) {
            Hid--;
            if(!(Hid == INVALID_PLAYER_ID)) break;
        }
    }
    return 1;
}
Then...

pawn Код:
for (new ply; ply<(Hid+1); ply++) {
        if (IsPlayerInRangeOfPoint(bla)) function();
}
Reply


Messages In This Thread
Local chat alternative (IsPlayerInRangeOfPoint()) - by Onyewu - 30.12.2010, 12:58
Re: Local chat alternative (IsPlayerInRangeOfPoint()) - by MadeMan - 30.12.2010, 13:04
Re: Local chat alternative (IsPlayerInRangeOfPoint()) - by gr56 - 30.12.2010, 13:05

Forum Jump:


Users browsing this thread: 2 Guest(s)