· 5 years ago · Feb 08, 2020, 11:08 PM
1#pragma semicolon 1
2#include <sourcemod>
3#include <sdktools>
4#include <sdkhooks>
5#include <multicolors>
6#include <entity>
7#include <cstrike>
8
9#define CASE_KNIFE 0
10#define CS_TEAM_SPECTATOR 1
11#define CS_TEAM_T 2
12#define CS_TEAM_CT 3
13
14
15#define IloscKlas 12
16#define LimitPoziomu 255
17#define IloscExpaZaKilla 2
18#define ExpMultiplier 1.0
19#define DamageMultiplier 1.05
20#define ReductionMultiplier 0.05
21#define SpeedMulttplier 0.01
22#define HealthMultiplayer 1.0
23
24Database DB;
25
26int g_iKlasa[MAXPLAYERS];
27int g_iPoziom[MAXPLAYERS][IloscKlas];
28int g_iDoswiadczenie[MAXPLAYERS][IloscKlas];
29char Nazwaklasy[][] =
30{
31 "Ninja [P]",
32 "Alien [P]",
33 "X [P]",
34 "Y [P]",
35 "Profesjonalista",
36 "Skoczek",
37 "Charger",
38 "Sprinter",
39 "Klasa5",
40 "Klasa6",
41 "Klasa7",
42 "Klasa8"
43};
44
45new const g_aNeededExp[] = {
46 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000,
47 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000,
48 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000,
49 5100, 5200, 5300, 5400, 5500, 5600, 5700, 5800, 5900, 6000, 6100, 6200, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000,
50 7100, 7200, 7300, 7400, 7500, 7600, 7700, 7800, 7900, 8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8800, 8900, 9000,
51 9100, 9200, 9300, 9400, 9500, 9600, 9700, 9800, 9900, 10000, 10100, 10200, 10300, 10400, 10500, 10600, 10700, 10800, 10900, 11000,
52 11100, 11200, 11300, 11400, 11500, 11600, 11700, 11800, 11900, 12000, 12100, 12200, 12300, 12400, 12500, 12600, 12700, 12800, 12900, 13000,
53 13100, 13200, 13300, 13400, 13500, 13600, 13700, 13800, 13900, 14000, 14100, 14200, 14300, 14400, 14500, 14600, 14700, 14800, 14900, 15000,
54 15100, 15200, 15300, 15400, 15500, 15600, 15700, 15800, 15900, 16000, 16100, 16200, 16300, 16400, 16500, 16600, 16700, 16800, 16900, 17000,
55 17100, 17200, 17300, 17400, 17500, 17600, 17700, 17800, 17900, 18000, 18100, 18200, 18300, 18400, 18500, 18600, 18700, 18800, 18900, 19000,
56 19100, 19200, 19300, 19400, 19500, 19600, 19700, 19800, 19900, 20000, 20100, 20200, 20300, 20400, 20500, 20600, 20700, 20800, 20900, 21000,
57 21100, 21200, 21300, 21400, 21500, 21600, 21700, 21800, 21900, 22000, 22100, 22200, 22300, 22400, 22500, 22600, 22700, 22800, 22900, 23000,
58 23100, 23200, 23300, 23400, 23500, 23600, 23700, 23800, 23900, 24000, 24100, 24200, 24300, 24400, 24500, 24600, 24700, 24800, 24900, 25000,
59 25100, 25200, 25300
60};
61
62public Plugin myinfo =
63{
64 name = "[ReGi] KlasyDeathrun",
65 author = "ReGi",
66 description = "KlasyDeathrun",
67 version = "1.0",
68 url = "plox.gameclan.pl"
69};
70
71public void OnPluginStart()
72{
73 RegConsoleCmd("sm_klasa", CMD_Klasa);
74 //HookEvent("round_start", RoundStartEvent);
75 //HookEvent("round_end", RoundEndEvent);
76 HookEvent("player_spawn", SpawnEvent);
77 HookEvent("player_death", DeathEvent);
78 //HookEvent("player_hurt", HurtEvent);
79 HookEventEx("bomb_planted", Event_BombPlanted);
80 HookEventEx("bomb_defused", Event_BombDefused);
81
82 char error[512];
83 DB = SQL_Connect("regi_klasydr", true, error, sizeof(error));
84 if (DB == INVALID_HANDLE)
85 {
86 LogError("[Klasy] Error podczas polaczenia z baza: %s", error);
87 }
88 else
89 {
90 char sQuery1[1024];
91 Format(sQuery1, sizeof(sQuery1), "CREATE TABLE IF NOT EXISTS `regi_deathrun` (`SteamID` INT NOT NULL PRIMARY KEY UNIQUE, `Nick` VARCHAR(255) NOT NULL,`Pexpone` INT NOT NULL, `Pexptwo` INT NOT NULL,`Pexpthree` INT NOT NULL,`Pexpfour` INT NOT NULL,`Nexpone` INT NOT NULL,`Nexptwo` INT NOT NULL,`Nexpthree` INT NOT NULL,`Nexpfour` INT NOT NULL,`Nexpfive` INT NOT NULL,`Nexpsix` INT NOT NULL,`Nexpseven` INT NOT NULL,`Nexpeight` INT NOT NULL);");
92 if (!SQL_FastQuery(DB, sQuery1))
93 {
94 SQL_GetError(DB, error, sizeof(error));
95 LogError("[Klasy] Could not create players table! Error: %s", error);
96 return;
97 }
98 }
99}
100
101public Action CMD_Klasa(int client, int args)
102{
103 char BufferKlas[250];
104 Menu menu = new Menu(Klasy_Handler);
105 menu.SetTitle("★ Wybierz Klasę ★");
106 Format(BufferKlas, sizeof(BufferKlas), "Ninja [P] [%d|Lv]",g_iPoziom[client][0]);
107 menu.AddItem("",BufferKlas);
108 Format(BufferKlas, sizeof(BufferKlas), "Alien [P][%d|Lv]",g_iPoziom[client][1]);
109 menu.AddItem("",BufferKlas);
110 Format(BufferKlas, sizeof(BufferKlas), "X [P][%d|Lv]",g_iPoziom[client][2]);
111 menu.AddItem("",BufferKlas);
112 Format(BufferKlas, sizeof(BufferKlas), "Y [P][%d|Lv]",g_iPoziom[client][3]);
113 menu.AddItem("",BufferKlas);
114 Format(BufferKlas, sizeof(BufferKlas), "Profesjonalista [%d|Lv]",g_iPoziom[client][4]);
115 menu.AddItem("",BufferKlas);
116 Format(BufferKlas, sizeof(BufferKlas), "Skoczek [%d|Lv]",g_iPoziom[client][5]);
117 menu.AddItem("",BufferKlas);
118 Format(BufferKlas, sizeof(BufferKlas), "Charger [%d|Lv]",g_iPoziom[client][6]);
119 menu.AddItem("",BufferKlas);
120 Format(BufferKlas, sizeof(BufferKlas), "Sprinter [%d|Lv]",g_iPoziom[client][7]);
121 menu.AddItem("",BufferKlas);
122 Format(BufferKlas, sizeof(BufferKlas), "Klasa5 [%d|Lv]",g_iPoziom[client][8]);
123 menu.AddItem("",BufferKlas);
124 Format(BufferKlas, sizeof(BufferKlas), "Klasa6 [%d|Lv]",g_iPoziom[client][9]);
125 menu.AddItem("",BufferKlas);
126 Format(BufferKlas, sizeof(BufferKlas), "Klasa7 [%d|Lv]",g_iPoziom[client][10]);
127 menu.AddItem("",BufferKlas);
128 Format(BufferKlas, sizeof(BufferKlas), "Klasa8 [%d|Lv]",g_iPoziom[client][11]);
129 menu.AddItem("",BufferKlas);
130 menu.Display(client, 120);
131}
132
133public int Klasy_Handler(Menu menu, MenuAction action, int client, int pozycja)
134{
135 if (action == MenuAction_End)
136 {
137 delete menu;
138 }
139 else if(action==MenuAction_Select)
140 {
141 g_iKlasa[client]=pozycja;
142 //AutoPoziomGracza(client,g_iKlasa[client]);
143 CPrintToChat(client, "{green}Wybrana Klasa to : {orange}%s", Nazwaklasy[pozycja]);
144 }
145}
146
147public void WczytajDane(int client)
148{
149 int sid = GetSteamAccountID(client);
150 char name[64];
151 char sQuery[1024];
152 char bufferq[512];
153 Format(bufferq,sizeof(bufferq), "SELECT Pexpone,Pexptwo,Pexpthree,Pexpfour,Nexpone,Nexptwo,Nexpthree,Nexpfour,Nexpfive,Nexpsix,Nexpseven,Nexpeight FROM `regi_deathrun` WHERE `SteamID`=%d;",sid);
154 DBResultSet query = SQL_Query(DB, bufferq);
155 if (query == null)
156 {
157 char error[255];
158 SQL_GetError(DB, error, sizeof(error));
159 LogError("Failed to query (error: %s)", error);
160 return;
161 }
162 if(!SQL_GetRowCount(query))
163 {
164 GetClientName(client, name, sizeof(name));
165 Format(sQuery, sizeof(sQuery),"INSERT INTO `regi_deathrun` VALUES(%d,'%s',0,0,0,0,0,0,0,0,0,0,0,0)", sid,name);
166 if (!SQL_FastQuery(DB, sQuery))
167 {
168 char error[255];
169 SQL_GetError(DB, error, sizeof(error));
170 LogError("[Klasy] Error: %s", error);
171 }
172 return;
173 }
174
175 while (SQL_FetchRow(query))
176 {
177 g_iDoswiadczenie[client][0]=SQL_FetchInt(query, 0);
178 g_iDoswiadczenie[client][1]=SQL_FetchInt(query, 1);
179 g_iDoswiadczenie[client][2]=SQL_FetchInt(query, 2);
180 g_iDoswiadczenie[client][3]=SQL_FetchInt(query, 3);
181 g_iDoswiadczenie[client][4]=SQL_FetchInt(query, 4);
182 g_iDoswiadczenie[client][5]=SQL_FetchInt(query, 5);
183 g_iDoswiadczenie[client][6]=SQL_FetchInt(query, 6);
184 g_iDoswiadczenie[client][7]=SQL_FetchInt(query, 7);
185 g_iDoswiadczenie[client][8]=SQL_FetchInt(query, 8);
186 g_iDoswiadczenie[client][9]=SQL_FetchInt(query, 9);
187 g_iDoswiadczenie[client][10]=SQL_FetchInt(query, 10);
188 g_iDoswiadczenie[client][11]=SQL_FetchInt(query, 11);
189 }
190}
191
192public void ZapiszDane(int client)
193{
194 int sid = GetSteamAccountID(client);
195 char sQuery[1024];
196 Format(sQuery, sizeof(sQuery), "UPDATE `regi_deathrun` SET Pexpone=%d,Pexptwo=%d,Pexpthree=%d,Pexpfour=%d,Nexpone=%d,Nexptwo=%d,Nexpthree=%d,Nexpfour=%d,Nexpfive=%d,Nexpsix=%d,Nexpseven=%d,Nexpeight=%d WHERE SteamID=%d;",g_iDoswiadczenie[client][0],g_iDoswiadczenie[client][1],g_iDoswiadczenie[client][2],g_iDoswiadczenie[client][3],g_iDoswiadczenie[client][4],g_iDoswiadczenie[client][5],g_iDoswiadczenie[client][6],g_iDoswiadczenie[client][7],g_iDoswiadczenie[client][8],g_iDoswiadczenie[client][9],g_iDoswiadczenie[client][10],g_iDoswiadczenie[client][11] ,sid);
197 if (!SQL_FastQuery(DB, sQuery))
198 {
199 char error[255];
200 SQL_GetError(DB, error, sizeof(error));
201 PrintToServer("Failed to query (error: %s)", error);
202 }
203}
204
205/*public void AutoPoziomGracza(int client, int klasa)
206{
207 g_iPoziom[client][klasa]=0;
208 while(g_iDoswiadczenie[client][klasa] >= g_aNeededExp[g_iPoziom[client][klasa]] && g_iPoziom[client][klasa] < LimitPoziomu)
209 {
210 g_iPoziom[client][klasa]++;
211 }
212}*/
213
214public void AutoPoziomGracza2(int client)
215{
216 for(int i=0;i<IloscKlas;i++)
217 {
218 g_iPoziom[client][i]=0;
219 while(g_iDoswiadczenie[client][i] >= g_aNeededExp[g_iPoziom[client][i]] && g_iPoziom[client][i] < LimitPoziomu)
220 {
221 g_iPoziom[client][i]++;
222 }
223 }
224}
225
226public int UntilNextLevel(int client)
227{
228 return (g_aNeededExp[g_iPoziom[client][g_iKlasa[client]]]+1);
229}
230
231public void OnClientPutInServer(client)
232{
233 SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
234 //SDKHook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost);
235 /*SDKHook(client, SDKHook_PreThink, Prethink);
236 SDKHook(client, SDKHook_TraceAttack, TraceAttack);*/
237 if(IsValidClient(client)&&!IsClientSourceTV(client))
238 {
239 for(int i=0;i<IloscKlas;i++)
240 {
241 g_iPoziom[client][i]=0;
242 g_iDoswiadczenie[client][i]=0;
243 }
244 g_iKlasa[client] = -1;
245 WczytajDane(client);
246 AutoPoziomGracza2(client);
247 }
248}
249
250public void OnClientDisconnect(client)
251{
252 SDKUnhook(client, SDKHook_OnTakeDamage, OnTakeDamage);
253 //SDKUnhook(client, SDKHook_WeaponSwitchPost, OnWeaponSwitchPost);
254 /*SDKUnhook(client, SDKHook_PreThink, Prethink);
255 SDKUnhook(client, SDKHook_TraceAttack, TraceAttack);*/
256 ZapiszDane(client);
257}
258
259/*public void RoundStartEvent(Event event, const char[] name, bool dontBroadcast) {
260{
261 //int client = GetClientOfUserId(GetEventInt(event, "userid"));
262}
263
264public void RoundEndEvent(Event event, const char[] name, bool dontBroadcast) {
265{
266 //int client = GetClientOfUserId(GetEventInt(event, "userid"));
267}*/
268
269public void DeathEvent(Event event, const char[] name, bool dontBroadcast)
270{
271 int client = GetClientOfUserId(GetEventInt(event, "userid"));
272 int killer = GetClientOfUserId(GetEventInt(event, "attacker"));
273 if(!IsValidClient(client) || !IsValidClient(killer))
274 {
275 return;
276 }
277 if(GetClientTeam(client)==GetClientTeam(killer))
278 {
279 return;
280 }
281 if(g_iKlasa[killer]==-1||g_iKlasa[client]==-1)
282 {
283 return;
284 }
285 g_iDoswiadczenie[killer][g_iKlasa[killer]]+=(IloscExpaZaKilla*g_iPoziom[client][g_iKlasa[killer]]);
286 CPrintToChat(killer, "Zdobyłeś %d expa za killa Exp : %d",(IloscExpaZaKilla*g_iPoziom[client][g_iKlasa[killer]]),g_iDoswiadczenie[killer][g_iKlasa[killer]]);
287 if(g_iDoswiadczenie[killer][g_iKlasa[killer]] >= g_aNeededExp[g_iPoziom[killer][g_iKlasa[killer]]])
288 {
289 g_iPoziom[killer][g_iKlasa[killer]]++;
290 }
291}
292
293public void SpawnEvent(Event event, const char[] name, bool dontBroadcast)
294{
295 int client = GetClientOfUserId(GetEventInt(event, "userid"));
296 if (!IsClientInGame(client) || IsFakeClient(client)||!IsValidClient(client))
297 {
298 return;
299 }
300
301 switch(g_iKlasa[client])
302 {
303 case 0:
304 {
305 SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", 1.4);
306 SetEntityGravity(client, 0.3);
307 RemoveAllWeapons(client);
308 GivePlayerItem(client, "weapon_deagle");
309 }
310 case 1:
311 {
312 SetEntPropFloat(client, Prop_Send, "m_flLaggedMovementValue", 1.2);
313 RemoveAllWeapons(client);
314 GivePlayerItem(client, "weapon_deagle");
315 GivePlayerItem(client, "weapon_smokegrenade");
316 GivePlayerItem(client, "weapon_molotov");
317 GivePlayerItem(client, "weapon_hegrenade");
318 GivePlayerItem(client, "weapon_flashbang");
319 }
320 }
321}
322
323public Action Event_BombPlanted(Handle event, const char[] name, bool dontBroadcast)
324{
325 //int client = GetClientOfUserId(GetEventInt(event, "userid"));
326}
327
328public Action Event_BombDefused(Handle event, const char[] name, bool dontBroadcast)
329{
330 //int client = GetClientOfUserId(GetEventInt(event, "userid"));
331}
332
333public Action OnTakeDamage(int victim, int & attacker, int & inflictor, float & damage, int & damagetype)
334{
335 if(!IsValidClient(victim)||!IsValidClient(attacker))
336 {
337 return Plugin_Continue;
338 }
339 if(GetClientTeam(victim)==GetClientTeam(attacker))
340 {
341 return Plugin_Continue;
342 }
343 /*--------------------------
344 Klasa Ninja
345 ----------------------------*/
346 if(g_iKlasa[attacker]==0)
347 {
348 if ((damagetype & DMG_SLASH) && (GetClientButtons(attacker) & IN_ATTACK2))
349 {
350 if(GetRandomInt(1,100)<50)
351 {
352 damage += 500;
353 return Plugin_Changed;
354 }
355 }
356 }
357 //damage+=g_iPoziom[attacker][klasa]*DamageMultiplier;
358 //damage-=g_iPoziom[victim][klasa]*ReductionMultiplier;
359 return Plugin_Changed;
360}
361
362/*public void OnWeaponSwitchPost(int client, int weapon)
363{
364 if(IsValidClient(client))
365 {
366 if(g_iKlasa[client]==0)
367 {
368 char weaponName[64];
369 GetClientWeapon(client, weaponName, sizeof(weaponName));
370 if (StrContains(weaponName, "knife") != -1)
371 {
372 SetEntityRenderMode(client, RENDER_TRANSCOLOR);
373 SetEntityRenderColor(client, 255, 255, 255, 0);
374 CreateTimer(3.0,Timer_Niewidzialnosc,GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
375 }
376 else
377 {
378 SetEntityRenderMode(client, RENDER_TRANSCOLOR);
379 SetEntityRenderColor(client, 255, 255, 255, 255);
380 }
381 }
382 }
383}
384
385public Action Timer_Niewidzialnosc(Handle timer, int client)
386{
387 SetEntityRenderMode(client, RENDER_TRANSCOLOR);
388 SetEntityRenderColor(client, 255, 255, 255, 255);
389 return Plugin_Stop;
390} */
391
392public bool IsValidClient(int client)
393{
394 if (client <= 0 || client > MaxClients || !IsClientConnected(client) || IsFakeClient(client))
395 {
396 return false;
397 }
398 return IsClientInGame(client);
399}
400
401public void RemoveAllWeapons(int client)
402{
403 if(IsValidClient(client))
404 {
405 int ent;
406 for(int i; i < 2; i++)
407 {
408 if((ent = GetPlayerWeaponSlot(client, i)) != -1)
409 {
410 RemovePlayerItem(client, ent);
411 RemoveEdict(ent);
412 }
413 }
414 }
415}