new ebank; //enter bank
new exbank; //exit bank
public OnPlayerPickUp(playerid,pickupid)
{
if(pickupid==exbank)
{
SetPlayerPos(playerid,-1706.7177,785.8370,25.1731);
SetPlayerInterior(playerid,0);
}
if(pickupid==ebank)
{
SetPlayerPos(playerid,2315.952880,-1.618174,26.742187);
SetPlayerInterior(playerid,0);
}
return 1;
}
#define bPATH "/BankDB/%s.ini"
stock BankDB(playerid)
{
new string[128],pName[MAX_PLAYER_NAME];//we defined the variable that will store the player's name
GetPlayerName(playerid,pName,sizeof(pName));//we get the name
format(string,sizeof(string),bPATH,pName);//we format the file for the player
return string;//this will return his name,because we actually stored in the string the player's name
}
enum bInfo
{
Owner[MAX_PLAYER_NAME],
CardNumber,
DepositedMoney
}
new BankInfo[MAX_PLAYERS][bInfo];//this will make the bank features available, and we will actually store the variables through BankInfo for each player
forward Load_FileTag(playerid,name[],value[]);
public Load_FileTag(playerid,name[],value[]);
{
return 1;
}
[BankData]//the actual tag Owner = [LSCS]Eddie DepositedMoney = 49750 CardNumber = 1000
forward LoadBankInfo_BankData(playerid,name[],value[]);
public LoadBankInfo_BankData(playerid,name[],value[])//you can see that the tag is BankData(like inside the file)
{
INI_String("Owner",BankInfo[playerid][Owner],24);//we will need to load the stored
INI_Int("CardNumber",BankInfo[playerid][CardNumber]);//the card number will be stored
INI_Int("DepositedMoney",BankInfo[playerid][DepositedMoney]);//the ammount of deposited ammount stored
return 1;
}
public OnPlayerConnect(playerid)
{
if(fexist(BankDB(playerid))) INI_ParseFile(BankDB(playerid), "LoadBankInfo_%s", .bExtra = true, .extra = playerid);//THIS is the actual loading
return 1;
}
enum pInfo
{
CardOwner
}
PlayerInfo[playerid][CardOwner]=0;
[NextBNumber] CurrentCardNum = 1000
#define DIALOG_DEPOSITM 18
#define DIALOG_WITHDRAWM 19
#define DIALOG_BUYCARD 20
#define DIALOG_CARDINFO 21
#define DIALOG_CARDCHECK 22
#define DIALOG_TRANSFERM 23
new DepositMoney;
new WithDrawMoney;
new BuyCard;
new TransferMoney;
new tShow[MAX_PLAYERS];//we will see later what this stands for
OnPlayerPickUpPickUp(playerid,pickupid)
{
if(pickupid==TransferMoney)
{
if(PlayerInfo[playerid][CardOwner]==1)
{
if(tShow[playerid]==0)
{
tShow[playerid]=1;
ShowPlayerDialog(playerid,DIALOG_CARDCHECK,DIALOG_STYLE_INPUT,"International Bank of SA","Insert your firend's card number:","OK","Cancel");
}
}
}
if(pickupid==DepositMoney)
{
if(PlayerInfo[playerid][CardOwner]==1)
{
ShowPlayerDialog(playerid,DIALOG_DEPOSITM,DIALOG_STYLE_INPUT,"International Bank of SA","Insert the ammount of money you wish to deposit:","OK","Cancel");
}
}
if(pickupid==WithDrawMoney)
{
if(PlayerInfo[playerid][CardOwner]==1)
{
ShowPlayerDialog(playerid,DIALOG_WITHDRAWM,DIALOG_STYLE_INPUT,"International Bank of SA","Insert the ammount of money you wish to withdraw","OK","Cancel");
}
}
if(pickupid==BuyCard)
{
ShowPlayerDialog(playerid,DIALOG_BUYCARD,DIALOG_STYLE_MSGBOX,"International Bank of San Andreas","Do you want to buy a card,in order to open a bank account(500$)?","Yes","No");
}
return 1;
}
new cNum;//the variable to store the card number in
INI:ABankNum[NextBNumber](name[], value[])
{
INI_Int("CurrentCardNum",cNum);//the storage
return 0;
}
new bInterest[MAX_PLAYERS];//the specific timer for each player
forward BankInterest(playerid);//this function will execute the code when the timer is over,and then repeats the timer
OnPlayerConnect(playerid)
{
tShow[playerid]=0;
//NOW I DO suposse,that when the player logs in,you parse(load) his pFile,AND now,therefor,something more will be loaded :D,and that is PlayerInfo[playerid][CardOwner],so here we go
if(fexist(YOURPlayerDataPath(playerid)))
{
//your loading function(OBVIUSLY,because you loaded the info,we will know the value of PlayerInfo[playerid][CardOwner]
if(PlayerInfo[playerid][CardOwner]==1) bInterest=SetTimerEx("BankInterest",1440000,true,"i",playerid);//we set the timer IF the player has a card
}
return 1;
}
public BankInterest(playerid)
{
BankInfo[playerid][DepositedMoney]=BankInfo[playerid][DepositedMoney]+10000;//the player receives 10k
new INI:bFile=INI_Open(BankDB(playerid));//we open the player's bank file
INI_SetTag(bFile,"BankData");//we set the tag
INI_WriteInt(bFile,"DepositedMoney",BankInfo[playerid][DepositedMoney]);//we modify the variable
INI_Close(bFile);//we close the file
SendClientMessage(playerid,COLOR_YELLOW,"Bank interest received!");//we tell the player that now he's richer
return 1;
}
if(dialogid==20)
{
if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted!");
if(response==1)
{
if(GetPlayerScore(playerid)>=30)//the score request
{
if(PlayerInfo[playerid][CardOwner]==0)//if he doesn't have a card
{
SendClientMessage(playerid,COLOR_GREEN,"You have succesfully bhought a bank card,and now have an account on your name opened in this bank!");
SendClientMessage(playerid,COLOR_GREEN,"In order to acces the informations of your card anytime you want,use /cardinfo");
INI_Load("ABankNum.ini");//WE LOAD THE CardNumber association file
GivePlayerMoney(playerid,-500);//we take te price of the card
BankInfo[playerid][CardNumber]=cNum;//as you should remeber I wanted to store the cardnumber in cNum
new INI:cInfo=INI_Open("ABankNum.ini");//now I open the file that stores the next card number
INI_SetTag(cInfo,"NextBNumber");//I set the tag
INI_WriteInt(cInfo,"CurrentCardNum",cNum+1);//I increment the number(if the actual player's cardnumber is 1000,the next one will be 1001
INI_Close(cInfo);
BankInfo[playerid][DepositedMoney]=0;//he receives no deposited bonus because I am a bad guy :D
new pName[24];
GetPlayerName(playerid,pName,sizeof(pName));
PlayerInfo[playerid][CardOwner]=1;
new INI:PFile=INI_Open(Accounts(playerid));//FIRST WE OPEN HIS ACCOUNT file
INI_SetTag(PFile,"Data");//we set the tag
INI_WriteInt(PFile,"CardOwner",PlayerInfo[playerid][CardOwner]);//we tell the DataBase that he now HAS a card
INI_Close(PFile);//we close the file
format(BankInfo[playerid][Owner],24,"%s",pName);
new INI:bFile=INI_Open(BankDB(playerid));//NOW we open his Bank DataBase file(actually,because he's buying card,we're creating IT,as the file DOES NOT exist
INI_SetTag(bFile,"BankData");//we set the tag
INI_WriteString(bFile,"Owner",BankInfo[playerid][Owner]);//we store the owner
INI_WriteInt(bFile,"DepositedMoney",BankInfo[playerid][DepositedMoney]);//we store the deposited ammount
INI_WriteInt(bFile,"CardNumber",BankInfo[playerid][CardNumber]);//we store his card number
INI_Close(bFile);
bInterest[playerid]=SetTimerEx("BankInterest",1440000,true,"i",playerid);//we set the timer FOR THE specific player
}
else SendClientMessage(playerid,COLOR_RED,"You already own a card!Type /cardinfo for more!");
}
else SendClientMessage(playerid,COLOR_RED,"You need at least 30 score to buy a card!");
}
}
if(dialogid==18)
{
if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted!");
if(response==1)
{
if(!strval(inputtext)) return SendClientMessage(playerid,COLOR_RED,"Invalid ammount!");//player is able to insert ONLY numbers
else
{
new DepositAmmount=strval(inputtext);//this is how we get the number he inserted through the dialog
new CurrentAmmount=GetPlayerMoney(playerid);//we get his money
if(DepositAmmount>CurrentAmmount) return SendClientMessage(playerid,COLOR_RED,"You don't have that much money one you!");//if he has 20,and tries to deposit 21,he won't be able
else
{
new INI:bFile=INI_Open(BankDB(playerid));//else we open his DataBase
INI_SetTag(bFile,"BankData");//we set the tag
BankInfo[playerid][DepositedMoney]=BankInfo[playerid][DepositedMoney]+DepositAmmount;//we modify the deposit variable by adding to it the number inserted through the dialog
INI_WriteInt(bFile,"DepositedMoney",BankInfo[playerid][DepositedMoney]);//and of course we store it
INI_Close(bFile);//then we close the file
GivePlayerMoney(playerid,-DepositAmmount);//BUT the player looses the deposited ammount(he had 40$,deposited 20$,now he has 20$)
SendClientMessage(playerid,COLOR_YELLOW,"Succesfully deposited money into account,type /cardinfo for more!");
}
}
}
}
if(dialogid==19)
{
if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted!");
if(response==1)
{
if(!strval(inputtext)) return SendClientMessage(playerid,COLOR_RED,"Invalid ammount!");
else
{
new WithDrawAmmount=strval(inputtext);
if(WithDrawAmmount>BankInfo[playerid][DepositedMoney]) return SendClientMessage(playerid,COLOR_RED,"You don't have that much money in bank,type /cardinfo for more!");
else
{
BankInfo[playerid][DepositedMoney]=BankInfo[playerid][DepositedMoney]-WithDrawAmmount;//when he substracted the respective ammount,then his deposited ammount has changed,of course
new INI:bFile=INI_Open(BankDB(playerid));//we open the DataBase
INI_SetTag(bFile,"BankData");//we set the tag
INI_WriteInt(bFile,"DepositedMoney",BankInfo[playerid][DepositedMoney]);//we STORE the new deposited ammount
INI_Close(bFile);//we close the file
GivePlayerMoney(playerid,WithDrawAmmount);//we provide him with the required money
new string[256];
format(string,sizeof(string),"Succesfully withdrawed %d$!",WithDrawAmmount);//I formated a string to inform the player how much he has withdrawed
SendClientMessage(playerid,COLOR_YELLOW,string);
}
}
}
}
new transferplayer;//this will store the playerid's wich has the inserted card number
if(dialogid==22)
{
if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted!");
if(response==1)
{
if(!strval(inputtext)) return SendClientMessage(playerid,COLOR_RED,"Invalid card number!");//again,he can only insert a numeric value in order to avoid bugs/errors
else
{
new cardnum;
cardnum=strval(inputtext);
new OK=0;//this variable will tell us if there's any player with the inserted card number(1 YES,0 NO)
for(new i=0;i<MAX_PLAYERS;i++)//we start the loop
{
if(BankInfo[i][CardNumber]==cardnum)//we check the players cardnumber,if it's the same as the inserted one
{
transferplayer=i;//if yes,we store his ID,into the variable defined earlier
OK=1;//we make the OK variable 1(THERE IS SOMEONE with the inserted card)
break;//we stoop the loop
}
}
if(OK==0) SendClientMessage(playerid,COLOR_RED,"Your friend is not connected or card number is invalid!");
else
{
ShowPlayerDialog(playerid,DIALOG_TRANSFERM,DIALOG_STYLE_INPUT,"International Bank of SA","Insert the ammount of money you wish to transfer:","OK","Cancel");//we show the ACTUAL TRANSFER dialog
}
}
}
}
if(dialogid==23)
{
if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action canceled!");
if(response==1)
{
if(!strval(inputtext)) return SendClientMessage(playerid,COLOR_RED,"Invalid ammount of money!");
else
{
new transmoney;
transmoney=strval(inputtext);//so we get the inserted ammount wich the player wishes to transfer
if(transmoney>BankInfo[playerid][DepositedMoney]) {SendClientMessage(playerid,COLOR_RED,"You don't have that much money on bank!");tShow[playerid]=0;//the variable that stops the dialogs from overwriting is now 0,because it's like he exited the pickup ;)}//BUT,if his deposited ammount is smaller than the inserted ammount,then he won't be able to transfer money anymore
else
{
BankInfo[playerid][DepositedMoney]=BankInfo[playerid][DepositedMoney]-transmoney;//first we modify the actual player's deposited ammount
new INI:bFile=INI_Open(BankDB(playerid));//we open his file
INI_SetTag(bFile,"BankData");//we set the tag
INI_WriteInt(bFile,"DepositedMoney",BankInfo[playerid][DepositedMoney]);//we store the new deposited ammount
INI_Close(bFile);//we close the file
BankInfo[transferplayer][DepositedMoney]=BankInfo[transferplayer][DepositedMoney]+transmoney;//NOW we modify the deposited ammount OF the player that the money has been transfered TO
new INI:bFile2=INI_Open(BankDB(transferplayer));//we open HIS DataBase
INI_SetTag(bFile2,"BankData");//we set the tag
INI_WriteInt(bFile2,"DepositedMoney",BankInfo[transferplayer][DepositedMoney]);//we store the new ammount
INI_Close(bFile2);//and we close his file
new pName[24],pName2[24];//variables to store the player's name
GetPlayerName(transferplayer,pName2,sizeof(pName2));
GetPlayerName(playerid,pName,sizeof(pName));
new string[256],string2[256];//informative messages
format(string,sizeof(string),"Succesfully transfered %d$ to %s!",transmoney,pName2);//we format the message wich will look like "Succesfully transfered 20$ to John"
SendClientMessage(playerid,COLOR_GREEN,string);//we inform the player
PlayerPlaySound(playerid,1057,0,0,0);
format(string2,sizeof(string2),"%s has succesfully transfered you %d$!",pName,transmoney);//again,informative messages
SendClientMessage(transferplayer,COLOR_GREEN,string2);
PlayerPlaySound(transferplayer,1057,0,0,0);//just a confirmation sound
tShow[playerid]=0;//again we make the variable that prevents dialogs from overwriting 0
}
}
}
}
COMMAND:cardinfo(playerid,params[])
{
if(PlayerInfo[playerid][CardOwner]==0) return SendClientMessage(playerid,COLOR_RED,"You don't have a bank card,go buy one for ONLY 500$!");
else
{
new string[128];
format(string,sizeof(string),"Card Owner:%s\nCard Number:%d\nDeposited Money:%d\n\n IBSA-POWER to you!",BankInfo[playerid][Owner],BankInfo[playerid][CardNumber],BankInfo[playerid][DepositedMoney]);//we format the string wich will contain the player's bank data
ShowPlayerDialog(playerid,DIALOG_CARDINFO,DIALOG_STYLE_MSGBOX,"International Bank of SA",string,"OK","Cancel");//this is the infromative dialog
}
return 1;
}
if(dialogid==21)
{
if(response==0||response==1) return SendClientMessage(playerid,COLOR_GREEN,"Enjoy the power brought to you by IBSA(International Bank of San Andreas)!");//sends the same message,no matter what button the player pressed :P
}
Nice tutorial but not explained much.The things are not explained that would be important to newbies.Anyways nice tutorial.
|
OK,thanks,BUT,honestly,how can you say that I didn't explained much,I explained everything that was to be explained,plus I gave examples,etc.,and it's an advanced tutorial,it's more like for intermediaries then Rockies,so :P,I kinda think that you don't understand something :P,and that's why you said I didn't explain too much
|
new cNum;//the variable to store the card number in
INI:ABankNum[NextBNumber](name[], value[])
{
INI_Int("CurrentCardNum",cNum);//the storage
return 0;
}
I knew everything about this
![]() ![]() One more thing that I wanted a explanation on this part,and how you edit this in the following codes. pawn Код:
|
INI_Load(FileName.ini);
error 033: array must be indexed (variable "bInterest")
if(PlayerInfo[playerid][CardOwner]==1) bInterest =SetTimerEx("bInterest",1440000,true,"i",playerid);//we set the timer IF the player has a card
Fuck i have 26 errors
![]() Can i get full code? pastebin or something like that ![]() I want that awesome bank system and understand something ![]() |
new cNum;
INI:ABankNum[NextBNumber](name[], value[])
{
INI_Int("CurrentCardNum",cNum);
return 0;
}
BankInfo[playerid][CardNumber]=cNum;
new INI:cInfo=INI_Open("ABankNum.ini");
INI_SetTag(cInfo,"NextBNumber");
INI_WriteInt(cInfo,"CurrentCardNum",cNum+1);
INI_Close(cInfo);