22.06.2012, 15:23
pawn Код:
CMD:createaccount(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid,10.0,2316.6199,-15.5360,26.7422)) return SendClientMessage(playerid,0xD6D6D6AA,"You are not in the bank");
{
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;
}
///////////////////////////
CMD:loginaccount(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid,10.0,2316.6213,-12.5825,26.7422)) return SendClientMessage(playerid,0xD6D6D6AA,"You are not in the bank");
{
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
CMD:deposit(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid,10.0,2316.6089,-7.2970,26.7422)) return SendClientMessage(playerid,0xD6D6D6AA,"You are not in the bank");
{
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;
}
//////////////////////
CMD:balance(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid,10.0,2316.6208,-4.7285,26.7422)) return SendClientMessage(playerid,0xD6D6D6AA,"You are not in the bank");
{
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;
}
////////////////////
CMD:withdraw(playerid, params[])
{
if(!IsPlayerInRangeOfPoint(playerid,10.0,2316.6208,-9.9430,26.7422)) return SendClientMessage(playerid,0xD6D6D6AA,"You are not in the bank");
{
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 1;
}