Issue with loop causing lag. -
MBilal - 18.12.2017
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
Re: Issue with loop causing lag. -
buburuzu19 - 18.12.2017
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.
Re: Issue with loop causing lag. -
Eoussama - 18.12.2017
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.
Re: Issue with loop causing lag. -
MBilal - 18.12.2017
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?
Re: Issue with loop causing lag. -
Eoussama - 18.12.2017
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.
Re: Issue with loop causing lag. -
MBilal - 18.12.2017
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?
Re: Issue with loop causing lag. -
0x88 - 19.12.2017
Код:
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
Re: Issue with loop causing lag. -
DeitY - 19.12.2017
Get profiler and u'll see.
Re: Issue with loop causing lag. -
jasperschellekens - 19.12.2017
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;
}
Re: Issue with loop causing lag. -
MBilal - 19.12.2017
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.