Sorting of 3d arrays... -
Kyle - 20.12.2012
Would someone assist with this please:
If you read the whole pastebin document my question is in the pastebin document:
http://pastebin.com/t5TfbRXB
Re: Sorting of 3d arrays... -
LarzI - 20.12.2012
Uhm. Do you manually assign them? Cuz in that case, you can just assign them in the order you want? I don't really get the problem here.
Re: Sorting of 3d arrays... -
Kyle - 20.12.2012
No I do not manually assign them, the server just looks for an slot ID with the available value as 1. It then fits into the first one...
My example was manually done on what the server COULD produce.
Re: Sorting of 3d arrays... -
Basssiiie - 20.12.2012
Your example isn't very clear. What do you want to do exactly? Do you want to show a list of all the drugs the player has, sorted by drug type? Or do you want to rearrange the drug types, so they are sorted inside the array?
Re: Sorting of 3d arrays... -
Kyle - 20.12.2012
Quote:
Originally Posted by Basssiiie
Your example isn't very clear. What do you want to do exactly? Do you want to show a list of all the drugs the player has, sorted by drug type? Or do you want to rearrange the drug types, so they are sorted inside the array?
|
I want to re-arranged them so that they are ordered by Drug Type.
Re: Sorting of 3d arrays... -
LarzI - 20.12.2012
If you could re-upload your script (pastebin expired) I'll try to make something.
Re: Sorting of 3d arrays... -
Basssiiie - 20.12.2012
What about
this? One of
these in specific?
These are all methods to sort a list. The bubble sort is probably the easiest one, but also one of the slowest. But there enough other possible algorithms.
Re: Sorting of 3d arrays... -
Kyle - 20.12.2012
Quote:
Originally Posted by Basssiiie
What about this? One of these in specific?
These are all methods to sort a list based on the number it's containing. The bubble sort is probably the easiest one, but also one of the slowest. But there enough other possible algorithms. 
|
I've no clue where to start, hence asking here.
Quote:
Originally Posted by LarzI
If you could re-upload your script (pastebin expired) I'll try to make something.
|
http://pastebin.com/wdQXXxYs
Re: Sorting of 3d arrays... -
Basssiiie - 20.12.2012
Quote:
Originally Posted by KyleSmith
I've no clue where to start, hence asking here.
|
You could look through the list there and see what might be doable, that one can you try then. Some of them are quite easy to replicate, but at they are generally slightly slower than the difficult ones.
Re: Sorting of 3d arrays... -
LarzI - 20.12.2012
I found something used in c++ to sort using the Bubble Sort method, try this:
pawn Код:
SortPlayerArray(playerid)
{
new
bool:flag = true,
temp;
for( new i = 0; ( i < MAX_DRUGS ) && flag; i ++ )
{
flag = false;
for( new j = 0; j < ( MAX_DRUGS - 1 ); j ++ )
{
if( DrugArray[ playerid ][ j + 1 ][ DrugType ] > DrugArray[ playerid ][ j ][ DrugType ] )
{
temp = DrugArray[ playerid ][ j ][ DrugType ];
DrugArray[ playerid ][ j ][ DrugType ] = DrugArray[ playerid ][ j + 1 ][ DrugType ]
DrugArray[ playerid ][ j + 1 ][ DrugType ] = temp;
flag = true;
}
}
}
}
Then simply do SortPlayerArray(playerid); to sort it.