forward ShowPlayerItems(playerid); public ShowPlayerItems(playerid) { new info[512], result; foreach(new i : i_count) { if(Item[i][item_owner] == DataPlayer[playerid][player_uid]) { format(info, sizeof(info), "%s\n[%d]\t%s (%d | %d)", info, Item[i][item_uid], Item[i][item_name], Item[i][item_amount], Item[i][item_amount2]); result++; } } if(!strlen(info)) { ShowPlayerDialog(playerid, DIALOG_I, DIALOG_STYLE_MSGBOX, "Przedmioty | Informacja", "Przykro nam ale twoja postać nie posiada przedmiotуw", "Ok", ""); } ShowPlayerDialog(playerid, DIALOG_P, DIALOG_STYLE_LIST, "Przedmioty", info, "Usage", "Close"); return 1; }
new item_sscanf_uid, item_sscanf_info[128], itemid; if(sscanf(inputtext, "ds[128]", item_sscanf_uid, item_sscanf_info)) { printf("%d ITEMID USE\n", item_sscanf_uid); return 1; } itemid = item_sscanf_uid; printf("%d ITEMID USE\n", itemid); UsePlayerItem(playerid, Item[itemid][item_type], Item[itemid][item_uid]);
case DIALOG_P: { if(!response) return 1; new item_sscanf_uid, item_sscanf_info[128], itemid; if(sscanf(inputtext, "ds[128]", item_sscanf_uid, item_sscanf_info)) { printf("%d ITEMID USE\n", item_sscanf_uid); return 1; } itemid = item_sscanf_uid; printf("%d ITEMID USE\n", itemid); UsePlayerItem(playerid, Item[itemid][item_type], Item[itemid][item_uid]); //ShowPlayerDialog(playerid, DIALOG_P_O, DIALOG_STYLE_LIST, "Item | Options", "Use Item\nInfo\n", "Wybierz", "Anuluj"); return 1; }
case DIALOG_P:
{
if(!response)return 1;
new count;
for(new i;i<sizeof(Item);i++)
{
if(listitem == count)
{
//Item[i][item_type] is the "Item-Type" which is clicked in the dialog.
UsePlayerItem(playerid, Item[i][item_type], Item[i][item_uid]);
break;
}
count ++;
}
}
ShowPlayerItems(playerid)
{
new info[512];
foreach(new i : i_count)
{
if (Item[i][item_owner] == DataPlayer[playerid][player_uid])
{
format(info, sizeof(info), "%s\n[%d]\t%s (%d | %d)", info, Item[i][item_uid], Item[i][item_name], Item[i][item_amount], Item[i][item_amount2]);
}
}
// no need of strlen, if first character is NULL then it is empty.
if (!info[0]) ShowPlayerDialog(playerid, DIALOG_I, DIALOG_STYLE_MSGBOX, "Przedmioty | Informacja", "Przykro nam ale twoja postać nie posiada przedmiotуw", "Ok", "");
else ShowPlayerDialog(playerid, DIALOG_P, DIALOG_STYLE_LIST, "Przedmioty", info, "Usage", "Close");
return 1;
}
case DIALOG_P:
{
if (!response) return 1;
new itemid = -1;
foreach(new i : i_count)
{
if (Item[i][item_owner] == DataPlayer[playerid][player_uid])
{
if (++itemid == listitem)
{
printf("%d ITEMID USE\n", itemid);
UsePlayerItem(playerid, Item[itemid][item_type], Item[itemid][item_uid]);
//ShowPlayerDialog(playerid, DIALOG_P_O, DIALOG_STYLE_LIST, "Item | Options", "Use Item\nInfo\n", "Wybierz", "Anuluj");
break; // stops the loop
}
}
}
return 1;
}
First of all, why a public function ? Will it be called by CallLocal / RemoteFunction or even a timer at all ? If not, it is not needed.
You will need to loop once again and for each item you find the player is owner, you need to increase a variable.When it is then equal to the listitem, that is the index for the array. PHP код:
It's better to loop through iterator "i_count" because it will have less items. |