30.12.2010, 12:58
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:
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:
Then...
Quote:
pawn Код:
|
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;
}
pawn Код:
for (new ply; ply<(Hid+1); ply++) {
if (IsPlayerInRangeOfPoint(bla)) function();
}