13.08.2012, 19:11
PHP код:
#define FILTERSCRIPT
#include <a_samp>
#include <streamer>
#include <sscanf2>
#include <YSI\y_ini>
#define DIALOG_ATMMENU 1
#define DIALOG_BALANCE 2
#define DIALOG_WITHDRAW 3
#define DIALOG_DEPOSIT 4
#define PATH "/BankAccounts/%s.ini"
enum pInfo
{
pBankAccount,
pAccountdata
}
new PlayerInfo[MAX_PLAYERS][pInfo];
public OnGameModeInit()
{
// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
CreateObject(2942,-2760.10009766,-358.79998779,6.80000019,0.00000000,0.00000000,180.00000000); //object(kmb_atm1) (1)
CreateObject(2942,-2761.00000000,-358.79998779,6.80000019,0.00000000,0.00000000,180.00000000); //object(kmb_atm1) (2)
return 1;
}
forward LoadUser_data(playerid,name[],value[]);
stock GetName(playerid)
{
new Name[MAX_PLAYER_NAME];
if(IsPlayerConnected(playerid))
{
GetPlayerName(playerid, Name, sizeof(Name));
}
return Name;
}
public LoadUser_data(playerid,name[],value[])
{
INI_Int("BankAccount",PlayerInfo[playerid][pBankAccount]);
INI_Int("Datasaved",PlayerInfo[playerid][pAccountdata]);
return 1;
}
stock UserPath(playerid)
{
new string[128],playername[MAX_PLAYER_NAME];
GetPlayerName(playerid,playername,sizeof(playername));
format(string,sizeof(string),PATH,playername);
return string;
}
public OnPlayerDisconnect(playerid, reason)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"BankAccount",PlayerInfo[playerid][pBankAccount]);
INI_WriteInt(File,"Datasaved",PlayerInfo[playerid][pAccountdata]);
INI_Close(File);
return 1;
}
public OnPlayerConnect(playerid)
{
if(PlayerInfo[playerid][pAccountdata] == 0)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"BankAccount",0);
INI_WriteInt(File,"DataSaved",1);
INI_Close(File);
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
}
else
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
}
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/atm", cmdtext, true, 10) == 0)
{
if(IsPlayerInRangeOfPoint(playerid,5.0,-2760.10009766,-358.79998779,6.80000019))
{
new string[256];
format(string, sizeof(string), "%s's Bank Account", GetName(playerid));
ShowPlayerDialog(playerid,DIALOG_ATMMENU,DIALOG_STYLE_LIST, string,"Check balance \nWithdraw\ndeposit", "Select", "Close");
return 1;
}
else
SendClientMessage(playerid,-1,"ERROR: You are not near a atm!");
return 1;
}
return 0;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
new balance[256];
switch( dialogid )
{
case DIALOG_ATMMENU:
{
if(!response)
{
SendClientMessage(playerid, 0xFFFFFF, "SERVER: Selection cancelled.");
}
else
{
switch(listitem)
{
case 0:
{
format(balance, sizeof(balance), """You currently have $%d In your bank account.", PlayerInfo[playerid][pBankAccount]);
ShowPlayerDialog(playerid,DIALOG_BALANCE,DIALOG_STYLE_MSGBOX, "Bank Account Balance", balance, "Back", "");
}
case 1:
{
ShowPlayerDialog(playerid,DIALOG_WITHDRAW,DIALOG_STYLE_INPUT, "Bank Account Withdraw", "How much would you like to withdraw your bank account?", "Withdraw", "");
}
}
}
return 1;
}
case DIALOG_BALANCE:
{
new string[256];
format(string, sizeof(string), "%s's Bank Account", GetName(playerid));
if(response)
{
ShowPlayerDialog(playerid,DIALOG_ATMMENU,DIALOG_STYLE_LIST, string,"Check balance \nWithdraw", "Select", "Close");
}
}
case DIALOG_WITHDRAW:
{
new string[256];
if(response)
{
new type = strval(inputtext);
if(type == 0)
{
ShowPlayerDialog(playerid,DIALOG_WITHDRAW,DIALOG_STYLE_INPUT, "Bank Account Withdraw", "How much would you like to withdraw your bank account?", "Withdraw", "");
}
if(PlayerInfo[playerid][pBankAccount] >= type)
{
PlayerInfo[playerid][pBankAccount] -= type;
GivePlayerMoney(playerid, type);
format(string, sizeof(string), "INFO: You have successfully withdrawn $%d from your bank account.", type);
SendClientMessage(playerid, 0xFFFFFF, string);
}
else SendClientMessage(playerid, 0xFFFFFF, "SERVER: You do not have that much amount in your account");
}
}
case DIALOG_DEPOSIT:
{
new string[256];
if(response)
{
new type = strval(inputtext);
if(type == 0)
{
ShowPlayerDialog(playerid,DIALOG_DEPOSIT,DIALOG_STYLE_INPUT, "Bank Account Deposit", "How much would you like to deposit into your bank account?", "deposit", "");
}
if(GetPlayerMoney(playerid)< type)
{
GivePlayerMoney(playerid,-type);
PlayerInfo[playerid][pBankAccount] += type;
format(string, sizeof(string), "INFO: You have successfully deposited $%d to your bank account.", type);
SendClientMessage(playerid, 0xFFFFFF, string);
}
else SendClientMessage(playerid, 0xFFFFFF, "SERVER: You do not have that much amount in your hand");
}
}
}
return 1;
}
ThAnKs.