Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <YSI/y_ini>
- #include <zcmd>
- native WP_Hash(buf[], len, const str[]);
- #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;
- }
- 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];
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment