SA-MP Forums Archive
Bug in my bank system - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Bug in my bank system (/showthread.php?tid=244104)



Bug in my bank system - OldDirtyBastard - 26.03.2011

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



Re: Bug in my bank system - iJumbo - 26.03.2011

i dont understand why u dont use sscanf ?


Re: Bug in my bank system - armyoftwo - 26.03.2011

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


Re: Bug in my bank system - iJumbo - 26.03.2011

and if player write no a number?


Re: Bug in my bank system - armyoftwo - 26.03.2011

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



Re: Bug in my bank system - iJumbo - 26.03.2011

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


Re: Bug in my bank system - armyoftwo - 26.03.2011

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


Re: Bug in my bank system - iJumbo - 26.03.2011

ah sorry ... yes I just wake up now xD


Re: Bug in my bank system - Calgon - 26.03.2011

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.


Re: Bug in my bank system - OldDirtyBastard - 26.03.2011

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