Dialog inventory
#1

Hello, I'm currently trying to create a dialog that shows the items that you have in your inventory after pressing a key, here's what I have

Код:
if (PRESSED(KEY_YES))
{
	new dialogstr[562];
	if(UserData[playerid][sItem1] > 0) return strcat(dialogstr, ""W"Item1:\t%d\n", UserData[playerid][sItem1]);
	if(UserData[playerid][sItem2] > 0) return strcat(dialogstr, ""W"Item2:\t%d\n", UserData[playerid][sItem2]);
	else SendClientMessage(playerid, -1, ""W"You don't have anything in your inventory");
	ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_TABLIST_HEADERS, ""COLORSV"Inventory", dialogstr, ""W"Select", ""W"Cancel");
}
However, nothing happens after pressing the key. If you don't have anything it does display the message, but if you have at least 1 item, the dialog doesn't show up.

I've also tried using format instead of strcat, but I get the same result. I don't want the dialog to show up items that you don't have, so is there another way to do this?

Thanks!
Reply
#2

Here's a script for an advanced Dialog Inventory system another server uses, hopefully this can help you out as it doesn't use strcat:

pawn Код:
stock ShowInventory(playerid)
{
    iItemList="";
    new invstring[128];
    for(new item;item<MAX_ITEMS;item++)
    {
        if(!strlen(_GetItemNamePVar(playerid,item))||!_GetItemAmountPVar(playerid,item))continue;
        format(iItemList,sizeof(iItemList),"%s\n%d\t\t%s",iItemList,_GetItemAmountPVar(playerid,item),_GetItemNamePVar(playerid,item));
    }
    format(iItemList,sizeof(iItemList),"Amount\t\tItem Name%s",iItemList);
    format(invstring,sizeof(invstring),"Backpack [%d/%d][Item Use]",PlayerInfo[playerid][pSlotu],PlayerInfo[playerid][pSlot]);
    ShowPlayerDialog(playerid,INV_DIALOG_ID,DIALOG_STYLE_LIST,invstring,iItemList,"Use","Close");
}
Okay this isn't going to be easy since you use "UserData[playerid][sItem1]" and you should use "UserData[playerid][sItem] [1]". I really think you should change that, when defining the array type it like this: sItem[AMOUNT OF ITEMS A PLAYER CAN STORE].

This way you can make the loop work and check if the player has any item on the given slot:
if(UserData[playerid][sItem][NUMBER]!=0)

And add the item to the list using the format:

format(iItemList,sizeof(iItemList),"Item%d:\t %d\n",NUMBER,UserData[playerid][sItem][NUMBER]);

And then simply display it after the loop finished messing around.

And instead of displaying the number of the item you can add a name to it using this script:

pawn Код:
stock GetItemName(modelid)
{
    new modelname[128];
    switch(modelid)
    {

    case ITEMID:format(modelname,sizeof(modelname),"Item Name");

   
    default: format(modelname, sizeof(modelname), "Unnamed Item");
    }
    return modelname;
}
And simply do this when listing the items:

format(iItemList,sizeof(iItemList),"Item%d:\t %d\n",NUMBER,GetItemName(UserData[playerid][sItem][NUMBER]));

Hope I helped you, if you have any questions I'll try to help you out!


Edit.: And don't use table_header dialog if you only want to display one thing per line, which is the name / id of the item that might also be the problem with your current script.
Reply
#3

Well, I've finally managed to do it. It was a lot easier than I expected:

Код:
	new itm1[32], itm2[32], total[64];

	if(UserData[playerid][sItem1] > 0)
	{
	format(itm11, sizeof(itm1), "Item1: %d", UserData[playerid][sItem1]);
	}

	if(UserData[playerid][sItem2] > 0)
	{
	format(itm2, sizeof(itm2), "Item2: %d", UserData[playerid][sItem2);
	}

	format(total, sizeof(total), "%s\n%s", itm1, itm2);
	SendClientMessage(playerid, -1, total);
	ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, ""COLORSV"Inventory", total, ""W"Select", ""W"Cancel");



The suggestion was a little hard to understand and I wanted to make it as simple as I could but thanks for replying!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)