· 6 years ago · Sep 09, 2019, 03:26 PM
1#define DEBUG
2
3#include <sourcemod>
4#include <Lei>
5#include <sdktools>
6#include <cstrike>
7#include <csgo_colors>
8//#include <sdkhooks>
9#define PLUGIN_AUTHOR "Alex"
10#define PLUGIN_VERSION "1.00"
11
12#pragma semicolon 1
13#pragma newdecls required
14
15public Plugin myinfo = {
16 name = "Cases",
17 author = PLUGIN_AUTHOR,
18 description = "Descriere aici",
19 version = PLUGIN_VERSION,
20};
21
22#define MPS MAXPLAYERS+1
23
24Handle DB = INVALID_HANDLE;
25bool isDB;
26
27char pluginname[256];
28char g_sAddress[32];
29
30char g_sName[MPS][MAX_NAME_LENGTH];
31char g_sSteamId[MPS][32];
32
33int g_iOmega[MPS];
34int g_iStar[MPS];
35int g_iGlove[MPS];
36int g_iKey[MPS];
37
38public void OnPluginStart() {
39 //DatabaseConnect();
40 if(DB == INVALID_HANDLE) {
41 SQL_TConnect(DBConnectCallBack, "cases");
42 }
43
44 RegConsoleCmd("sm_cases", CMDCase, "");
45 RegConsoleCmd("sm_case", CMDCase, "");
46
47 Handle plugin = GetMyHandle();
48 GetPluginFilename(plugin, pluginname, sizeof(pluginname));
49 GetServerIP();
50
51 if (StrEqual(g_sAddress, "188.212.102.88")) {
52 CGOPrintToChatAll("{GREEN}Pluginul {RED}Cases {GREEN}a fost incarcat cu {RED}succes.");
53 }
54 else {
55 //ServerCommand("sm plugins unload %s", pluginname);
56 //SetFailState("Pluginul Cases a fost oprit");
57 //CGOPrintToChatAll("{GREEN}Pluginul {RED}FreeDay {GREEN}a fost oprit.");
58 }
59 for(int i = 1; i <= MaxClients; i++){
60 if(IsValidClient(i)) {
61 OnClientPutInServer(i);
62 }
63 }
64}
65
66public void OnClientPutInServer(int client) {
67 if (IsValidClient(client)) {
68 GetClientAuthId(client, AuthId_Steam2, g_sSteamId[client], sizeof(g_sSteamId[]));
69 GetClientName(client, g_sName[client], sizeof(g_sName[]));
70 CaseData(client);
71 }
72}
73
74public void CaseData(int client) {
75 if (IsValidClient(client)) {
76 char PutInQuerryCase[2000];
77 PrintToChatAll("%s s", g_sSteamId[client]);
78 Format(PutInQuerryCase, sizeof(PutInQuerryCase), "SELECT `omegacase`,`starcase`,`glovecase`,`key` FROM Cases WHERE steamid = '%s'", g_sSteamId[client]);
79 SQL_TQuery(DB, JoinSelectDataCallBack, PutInQuerryCase, GetClientUserId(client));
80 }
81}
82
83public int DBConnectCallBack(Handle owner, Handle hndl, char [] error, any data) {
84 char SqlBuff[1024];
85 if(hndl == INVALID_HANDLE) {
86 LogError("Database failure: %s", error);
87 SetFailState("Databases dont work");
88 }
89 else {
90 DB = hndl;
91 char driv[16];
92 SQL_GetDriverIdent(owner, driv, sizeof(driv));
93 isDB = StrEqual(driv, "mysql", false) ? true : false;
94 if(isDB)
95 {
96 LogError("Cases Table Created");
97 Format(SqlBuff, sizeof(SqlBuff), "CREATE TABLE IF NOT EXISTS `Cases` (\
98 `id` int(11) NOT NULL AUTO_INCREMENT,\
99 `steamid` varchar(32) NOT NULL,\
100 `name` varchar(64) NOT NULL,\
101 `omegacase` int(11) NOT NULL,\
102 `glovecase` int(11) NOT NULL,\
103 `starcase` int(11) NOT NULL,\
104 `key` int(11) NOT NULL,\
105 PRIMARY KEY (`id`),\
106 UNIQUE KEY `steamid` (`steamid`)\
107 )");
108 SQL_TQuery(DB, OnSQLConnectCallback, SqlBuff);
109 }
110 }
111}
112
113public int JoinSelectDataCallBack(Handle owner, Handle hndl, char [] error, int data) {
114 char Query[512];
115 int client = GetClientOfUserId(data);
116 if (client == 0) return;
117
118 if (SQL_GetRowCount(hndl) == 0) {
119 Format(Query, sizeof(Query), "INSERT INTO Cases (`steamid`,`name`,`omegacase`,`glovecase`,`starcase`,`key`) VALUES ('%s','%s',0,0,0,0)", g_sSteamId[client], g_sName[client]);
120 SQL_TQuery(DB, FirstInsertCallBack, Query, GetClientOfUserId(client));
121 g_iOmega[client] = 0;
122 g_iStar[client] = 0;
123 g_iGlove[client] = 0;
124 g_iKey[client] = 0;
125 }
126 else if (SQL_FetchRow(hndl)) {
127 g_iOmega[client] = SQL_FetchInt(hndl, 0);
128 g_iStar[client] = SQL_FetchInt(hndl, 1);
129 g_iGlove[client] = SQL_FetchInt(hndl, 2);
130 g_iKey[client] = SQL_FetchInt(hndl, 3);
131 }
132}
133
134public int FirstInsertCallBack(Handle owner, Handle hndl, char [] error, any data) {
135 if(hndl == INVALID_HANDLE) {
136 LogError("%s Eroare cases",error);
137 return;
138 }
139}
140public int OnSQLConnectCallback(Handle owner, Handle hndl, char [] error, any data) {
141 if(hndl == INVALID_HANDLE){
142 LogError("Cases DB Error");
143 return;
144 }
145}
146
147stock void GetServerIP() {
148 int iHostIP = FindConVar("hostip").IntValue;
149 FormatEx(g_sAddress, sizeof(g_sAddress), "%d.%d.%d.%d", (iHostIP >> 24) & 0x000000FF, (iHostIP >> 16) & 0x000000FF, (iHostIP >> 8) & 0x000000FF, iHostIP & 0x000000FF);
150}
151
152stock bool IsValidClient(int iClient) {
153 return (iClient > 0 && iClient < MaxClients && IsClientInGame(iClient) && !IsFakeClient(iClient));
154}
155
156public Action CMDCase(int client, int args) {
157 char OmegaCaseFormat[255], GloveCaseFormat[255], StarCaseFormat[255], KeyTitleFormat[255];
158 Menu casemenu = new Menu(HandMenuCase, MenuAction_Select | MenuAction_End | MenuAction_DisplayItem);
159
160 Format(KeyTitleFormat, sizeof(KeyTitleFormat), "[Case Opening] Panou cutii\n \nCheile tale : %i \n \n", g_iKey[client]);
161 Format(OmegaCaseFormat, sizeof(OmegaCaseFormat), "Omega Case : %i", g_iOmega[client]);
162 Format(GloveCaseFormat, sizeof(GloveCaseFormat), "Star Case : %i", g_iStar[client]);
163 Format(StarCaseFormat, sizeof(StarCaseFormat), "Glove Case : %i", g_iGlove[client]);
164
165 SetMenuTitle(casemenu, KeyTitleFormat);
166 AddMenuItem(casemenu, "omega",OmegaCaseFormat);
167 AddMenuItem(casemenu, "star",GloveCaseFormat);
168 AddMenuItem(casemenu, "glove",StarCaseFormat);
169 AddMenuItem(casemenu, "blanc", "blanc",ITEMDRAW_SPACER);
170 AddMenuItem(casemenu, "buykey", "Cumpara o cheie (1000 credite).");
171 DisplayMenu(casemenu, client, MENU_TIME_FOREVER);
172 return Plugin_Handled;
173}
174
175public int HandMenuCase(Handle menu, MenuAction action, int client, int param2) {
176 switch (action) {
177 case MenuAction_Select: {
178 char item[64];
179 GetMenuItem(menu, param2, item, sizeof(item));
180
181 /*
182 if (StrEqual(item, "lei")) {
183 Menu menulei = new Menu(HandMenu);
184 SetMenuTitle(menulei, "[LLG] Shop lei \n \n");
185 AddMenuItem(menulei, "vipl", "Cumpara VIP.");
186 AddMenuItem(menulei, "credite", "Credite.");
187 AddMenuItem(menulei, "bpl", "BattlePass.");
188 SetMenuExitButton(menulei, true);
189 DisplayMenu(menulei, client, MENU_TIME_FOREVER);
190 }
191 */
192 }
193 case MenuAction_End: {
194 CloseHandle(menu);
195 }
196 case MenuAction_DisplayItem: {
197 char item[64];
198 GetMenuItem(menu, param2, item, sizeof(item));
199 }
200 }
201}