rendered paste body// simple banking script
//
// thanks to jerbob 1992
// for bank stuff
// this script needs >> scriptfiles/banks.txt << to exist
#include <a_samp>
#include <core>
#include <float>
#pragma tabsize 0
#define CP_BANK 0
#define CP_BANK_2 2
#define CP_BANK_3 3
#define COLOR_GREY 0xAFAFAFAA //---MAFIA
#define COLOR_GREEN 0x33AA33AA //---NEWS
#define COLOR_RED 0xAA3333AA //--ZOMBI
#define COLOR_YELLOW 0xFFFF00AA //---PIMPS
#define COLOR_WHITE 0xFFFFFFAA //---civillian
#define COLOR_WHITE2 0xFF4080AA //---
#define COLOR_LIGHTBLUE 0x33CCFFAA //---ARMY
#define COLOR_ORANGE 0xFF9900AA //---GANGSTAS
#define BANKFILE "banks.txt"
new bmsg[250];
new File:bfileh;
new b_name[MAX_PLAYER_NAME];
new str_b[256];
forward getCheckpointType(playerID);
forward checkpointUpdate();
forward SendPlayerFormattedText(playerid, const str[], define);
forward SendAllFormattedText(playerid, const str[], define);
forward isPlayerInArea(playerID, Float:data[4]);
new bank[MAX_PLAYERS];
new playerCheckpoint[MAX_PLAYERS];
#define MAX_POINTS 3
new Float:checkCoords[MAX_POINTS][4] = {
{-36.5483,-57.9948, -17.2655,-49.2967}, //BANK
{-37.2183,-91.8006, -14.1099,-74.6845}, //BANK_2
{-34.6621,-31.4095, -2.6782,-25.6232} //BANK_3
};
new Float:checkpoints[MAX_POINTS][3] = {
{-22.2549,-55.6575,1003.5469},
{-23.0664,-90.0882,1003.5469},
{-33.9593,-29.0792,1003.5573}
};
new checkpointType[MAX_POINTS] = {
CP_BANK,
CP_BANK_2,
CP_BANK_3
};
#define MAX_GANGS 20
new gangBank[MAX_GANGS];
new playerGang[MAX_PLAYERS];
main()
{
print("\n--------------------------------------");
print(" Corpse's Simple Banking FilterScript 0.1 ");
print("--------------------------------------\n");
}
//-----
//-----
public isPlayerInArea(playerID, Float:data[4])
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerID, X, Y, Z);
if(X >= data[0] && X <= data[2] && Y >= data[1] && Y <= data[3]) {
return 1;
}
return 0;
}
public checkpointUpdate()
{
for(new i=0; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i)) {
for(new j=0; j < MAX_POINTS; j++) {
if(isPlayerInArea(i, checkCoords[j])) {
if(playerCheckpoint[i]!=j) {
DisablePlayerCheckpoint(i);
SetPlayerCheckpoint(i, checkpoints[j][0],checkpoints[j][1],checkpoints[j][2],2);
playerCheckpoint[i] = j;
}
} else {
if(playerCheckpoint[i]==j) {
DisablePlayerCheckpoint(i);
playerCheckpoint[i] = 999;
}
}
}
}
}
}
//-----
public getCheckpointType(playerID) {
return checkpointType[playerCheckpoint[playerID]];
}
//------
public OnPlayerCommandText(playerid, cmdtext[])
{
new string[256];
new cmd[256];
new moneys, idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/bank", true) == 0 || strcmp(cmd, "/gbank", true) == 0) {
new gang;
if(strcmp(cmd, "/gbank", true) == 0)
gang = 1;
if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
return 1;
}
if(gang && playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
return 1;
}
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /(g)bank [amount]");
return 1;
}
moneys = strval(tmp);
if(moneys < 1) {
SendClientMessage(playerid, COLOR_YELLOW, "Hey what are you trying to pull here.");
return 1;
}
if(GetPlayerMoney(playerid) < moneys) {
moneys = GetPlayerMoney(playerid);
}
GivePlayerMoney(playerid, 0-moneys);
if(gang)
gangBank[playerGang[playerid]]+=moneys;
else
bank[playerid]+=moneys;
if(gang)
format(string, sizeof(string), "You have deposited $%d, your gang's balance is $%d.", moneys, gangBank[playerGang[playerid]]);
else
format(string, sizeof(string), "You have deposited $%d, your current balance is $%d.", moneys, bank[playerid]);
SendClientMessage(playerid, COLOR_YELLOW, string);
GetPlayerName(playerid, b_name, MAX_PLAYER_NAME);
bfileh = fopen(BANKFILE,io_readwrite);
format(bmsg,sizeof(bmsg),"%s $%d\r\n",b_name,bank[playerid]);
fwrite(bfileh,bmsg);
fclose(bfileh);
return 1;
}
//------------------- /withdraw
if(strcmp(cmd, "/withdraw", true) == 0 || strcmp(cmd, "/gwithdraw", true) == 0) {
new gang;
if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
return 1;
}
if(strcmp(cmd, "/gwithdraw", true) == 0)
gang = 1;
if(gang && playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
return 1;
}
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) {
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /(g)withdraw [amount]");
return 1;
}
moneys = strval(tmp);
if(moneys < 1) {
SendClientMessage(playerid, COLOR_YELLOW, "Hey what are you trying to pull here.");
return 1;
}
if(gang) {
if(moneys > gangBank[playerGang[playerid]])
moneys = gangBank[playerGang[playerid]];
} else {
if(moneys > bank[playerid])
moneys = bank[playerid];
}
GivePlayerMoney(playerid, moneys);
if(gang)
gangBank[playerGang[playerid]] -= moneys;
else
bank[playerid] -= moneys;
if(gang)
format(string, sizeof(string), "You have withdrawn $%d, your gang's balance is $%d.", moneys, gangBank[playerGang[playerid]]);
else
format(string, sizeof(string), "You have withdrawn $%d, your current balance is $%d.", moneys, bank[playerid]);
SendClientMessage(playerid, COLOR_YELLOW, string);
GetPlayerName(playerid, b_name, MAX_PLAYER_NAME);
bfileh = fopen(BANKFILE,io_readwrite);
format(bmsg,sizeof(bmsg),"%s $%d\r\n",b_name,bank[playerid]);
fwrite(bfileh,bmsg);
fclose(bfileh);
return 1;
}
//------------------- /balance
if(strcmp(cmd, "/balance", true) == 0 || strcmp(cmd, "/gbalance", true) == 0) {
new gang;
if(strcmp(cmd, "/gbalance", true) == 0)
gang = 1;
if(IsPlayerInCheckpoint(playerid) == 0 || getCheckpointType(playerid) != CP_BANK && getCheckpointType(playerid) != CP_BANK_2 && getCheckpointType(playerid) != CP_BANK_3) {
SendClientMessage(playerid, COLOR_YELLOW, "You must be at a bank area to use this. ATMs are located in convenience stores.");
return 1;
}
if(gang && playerGang[playerid]==0) {
SendClientMessage(playerid, COLOR_RED, "You are not in a gang!");
return 1;
}
if(gang)
format(string, sizeof(string), "Your gang has $%d in the bank.", gangBank[playerGang[playerid]]);
else
GetPlayerName(playerid, b_name, MAX_PLAYER_NAME);
bfileh = fopen(BANKFILE,io_read);
while(fread(bfileh, bmsg)) {
if(strcmp(str_b, b_name, true, strlen(b_name))==0) {
format(bmsg, sizeof(bmsg), "%s you have $%d banked",b_name,bank[playerid]);
SendClientMessage(playerid, COLOR_YELLOW, bmsg);
fclose(bfileh);
}
}
return 1;
}
return 0;
}
//--strtok
public OnPlayerEnterCheckpoint(playerid)
{
// new string[256];
// new ownplayer[MAX_PLAYER_NAME];
switch(getCheckpointType(playerid))
{
case CP_BANK: {
SendClientMessage(playerid, COLOR_YELLOW, "You are at an ATM. To store money use '/bank amount', to withdraw");
SendClientMessage(playerid, COLOR_YELLOW, "money use '/withdraw amount', and '/balance' to see your balance.");
}
case CP_BANK_2: {
SendClientMessage(playerid, COLOR_YELLOW, "You are at an ATM. To store money use '/bank amount', to withdraw");
SendClientMessage(playerid, COLOR_YELLOW, "money use '/withdraw amount', and '/balance' to see your balance.");
}
case CP_BANK_3: {
SendClientMessage(playerid, COLOR_YELLOW, "You are at an ATM. To store money use '/bank amount', to withdraw");
SendClientMessage(playerid, COLOR_YELLOW, "money use '/withdraw amount', and '/balance' to see your balance.");
}
}
}
//--
//--
public OnFilterScriptInit()
{
SetTimer("checkpointUpdate", 1100, 1);
print("\n--------------------------------------");
print(" corpse's simple banking filterscript 0.1 ");
print("--------------------------------------\n");
return 1;
}
//---
public SendPlayerFormattedText(playerid, const str[], define)
{
new tmpbuf[256];
format(tmpbuf, sizeof(tmpbuf), str, define);
SendClientMessage(playerid, 0xFFFF00AA, tmpbuf);
}
public SendAllFormattedText(playerid, const str[], define)
{
new tmpbuf[256];
format(tmpbuf, sizeof(tmpbuf), str, define);
SendClientMessageToAll(0xFFFF00AA, tmpbuf);
}
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
//--
public OnFilterScriptExit()
{
return 1;
}