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");
new _string[128]; // check how much chars u need
format(string, sizeof(_string), "text");
ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_LIST, "24/7 Shop", string, "Buy", "Cancel");
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");
#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;
}
Do you mean:
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;
}
What's wrong with having a long string? You are just getting the server to do more work to replicate something you already have.
|
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");
@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?
|
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;
}
Thank you very much, how i should edit the dialog response now that you added the loop?
|
case 0..3:
case 0..sizeof(ShopItems):