[Tutorial] How to create a simple bank system using Y_INI
#1

Hey guys, another tutorial from me; this time its about a simple Bank. This will not be a filterscript, but we will add this to your gamemode. You can make it a filterscript if you want, but i would add it to your gamemode.
Please read everything CAREFULY, otherwise it might give errors, and wont work.
If youre gonna edit this in your gamemode, please, back-up your gamemode so you wont have to remove every single thing you added when trying this and saying you dont want this.

Includes
For this tutorial we will be using these includes & plugins:
Код:
- a_samp (#include <a_samp>)
- y_ini (#include <YSI/y_ini>)
- zcmd (#include <zcmd>)
- whirlpool (native WP_Hash(buf[], len, const str[]);)
ALL the download links are down at the credits, if you need them.

All the callbacks and functions we will gonna use
Callbacks
OnPlayerConnect(playerid)
This callback will be called, when a player trys to connect to your gamemode.
Код:
playerid - This is the ID who connected
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
This callback will be called, when a player 'opens' a dialog.
Код:
playerid - This is the ID who have the dialog opened
dialogid - This is the ID of the dialog, so you can use multiple dialogs
response - You got 2 buttons, if the reponse == 1, you have clicked on the first button, and when it returns 0, you clicked on the second button
listitem - This is optional, and just if you use the style 'DIALOG_STYLE_LIST'
inputtext[] - This is optional aswell, and only for 'DIALOG_STYLE_INPUT'
OnPlayerDisconnect(playerid, reason)
This callback will be called, when a player disconnects.
Код:
playerid - This is the ID who is disconnecting
reason - This is the reason, can be timed out, banned/kicked or just leaving
Functions (Important ones)
strlen - This will 'count' the amount of letters/numbers you have in a word
isnumeric - This will check if the string contains numbers
format - This will format a string to include variables and other strings inside it
fexist - This checks if a folder/file exists
strcmp - This will compare 2 things with eachother, if they compare it returns '0', and if it doesnt compare it returns '1'
strval - This will convert a string in a integer

Self-made functions we will need
First we need a couple of self-made functions. Its not really necessary, but its easier.
pawn Код:
#define PATH "BankAccount/%s.ini" // this will define the path to the folder where the files will be saved
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_RED 0xFF0000FF
// those will be the dialog ids, change them to your own dialogids
#define DIALOG_BANKHOME 5
#define DIALOG_BANKWITHDRAW 6
#define DIALOG_BANKDEPOSIT 7

stock BankPath(playerid)
{
    new string[50];
    format (string, sizeof string, PATH, GetName(playerid) );
    return string;
}

stock GetName(playerid)
{
    new name[24];
    GetPlayerName(playerid, name, sizeof name);
    return name;
}
Alright, now when we have those, we can continue with the variables we need, the enums etc.
pawn Код:
enum pInfo { // add those things which are inside this to your own enum of your PlayerInfo, or just create a new variable for all the bank things
    BankPassword[129], // the password is stored in this
    BankWealth, // the amount of money you have on the ban
    BankLogged // are you logged
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Like i commented, add those things to your already existing enum, or just create a new one.

Connect message
We are going to make if you dont have a bank account yet, to show a message. When you already have a bank account, you wont get a message, and if you want to you can just add it yourself.
pawn Код:
public OnPlayerConnect(playerid)
{
    // NOTE: if youre making this in your GM, add this at the top, or down
    if( !fexist( BankPath(playerid) ) ) // checks if you have a bank account file
    {
        SendClientMessage(playerid, COLOR_YELLOW, "You do not own a bank account yet! Please use /registerbank to register a bank account! ");
        // you dont need a 'return' here, otherwise if you dont have a bank account it wont continue with the things that are used down here
    }
    else if( fexist( BankPath(playerid) ) )
    {
        INI_ParseFile( BankPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); // this will parse all the things that are in the files to the variables
        // for this 'INI_ParseFile' we will have to create a new 'callback', to load everything
    }
    return 1;
}

// if you already have something like this, just add those 2 lines to the existing one, and it should work aswell
forward LoadUser_data(playerid, name[], value[]);
public LoadUser_data(playerid, name[], value[])
{
    INI_Int("Bank_Wealth", PlayerInfo[playerid][BankWealth]);
    INI_String("Bank_Password", PlayerInfo[playerid][BankPassword], 129); // make sure you have the size behind the INI_String, otherwise it will give you an error
    return 1;
}
Okay, now when you connect it will give you a message if you DONT have a bank account yet. Lets continue with the register command

Register command
I will be using the command processor 'ZCMD' for this command, and we will NOT use dialogs to register your bank account.
pawn Код:
COMMAND:registerbank(playerid, params[])
{
    if( !fexist( BankPath(playerid) ) ) // this will check if you dont already have a bank file
    {
        if( !strlen( params ) ) return SendClientMessage(playerid, COLOR_RED, "Usage: /registerbank [pin]"); // if you didnt enter anything in the params, it shows this message
        if( strlen( params ) < 4 || strlen( params ) > 4 ) return SendClientMessage(playerid, COLOR_RED, "A pin has 4 numbers, please use numbers only! "); // if the params have under 4 characters or above 4 characters it shows the message
        if( !isnumeric( params ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only please! "); // when the player doesnt enter numbers, it shows him the message
        new Buffer[129], Message[128]; // create some variables which we will use to format a message, and where we will save the password in
        new INI:file = INI_Open( BankPath(playerid) ); // opening the file using the variable 'file'
        WP_Hash( Buffer, sizeof Buffer, params ); // hashing the params, so you got an encrypted pin code
        INI_WriteString( file, "Bank_Password", Buffer ); // saves the password inside the file
        INI_WriteInt( file, "Bank_Wealth", 0 ); // setting the bank health to 0 so you will have the line in it
        INI_WriteInt( file, "Bank_Logged", 1 ); // you are now logged in
        INI_Close( file ); // closing the file
        INI_ParseFile( BankPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid); // parsing all the things that are in the file in your variables
        format( Message, sizeof Message, "Thank you for registering %s! Your bank pin is: %s", GetName(playerid), params ); // formatting a message, you should know how this works
        SendClientMessage( playerid, COLOR_YELLOW, Message ); // sending the message.. duh :)
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "You already have a bank account and dont need to register. "); // if you already have a file, you get this message and stops the command
        return 0;
    }
    return 1;
}
Now we have the register command, we can continue with the login command, but first lets explain what we already have.
When you connect to your gamemode, it will show a message that you dont have a bank account yet (if you didnt register it yet ofcourse). When you do /registerbank, it will give you an usage message with 'Usage: /registerbank[pin]'. The pin can only contain 4 numbers, no letters, just 4 numbers. When you do '/registerbank 1234', it will register your bank account with he password '1234'.
If you already got a bank account registered, it will show you a message that you already registered. Now lets start with the login command!

Login command
Once again, we will use ZCMD to create the commands, and again NO dialogs when loggin in.
pawn Код:
COMMAND:banklogin(playerid, params[])
{
    if( PlayerInfo[playerid][BankLogged] == 1 ) return SendClientMessage(playerid, COLOR_RED, "You're already logged in! "); // if youre already logged in it gives you this message
    if( !fexist( BankPath(playerid) ) ) // if you dont have a bank account yet (the file doesnt exist) it will show this message and stops the command
    {
        SendClientMessage(playerid, COLOR_RED, "You dont have a bank account yet, please use /registerbank to register it! ");
        return 0;
    }
    else if( fexist( BankPath(playerid) ) ) // if your file does exist, it continues with this
    {
        if( !strlen( params ) ) return SendClientMessage(playerid, COLOR_RED, "Usage: /banklogin [pin]"); // like the register command
        if( strlen( params ) < 4 || strlen( params ) > 4 ) return SendClientMessage(playerid, COLOR_RED, "A pin has 4 numbers, please use numbers only! "); // idem dito
        if( !isnumeric( params ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only please! "); // what can i say? :)
        if( !strcmp( params, PlayerInfo[playerid][BankPassword], true ) ) // with this it compares the params with the variable BankPassword, if they both compare, strcmp will return '0', and thats why we have '1' in front of strcmp. the 'true' wont really matter in this case, since its for to check if youre using upper cased letters or lower cased
        {
            PlayerInfo[playerid][BankLogged] = 1; // youre now logged in
            SendClientMessage(playerid, COLOR_YELLOW, "Thank you for logging in to your bank account! "); // sending a message
        }
        else // if you enter the wrong pin
        {
            SendClientMessage(playerid, COLOR_RED, "Wrong pin! Please try again. ");
            return 0;
        }
        return 1;
    }
    return 1;
}
Nothing much to explain here, lets continue!

Bank home command and wealth function
This is the easiest command from the whole bank account.
pawn Код:
COMMAND:bankhome(playerid, params[])
{
    if( PlayerInfo[playerid][BankLogged] != 1 ) return SendClientMessage( playerid, COLOR_RED, "You are not logged in and can't open your bank yet. "); // this will check if you are logged in, and if youre not it stops the command
    ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // showing the bank home dialog
    return 1;
}
Alright, now with this command it will show the command, but when you press anything ont he dialog, nothing will happen! Lets configurate that now.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dont have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                       // not in use yet
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        // not in use yet
                    }
                }
            }
           
        }
    }
    return 1;
}
Oh well, that was easy
Lets continue with the withdraw.

Withdraw function
First we need to show a dialog when the player presses the second listitem in the dialog (withdraw money).
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dont have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                       // not in use yet
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        // not in use yet
                    }
                }
            }
           
        }
    }
    return 1;
}
That is what we have right now. Since its the second listitem, we will edit the 'case 1'.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dont have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                        ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw. ", "Ok", "Back" ); // showing a new dialog
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        // not in use yet
                    }
                }
            }
           
        }
    }
    return 1;
}
HEY! That wasnt hard at all. Yes, i know that but this is just the start
Now when you come at the the dialog from the withdraw, nothing will happen if you enter anything or click any button. Lets add that to the onDialogResponse.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dotn have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                        ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw. ", "Ok", "Back" ); // showing a new dialog
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        // not in use yet
                    }
                }
            }
           
        }
        case DIALOG_BANKWITHDRAW: // when the dialog is DIALOG_BANKWITHDRAW (6)
        {
            if( response )
            {
                if( !isnumeric( inputtext ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only! "); // this will check if the inputtext contains numbers
                if( strval( inputtext ) > PlayerInfo[playerid][BankWealth] ) return SendClientMessage( playerid, COLOR_RED, "You dont have that amount of money on your bank! " ), ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw.", "Ok", "Back" ); // if the inputtext is higher then you have on your bank, it will show an error message
                PlayerInfo[playerid][BankWealth] = ( PlayerInfo[playerid][BankWealth] - strval( inputtext ) ); // this will remove the money from your bank account
                GivePlayerMoney( playerid, strval( inputtext ) ); // this will add the money from the bank account to your own money
                new String[128];
                format( String, sizeof String, "You withdrew $%i from your bank, and now got $%i on your bank left. ", strval( inputtext ), PlayerInfo[playerid][BankWealth] ); // formatting amessage which shows the amount you withdrew, and the money you have left
                SendClientMessage( playerid, COLOR_YELLOW, String ); // sending the message
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // showing the dialog again, so you dont have to do /bankhome
            }
            else if( !response )
            {
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // when you press the button 'Back', it will go to /bankhome
            }
        }
    }
    return 1;
}
Now when you added the 'case DIALOG_BANKWITHDRAW' thing, and the things that are under it; you will be able to withdraw money from your bank!
Alright, now i can withdraw, but how can i withdraw something when i dont have any money on my bank account?!?!?!?!?!
Well, with the deposit function ofcourse!
Lets start with the deposit function, and then were almost done!
Deposit function
With the deposit function we can deposit the money to your bank account, duh.
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dotn have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                        ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw. ", "Ok", "Back" ); // showing a new dialog
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        // not in use yet
                    }
                }
            }
           
        }
        case DIALOG_BANKWITHDRAW: // when the dialog is DIALOG_BANKWITHDRAW (6)
        {
            if( response )
            {
                if( !isnumeric( inputtext ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only! "); // this will check if the inputtext contains numbers
                if( strval( inputtext ) > PlayerInfo[playerid][BankWealth] ) return SendClientMessage( playerid, COLOR_RED, "You dont have that amount of money on your bank! " ), ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw.", "Ok", "Back" ); // if the inputtext is higher then you have on your bank, it will show an error message
                PlayerInfo[playerid][BankWealth] = ( PlayerInfo[playerid][BankWealth] - strval( inputtext ) ); // this will remove the money from your bank account
                GivePlayerMoney( playerid, strval( inputtext ) ); // this will add the money from the bank account to your own money
                new String[128];
                format( String, sizeof String, "You withdrew $%i from your bank, and now got $%i on your bank left. ", strval( inputtext ), PlayerInfo[playerid][BankWealth] ); // formatting amessage which shows the amount you withdrew, and the money you have left
                SendClientMessage( playerid, COLOR_YELLOW, String ); // sending the message
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // showing the dialog again, so you dont have to do /bankhome
            }
            else if( !response )
            {
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // when you press the button 'Back', it will go to /bankhome
            }
        }
    }
    return 1;
}
This is what we have already, but now we need a deposit case in this. Follow the instructions, and you will know how it works
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid ) // this will 'switch' through the dialogids, you can use if() aswell, but if im right its faster with switch()
    {
        case DIALOG_BANKHOME: // when the dialog is DIALOG_BANKHOME (5)
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // when you selected the first listitem ('Wealth check') and press the first button
                    {
                        new Wealth[128];
                        format( Wealth, sizeof Wealth, "You have $%i on your bank account. ", PlayerInfo[playerid][BankWealth] ); // this will get the amount of money that is in your bank account
                        SendClientMessage(playerid, COLOR_YELLOW, Wealth); // this will send the message.. hm how is that possible o.O
                        ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // Showing the dialog again, so you dotn have to do /bankhome again
                        return 0;
                    }
                    case 1: // when you selected the listitem 'Withdraw money' and press the first button
                    {
                        ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw. ", "Ok", "Back" ); // showing a new dialog
                    }
                    case 2: // when you selected the listitem 'Deposit money' and press the first button
                    {
                        ShowPlayerDialog( playerid, DIALOG_BANKDEPOSIT, DIALOG_STYLE_INPUT, "Bank Deposit", "Please enter the amoutn of money you want to deposit. ", "Ok", "Back" ); // showing a new dialog
                    }
                }
            }
           
        }
        case DIALOG_BANKWITHDRAW: // when the dialog is DIALOG_BANKWITHDRAW (6)
        {
            if( response )
            {
                if( !isnumeric( inputtext ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only! "); // this will check if the inputtext contains numbers
                if( strval( inputtext ) > PlayerInfo[playerid][BankWealth] ) return SendClientMessage( playerid, COLOR_RED, "You dont have that amount of money on your bank! " ), ShowPlayerDialog( playerid, DIALOG_BANKWITHDRAW, DIALOG_STYLE_INPUT, "Bank Withdraw", "Please enter the amount of money you want to withdraw.", "Ok", "Back" ); // if the inputtext is higher then you have on your bank, it will show an error message
                PlayerInfo[playerid][BankWealth] = ( PlayerInfo[playerid][BankWealth] - strval( inputtext ) ); // this will remove the money from your bank account
                GivePlayerMoney( playerid, strval( inputtext ) ); // this will add the money from the bank account to your own money
                new String[128];
                format( String, sizeof String, "You withdrew $%i from your bank, and now got $%i on your bank left. ", strval( inputtext ), PlayerInfo[playerid][BankWealth] ); // formatting amessage which shows the amount you withdrew, and the money you have left
                SendClientMessage( playerid, COLOR_YELLOW, String ); // sending the message
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // showing the dialog again, so you dont have to do /bankhome
            }
            else if( !response )
            {
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // when you press the button 'Back', it will go to /bankhome
            }
        }
        case DIALOG_BANKDEPOSIT: // when the dialog is DIALOG_BANKDEPOSIT (7)
        {
            if( response )
            {
                if( !isnumeric( inputtext ) ) return SendClientMessage(playerid, COLOR_RED, "Numbers only! "); // this will check if the inputtext contains numbers

                if( GetPlayerMoney( playerid ) < strval( inputtext ) ) return SendClientMessage( playerid, COLOR_RED, "You dont have that amount of money on you. "), ShowPlayerDialog( playerid, DIALOG_BANKDEPOSIT, DIALOG_STYLE_INPUT, "Bank Deposit", "Please enter the amoutn of money you want to deposit. ", "Ok", "Back" ); // if your money is lower as the amount you entered, it will give you an error message and show the same dialog
                PlayerInfo[playerid][BankWealth] = ( PlayerInfo[playerid][BankWealth] + strval( inputtext ) ); // adding the amount of money to your bank account
                GivePlayerMoney( playerid, - strval( inputtext) ); // removing the money from 'pocket'
                new String[128];
                format( String, sizeof String, "You depositted $%i to your bank, and now got $%i on your bank. ", strval( inputtext ), PlayerInfo[playerid][BankWealth] ); // formatting the message which howmutch you depositted, and the amount you now got on your bank
                SendClientMessage( playerid, COLOR_YELLOW, String ); // sending the message
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // showing /bankhome dialog again
            }
            else if( !response )
            {
                ShowPlayerDialog( playerid, DIALOG_BANKHOME, DIALOG_STYLE_LIST, "Bank home", "Wealth check \nWithdraw money \nDeposit money", "Ok", "Leave" ); // when you press the button 'Back', it will go to /bankhome
            }
        }
    }
    return 1;
}
Alrightyo, now we got the deposit function aswell. Now we are practicly done, but when we log out and we stored some money in the bank, it doesnt save the money yet. Thats why we have the callback 'OnPlayerDisconnect(explained on top)'.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if( fexist( BankPath(playerid) ) )
    {
        new INI:file = INI_Open(BankPath(playerid)); // opening the file
        INI_WriteInt( file, "Bank_Wealth", PlayerInfo[playerid][BankWealth] ); // saving the bankwealth in the file
        INI_WriteInt( file, "Bank_Logged", 0 ); // changing that you arent logged in to your bank account
        INI_Close( file ); // closing the file
    }
    return 1;
}
Now we are done, and the bank system works 100% (if you done it the right way ofcourse >: ) ). If you got any further questions, please ask them and imma answer them ASAP.

~Wesley

Credits
- Wesley221 - Creating this tutorial
- ****** - Creating y_ini and Whirlpool
- Zeex - Creating ZCMD
Reply
#2

Very nice man! rep
Reply
#3



Very good explanations, and it's really a SIMPLE bank system.

5/5 for tutorial.
Reply
#4

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Very nice man! rep
Thanks
Quote:
Originally Posted by costel_nistor96
Посмотреть сообщение


Very good explanations, and it's really a SIMPLE bank system.

5/5 for tutorial.
Haha, that why it says 'Simple' in the title
I might 'update' this tut later, and add a transfer function in it aswell.
Reply
#5

Looks good man!
Reply
#6

Amazing. You are the man!
Reply
#7

Quote:
Originally Posted by Kingunit
Посмотреть сообщение
Looks good man!
Quote:
Originally Posted by BigAl
Посмотреть сообщение
Amazing. You are the man!
Thanks and thanks
Reply
#8

How in the goddamn world will this work?

pawn Код:
INI_ParseFile( BankPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
And it's not even formatted!
Reply
#9

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
How in the goddamn world will this work?

pawn Код:
INI_ParseFile( BankPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
And it's not even formatted!
If youre gonna try it, you will see that it will work
Reply
#10

Quote:
Originally Posted by costel_nistor96
Посмотреть сообщение


Very good explanations, and it's really a SIMPLE bank system.

5/5 for tutorial.
I wanted to say that!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)