Making a bank system and need help [y_ini]
#1

Making a Bank System


What's going on?
Hey guys! So.. I started learning pawn few days ago and I started building my very first Gamemode. Now I am making a bank system in it and I need help from you guys to make it work properly. But first things first. The first thing I made was ATMs. And it worked good but I want to remake it... I'll show you how and why later. First, check the old version:
First ATM System
Here we go! Here's everithing connected with the ATM System:

Includes, defines, variables...:
PHP код:
#include <a_samp>
#include <YSI\y_ini> //I am using this include for the Login/Register System, but I want to use it for ATMs too... later about that
#define MAX_ATM 100
#define DIALOG_ATM_HOME 6
#define DIALOG_ATM_BALANCE 7
#define DIALOG_ATM_WITHDRAWAL 8
new PickupATM
Let's work with one ATM only for now. It'll be easier.
In callback OnGameModeInit we are creating object (the atm) and a pickup.
PHP код:
public OnGameModeInit()
{
    
PickupATM CreatePickup(1212,2,-1981.2130.927.25,-1);
    
CreateObject(2942,-1980.6000000,130.9004000,27.3000000,0.0000000,0.0000000,270.0000000);
    return 
1;

In callback OnPlayerConnect we'll create a MapIcon for the ATM.
PHP код:
public OnPlayerConnect(playerid)
{
    
SetPlayerMapIcon(playerid5, -1980.6000000,130.9000000,27.3000000520MAPICON_LOCAL);
    return 
1;

Now we have everithing set in the world. We have to make dialogs and other stuff:
PHP код:
public OnPlayerPickUpPickup(playeridpickupid)
{
    if(
pickupid == PickupATM)
    {
        
ShowPlayerDialog(playeridDIALOG_ATM_HOMEDIALOG_STYLE_LIST"ATM""Withdrawal\nAccount Balance""OK""CANCEL");
        }
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    case 
DIALOG_ATM_HOME:
    {
        if(
response)
        {
            switch(
listitem)
            {
                case 
0:
                {
                    
ShowPlayerDialog(playeridDIALOG_ATM_WITHDRAWALDIALOG_STYLE_INPUT"ATM - Withdrawal""{00DCDC}Enter the amount and press OK.""OK""CANCEL");
                }
                case 
1
                {
                    new 
balancestring[60];
                    
format(balancestringsizeof(balancestring), "{00DCDC}Account Balance:\n\t{148C0A} $%i"PlayerInfo[playerid][pBank]);
                    
ShowPlayerDialog(playeridDIALOG_ATM_BALANCEDIALOG_STYLE_MSGBOX"ATM - Balance"balancestring"OK""");
                }
            }
        }
    }
    case 
DIALOG_ATM_BALANCE:
    {
        if(
response)
        {
            
ShowPlayerDialog(playeridDIALOG_ATM_HOMEDIALOG_STYLE_LIST"ATM""Withdrawal\nAccount Balance""OK""CANCEL");
        }
    }
    case 
DIALOG_ATM_WITHDRAWAL:
    {
        if(!
response)
        {
            
ShowPlayerDialog(playeridDIALOG_ATM_HOMEDIALOG_STYLE_LIST"ATM""Withdrawal\nAccount Balance""OK""CANCEL");
        }
        else
        {
            new 
input strval(inputtext);
            if (
input 0)
            {
                if (
PlayerInfo[playerid][pBank] >= input)
                {
                    
GivePlayerMoney(playeridinput);
                    
PlayerInfo[playerid][pBank] = PlayerInfo[playerid][pBank] - input;
                }
                else    
                {
                    
ShowPlayerDialog(playeridDIALOG_ATM_WITHDRAWALDIALOG_STYLE_INPUT"ATM - Withdrawal"""COL_RED"You don't have enough money in your bank account!\n{00DCDC}Enter the amount and press OK.""OK""CANCEL");
                }
            }
            else
            {
                
ShowPlayerDialog(playeridDIALOG_ATM_WITHDRAWALDIALOG_STYLE_INPUT"ATM - Withdrawal"""COL_RED"You've entered Incorrect Value!\n{00DCDC}Enter the amount and press OK.""OK""CANCEL");
            }
        }
    }
    return 
1;

Pretty easy huh?
But I am going to make some jobs and stuff, and I'd like the ATMs to have some cash in stock, so as to make a job which will have to restock the ATMs... Next thing is, that there's no only one ATM at the world. SO I need to give every ATM an ID, so as to controll the cash in every single one of them. And I want to save all this information into files for each ATM. It'll be nice to have coordinates of each ATM (object) and it's pickup in those files too...

So I spent two nights finding tutorials, trying to make this system work but with no result. I need your help guys.

Update of ATM System
Well... here's my try. I don't even know where are errors and how many errors are there... I don't know If I'm using y_ini properly. But let's see:

Of course, includes,defines and stuff. And I made some folders in scriptfiles. You can see the path here.
PHP код:
#include <a_samp>
#include <YSI\y_ini>
#define MAX_ATM 100
#define DIALOG_ATM_HOME 6
#define DIALOG_ATM_BALANCE 7
#define DIALOG_ATM_WITHDRAWAL 8
#define ATM_PATH "/WTS/ATM/&i.ini"     //path to the files
enum atmInfo
{
    
atmID,
    
Float:AtmObjXpos,        //position of an object
    
Float:AtmObjYpos,        //position of an object
    
Float:AtmObjZpos,        //position of an object
    
Float:AtmObjZrot,        //rotation of an object
    
atmObjId,                 //object id
    
atmCash,                  //cash in stock
    
Float:AtmPuXpos,       //pickp position
    
Float:AtmPuYpos,       //pickp position
    
Float:AtmPuZpos,       //pickp position
    
atmPuId,                 //pickup id
    
atmPuType,             //pickup type
    
atmMapIconId,         //map icon id
    
Float:AtmCheckXpos,     //checkpoint position (I will use it in some jobs)
    
Float:AtmCheckYpos,     //checkpoint position (I will use it in some jobs)
    
Float:AtmCheckZpos     //checkpoint position (I will use it in some jobs)
}
new 
PickupATM[MAX_ATM];   //I don't know if I need this 
new AtmInfo[MAX_ATM][atmInfo];   //when I've got this 
I have to tell you that I have no idea if I did it right, but I can tell, it's not working. I can't tell you, what the next functions are doing, but I can only tell, what I am expecting of those functions...
And one more thing! I don't know how to set/get/or whatever 'atmid'. HERE WE GO:

This should do the magic with the path to the files... So ATM with ID 1 should have the file '1.ini'.
PHP код:
stock AtmPath(atmid)
{    
    new 
number[3];
    
format(number,sizeof(number),ATM_PATH,atmid);
    return 
number;

And this should load all the data somewhen...
PHP код:
forward LoadAtm_data(atmid,name[],value[]);
public 
LoadAtm_data(atmid,name[],value[])
{
    
INI_Int("ID",AtmInfo[atmid][atmID]); print("Stage 1");
    
INI_Float("ATM Object X position",AtmInfo[atmid][AtmObjXpos]);
    
INI_Float("ATM Object Y position",AtmInfo[atmid][AtmObjYpos]);
    
INI_Float("ATM Object Z position",AtmInfo[atmid][AtmObjZpos]);
    
INI_Float("ATM Object Z rotation",AtmInfo[atmid][AtmObjZrot]);
    
INI_Int("Object ID"AtmInfo[atmid][atmObjId]);
    
INI_Int("Cash",AtmInfo[atmid][atmCash]);
    
INI_Float("ATM Pickup X position",AtmInfo[atmid][AtmPuXpos]);
    
INI_Float("ATM Pickup Y position",AtmInfo[atmid][AtmPuYpos]);
    
INI_Float("ATM Pickup Z position",AtmInfo[atmid][AtmPuZpos]);
    
INI_Int("Pickup ID",AtmInfo[atmid][atmPuId]);
    
INI_Int("Pickup Type",AtmInfo[atmid][atmPuType]);
    
INI_Int("MapIcon ID",AtmInfo[atmid][atmMapIconId]);
    
INI_Float("ATM Checkpoint X position",AtmInfo[atmid][AtmCheckXpos]);
    
INI_Float("ATM Checkpoint Y position",AtmInfo[atmid][AtmCheckYpos]); 
    
INI_Float("ATM Checkpoint Z position",AtmInfo[atmid][AtmCheckZpos]);
    return 
1;

In callback OnGamemodeInit I want to make all the pickups and objects (if the file exists):
PHP код:
public OnGameModeInit()
{
    for(new 
atm 0atm <= MAX_ATMatm++)
    {
        if(
fexist(AtmPath(atm)))
        {
            
PickupATM[atm] = CreatePickup(AtmInfo[atm][atmPuId],AtmInfo[atm][atmPuType],AtmInfo[atm][AtmPuXpos],AtmInfo[atm][AtmPuYpos],AtmInfo[atm][AtmPuZpos]); print("Stage 19");
            
CreateObject(AtmInfo[atm][atmObjId],AtmInfo[atm][AtmObjXpos],AtmInfo[atm][AtmObjYpos],AtmInfo[atm][AtmObjZpos],0.0000000,0.0000000,AtmInfo[atm][AtmObjZrot]); print("Stage 20");
        }
    }
    return 
1;

OnGameModeExit callback will save the CASH information of all ATMs:
PHP код:
public OnGameModeExit()
{
    for(new 
atm 0atm <= MAX_ATMatm++)
    {
        new 
INI:File INI_Open(UserPath(atm));
        
INI_SetTag(File,"data");
        
INI_WriteInt(File,"Cash",AtmInfo[atmID][atmCash]);
        
INI_Close(File);
    }
    return 
1;

And of course we will make Map Icons for all ATMs in OnPlayerConnect callback:
PHP код:
public OnPlayerConnect(playerid)
{
    for(new 
atm 0atm <= MAX_ATMatm++)
    {
        if(
fexist(AtmPath(atm)))
        {
            
SetPlayerMapIcon(playerid,atm,AtmInfo[atm][AtmObjXpos],AtmInfo[atm][AtmObjYpos],AtmInfo[atm][AtmObjZpos],AtmInfo[atm][atmMapIconId],0,MAPICON_LOCAL ); print("Stage 22");
        }
    }
    return 
1;

And now the dialog... But I want the dialog title to be 'ATM - ID' this time.
PHP код:
public OnPlayerPickUpPickup(playeridpickupid)
{
    for(new 
atm 0atm <= MAX_ATMatm++)
    {
        if(
pickupid == PickupATM[atm])
        {
            new 
titlestring[10];
            
format(titlestring,sizeof(titlestring),"ATM - %i"atm);
            
ShowPlayerDialog(playeridDIALOG_ATM_HOMEDIALOG_STYLE_LISTtitlestring"Withdrawal\nAccount Balance""OK""CANCEL");  //this should do it
        
}
    }
    return 
1;

And the last thing to do is to add new if statement with 'AtmInfo[atmid][atmCash]' but I haven't done it yet. I'm sure I'll be able to do that when everything else will work.

I will be thankful if you can help me with this somehow guys.
Reply
#2

Some Ideas? I'd like to have this done so as to continue making this Bank System :/ I'm preparing Banks and stuff...
Reply
#3

Wrong place.

http://forum.sa-mp.com/forumdisplay.php?f=70
Reply
#4

This is not a tutorial I'm asking for serious help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)