Is this efficient or not? - 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)
+--- Thread: Is this efficient or not? (
/showthread.php?tid=450041)
Is this efficient or not? -
Sellize - 11.07.2013
My first piece of code i did without looking anything up, is this efficient?
Код:
forward SendLocalMessage(playerid, color, message[]);
public SendLocalMessage(playerid, color, message[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if(IsPlayerInRangeOfPoint(i, 10.0, x, y, z))
{
SendClientMessage(i, color, message);
}
}
return 1;
}
Re: Is this efficient or not? -
ikey07 - 11.07.2013
under
for(new i = 0; i < MAX_PLAYERS; i++)
{
add
if(IsPlayerConnected(i))
{
Re: Is this efficient or not? -
DobbysGamertag - 11.07.2013
Seems good to me. Although you could probably use foreach for the loop, or define max players for less of a impact.
Re: Is this efficient or not? -
Macluawn - 11.07.2013
define the variables outside the loop and it shouldnt really be a public function (unless you want to access it in filterscripts)