Raised This Month: $51 Target: $400
 12% 

Bank System Nvault/SQL Support


Post New Thread Reply   
 
Thread Tools Display Modes
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 04-28-2022 , 05:45   Re: Bank System Nvault/SQL Support
Reply With Quote #51

Hello again! I have a question, what changes should I made to avoid interference If I wanted to use 2 of this plugin at the same time, thanks!

btw I solved the last problem by creating a new table, the plugin works great!
sigerman is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-28-2022 , 09:34   Re: Bank System Nvault/SQL Support
Reply With Quote #52

Quote:
Originally Posted by sigerman View Post
Hello again! I have a question, what changes should I made to avoid interference If I wanted to use 2 of this plugin at the same time, thanks!
Change the table name of nvault and sql also change the command of the menu and check line 11/12
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 04-28-2022 , 13:22   Re: Bank System Nvault/SQL Support
Reply With Quote #53

Quote:
Originally Posted by Supremache View Post
Change the table name of nvault and sql also change the command of the menu and check line 11/12
I don't know how to: change the command of the menu

The rest I've done It with no problem!
sigerman is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-28-2022 , 13:48   Re: Bank System Nvault/SQL Support
Reply With Quote #54

Quote:
Originally Posted by sigerman View Post
I don't know how to: change the command of the menu

The rest I've done It with no problem!
if you want to use this plugin with more currencies then there is two ways to do that:
1. Edit the full code of plugin
2. Use the plugin two time with different data for exmaple..
  • Change the name of the cofing file line 41 "new const g_iFile[ ] = "BankSystem.ini";"
  • Change the data in the confing file like
    • "SQL_TABLE = bank"
    • "NVAULT_DATABASE = Bank"
    • "BANK_MENU = say /bank , say_team /bank" // This is the command of the menu
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 04-28-2022 at 13:49.
Supremache is offline
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 04-28-2022 , 15:18   Re: Bank System Nvault/SQL Support
Reply With Quote #55

I've done everything exactly as you told me, the first plugin in plugin.ini is the one that works fine, the second one works works with the same currency as the first one. (I configured the second plugin to work with another currency, If I use the plugin alone, It works fine, but If I use them together It happens what I already told you)

And I have to report also, when I try to donate to someone, all the players I select to donate, the plugin responds with a: this player does not exist ☹️

Last edited by sigerman; 04-28-2022 at 15:55. Reason: Clarifying
sigerman is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-28-2022 , 19:54   Re: Bank System Nvault/SQL Support
Reply With Quote #56

Quote:
I've done everything exactly as you told me, the first plugin in plugin.ini is the one that works fine, the second one works works with the same currency as the first one. (I configured the second plugin to work with another currency, If I use the plugin alone, It works fine, but If I use them together It happens what I already told you)
I edited the code to use it in two currencies so you need to add another command for another currency for example:
BANK_MENU = say /bank, say_team /bank, say /banktwo , say_team /banktwo
/bank = first currency
/banktwo = sec currency

Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <nvault>
#include <sqlx>
#include <cromchat>

#define get_cash2(%1) cs_get_user_armor(%1)
#define set_cash2(%1,%2) cs_set_user_armor(%1, %2, CS_ARMOR_VESTHELM) 
#define get_cash(%1) cs_get_user_money(%1)
#define set_cash(%1,%2) cs_set_user_money(%1, %2) 
		
#if !defined client_disconnected
	#define client_disconnected client_disconnect
#endif

#if !defined MAX_PLAYERS
	const MAX_PLAYERS = 32
#endif

#if !defined MAX_MENU_LENGTH
	const MAX_MENU_LENGTH = 512
#endif

#if !defined MAX_NAME_LENGTH
	const MAX_NAME_LENGTH = 32
#endif

#if !defined MAX_AUTHID_LENGTH
	const MAX_AUTHID_LENGTH = 64
#endif

#if !defined MAX_IP_LENGTH
	const MAX_IP_LENGTH = 16
#endif
  
const MAX_QUERY_LENGTH = 256;
const MAX_CASH_LENGTH = 16;

new const g_iFile[ ] = "BankSystem.ini";
new const Version[ ] = "2.0";

enum _:SaveTypes
{
	NICKNAME,
	IP,
	STEAMID
}

enum _:SaveMethods
{
	Nvault,
	MySQL,
	SQLite
}

enum eSettings
{
	PREFIX_CHAT[ MAX_NAME_LENGTH ],
	SQL_HOST[ MAX_NAME_LENGTH ],
	SQL_USER[ MAX_NAME_LENGTH ],
	SQL_PASS[ MAX_NAME_LENGTH ],
	SQL_DATABASE[ MAX_NAME_LENGTH ],
	SQL_TABLE[ MAX_NAME_LENGTH ],
	NVAULT_DATABASE[ MAX_NAME_LENGTH ],
	USE_SQL,
	SAVE_TYPE,
	MAX_CASH,
	MAX_CASH_SAVE,
	MENU_DONATE_ACCESS,
	MENU_RESET_ACCESS,
}

enum PlayerData
{
	SaveInfo[ MAX_AUTHID_LENGTH ],
	Bank,
	Bank2,
	Donate,
	bool:BotOrHLTV
}

new g_iPlayer[ MAX_PLAYERS + 1 ][ PlayerData ],
	g_iSettings[ eSettings ],
	bool:g_bBankOption[ MAX_PLAYERS + 1 ],
	g_iFUserNameChanged,
	Handle:g_SQLTuple,
	g_szSQLError[ MAX_QUERY_LENGTH ],
	g_iVault;

public plugin_init( ) 
{
	register_plugin( "Bank System", Version, "Supremache" );
	register_cvar( "BankSystem", Version, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED );
	
	register_clcmd( "EnterAmount", "@OnPlayerDonations" );
	register_clcmd( "DepositCash", "@OnDepositCash" );
	register_clcmd( "TakeCash", "@OnWithdrawCash" );
	
	register_event( "SayText", "OnSayText", "a", "2=#Cstrike_Name_Change" )

	ReadFile( );
	
	switch( g_iSettings[ USE_SQL ] )
	{
		case Nvault:
		{
			if ( ( g_iVault = nvault_open( g_iSettings[ NVAULT_DATABASE ] ) ) == INVALID_HANDLE )
				set_fail_state("BANK: Failed to open the vault.");
		}
		case MySQL, SQLite: 
		{
			if( g_iSettings[ USE_SQL ] == SQLite )
				SQL_SetAffinity( "sqlite" );
				
			g_SQLTuple = SQL_MakeDbTuple( g_iSettings[ SQL_HOST ], g_iSettings[ SQL_USER ], g_iSettings[ SQL_PASS ], g_iSettings[ SQL_DATABASE ] );
			    
			new szQuery[ MAX_QUERY_LENGTH ], Handle:SQLConnection, iErrorCode;
			SQLConnection = SQL_Connect( g_SQLTuple, iErrorCode, g_szSQLError, charsmax( g_szSQLError ) );
			    
			if( SQLConnection == Empty_Handle )
				set_fail_state( g_szSQLError );
	
			formatex( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS `%s` (`Player` VARCHAR(%i) NOT NULL,\
			`Cash` INT(%i) NOT NULL, `Cash2` INT(%i) NOT NULL, PRIMARY KEY(Player));", g_iSettings[ SQL_TABLE ], MAX_AUTHID_LENGTH, MAX_CASH_LENGTH, MAX_CASH_LENGTH );
			
			RunQuery( SQLConnection, szQuery, g_szSQLError, charsmax( g_szSQLError ) );
		}
	}
}

public OnSayText( iMsg, iDestination, iEntity )
{
	g_iFUserNameChanged = register_forward(FM_ClientUserInfoChanged, "OnNameChange", 1 )
}

public OnNameChange( id )
{
	if( !is_user_connected( id ) )
	{
		return;
	}

	new szName[ MAX_NAME_LENGTH ]
	get_user_name( id, szName, charsmax( szName ) )

	if( g_iSettings[ SAVE_TYPE ] == NICKNAME )
	{
		ReadData( id );
		copy( g_iPlayer[ id ][ SaveInfo ], charsmax( g_iPlayer[ ][ SaveInfo ] ), szName )

		if( g_iSettings[ USE_SQL ] != Nvault )
		{
			ResetData( id )
		}

		ReadData( id, false );
	}

	unregister_forward( FM_ClientUserInfoChanged, g_iFUserNameChanged , 1 )
}

public client_connect( id )
{
	if ( !( g_iPlayer[ id ][ BotOrHLTV ] = bool:( is_user_bot( id ) || is_user_hltv( id ) ) ) )
	{
		ResetData( id )
		
		switch( g_iSettings[ SAVE_TYPE ] )
		{
			case NICKNAME: get_user_name( id, g_iPlayer[ id ][ SaveInfo ], charsmax( g_iPlayer[ ][ SaveInfo ] ) )
			case IP:       get_user_ip( id, g_iPlayer[ id ][ SaveInfo ], charsmax( g_iPlayer[ ][ SaveInfo ]), 1 )
			case STEAMID:  get_user_authid( id, g_iPlayer[ id ][ SaveInfo ], charsmax( g_iPlayer[ ][ SaveInfo ] ) )
		}
		
		ReadData( id, false );
	}
}

public client_disconnected( id )
{
	if ( !g_iPlayer[ id ][ BotOrHLTV ] )
	{
		ReadData( id );
	}
}

@BankMenu( id )
{
	static szCommand[ 16 ];
	read_argv( 1, szCommand, charsmax( szCommand ) )
	
	if( szCommand[ 5 ] )
		g_bBankOption[ id ] = true;
	else
		g_bBankOption[ id ] = false;

	new iMenu = menu_create( "\yBank System: \r[Protected]", "@BankHandler" );
	
	menu_additem( iMenu, "Deposit" );
	menu_additem( iMenu, "Deposit All^n" );
	menu_additem( iMenu, "Withdraw" );
	menu_additem( iMenu, "Withdraw All^n" );
	menu_additem( iMenu, "Bank balance" );
	menu_additem( iMenu, "Donate" );
	menu_additem( iMenu, "Reset Bank" );
	
	menu_display(id, iMenu)
	return PLUGIN_HANDLED;
}

@BankHandler( id, iMenu, iItem ) 
{
	if( iItem != MENU_EXIT ) 
	{
		switch(iItem) 
		{
			case 0: 
			{
				client_cmd( id, "messagemode DepositCash" );
				set_hudmessage( 255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1 );
				show_hudmessage(id, " Type how much you want to deposit." );
			}
			case 1: @OnDepositAllCash( id );
			case 2: 
			{
				client_cmd( id, "messagemode TakeCash" );
				set_hudmessage( 255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1 );
				show_hudmessage( id, "Type how much you want to withdraw." );
			}
			case 3: @OnWithdrawAllCash( id );
			case 4: CC_SendMessage( id, "Your Cash is:^4 %d", g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] );
			case 5: @DonateMenu( id );
			case 6: @ResetMenu( id );
		}
	}
	menu_destroy( iMenu );
	return PLUGIN_HANDLED;
}

@DonateMenu( id )
{		
	if( ~get_user_flags( id ) & g_iSettings[ MENU_DONATE_ACCESS ] )
	{
		CC_SendMessage(id, "You don't have access to this command.");
		return PLUGIN_HANDLED;
	}
		
	new szPlayers[ MAX_PLAYERS ], iNum, szID[ MAX_PLAYERS ], szName[ MAX_NAME_LENGTH ];
			
	new iMenu = menu_create( "Players List:", "@DonateHandler" );
	get_players( szPlayers, iNum, "ch" );
	
	for( new iPlayer, i; i < iNum; i++ )
	{
		if( ( iPlayer = szPlayers[ i ] ) != id )
		{
			num_to_str( iPlayer, szID, charsmax( szID ) );
			get_user_name( iPlayer, szName, charsmax( szName ) );
			menu_additem( iMenu, szName, szID )
		}
	}
	menu_display( id, iMenu );
	return PLUGIN_HANDLED;
}

@DonateHandler( id, iMenu, iItem ) 
{
	if(iItem != MENU_EXIT) 
	{
		new szData[ 10 ], iUnused;
		menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax( szData ), .callback = iUnused )
		
		g_iPlayer[ id ][ Donate ] = find_player( "k", str_to_num( szData ) ); 

		if ( ! g_iPlayer[ id ][ Donate ] )
		{
			CC_SendMessage( id,"This player does not exist." );
			return PLUGIN_HANDLED;
		}
		
		client_cmd(id, "messagemode EnterAmount");
		
		set_hudmessage( 255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1 );
		show_hudmessage( id, "Type how much you want to give." );
	}
	menu_destroy(iMenu);
	return PLUGIN_HANDLED;
}

@OnPlayerDonations( id )
{
	new szValue[ MAX_CASH_LENGTH ], szPlayerName[ MAX_NAME_LENGTH ], szTargetName[ MAX_NAME_LENGTH ];
	read_argv( 1, szValue, charsmax( szValue ) );
	
	new iValue = str_to_num( szValue ), iCash = g_bBankOption[ id ] ? get_cash2( id ) : get_cash( id ), iPlayer = g_iPlayer[ id ][ Donate ]; 

	if( iCash < iValue || iValue <= 0 )
	{
		CC_SendMessage( id,"You do not have enough cash or invalid value." );
		return PLUGIN_CONTINUE;
	}
		
	get_user_name( id, szPlayerName, charsmax( szPlayerName ) );
	get_user_name( iPlayer, szTargetName, charsmax( szTargetName ) );
	
	if( g_bBankOption[ id ] )
	{
		set_cash2( id, iCash - iValue )
		set_cash2( iPlayer, g_bBankOption[ id ] ? get_cash2( iPlayer ) : get_cash( iPlayer ) + iValue )
	}
	else
	{
		set_cash( id, iCash - iValue )
		set_cash( iPlayer, g_bBankOption[ id ] ? get_cash2( iPlayer ) : get_cash( iPlayer ) + iValue )
	}

	CC_SendMessage(0,"Player^4 %s^1 donated^4 $%d^1 for^4 %s.", szPlayerName, iValue, szTargetName );
	client_cmd(iPlayer, "spk ^"items/9mmclip1.wav^"")
	ReadData( id );
	
	return PLUGIN_HANDLED;
} 

@ResetMenu( id )
{		
	if( ~get_user_flags( id ) & g_iSettings[ MENU_RESET_ACCESS ] )
	{
		CC_SendMessage(id, "You don't have access to this command.");
		return PLUGIN_HANDLED;
	}
		
	new szPlayers[ MAX_PLAYERS ], iNum, szID[ MAX_PLAYERS ], szName[ MAX_NAME_LENGTH ];
			
	new iMenu = menu_create( "Players List:", "@ResetHandler" );
	get_players( szPlayers, iNum, "ch" );
	
	for( new iPlayer, i; i < iNum; i++ )
	{
		if( ( iPlayer = szPlayers[ i ] ) != id )
		{
			num_to_str( iPlayer, szID, charsmax( szID ) );
			get_user_name( iPlayer, szName, charsmax( szName ) );
			menu_additem( iMenu, szName, szID )
		}
	}
	menu_display( id, iMenu );
	return PLUGIN_HANDLED;
}

@ResetHandler( id, iMenu, iItem ) 
{
	if(iItem != MENU_EXIT) 
	{
		new szData[ 10 ], iUnused, szPlayerName[ MAX_NAME_LENGTH ], szTargetName[ MAX_NAME_LENGTH ];
		menu_item_getinfo( iMenu, iItem, iUnused, szData, charsmax( szData ), .callback = iUnused )
		
		new iPlayer = find_player( "k", str_to_num( szData ) ); 
		
		if( !iPlayer )
		{
			CC_SendMessage( id,"This player does not exist." );
			return PLUGIN_HANDLED;
		}
		
		get_user_name( id, szPlayerName, charsmax( szPlayerName ) );
		get_user_name( iPlayer, szTargetName, charsmax( szTargetName ) );
	
		g_iPlayer[ iPlayer ][ g_bBankOption[ id ] ? Bank2 : Bank ] = 0;
		CC_SendMessage( 0,"[ADMIN]^4 %s:^1 reset bank of^4 %s.", szPlayerName, szTargetName );
		ReadData( id );
	}
	menu_destroy(iMenu);
	return PLUGIN_HANDLED;
}

@OnDepositAllCash( id ) 
{
	new iCash = clamp( g_bBankOption[ id ] ? get_cash2( id ) : get_cash( id ), 0, g_iSettings[ MAX_CASH_SAVE ] );
	
	if( iCash <= 0)
	{
		CC_SendMessage(id,"You do not have enough cash or invalid value.");
		return PLUGIN_CONTINUE;
	}
	
	if( g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] > g_iSettings[ MAX_CASH_SAVE ] )
	{
		CC_SendMessage( id,"Your bank is full." );
		return PLUGIN_CONTINUE;
	}

	g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] += iCash;
	if( g_bBankOption[ id ] )
		set_cash2(id, iCash - get_cash2( id ) );
	else
		set_cash(id, iCash - get_cash( id ) );
			
	CC_SendMessage( id,"You have deposit^4 %i", iCash );
	ReadData( id );
	return PLUGIN_HANDLED;
}

@OnWithdrawAllCash( id )
{
	new iCash = g_bBankOption[ id ] ? get_cash2( id ) : get_cash( id );
	
	if( g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] <= 0 )
	{
		CC_SendMessage(id,"You do not have enough cash or invalid value.");
		return PLUGIN_CONTINUE;
	}
	
	new iMax = max( iCash, g_iSettings[ MAX_CASH ] );
	
	if( g_iSettings[ MAX_CASH ] && g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] > iMax )
	{
		if( g_bBankOption[ id ] )
			set_cash2(id, iCash + iMax );
		else
			set_cash(id, iCash + iMax );
			
		g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] -= iMax;
		CC_SendMessage( id,"You have withdraw^4 %i", iMax );
	}
	else
	{
		CC_SendMessage( id,"You have withdraw^4 %i", g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] );
		if( g_bBankOption[ id ] )
			set_cash2( id, iCash + g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] );
		else
			set_cash( id, iCash + g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] );
			
		g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] = 0;
	}
	
	ReadData( id );

	return PLUGIN_HANDLED;
}

@OnDepositCash( id ) 
{
	new szValue[ MAX_CASH_LENGTH ];
	read_argv( 1, szValue, charsmax( szValue ) );
	new iValue = clamp( str_to_num( szValue ), 0, g_iSettings[ MAX_CASH_SAVE ] ), iCash =  g_bBankOption[ id ] ? get_cash2( id ) : get_cash( id );
	
	if( iCash < iValue || iValue <= 0)
	{
		CC_SendMessage(id,"You do not have enough cash or invalid value.");
		return PLUGIN_CONTINUE;
	}

	if( g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] > g_iSettings[ MAX_CASH_SAVE ] )
	{
		CC_SendMessage( id,"Your bank is full." );
		return PLUGIN_CONTINUE;
	}
	
	g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] += iValue;
	if( g_bBankOption[ id ] )
		set_cash2( id, iCash - iValue );
	else
		set_cash( id, iCash - iValue );

	CC_SendMessage(id,"You have deposit^4 %i", iValue );
	ReadData( id );
	
	return PLUGIN_HANDLED;
}

@OnWithdrawCash( id )
{
	new szValue[ MAX_CASH_LENGTH ];
	read_argv( 1, szValue, charsmax( szValue ) );
	new iValue = g_iSettings[ MAX_CASH ] ? clamp( str_to_num( szValue ), 0, g_iSettings[ MAX_CASH ] ) : str_to_num( szValue )
	new iCash = g_bBankOption[ id ] ? get_cash2( id ) : get_cash( id );
	
	if( g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] < iValue || iValue <= 0 )
	{
		CC_SendMessage(id,"You do not have enough cash or invalid value.");
		return PLUGIN_CONTINUE;
	}
	
	g_iPlayer[ id ][ g_bBankOption[ id ] ? Bank2 : Bank ] -= iValue;
	if( g_bBankOption[ id ] )
		set_cash2( id, iCash + iValue );
	else
		set_cash( id, iCash + iValue );

	CC_SendMessage( id,"You have withdraw^4 %i", iValue );
	ReadData( id );
	
	return PLUGIN_HANDLED;
}

ReadFile( )
{
	new szConfings[ 128 ], szFile[ 128 ];
	get_configsdir( szConfings, charsmax( szConfings ) )
	formatex( szFile, charsmax( szFile ), "%s/%s", szConfings, g_iFile );
	
	new iFile = fopen( szFile, "rt" );
	
	if( iFile )
	{
		new szData[ 256 ], szKey[ 32 ], szValue[ 128 ];
			
		while( fgets( iFile, szData, charsmax( szData ) ) )
		{
			trim( szData );
			
			switch( szData[ 0 ] )
			{
				case EOS, '#', ';', '/', '[': continue;
				default:
				{
					strtok( szData, szKey, charsmax( szKey ), szValue, charsmax( szValue ), '=' );
					trim( szKey ); trim( szValue );
                            
					if( !szValue[ 0 ] || !szKey[ 0 ] )
						continue;
						
					if( equal( szKey, "BANK_MENU" ) )
					{
						while( szValue[ 0 ] != 0 && strtok( szValue, szKey, charsmax( szKey ), szValue, charsmax( szValue ), ',' ) )
						{
							trim( szKey ); trim( szValue );
							register_clcmd( szKey, "@BankMenu" );
						}
					}
					else if( equal( szKey, "PREFIX_CHAT" ) )
					{
						copy( g_iSettings[ PREFIX_CHAT ], charsmax( g_iSettings[ PREFIX_CHAT ] ), szValue );
					}
					else if(equal(szKey, "SQL_HOST"))
					{
						copy( g_iSettings[SQL_HOST], charsmax( g_iSettings[SQL_HOST] ), szValue );
					}
					else if(equal(szKey, "SQL_USER"))
					{
						copy( g_iSettings[ SQL_USER ], charsmax( g_iSettings[ SQL_USER ] ), szValue );
					}
					else if(equal(szKey, "SQL_PASS"))
					{
						copy( g_iSettings[ SQL_PASS ], charsmax( g_iSettings[ SQL_PASS ] ), szValue );
					}
					else if(equal(szKey, "SQL_DATABASE"))
					{
						copy( g_iSettings[ SQL_DATABASE ], charsmax( g_iSettings[ SQL_DATABASE ] ), szValue );
					}
					else if(equal(szKey, "SQL_TABLE"))
					{
						copy( g_iSettings[ SQL_TABLE ], charsmax( g_iSettings[ SQL_TABLE ] ), szValue );
					}
					else if(equal(szKey, "NVAULT_DATABASE"))
					{
						copy( g_iSettings[ NVAULT_DATABASE ], charsmax( g_iSettings[ NVAULT_DATABASE ] ), szValue );
					}
					else if( equal(szKey, "SAVE_METHOD") )
					{
						g_iSettings[ USE_SQL ] = clamp( str_to_num( szValue ), Nvault, SQLite );
					}
					else if( equal( szKey, "SAVE_TYPE" ) )
					{
						g_iSettings[ SAVE_TYPE ] = clamp( str_to_num( szValue ), NICKNAME, STEAMID );
					}
					else if( equal( szKey, "MAX_CASH" ) )
					{
						g_iSettings[ MAX_CASH ] = str_to_num( szValue );
					}
					else if( equal( szKey, "MAX_CASH_SAVE" ) )
					{
						g_iSettings[ MAX_CASH_SAVE ] = str_to_num( szValue );
					}
					else if( equal( szKey, "MENU_RESET_ACCESS" ) )
					{
						g_iSettings[ MENU_RESET_ACCESS ] = szValue[ 0 ] == '0' ? ADMIN_ALL : read_flags( szValue );
					}
					else if( equal( szKey, "MENU_DONATE_ACCESS" ) )
					{
						g_iSettings[ MENU_DONATE_ACCESS ] = szValue[ 0 ] == '0' ? ADMIN_ALL : read_flags( szValue );
					}
				}
			}
		}
		fclose( iFile )
	}
	else log_amx( "File %s does not exists", szFile )
	
	CC_SetPrefix( g_iSettings[ PREFIX_CHAT ] );
}

ReadData( id, bool:bSave = true )
{
	new szQuery[ MAX_QUERY_LENGTH ], szValue[ MAX_CASH_LENGTH ];

	if( bSave )
	{
		switch( g_iSettings[ USE_SQL ] )
		{
			case Nvault:
			{
				formatex( szValue, charsmax( szValue ), "%i %i", g_iPlayer[ id ][ Bank ], g_iPlayer[ id ][ Bank2 ] )
				nvault_set( g_iVault, g_iPlayer[ id ][ SaveInfo ], szValue );
			}
			case MySQL, SQLite:
			{
				formatex( szQuery , charsmax( szQuery ), "REPLACE INTO `%s` (`Player`,`Cash`,`Cash2`) VALUES ('%s','%i','%i');",\
				g_iSettings[ SQL_TABLE ], g_iPlayer[ id ][ SaveInfo ], g_iPlayer[ id ][ Bank ], g_iPlayer[ id ][ Bank2 ] );
				SQL_ThreadQuery( g_SQLTuple, "QueryHandle", szQuery );
			}
		}
	}
	else
	{
		switch( g_iSettings[ USE_SQL ] )
		{
			case Nvault:
			{
				new szBank[ MAX_CASH_LENGTH ], szBank2[ MAX_CASH_LENGTH ];
				nvault_get( g_iVault, g_iPlayer[ id ][ SaveInfo ], szValue, charsmax( szValue ) );
				parse( szValue, szBank, charsmax( szBank ), szBank2, charsmax( szBank2 ) )
				g_iPlayer[ id ][ Bank ] = str_to_num( szBank )
				g_iPlayer[ id ][ Bank2 ] = str_to_num( szBank2 )
			}
			case MySQL, SQLite:
			{
				formatex( szQuery , charsmax( szQuery ), "SELECT * FROM `%s` WHERE Player = '%s';",\
				g_iSettings[ SQL_TABLE ], g_iPlayer[ id ][ SaveInfo ] );
				new szData[ 1 ]; szData[ 0 ] = id
				SQL_ThreadQuery( g_SQLTuple, "QueryHandle", szQuery, szData, sizeof( szData ) );
			}
		}
	}
}

RunQuery( Handle:SQLConnection, const szQuery[ ], szSQLError[ ], iErrLen )
{
	new Handle:iQuery = SQL_PrepareQuery( SQLConnection , szQuery );
	
	if( !SQL_Execute( iQuery ) )
	{
		SQL_QueryError( iQuery, szSQLError, iErrLen );
		set_fail_state( szSQLError );
	}
	
	SQL_FreeHandle( iQuery );
}

public QueryHandle( iFailState, Handle:iQuery, const szError[ ], iErrCode, const szData[ ], iDataSize )
{
	switch( iFailState )
	{
		case TQUERY_CONNECT_FAILED: { log_amx( "[SQL Error] Connection failed (%i): %s", iErrCode, szError ); return; }
		case TQUERY_QUERY_FAILED: { log_amx( "[SQL Error] Query failed (%i): %s", iErrCode, szError ); return; }
	}
	
	static id; id = szData[ 0 ];
	if( SQL_NumResults( iQuery ) )
	{
		g_iPlayer[ id ][ Bank ] = SQL_ReadResult( iQuery , SQL_FieldNameToNum( iQuery, "Cash" ) );
		g_iPlayer[ id ][ Bank2 ] = SQL_ReadResult( iQuery , SQL_FieldNameToNum( iQuery, "Cash2" ) );
	}
} 

ResetData( const id )
{
	g_iPlayer[ id ][ Bank ] = 0;
	g_iPlayer[ id ][ Bank2 ] = 0;
	g_iPlayer[ id ][ Donate ] = 0;
	g_iPlayer[ id ][ BotOrHLTV ] = false;
}

public plugin_natives( )
{
	register_library("Bank");
	register_native("get_user_bank", "_get_user_bank")
	register_native("set_user_bank", "_set_user_bank")
	register_native("get_user_bank2", "_get_user_bank2")
	register_native("set_user_bank2", "_set_user_bank2")
}

public _get_user_bank2( iPlugin , iParams )
{
	return g_iPlayer[ get_param( 1 ) ][ Bank2 ]
}

public _set_user_bank2( iPlugin , iParams )
{
	new id = get_param( 1 )
	g_iPlayer[ id ][ Bank2 ] = get_param( 2 );
	ReadData( id );
}

public _get_user_bank( iPlugin , iParams )
{
	return g_iPlayer[ get_param( 1 ) ][ Bank ]
}

public _set_user_bank( iPlugin , iParams )
{
	new id = get_param( 1 )
	g_iPlayer[ id ][ Bank ] = get_param( 2 );
	ReadData( id );
}


public plugin_end( )
{
	if( g_iSettings[ USE_SQL ] )
	{
		SQL_FreeHandle( g_SQLTuple );
	}
	else
	{
		nvault_close( g_iVault );
	}
}
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-03-2022 at 03:32.
Supremache is offline
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 04-29-2022 , 12:54   Re: Bank System Nvault/SQL Support
Reply With Quote #57

Yesterday I started to test the edition you did to use 2 times the plugin. Until now I could not make It work, but I've just started testing, In the following days I will go back to you and post a response here.

And the donation thing, I've modified the plugin with your edition, I deleted the part you posted on the plugin [Remove these lines]. Then I tested in my servers and It's still saying the players does not exist

Last edited by sigerman; 04-29-2022 at 12:55.
sigerman is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 04-29-2022 , 22:13   Re: Bank System Nvault/SQL Support
Reply With Quote #58

Quote:
Yesterday I started to test the edition you did to use 2 times the plugin. Until now I could not make It work, but I've just started testing, In the following days I will go back to you and post a response here.
Have you used this edition? If so, it works with two currencies, I tested it
To use this plugin, you need to replace this line in the config file that starts with "BANK_MENU" to
BANK_MENU = say /bank, say_team /bank, say /banktwo , say_team /banktwo

First currency:
Code:
#define get_cash(%1) cs_get_user_money(%1)
#define set_cash(%1,%2) cs_set_user_money(%1, %2)
  • Command that show the first bank menu:
    • /bank // You can not change it

Sec currency:
Code:
#define get_cash2(%1) cs_get_user_money(%1)
#define set_cash2(%1,%2) cs_set_user_money(%1, %2)
  • Command that show the sec bank menu:
    • /banktwo // You can change it to whatever you want but it must have a bank name

Quote:
And the donation thing, I've modified the plugin with your edition, I deleted the part you posted on the plugin [Remove these lines]. Then I tested in my servers and It's still saying the players does not exist
Show me what you did! Because I already fixed it in the modified plugin and you are saying "I used the modified plugin"
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
sigerman
Senior Member
Join Date: Aug 2013
Location: Argentina, Bs.As.
Old 05-02-2022 , 22:01   Re: Bank System Nvault/SQL Support
Reply With Quote #59

Quote:
Originally Posted by Supremache View Post
Have you used this edition? If so, it works with two currencies, I tested it
To use this plugin, you need to replace this line in the config file that starts with "BANK_MENU" to
BANK_MENU = say /bank, say_team /bank, say /banktwo , say_team /banktwo

First currency:
Code:
#define get_cash(%1) cs_get_user_money(%1)
#define set_cash(%1,%2) cs_set_user_money(%1, %2)
  • Command that show the first bank menu:
    • /bank // You can not change it

Sec currency:
Code:
#define get_cash2(%1) cs_get_user_money(%1)
#define set_cash2(%1,%2) cs_set_user_money(%1, %2)
  • Command that show the sec bank menu:
    • /banktwo // You can change it to whatever you want but it must have a bank name


Show me what you did! Because I already fixed it in the modified plugin and you are saying "I used the modified plugin"
Oh, sorry for the delay, I've been trying to test before posting. The plugin you modified works fine, but It seems It does not save the values, I use mysql databases for both currencies, one table for bank and another for bank two. I use ocixcrom rank system in banktwo.

Quote:
Show me what you did! Because I already fixed it in the modified plugin and you are saying "I used the modified plugin"
I downloaded the plugin in the first page https://forums.alliedmods.net/attach...5&d=1650049174 then I modifie It with the code you provided [In the code I deleted the part: Remove these lines]

PHP Code:
@OnPlayerDonationsid )
{
    new 
szValueMAX_CASH_LENGTH ], szPlayerNameMAX_NAME_LENGTH ], szTargetNameMAX_NAME_LENGTH ];
    
read_argv1szValuecharsmaxszValue ) );
    
    new 
iValue str_to_numszValue ), iCash get_cashid ), iPlayer g_iPlayerid ][ Donate ]; 

    if( 
iCash iValue || iValue <= )
    {
        
CC_SendMessageid,"You do not have enough cash or invalid value." );
        return 
PLUGIN_CONTINUE;
    }
    
    
get_user_nameidszPlayerNamecharsmaxszPlayerName ) );
    
get_user_nameiPlayerszTargetNamecharsmaxszTargetName ) );
    
    
set_cashidiCash iValue )
    
set_cashiPlayerget_cashiPlayer ) + iValue )
    
    
CC_SendMessage(0,"Player^4 %s^1 donated^4 $%d^1 for^4 %s."szPlayerNameiValueszTargetName );
    
client_cmd(iPlayer"spk ^"items/9mmclip1.wav^"")
    
ReadDataid );
    
    return 
PLUGIN_HANDLED;

All the plugin:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <nvault>
#include <sqlx>
#include <cromchat>

/* You can make this plugin work with Ammo Packs,
 * BaseBuilder Credits, JBPacks, Points and more */

#define get_cash(%1) cs_get_user_money(%1)
#define set_cash(%1,%2) cs_set_user_money(%1, %2) 

#if !defined client_disconnected
    #define client_disconnected client_disconnect
#endif

#if !defined MAX_PLAYERS
    
const MAX_PLAYERS 32
#endif

#if !defined MAX_MENU_LENGTH
    
const MAX_MENU_LENGTH 512
#endif

#if !defined MAX_NAME_LENGTH
    
const MAX_NAME_LENGTH 32
#endif

#if !defined MAX_AUTHID_LENGTH
    
const MAX_AUTHID_LENGTH 64
#endif

#if !defined MAX_IP_LENGTH
    
const MAX_IP_LENGTH 16
#endif
  
const MAX_QUERY_LENGTH 256;
const 
MAX_CASH_LENGTH 16;

new const 
g_iFile[ ] = "BankSystem.ini";
new const 
Version[ ] = "2.0";

enum _:SaveTypes
{
    
NICKNAME,
    
IP,
    
STEAMID
}

enum _:SaveMethods
{
    
Nvault,
    
MySQL,
    
SQLite
}

enum eSettings
{
    
PREFIX_CHATMAX_NAME_LENGTH ],
    
SQL_HOSTMAX_NAME_LENGTH ],
    
SQL_USERMAX_NAME_LENGTH ],
    
SQL_PASSMAX_NAME_LENGTH ],
    
SQL_DATABASEMAX_NAME_LENGTH ],
    
SQL_TABLEMAX_NAME_LENGTH ],
    
NVAULT_DATABASEMAX_NAME_LENGTH ],
    
USE_SQL,
    
SAVE_TYPE,
    
MAX_CASH,
    
MAX_CASH_SAVE,
    
MENU_DONATE_ACCESS,
    
MENU_RESET_ACCESS,
}

enum PlayerData
{
    
SaveInfoMAX_AUTHID_LENGTH ],
    
Bank,
    
Donate,
    
bool:BotOrHLTV
}

new 
g_iPlayerMAX_PLAYERS ][ PlayerData ],
    
g_iSettingseSettings ],
    
g_iFUserNameChanged,
    
Handle:g_SQLTuple,
    
g_szSQLErrorMAX_QUERY_LENGTH ],
    
g_iVault;
    
public 
plugin_init( ) 
{
    
register_plugin"Bank System"Version"Supremache" );
    
register_cvar"BankSystem"VersionFCVAR_SERVER FCVAR_SPONLY FCVAR_UNLOGGED );
    
    
register_clcmd"EnterAmount""@OnPlayerDonations" );
    
register_clcmd"DepositCash""@OnDepositCash" );
    
register_clcmd"TakeCash""@OnWithdrawCash" );
    
    
register_event"SayText""OnSayText""a""2=#Cstrike_Name_Change" )
    
    
ReadFile( );
    
    switch( 
g_iSettingsUSE_SQL ] )
    {
        case 
Nvault:
        {
            if ( ( 
g_iVault nvault_openg_iSettingsNVAULT_DATABASE ] ) ) == INVALID_HANDLE )
                
set_fail_state("BANK: Failed to open the vault.");
        }
        case 
MySQLSQLite
        {
            if( 
g_iSettingsUSE_SQL ] == SQLite )
                
SQL_SetAffinity"sqlite" );
                
            
g_SQLTuple SQL_MakeDbTupleg_iSettingsSQL_HOST ], g_iSettingsSQL_USER ], g_iSettingsSQL_PASS ], g_iSettingsSQL_DATABASE ] );
                
            new 
szQueryMAX_QUERY_LENGTH ], Handle:SQLConnectioniErrorCode;
            
SQLConnection SQL_Connectg_SQLTupleiErrorCodeg_szSQLErrorcharsmaxg_szSQLError ) );
                
            if( 
SQLConnection == Empty_Handle )
                
set_fail_stateg_szSQLError );
    
            
formatexszQuerycharsmaxszQuery ), "CREATE TABLE IF NOT EXISTS `%s` (`Player` VARCHAR(%i) NOT NULL,\
            `Cash` INT(%i) NOT NULL, PRIMARY KEY(Player));"
g_iSettingsSQL_TABLE ], MAX_AUTHID_LENGTHMAX_CASH_LENGTH );
            
            
RunQuerySQLConnectionszQueryg_szSQLErrorcharsmaxg_szSQLError ) );
        }
    }
}

public 
OnSayTextiMsgiDestinationiEntity )
{
    
g_iFUserNameChanged register_forward(FM_ClientUserInfoChanged"OnNameChange")
}

public 
OnNameChangeid )
{
    if( !
is_user_connectedid ) )
    {
        return;
    }

    new 
szNameMAX_NAME_LENGTH ]
    
get_user_nameidszNamecharsmaxszName ) )

    if( 
g_iSettingsSAVE_TYPE ] == NICKNAME )
    {
        
ReadDataid );
        
copyg_iPlayerid ][ SaveInfo ], charsmaxg_iPlayer[ ][ SaveInfo ] ), szName )

        if( 
g_iSettingsUSE_SQL ] != Nvault )
        {
            
ResetDataid )
        }

        
ReadDataidfalse );
    }

    
unregister_forwardFM_ClientUserInfoChangedg_iFUserNameChanged )
}

public 
client_connectid )
{
    if ( !( 
g_iPlayerid ][ BotOrHLTV ] = bool:( is_user_botid ) || is_user_hltvid ) ) ) )
    {
        
ResetDataid )
        
        switch( 
g_iSettingsSAVE_TYPE ] )
        {
            case 
NICKNAMEget_user_nameidg_iPlayerid ][ SaveInfo ], charsmaxg_iPlayer[ ][ SaveInfo ] ) )
            case 
IP:       get_user_ipidg_iPlayerid ][ SaveInfo ], charsmaxg_iPlayer[ ][ SaveInfo ]), )
            case 
STEAMID:  get_user_authididg_iPlayerid ][ SaveInfo ], charsmaxg_iPlayer[ ][ SaveInfo ] ) )
        }
        
        
ReadDataidfalse );
    }
}

public 
client_disconnectedid )
{
    if ( !
g_iPlayerid ][ BotOrHLTV ] )
    {
        
ReadDataid );
    }
}

@
BankMenuid )
{
    new 
iMenu menu_create"\yBank System: \r[Protected]""@BankHandler" );
    
    
menu_additemiMenu"Deposit" );
    
menu_additemiMenu"Deposit All^n" );
    
menu_additemiMenu"Withdraw" );
    
menu_additemiMenu"Withdraw All^n" );
    
menu_additemiMenu"Bank balance" );
    
menu_additemiMenu"Donate" );
    
menu_additemiMenu"Reset Bank" );
    
    
menu_display(idiMenu)
    return 
PLUGIN_HANDLED;
}

@
BankHandleridiMenuiItem 
{
    if( 
iItem != MENU_EXIT 
    {
        switch(
iItem
        {
            case 
0
            {
                
client_cmdid"messagemode DepositCash" );
                
set_hudmessage255255850.010.1820.56.00.050.05, -);
                
show_hudmessage(id" Type how much you want to deposit." );
            }
            case 
1: @OnDepositAllCashid );
            case 
2
            {
                
client_cmdid"messagemode TakeCash" );
                
set_hudmessage255255850.010.1820.56.00.050.05, -);
                
show_hudmessageid"Type how much you want to withdraw." );
            }
            case 
3: @OnWithdrawAllCashid );
            case 
4CC_SendMessageid,"Your Cash is:^4 %d"g_iPlayerid ][ Bank ] );
            case 
5: @DonateMenuid );
            case 
6: @ResetMenuid );
        }
    }
    
menu_destroyiMenu );
    return 
PLUGIN_HANDLED;
}

@
DonateMenuid )
{        
    if( ~
get_user_flagsid ) & g_iSettingsMENU_DONATE_ACCESS ] )
    {
        
CC_SendMessage(id"You don't have access to this command.");
        return 
PLUGIN_HANDLED;
    }
        
    new 
szPlayersMAX_PLAYERS ], iNumszIDMAX_PLAYERS ], szNameMAX_NAME_LENGTH ];
            
    new 
iMenu menu_create"Players List:""@DonateHandler" );
    
get_playersszPlayersiNum"ch" );
    
    for( new 
iPlayeriiNumi++ )
    {
        if( ( 
iPlayer szPlayers] ) != id )
        {
            
num_to_striPlayerszIDcharsmaxszID ) );
            
get_user_nameiPlayerszNamecharsmaxszName ) );
            
menu_additemiMenuszNameszID )
        }
    }
    
menu_displayidiMenu );
    return 
PLUGIN_HANDLED;
}

@
DonateHandleridiMenuiItem 
{
    if(
iItem != MENU_EXIT
    {
        new 
szData10 ], iUnused;
        
menu_item_getinfoiMenuiItemiUnusedszDatacharsmaxszData ), .callback iUnused )
        
        
g_iPlayerid ][ Donate ] = find_player"k"str_to_numszData ) ); 

        if ( ! 
g_iPlayerid ][ Donate ] )
        {
            
CC_SendMessageid,"This player does not exist." );
            return 
PLUGIN_HANDLED;
        }
        
        
client_cmd(id"messagemode EnterAmount");
        
        
set_hudmessage255255850.010.1820.56.00.050.05, -);
        
show_hudmessageid"Type how much you want to give." );
    }
    
menu_destroy(iMenu);
    return 
PLUGIN_HANDLED;
}

@
OnPlayerDonationsid )
{
    new 
szValueMAX_CASH_LENGTH ], szPlayerNameMAX_NAME_LENGTH ], szTargetNameMAX_NAME_LENGTH ];
    
read_argv1szValuecharsmaxszValue ) );
    
    new 
iValue str_to_numszValue ), iCash get_cashid ), iPlayer g_iPlayerid ][ Donate ]; 

    if( 
iCash iValue || iValue <= )
    {
        
CC_SendMessageid,"You do not have enough cash or invalid value." );
        return 
PLUGIN_CONTINUE;
    }
    
    
get_user_nameidszPlayerNamecharsmaxszPlayerName ) );
    
get_user_nameiPlayerszTargetNamecharsmaxszTargetName ) );
    
    
set_cashidiCash iValue )
    
set_cashiPlayerget_cashiPlayer ) + iValue )
    
    
CC_SendMessage(0,"Player^4 %s^1 donated^4 $%d^1 for^4 %s."szPlayerNameiValueszTargetName );
    
client_cmd(iPlayer"spk ^"items/9mmclip1.wav^"")
    
ReadDataid );
    
    return 
PLUGIN_HANDLED;


@
ResetMenuid )
{        
    if( ~
get_user_flagsid ) & g_iSettingsMENU_RESET_ACCESS ] )
    {
        
CC_SendMessage(id"You don't have access to this command.");
        return 
PLUGIN_HANDLED;
    }
        
    new 
szPlayersMAX_PLAYERS ], iNumszIDMAX_PLAYERS ], szNameMAX_NAME_LENGTH ];
            
    new 
iMenu menu_create"Players List:""@ResetHandler" );
    
get_playersszPlayersiNum"ch" );
    
    for( new 
iPlayeriiNumi++ )
    {
        if( ( 
iPlayer szPlayers] ) != id )
        {
            
num_to_striPlayerszIDcharsmaxszID ) );
            
get_user_nameiPlayerszNamecharsmaxszName ) );
            
menu_additemiMenuszNameszID )
        }
    }
    
menu_displayidiMenu );
    return 
PLUGIN_HANDLED;
}

@
ResetHandleridiMenuiItem 
{
    if(
iItem != MENU_EXIT
    {
        new 
szData10 ], iUnusedszPlayerNameMAX_NAME_LENGTH ], szTargetNameMAX_NAME_LENGTH ];
        
menu_item_getinfoiMenuiItemiUnusedszDatacharsmaxszData ), .callback iUnused )
        
        new 
iPlayer find_player"k"str_to_numszData ) ); 
        
        if( !
iPlayer )
        {
            
CC_SendMessageid,"This player does not exist." );
            return 
PLUGIN_HANDLED;
        }
        
        
get_user_nameidszPlayerNamecharsmaxszPlayerName ) );
        
get_user_nameiPlayerszTargetNamecharsmaxszTargetName ) );
    
        
g_iPlayeriPlayer ][ Bank ] = 0;
        
CC_SendMessage0,"[ADMIN]^4 %s:^1 reset bank of^4 %s."szPlayerNameszTargetName );
        
ReadDataid );
    }
    
menu_destroy(iMenu);
    return 
PLUGIN_HANDLED;
}

@
OnDepositAllCashid 
{
    new 
iCash clampget_cashid ), 0g_iSettingsMAX_CASH_SAVE ] );
    
    if( 
iCash <= 0)
    {
        
CC_SendMessage(id,"You do not have enough cash or invalid value.");
        return 
PLUGIN_CONTINUE;
    }
    
    if( 
g_iPlayerid ][ Bank ] > g_iSettingsMAX_CASH_SAVE ] )
    {
        
CC_SendMessageid,"Your bank is full." );
        return 
PLUGIN_CONTINUE;
    }

    
g_iPlayerid ][ Bank ] += iCash;
    
set_cash(idiCash get_cashid ) );
    
CC_SendMessageid,"You have deposit^4 %i"iCash );
    
ReadDataid );
    return 
PLUGIN_HANDLED;
}

@
OnWithdrawAllCashid )
{
    new 
iCash get_cashid );
    
    if( 
g_iPlayerid ][ Bank ] <= )
    {
        
CC_SendMessage(id,"You do not have enough cash or invalid value.");
        return 
PLUGIN_CONTINUE;
    }
    
    new 
iMax maxiCashg_iSettingsMAX_CASH ] );
    
    if( 
g_iSettingsMAX_CASH ] && g_iPlayerid ][ Bank ] > iMax )
    {
        
set_cash(idiCash iMax );
        
g_iPlayerid ][ Bank ] -= iMax;
        
CC_SendMessageid,"You have withdraw^4 %i"iMax );
    }
    else
    {
        
CC_SendMessageid,"You have withdraw^4 %i"g_iPlayerid ][ Bank ] );
        
set_cashidiCash g_iPlayerid ][ Bank ] );
        
g_iPlayerid ][ Bank ] = 0;
    }
    
    
ReadDataid );

    return 
PLUGIN_HANDLED;
}

@
OnDepositCashid 
{
    new 
szValueMAX_CASH_LENGTH ];
    
read_argv1szValuecharsmaxszValue ) );
    new 
iValue clampstr_to_numszValue ), 0g_iSettingsMAX_CASH_SAVE ] ), iCash get_cashid );
    
    if( 
iCash iValue || iValue <= 0)
    {
        
CC_SendMessage(id,"You do not have enough cash or invalid value.");
        return 
PLUGIN_CONTINUE;
    }

    if( 
g_iPlayerid ][ Bank ] > g_iSettingsMAX_CASH_SAVE ] )
    {
        
CC_SendMessageid,"Your bank is full." );
        return 
PLUGIN_CONTINUE;
    }
    
    
g_iPlayerid ][ Bank ] += iValue;
    
set_cashidiCash iValue );
    
CC_SendMessage(id,"You have deposit^4 %i"iValue );
    
ReadDataid );
    
    return 
PLUGIN_HANDLED;
}

@
OnWithdrawCashid )
{
    new 
szValueMAX_CASH_LENGTH ];
    
read_argv1szValuecharsmaxszValue ) );
    new 
iValue g_iSettingsMAX_CASH ] ? clampstr_to_numszValue ), 0g_iSettingsMAX_CASH ] ) : str_to_numszValue )
    new 
iCash get_cashid );
    
    if( 
g_iPlayerid ][ Bank ] < iValue || iValue <= )
    {
        
CC_SendMessage(id,"You do not have enough cash or invalid value.");
        return 
PLUGIN_CONTINUE;
    }
    
    
g_iPlayerid ][ Bank ] -= iValue;
    
set_cashidiCash iValue );
    
CC_SendMessageid,"You have withdraw^4 %i"iValue );
    
ReadDataid );
    
    return 
PLUGIN_HANDLED;
}

ReadFile( )
{
    new 
szConfings128 ], szFile128 ];
    
get_configsdirszConfingscharsmaxszConfings ) )
    
formatexszFilecharsmaxszFile ), "%s/%s"szConfingsg_iFile );
    
    new 
iFile fopenszFile"rt" );
    
    if( 
iFile )
    {
        new 
szData256 ], szKey32 ], szValue128 ];
            
        while( 
fgetsiFileszDatacharsmaxszData ) ) )
        {
            
trimszData );
            
            switch( 
szData] )
            {
                case 
EOS'#'';''/''[': continue;
                default:
                {
                    
strtokszDataszKeycharsmaxszKey ), szValuecharsmaxszValue ), '=' );
                    
trimszKey ); trimszValue );
                            
                    if( !
szValue] || !szKey] )
                        continue;
                        
                    if( 
equalszKey"BANK_MENU" ) )
                    {
                        while( 
szValue] != && strtokszValueszKeycharsmaxszKey ), szValuecharsmaxszValue ), ',' ) )
                        {
                            
trimszKey ); trimszValue );
                            
register_clcmdszKey"@BankMenu" );
                        }
                    }
                    else if( 
equalszKey"PREFIX_CHAT" ) )
                    {
                        
copyg_iSettingsPREFIX_CHAT ], charsmaxg_iSettingsPREFIX_CHAT ] ), szValue );
                    }
                    else if(
equal(szKey"SQL_HOST"))
                    {
                        
copyg_iSettings[SQL_HOST], charsmaxg_iSettings[SQL_HOST] ), szValue );
                    }
                    else if(
equal(szKey"SQL_USER"))
                    {
                        
copyg_iSettingsSQL_USER ], charsmaxg_iSettingsSQL_USER ] ), szValue );
                    }
                    else if(
equal(szKey"SQL_PASS"))
                    {
                        
copyg_iSettingsSQL_PASS ], charsmaxg_iSettingsSQL_PASS ] ), szValue );
                    }
                    else if(
equal(szKey"SQL_DATABASE"))
                    {
                        
copyg_iSettingsSQL_DATABASE ], charsmaxg_iSettingsSQL_DATABASE ] ), szValue );
                    }
                    else if(
equal(szKey"SQL_TABLE"))
                    {
                        
copyg_iSettingsSQL_TABLE ], charsmaxg_iSettingsSQL_TABLE ] ), szValue );
                    }
                    else if(
equal(szKey"NVAULT_DATABASE"))
                    {
                        
copyg_iSettingsNVAULT_DATABASE ], charsmaxg_iSettingsNVAULT_DATABASE ] ), szValue );
                    }
                    else if( 
equal(szKey"SAVE_METHOD") )
                    {
                        
g_iSettingsUSE_SQL ] = clampstr_to_numszValue ), NvaultSQLite );
                    }
                    else if( 
equalszKey"SAVE_TYPE" ) )
                    {
                        
g_iSettingsSAVE_TYPE ] = clampstr_to_numszValue ), NICKNAMESTEAMID );
                    }
                    else if( 
equalszKey"MAX_CASH" ) )
                    {
                        
g_iSettingsMAX_CASH ] = str_to_numszValue );
                    }
                    else if( 
equalszKey"MAX_CASH_SAVE" ) )
                    {
                        
g_iSettingsMAX_CASH_SAVE ] = str_to_numszValue );
                    }
                    else if( 
equalszKey"MENU_RESET_ACCESS" ) )
                    {
                        
g_iSettingsMENU_RESET_ACCESS ] = szValue] == '0' ADMIN_ALL read_flagsszValue );
                    }
                    else if( 
equalszKey"MENU_DONATE_ACCESS" ) )
                    {
                        
g_iSettingsMENU_DONATE_ACCESS ] = szValue] == '0' ADMIN_ALL read_flagsszValue );
                    }
                }
            }
        }
        
fcloseiFile )
    }
    else 
log_amx"File %s does not exists"szFile )
    
    
CC_SetPrefixg_iSettingsPREFIX_CHAT ] );
}

ReadDataidbool:bSave true )
{
    new 
szQueryMAX_QUERY_LENGTH ];

    if( 
bSave )
    {
        switch( 
g_iSettingsUSE_SQL ] )
        {
            case 
Nvault:
            {
                new 
szValueMAX_CASH_LENGTH ];
                
num_to_strg_iPlayerid ][ Bank ], szValuecharsmaxszValue ) )
                
nvault_setg_iVaultg_iPlayerid ][ SaveInfo ], szValue );
            }
            case 
MySQLSQLite:
            {
                
formatexszQuery charsmaxszQuery ), "REPLACE INTO `%s` (`Player`, `Cash`) VALUES ('%s', '%i');",\
                
g_iSettingsSQL_TABLE ], g_iPlayerid ][ SaveInfo ], g_iPlayerid ][ Bank ] );
                
SQL_ThreadQueryg_SQLTuple"QueryHandle"szQuery );
            }
        }
    }
    else
    {
        switch( 
g_iSettingsUSE_SQL ] )
        {
            case 
Nvaultg_iPlayerid ][ Bank ] = nvault_getg_iVaultg_iPlayerid ][ SaveInfo ] );
            case 
MySQLSQLite:
            {
                
formatexszQuery charsmaxszQuery ), "SELECT Cash FROM `%s` WHERE Player = '%s';",\
                
g_iSettingsSQL_TABLE ], g_iPlayerid ][ SaveInfo ] );
                new 
szData]; szData] = id
                SQL_ThreadQuery
g_SQLTuple"QueryHandle"szQueryszDatasizeofszData ) );
            }
        }
    }
}

RunQueryHandle:SQLConnection, const szQuery[ ], szSQLError[ ], iErrLen )
{
    new 
Handle:iQuery SQL_PrepareQuerySQLConnection szQuery );
    
    if( !
SQL_ExecuteiQuery ) )
    {
        
SQL_QueryErroriQueryszSQLErroriErrLen );
        
set_fail_stateszSQLError );
    }
    
    
SQL_FreeHandleiQuery );
}

public 
QueryHandleiFailStateHandle:iQuery, const szError[ ], iErrCode, const szData[ ], iDataSize )
{
    switch( 
iFailState )
    {
        case 
TQUERY_CONNECT_FAILED: { log_amx"[SQL Error] Connection failed (%i): %s"iErrCodeszError ); return; }
        case 
TQUERY_QUERY_FAILED: { log_amx"[SQL Error] Query failed (%i): %s"iErrCodeszError ); return; }
    }
    
    if( 
SQL_NumResultsiQuery ) )
    {
        
g_iPlayerszData] ][ Bank ] = SQL_ReadResultiQuery );
    }


ResetData( const id )
{
    
g_iPlayerid ][ Bank ] = 0;
    
g_iPlayerid ][ Donate ] = 0;
    
g_iPlayerid ][ BotOrHLTV ] = false;
}

public 
plugin_natives( )
{
    
register_library("Bank");
    
register_native("get_user_bank""_get_user_bank")
    
register_native("set_user_bank""_set_user_bank")
}

public 
_get_user_bankiPlugin iParams )
{
    return 
g_iPlayerget_param) ][ Bank ]
}

public 
_set_user_bankiPlugin iParams )
{
    new 
id get_param)
    
g_iPlayerid ][ Bank ] = get_param);
    
ReadDataid );
}

public 
plugin_end( )
{
    if( 
g_iSettingsUSE_SQL ] )
    {
        
SQL_FreeHandleg_SQLTuple );
    }
    else
    {
        
nvault_closeg_iVault );
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ fbidis\\ ansi\\ ansicpg1252\\ deff0{\\ fonttbl{\\ f0\\ fnil\\ fcharset0 Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ ltrpar\\ lang3073\\ f0\\ fs16 \n\\ par }
*/ 
sigerman is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-03-2022 , 03:36   Re: Bank System Nvault/SQL Support
Reply With Quote #60

I made small changes, also tested Mysql, Sqlite, Nvault and donation system and it works perfect
https://forums.alliedmods.net/showpo...6&postcount=56
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:19.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode