30.03.2014, 01:18
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 SystemHey 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:
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;
In callback OnGameModeInit we are creating object (the atm) and a pickup.
PHP код:
public OnGameModeInit()
{
PickupATM = CreatePickup(1212,2,-1981.2, 130.9, 27.25,-1);
CreateObject(2942,-1980.6000000,130.9004000,27.3000000,0.0000000,0.0000000,270.0000000);
return 1;
}
PHP код:
public OnPlayerConnect(playerid)
{
SetPlayerMapIcon(playerid, 5, -1980.6000000,130.9000000,27.3000000, 52, 0, MAPICON_LOCAL);
return 1;
}
PHP код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
if(pickupid == PickupATM)
{
ShowPlayerDialog(playerid, DIALOG_ATM_HOME, DIALOG_STYLE_LIST, "ATM", "Withdrawal\nAccount Balance", "OK", "CANCEL");
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
case DIALOG_ATM_HOME:
{
if(response)
{
switch(listitem)
{
case 0:
{
ShowPlayerDialog(playerid, DIALOG_ATM_WITHDRAWAL, DIALOG_STYLE_INPUT, "ATM - Withdrawal", "{00DCDC}Enter the amount and press OK.", "OK", "CANCEL");
}
case 1:
{
new balancestring[60];
format(balancestring, sizeof(balancestring), "{00DCDC}Account Balance:\n\t{148C0A} $%i", PlayerInfo[playerid][pBank]);
ShowPlayerDialog(playerid, DIALOG_ATM_BALANCE, DIALOG_STYLE_MSGBOX, "ATM - Balance", balancestring, "OK", "");
}
}
}
}
case DIALOG_ATM_BALANCE:
{
if(response)
{
ShowPlayerDialog(playerid, DIALOG_ATM_HOME, DIALOG_STYLE_LIST, "ATM", "Withdrawal\nAccount Balance", "OK", "CANCEL");
}
}
case DIALOG_ATM_WITHDRAWAL:
{
if(!response)
{
ShowPlayerDialog(playerid, DIALOG_ATM_HOME, DIALOG_STYLE_LIST, "ATM", "Withdrawal\nAccount Balance", "OK", "CANCEL");
}
else
{
new input = strval(inputtext);
if (input > 0)
{
if (PlayerInfo[playerid][pBank] >= input)
{
GivePlayerMoney(playerid, input);
PlayerInfo[playerid][pBank] = PlayerInfo[playerid][pBank] - input;
}
else
{
ShowPlayerDialog(playerid, DIALOG_ATM_WITHDRAWAL, DIALOG_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(playerid, DIALOG_ATM_WITHDRAWAL, DIALOG_STYLE_INPUT, "ATM - Withdrawal", ""COL_RED"You've entered Incorrect Value!\n{00DCDC}Enter the amount and press OK.", "OK", "CANCEL");
}
}
}
return 1;
}
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
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;
}
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;
}
PHP код:
public OnGameModeInit()
{
for(new atm = 0; atm <= MAX_ATM; atm++)
{
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;
}
PHP код:
public OnGameModeExit()
{
for(new atm = 0; atm <= MAX_ATM; atm++)
{
new INI:File = INI_Open(UserPath(atm));
INI_SetTag(File,"data");
INI_WriteInt(File,"Cash",AtmInfo[atmID][atmCash]);
INI_Close(File);
}
return 1;
}
PHP код:
public OnPlayerConnect(playerid)
{
for(new atm = 0; atm <= MAX_ATM; atm++)
{
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;
}
PHP код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
for(new atm = 0; atm <= MAX_ATM; atm++)
{
if(pickupid == PickupATM[atm])
{
new titlestring[10];
format(titlestring,sizeof(titlestring),"ATM - %i", atm);
ShowPlayerDialog(playerid, DIALOG_ATM_HOME, DIALOG_STYLE_LIST, titlestring, "Withdrawal\nAccount Balance", "OK", "CANCEL"); //this should do it
}
}
return 1;
}
I will be thankful if you can help me with this somehow guys.