Issue with loop causing lag.
#1

Well I'm using this code to send message to admins only it working perfect but but.
the problem come it causing lag because I'm calling this function in many locations like when some body
cheating it send message to admin even some body join it send message to admin.
Now it start making lag.

Код:
SendToAdmins(color,Message[])
{
	foreach(new i : Player)
	{
	if(pInfo[i][pLevel] >= 1)
	SCM(i, color, Message);
	}
	return 1;
}
Is there anyway rather than using loop i can send message to only admins?

Cheers.
Thanks
Reply
#2

Quote:
Originally Posted by MBilal
Посмотреть сообщение
Well I'm using this code to send message to admins only it working perfect but but.
the problem come it causing lag because I'm calling this function in many locations like when some body
cheating it send message to admin even some body join it send message to admin.
Now it start making lag.

Код:
SendToAdmins(color,Message[])
{
	foreach(new i : Player)
	{
	if(pInfo[i][pLevel] >= 1)
	SCM(i, color, Message);
	}
	return 1;
}
Is there anyway rather than using loop i can send message to only admins?

Cheers.
Thanks
if(pInfo[i][pLevel] >= 1) you don't need this line. You need something like pAdmin or pAdminLevel >= 1.
Reply
#3

Why are you people using this SCM abbreviation? are you too lazy to type SendClientMessage? not only that, there is a tremendous amount of text editors that support syntax completion. not happy with your autocompletion.

I have a similar function in my gm, but I use it rather differently, I have an iterator that's specifically made to loop through admins only, I don't have any signs of lag coming from the function though.
Reply
#4

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
if(pInfo[i][pLevel] >= 1) you don't need this line. You need something like pAdmin or pAdminLevel >= 1.
changing varaible name doesn't make sense dude lol.

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
Why are you people using this SCM abbreviation? are you too lazy to type SendClientMessage? not only that, there is a tremendous amount of text editors that support syntax completion. not happy with your autocompletion.

I have a similar function in my gm, but I use it rather differently, I have an iterator that's specifically made to loop through admins only, I don't have any signs of lag coming from the function though.
Yeah a sory bit lazy lol.as i mentioned above dude like i'm using aka system when some body join it send message to admins like if 4 to 5 guy connect together that mean 4 to 5 loops start together at same time that can cause lag.

You understand bud?
Reply
#5

Quote:
Originally Posted by MBilal
Посмотреть сообщение
changing varaible name doesn't make sense dude lol.
if you're not sure kindly please don't spam post without thinking.
He didn't mean it that way, he simply suggested that you would make an array with only admin ids in it so that you can iterate over it without worry about checking their admin levels.
Reply
#6

Quote:
Originally Posted by Eoussama
Посмотреть сообщение
He didn't mean it that way, he simply suggested that you would make an array with only admin ids in it so that you can iterate over it without worry about checking their admin levels.
maybe I'm wrong at that moment.
kindly can give me Example bud?
Reply
#7

Код:
SendToAdmins(color, Message[])
{
	foreach(new i : Player)
	{
	      if(!IsPlayerAdmin(i)) continue;
	      SCM(i, color, Message);
	}
	return 1;
}
Replace the red text with the variable you want to name as the admin
Reply
#8

Get profiler and u'll see.
Reply
#9

Try this,
Works perfect for me.
Код:
for(new a=0;a<MAX_PLAYERS;a++)
		if(AdminLevel[a]>=2) // YOUR ADMIN VAR here
		{
			SendClientMessage(a,-1,string);
		}
OR

Код:
		SendMessageToAdmins(-1,str);
stock SendMessageToAdmins(color,const string[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnectedEx(i))
        if(AdminLevel[i] >=2)
        SendClientMessage(i,color,string);
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by 0x88
Посмотреть сообщение
Код:
SendToAdmins(color, Message[])
{
	foreach(new i : Player)
	{
	      if(!IsPlayerAdmin(i)) continue;
	      SCM(i, color, Message);
	}
	return 1;
}
Replace the red text with the variable you want to name as the admin
I'll try this dude let see hope it help.

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Try this,
Works perfect for me.
Код:
for(new a=0;a<MAX_PLAYERS;a++)
		if(AdminLevel[a]>=2) // YOUR ADMIN VAR here
		{
			SendClientMessage(a,-1,string);
		}
OR

Код:
		SendMessageToAdmins(-1,str);
stock SendMessageToAdmins(color,const string[])
{
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnectedEx(i))
        if(AdminLevel[i] >=2)
        SendClientMessage(i,color,string);
    }
    return 1;
}
Alright i think foreach is faster than for(new i = 0; i< MAX_PLAYERS , i++) well maybe i'm wrong.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)