Order a list
#1

Hello. I'm making an Inventory system. I have a command (/inv) that shows a list dialog with your items. You can attach items and save the item again to your inventory. What I want is order the list when a Object is attached.

Now I have a list like:

Код:
1 - Colt 45
2 - Didlo
3 - AK47
4 - Empty
....
10 - Empty
Equipped:
Right hand: Nothing
Left hand: Nothing
When I attach, for example, the item 2, the list shown is:

Код:
1 - Colt 45
2 - Empty
3 - AK47
....
10 - Empty
Equipped:
Right hand: Dildo
Left hand: Nothing
It's logic because in the for loop, the variable is equipped so, the 2 item is empty. But I don't want to show an empty space and then a Item, I want to show everything sorted. First the objects then empty spaces.

This is how I do the list
Код:
for(new i = 0; i < 10; i++)
	{
	    if(pItems[playerid][iID][i] > 0 && pItems[playerid][iUsed][i] == 0)
	    {
    		slot += 1;
  	 	  	format(string,sizeof(string), "%s[%i]\t%s\t[%i]\n", string, slot, NObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
   		}
   		else
   		{
   		    slot += 1;
   		    format(string,sizeof(string), "%s[%i]\tEmpty space\n", string, slot);
   		}
	}
Reply
#2

Do something like this:
PHP код:
new count;
for(new 
010++)
{
    if(
pItems[playerid][iID][i] > && pItems[playerid][iUsed][i] == 0)
    {
        
count ++;
        
format(stringsizeof(string), "%s[%i]\t%s\t[%i]\n"stringcountNObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
    }
}
for(new 
count10++)
{
    
format(stringsizeof(string), "%s[%i]\tEmpty space\n"stringi);

Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Do something like this:
PHP код:
new count;
for(new 
010++)
{
    if(
pItems[playerid][iID][i] > && pItems[playerid][iUsed][i] == 0)
    {
        
count ++;
        
format(stringsizeof(string), "%s[%i]\t%s\t[%i]\n"stringcountNObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
    }
}
for(new 
count10++)
{
    
format(stringsizeof(string), "%s[%i]\tEmpty space\n"stringi);

That's going to show the same number twice. Preferably:

PHP код:
new count;
for(new 
i10++)
{
    if(
pItems[playerid][iID][i] > && pItems[playerid][iUsed][i] == 0)
    {
        
count ++;
        
format(stringsizeof(string), "%s[%i]\t%s\t[%i]\n"stringcountNObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
    }
}
if(
count 10)
{
    for(new 
i10-counti++)
    {
        
count++;
        
format(stringsizeof(string), "%s[%i]\tEmpty space\n"stringcount);
    }

Reply
#4

Quote:
Originally Posted by Marricio
Посмотреть сообщение
That's going to show the same number twice. Preferably:

PHP код:
new count;
for(new 
i10++)
{
    if(
pItems[playerid][iID][i] > && pItems[playerid][iUsed][i] == 0)
    {
        
count ++;
        
format(stringsizeof(string), "%s[%i]\t%s\t[%i]\n"stringcountNObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
    }
}
if(
count 10)
{
    for(new 
i10-counti++)
    {
        
count++;
        
format(stringsizeof(string), "%s[%i]\tEmpty space\n"stringcount);
    }

Thanks, but there's a problem.

When the player has no items, show 10 slots. When the player has 1 item it shows 9 slots (1 occuped 8 empty), if 2, shows 8 slots, etc.

// EDIT

Worked, using:
Код:
.......
if(count < 10)
{
    new rest; 
    rest = 10-count;
    for(new i; i < rest; i++) 
    {
...
Thanks!!!
Reply
#5

Quote:
Originally Posted by HidroDF
Посмотреть сообщение
Thanks, but there's a problem.

When the player has no items, show 10 slots. When the player has 1 item it shows 9 slots (1 occuped 8 empty), if 2, shows 8 slots, etc.
That's weird. Not sure if it will make any difference, but try:

pawn Код:
new count;
for(new i; i < 10; i ++)
{
    if(pItems[playerid][iID][i] > 0 && pItems[playerid][iUsed][i] == 0)
    {
        count ++;
        format(string, sizeof(string), "%s[%i]\t%s\t[%i]\n", string, count, NObject(pItems[playerid][iType][i]), pItems[playerid][iAmmo][i]);
    }
}

if(count < 10)
{
    for(new i = count; i < 10; i++)
    {
        count++;
        format(string, sizeof(string), "%s[%i]\tEmpty space\n", string, count);
    }
}

EDIT: Figured out why, while we're increasing the count variable value we're also passing it as reference during the loop, that's why we're getting less repetitions.
Reply
#6

Thanks Marricio, I've solved the issue making a new variable for the rest.

Lot of thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)