· 6 years ago · Jan 10, 2020, 01:20 AM
1/*
2===================================================================================================
3 Adaugare cutie noua.
4
5 Modifici : #define MaxCases [Cate cutii vrei]
6 Cauti functia void AddDropCase si adaugi sub toate noua cutie,id-ul sa fie precedentul + 1
7
8 Sansele de drop sa fie descrescator.
9===================================================================================================
10*/
11
12
13#define DEBUG
14
15#include <sourcemod>
16#include <cstrike>
17#include <csgo_colors>
18#include <LLGAlex>
19#include <shop>
20
21#define PLUGIN_AUTHOR "Alex"
22#define PLUGIN_VERSION "1.00"
23
24#pragma semicolon 1
25#pragma newdecls required
26
27public Plugin myinfo = {
28 name = "New Cases V2",
29 author = PLUGIN_AUTHOR,
30 description = "Descriere aici",
31 version = PLUGIN_VERSION,
32};
33
34#define MPS MAXPLAYERS+1
35char CaseMessage[512] = "{GREEN}{PLAYER} {OLIVE}a deschis {GREEN}{CASE} : {PURPLE} {PREMIU} {GREEN}[{TYPE}] {GREEN} -> {RED}[{DROP}%%%%%]";
36
37//============================================== CASE INFO ==============================================
38char CaseNameMySQL[][16] = {
39 "OMEGA",
40 "DUST",
41 "HONOR"
42};
43char KeyNameMySQL[][16] = {
44 "NORMALKEY"
45};
46//============================================== CASE INFO ==============================================
47
48//=========================================== DONT CHANGE THIS ==========================================
49const MaxCases = sizeof(CaseNameMySQL);
50const MaxKey = sizeof(KeyNameMySQL);
51//=========================================== DONT CHANGE THIS ==========================================
52
53Handle DB = INVALID_HANDLE;
54bool isDB;
55
56char g_sName[MPS][MAX_NAME_LENGTH];
57char g_sSafeName[MPS][MAX_NAME_LENGTH];
58char g_sSteamId[MPS][32];
59
60int g_iCaseValue[MPS][MaxCases];
61int g_iKeyValue[MPS][MaxKey];
62
63ArrayList g_aSansa[MaxCases];
64ArrayList g_aNameString[MaxCases];
65ArrayList g_aTypePremiu[MaxCases];
66ArrayList g_aValoareString[MaxCases];
67
68public void OnPluginStart() {
69 char IP[32];
70 LLGAlex_GetServerIP(IP, sizeof(IP));
71 if(StrEqual(IP, "89.40.104.217")){
72 CGOPrintToChatAll("{GREEN}OK");
73 }
74 else SetFailState("NewCase Bad IP :(");
75 AddDropCase();
76
77 if(DB == INVALID_HANDLE) {
78 SQL_TConnect(DBConnectCallBack, "LLGAlex_main");
79 }
80
81 RegAdminCmd("sm_drop", CMDDrop,ADMFLAG_ROOT, "");
82 RegAdminCmd("sm_droplist", CMDDropList,ADMFLAG_ROOT, "");
83 RegAdminCmd("sm_dropinfo", CMDDropList,ADMFLAG_ROOT, "");
84}
85
86void AddDropCase() {
87 for(int i = 0; i < MaxCases ; i++) {
88 g_aSansa[i] = CreateArray(1);
89 g_aNameString[i] = CreateArray(64);
90 g_aTypePremiu[i] = CreateArray(64);
91 g_aValoareString[i] = CreateArray(64);
92 }
93 //===============================================================================================================
94 // id | nr) Nume | (%)Drop | Tip Drop | Valoare |
95 //===============================================================================================================
96 LLGCase_AddDrop_ToCase( 0 , "1) Omega Case" , 50 , "credite" , "5 | 50" );
97 LLGCase_AddDrop_ToCase( 0 , "2) Omega Case" , 30 , "pulbere" , "1 | 2" );
98 LLGCase_AddDrop_ToCase( 0 , "3) Omega Case" , 10 , "fragment" , "1 | 1" );
99 LLGCase_AddDrop_ToCase( 0 , "4) Omega Case" , 5 , "chei" , "1 | 5" );
100 LLGCase_AddDrop_ToCase( 0 , "5) Omega Case" , 2 , "no-prize" , "Cutie goala" );
101 LLGCase_AddDrop_ToCase( 0 , "6) Omega Case" , 2 , "credite" , "1 | 100" );
102 LLGCase_AddDrop_ToCase( 0 , "7) Omega Case" , 1 , "lei" , "1 | 1" );
103 //===============================================================================================================
104 LLGCase_AddDrop_ToCase( 1 , "1) Dust Case" , 50 , "credite" , "500 | 5000" );
105 LLGCase_AddDrop_ToCase( 1 , "2) Dust Case" , 30 , "pulbere" , "100 | 200" );
106 LLGCase_AddDrop_ToCase( 1 , "3) Dust Case" , 10 , "fragment" , "100 | 100" );
107 LLGCase_AddDrop_ToCase( 1 , "4) Dust Case" , 5 , "chei" , "100 | 500" );
108 LLGCase_AddDrop_ToCase( 1 , "5) Dust Case" , 2 , "no-prize" , "Cutie goala" );
109 LLGCase_AddDrop_ToCase( 1 , "6) Dust Case" , 2 , "credite" , "100 | 10000" );
110 LLGCase_AddDrop_ToCase( 1 , "7) Dust Case" , 1 , "lei" , "100 | 100" );
111 //===============================================================================================================
112 LLGCase_AddDrop_ToCase( 2 , "1) Honor Case" , 50 , "credite" , "5000 | 50000" );
113 LLGCase_AddDrop_ToCase( 2 , "2) Honor Case" , 30 , "pulbere" , "1000 | 2000" );
114 LLGCase_AddDrop_ToCase( 2 , "3) Honor Case" , 10 , "fragment" , "1000 | 1000" );
115 LLGCase_AddDrop_ToCase( 2 , "4) Honor Case" , 5 , "chei" , "1000 | 5000" );
116 LLGCase_AddDrop_ToCase( 2 , "5) Honor Case" , 2 , "no-prize" , "Cutie goala" );
117 LLGCase_AddDrop_ToCase( 2 , "6) Honor Case" , 2 , "credite" , "1000 | 100000" );
118 LLGCase_AddDrop_ToCase( 2 , "7) Honor Case" , 1 , "lei" , "1000 | 1000" );
119 //===============================================================================================================
120 //LLGCase_AddDrop_ToCase( 1 , "Dust Case" , 30 , "pulbere" , "10 | 20");
121 //LLGCase_AddDrop_ToCase( 1 , "Honor Case" , 10 , "lei" , "1 | 10");
122 //LLGCase_AddDrop_ToCase( 1 , "Marble Case" , 5 , "skin" , "Voyager - [T]");
123 //LLGCase_AddDrop_ToCase( 1 , "Jackpot" , 1 , "lei" , "100 | 100");
124}
125
126public bool LLGCase_AddDrop_ToCase(int id,const char[] name, int sansa, const char[] type, const char[] val) {
127 if(g_aSansa[id].FindString(name) != -1) return false;
128
129 g_aSansa[id].Push(sansa);
130 g_aNameString[id].PushString(name);
131 g_aTypePremiu[id].PushString(type);
132 g_aValoareString[id].PushString(val);
133
134 return true;
135}
136
137int GetRandomFromString(char[] premiu,char[] val) {
138 char v1[2][8];
139 ExplodeString(premiu, "|", v1, sizeof(v1), sizeof(v1[]));
140
141 int min = StringToInt(v1[0]);
142 int max = StringToInt(v1[1]);
143 int rand = GetRandomInt(min,max);
144 Format(val, 32, "%i", rand);
145}
146
147public Action CMDDropList(int client, int args) {
148 char arg1[32];
149 int CaseNr = -1;
150 GetCmdArg(1, arg1, sizeof(arg1));
151
152 for(int i = 0; i < MaxCases; i++) {
153 if (StrEqual(arg1, CaseNameMySQL[i],false)) {
154 CaseNr = i;
155 }
156 }
157 PrintDrop(client,CaseNr);
158 return Plugin_Handled;
159}
160
161stock void PrintDrop(int client,int CaseNr) {
162 CGOPrintToChat(client, "");
163 CGOPrintToChat(client, "{GREEN}=========== {RED}%s CASE {GREEN}===========",CaseNameMySQL[CaseNr]);
164 for (int i = 0 ; i < g_aNameString[CaseNr].Length; i++) {
165 char name[64],type[32],premiu[64];
166 g_aNameString[CaseNr].GetString(i, name, sizeof(name));
167 g_aTypePremiu[CaseNr].GetString(i, type, sizeof(type));
168 g_aValoareString[CaseNr].GetString(i, premiu, sizeof(premiu));
169
170 int sansa = GetRarityWeight(CaseNr,name);
171
172 ReplaceString(premiu, sizeof(premiu),"|", "-");
173
174 CGOPrintToChat(client, "{GREEN}%i{BLUE}) {GREEN}%s {BLUE}- {PURPLE}%i%% {BLUE}- {GREEN}%s {BLUE}- {PURPLE}%s", i+1,name[3],sansa,premiu,type);
175 }
176 CGOPrintToChat(client, "{GREEN}=========== {RED}%s CASE {GREEN}===========",CaseNameMySQL[CaseNr]);
177}
178
179public Action CMDDrop(int client, int args) {
180 char ValString[32];
181 CGOPrintToChatAll("{PURPLE}==================================================");
182 for(int i=0;i<=2;i++){
183 int index = GetRandomRarity(i);
184
185 char name[64],type[32],premiu[64];
186 g_aNameString[i].GetString(index, name, sizeof(name));
187 g_aTypePremiu[i].GetString(index, type, sizeof(type));
188 g_aValoareString[i].GetString(index, premiu, sizeof(premiu));
189
190 int sansa = GetRarityWeight(i,name);
191 if (StrEqual(type, "lei") || StrEqual(type, "credite") || StrEqual(type, "pulbere") || StrEqual(type, "chei") || StrEqual(type, "fragment")){
192 GetRandomFromString(premiu,ValString);
193 }
194 else {
195 strcopy(ValString, sizeof(ValString), premiu);
196 }
197 GivePremiu(client,type,ValString);
198 ChatMessageFormat(client,name,ValString,type,sansa);
199 //CGOPrintToChatAll("%s {GREEN}- {PURPLE}%i%% {PURPLE}- {LIGHTBLUE}%s {PURPLE}- {GREEN}%s ", name, sansa,type,ValString);
200 }
201 CGOPrintToChatAll("{PURPLE}==================================================");
202 return Plugin_Handled;
203}
204
205void GivePremiu(int client,char[] type,char[] ValoarePremiu) {
206 int IntVar;
207 if(StrEqual(type, "credite")) {
208 IntVar = StringToInt(ValoarePremiu);
209 Shop_GiveClientCredits(client, IntVar);
210 }
211}
212
213char ChatMessageFormat(int client, char[] CaseName , char[] Premiu,char[] type,int Drop){
214 char Name[MAX_NAME_LENGTH], Message[512];
215 GetClientName(client, Name, sizeof(Name));
216 Format(Message, sizeof(Message), CaseMessage);
217
218 ReplaceString (Message, sizeof(Message) , "{PLAYER}" , Name);
219 ReplaceString (Message, sizeof(Message) , "{CASE}" , CaseName[3]);
220 ReplaceString (Message, sizeof(Message) , "{PREMIU}" , Premiu);
221 ReplaceString (Message, sizeof(Message) , "{TYPE}" , type);
222 ReplaceStringInt (Message, sizeof(Message) , "{DROP}" , Drop);
223
224 CGOPrintToChat(client, Message);
225}
226
227public int GetRarityWeight(int id,const char[] rarity) {
228 int index = g_aNameString[id].FindString(rarity);
229 if(index == -1)
230 return 0;
231
232 return g_aSansa[id].Get(index);
233}
234
235stock int GetRandomRarity(int id) {
236 int Sum, Total;
237
238 for(int i = 0; i < g_aNameString[id].Length; i++) {
239 char name[64];
240 g_aNameString[id].GetString(i, name, sizeof(name));
241
242 Sum += GetRarityWeight(id,name);
243 }
244
245 int Random = GetRandomInt(0, Sum - 1);
246
247 for(int i = 0; i < g_aNameString[id].Length; i++) {
248 char name[64];
249 g_aNameString[id].GetString(i, name, sizeof(name));
250
251 Total += GetRarityWeight(id,name);
252 if(Total > Random)
253 return i;
254 }
255 return -1;
256}
257
258stock void ReplaceStringInt(char[] message, int len, const char[] replace,int value, bool caseSensitive = false) {
259 char intString[16];
260 IntToString(value, intString, sizeof(intString));
261 ReplaceString(message, len, replace, intString, caseSensitive);
262}
263
264public int DBConnectCallBack(Handle owner, Handle hndl, char [] error, any data) {
265 char SqlBuff[1024];
266 if(hndl == INVALID_HANDLE) {
267 LogError("Database failure: %s", error);
268 SetFailState("Databases dont work (Contacteaza-l pe Alex.:(");
269 }
270 else {
271 DB = hndl;
272 char driv[16];
273 SQL_GetDriverIdent(owner, driv, sizeof(driv));
274 isDB = StrEqual(driv, "mysql", false) ? true : false;
275 if(isDB) {
276 LogError("Cases Table Created");
277 Format(SqlBuff, sizeof(SqlBuff), "CREATE TABLE IF NOT EXISTS `NewCases` (\
278 `id` int(11) NOT NULL AUTO_INCREMENT,\
279 `steamid` varchar(32) NOT NULL,\
280 `name` varchar(64) NOT NULL,\
281 `Value1` varchar(64) NOT NULL COMMENT 'text',\
282 `Value2` int(11) NOT NULL DEFAULT 0 COMMENT 'int',\
283 PRIMARY KEY (`id`)\
284 )");
285 SQL_TQuery(DB, SimpleCallBack, SqlBuff);
286 }
287 }
288 for (int i=1 ;i<=MaxClients ; i++){
289 if(IsValidClient(i)) OnClientPutInServer(i);
290 }
291}
292
293public void OnClientPutInServer(int client) {
294 if (IsValidClient(client)) {
295 GetClientAuthId(client, AuthId_Steam2, g_sSteamId[client], sizeof(g_sSteamId[]));
296 GetClientName(client, g_sName[client], sizeof(g_sName[]));
297 SQL_EscapeString(DB, g_sName[client], g_sSafeName[client], sizeof(g_sSafeName));
298 InsertToMySQL(client);
299 }
300}
301
302public void InsertToMySQL(int client) {
303 if (IsValidClient(client)) {
304 char PutInQuerryCase[2000];
305 for (int i = 0; i < MaxCases; i++) {
306 Format(PutInQuerryCase, sizeof(PutInQuerryCase), "SELECT `Value2` FROM `NewCases` WHERE `steamid` = '%s' AND `Value1` = '%s'", g_sSteamId[client],CaseNameMySQL[i]);
307
308 DataPack SelectPack = new DataPack();
309 SelectPack.WriteCell(GetClientUserId(client));
310 SelectPack.WriteCell(i);
311 SelectPack.WriteCell(0);
312
313 SQL_TQuery(DB, JoinSelectDataCallBack, PutInQuerryCase, SelectPack);
314 }
315 for (int i = 0; i < MaxKey; i++) {
316 Format(PutInQuerryCase, sizeof(PutInQuerryCase), "SELECT `Value2` FROM `NewCases` WHERE `steamid` = '%s' AND `Value1` = '%s'", g_sSteamId[client],KeyNameMySQL[i]);
317
318 DataPack SelectPack = new DataPack();
319 SelectPack.WriteCell(GetClientUserId(client));
320 SelectPack.WriteCell(i);
321 SelectPack.WriteCell(1);
322
323 SQL_TQuery(DB, JoinSelectDataCallBack, PutInQuerryCase, SelectPack);
324 }
325
326 }
327}
328
329public int JoinSelectDataCallBack(Handle owner, Handle hndl, char [] error, DataPack SelectPack) {
330 char Query[512];
331
332 SelectPack.Reset();
333 int client = GetClientOfUserId(SelectPack.ReadCell());
334 int Id = SelectPack.ReadCell();
335 int Type = SelectPack.ReadCell(); // 0 - Case | 1 - Key
336 delete SelectPack;
337
338 if (client == 0) return;
339
340 if (SQL_GetRowCount(hndl) == 0) {
341 Format(Query, sizeof(Query), "INSERT INTO NewCases (`steamid`,`name`,`Value1`,`Value2`) VALUES ('%s','%s','%s',0)", g_sSteamId[client], g_sSafeName[client],Type == 0 ? CaseNameMySQL[Id] : KeyNameMySQL[Id]);
342 SQL_TQuery(DB, SimpleCallBack, Query, GetClientUserId(client));
343 switch(Type){
344 case 0 : {
345 g_iCaseValue[client][Id] = 0;
346 }
347 case 1 : {
348 g_iKeyValue[client][Id] = 0;
349 }
350 default : LogError("NEW-CASE error in `default` case");
351 }
352 return;
353 }
354 if(SQL_FetchRow(hndl)){
355 switch(Type){
356 case 0 : {
357 g_iCaseValue[client][Id] = SQL_FetchInt(hndl, 0);
358 }
359 case 1 : {
360 g_iKeyValue[client][Id] = SQL_FetchInt(hndl, 0);
361 }
362 default : LogError("NEW-CASE error in `default` case");
363 }
364 return;
365 }
366}
367
368public int SimpleCallBack(Handle owner, Handle hndl, char [] error, any data) {
369 if(hndl == INVALID_HANDLE){
370 LogError("Cases DB Error");
371 return;
372 }
373}
374
375stock bool IsValidClient(int iClient) {
376 return (iClient > 0 && iClient < MaxClients && IsClientInGame(iClient) && !IsFakeClient(iClient));
377}
378
379
380//210