Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * YLLERON'S BANK SYSTEM
- * 2011 (C)
- * You can't present this script as your, or
- * make version and public it without my perm.
- *
- * Version: 1.6
- * Cheers Y
- */
- #include <a_samp>
- #tryinclude <dini>
- // Defines ---------------------------------------------------------------------
- //------------------------------------------------------------------------------
- #define MAX_BANK 50
- //-----------------------------|
- #define YBANK_FILE_PATH "/ybank/users/%s.ini"
- #define c_YBANK:: c_YBANK_
- #define YBANK:: YBANK_
- #define PDATA:: PDATA_
- //-----------------------------|
- #define YDIALOG ShowPlayerDialog
- //-----------------------------|
- #define INPUT DIALOG_STYLE_INPUT
- #define LIST DIALOG_STYLE_LIST
- #define BOX DIALOG_STYLE_MSGBOX
- //-----------------------------|
- #define SCRIPT:%0(%1) \
- forward %0(%1); \
- public %0(%1)
- #define PRIVATE:%0(%1) \
- stock %0(%1)
- //-----------------------------|
- #define YD_DEPOSITACCOUNT 100
- #define YD_ACCOUNTSTATUS 101
- #define YD_TRANSACTAMOUT 102
- #define YD_DRAWACCOUNT 103
- #define YD_TRANSACTID 104
- #define YD_CHANGEPASS 105
- #define YD_GETPASS 106
- #define YD_REGIST 107
- #define YD_DELACC 108
- #define YD_BASIC 109
- #define YD_LOGIN 110
- //-----------------------------|
- #define C_RED 0xFF0000AA
- //-----------------------------|
- enum e_ybank
- {
- Float:Float_X,
- Float:Float_Y,
- Float:Float_Z,
- NameBank[50],
- IdDialog,
- IdPickup,
- Cash
- }
- enum e_pData
- {
- TransactName[32],
- TransactID,
- bool:Log
- }
- new YBANK::[MAX_BANK][e_ybank];
- new YBANK::MAX_COUNT = 0;
- static PDATA::[MAX_PLAYERS][e_pData];
- SCRIPT: yOnDialogResponse ( playerid, dialogid, response, listitem, inputtext[] )
- {
- for ( new i=0;i<YBANK::MAX_COUNT;i++ ) {
- if ( dialogid == YBANK::[i][IdDialog] ) {
- new nb[ 50 ];
- format ( nb,50,"Bank %s", YBANK::[i][NameBank] );
- switch ( listitem ) {
- case 0:
- {
- new _Str1 [ 80 ];
- format (_Str1, sizeof (_Str1), "YBANK: On your account is $%i", ybank_Money(playerid) );
- YDIALOG (playerid, YD_ACCOUNTSTATUS, BOX, nb, _Str1, "OK", "");
- }
- case 1:
- {
- YDIALOG ( playerid, YD_DRAWACCOUNT, INPUT, nb, "YBANK: Please type amout to draw", "OK", "" );
- }
- case 2:
- {
- YDIALOG ( playerid, YD_DEPOSITACCOUNT, INPUT, nb, "YBANK: Please type amout to deposit", "OK", "" );
- }
- case 3:
- {
- YDIALOG ( playerid, YD_TRANSACTID, INPUT, nb, "YBANK: Please type id of given player", "OK", "" );
- }
- case 4:
- {
- YDIALOG ( playerid, YD_DELACC, BOX, nb, "YBANK: Are you sure?", "Yes", "No" );
- }
- case 5:
- {
- YDIALOG ( playerid, YD_CHANGEPASS, INPUT, nb, "YBANK: Please type your new password", "OK", "Cancel" );
- }
- case 6:
- {
- return true;
- }
- }
- }
- }
- if ( dialogid == YD_BASIC ) {
- if ( response ) return true;
- }
- if ( dialogid == YD_REGIST ) {
- if ( response ) {
- YDIALOG ( playerid, YD_GETPASS, INPUT, "Please fill following textfield", "Type your password to you account", "Submit", "" );
- }
- }
- if ( dialogid == YD_LOGIN ) {
- if ( response ) {
- if (!strlen(inputtext)) return YDIALOG ( playerid, YD_LOGIN, INPUT, "Error", "Welcome!\nPlease fill following field with your account password", "Login", "Cancel" );
- else
- {
- new pass[20];
- strcat( pass, dini_Get(fPath(playerid), "BankPass"), 20 );
- if (phash(inputtext) == strval(pass)) {
- PDATA::[playerid][Log] = true;
- SendClientMessage ( playerid, C_RED, "YBANK: You've been successfully logged in your account" );
- }
- }
- }
- }
- if ( dialogid == YD_GETPASS ) {
- if ( response ) {
- if (!strlen(inputtext) || strlen(inputtext) > 12) return SendClientMessage ( playerid, C_RED, "YBANK: Password lenght must be in 4-12 range" );
- else
- {
- dini_Create(fPath(playerid));
- // Password
- dini_IntSet(fPath(playerid), "BankPass", phash(inputtext));
- // Bank cash
- dini_IntSet(fPath(playerid), "BankCash", 0);
- SendClientMessage ( playerid, C_RED, "YBANK: You've been successfully registered in bank" );
- }
- }
- }
- if ( dialogid == YD_DRAWACCOUNT ) {
- if ( response ) {
- if ( !strlen ( inputtext ) ) return YDIALOG ( playerid, YD_DRAWACCOUNT, INPUT, "Bank" , "YBANK: Please type amout to draw", "OK", "" );
- if ( ybank_Money( playerid ) < strval(inputtext) ) return SendClientMessage ( playerid, C_RED, "YBANK: You don't have so much money on your account!" );
- else
- {
- new pDraw = strval(inputtext);
- GivePlayerMoney( playerid, pDraw );
- ybank_Delete ( playerid, pDraw );
- new _Str [ 90 ];
- format ( _Str, sizeof (_Str), "Cash in bank: $%i\nYou draw: $%i", ybank_Money ( playerid ), pDraw );
- YDIALOG ( playerid, YD_BASIC, BOX, "Information", _Str, "OK", "" );
- }
- }
- }
- if ( dialogid == YD_DEPOSITACCOUNT ) {
- if ( response ) {
- if ( !strlen ( inputtext ) ) return YDIALOG ( playerid, YD_DEPOSITACCOUNT, INPUT, "Error", "YBANK: Please type amout to deposit", "OK", "" );
- if ( GetPlayerMoney ( playerid ) < strval( inputtext ) ) return SendClientMessage ( playerid, C_RED, "YBANK: You don't have amout, you typed" );
- else
- {
- new pDeposit = strval( inputtext );
- GivePlayerMoney ( playerid, -pDeposit);
- ybank_Add ( playerid, pDeposit );
- new _Str [ 90 ];
- format ( _Str, sizeof (_Str), "Cash in bank: $%i\nYou deposit: $%i", ybank_Money ( playerid ), pDeposit );
- YDIALOG ( playerid, YD_BASIC, BOX, "Information", _Str, "OK", "" );
- }
- }
- }
- if ( dialogid == YD_TRANSACTID ) {
- if ( response ) {
- if ( !strlen ( inputtext ) ) return YDIALOG ( playerid, YD_TRANSACTID, INPUT, "Error", "YBANK: Please type id/name of given player", "OK", "Cancel" );
- if (IsNumeric(inputtext))
- {
- new targetid = strval(inputtext);
- if ( IsPlayerConnected(targetid) ) {
- PDATA::[playerid][TransactID] = targetid;
- }
- }
- else {
- strcat( PDATA::[playerid][TransactName], inputtext, 32 );
- YDIALOG ( playerid, YD_TRANSACTAMOUT, BOX, "Bank", "YBANK: Type amout cash to transact", "OK", "Cancel" );
- return true;
- }
- }
- }
- if ( dialogid == YD_TRANSACTAMOUT ) {
- if ( response ) {
- new amout = strval(inputtext);
- if ( !strlen ( inputtext ) ) return YDIALOG ( playerid, YD_TRANSACTAMOUT, BOX, "Error", "YBANK: Type amout cash to transact", "OK", "Cancel" );
- if ( !IsNumeric ( inputtext ) ) return YDIALOG ( playerid, YD_TRANSACTAMOUT, BOX, "Error", "YBANK: Type amout cash to transact", "OK", "Cancel" );
- else
- {
- new targetid = PDATA::[playerid][TransactID];
- if ( IsPlayerConnected (targetid) ) {
- ybank_Add ( targetid, amout );
- ybank_Delete ( playerid, amout );
- }
- else {
- if ( dini_Exists(fPath(getId(inputtext))) ) {
- ybank_Add ( getId(inputtext), amout );
- ybank_Delete ( playerid, amout );
- }
- }
- new _Str [ 90 ];
- format ( _Str, sizeof (_Str), "Cash in bank: $%i\nYou transact: $%i (ID: %i)", ybank_Money ( playerid ), amout, targetid );
- YDIALOG ( playerid, YD_BASIC, BOX, "Information", _Str, "OK", "" );
- }
- }
- }
- if ( dialogid == YD_DELACC ) {
- if ( response ) {
- fremove(fPath(playerid));
- SendClientMessage(playerid, C_RED, "YBANK: Your account has been deleted!");
- }
- }
- if ( dialogid == YD_CHANGEPASS ) {
- if ( response ) {
- if ( dini_Exists (fPath(playerid)) ) {
- dini_IntSet(fPath(playerid), "BankPass", phash(inputtext));
- }
- }
- }
- return true;
- }
- SCRIPT: yOnPlayerPickUpPickup ( playerid, pickupid )
- {
- for ( new i=0;i<YBANK::MAX_COUNT;i++ ) {
- if ( pickupid == YBANK::[i][IdPickup] ) {
- YBANK::[i][IdDialog] = i;
- //-----------------------------------------
- if (!dini_Exists(fPath(playerid)))
- {
- new str[ 100 ];
- format( str, sizeof(str), "Welcome %s", getName(playerid));
- YDIALOG ( playerid, YD_REGIST, BOX, str, "Do you want create account in our bank?", "Yes", "No, thanks" );
- }
- else
- {
- if (!PDATA::[playerid][Log])
- {
- YDIALOG ( playerid, YD_LOGIN, INPUT, "Login", "Welcome!\nPlease fill following field with your account password", "Login", "Cancel" );
- }
- else
- {
- new nb[ 50 ];
- format(nb,50,"Bank %s", YBANK::[i][NameBank]);
- YDIALOG ( playerid, YBANK::[i][IdDialog], LIST, nb, "Account status\nDraw from account\nDeposit to account\nTransact cash\nDelete Account\nCancel", "OK", "");
- }
- }
- }
- }
- return true;
- }
- SCRIPT: CreateYBank( Float:X, Float:Y, Float:Z, bankname[] )
- {
- if ( YBANK::MAX_COUNT <= MAX_BANK ) {
- YBANK::MAX_COUNT++;
- new bankid = YBANK::MAX_COUNT;
- YBANK::[bankid][Float_X] = X;
- YBANK::[bankid][Float_Y] = Y;
- YBANK::[bankid][Float_Z] = Z;
- strmid( YBANK::[bankid][NameBank], bankname, 0, strlen( bankname ), 50 );
- CreateYBankPickup( bankid, X, Y, Z);
- printf ( "YBANK - Banks created %i", YBANK::MAX_COUNT );
- }
- else {
- printf ( "YBANK says: BANK limit exceed! Banks created %i", YBANK::MAX_COUNT );
- return false;
- }
- return true;
- }
- SCRIPT: CreateYBankPickup( bankid, Float:X, Float:Y, Float:Z)
- {
- YBANK::[bankid][IdPickup] = CreatePickup( 1318, 2, X, Y, Z, 0 );
- return true;
- }
- ybank_SetMoney( playerid, cash )
- {
- if ( dini_Exists(fPath(playerid) ) )
- return dini_IntSet( fPath(playerid), "BankCash", cash );
- return 1;
- }
- ybank_Delete( playerid, cash )
- {
- if ( dini_Exists(fPath(playerid) ) )
- return dini_IntSet( fPath(playerid), "BankCash", dini_Int( fPath(playerid), "BankCash")-cash );
- return 1;
- }
- ybank_Money( playerid )
- {
- if ( dini_Exists(fPath(playerid) ) )
- return dini_Int(fPath(playerid), "BankCash");
- return 1;
- }
- ybank_Add( playerid, cash )
- {
- if ( dini_Exists(fPath(playerid) ) )
- return dini_IntSet( fPath(playerid), "BankCash", dini_Int(fPath(playerid), "BankCash" )+cash );
- return 1;
- }
- getName(playerid)
- {
- new n[32];
- GetPlayerName( playerid, n, sizeof(n));
- return n;
- }
- getId(pname[])
- {
- for ( new i=0;i<MAX_PLAYERS;i++ ) {
- if ( !strcmp(pname, getName(i), true) ) {
- return i;
- }
- }
- return -1;
- }
- fPath(playerid)
- {
- new fp[70];
- format(fp, sizeof(fp), YBANK_FILE_PATH, getName(playerid));
- return fp;
- }
- stock IsNumeric (str[])
- {
- for (new i=0;i<strlen(str);i++) {
- if (str[i] >= 0 && str[i] <= 9 ) return true;
- else return false;
- }
- return -1;
- }
- stock phash (buf[])
- {
- new length = strlen( buf );
- new s1 = 1;
- new s2 = 0;
- new n;
- for ( n=0; n<length; n++ ) {
- s1 = ( s1 + buf[n] ) % 65521;
- s2 = ( s2 + s1 ) % 65521;
- }
- return ( s2 << 16 ) + s1;
- }
Add Comment
Please, Sign In to add comment