· 8 years ago · May 18, 2018, 11:52 AM
1/*
2 INCLUDES
3 */
4#include <sourcemod>
5#include <cstrike>
6#include <sdktools>
7//#include <csgo_colors>
8
9/*
10 DEFINES
11 */
12#define XP_BY_KILL 50
13#define XP_BY_KILL_ADMIN 70
14#define LVL2 100
15#define LVL3 150
16#define LVL4 200
17#define LVL5 250
18#define LVL6 300
19#define LVL7 350
20#define LVL8 400
21#define LVL9 450
22#define LVL10 500
23#define LVL11 550
24#define LVL12 600
25#define LVL13 650
26#define LVL14 700
27#define LVL15 750
28#define LVL16 800
29#define LVL17 850
30#define LVL18 900
31#define LVL19 950
32#define LVL20 1000
33#define LVL21 1050
34#define LVL22 1100
35#define LVL23 1150
36
37/*
38 VARIABLES
39 */
40new String:PLAYER_WEAPON[32][MAXPLAYERS+1];
41new PLAYER_XP[MAXPLAYERS+1] = 0;
42new PLAYER_LVL[MAXPLAYERS+1] = 1;
43new PLAYER_KILLS[MAXPLAYERS+1];
44new Handle:INFO[MAXPLAYERS+1];
45new Handle:DATABASE = INVALID_HANDLE;
46new Handle:AUTOSAVE = INVALID_HANDLE;
47
48public Plugin:myinfo =
49{
50 name = "GunXPMod",
51 author = "Equiment",
52 version = "1.0"
53}
54
55public OnPluginStart()
56{
57 HookEvent("player_spawn", OnPlayerSpawn);
58 HookEvent("player_death", OnPlayerDeath);
59 ConnectToMysql();
60 RegAdminCmd("sm_setgunlvl", SetLVL, ADMFLAG_ROOT);
61}
62
63public OnMapStart() AUTOSAVE = CreateTimer(60.0, AutosaveTimer, _, TIMER_REPEAT);
64public OnMapEnd() KillTimer(AUTOSAVE);
65
66public Action:AutosaveTimer(Handle:timer)
67{
68 for (new i = 1; i <= MaxClients; i++)
69 {
70 if(IsClientInGame(i))
71 {
72 decl String:SteamID[64];
73 GetClientAuthId(i, AuthId_SteamID64, SteamID, sizeof(SteamID));
74 decl String:MysqlQuery[512];
75 Format(MysqlQuery, sizeof(MysqlQuery), "UPDATE gunxpmod_players SET exp = '%i', lvl = '%i' WHERE steamid = '%s'", PLAYER_XP[i], PLAYER_LVL[i], SteamID);
76 SQL_FastQuery(DATABASE, MysqlQuery);
77 }
78 }
79
80 PrintToChatAll("Stats saved!");
81}
82
83public Action:SetLVL(client, args)
84{
85 if (args < 1)
86 {
87 ReplyToCommand(client, "Use sm_setgunlvl $nick $lvl");
88 return Plugin_Handled;
89 }
90
91 decl String:string_nickname[65], String:string_lvl[3];
92 GetCmdArg(1, string_nickname, sizeof(string_nickname));
93 GetCmdArg(2, string_lvl, sizeof(string_lvl));
94 new NewLVL = StringToInt(string_lvl, 10);
95
96 decl String:target_name[MAX_TARGET_LENGTH];
97 decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
98
99 if ((target_count = ProcessTargetString(string_nickname,client,target_list,MAXPLAYERS,COMMAND_FILTER_ALIVE,target_name,sizeof(target_name),tn_is_ml)) <= 0)
100 {
101 ReplyToTargetError(client, target_count);
102 return Plugin_Handled;
103 }
104
105 for (new i = 0; i < target_count; i++)
106 {
107 new attacker = target_list[i];
108 PLAYER_LVL[attacker] = NewLVL;
109 if(GetClientTeam(attacker) == 2) GiveWeaponTT(attacker);
110 else if(GetClientTeam(attacker) == 3) GiveWeaponCT(attacker);
111
112 new ent;
113 new Float:PosPlayer[3];
114 GetClientAbsOrigin(attacker, PosPlayer);
115 PosPlayer[2] = PosPlayer[2] + 50.0;
116 ent = CreateEntityByName("info_particle_system");
117 DispatchKeyValue(ent , "start_active", "0");
118 DispatchKeyValue(ent, "effect_name", "weapon_confetti_balloons");
119 DispatchSpawn(ent);
120 TeleportEntity(ent , PosPlayer, NULL_VECTOR, NULL_VECTOR);
121 ActivateEntity(ent);
122 AcceptEntityInput(ent, "Start");
123 CreateTimer(2.0, Timer_RemoveEntity, any:ent);
124 ClientCommand(attacker, "play buttons/bell1.wav");
125 }
126
127 return Plugin_Handled;
128}
129
130stock ConnectToMysql()
131{
132 if(DATABASE != INVALID_HANDLE)
133 {
134 LogMessage("Disconnecting DATABASE connection");
135 CloseHandle(DATABASE);
136 DATABASE = INVALID_HANDLE;
137 }
138
139 decl String:dbname[64];
140 dbname = "GunXP";
141
142 if(!SQL_CheckConfig(dbname))
143 {
144 LogMessage("DATABASE configuration '%s' does not exist, using default.", dbname);
145 dbname = "default";
146 }
147
148 SQL_TConnect(OnSqlConnect, dbname);
149}
150
151public OnSqlConnect(Handle:owner, Handle:hndl, const String:error[], any:data)
152{
153 if (hndl == INVALID_HANDLE) LogError("Database failure: %s", error);
154 else
155 {
156 DATABASE = hndl;
157 SQL_FastQuery(DATABASE, "CREATE TABLE IF NOT EXISTS 'gunxpmod_players' (id INT NOT NULL AUTO_INCREMENT, steamid TEXT, lvl INT, exp INT);");
158 }
159}
160
161public OnClientPutInServer(client) SelectInfo(client);
162
163public OnClientDisconnect(client)
164{
165 decl String:SteamID[64];
166 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
167 decl String:MysqlQuery[512];
168 Format(MysqlQuery, sizeof(MysqlQuery), "UPDATE gunxpmod_players SET exp = '%i', lvl = '%i' WHERE steamid = '%s'", PLAYER_XP[client], PLAYER_LVL[client], SteamID);
169 SQL_FastQuery(DATABASE, MysqlQuery);
170}
171
172stock SelectInfo(client)
173{
174 decl String:SteamID[64];
175 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
176
177 decl String:MysqlQuery[512];
178 Format(MysqlQuery, sizeof(MysqlQuery), "SELECT exp, lvl FROM gunxpmod_players WHERE steamid = '%s'", SteamID);
179 SQL_TQuery(DATABASE, SelectEXP, MysqlQuery, GetClientUserId(client));
180}
181
182public InsertUser(Handle:owner, Handle:hndl, const String:error[], any:data)
183{
184 new client = GetClientOfUserId(data);
185 SelectInfo(client);
186}
187
188public SelectEXP(Handle:owner, Handle:hndl, const String:error[], any:data)
189{
190 new client = GetClientOfUserId(data);
191 if(error[0])
192 {
193 LogError("Error in Select Block: %s", error);
194 return;
195 }
196 if(!SQL_FetchRow(hndl))
197 {
198 decl String:SteamID[64];
199 GetClientAuthId(client, AuthId_SteamID64, SteamID, sizeof(SteamID));
200 decl String:MysqlQuery[512];
201 Format(MysqlQuery, sizeof(MysqlQuery), "INSERT INTO gunxpmod_players (steamid, exp, lvl) VALUES ('%s', '0', '1')", SteamID);
202 SQL_TQuery(DATABASE, InsertUser, MysqlQuery, GetClientUserId(client));
203 }
204 else
205 {
206 PLAYER_XP[client] = SQL_FetchInt(hndl, 0);
207 PLAYER_LVL[client] = SQL_FetchInt(hndl, 1);
208 INFO[client] = CreateTimer(1.0, Message, client, TIMER_REPEAT);
209 }
210
211}
212
213public Action:OnPlayerSpawn(Handle:event, const String:name[], bool:db)
214{
215 new client = GetClientOfUserId(GetEventInt(event, "userid"));
216 PLAYER_KILLS[client] = 0;
217 if(GetClientTeam(client) == 2) GiveWeaponTT(client);
218 else if(GetClientTeam(client) == 3) GiveWeaponCT(client);
219}
220
221public Action:OnPlayerDeath(Handle:event, const String:name[], bool:db)
222{
223 new client = GetClientOfUserId(GetEventInt(event, "userid"));
224 new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
225
226 PLAYER_KILLS[attacker]++;
227 if(PLAYER_KILLS[client] > 5) PrintToChatAll(" x\04KILLSTREAK] %N stopped killstreak %N!", attacker, client);
228
229 if(client != attacker && attacker > 0 && PLAYER_LVL[attacker] < 23)
230 {
231 if(GetUserFlagBits(attacker) & ADMFLAG_ROOT || GetUserFlagBits(attacker) & ADMFLAG_CUSTOM1) PLAYER_XP[attacker] = PLAYER_XP[attacker] + XP_BY_KILL_ADMIN;
232 else PLAYER_XP[attacker] = PLAYER_XP[attacker] + XP_BY_KILL;
233
234 if(PLAYER_KILLS[attacker] > 3) PLAYER_XP[attacker]++;
235
236 if( (PLAYER_XP[attacker] >= LVL2 && PLAYER_LVL[attacker] < 2) ||
237 (PLAYER_XP[attacker] >= LVL3 && PLAYER_LVL[attacker] < 3) ||
238 (PLAYER_XP[attacker] >= LVL4 && PLAYER_LVL[attacker] < 4) ||
239 (PLAYER_XP[attacker] >= LVL5 && PLAYER_LVL[attacker] < 5) ||
240 (PLAYER_XP[attacker] >= LVL6 && PLAYER_LVL[attacker] < 6) ||
241 (PLAYER_XP[attacker] >= LVL7 && PLAYER_LVL[attacker] < 7) ||
242 (PLAYER_XP[attacker] >= LVL8 && PLAYER_LVL[attacker] < 8) ||
243 (PLAYER_XP[attacker] >= LVL9 && PLAYER_LVL[attacker] < 9) ||
244 (PLAYER_XP[attacker] >= LVL10 && PLAYER_LVL[attacker] < 10) ||
245 (PLAYER_XP[attacker] >= LVL11 && PLAYER_LVL[attacker] < 11) ||
246 (PLAYER_XP[attacker] >= LVL12 && PLAYER_LVL[attacker] < 12) ||
247 (PLAYER_XP[attacker] >= LVL13 && PLAYER_LVL[attacker] < 13) ||
248 (PLAYER_XP[attacker] >= LVL14 && PLAYER_LVL[attacker] < 14) ||
249 (PLAYER_XP[attacker] >= LVL15 && PLAYER_LVL[attacker] < 15) ||
250 (PLAYER_XP[attacker] >= LVL16 && PLAYER_LVL[attacker] < 16) ||
251 (PLAYER_XP[attacker] >= LVL17 && PLAYER_LVL[attacker] < 17) ||
252 (PLAYER_XP[attacker] >= LVL18 && PLAYER_LVL[attacker] < 18) ||
253 (PLAYER_XP[attacker] >= LVL19 && PLAYER_LVL[attacker] < 19) ||
254 (PLAYER_XP[attacker] >= LVL20 && PLAYER_LVL[attacker] < 20) ||
255 (PLAYER_XP[attacker] >= LVL21 && PLAYER_LVL[attacker] < 21) ||
256 (PLAYER_XP[attacker] >= LVL22 && PLAYER_LVL[attacker] < 22) )
257 {
258 PLAYER_LVL[attacker]++;
259 PLAYER_XP[attacker] = 0;
260 if(GetClientTeam(attacker) == 2) GiveWeaponTT(attacker);
261 else if(GetClientTeam(attacker) == 3) GiveWeaponCT(attacker);
262
263 new ent;
264 new Float:PosPlayer[3];
265 GetClientAbsOrigin(attacker, PosPlayer);
266 PosPlayer[2] = PosPlayer[2] + 50.0;
267 ent = CreateEntityByName("info_particle_system");
268 DispatchKeyValue(ent , "start_active", "0");
269 DispatchKeyValue(ent, "effect_name", "weapon_confetti_balloons");
270 DispatchSpawn(ent);
271 TeleportEntity(ent , PosPlayer, NULL_VECTOR, NULL_VECTOR);
272 ActivateEntity(ent);
273 AcceptEntityInput(ent, "Start");
274 CreateTimer(2.0, Timer_RemoveEntity, any:ent);
275 ClientCommand(attacker, "play buttons/bell1.wav");
276 }
277 }
278}
279
280public Action:Message(Handle:timer, any:client)
281{
282 if(IsClientInGame(client))
283 {
284 if(IsPlayerAlive(client)) PrintHintText(client, "Poziom: <font color='#CD5D17'><b>%d</b></font> | Broń: <font color='#CD5D17'><b>%s</b></font>\nExp: <font color='#CD5D17'><b>%d/%d</b></font> | Seria zabójstw: <font color='#CD5D17'><b>%d</b></font>", PLAYER_LVL[client], PLAYER_WEAPON[client], PLAYER_XP[client], 50*(PLAYER_LVL[client]+1), PLAYER_KILLS[client]);
285 else if(GetEntProp(client, Prop_Send, "m_iObserverMode") == 4 || GetEntProp(client, Prop_Send, "m_iObserverMode") == 5)
286 {
287 new Target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
288
289 if (Target > 0)
290 {
291 PrintHintText(client, "Player: <font color='#CD5D17'><b>%N</b></font> | KILLSTREAK: <font color='#CD5D17'><b>%d</b></font>\nPoziom: <font color='#CD5D17'><b>%d</b></font> | Broń: <font color='#CD5D17'><b>%s</b></font>", Target, PLAYER_KILLS[Target], PLAYER_LVL[Target], PLAYER_WEAPON[Target]);
292 }
293 }
294 }
295}
296
297public Action:Timer_RemoveEntity(Handle:timer, any:fuck)
298{
299 AcceptEntityInput(fuck, "Stop");
300 AcceptEntityInput(fuck, "Kill");
301}
302
303
304stock GiveWeaponTT(client)
305{
306 decl weapon;
307 for(new i = 0; i <= 4; i++)
308 {
309 while((weapon = GetPlayerWeaponSlot(client, i)) != -1)
310 {
311 RemovePlayerItem(client, weapon);
312 AcceptEntityInput(weapon, "kill");
313 }
314 }
315
316 GivePlayerItem(client, "weapon_knife");
317 if(PLAYER_LVL[client] == 1)
318 {
319 GivePlayerItem(client, "weapon_glock");
320 PLAYER_WEAPON[client] = "Glock-18";
321 }
322 else if(PLAYER_LVL[client] == 2)
323 {
324 GivePlayerItem(client, "weapon_p250");
325 PLAYER_WEAPON[client] = "P250";
326 }
327 else if(PLAYER_LVL[client] == 3)
328 {
329 GivePlayerItem(client, "weapon_revolver");
330 PLAYER_WEAPON[client] = "R8 Revolver";
331 }
332 else if(PLAYER_LVL[client] == 4)
333 {
334 GivePlayerItem(client, "weapon_elite");
335 PLAYER_WEAPON[client] = "Dual Berettas";
336 }
337 else if(PLAYER_LVL[client] == 5)
338 {
339 GivePlayerItem(client, "weapon_tec9");
340 PLAYER_WEAPON[client] = "Tec-9";
341 }
342 else if(PLAYER_LVL[client] == 6)
343 {
344 GivePlayerItem(client, "weapon_deagle");
345 PLAYER_WEAPON[client] = "Desert Eagle";
346 }
347 else if(PLAYER_LVL[client] == 7)
348 {
349 GivePlayerItem(client, "weapon_nova");
350 PLAYER_WEAPON[client] = "Nova";
351 }
352 else if(PLAYER_LVL[client] == 8)
353 {
354 GivePlayerItem(client, "weapon_xm1014");
355 PLAYER_WEAPON[client] = "XM1014";
356 }
357 else if(PLAYER_LVL[client] == 9)
358 {
359 GivePlayerItem(client, "weapon_sawedoff");
360 PLAYER_WEAPON[client] = "Sawed-Off";
361 }
362 else if(PLAYER_LVL[client] == 10)
363 {
364 GivePlayerItem(client, "weapon_mag7");
365 PLAYER_WEAPON[client] = "MAG-7";
366 }
367 else if(PLAYER_LVL[client] == 11)
368 {
369 GivePlayerItem(client, "weapon_m249");
370 PLAYER_WEAPON[client] = "M249";
371 }
372 else if(PLAYER_LVL[client] == 12)
373 {
374 GivePlayerItem(client, "weapon_negev");
375 PLAYER_WEAPON[client] = "Negev";
376 }
377 else if(PLAYER_LVL[client] == 13)
378 {
379 GivePlayerItem(client, "weapon_mac10");
380 PLAYER_WEAPON[client] = "MAC-10";
381 }
382 else if(PLAYER_LVL[client] == 14)
383 {
384 GivePlayerItem(client, "weapon_mp7");
385 PLAYER_WEAPON[client] = "MP7";
386 }
387 else if(PLAYER_LVL[client] == 15)
388 {
389 GivePlayerItem(client, "weapon_bizon");
390 PLAYER_WEAPON[client] = "PP-Bizon";
391 }
392 else if(PLAYER_LVL[client] == 16)
393 {
394 GivePlayerItem(client, "weapon_ump45");
395 PLAYER_WEAPON[client] = "UMP-45";
396 }
397 else if(PLAYER_LVL[client] == 17)
398 {
399 GivePlayerItem(client, "weapon_p90");
400 PLAYER_WEAPON[client] = "P90";
401 }
402 else if(PLAYER_LVL[client] == 18)
403 {
404 GivePlayerItem(client, "weapon_galilar");
405 PLAYER_WEAPON[client] = "Galil AR";
406 }
407 else if(PLAYER_LVL[client] == 19)
408 {
409 GivePlayerItem(client, "weapon_ak47");
410 PLAYER_WEAPON[client] = "AK-47";
411 }
412 else if(PLAYER_LVL[client] == 20)
413 {
414 GivePlayerItem(client, "weapon_sg556");
415 PLAYER_WEAPON[client] = "SG 553";
416 }
417 else if(PLAYER_LVL[client] == 21)
418 {
419 GivePlayerItem(client, "weapon_ssg08");
420 PLAYER_WEAPON[client] = "SSG 08";
421 }
422 else if(PLAYER_LVL[client] == 22)
423 {
424 GivePlayerItem(client, "weapon_awp");
425 PLAYER_WEAPON[client] = "AWP";
426 }
427 else if(PLAYER_LVL[client] == 23)
428 {
429 GivePlayerItem(client, "weapon_g3sg1");
430 PLAYER_WEAPON[client] = "G3SG1";
431 }
432}
433
434stock GiveWeaponCT(client)
435{
436 decl weapon;
437 for(new i = 0; i <= 4; i++)
438 {
439 while((weapon = GetPlayerWeaponSlot(client, i)) != -1)
440 {
441 RemovePlayerItem(client, weapon);
442 AcceptEntityInput(weapon, "kill");
443 }
444 }
445
446 GivePlayerItem(client, "weapon_knife");
447 if(PLAYER_LVL[client] == 1)
448 {
449 GivePlayerItem(client, "weapon_usp_silencer");
450 PLAYER_WEAPON[client] = "USP";
451 }
452 else if(PLAYER_LVL[client] == 2)
453 {
454 GivePlayerItem(client, "weapon_p250");
455 PLAYER_WEAPON[client] = "P250";
456 }
457 else if(PLAYER_LVL[client] == 3)
458 {
459 GivePlayerItem(client, "weapon_revolver");
460 PLAYER_WEAPON[client] = "R8 Revolver";
461 }
462 else if(PLAYER_LVL[client] == 4)
463 {
464 GivePlayerItem(client, "weapon_elite");
465 PLAYER_WEAPON[client] = "Dual Berettas";
466 }
467 else if(PLAYER_LVL[client] == 5)
468 {
469 GivePlayerItem(client, "weapon_fiveseven");
470 PLAYER_WEAPON[client] = "Five-SeveN";
471 }
472 else if(PLAYER_LVL[client] == 6)
473 {
474 GivePlayerItem(client, "weapon_deagle");
475 PLAYER_WEAPON[client] = "Desert Eagle";
476 }
477 else if(PLAYER_LVL[client] == 7)
478 {
479 GivePlayerItem(client, "weapon_nova");
480 PLAYER_WEAPON[client] = "Nova";
481 }
482 else if(PLAYER_LVL[client] == 8)
483 {
484 GivePlayerItem(client, "weapon_xm1014");
485 PLAYER_WEAPON[client] = "XM1014";
486 }
487 else if(PLAYER_LVL[client] == 9)
488 {
489 GivePlayerItem(client, "weapon_sawedoff");
490 PLAYER_WEAPON[client] = "Sawed-Off";
491 }
492 else if(PLAYER_LVL[client] == 10)
493 {
494 GivePlayerItem(client, "weapon_mag7");
495 PLAYER_WEAPON[client] = "MAG-7";
496 }
497 else if(PLAYER_LVL[client] == 11)
498 {
499 GivePlayerItem(client, "weapon_m249");
500 PLAYER_WEAPON[client] = "M249";
501 }
502 else if(PLAYER_LVL[client] == 12)
503 {
504 GivePlayerItem(client, "weapon_negev");
505 PLAYER_WEAPON[client] = "Negev";
506 }
507 else if(PLAYER_LVL[client] == 13)
508 {
509 GivePlayerItem(client, "weapon_mp9");
510 PLAYER_WEAPON[client] = "MP9";
511 }
512 else if(PLAYER_LVL[client] == 14)
513 {
514 GivePlayerItem(client, "weapon_mp7");
515 PLAYER_WEAPON[client] = "MP7";
516 }
517 else if(PLAYER_LVL[client] == 15)
518 {
519 GivePlayerItem(client, "weapon_bizon");
520 PLAYER_WEAPON[client] = "PP-Bizon";
521 }
522 else if(PLAYER_LVL[client] == 16)
523 {
524 GivePlayerItem(client, "weapon_ump45");
525 PLAYER_WEAPON[client] = "UMP-45";
526 }
527 else if(PLAYER_LVL[client] == 17)
528 {
529 GivePlayerItem(client, "weapon_p90");
530 PLAYER_WEAPON[client] = "P90";
531 }
532 else if(PLAYER_LVL[client] == 18)
533 {
534 GivePlayerItem(client, "weapon_famas");
535 PLAYER_WEAPON[client] = "FAMAS";
536 }
537 else if(PLAYER_LVL[client] == 19)
538 {
539 GivePlayerItem(client, "weapon_m4a4");
540 PLAYER_WEAPON[client] = "M4A4";
541 }
542 else if(PLAYER_LVL[client] == 20)
543 {
544 GivePlayerItem(client, "weapon_aug");
545 PLAYER_WEAPON[client] = "AUG";
546 }
547 else if(PLAYER_LVL[client] == 21)
548 {
549 GivePlayerItem(client, "weapon_ssg08");
550 PLAYER_WEAPON[client] = "SSG 08";
551 }
552 else if(PLAYER_LVL[client] == 22)
553 {
554 GivePlayerItem(client, "weapon_awp");
555 PLAYER_WEAPON[client] = "AWP";
556 }
557 else if(PLAYER_LVL[client] == 23)
558 {
559 GivePlayerItem(client, "weapon_scar20");
560 PLAYER_WEAPON[client] = "SCAR-20";
561 }
562}