https://raw.githubusercontent.com/xPaw/ ... mx_gag.sma
Salveaza pe MYSQL date si este super.
Moderators: Moderatori ajutatori, Moderatori, Echipa eXtreamCS.com
Code: Select all
#include < amxmodx >
#include < cstrike >
#include < sqlx >
#include <gag>
#pragma tabsize 0
const GT = 333
enum _:DataH
{
R,
G,
B,
Float:X,
Float:Y,
E,
Float:FXT,
Float:HT,
Float:FI,
Float:FO,
CH
}
new const HSE[][DataH]=
{
{255,0,0,0.0,-1.0,0,6.0,12.0,1.0,1.0,-2}
}
new const SQL_TABLE [ ] = "users_stats";
new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [65], PlayerAuthID [33] [35], PlayerName [33] [33],
Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser,
cSqlPassword, cSqlDatabase, MaxPlayers,HSY;
public plugin_init ( )
{
register_event ( "DeathMsg", "EventDeathMsg", "a" );
register_logevent ( "leRoundEnd", 2, "1=Round_End" );
cSqlHost = register_cvar ( "sql_host", "host" );
cSqlUser = register_cvar ( "sql_user", "user" );
cSqlPassword = register_cvar ( "sql_password", "pw" );
cSqlDatabase = register_cvar ( "sql_database", "db" );
MaxPlayers = get_maxplayers ( );
HSY=CreateHudSyncObj()
}
public plugin_cfg ( )
{
get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) );
get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) );
get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) );
get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) );
iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase );
static Query [555 char], Len;
Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE );
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL," );
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,");
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,");
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,");
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,");
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,");
Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" );
SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query );
}
public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime )
{
if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) set_fail_state ( "[SQL] Query Error" );
if ( Errcode ) log_amx ( "[SQL] Error: %s", Error );
}
public client_putinserver ( id )
{
if(!is_user_connected(id)||is_user_bot(id)||is_user_hltv(id)) return
get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) );
get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) );
iFrags [id] = 0;
iDeaths [id] = 0;
iMoney [id] = 0;
iLastConnected [id] = "N/A";
LoadData ( id );
if(is_user_gagged(id)) set_task(1.0,"CDG",id+GT,.flags="b")
}
public CDG(id)
{
id-=GT
if(!is_user_gagged(id))
{
remove_task(id)
return
}
set_hudmessage(HSE[0][R],HSE[0][G],HSE[0][B],HSE[0][X],HSE[0][Y],HSE[0][E],HSE[0][FXT],HSE[0][HT],HSE[0][FI],HSE[0][FO],HSE[0][CH])
ShowSyncHudMsg(id,HSY,"Nu esti eligibil pentru a primi premii, ai cooldown %d secund%s",get_gagtime(id),get_gagtime(id)==1?"a":"e")
}
public client_disconnect ( id )
{
iMoney [id] += cs_get_user_money ( id );
new iTime [32];
get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) )
copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime )
SaveData ( id );
}
public EventDeathMsg ( )
{
new Killer = read_data ( 1 );
new Victim = read_data ( 2 );
if ( !is_user_connected ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) return
iFrags [Killer] ++;
iDeaths [Victim] ++;
}
public leRoundEnd ( )
{
for ( new i = 1; i <= MaxPlayers; i ++ )
{
if(!is_user_connected(i)||is_user_bot(i)||is_user_hltv(i)||is_user_gagged(i)) continue
SaveData ( i );
}
}
public LoadData ( id )
{
static Query [256], Data [1];
Data [0] = id;
formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] );
SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 );
}
public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime )
{
if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
{
log_amx ( "[SQL] %s", Error );
return;
}
else
{
new id = Data [0];
if ( SQL_NumResults ( Query ) < 1 )
{
new Query [256];
formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] );
SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query );
}
else
{
iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) );
iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) );
iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) ) + cs_get_user_money(id);
SQL_ReadResult (Query, SQL_FieldNameToNum ( Query, "last_seen_online" ),iLastConnected [id],charsmax(iLastConnected []));
}
}
}
public SaveData ( id )
{
new Query [256], sQuery [3000];
formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE );
add ( sQuery, charsmax ( sQuery ), Query );
formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] );
add ( sQuery, charsmax ( sQuery ), Query );
formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] );
add ( sQuery, charsmax ( sQuery ), Query );
formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] );
add ( sQuery, charsmax ( sQuery ), Query );
formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] );
add ( sQuery, charsmax ( sQuery ), Query );
formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] );
add ( sQuery, charsmax ( sQuery ), Query );
SQL_ThreadQuery ( iSqlTuple, "QueryUpdateData", sQuery );
}
public QueryUpdateData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime )
{
if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
{
log_amx ( "[SQL] %s", Error );
return;
}
else
{
new id,QueryF [256]
id = Data [0]
if ( SQL_NumResults ( Query ) < 1 )
{
formatex ( QueryF, charsmax ( QueryF ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"%i^",^"%i^",^"%i^",^"N/A^");",
SQL_TABLE, PlayerAuthID [id], PlayerName [id],iFrags[id],iDeaths[id],iMoney[id] );
}
else
{
formatex ( QueryF, charsmax ( QueryF ), "UPDATE `%s` `frags`=`frags`+'%i',`deaths`=`deaths`+'%i',`money`=`money`+'%i',`last_seen_online`=^"%s^" WHERE `%s`.`steamid`=^"%s^";",
SQL_TABLE, iFrags[id],iDeaths[id],iMoney[id],iLastConnected[id],SQL_TABLE,PlayerAuthID [id] );
}
SQL_ThreadQuery ( iSqlTuple, "QuerySetData", QueryF );
}
}
public plugin_end ( ) SQL_FreeHandle ( iSqlTuple );
Multumesc frumos.L E V I N wrote: ↑27 Mar 2020, 21:57nu prea mi place salvarea pe mysql..nu știi când pică
gagu ăla e automat, adică dacă are gag 10 ani, mai are ungag peste 10 ani, pot face doar să nu i seteze alea cât timp are gagu, și cooldown normal..adică să i arate cât mai are din gag dacă areCode: Select all
#include < amxmodx > #include < cstrike > #include < sqlx > #include <gag> #pragma tabsize 0 const GT = 333 enum _:DataH { R, G, B, Float:X, Float:Y, E, Float:FXT, Float:HT, Float:FI, Float:FO, CH } new const HSE[][DataH]= { {255,0,0,0.0,-1.0,0,6.0,12.0,1.0,1.0,-2} } new const SQL_TABLE [ ] = "users_stats"; new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [65], PlayerAuthID [33] [35], PlayerName [33] [33], Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser, cSqlPassword, cSqlDatabase, MaxPlayers,HSY; public plugin_init ( ) { register_event ( "DeathMsg", "EventDeathMsg", "a" ); register_logevent ( "leRoundEnd", 2, "1=Round_End" ); cSqlHost = register_cvar ( "sql_host", "host" ); cSqlUser = register_cvar ( "sql_user", "user" ); cSqlPassword = register_cvar ( "sql_password", "pw" ); cSqlDatabase = register_cvar ( "sql_database", "db" ); MaxPlayers = get_maxplayers ( ); HSY=CreateHudSyncObj() } public plugin_cfg ( ) { get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) ); get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) ); get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) ); get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) ); iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase ); static Query [555 char], Len; Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE ); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL," ); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,"); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,"); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,"); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,"); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,"); Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" ); SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query ); } public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) { if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) set_fail_state ( "[SQL] Query Error" ); if ( Errcode ) log_amx ( "[SQL] Error: %s", Error ); } public client_putinserver ( id ) { if(!is_user_connected(id)||is_user_bot(id)||is_user_hltv(id)) return get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) ); get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) ); iFrags [id] = 0; iDeaths [id] = 0; iMoney [id] = 0; iLastConnected [id] = "N/A"; LoadData ( id ); if(is_user_gagged(id)) set_task(1.0,"CDG",id+GT,.flags="b") } public CDG(id) { id-=GT if(!is_user_gagged(id)) { remove_task(id) return } set_hudmessage(HSE[0][R],HSE[0][G],HSE[0][B],HSE[0][X],HSE[0][Y],HSE[0][E],HSE[0][FXT],HSE[0][HT],HSE[0][FI],HSE[0][FO],HSE[0][CH]) ShowSyncHudMsg(id,HSY,"Nu esti eligibil pentru a primi premii, ai cooldown %d secund%s",get_gagtime(id),get_gagtime(id)==1?"a":"e") } public client_disconnect ( id ) { iMoney [id] += cs_get_user_money ( id ); new iTime [32]; get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) ) copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime ) SaveData ( id ); } public EventDeathMsg ( ) { new Killer = read_data ( 1 ); new Victim = read_data ( 2 ); if ( !is_user_connected ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) return iFrags [Killer] ++; iDeaths [Victim] ++; } public leRoundEnd ( ) { for ( new i = 1; i <= MaxPlayers; i ++ ) { if(!is_user_connected(i)||is_user_bot(i)||is_user_hltv(i)||is_user_gagged(i)) continue SaveData ( i ); } } public LoadData ( id ) { static Query [256], Data [1]; Data [0] = id; formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] ); SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 ); } public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime ) { if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) { log_amx ( "[SQL] %s", Error ); return; } else { new id = Data [0]; if ( SQL_NumResults ( Query ) < 1 ) { new Query [256]; formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] ); SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query ); } else { iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) ); iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) ); iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) ) + cs_get_user_money(id); SQL_ReadResult (Query, SQL_FieldNameToNum ( Query, "last_seen_online" ),iLastConnected [id],charsmax(iLastConnected [])); } } } public SaveData ( id ) { new Query [256], sQuery [3000]; formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE ); add ( sQuery, charsmax ( sQuery ), Query ); formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] ); add ( sQuery, charsmax ( sQuery ), Query ); formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] ); add ( sQuery, charsmax ( sQuery ), Query ); formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] ); add ( sQuery, charsmax ( sQuery ), Query ); formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] ); add ( sQuery, charsmax ( sQuery ), Query ); formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] ); add ( sQuery, charsmax ( sQuery ), Query ); SQL_ThreadQuery ( iSqlTuple, "QueryUpdateData", sQuery ); } public QueryUpdateData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) { if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) { log_amx ( "[SQL] %s", Error ); return; } else { new id,QueryF [256] id = Data [0] if ( SQL_NumResults ( Query ) < 1 ) { formatex ( QueryF, charsmax ( QueryF ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"%i^",^"%i^",^"%i^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id],iFrags[id],iDeaths[id],iMoney[id] ); } else { formatex ( QueryF, charsmax ( QueryF ), "UPDATE `%s` `frags`=`frags`+'%i',`deaths`=`deaths`+'%i',`money`=`money`+'%i',`last_seen_online`=^"%s^" WHERE `%s`.`steamid`=^"%s^";", SQL_TABLE, iFrags[id],iDeaths[id],iMoney[id],iLastConnected[id],SQL_TABLE,PlayerAuthID [id] ); } SQL_ThreadQuery ( iSqlTuple, "QuerySetData", QueryF ); } } public plugin_end ( ) SQL_FreeHandle ( iSqlTuple );
Si pe langa asta inca un camp la tabelul sql cu valorile 0/1 (gag/ungag). Dupa facut un bool care se seteaza true sau false in functie de valoarea din campul sql. Dupa in functie de bool:t=0/1 faci ce vrei sa faca.