- /* Plugin generated by AMXX-Studio */ 
-   
- #include <amxmodx> 
- #include <sqlx> 
-   
- #if AMXX_VERSION_NUM < 183 
- #include <colorchat> 
-   
- #define print_team_default DontChange 
- #define print_team_grey Grey 
- #define print_team_red Red 
- #define print_team_blue Blue 
- #endif 
-   
- #define MaxPlayers 33 
-   
- new const SQL_INFO[][] = { 
-     "127.0.0.1",    // HOST 
-     "root",     // USERNAME 
-     "",     // PASSWORD 
-     "amxx"      // DATABASE 
- } 
-   
- new Handle:g_SqlTuple; 
-   
- // tároljuk valamibe a nevet is, mert nem akarom, mindig lekérni. 
- new name[33][32] 
-   
- new TotalAchievements[33] 
-   
- enum _:iAchCount { 
-     CONNECT 
- } 
-   
- new const iAchPoints[iAchCount] = { 
-     500 
- } 
-   
- new iAchLevel[MaxPlayers][iAchCount]; 
-   
- public plugin_init()  
- { 
-     register_clcmd("say /achs", "CmdPlayerInfo") 
- } 
-   
- public client_putinserver(id)  
- { 
-     if(++iAchLevel[id][CONNECT] == 500)  
-         set_task(2.0, "ReachAddict", id) // Avoid playing the sound and printing the message to  
-      
-     if(!is_user_bot(id))  
-     { 
-         get_user_name(id, name[id], charsmax(name)) 
-         load(id) 
-     } 
- }  
-   
- public ReachAddict(id)  
- { 
-     TotalAchievements[id]++ 
-     client_print_color(id, print_team_default, "^4[Achievements] ^1Congratulations! You have unlocked the achievement:^3 Addict!") 
- } 
-   
- public CmdPlayerInfo(id)  
- { 
-     new iMenu = menu_create("\d[Achievements]\y Test Ach", "handlePlayerMenu"); 
-     new iPlayers[32], iNum, iPlayer, szName[32], szKey[4]; 
-     get_players(iPlayers, iNum); 
-     new szMenuKey[128]; 
-     for( new i; i < iNum; i++ ) 
-     { 
-         iPlayer = iPlayers[i]; 
-         new percent = 100 * iAchLevel[id][i]/iAchPoints[i] 
-         get_user_name(iPlayer, szName, charsmax(szName)); 
-         format(szMenuKey,127,"\r%s \d[%d%%] ^n\w",szName,percent); 
-         num_to_str(iPlayer, szKey, charsmax(szKey)); 
-         menu_additem(iMenu, szMenuKey, szKey); 
-     }    
-     menu_setprop(iMenu, MPROP_EXITNAME, "Exit"); 
-     menu_display(id, iMenu, 0); 
- } 
- public handlePlayerMenu(id, iMenu, iItem) 
- { 
-     if( iItem == MENU_EXIT ) 
-     { 
-         menu_destroy(iMenu); 
-         return PLUGIN_HANDLED; 
-     } 
-     new szData[6], iAccess, iCallback; 
-     menu_item_getinfo(iMenu, iItem, iAccess, szData, charsmax(szData), _, _, iCallback); 
-     new i = str_to_num(szData); 
-     new szAuth[35], szName[32]; 
-     get_user_authid(i, szAuth, charsmax(szAuth)); 
-     get_user_name(i, szName, charsmax(szName)); 
-     static szMotd[30000]; 
-     new iLen = formatex(szMotd, charsmax(szMotd), "<html>"); 
-     iLen = formatex(szMotd[iLen], charsmax(szMotd)-iLen,"<STYLE>body{background:#212121;color:#d1d1d1;font-family:Arial}table{width:100%%;font-size:11px}</STYLE><table cellpadding=1>"); 
-     iLen += formatex(szMotd[iLen], charsmax(szMotd)-iLen, "<tr bgcolor=#333333><th width=5%%><align=left font color=white> Name <th width=10%%> Stats <th width=10%%> Percent <th width=10%%>"); 
-     iLen += formatex(szMotd[iLen], charsmax(szMotd)-iLen, "<tr bgcolor=#333333><th width=5%%><align=left font color=white> Addicted! <th width=10%%> %i/%i <th width=10%%> %d <th width=10%%>", iAchLevel[i][CONNECT], iAchPoints[CONNECT], 100 * iAchLevel[id][CONNECT] / iAchPoints[CONNECT]); 
-     iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</p>"); 
-     iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</body>"); 
-     iLen += formatex(szMotd[iLen], charsmax(szMotd) - iLen, "</html>"); 
-     show_motd(id,szMotd, "Achievement Player Info"); 
-     CmdPlayerInfo(id); 
-     menu_destroy(iMenu); 
-     return PLUGIN_HANDLED; 
- } 
-   
- public plugin_cfg()  
- { 
-     new Query[1024]; 
-     g_SqlTuple = SQL_MakeDbTuple(SQL_INFO[0],SQL_INFO[1],SQL_INFO[2],SQL_INFO[3]) 
-      
-     formatex(Query, charsmax(Query), "CREATE TABLE IF NOT EXISTS `tabla_neve` (`username` varchar(32) NOT NULL,`connect` int(11) NOT NULL,`id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)") 
-     SQL_ThreadQuery(g_SqlTuple,"createTableThread", Query) 
- } 
-   
- public createTableThread(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Queuetime) { 
-     if(FailState == TQUERY_CONNECT_FAILED) 
-         set_fail_state("Nem tudtam csatlakozni az adatbazishoz."); 
-     else if(FailState == TQUERY_QUERY_FAILED) 
-         set_fail_state("Query Error"); 
-     if(Errcode) 
-         log_amx("Hibat dobtam: %s",Error); 
- } 
-   
- public load(id)  
- { 
-     new Query[512], Data[1] 
-     Data[0] = id 
-     formatex(Query, charsmax(Query), "SELECT * FROM `tabla_neve` WHERE username = ^"%s^";", name[id]) 
-     SQL_ThreadQuery(g_SqlTuple, "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("%s", Error) 
-         return 
-     } 
-     else  
-     { 
-         new id = Data[0]; 
-          
-         if(SQL_NumRows(Query) > 0)  
-         { 
-             iAchLevel[id][CONNECT] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "connect")) 
-         } 
-         else  
-         { 
-             save(id) 
-         } 
-     } 
- } 
-   
- public save(id)  
- { 
-     new text[1024]; 
-     formatex(text, charsmax(text), "INSERT INTO `tabla_neve` (`username`, `connect`) VALUES (^"%s^", ^"0^");", name[id], iAchLevel[id][CONNECT]) 
-     SQL_ThreadQuery(g_SqlTuple, "QuerySetData", text) 
- } 
-   
- public QuerySetData(FailState, Handle:Query, Error[], Errcode, Data[], DataSize, Float:Queuetime)  
- { 
-     if(FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED)  
-     { 
-         log_amx("%s", Error) 
-         return 
-     } 
- } 
-   
- public update(id)  
- { 
-     new text[1024]; 
-     formatex(text, charsmax(text), "UPDATE `tabla_neve` SET connect = ^"%i^" WHERE username = ^"%s^";", iAchLevel[id][CONNECT], name[id]) 
-     SQL_ThreadQuery(g_SqlTuple, "QuerySetData", text) 
- } 
-   
- public client_disconnected(id)  
- { 
-     if(!is_user_bot(id))  
-     { 
-         update(id) 
-     } 
-     copy(name[id], charsmax(name[]), "") 
- } 
-   
- public plugin_end()  
- { 
-     SQL_FreeHandle(g_SqlTuple) 
- }