SA-MP Forums Archive
Amount of drugs to buy - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Amount of drugs to buy (/showthread.php?tid=524152)



Amount of drugs to buy - friezakinght - 05.07.2014

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


Re: Amount of drugs to buy - BroZeus - 05.07.2014

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

}



Re: Amount of drugs to buy - friezakinght - 05.07.2014

And how can i use it?


Re: Amount of drugs to buy - friezakinght - 05.07.2014

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);
    }



Re: Amount of drugs to buy - rickisme - 05.07.2014

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);
        }
    }

}



Re: Amount of drugs to buy - friezakinght - 05.07.2014

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