помогите кто нибудь с с плагином статистики который работает с базой данных Sqlite
Код подло вырезан из плагина RankMe v2.8.3. Плагин компилируется но не работает(
Код
#include <sourcemod>
enum STATS_NAMES { K, D, TK } new bool:OnDB[MAXPLAYERS+1]; new Handle:g_hStatsDb; new String:g_sSQLTable[100]; new String:g_sSqlInsert[] = "INSERT INTO `%s` VALUES (NULL,'%s','0','0','0');"; new String:g_sSqlCreate[] = "CREATE TABLE IF NOT EXISTS `%s` (id INTEGER PRIMARY KEY, steam TEXT, KILLS NUMERIC, DEATHS NUMERIC, TEAMKILLS NUMERIC)"; new String:g_sSqlSave[] = "UPDATE `%s` SET KILLS = '%i', DEATHS = '%i', TEAMKILLS='%i';"; new String:g_sSqlRetrieveClient[] = "SELECT * FROM `%s` WHERE steam='%s';"; new String:g_aClientSteam[MAXPLAYERS+1][64]; new g_aSession[MAXPLAYERS+1][STATS_NAMES]; new g_aStats[MAXPLAYERS+1][STATS_NAMES]; new bool:g_iReady[MAXPLAYERS + 1];
public OnPluginStart() { HookEvent("player_death", player_death); RegConsoleCmd("mystats", mystats_cmd);
DB_Connect(); }
public DB_Connect() { decl String:sError[256]; g_hStatsDb = SQLite_UseDatabase("Stats",sError,sizeof(sError)); if(g_hStatsDb == INVALID_HANDLE) { SetFailState("[Stats] Не удается подключиться к базе данных (%s)",sError); } SQL_LockDatabase(g_hStatsDb); new String:sQuery[1200]; Format(sQuery,sizeof(sQuery),g_sSqlCreate,g_sSQLTable); SQL_FastQuery(g_hStatsDb,sQuery); SQL_UnlockDatabase(g_hStatsDb);
new String:query[1500]; Format(query,sizeof(query),g_sSqlSave,g_sSQLTable,g_aClientSteam[client],g_aStats[client][K],g_aStats[client][D],g_aStats[client][TK]); SQL_TQuery(g_hStatsDb,SQL_SaveCallback,query,client,DBPrio_High); }
public SQL_SaveCallback(Handle:owner, Handle:hndl, const String:error[], any:client) { if(hndl == INVALID_HANDLE) { LogError("[Stats] Сохранить игрока:провал (%s)", error); return; } }
public player_death(Handle:event, const String:name[], bool:dontBroadcast) { new killer = GetClientOfUserId(GetEventInt(event, "attacker")); if (killer < 1 || IsFakeClient(killer)) { return; } new victim = GetClientOfUserId(GetEventInt(event, "userid")); if (GetClientTeam(killer) == GetClientTeam(victim)) { g_aStats[killer][TK]++; } g_aStats[killer][K]++; g_aStats[victim][D]++; }
public Action:mystats_cmd(client, args) { if (0 < client <= MaxClients) { if (g_iReady[client]) { PrintToChat(client, "Убийств: %d", g_aStats[client][K]); PrintToChat(client, "Смертей: %d", g_aStats[client][D]); PrintToChat(client, "Тим кил: %d", g_aStats[client][TK]); } else PrintToChat(client, "Вы не авторизованы"); } return Plugin_Handled; }