Bank dialog
#1

Hello i have a problem with the following code:
pawn Код:
if(dialogid == DIALOG_WITHDRAW)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid, DIALOG_WITHDRAW, DIALOG_STYLE_INPUT, "Choose your value", "Please input a number in which you want to withdraw.\nPlease input a value!", "Ok", "Cancel");
        }
        new string[128];
        if(PlayerInfo[playerid][Pbank] < strlen(inputtext))
        {
            SendClientMessage(playerid, COLOR_RED, "Sorry, you dont have this much cash");
            return 1;
        }
        else if(strlen(inputtext) < 0 || strlen(inputtext) > 1000000)
        {
            SendClientMessage(playerid, COLOR_RED, "Only number values and it has to be more than 0 and less than 1 million");
            return 1;
        }
        else if(PlayerInfo[playerid][Pbank] >=strlen(inputtext))
        {
            GivePlayerMoney(playerid, strlen(inputtext));
            PlayerInfo[playerid][Pbank] -=strlen(inputtext);
            format(string, sizeof(string), "Thank you for using san fierro bank.\nYou have withdrawn $%i from your bank account.\nYour bank balence now stands at $%i", strlen(inputtext), PlayerInfo[playerid][Pbank]);
            ShowPlayerDialog(playerid, 1939, DIALOG_STYLE_MSGBOX, "Withdraw statment", string, "Ok", "Close");
            return 1;
        }
    }
i have some bugs soz if they are stupid mistakes i never really work with inputtext.

well for one i can enter a letter in the dialog without it displaying
Quote:

Only number values and it has to be more than 0 and less than 1 million

second if i have say 12 $ in the bank account and i withdraw 2$ it will say a random number say 49 was withdrawed but then will display the correct balence
Reply
#2

Well,it must be strval(inputtext),because you're INSERTING a number,strlen stands for string lenght,and it's used for getting the text inserted,like a password,or something.
Reply
#3

Thanks
Reply
#4

Oh sorry fr double posting but how do i solve the text problem like to make sure whatever they enter is a number
Reply
#5

pawn Код:
if(!strval(inputtext))
Replace the first if statement with that.

Код:
This forum requires that you wait 120 seconds between posts. Please try again in 39 seconds.
Reply
#6

It didnt solve anything :/ i can enter these things:

Код:
0 a b c d e f g h i j k l m n o p q r s t u v w x y z
Reply
#7

pawn Код:
if(dialogid == DIALOG_WITHDRAW)
    {
        if(!strval(inputtext))
        {
            ShowPlayerDialog(playerid, DIALOG_WITHDRAW, DIALOG_STYLE_INPUT, "Choose your value", "Please input a number in which you want to withdraw.\nPlease input a value!", "Ok", "Cancel");
        }
        else
        {
           new string[128];
           if(PlayerInfo[playerid][Pbank] < strval(inputtext))
           {
              SendClientMessage(playerid, COLOR_RED, "Sorry, you dont have this much cash");
              return 1;
           }
           if(strval(inputtext) < 0 || strval(inputtext) > 1000000)
           {
              SendClientMessage(playerid, COLOR_RED, "Only number values and it has to be more than 0 and less than 1 million");
              return 1;
           }
           if(PlayerInfo[playerid][Pbank] >=strval(inputtext))
          {
              GivePlayerMoney(playerid, strval(inputtext));
              PlayerInfo[playerid][Pbank] -=strval(inputtext);
              format(string, sizeof(string), "Thank you for using san fierro bank.\nYou have withdrawn $%i from your bank account.\nYour bank balence now stands at $%i", strval(inputtext), PlayerInfo[playerid][Pbank]);
              ShowPlayerDialog(playerid, 1939, DIALOG_STYLE_MSGBOX, "Withdraw statment", string, "Ok", "Close");
              return 1;
          }
          else
          {
              SendClientMessage(playerid,COLOR_RED,"You don't have that much money in bank!");
              return 1;
          }
     }
Replace the whole code with that.
Reply
#8

To clear the confusion,

Strval: it is used to convert string into integer.
Strlen: it is used to check the length of the string.

pawn Код:
if( !strlen( inputtext ) ) return print( "atleast write something" ); // if inputtext has nothing
Reply
#9

Ok then here is my dialog

pawn Код:
if(dialogid == DIALOG_WITHDRAW)
    {
        if(!strlen(inputtext))
        {
            ShowPlayerDialog(playerid, DIALOG_WITHDRAW, DIALOG_STYLE_INPUT, "Choose your value", "Please input a number in which you want to withdraw.\nPlease input a value!", "Ok", "Cancel");
        }
        new string[128];
        if(PlayerInfo[playerid][Pbank] < strval(inputtext))
        {
            SendClientMessage(playerid, COLOR_RED, "Sorry, you dont have this much cash");
            return 1;
        }
        else if(strval(inputtext) < 0 || strval(inputtext) > 1000000)
        {
            SendClientMessage(playerid, COLOR_RED, "Only number values and it has to be more than 0 and less than 1 million");
            return 1;
        }
        else if(PlayerInfo[playerid][Pbank] >=strval(inputtext))
        {
            new Query[200];
            GivePlayerMoney(playerid, strval(inputtext));
            PlayerInfo[playerid][Pbank] -=strval(inputtext);
            format(Query, sizeof(Query), "UPDATE users SET bank =%i WHERE username='%s'", PlayerInfo[playerid][Pbank], PlayerName(playerid));
            mysql_query(Query);
            format(string, sizeof(string), "Thank you for using san fierro bank.\nYou have withdrawn $%i from your bank account.\nYour bank balence now stands at $%i", strval(inputtext), PlayerInfo[playerid][Pbank]);
            ShowPlayerDialog(playerid, 1939, DIALOG_STYLE_MSGBOX, "Withdraw statment", string, "Ok", "Close");
            return 1;
        }
    }
Have i missed something u said? cause i can still enter letters
Reply
#10

Quote:
Originally Posted by thefatshizms
Посмотреть сообщение
Ok then here is my dialog

pawn Код:
if(dialogid == DIALOG_WITHDRAW)
    {
        if(!strlen(inputtext))
        {
            ShowPlayerDialog(playerid, DIALOG_WITHDRAW, DIALOG_STYLE_INPUT, "Choose your value", "Please input a number in which you want to withdraw.\nPlease input a value!", "Ok", "Cancel");
        }
        new string[128];
        if(PlayerInfo[playerid][Pbank] < strval(inputtext))
        {
            SendClientMessage(playerid, COLOR_RED, "Sorry, you dont have this much cash");
            return 1;
        }
        else if(strval(inputtext) < 0 || strval(inputtext) > 1000000)
        {
            SendClientMessage(playerid, COLOR_RED, "Only number values and it has to be more than 0 and less than 1 million");
            return 1;
        }
        else if(PlayerInfo[playerid][Pbank] >=strval(inputtext))
        {
            new Query[200];
            GivePlayerMoney(playerid, strval(inputtext));
            PlayerInfo[playerid][Pbank] -=strval(inputtext);
            format(Query, sizeof(Query), "UPDATE users SET bank =%i WHERE username='%s'", PlayerInfo[playerid][Pbank], PlayerName(playerid));
            mysql_query(Query);
            format(string, sizeof(string), "Thank you for using san fierro bank.\nYou have withdrawn $%i from your bank account.\nYour bank balence now stands at $%i", strval(inputtext), PlayerInfo[playerid][Pbank]);
            ShowPlayerDialog(playerid, 1939, DIALOG_STYLE_MSGBOX, "Withdraw statment", string, "Ok", "Close");
            return 1;
        }
    }
Have i missed something u said? cause i can still enter letters
Yup, replace "if(!strlen(inputtext))" with "if(!strval(inputtext))"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)