Local chat alternative (IsPlayerInRangeOfPoint()) - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Local chat alternative (IsPlayerInRangeOfPoint()) (
/showthread.php?tid=204750)
Local chat alternative (IsPlayerInRangeOfPoint()) -
Onyewu - 30.12.2010
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();
}
Re: Local chat alternative (IsPlayerInRangeOfPoint()) -
MadeMan - 30.12.2010
There could be some IDs between 0 and highest ID that are not connected.
For example there could be players with IDs 0, 1, 5, 6, 10.
And the performance you get from there isn't very big.
You can always redefine MAX_PLAYERS also.
Re: Local chat alternative (IsPlayerInRangeOfPoint()) -
gr56 - 30.12.2010
Just change MAX_PLAYERS to number of your slots or use foreach