Is this efficient or not?
#1

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;
}
Reply
#2

under

for(new i = 0; i < MAX_PLAYERS; i++)
{

add
if(IsPlayerConnected(i))
{
Reply
#3

Seems good to me. Although you could probably use foreach for the loop, or define max players for less of a impact.
Reply
#4

define the variables outside the loop and it shouldnt really be a public function (unless you want to access it in filterscripts)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)