· 7 years ago · Dec 18, 2018, 09:04 PM
1public void OnPluginStart()
2{
3 SQL_InitConnection();
4 LoadTop();
5 HookEventEx("cs_win_panel_match", Event_WinPanelMatch);
6 RegConsoleCmd("sm_odznaki", ShowTop, "pokazuje topke");
7}
8public Action Event_WinPanelMatch(Handle event, const char[] name, bool dontBroadcast)
9{
10 GiveMedals();
11}
12public void SQL_InitConnection()
13{
14 SQL_ConnectToDB();
15}
16
17public void SQL_ConnectToDB()
18{
19 char sError[512];
20 DB = SQLite_UseDatabase("ODZNAKI",sError,sizeof(sError));
21
22 SQL_CheckIfConnected(sError);
23}
24public void SQL_CheckIfConnected(char[] sError)
25{
26 if (DB == null)
27 {
28 LogMessage("Could not connect to the DataBase! Error: %s", sError);
29 }
30 else SQL_Create_Players_Table();
31}
32public void SQL_Create_Players_Table()
33{
34 char query[512];
35 FormatPlayersQuery(query);
36 DB.Query(CheckIf_Players_QueryPassed, query, _, DBPrio_High);
37}
38public void FormatPlayersQuery(char[] query)
39{
40 Format(query, 511, "CREATE TABLE IF NOT EXISTS `Players` (`PlayerID` INTEGER NOT NULL UNIQUE, `Name` INTEGER NOT NULL, `GoldMedals` INTEGER NOT NULL, `SilverMedals` INTEGER NOT NULL, `BronzeMedals` INTEGER NOT NULL;");
41}
42public void CheckIf_Players_QueryPassed(Database db, DBResultSet results, const char[] error, any data)
43{
44 if (db == null)
45 {
46 LogMessage("Could not create players table! Error: %s", error);
47 }
48 tablesCreated = true;
49}
50public void LoadPlayerData(int client)
51{
52 if (!tablesCreated)
53 {
54 LogMessage("Tables not yet created!");
55 CreateTimer(1.0, RepeatLoad, GetClientUserId(client));
56 return;
57 }
58 char query[512];
59 Format(query, sizeof(query), "SELECT * FROM `Players` WHERE `PlayerID`=%d", GetPlayerID(client));
60 DB.Query(LoadPlayerResults, query, GetClientUserId(client), DBPrio_High);
61}