13.04.2013, 04:07
I have a script that does not create a dini file to save stuff for my bank, any ideas?
I would use y_ini but I have no experience with it, if anyone could help me that would be great.
If you know a similar script like this that allows me to make bank locations in game and also requires to be in the bank to use /deposit and /withdraw. then please send me it
current code:
I would use y_ini but I have no experience with it, if anyone could help me that would be great.
If you know a similar script like this that allows me to make bank locations in game and also requires to be in the bank to use /deposit and /withdraw. then please send me it
current code:
PHP код:
//------[Includes]--------
#include <a_samp>
#include <Dini>
#include <sscanf2>
#include <zcmd>
#include <streamer>
//------[Defines]--------
#define PlayerFile "/bank/Accounts"
#define Banks "/bank/Banks/%i.ini"
#define COLOR_RED 0xFF0000AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_GREEN 0x00FF00AA
#define MAX_BANKS 100
//------[Enums]--------
enum PLAYER_MAIN
{
BankCash,
Text3D:bLabel,
CP,
};
//------[Arrays]--------
new pInfo[MAX_PLAYERS][PLAYER_MAIN],
ExitCP,
BankIcon,
cpid[32],
IsInBank[MAX_PLAYERS],
file[100],
Label[128];
new BankInfo[MAX_BANKS][PLAYER_MAIN];
//----------------[Stocks]--------------------
stock GetLastBankID()
{
new count = 0;
for(new i=0; i<MX_BANKS; i++)
{
format(String,sizeof(String),banks,i);
{
count++;
}
}
return count;
}
stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
switch(IsPlayerInAnyVehicle(playerid))
{
case 0: GetPlayerFacingAngle(playerid, a);
case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
return a;
}
stock LoadBanks()
{
new count = 0;
for(new i=0; i<MAX_BANKS; i++)
{
new String[250];
format(String,sizeof(String),Banks,i);
if(dini_Exists(String))
{
BankInfo[i][CP] = CreateDynamicCP(dini_Float(String, "BankX"),dini_Float(String, "BankY"),dini_Float(String, "BankZ"),1.0,dini_Int(String, "World"),dini_Int(String, "Interior"),-1,100.0);
SetPlayerMapIcon(i, 12, dini_Float(String, "BankX"),dini_Float(String, "BankY"),dini_Float(String, "BankZ"), 52, 1);
count++;
}
}
return printf("Total Businesses Loaded: %i",count);
}
stock UnloadBanks()
{
for(new i=0; i<MAX_BANKS; i++)
{
Delete3DTextLabel(BankInfo[i][bLabel]);
DestroyDynamicCP(BankInfo[i][CP]);
RemovePlayerMapIcon(i, BankIcon);
}
return 1;
}
public OnFilterScriptInit()
{
ExitCP = CreateDynamicCP(2304.675537, -16.035686, 26.742187,1,-1,-1,-1,10.0);
LoadBanks();
return 1;
}
public OnFilterScriptExit()
{
UnloadBanks();
return 1;
}
public OnPlayerConnect(playerid)
{
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(file,sizeof(file),PlayerFile,name);
if(!dini_Exists(file))
{
dini_Create(file);
dini_IntSet(file,"BankCash",pInfo[playerid][BankCash]);
}
else if(dini_Exists(file))
{
pInfo[playerid][BankCash] = dini_Int(file,"BankCash");
}
return 1;
}
public OnPlayerEnterDynamicCP(playerid,checkpointid)
{
for(new i = 0;i<MAX_BANKS;i++)
{
if(checkpointid == BankInfo[i][CP])
{
cpid[playerid] = i;
format(file,sizeof(file),"Business/%i.ini",i);
{
SetPlayerPos(playerid,2307.8965,-15.9761,26.7496);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, i);
SetPlayerFacingAngle(playerid, 280);
SendClientMessage(playerid, COLOR_YELLOW, "Welcome to the bank! Type /bankhelp for bank commands!");
IsInBank[playerid] = 1;
}
}
}
if(checkpointid == ExitCP)
{
format(file, sizeof(file), Banks, GetPlayerVirtualWorld(playerid));
SetPlayerPos(playerid, dini_Float(file, "SpawnOutX"), dini_Float(file, "SpawnOutY"), dini_Float(file, "BankZ"));
SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
SetCameraBehindPlayer(playerid);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerInterior(playerid, 0);
IsInBank[playerid] = 0;
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(file,sizeof(file),PlayerFile,name);
dini_IntSet(file,"BankCash",pInfo[playerid][BankCash]);
return 1;
}
CMD:bankhelp(playerid,params[])
{
if(IsInBank[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not inside a bank!");
SendClientMessage(playerid, COLOR_GREEN, "Bank commands: /deposit, /withdraw, /balance, /transfer");
return 1;
}
CMD:deposit(playerid, params[])
{
new amount;
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(file,sizeof(file),PlayerFile,name);
if(IsInBank[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not inside a bank!");
if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_RED, "/deposit [amount]");
if(amount > GetPlayerMoney(playerid)) return SendClientMessage(playerid,COLOR_RED,"You dont have that much cash!");
if(amount <= 0) return SendClientMessage(playerid,COLOR_RED,"You have to add atleast $1 into the bank!");
GivePlayerMoney(playerid,-amount);
pInfo[playerid][BankCash] += amount;
new string[128];
format(string,sizeof(string),"You have deposited: $%d",amount);
SendClientMessage(playerid,COLOR_GREEN,string);
dini_IntSet(file,"BankCash",pInfo[playerid][BankCash]);
format(string,sizeof(string),"Your new bank balance is: $%d",pInfo[playerid][BankCash]);
SendClientMessage(playerid,COLOR_GREEN,string);
return 1;
}
CMD:withdraw(playerid, params[])
{
new amount;
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); format(file,sizeof(file),PlayerFile,name);
if(IsInBank[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not inside a bank!");
if(sscanf(params, "i", amount)) return SendClientMessage(playerid, COLOR_RED, "/withdraw [amount]");
if(amount > pInfo[playerid][BankCash]) return SendClientMessage(playerid,COLOR_RED,"You dont have that much cash in the bank!");
if(amount <= 0) return SendClientMessage(playerid,COLOR_RED,"You have to withdraw atleast $1 from the bank!");
if(pInfo[playerid][BankCash] == 0) return SendClientMessage(playerid,COLOR_RED,"You dont have money in the bank!");
GivePlayerMoney(playerid,amount);
pInfo[playerid][BankCash] -= amount;
new string[128];
format(string,sizeof(string),"You have withdrawn: $%d",amount);
SendClientMessage(playerid,COLOR_GREEN,string);
dini_IntSet(file,"BankCash",pInfo[playerid][BankCash]);
format(string,sizeof(string), "Your new balance is: $%d",pInfo[playerid][BankCash]);
SendClientMessage(playerid,COLOR_GREEN,string);
return 1;
}
CMD:transfer(playerid, params[])
{
new target, amount;
new name[MAX_PLAYER_NAME], TargetName[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); GetPlayerName(target, TargetName, sizeof(name)); format(file,sizeof(file),PlayerFile,name);
if(sscanf(params, "ui", target, amount)) return SendClientMessage(playerid, COLOR_RED, "/transfer [player] [amount]");
if(amount <= 0) return SendClientMessage(playerid,COLOR_RED,"You have to transfer atleast $1!");
if(amount > pInfo[playerid][BankCash]) return SendClientMessage(playerid,COLOR_RED,"You dont have that much cash in the bank!");
if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player is not connected");
if(IsInBank[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not inside a bank!");
new string[128];
pInfo[playerid][BankCash] -= amount;
pInfo[target][BankCash] += amount;
format(string,sizeof(string),"You have transfered $%d to %s's bank account.",amount,TargetName);
SendClientMessage(playerid,COLOR_GREEN,string);
dini_IntSet(file,"BankCash",pInfo[playerid][BankCash]);
format(string,sizeof(string),"Your new balance is $%d",pInfo[playerid][BankCash]);
SendClientMessage(playerid,COLOR_GREEN,string);
format(string,sizeof(string),"%s has deposited $%d into your bank account.",name,amount);
SendClientMessage(target,COLOR_GREEN,string);
format(string,sizeof(string),"Your new bank balance is: $%d",pInfo[target][BankCash]);
SendClientMessage(target,COLOR_GREEN,string);
return 1;
}
CMD:balance(playerid, params[])
{
new string[128];
format(string,sizeof(string),"Your current balance is: Hand: $%d. Bank: $%d. Total: $%d.",GetPlayerMoney(playerid), pInfo[playerid][BankCash], GetPlayerMoney(playerid)+pInfo[playerid][BankCash]);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
CMD:createbank(playerid, params[])
{
new bankid,
Float:x,Float:y,
Float:X,Float:Y,Float:Z,
string[128];
if(!IsPlayerAdmin(playerid)) return 0;
for(new i=0; i<MAX_BANKS; i++)
{
format(file,sizeof(file),Banks,i);
if(!dini_Exists(file))
{
bankid = i;
break;
}
}
format(file,sizeof(file),Banks,bankid);
GetPlayerPos(playerid, X, Y, Z);
GetPosInFrontOfPlayer(playerid, x, y, -2.5);
dini_Create(file);
dini_FloatSet(file, "BankX", X);
dini_FloatSet(file, "BankY", Y);
dini_FloatSet(file, "BankZ", Z);
dini_FloatSet(file, "SpawnOutX", x);
dini_FloatSet(file, "SpawnOutY", y);
dini_FloatSet(file, "SpawnOutZ", Z);
dini_IntSet(file, "World",GetPlayerVirtualWorld(playerid));
dini_IntSet(file, "Interior",GetPlayerInterior(playerid));
format(Label,sizeof(Label),"Bank",bankid);
BankIcon = SetPlayerMapIcon(playerid, 12, X, Y, Z, 52, 1);
BankInfo[bankid][CP] = CreateDynamicCP(X,Y,Z,1.0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),-1,50.0);
BankInfo[bankid][bLabel] = Create3DTextLabel(Label,COLOR_GREEN,X,Y,Z,100.0,GetPlayerVirtualWorld(playerid),1);
format(string,sizeof(string), "Created bank ID: %i.",bankid);
SendClientMessage(playerid, COLOR_GREEN, string);
return 1;
}
CMD:deletebank(playerid, params[])
{
new bankid,
String[148];
if(!IsPlayerAdmin(playerid)) return 0;
if(sscanf(params, "i", bankid)) return SendClientMessage(playerid,COLOR_RED,"Usage: /deletebank [bankid]");
format(file,sizeof(file),Banks,bankid);
if(!dini_Exists(file))return SendClientMessage(playerid,COLOR_RED,"That bankID does not exists.");
format(String,sizeof(String),"You have successfully deleted a bank. ID: %i.",bankid);
SendClientMessage(playerid,COLOR_RED,String);
DestroyDynamicCP(BankInfo[bankid][CP]);
Delete3DTextLabel(BankInfo[bankid][bLabel]);
RemovePlayerMapIcon(playerid, BankIcon);
dini_Remove(file);
return 1;
}