Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*-----------------------------------------------------------------------------------------------------------------------------------------------------------*//
- #include <a_samp>
- #include <Dini>
- #include <dudb>
- new pname[MAX_PLAYER_NAME];
- new banklogged[MAX_PLAYERS];
- new bankmoney[MAX_PLAYERS];
- #define COLOR_RED 0xFF0000AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_GREEN 0x00FF00AA
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- CreatePickup(1239, 23, 1458.6437,-1011.8918,26.8438, -1);
- print("/////////////////////////////////////////");
- print("// SIMPLE BANK SYSTEM BY SEAN5874 //");
- print("// Releasedate: 04-04-10 //");
- print("///////////////////////////////////////");
- return 1;
- }
- public OnFilterScriptExit()
- {
- return 1;
- }
- #endif
- public OnPlayerDisconnect(playerid, reason)
- {
- dini_IntSet(udb_encode(pname), "bankmoney", bankmoney[playerid]);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx, tmp[265], tmp2[256];
- cmd = strtok(cmdtext, idx);
- GetPlayerName(playerid, pname, sizeof(pname));
- new string[128];
- //register and login stuff
- if (strcmp("/createaccount", cmdtext, true, 10) == 0)
- {
- new pincode; //creating the variable
- tmp = strtok(cmdtext, idx);
- if(!strlen(tmp)) //checks of the player dont forgot any variable
- {
- SendClientMessage(playerid, COLOR_RED, "USAGE: /createaccount [pincode]");
- return 1;
- }
- pincode = strval(tmp); //'pincode' got saved in an TMP
- if (!dini_Exists(udb_encode(pname))) //checks of the player have already made an account
- {
- dini_Create(udb_encode(pname));
- dini_IntSet(udb_encode(pname), "pincode", udb_hash(tmp)); //puts the pincode in the file
- dini_IntSet(udb_encode(pname), "bankmoney", 0); // if you want to give the player a starters bonus, then add here an other number
- SendClientMessage(playerid, COLOR_GREEN,"You have created new bank account! You can now log in.");
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"You have already a bank account!"); //if the player have already an bankaccount
- return 1;
- }}
- if (strcmp("/loginaccount", cmdtext, true, 10) == 0)
- {
- new pincode; //creating the variable
- tmp = strtok(cmdtext, idx);
- if(banklogged[playerid] == 1) //checks if a player is logged in in his account
- {
- SendClientMessage(playerid, COLOR_RED, "You are already logged in!"); return 1;
- }
- if(!strlen(tmp)) //checks of the player dont forgot any variable
- {
- SendClientMessage(playerid, COLOR_RED, "USAGE: /loginaccount [pincode]");
- return 1;
- }
- pincode = strval(tmp); //'pincode' got saved in an TMP
- tmp2 = dini_Get(udb_encode(pname), "pincode"); //gets the pincode that is given by creating the account
- if (udb_hash(tmp) != strval(tmp2)) //looks of the given pincode match with the pincode in the file
- {
- SendClientMessage(playerid, COLOR_RED, "You have entered a wrong pincode, try again!"); //if not...
- return 1;
- }
- SendClientMessage(playerid, COLOR_GREEN, "You have logged in into your bankaccount!");//if yes...
- banklogged[playerid] = 1;
- return 1;
- }
- //deposit, withdraw and balance cmd's
- if(strcmp(cmd, "/deposit", true)==0)
- {
- new amount; //creating the variable
- tmp = strtok(cmdtext, idx);
- if(banklogged[playerid] == 0) //checks if a player is logged in in his account
- {
- SendClientMessage(playerid, COLOR_RED, "You are not logged in on your bank account!"); return 1;
- }
- if(!strlen(tmp)) // checks of the player dont forgot any variable
- {
- SendClientMessage(playerid, COLOR_RED, "USAGE: /deposit [amount]"); return 1;
- }
- amount = strval(tmp); //'amount' got saved in an TMP
- new currentm = GetPlayerMoney(playerid);
- if(currentm <= amount) //checks if the players current money is lower than the amount he want to deposit
- {
- SendClientMessage(playerid, COLOR_RED,"You can't deposit more money than you have!"); return 1;
- }
- if(IsPlayerInRangeOfPoint(playerid, 1.0, 1458.6437,-1011.8918,26.8438))// checks if the player at the bank
- {
- bankmoney[playerid] += amount; //money goes on the bank account
- format(string, sizeof(string), "You have deposited $%d to your bank account.",amount);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- GivePlayerMoney(playerid, -amount);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"You are not at the Bank!"); return 1; // if hes not at the bank...
- }
- }
- if(strcmp(cmd, "/balance", true)==0)
- {
- if(banklogged[playerid] == 0) //checks if a player is logged in in his account
- {
- SendClientMessage(playerid, COLOR_RED, "You are not logged in on your bank account!"); return 1;
- }
- if(IsPlayerInRangeOfPoint(playerid, 1.0, 1458.6437,-1011.8918,26.8438)) //check if the player is at the bank
- {
- format(string, sizeof(string), "You have currently $%d in your bank account.",bankmoney[playerid]); //show the amount of money on the account
- SendClientMessage(playerid, COLOR_YELLOW, string);
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"You are not at the Bank!"); return 1; //if hes not at the bank
- }
- }
- if(strcmp(cmd, "/withdraw", true)==0)
- {
- new wamount; //creating the variable
- tmp = strtok(cmdtext, idx);
- if(banklogged[playerid] == 0) // checks if a player is logged in in his account
- {
- SendClientMessage(playerid, COLOR_RED, "You are not logged in on your bank account!"); return 1;
- }
- if(!strlen(tmp)) // checks of the player dont forgot any variable
- {
- SendClientMessage(playerid, COLOR_RED, "USAGE: /withdraw [amount]"); return 1;
- }
- wamount = strval(tmp); //'wamount' got saved in an TMP
- new bank = bankmoney[playerid];
- if(bank <= wamount) // if a player tries to withdraw more money than he haves on his account...
- {
- SendClientMessage(playerid, COLOR_RED,"You can't withdraw more money than you have!"); return 1;
- }
- if(IsPlayerInRangeOfPoint(playerid, 1.0, 1458.6437,-1011.8918,26.8438))// check if the player is at the bank
- {
- bankmoney[playerid] -= wamount; //money is taken from the bank account
- format(string, sizeof(string), "You have withdrawed $%d to your bank account.",wamount); // show the amount of withdrawed money
- SendClientMessage(playerid, COLOR_YELLOW, string);
- GivePlayerMoney(playerid, wamount);// gives the player his money
- return 1;
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED,"You are not at the Bank!"); return 1; //if hes not at the bank
- }
- }
- return 0;
- }
- //*-----------------------------------------------------------------------------------------------------------------------------------------------------------*//
Advertisement
Add Comment
Please, Sign In to add comment