SA-MP Forums Archive
Can i do it like that? - 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: Can i do it like that? (/showthread.php?tid=498044)



Can i do it like that? - audriuxxx - 01.03.2014

Код:
foreach(new allplayerqq : Player)
{
if(cache_num_rows())
				{
					for(new r=0; r < cache_get_row_count(); ++r)
					{
					    cache_get_row(r, 0, internetplayername);

						format( createstring,25,"%s", internetplayername );
						SendClientMessage( allplayerqq,COLOR_YELLOW,createstring );
					}
				}
			
}
What i have mean, can i do foreach and then do a for(new and get a information from mysql for everone player?


Respuesta: Can i do it like that? - CuervO - 01.03.2014

Yes. You can put loops inside loops inside loops inside loops (x infinity).

I recommend putting the cache_num_rows check outside the first loop, otherwise it would check to all players and stop if it's missing all the times.


Re: Can i do it like that? - audriuxxx - 01.03.2014

But i mean, when i will do it for first player

for(new r=0; r < cache_get_row_count(); ++r)
{
And then when will be other player, i too can get

for(new r=0; r < cache_get_row_count(); ++r)
{

?


Respuesta: Re: Can i do it like that? - CuervO - 01.03.2014

Quote:
Originally Posted by audriuxxx
Посмотреть сообщение
But i mean, when i will do it for first player

for(new r=0; r < cache_get_row_count(); ++r)
{
And then when will be other player, i too can get

for(new r=0; r < cache_get_row_count(); ++r)
{

?
Loops are run X amount times as you specified. Foreach will run one time per player, and within that one time per player run, the second loop will run X amount of times as you specified it (in this case, cache_get_row_count() amount of times).
Код:
Run(10 times)
{
     run(20 times)
     {
         //code
     }
}
That's just an example, that code would be run 200 amount of times, whatever is first will be run 10 times and inside those 10 times a new code will be run 20 times each run the first one haves.