Снова я. Теперь скидываю исходник плагина, нужно проверить будет ли он работать если убрать SQL, если да то убрать и QSL и ZP
Код:
#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
//#include < sqlx >
#define ZP_SUPPORT
#define MAX_CLIENTS 32
#define TASK_LOAD_DATA 12352
//#if defined ZP_SUPPORT
//#include < zombieplague >
//#endif
// CBasePlayer
#define m_iAccount 115
// CBaseMonster
#define m_LastHitGroup 75
#define FLAG_VIP ADMIN_LEVEL_H // Флаг для VIP игрока
#define LIMIT_USER 16000 // Максимальное кол-во денег у обычного игрока
#define LIMIT_VIP 16000 // Максимальное кол-во денег у VIP игрока
#define MONEY_START 800 // Деньги при старте (если игрок зашёл первый раз на сервер)
#define MONEY_HEAD random_num( 50, 55 ) // Деньги при попадании в голову
#define MONEY_CHEST random_num( 30, 35 ) // Деньги при попадании в грудь
#define MONEY_STOMACH 25 // Деньги при попадании в живот
#define MONEY_ARM random_num( 15, 17 ) // Деньги при попадании в руки
#define MONEY_LEG random_num( 7, 10 ) // Деньги при попадании в ноги
#define MONEY_KILL 200 // Деньги за убийство
new g_iMsgID_Money;
new g_iMoney[ MAX_CLIENTS +1 ];
new bool: g_bUserLoaded[ MAX_CLIENTS +1 ];
new g_szUserSteamID[ MAX_CLIENTS +1 ][ 34 ];
new g_szQuery[ 512 ];
new Handle: g_hDBTuple;
new Handle: g_hConnect;
//#define SQL_HOST ""
//#define SQL_USER ""
//#define SQL_PASSWORD ""
//#define SQL_DATABASE ""
//#define SQL_TABLENAME "amxx_money_system"
public plugin_init( )
{
register_plugin( "[AMXX] Money System", "Best", "t3rkecorejz" );
register_event( "HLTV", "EV_RoundStart", "a", "1=0", "2=0" );
g_iMsgID_Money = get_user_msgid( "Money" );
register_message( g_iMsgID_Money, "MSG_Money" );
RegisterHam( Ham_Spawn, "player", "CPlayer__Spawn_Post", .Post = 1 );
RegisterHam( Ham_Killed, "player", "CPlayer__Killed_Post", .Post = 1 );
RegisterHam( Ham_TakeDamage, "player", "CPlayer__TakeDamage_Post", .Post = 1 );
}
public plugin_natives( )
{
register_native( "GetUserMoney", "native_get_money", 1 );
register_native( "SetUserMoney", "native_set_money", 1 );
}
public plugin_cfg( ) SQL_LoadDebug( );
public plugin_end( )
{
if( g_hDBTuple )
SQL_FreeHandle( g_hDBTuple );
if( g_hConnect )
SQL_FreeHandle( g_hConnect );
return;
}
public client_putinserver( iPlayer ) set_task( random_float( 1.0, 3.0 ), "CTask__LoadData", iPlayer +TASK_LOAD_DATA );
public client_disconnect( iPlayer )
{
if( !g_bUserLoaded[ iPlayer ] )
return;
formatex( g_szQuery, charsmax( g_szQuery ), "UPDATE `%s` SET `Money` = '%d' WHERE `%s`.`SteamID` = '%s';", SQL_TABLENAME, g_iMoney[ iPlayer ], SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
}
// Events
public EV_RoundStart( )
{
for( new iPlayer = 1; iPlayer <= MAX_CLIENTS; iPlayer++ )
{
if( !is_user_connected( iPlayer ) )
continue;
if( !g_bUserLoaded[ iPlayer ] )
return;
formatex( g_szQuery, charsmax( g_szQuery ), "UPDATE `%s` SET `Money` = '%d' WHERE `%s`.`SteamID` = '%s';", SQL_TABLENAME, g_iMoney[ iPlayer ], SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
}
}
// Messages
public MSG_Money( MsgID, MSG_DEST, iEntity )
{
new iMoney = g_iMoney[ iEntity ];
set_msg_arg_int( 1, ARG_LONG, iMoney );
set_pdata_int( iEntity, m_iAccount, iMoney, 5 );
}
// Ham
public CPlayer__Spawn_Post( iPlayer )
{
if( !is_user_alive( iPlayer ) )
return;
set_pdata_int( iPlayer, m_iAccount, g_iMoney[ iPlayer ], 5 );
UTIL_Money( iPlayer, g_iMoney[ iPlayer ], 0 );
}
public CPlayer__Killed_Post( iVictim, iAttacker, iGib )
{
if( !is_user_connected( iVictim ) || !is_user_connected( iAttacker ) || iVictim == iAttacker )
return;
#if defined ZP_SUPPORT
if( zp_get_user_zombie( iAttacker ) )
return;
#endif
if( pev_valid( iAttacker ) == 2 )
{
set_pdata_int( iAttacker, m_iAccount, g_iMoney[ iAttacker ], 5 );
UTIL_Money( iAttacker, g_iMoney[ iAttacker ], 0 );
}
Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_KILL );
}
public CPlayer__TakeDamage_Post( iVictim, iInflictor, iAttacker, Float: flDamage )
{
if( !is_user_connected( iVictim ) || !is_user_connected( iAttacker ) || iVictim == iAttacker )
return;
#if defined ZP_SUPPORT
if( zp_get_user_zombie( iAttacker ) )
return;
#endif
switch( get_pdata_int( iVictim, m_LastHitGroup, 5 ) )
{
case HIT_HEAD: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_HEAD );
case HIT_CHEST: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_CHEST );
case HIT_STOMACH: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_STOMACH );
case HIT_LEFTARM, HIT_RIGHTARM: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_ARM );
case HIT_LEFTLEG, HIT_RIGHTLEG: Native_SetUserMoney( iAttacker, g_iMoney[ iAttacker ] +MONEY_LEG );
}
}
// Task
public CTask__LoadData( iTask )
{
new iPlayer = iTask -TASK_LOAD_DATA;
if( !is_user_connected( iPlayer ) )
return;
new iParams[ 1 ];
iParams [ 0 ] = iPlayer;
get_user_authid( iPlayer, g_szUserSteamID[ iPlayer ], charsmax( g_szUserSteamID[ ] ) );
formatex( g_szQuery, charsmax( g_szQuery ), "SELECT * FROM `%s` WHERE ( `%s`.`SteamID` = '%s' )", SQL_TABLENAME, SQL_TABLENAME, g_szUserSteamID[ iPlayer ] );
SQL_ThreadQuery( g_hDBTuple, "SQL_QueryConnection", g_szQuery, iParams, sizeof iParams );
}
// MySQL
public SQL_LoadDebug( )
{
new szError[ 512 ];
new iErrorCode;
g_hDBTuple = SQL_MakeDbTuple( SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_DATABASE );
g_hConnect = SQL_Connect( g_hDBTuple, iErrorCode, szError, charsmax( szError ) );
if( g_hConnect == Empty_Handle )
set_fail_state( szError );
if( !SQL_TableExists( g_hConnect, SQL_TABLENAME ) )
{
new Handle: hQueries;
new szQuery[ 512 ];
formatex( szQuery, charsmax( szQuery ), "CREATE TABLE IF NOT EXISTS `%s` ( SteamID varchar( 32 ) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, Money INT NOT NULL, PRIMARY KEY ( SteamID ) )", SQL_TABLENAME );
hQueries = SQL_PrepareQuery( g_hConnect, szQuery );
if( !SQL_Execute( hQueries ) )
{
SQL_QueryError( hQueries, szError, charsmax( szError ) );
set_fail_state( szError );
}
SQL_FreeHandle( hQueries );
}
SQL_QueryAndIgnore( g_hConnect, "SET NAMES utf8" );
}
public SQL_QueryConnection( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize )
{
switch( iState )
{
case TQUERY_CONNECT_FAILED: log_amx( "Load - Could not connect to SQL database. [%d] %s", iErrorCode, szError );
case TQUERY_QUERY_FAILED: log_amx( "Load Query failed. [%d] %s", iErrorCode, szError );
}
new iPlayer = iParams[ 0 ];
g_bUserLoaded[ iPlayer ] = true;
if( SQL_NumResults( hQuery ) < 1 )
{
if( equal( g_szUserSteamID[ iPlayer ], "ID_PENDING" ) )
return PLUGIN_HANDLED;
g_iMoney[ iPlayer ] = MONEY_START;
formatex( g_szQuery, charsmax( g_szQuery ), "INSERT INTO `%s` ( `SteamID`, `Money` ) VALUES ( '%s', '%d' );", SQL_TABLENAME, g_szUserSteamID[ iPlayer ], g_iMoney[ iPlayer ] );
SQL_ThreadQuery( g_hDBTuple, "SQL_ThreadQueryHandler", g_szQuery );
return PLUGIN_HANDLED;
}
else Native_SetUserMoney( iPlayer, SQL_ReadResult( hQuery, 1 ) );
return PLUGIN_HANDLED;
}
public SQL_ThreadQueryHandler( iState, Handle: hQuery, szError[ ], iErrorCode, iParams[ ], iParamsSize )
{
if( iState == 0 )
return;
log_amx( "SQL Error: %d (%s)", iErrorCode, szError );
}
// Natives
Native_SetUserMoney( iPlayer, iAmount, iFlash = 1 )
{
if( pev_valid( iPlayer ) != 2 )
return;
static iMax;
if( get_user_flags( iPlayer ) & FLAG_VIP ) iMax = LIMIT_VIP;
else iMax = LIMIT_USER;
if( iAmount > iMax )
{
g_iMoney[ iPlayer ] = iMax;
set_pdata_int( iPlayer, m_iAccount, iMax, 5 );
UTIL_Money( iPlayer, iMax, 0 );
return;
}
g_iMoney[ iPlayer ] = iAmount;
set_pdata_int( iPlayer, m_iAccount, iAmount, 5 );
UTIL_Money( iPlayer, iAmount, iFlash );
}
public native_set_money( iPlayer, iValue )
Native_SetUserMoney( iPlayer, iValue );
public native_get_money( iPlayer )
return g_iMoney[ iPlayer ];
// Stocks
stock UTIL_Money( iPlayer, iAmount, iFlash )
{
message_begin( MSG_ONE, g_iMsgID_Money, _, iPlayer );
write_long( iAmount );
write_byte( iFlash );
message_end( );
}
stock bool: SQL_TableExists( Handle: hDataBase, const szTable[ ] )
{
new Handle: hQuery = SQL_PrepareQuery( hDataBase, "SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;", szTable );
new szError[ 512 ];
if( !SQL_Execute( hQuery ) )
{
SQL_QueryError( hQuery, szError, charsmax( szError ) );
set_fail_state( szError );
}
else if( !SQL_NumResults( hQuery ) )
{
SQL_FreeHandle( hQuery );
return false;
}
SQL_FreeHandle( hQuery );
return true;
}