Amount of drugs to buy
#1

Hi guys please help me with something, I created a input style dialog
pawn Код:
ShowPlayerDialog(playerid, DRUG_SHOP_MENU, DIALOG_STYLE_INPUT,"Buy drugs","Enter the amount of grams you would like to buy:","Buy","Close");
and I would like to get the amount of how much the player typed in there and make it take player cash for every gram, so far, i got this for OnDialogRespone:
[PAWN]if(dialogid == DRUG_SHOP_MENU && response == 1)
{

} [/[PAWN] Please help me i will +rep
Reply
#2

like this
pawn Код:
if(dialogid == DRUG_SHOP_MENU && response == 1)
{
new amount = strval(inputtext); //now in "amount" the the amount user entered is stored use it

}
Reply
#3

And how can i use it?
Reply
#4

Is it good if i use it like this? Will the player's cash drop considering the amount he bought and will it show how much dollars he spent on the drugs??
pawn Код:
if(dialogid == DRUG_SHOP_MENU && response == 1)
    {
        new amount = strval(inputtext);
        new cash = GivePlayerCash(playerid, -1000 * amount);
        new drugmsg[100];
        format(drugmsg, sizeof(drugmsg), "You bought %d grams of drugs for %d !", amount, cash);
        SendClientMessage(playerid, WHITE, drugmsg);
    }
Reply
#5

pawn Код:
stock IsNumeric(const string[])
{
    new i;
    while(string[i] != '\0') //end of string
    {
        if (string[i] > '9' || string[i] < '0'){return 0;}
        i++;
    }
    return 1;
}
// OnDialogResponse
if(dialogid == DRUG_SHOP_MENU && response == 1)
{
    if(strlen(inputtext) <= 0) { ShowPlayerDialog(playerid, DRUG_SHOP_MENU, DIALOG_STYLE_INPUT,"Buy drugs","Enter the amount of grams you would like to buy:","Buy","Close"); }
    else if(!IsNumeric(inputtext)) { ShowPlayerDialog(playerid, DRUG_SHOP_MENU, DIALOG_STYLE_INPUT,"Buy drugs","Enter the amount of grams you would like to buy:","Buy","Close"); }
    else
    {
        new
            str[128],
            amount = strval(inputtext),
            cash = amount * 1000;
        if(GetPlayerCash(playerid) < cash) { ShowPlayerDialog(playerid, DRUG_SHOP_MENU, DIALOG_STYLE_INPUT,"Buy drugs","Enter the amount of grams you would like to buy:","Buy","Close"); }
        else
        {
            GivePlayerCash(playerid, - cash);
            format(str, sizeof(str), "You bought %d grams of drugs for %d $", amount, cash);
            SendClientMessage(playerid, -1, str);
        }
    }

}
Reply
#6

It works thank you so much ! +REPPED BOTH OF YOU!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)