Mam dwa pluginy, jeden wykorzystuje komendę /topczas do sprawdzania ile kto przegrał na serwerze.
Drugi to medale, który wyświetla ilość medali i ich sumę w komendzie /medale.
Chciałbym, aby ten pierwszy też był tak ładnie sformatowany jak ten drugi. Czy ktoś może mi pomóc?
Próbowałem na własną rękę, ale paliło to na panewce...
Kod .sma dla medali:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <sqlx> #include <colorchat> new const nazwy[][] = { "Zlote", "Srebrne", "Brazowe" } new Handle: g_SqlTuple; new gQuery[512]; enum _:staty { KILL, GOLD, SILVER, BRONZE } enum _:cvary { HOST, PASS, USER, DBNAME, MIMPLR } new gStaty[staty][33]; new gCvary[cvary]; new gNick[33][33]; new gData[2048], len, gLast; public plugin_end() SQL_FreeHandle(g_SqlTuple); public plugin_init() { register_plugin("Medale SQL Ver", "1.0", "byCZEK"); register_event("DeathMsg", "event_death", "a"); register_message(SVC_INTERMISSION, "MsgIntermission"); register_clcmd("say /medale", "MenuMedali"); gCvary[HOST] = register_cvar("medale_hostname", "hostname"); gCvary[PASS] = register_cvar("medale_password", "password"); gCvary[USER] = register_cvar("medale_username", "username"); gCvary[DBNAME] = register_cvar("medale_dbname", "db"); gCvary[MIMPLR] = register_cvar("medale_minp", "3"); new temp[staty][64]; get_pcvar_string(gCvary[HOST], temp[HOST], 63); get_pcvar_string(gCvary[PASS], temp[PASS], 63); get_pcvar_string(gCvary[USER], temp[USER], 63); get_pcvar_string(gCvary[DBNAME], temp[DBNAME], 63); g_SqlTuple = SQL_MakeDbTuple(temp[HOST], temp[USER], temp[PASS], temp[DBNAME]); if(g_SqlTuple == Empty_Handle) set_fail_state("Nie mozna utworzyc uchwytu do polaczenia."); new iErr, szError[32]; new Handle:link = SQL_Connect(g_SqlTuple, iErr, szError, 31); if(link == Empty_Handle){ log_amx("Error (%d): %s", iErr, szError); set_fail_state("Brak polaczenia z baza danych"); } new Handle:query; query = SQL_PrepareQuery(link, "CREATE TABLE IF NOT EXISTS `medale` ( \ `id` int(5) NOT NULL auto_increment, \ `nick` varchar(36) NOT NULL, \ `kill` INT(11) NOT NULL DEFAULT 0, \ `gold` INT(11) NOT NULL DEFAULT 0, \ `silver` INT(11) NOT NULL DEFAULT 0, \ `bronze` INT(11) NOT NULL DEFAULT 0, \ PRIMARY KEY (`id`) \ )"); SQL_Execute(query); SQL_FreeHandle(query); WczytajMedale(); } public client_putinserver(id) { Wyczysc(id); get_user_name(id, gNick[id], 32); formatex(gQuery, charsmax(gQuery), "SELECT * FROM `medale` WHERE `nick` = ^"%s^"", gNick[id]); new ids[1]; ids[0] = id; SQL_ThreadQuery(g_SqlTuple, "handleLoadData", gQuery, ids, 1); } public client_disconnect(id) { formatex(gQuery, charsmax(gQuery), "UPDATE `medale` SET `kill` = %d, `gold` = %d, `silver` = %d, `bronze` = %d WHERE `nick` = ^"%s^"", gStaty[KILL][id], gStaty[GOLD][id], gStaty[SILVER][id], gStaty[BRONZE][id], gNick[id]); SQL_ThreadQuery(g_SqlTuple, "handleStandard", gQuery); Wyczysc(id); } public Wyczysc(id) { for(new i = 0; i < staty; i++) gStaty[i][id] = 0; } public WczytajMedale() { gLast = get_systime(); SQL_ThreadQuery(g_SqlTuple, "handeLoadRank", "SELECT * FROM `medale` ORDER BY `gold` DESC LIMIT 15"); } public handleLoadData(failstate, Handle:query, error[], errnum, data[], size){ if(failstate != TQUERY_SUCCESS){ log_amx("SQL Load error: %s",error); return; } new id = data[0]; if(!is_user_connected(id)) return; if(SQL_MoreResults(query)) { gStaty[KILL][id] = SQL_ReadResult(query, 2); gStaty[GOLD][id] = SQL_ReadResult(query, 3); gStaty[SILVER][id] = SQL_ReadResult(query, 4); gStaty[BRONZE][id] = SQL_ReadResult(query, 5); } else { formatex(gQuery, charsmax(gQuery), "INSERT INTO `medale` (`nick`) VALUES (^"%s^")", gNick[id]); SQL_ThreadQuery(g_SqlTuple, "handleStandard", gQuery); } } public handleStandard(failstate, Handle:query, error[], errnum, data[], size) { if(failstate != TQUERY_SUCCESS) { log_amx("SQL Insert error: %s",error); return; } } public event_death() { new kid = read_data(1); new vid = read_data(2); if(kid != vid && get_user_team(kid) != get_user_team(vid)) gStaty[KILL][kid]++; } public MenuMedali(id) { new m = menu_create("[BLABLA] Menu medali:", "MenuMedali_"); menu_additem(m, "Twoje medale"); menu_additem(m, "Ranking medali"); menu_setprop(m, MPROP_EXIT, MEXIT_ALL); menu_display(id, m); } public MenuMedali_(id, m, i) { if(i == MENU_EXIT) { menu_destroy(m); return PLUGIN_CONTINUE; } switch(i) { case 0: { TwojeMedale(id); } case 1: { RankingMedali(id); } } return PLUGIN_CONTINUE; } public TwojeMedale(id) { new m = menu_create("Twoje medale", "TwojeMedale_"); new t[128]; for(new i = 1; i < staty; i++) { formatex(t, charsmax(t), "%s: \r%d", nazwy[i-1], gStaty[i][id]); menu_additem(m, t); } menu_display(id, m); } public TwojeMedale_(id, m) menu_destroy(m); public RankingMedali(id) { if(get_systime() - gLast > 20) { WczytajMedale(); } show_motd(id, gData, "TOP15 - Medale"); } public handeLoadRank(failstate, Handle:query, error[], errnum, data[], size) { if(failstate != TQUERY_SUCCESS) { log_amx("SQL Load error: %s",error); return; } new nick[33], medale[4], i = 0; len = formatex(gData, charsmax(gData), "<body bgcolor=#000000><font color=#FFB000><pre>%2s %-22.22s %6s %8s %8s %5s^n", "#", "Nick", nazwy[0], nazwy[1], nazwy[2], "Suma"); while(SQL_MoreResults(query)) { i++; SQL_ReadResult(query, 1, nick, 32); medale[0] = SQL_ReadResult(query, 3); medale[1] = SQL_ReadResult(query, 4); medale[2] = SQL_ReadResult(query, 5); medale[3] = medale[0] + medale[1] + medale[2]; replace_all(nick, charsmax(nick), "<", "["); replace_all(nick, charsmax(nick), ">", "]"); len += formatex(gData[len], charsmax(gData) - len, "%2d %-22.22s %6d %8d %8d %5d^n", i, nick, medale[0], medale[1], medale[2], medale[3]); SQL_NextRow(query); } } public MsgIntermission() { new name[33], players[32], best[3], num, id, fragi; get_players(players, num, "h"); if(num < get_pcvar_num(gCvary[MIMPLR])) return PLUGIN_CONTINUE; new const typ[][] = { "Zloty", "Srebrny", "Brazowy" } for(new i = 0; i < 3; i++) { for(new j = 0; j < num; j++) { id = players[j]; if(!is_user_connected(id) || best[0] == id || best[1] == id) continue; if(get_user_frags(id) > fragi) { fragi = get_user_frags(id); best[i] = id; } } fragi = 0; if(best[i]) { gStaty[1+i][best[i]]++; get_user_name(best[i], name, 32); ColorChat(0, TEAM_COLOR, "[BLABLA]^x04[Medale]^x03 %s^x01 -^x04 %s medal! ^x03(%i miejsce)", name, typ[i], i+1); } } return PLUGIN_CONTINUE; }
Kod .sma dla czasu gry:
#include <amxmodx> #include <amxmisc> #include <fvault> #include <colorchat> #define PLUGIN "Time" #define VERSION "1.1" #define AUTHOR "StarMazter" #define MAXPLAYERS 32 #define MAX_BUFFER_LENGTH 2047 new szVault[] = "Time"; new iTotalLevels = 1; new szLevels[][128] = { "Noob 1", "Noob 2" }; new szTimes[][64] = { "1", "2" }; new Trie:SaveTime; new Trie:Rank; new Trie:Name; new TotalRanks; new iCurrentTime[MAXPLAYERS+1]; new sBuffer[MAX_BUFFER_LENGTH + 1] public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR); register_clcmd("say /topczas", "CmdTimeTop"); // Register Commands. register_clcmd("say /czas", "CmdTime"); register_clcmd("say /poziomy", "CmdLevels"); } public plugin_cfg() { SaveTime = TrieCreate(); Rank = TrieCreate() Name = TrieCreate() LoadData(); } public plugin_end() { TrieDestroy(SaveTime); // Delete Trie to prevent bugs TrieDestroy(Rank); } LoadData() { new iTotal = fvault_size(szVault); new szSteamId[32], szName[32], szTime[32], szData[64], szKey[32]; for( new i = 0; i < iTotal; i++ ) { fvault_get_keyname(szVault, i, szSteamId, sizeof(szSteamId) - 1); // Return Saved Values. fvault_get_data(szVault, szSteamId, szData, sizeof(szData) - 1); parse(szData, szName, sizeof(szName) - 1, szTime, sizeof(szTime) - 1) TrieSetCell(SaveTime, szSteamId, str_to_num(szTime)) // Set the players new time to the Cell. num_to_str(TotalRanks, szKey, sizeof(szKey) - 1) TrieSetString(Name, szKey, szName) TrieSetCell(Rank, szKey, str_to_num(szTime)) TotalRanks++ } } SaveData(id) { new szSteamId[32], szName[32], szTime[32], szData[64]; get_user_authid(id, szSteamId, 31) // Retrieve Steamid. get_user_name(id, szName, 31) TrieSetCell(SaveTime, szSteamId, iCurrentTime[id]) // Set the players new time to the Cell. num_to_str(iCurrentTime[id], szTime, sizeof(szTime) - 1) // Set the num to a string formatex(szData, sizeof(szData) - 1, "^"%s^" %s", szName, szTime) fvault_set_data(szVault, szSteamId, szData) // Set data to the vault. } public client_authorized(id) { new szSteamId[32]; get_user_authid(id, szSteamId, sizeof(szSteamId) - 1) // Retrieve Steamid. TrieGetCell(SaveTime, szSteamId, iCurrentTime[id]); // Load user's old time. } public client_disconnected(id) { new iAddTime = get_user_time(id); // Getting the user's hes current time. iCurrentTime[id] += iAddTime; // Adding hes new time to hes old time. SaveData(id) } public CmdTimeTop(id) { new iRanks[10], iRanking[10], szKey[5], iTemp, z for(new x; x < 10; x++) { for(new i=0; i <= TotalRanks; i++) { num_to_str(i, szKey, sizeof(szKey) - 1) TrieGetCell(Rank, szKey, iTemp) if(x == 0) { if(iRanks[x] < iTemp) { iRanks[x] = iTemp iRanking[x] = i if(z<x) z=x } } else { if(iRanks[x] < iTemp && iRanks[x-1] > iTemp) { iRanks[x] = iTemp iRanking[x] = i if(z<x) z=x } } } } new szName[32] new iLen iLen = format(sBuffer, MAX_BUFFER_LENGTH, "<body bgcolor=#000000><font color=#FFB000><pre>") iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "#%s %s %s^n", "Rank", "Nick", "Czas na serwerze") for(new y; y <= z; y++) { num_to_str(iRanking[y], szKey, sizeof(szKey) - 1) TrieGetCell(Rank, szKey, iTemp) TrieGetString(Name, szKey, szName, sizeof(szName) - 1) iLen += format(sBuffer[iLen], MAX_BUFFER_LENGTH - iLen, "#%i %s %i ^n", y + 1, szName, iTemp) } show_motd(id, sBuffer, "Czas gry - TOP 10") } public CmdTime(id) { new iSecTempTime, iLevel, iRank, iTime, szKey[5]; iSecTempTime = (iCurrentTime[id] + get_user_time(id)) // Get user's current time for(new i; i < iTotalLevels; i++) { if((iSecTempTime/3600) >= str_to_num(szTimes[i])) // Compare with presseted levels. { iLevel++ // Add a level } } iRank=1 for(new i; i < TotalRanks + 1; i++) { num_to_str(i, szKey, sizeof(szKey) - 1) TrieGetCell(Rank, szKey, iTime) if(iCurrentTime[id] < iTime) { iRank++ } } ColorChat(id,TEAM_COLOR,"[BLABLA]^1 Twoj czas gry:^4 %i ^1godzin. Ranking:^4 %i^1/^4%i ^3[%i minut]", iSecTempTime/3600, iRank, TotalRanks, iSecTempTime/60); ColorChat(id,TEAM_COLOR,"[BLABLA]^1 %s", szLevels[iLevel]) } public CmdLevels(id) { ColorChat(id,TEAM_COLOR,"[BLABLA]^1 Sprawdz konsole."); for(new i; i < iTotalLevels; i++) { console_print(id, "%s", szLevels[i]) // Print all levels in user's console } }
Wiem, że główna zmiana będzie pod względem:
<body bgcolor=#000000><font color=#FFB000><pre>%2s %-22.22s %6s %8s %8s %5s^n
Tylko jak to spiąć w całość... Chciałbym, żeby to było wyświetlane tj. w normalnym TOP15, z takim ładnym formatowaniem. Proszę o pomoc