money transfer to offline player
#1

PHP код:
if(dialogid == 709)
    {
        if(
response)
        {
            new 
id[24], cash;
            if(
sscanf(inputtext,"s[24]d"idcash ))
            {
                
SendError(playerid"laukelis nebuvo pilnai uћpildytas !"); // the field is empty 
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
                return 
1;
            }
            if(!
strcmp(getPlayerName(playerid), inputtextfalse)) 
            {
                
SendError(playerid"pinigų pervesti sau negalite !"); // you can't transfer money to ur self
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
                return 
1;
            } 
            if(
cash != IsNumeric(inputtext))
            {
                
SendError(playerid"pinigų suma turi būti įvęsta skaičiais !"); // I get error right here ! every time it shows that money should be written by numbers, but every time it's numbers. EX: Iam_Satans 500
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
                return 
1;
            }
            if(
cash bank[playerid][pBankMoney]) // if player inputted more money then in his bank 
            
{
                
SendError(playerid"tiek pinigų banko sąsk. neturite !");
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
                return 
1;
            }
            
format(g_szBuffersizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
            
mysql_query(g_szBuffer);
            
mysql_store_result();
            if(
mysql_num_rows() == 1)
            {
                
format(g_szBuffersizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
                
mysql_query(g_szBuffer);
                
mysql_store_result();
                if(
mysql_num_rows() == 1)
                {
                    
SendSucces(playerid"zaidejas turi sask"); // player has a bank acc
                    
return 1;
                }
                else
                {
                    
SendError(playerid"zaidejas neturi sask"); // player doesnt have bank acc
                    
return 1;
                }
            }
            else
            {
                
SendError(playerid"ZAIDEJAS NEEGZISTUOJA"); // in db there's isn'nt name inputtext
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
            }
        }
    } 
I wrote the problems in the code by // coments.
Reply
#2

of course
pawn Код:
if(cash != IsNumeric(inputtext))
this will always equal to "true".
"inputtext" is an array of chars, not just a single number.

also, you don'teven have to check if the input was a number,
you can use sscanf's return value for that.
pawn Код:
if(!sscanf(inputtext,"s[24]d", id, cash ))
sscanf returns 0 if inputtext doesen't look like:
"someName 1234"
we have to invert that using "!" so that the control statement equals true
and your error message can be displayed here
Reply
#3

So i have to change:
PHP код:
if(cash != IsNumeric(inputtext)) 
To:
PHP код:
if(!sscanf(inputtext,"s[24]d"idcash )) 
Or what? Because this system really pissed me off.. Yesterday I written almost all bank system and BAM i'm stuck here..
Reply
#4

Quote:
Originally Posted by bogushas
Посмотреть сообщение
So i have to change:
PHP код:
if(cash != IsNumeric(inputtext)) 
To:
PHP код:
if(!sscanf(inputtext,"s[24]d"idcash )) 
Or what? Because this system really pissed me off.. Yesterday I written almost all bank system and BAM i'm stuck here..
no, not really

try
pawn Код:
if(dialogid == 709)
    {
        if(response)
        {
            new id[24], cash;
            if(!sscanf(inputtext,"s[24]d", id, cash ))//equals true if inputtext doesent look like "someName 123"
            {
                SendError(playerid, "laukelis nebuvo pilnai uћpildytas !"); // the field is empty
                ShowPlayerDialog(playerid, 709, DIALOG_STYLE_INPUT, "Pinigų pervedimas OFFLINE ћaidėjui", "{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.", "Pervesti", "Atgal");
                return 1;
            }
            if(!strcmp(getPlayerName(playerid), inputtext, false))
            {
                SendError(playerid, "pinigų pervesti sau negalite !"); // you can't transfer money to ur self
                ShowPlayerDialog(playerid, 709, DIALOG_STYLE_INPUT, "Pinigų pervedimas OFFLINE ћaidėjui", "{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.", "Pervesti", "Atgal");
                return 1;
            }
            /*if(cash != IsNumeric(inputtext))//don't need that, we're checking the input at the top using sscanf'sreturn value
            {
                SendError(playerid, "pinigų suma turi būti įvęsta skaičiais !"); // I get error right here ! every time it shows that money should be written by numbers, but every time it's numbers. EX: Iam_Satans 500
                ShowPlayerDialog(playerid, 709, DIALOG_STYLE_INPUT, "Pinigų pervedimas OFFLINE ћaidėjui", "{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.", "Pervesti", "Atgal");
                return 1;
            }*/

            if(cash > bank[playerid][pBankMoney]) // if player inputted more money then in his bank
            {
                SendError(playerid, "tiek pinigų banko sąsk. neturite !");
                ShowPlayerDialog(playerid, 709, DIALOG_STYLE_INPUT, "Pinigų pervedimas OFFLINE ћaidėjui", "{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.", "Pervesti", "Atgal");
                return 1;
            }

            format(g_szBuffer, sizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'", id);
            mysql_query(g_szBuffer);
            mysql_store_result();
            if(mysql_num_rows() == 1)
            {
                format(g_szBuffer, sizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'", id);
                mysql_query(g_szBuffer);
                mysql_store_result();
                if(mysql_num_rows() == 1)
                {
                    SendSucces(playerid, "zaidejas turi sask"); // player has a bank acc
                    return 1;
                }
                else
                {
                    SendError(playerid, "zaidejas neturi sask"); // player doesnt have bank acc
                    return 1;
                }
            }
            else
            {
                SendError(playerid, "ZAIDEJAS NEEGZISTUOJA"); // in db there's isn'nt name inputtext
                ShowPlayerDialog(playerid, 709, DIALOG_STYLE_INPUT, "Pinigų pervedimas OFFLINE ћaidėjui", "{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.", "Pervesti", "Atgal");
            }
        }
    }
also, instead of sayin the field is empty, you could now say something like "invalid input"
Reply
#5

Yeah I just thinked the same with that. Sscanf already checks all that fields, and IsNumeric(inputtext) check the whole input including name..
Reply
#6

PHP код:
format(g_szBuffersizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
            
mysql_query(g_szBuffer);
            
mysql_store_result();
            if(
mysql_num_rows() == 1)
            {
                
format(g_szBuffersizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
                
mysql_query(g_szBuffer);
                
mysql_store_result();
                if(
mysql_num_rows() == 1)
                {
                    
SendSucces(playerid"zaidejas turi sask"); // player has a bank acc
                    
return 1;
                }
                else
                {
                    
SendError(playerid"zaidejas neturi sask"); // player doesnt have bank acc
                    
return 1;
                }
            } 
In DB there is one name Iam_Satan and other one is Iam_Satans, in game i'am Iam_Satan, and i wrote in input Iam_Satans 500 and i get
PHP код:
SendSucces(playerid"zaidejas turi sask"); // player has a bank acc 
but in dB pBank == 0.
Reply
#7

Quote:
Originally Posted by bogushas
Посмотреть сообщение
PHP код:
format(g_szBuffersizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
            
mysql_query(g_szBuffer);
            
mysql_store_result();
            if(
mysql_num_rows() == 1)
            {
                
format(g_szBuffersizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'"id);
                
mysql_query(g_szBuffer);
                
mysql_store_result();
                if(
mysql_num_rows() == 1)
                {
                    
SendSucces(playerid"zaidejas turi sask"); // player has a bank acc
                    
return 1;
                }
                else
                {
                    
SendError(playerid"zaidejas neturi sask"); // player doesnt have bank acc
                    
return 1;
                }
            } 
In DB there is one name Iam_Satan and other one is Iam_Satans, in game i'am Iam_Satan, and i wrote in input Iam_Satans 500 and i get
PHP код:
SendSucces(playerid"zaidejas turi sask"); // player has a bank acc 
but in dB pBank == 0.
it's 0 because you don't increase it.
you just send a message saying that he has a bank account
so of course there arent any changes.

so instead of sending that message, update that pBank field in your db.
get the current value of pBank and increase it by "cash"
and then update it.
use "mysql_fetch_int()" to get the value of pBank if you're unsure as to how to do that

also very important, you forgot to free the result again after storing it
pawn Код:
mysql_free_result();
at the end
Reply
#8

No, no. You didin't get it. That player, for EX. Iam_Satans doesn't have bank acc, so he can't get the transfers from the bank. It has to be set to 0
Reply
#9

Quote:
Originally Posted by bogushas
Посмотреть сообщение
No, no. You didin't get it. That player, for EX. Iam_Satans doesn't have bank acc, so he can't get the transfers from the bank. It has to be set to 0
ah! so pBank is not the amount of cash someone has, but indicates if someone has a bank account or not!
now it makes sense :P

okey, then you just have to get that value of pBank and see if its 0 or 1
meaning you just use "mysql_fetch_int()"
after storing the result we could do it like this:
pawn Код:
format(g_szBuffer, sizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'", id);
            mysql_query(g_szBuffer);
            mysql_store_result();
            if(mysql_num_rows() == 1)
            {
                format(g_szBuffer, sizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s'", id);
                mysql_query(g_szBuffer);
                mysql_store_result();
                if(mysql_fetch_int() == 1)//if pBank is 1
                {
                    SendSucces(playerid, "zaidejas turi sask"); // player has a bank acc
                    return 1;
                }
                else//anything else, like 0
                {
                    SendError(playerid, "zaidejas neturi sask"); // player doesnt have bank acc
                    return 1;
                }
            }
mysql_free_result();//freeing is very important
Reply
#10

PHP код:
format(g_szBuffersizeof(g_szBuffer), "SELECT `pName` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s' LIMIT 1"id);
            
mysql_query(g_szBuffer);
            
mysql_store_result();
            if(
mysql_num_rows() == 1)
            {
                
format(g_szBuffersizeof(g_szBuffer), "SELECT `pBank` FROM `"MySQL_PLAYERS_TABLE"` WHERE pName = '%s' LIMIT 1"id);
                
mysql_query(g_szBuffer);
                
mysql_store_result();
                new 
bankCheck mysql_fetch_int();
                if(
bankCheck == 0)
                {
                    
SendError(playerid"ћaidėjas neturi sąskaitos !");
                }
                else
                {
                    
SendSucces(playerid"atliekas pavedima xDD");
                }
                
mysql_free_result();
            }
            else
            {
                
SendError(playerid"ZAIDEJAS NEEGZISTUOJA");
                
ShowPlayerDialog(playerid709DIALOG_STYLE_INPUT"Pinigų pervedimas OFFLINE ћaidėjui""{ffffff}Pinigų pervedimas ћaidėjui iљ banko sąsk.:\n \n      {3B9DFF}•{FFFFFF} įvęskite ћaidėjo V_P, bei pinigų sumą į laukelį, kurią norite pervesti.""Pervesti""Atgal");
            }
            
mysql_free_result();
        } 
IS this okey?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)