Bug in my bank system
#1

Hello, i have a little bug in my bank system, it doesnt writes the correct ammount of money.
First time it writes the correct one, but the second time it goes kinda messsy and it isnt calculating
the ammounts and etc..
Could anyone please take a look at it and tell me what could be wrong?
Thanks regards.

pawn Код:
CMD:bank(playerid, params[])
{
    //Statements like sscanf, Insufficient Funds and etc...
    new PlayerFile[13 + MAX_PLAYER_NAME];
    format(PlayerFile, sizeof PlayerFile, "Accounts/%s.ini", Encode(PlayaName(playerid)));
    if(GetPVarInt(playerid, "Bank") + strval(params) > 100000)
    {
        SendClientMessage(playerid, -1, ""COL_RED"ERROR:{FFFFFF} Your bank account can only hold 100 000$");
    }
    else
    {
        new INI:PlayerAcc = INI_Open(PlayerFile);
        INI_WriteInt(PlayerAcc,"BANK",GetPVarInt(playerid, "Bank") + strval(params));
        INI_Close(PlayerAcc);
        GivePlayerMoney(playerid,-strval(params));
        new string[128];
        format(string,sizeof(string),"You have successfully banked %d$ into your bank account.",strval(params));
        SendClientMessage(playerid,COLOR_GREEN,string);
    }
    return 1;
}
pawn Код:
if(!strcmp(name,"BANK"))SetPVarInt(playerid,"Bank",strval(value));
Reply
#2

i dont understand why u dont use sscanf ?
Reply
#3

Quote:
Originally Posted by [ISS]jumbo
Посмотреть сообщение
i dont understand why u dont use sscanf ?
Because he doesn't need sscanf in this case.

pawn Код:
CMD:bank(playerid, params[])
{
    //Statements like sscanf, Insufficient Funds and etc...
    new PlayerFile[13 + MAX_PLAYER_NAME];
    format(PlayerFile, sizeof PlayerFile, "Accounts/%s.ini", Encode(PlayaName(playerid)));
    if(GetPVarInt(playerid, "Bank") + strval(params) > 100000)
    {
        SendClientMessage(playerid, -1, ""COL_RED"ERROR:{FFFFFF} Your bank account can only hold 100 000$");
    }
    else
    {
        new INI:PlayerAcc = INI_Open(PlayerFile);
        INI_WriteInt(PlayerAcc,"BANK",GetPVarInt(playerid, "Bank") + strval(params));
        INI_Close(PlayerAcc);
        GivePlayerMoney(playerid,-strval(params));
        SetPVarInt(playerid, "Bank", GetPVarInt(playerid, "Bank") + strval(params));
        new string[128];
        format(string,sizeof(string),"You have successfully banked %d$ into your bank account.",strval(params));
        SendClientMessage(playerid,COLOR_GREEN,string);
    }
    return 1;
}
You forgot SetPVarInt(playerid, "Bank", GetPVarInt(playerid, "Bank") + strval(params));
Reply
#4

and if player write no a number?
Reply
#5

Quote:
Originally Posted by [ISS]jumbo
Посмотреть сообщение
and if player write no a number?
Use this function
pawn Код:
stock IsNumeric(const stringg[])
{
    for(new i = 0; i < strlen(stringg); i++)
    {
        if(stringg[i] > '9' || stringg[i] < '0') return 0;
    }
    return 1;
}
Reply
#6

yeah .. but the code is ok i dont see problems :/
Reply
#7

Quote:
Originally Posted by [ISS]jumbo
Посмотреть сообщение
yeah .. but the code is ok i dont see problems :/
I have posted the "fixed" code.
Reply
#8

ah sorry ... yes I just wake up now xD
Reply
#9

Also you should just create an integer and use strval once or you're just going to waste time trying to convert the string to an integer every single time that you need it.

Good usage of isnull though, hardly anyone uses this trick.
Reply
#10

Nice one armyoftwo it works perfectly now. And thanks for the hint Calg00ne.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)