· 7 years ago · Nov 10, 2018, 01:18 PM
1#include <sourcemod>
2#include <sdktools>
3
4#pragma semicolon 1
5#pragma newdecls required
6
7public Plugin myinfo =
8{
9 name = "Private Skins",
10 author = "Tonki_Ton",
11 version = "1.0",
12 url = "vk.com/tonki_ton"
13};
14
15KeyValues g_hSkinsKV;
16
17Database g_hSkinsDB;
18
19StringMap g_hSkins;
20
21public void OnPluginStart()
22{
23 g_hSkinsKV = new KeyValues("Private_Skins");
24 g_hSkins = new StringMap();
25
26 char sBuff[128], sFullCommString[128], sExplodedComms[4][16];
27
28 BuildPath(Path_SM, sBuff, sizeof(sBuff), "configs/private_skins.ini");
29 if (!g_hSkinsKV.ImportFromFile(sBuff))
30 SetFailState("Конфигурационный файл отÑутÑтвует!");
31
32 g_hSkinsKV.GetString("Commands", sFullCommString, sizeof(sFullCommString), "sm_slot;sm_lot");
33
34 int iMax = ExplodeString(sFullCommString, ";", sExplodedComms, 4, 16);
35 for (int i; i < iMax; ++i)
36 RegConsoleCmd(sExplodedComms[i], MainSkinsMenu);
37
38 if (SQL_CheckConfig("private_skins"))
39 Database.Connect(DBConnect, "private_skins", 0);
40 else {
41 KeyValues hKbDb = new KeyValues(NULL_STRING);
42 hKbDb.SetString("driver", "sqlite");
43 hKbDb.SetString("database", "private_skins");
44
45 char sError[256];
46 g_hSkinsDB = SQL_ConnectCustom(hKbDb, sError, sizeof(sError), false);
47
48 delete hKbDb;
49
50 DBConnect(g_hSkinsDB, sError, 1);
51 }
52
53 HookEvent("player_spawn", PS);
54}
55
56public void OnMapStart()
57{
58 g_hSkins.Clear();
59
60 char sBuff[64];
61
62 g_hSkinsKV.Rewind();
63 if (g_hSkinsKV.GotoFirstSubKey())
64 {
65 do
66 {
67 g_hSkinsKV.GetSectionName(sBuff, sizeof(sBuff));
68
69 if (g_hSkinsKV.GotoFirstSubKey(false))
70 {
71 char sPath[128], sName[64];
72 do
73 {
74 g_hSkinsKV.GetSectionName(sName, sizeof(sName));
75 g_hSkinsKV.GetString("model", sPath, sizeof(sPath));
76
77 g_hSkins.SetString(sName, sPath);
78
79 }
80 while (g_hSkinsKV.GotoNextKey(false));
81 g_hSkinsKV.GoBack();
82 }
83 }
84 while (g_hSkinsKV.GotoNextKey());
85 }
86}
87
88public void PS(Event hEvent, char[] sName, bool bDontBroadcast)
89{
90
91}
92
93public Action MainSkinsMenu(int iClient, int iArgs)
94{
95 Menu hMenu = new Menu(MainSkinsMenuHandler);
96
97 hMenu.SetTitle("Скины: Главное меню \n \n", iClient);
98
99 hMenu.AddItem("skins", "Скины");
100
101 hMenu.AddItem("admin", "ÐдминиÑтрирование", GetUserFlagBits(iClient) & ADMFLAG_ROOT ? ITEMDRAW_DEFAULT:ITEMDRAW_DISABLED);
102
103 hMenu.Display(iClient, 20);
104 return Plugin_Handled;
105}
106
107public int MainSkinsMenuHandler(Menu hMenu, MenuAction action, int iClient, int iPick)
108{
109 if (action == MenuAction_End)
110 delete hMenu;
111 else if (action == MenuAction_Select)
112 {
113 char sItem[24];
114 hMenu.GetItem(iPick, sItem, sizeof(sItem));
115
116 if (StrEqual(sItem, "skins"))
117 {
118 SkinsMenu(iClient);
119 }
120 else if (StrEqual(sItem, "admin"))
121 {
122 AdminMenu(iClient);
123 }
124 }
125}
126
127void SkinsMenu(int iClient)
128{
129 char sBuff[64], sSkinName[128];
130
131 Menu hMenu = new Menu(ChoiceMenuHandler);
132
133 hMenu.SetTitle("Выбор Ñкина", iClient);
134
135 g_hSkinsKV.Rewind();
136
137 if (g_hSkinsKV.JumpToKey("skins") && g_hSkinsKV.GotoFirstSubKey())
138 {
139 do
140 {
141 g_hSkinsKV.GetSectionName(sBuff, sizeof(sBuff));
142 g_hSkinsKV.GetString("Name", sSkinName, sizeof(sSkinName));
143
144 hMenu.AddItem(sBuff, sSkinName);
145 }
146 while (g_hSkinsKV.GotoNextKey());
147 }
148}
149
150public int ChoiceMenuHandler(Menu hMenu, MenuAction action, int iClient, int iPick)
151{
152 if (action == MenuAction_End)
153 delete hMenu;
154 else if (action == MenuAction_Select)
155 {
156 char sItem[64];
157 hMenu.GetItem(iPick, sItem, sizeof(sItem));
158
159 ChoicedSkinMenu(iClient, sItem);
160 }
161}
162
163void ChoicedSkinMenu(int iClient, const char[] sBuff)
164{
165 char sBuff[64], sBuff2[128];
166
167 Menu hMenu = new Menu(ChoiceMenuHandler);
168
169 g_hSkinsKV.Rewind();
170
171 g_hSkinsKV.GetString("%s/name", sBuff, sizeof(sBuff));
172 g_hSkinsKV.GetString("%s/info", sBuff, sizeof(sBuff));
173
174 hMenu.SetTitle("%s\n %s\n ", sBuff, sBuff2);
175}
176
177void AdminMenu(int iClient)
178{
179
180}
181
182////////////
183//DATABASE//
184////////////
185
186public void DBConnect(Database hDB, const char[] cError, any data)
187{
188 if (hDB == null || cError[0]) {
189 SetFailState("Database connect failure: %s", cError);
190 return;
191 }
192
193 char sDriver[16];
194 DBDriver hDBDriver = hDB.Driver;
195 hDBDriver.GetIdentifier(sDriver, sizeof(sDriver));
196
197 g_hSkinsDB = hDB;
198
199 if (StrEqual(sDriver, "sqlite", false))
200 g_hSkinsDB.Query(SQL_Callback_ErrorCheck, "CREATE TABLE IF NOT EXISTS `coc_base` (`auth` VARCHAR(32) NOT NULL,\
201 `name` VARCHAR(64) NOT NULL default 'unknown', `credit` INTEGER NOT NULL default '0',\
202 `expire` INTEGER NOT NULL default '0',`ban_expire` INTEGER NOT NULL default '0',\
203 `warnings` INTEGER NOT NULL default '0', `total` INTEGER NOT NULL default '0');");
204 else if (StrEqual(sDriver, "mysql", false))
205 g_hSkinsDB.Query(SQL_Callback_ErrorCheck, "CREATE TABLE IF NOT EXISTS `coc_base` (`auth` varchar(32) NOT NULL,\
206 `name` varchar(64) NOT NULL default 'unknown', `credit` int NOT NULL default 0,\
207 `expire` int NOT NULL default 0, `ban_expire` int NOT NULL default 0,\
208 `warnings` int NOT NULL default 0, `total` int NOT NULL default 0,\
209 PRIMARY KEY (`auth`)) DEFAULT CHARSET=utf8;");
210
211 g_hSkinsDB.SetCharset("utf8");
212
213 //for (int i = 1; i <= MaxClients; ++i)
214 // DBReg(i);
215}
216
217public void SQL_Callback_ErrorCheck(Database hOwner, DBResultSet hResults, const char[] sError, any data)
218{
219 if (hResults == null || sError[0])
220 LogError("SQL_Callback_ErrorCheck: %s", sError);
221}