Помощь помогите подключить плагин к базе mysql

adriking

Участник
Сообщения
12
Симпатии
0
Баллы
22
Возраст
24
#1
#include < Bux_Main_Core >

#define PLUGIN "DeathRun Level System + Money + Speedometr"
#define VERSION "1.0"
#define AUTHOR "BuxChumStar"

#define HIDE_MONEY ( 1 << 5 )

new OneKill = 25
new TwoKill = 25

new Level[ 33 ] , UserKills[ 33 ] , LevelNext[ 33 ], g_Gold[ 33 ], g_Silver[ 33 ]

new MaxPlayers, TaskEnt, ShowSpeed, g_iMsg_HideWeapon
new bool:plrSpeed[33], bool: g_restart_attempt[ 33 ]

// [ Start: MYSQL ]

new g_szQuery[ 2048 ]
new szName[ 33 ][ 34 ]

new Handle: g_hDBTuple , Handle: g_hConnect ;

new const szHost[ ] = "83.222.117.13:3336" ,
szUser[ ] = "27015" ,
szPassword[ ] = "" ,
szDataBase[ ] = "27015" ,
szTableName[ ] = "drlevel"
// [ End: MYSQL ]

public plugin_init() {
register_plugin( PLUGIN , VERSION , AUTHOR )

register_forward(FM_Think, "Think")

TaskEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
set_pev(TaskEnt, pev_classname, "speedometer_think")
set_pev(TaskEnt, pev_nextthink, get_gametime() + 1.01)

RegisterHam( Ham_Killed , "player" , "Player_Killing" , 1 );
RegisterHam( Ham_Spawn , "player" , "Player_Spawn" , 1 );

register_event( "ResetHUD", "eHud_reset", "be" );
register_clcmd( "fullupdate", "clcmd_fullupdate" );
register_event( "TextMsg", "eRestart_attempt", "a", "2=#Game_will_restart_in" );
g_iMsg_HideWeapon = get_user_msgid( "HideWeapon" );

MaxPlayers = get_maxplayers();
ShowSpeed = register_cvar("showspeed", "1")
}

public plugin_natives( ) {
register_native( "SetUserLevel" , "NativeSetUserLevel" , 1 )
register_native( "GetUserLevel" , "NativeGetUserLevel" , 1 )
register_native( "SetUserNext" , "NativeSetUserNext" , 1 )
register_native( "GetUserNext" , "NativeGetUserNext" , 1 )
register_native( "GetUserGold" , "NativeGetUserGold" , 1 )
register_native( "SetUserGold" , "NativeSetUserGold" , 1 )
register_native( "GetUserSilver", "NativeGetUserSilver", 1 )
register_native( "SetUserSilver", "NativeSetUserSilver", 1 )

}

public clcmd_fullupdate() {
return PLUGIN_HANDLED_MAIN;
}

public eRestart_attempt() {
new iPlayers[32], iNum;
get_players( iPlayers, iNum, "a");
for( new i; i < iNum; ++i ) {
g_restart_attempt[ iPlayers ] = true;
}
}


public eHud_reset( pPlayer ) {
if( g_restart_attempt[pPlayer] ) {
g_restart_attempt[pPlayer] = false;
return;
}
ePlayer_spawn( pPlayer );
}


public ePlayer_spawn( pPlayer ) {
set_task( 0.1, "ePostResethud", pPlayer );
}


public ePostResethud( pPlayer ) {
if( is_user_alive( pPlayer ) ) {
HideMoney( pPlayer );
}
}


public HideMoney( pPlayer ) {
message_begin( MSG_ONE, g_iMsg_HideWeapon, _, pPlayer );
write_byte( HIDE_MONEY );
message_end();
}


public Think( ent )
{
if(ent == TaskEnt)
{
Info()
set_pev(ent, pev_nextthink, get_gametime() + 0.1)
}
}


public Player_Killing( victim , attacker )
{
if( !is_user_connected( attacker ) || Level[attacker] >= 20 )
return HAM_IGNORED


UserKills[attacker] += 1
g_Gold[ attacker ] += random_num( 1 , 3 )
g_Silver[ attacker ] += random_num( 1, 6 )


if(UserKills[attacker] >= LevelNext[attacker])
{
LevelNext[attacker] += TwoKill
Level[attacker] += 1

client_print( attacker , print_center , "Вы достигли %d уровня. Следующий через %d убийств" , Level[ attacker ] , LevelNext[ attacker ] )

UserKills[ attacker ] = 0
}
return PLUGIN_HANDLED;
}


public Player_Spawn( pPlayer )
{
if( !is_user_connected( pPlayer ) )
return;


set_task( 2.0 , "Check_Level" , pPlayer )
}


public Info() {
static target
static Float: velocity[ 3 ]
static Float: speedh

for(new pPlayer = 0; pPlayer <= MaxPlayers; pPlayer++){
if(!is_user_bot(pPlayer) && is_user_connected(pPlayer) || (!plrSpeed[pPlayer])){
target = pev(pPlayer, pev_iuser1) == 4 ? pev(pPlayer, pev_iuser2) : pPlayer
pev(target, pev_velocity, velocity)
speedh = floatsqroot(floatpower(velocity[0], 2.0) + floatpower(velocity[1], 2.0))
set_hudmessage( 100, 255, 0, 1.0, 0.85, 0, 0.0, 0.1, 0.01, 0.0 )
if(Level [ pPlayer ] <= 19 && get_user_team( pPlayer ) == 2){
show_hudmessage( pPlayer , "[ Скорость: %3.2f | Класс: Спецназ ]^n[ Серебро: %d | Золото: %d ]^n[ Уровень: %d | Опыт: %i / %i ]" , speedh , g_Silver[ pPlayer ] , g_Gold[ pPlayer ], Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , UserKills[ pPlayer ] )
}
else if(Level [ pPlayer ] <= 19 && get_user_team( pPlayer ) == 1){
show_hudmessage( pPlayer , "[ Скорость: %3.2f | Класс: Террорист ]^n[ Серебро: %d | Золото: %d ]^n[ Уровень: %d | Опыт: %i / %i ]" , speedh , g_Silver[ pPlayer ] , g_Gold[ pPlayer ], Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , UserKills[ pPlayer ] )
}
else if( get_user_team( pPlayer ) == 1 && Level[ pPlayer ] >= 20 ) {
show_hudmessage( pPlayer , "[ Скорость: %3.2f | Класс: Террорист ]^n[ Серебро: %d | Золото: %d ]^n[ Уровень: 20 | Максимум ]" , speedh, g_Silver[ pPlayer ] , g_Gold[ pPlayer ] )
}
else if( get_user_team( pPlayer ) == 2 && Level[ pPlayer ] >= 20 ) {
show_hudmessage( pPlayer , "[ Скорость: %3.2f | Класс: Спецназ ]^n[ Серебро: %d | Золото: %d ]^n[ Уровень: 20 | Максимум ]" , speedh, g_Silver[ pPlayer ] , g_Gold[ pPlayer ] )
}
}
}
return PLUGIN_CONTINUE
}


public Check_Level( pPlayer )
{
if( Level[ pPlayer ] < 1 )
{
Level[ pPlayer ] = 1
LevelNext[ pPlayer ] = OneKill
}
}


// [ Start: MYSQL ]

public plugin_cfg( ) {
new szError[ 512 ] , iErrorCode;

g_hDBTuple = SQL_MakeDbTuple ( szHost , szUser , szPassword , szDataBase );
g_hConnect = SQL_Connect( g_hDBTuple , iErrorCode , szError , charsmax( szError ) );

if ( g_hConnect == Empty_Handle )
set_fail_state( szError );

if ( !SQL_TableExists( g_hConnect , szTableName ) ) {
new Handle: Queries;
new Query [ 1024 ];
format( Query , 1023 , "CREATE TABLE `%s` (Name VARCHAR(40) CHARACTER SET cp1250 COLLATE cp1250_general_ci NOT NULL, Silver INT NOT NULL, Gold INT NOT NULL, Level INT NOT NULL, Kills INT NOT NULL, NextKills INT NOT NULL, PRIMARY KEY (Name))" , szTableName );
Queries = SQL_PrepareQuery( g_hConnect, Query );

if ( !SQL_Execute( Queries ) ) {
SQL_QueryError( Queries , szError ,charsmax( szError ) );
set_fail_state( szError );
}
SQL_FreeHandle ( Queries );
}
SQL_QueryAndIgnore( g_hConnect , "SET NAMES utf8" );
}


public plugin_end ( ) {
if( g_hDBTuple ) SQL_FreeHandle( g_hDBTuple );
if( g_hConnect ) SQL_FreeHandle( g_hConnect );
return;
}


public client_putinserver( pPlayer )
{
new iParams [ 1 ]; iParams [ 0 ] = pPlayer;
get_user_name( pPlayer, szName [ pPlayer ] , charsmax( szName[ ] ) )
plrSpeed[pPlayer] = ShowSpeed > 0 ? true : false


format( g_szQuery , charsmax( g_szQuery ) ,
"SELECT * FROM `%s` WHERE ( `%s`.`Name` = '%s' )", szTableName , szTableName , szName [ pPlayer ]
);

SQL_ThreadQuery( g_hDBTuple, "SQL_QueryConnection", g_szQuery, iParams, sizeof iParams );
}


public client_disconnect( pPlayer ) {
format( g_szQuery , charsmax( g_szQuery ),
"UPDATE `%s` SET `Silver` = '%d' , `Gold` = '%d' , `Level` = '%i' , `Kills` = '%i' , `NextKills` = '%i' WHERE `%s`.`Name` = '%s';",
szTableName , g_Silver[ pPlayer ], g_Gold[ pPlayer ] , Level[ pPlayer ] , UserKills[ pPlayer ] , LevelNext[ pPlayer ] , szTableName , szName [ pPlayer ]
);

SQL_ThreadQuery( g_hDBTuple, "ThreadQueryHandler", g_szQuery );
}


public SQL_QueryConnection ( iState , Handle: hQuery , szError [ ] , iErrcode , iParams [ ] , iParamsSize ) {
switch ( iState ) {
case TQUERY_CONNECT_FAILED: log_amx ( "Load - Could not connect to SQL database. [%d] %s" , iErrcode , szError );
case TQUERY_QUERY_FAILED: log_amx ( "Load Query failed. [%d] %s" , iErrcode , szError );
}

new pPlayer = iParams[ 0 ];

if ( SQL_NumResults( hQuery ) < 1 ) {
if ( equal( szName [ pPlayer ] , "ID_PENDING" ) )
return PLUGIN_HANDLED;


Level [ pPlayer ] = 0;
g_Silver[ pPlayer ] = 0;
g_Gold [ pPlayer ] = 0;

format(
g_szQuery , charsmax( g_szQuery ),

"INSERT INTO `%s` ( `Name` , `Silver` , `Gold` , `Level` , `Kills` , `NextKills` ) VALUES ( '%s' , '%d' , '%d' , '%i' , '%i' , '%i' );",
szTableName , szName [ pPlayer ] , g_Silver[ pPlayer ] , g_Gold[ pPlayer ] , Level [ pPlayer ] , UserKills [ pPlayer ] , LevelNext [ pPlayer ]
);

SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );

return PLUGIN_HANDLED;
}
else {
g_Silver[ pPlayer ] = SQL_ReadResult ( hQuery, 1 );
g_Gold [ pPlayer ] = SQL_ReadResult ( hQuery , 2 );
Level [ pPlayer ] = SQL_ReadResult ( hQuery , 3 );
UserKills [ pPlayer ] = SQL_ReadResult ( hQuery , 4 );
LevelNext [ pPlayer ] = SQL_ReadResult ( hQuery , 5 );
}

return PLUGIN_HANDLED;
}


public ThreadQueryHandler( iState , Handle: hQuery , szError [ ], iError , iParams [ ] , iParamsSize ) {
if ( iState == 0 )
return;

log_amx( "SQL Error: %d (%s)" , iError , szError );
}


stock bool: SQL_TableExists ( Handle: db , const szTable [ ] ) {
new Handle: query = SQL_PrepareQuery ( db , "SELECT * FROM information_schema.tables WHERE table_name = '%s' LIMIT 1;" , szTable );
new g_Error [ 512 ];

if ( !SQL_Execute ( query ) ) {
SQL_QueryError ( query , g_Error , charsmax ( g_Error ) );
set_fail_state ( g_Error );
}
else if ( !SQL_NumResults ( query ) ){
SQL_FreeHandle ( query );
return false;
}
SQL_FreeHandle ( query );
return true;
}


public NativeSetUserLevel( pPlayer , iValue ) {
Level [ pPlayer ] = iValue;


format( g_szQuery , charsmax( g_szQuery ) , "UPDATE `%s` SET `Level` = '%i' WHERE `%s`.`Name` = '%s';", szTableName, Level [ pPlayer ] , szTableName , szName [ pPlayer ] );
SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
}


public NativeSetUserNext( pPlayer , iValue ) {
LevelNext [ pPlayer ] = iValue;


format( g_szQuery , charsmax( g_szQuery ) , "UPDATE `%s` SET `LevelNext` = '%i' WHERE `%s`.`Name` = '%s';", szTableName, LevelNext [ pPlayer ] , szTableName , szName [ pPlayer ] );
SQL_ThreadQuery( g_hDBTuple , "ThreadQueryHandler" , g_szQuery );
}


public NativeSetUserSilver( pPlayer , num )
{
g_Silver[ pPlayer ] = num
}


public NativeSetUserGold( pPlayer , num )
{
g_Gold[ pPlayer ] = num
}


public NativeGetUserNext( pPlayer ) {
return LevelNext[ pPlayer ];
}


public NativeGetUserLevel( pPlayer ) {
return Level[ pPlayer ];
}


public NativeGetUserSilver( pPlayer )
{
return g_Silver[ pPlayer ]
}


public NativeGetUserGold( pPlayer )
{
return g_Gold[ pPlayer ]
}
// [ End: MYSQL ]
помогите мне пожалуста есть плагин и не могу подключить его к базе mysql !
 
Последнее редактирование модератором:

Mmonster

Модератор
Сообщения
327
Симпатии
110
Баллы
149
#2
new const szHost[ ] = "83.222.117.13:3336" ,
szUser[ ] = "27015" ,
szPassword[ ] = "" ,
szDataBase[ ] = "27015" ,
szTableName[ ] = "drlevel"
Хоть немножко головой думать нужно,когда выкладываете свои данные от БД.А потом начнете написывать в поддержку,что сервер взломали.
Удалил пароль от посторонних глаз.
 

adriking

Участник
Сообщения
12
Симпатии
0
Баллы
22
Возраст
24
#3
изменил пароль, с плагином поможет кто то?
 
Сверху