ShowPlayerDialog enum
#1

Ok so, i made a simple 24/7 shop where players can buy anything they want.

Currently shop dialog is this:

pawn Code:
ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "24/7 Shop", "Lighter - ("GREEN"$"#LIGHTER_COST") "WHITE"\nGps - ("GREEN"$"#GPS_COST") "WHITE"\nMarijuana Seeds - ("GREEN"$"#MARIJUANA_5_SEEDS_COST") "WHITE"\nCocaine Seeds - ("GREEN"$"#COCAINE_5_SEEDS_COST") "WHITE"\nHeroin Seeds - ("GREEN"$"#HEROIN_5_SEEDS_COST")\nPhone - ("GREEN"$"#PHONE_COST")\nTop Up Phone Credit\nFishing Rod - ("GREEN"$"#FISHING_ROD_COST") "WHITE"", "Buy", "Cancel");
As you can see, the dialog text is so damn long, my question now is...it's possible to store this items maybe in an enum and show them in the dialog? And how i should work with dialog response if i do in this way?

Thanks.
Reply
#2

u can try with a string maybe?

PHP Code:

new _string[128]; // check how much chars u need
format(stringsizeof(_string), "text");
ShowPlayerDialog(playeridDIALOG_SHOPDIALOG_STYLE_LIST"24/7 Shop"string"Buy""Cancel"); 
Reply
#3

...............
Reply
#4

I don't know if you two are trolling me, if no, please read again my first post.

My question was if it's possible to store in an enum this shop items and calling them with ShowPlayerDialog.
Reply
#5

He meant like this

pawn Code:
new gStr[900];
    strcat(gStr, "Lighter - ("GREEN"$"#LIGHTER_COST") "WHITE"\nGps - ("GREEN"$"#GPS_COST") "WHITE"\n");
    strcat(gStr, "Marijuana Seeds - ("GREEN"$"#MARIJUANA_5_SEEDS_COST") "WHITE"\n");
    strcat(gStr, "Cocaine Seeds - ("GREEN"$"#COCAINE_5_SEEDS_COST") "WHITE"\nHeroin Seeds - ("GREEN"$"#HEROIN_5_SEEDS_COST")\n");
    strcat(gStr, "Phone - ("GREEN"$"#PHONE_COST")\n");
    strcat(gStr, "Top Up Phone Credit\nFishing Rod - ("GREEN"$"#FISHING_ROD_COST") "WHITE"\n");
    ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "24/7 Shop", gStr, "Buy", "Cancel");
Reply
#6

Update ypur compiler to zeex's compiler.
Reply
#7

Do you mean:

pawn Code:
#include <a_samp>

enum ENUM_SHOP
{
    ITEM_NAME[28],
    ITEM_PRICE
};

static const ShopItems[][ENUM_SHOP] =    {
    {"Marijuana Seeds",                    {5000}},
    {"GPS",            {4000}},
    {"Condom",                   {3000}}
};

public OnFilterScriptInit()
{
    printf("Item name: %s - Item price : $%d", ShopItems[1], ShopItems[1][ITEM_PRICE]);
    return 1;
}
Reply
#8

Quote:
Originally Posted by TheToretto
View Post
Do you mean:

pawn Code:
#include <a_samp>

enum ENUM_SHOP
{
    ITEM_NAME[28],
    ITEM_PRICE
};

static const ShopItems[][ENUM_SHOP] =    {
    {"Marijuana Seeds",                    {5000}},
    {"GPS",            {4000}},
    {"Condom",                   {3000}}
};

public OnFilterScriptInit()
{
    printf("Item name: %s - Item price : $%d", ShopItems[1], ShopItems[1][ITEM_PRICE]);
    return 1;
}
Finally someone that understand! How do i work with OnDialogResponse?
Reply
#9

pawn Code:
#include <a_samp>
#include <zcmd>

#define DIALOG_SHOP 1337

enum ENUM_SHOP
{
    ITEM_NAME[28],
    ITEM_PRICE
};

static const ShopItems[][ENUM_SHOP] =    {
    {"Lighter",                    {500}},
    {"GPS",            {1250}},
    {"Condom",                   {25}}
};

public OnFilterScriptInit()
{
    printf("Item name: %s - Item price : $%d", ShopItems[1], ShopItems[1][ITEM_PRICE]);
    return 1;
}

CMD:buy(playerid, params[])
{
    // For this one, you have to format it, but it will a lot longer that defining them manually
    ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "24/7 Shop", "Lighter - ($500)\nGps - ($1250) \nCondom - ($25)", "Buy", "Cancel");
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == DIALOG_SHOP)
    {
        if(response)
        {
            new str[64];
            switch(listitem)
            {
               
                case 0..3:
                {
                    format(str, sizeof(str), "Item name: %s - Item price : $%d", ShopItems[listitem], ShopItems[listitem][ITEM_PRICE]);
                    SendClientMessage(playerid, -1, str);
                }
            }
        }
        return 1;
    }
    return 0;
}
Read the commented part
Reply
#10

Quote:
Originally Posted by TheToretto
View Post
//code
Any way to show items in enum in ShowPlayerDialog without writing one per one?
Reply
#11

What's wrong with having a long string? You are just getting the server to do more work to replicate something you already have.
Reply
#12

Quote:
Originally Posted by Y_Less
View Post
What's wrong with having a long string? You are just getting the server to do more work to replicate something you already have.
Then i don't see the reason of using an enum if i have to rewrite everything in ShowPlayerDialog!
Reply
#13

That's what you need:

pawn Code:
new string[64];
format(string, sizeof(string), "%s - ($%d)\n%s - ($%d)\n%s - ($%d)", ShopItems[0], ShopItems[0][ITEM_PRICE], ShopItems[1], ShopItems[1][ITEM_PRICE], ShopItems[2], ShopItems[2][ITEM_PRICE]);
ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, string, "Buy", "Cancel");
I told you it was going to be a long sentence.
Reply
#14

Yes, that was my point. I don't see the point in using an enum either.
Reply
#15

Using an enumerator for this kind of script is useful, for example to modify easily the names of articles, or their prices, or even replace/remove them without having to #define them every time, plus it's neater for anyone reading the script.
Reply
#16

@TheToretto it's possible to loop through that enum and add items with just one line at ShowPlayerDialog? I mean without writing ShopItems[0][ITEM_PRICE]/ShopItems[1][ITEM_PRICE] and so on for every item?
Reply
#17

Quote:
Originally Posted by KinderClans
View Post
@TheToretto it's possible to loop through that enum and add items with just one line at ShowPlayerDialog? I mean without writing ShopItems[0][ITEM_PRICE]/ShopItems[1][ITEM_PRICE] and so on for every item?
Sure:

pawn Code:
CMD:buy(playerid, params[])
{
    new string[64], dialog[64];
    for(new i; i < sizeof(ShopItems); i++)
    {
        format(string, sizeof(string), "%s - ($%d)\n", ShopItems[i], ShopItems[i][ITEM_PRICE]);
        strcat(dialog, string);
    }

    ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "24/7 SHOP", dialog, "Buy", "Cancel");
    return 1;
}
Reply
#18

Thank you very much, how i should edit the dialog response now that you added the loop?
Reply
#19

Quote:
Originally Posted by KinderClans
View Post
Thank you very much, how i should edit the dialog response now that you added the loop?
You needn't, just something I just figured out myself:

Replace in the switch statement, previously was:

pawn Code:
case 0..3:
by

pawn Code:
case 0..sizeof(ShopItems):
So you don't have to change every time the limit.
Reply
#20

Finally, thank you very much.

This topic can be closed.
Reply


Forum Jump:


Users browsing this thread: