SA-MP Forums Archive
This is possible? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: This is possible? (/showthread.php?tid=244977)



This is possible? - Baboon - 29.03.2011

Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
	if(IsPlayerConnected(i))
	{
		for(new a = 0; a < MAX_PLAYERS; a != i; a++)
		{
			if(IsPlayerConnecteD(a))
			{
			}
		}
	}
{



Re: This is possible? - Hornet600 - 29.03.2011

why loop two times MAX_PLAYERS?? seems weird ...if you explain more what you want to do...


AW: This is possible? - Nero_3D - 29.03.2011

actually I cant see the reason for nested player loops but its possible
Just get foreach, it uses an advanced structure to create a faster loops


Re: This is possible? - Baboon - 01.04.2011

okay, because I want to use variables in it for my scoreboard in the end of the session, like who has the most kills etc. But is there a way to ingnore if a and i are the same?


AW: Re: This is possible? - Nero_3D - 01.04.2011

Quote:
Originally Posted by timothyinthehouse
Посмотреть сообщение
okay, because I want to use variables in it for my scoreboard in the end of the session, like who has the most kills etc. But is there a way to ingnore if a and i are the same?
pawn Код:
(a < MAX_PLAYERS) && (a != i)
But there are better sorting methodes than two player loops

That would be Insertionsort, just ****** Sorting algorithm for more advanced once
Some advanced sorthing algorithm like quicksort can be found in this forum

pawn Код:
new
    i,
    j,
    id,
    value,
    id[sizeof Kills] = {0, 1, 2, ...};
for( ; i != sizeof Kills; ++i) {
    value = Kills[i];
    for(j = i; (j != 0) && (Kills[id[j - 1]] < value); --j) {
        id[j] = id[j - 1]
    }
    id[j] = i;
}
//id[0] is the id with the most kills (Kills[id[0]] would be the kills)