· 6 years ago · Oct 02, 2019, 11:56 AM
1#include <amxmodx>
2#include <amxmisc>
3#include <fakemeta>
4#include <fakemeta_util>
5#include <hamsandwich>
6#include <cstrike>
7#include <engine>
8#include <sqlx>
9#include <xs>
10#include <csgomod>
11
12#define PLUGIN "CS:GO Mod"
13#define VERSION "1.0"
14#define AUTHOR "O'Zone | Alelluja"
15
16#define TASK_SKINS 3045
17#define TASK_DATA 4592
18#define TASK_AIM 5309
19#define TASK_AD 6234
20
21#define WEAPON_ALL 31
22
23new const commandSkins[][] = {
24 "/skins",
25 "/skin",
26 "/skiny",
27 "/modele",
28 "/model",
29};
30
31new const commandHelp[][] = {
32 "/pomoc",
33 "/help"
34};
35
36new const commandSet[][] = {
37 "/ustaw",
38 "/set"
39};
40
41new const commandBuy[][] = {
42 "/kup",
43 "/buy",
44 "/sklep"
45};
46
47new const commandChest[][] = {
48 "/otworz",
49 "/los",
50 "/losuj"
51};
52
53new const commandExchange[][] = {
54 "/exchange",
55 "/zamien",
56 "/wymien",
57 "/wymiana"
58};
59
60new const commandGive[][] = {
61 "/give",
62 "/oddaj",
63 "/daj"
64};
65
66new const commandMarket[][] = {
67 "/market",
68 "/rynek"
69};
70
71new const commandSell[][] = {
72 "/wystaw"
73};
74
75new const commandPurchase[][] = {
76 "/wykup"
77};
78
79new const commandWithdraw[][] = {
80 "/wycofaj"
81};
82
83new const defaultSkin[][] = { "", "models/csgo_modele/default/v_p228.mdl", "", "models/csgo_modele/default/v_scout.mdl", "", "models/csgo_modele/default/v_xm1014.mdl", "",
84 "models/csgo_modele/default/v_mac10.mdl", "models/csgo_modele/default/v_aug2.mdl", "", "models/csgo_modele/default/v_elite.mdl", "models/csgo_modele/default/v_fiveseven2.mdl",
85 "models/csgo_modele/default/v_ump45.mdl", "models/csgo_modele/default/v_sg5502.mdl", "models/csgo_modele/default/v_galil.mdl", "models/csgo_modele/default/v_famas2.mdl",
86 "models/csgo_modele/default/v_usp2.mdl","models/csgo_modele/default/v_glock18.mdl", "models/csgo_modele/default/v_awp.mdl", "models/csgo_modele/default/v_mp5navy.mdl",
87 "models/csgo_modele/default/v_m249.mdl", "models/csgo_modele/default/v_m3.mdl", "models/csgo_modele/default/v_m4a12.mdl", "models/csgo_modele/default/v_tmp2.mdl",
88 "models/csgo_modele/default/v_g3sg1.mdl", "", "models/csgo_modele/default/v_deagle.mdl", "models/csgo_modele/default/v_sg552.mdl",
89 "models/csgo_modele/default/v_ak47.mdl", "models/csgo_modele/default/v_knife.mdl", "models/csgo_modele/default/v_p90.mdl", "models/csgo_modele/default/v_knife_t.mdl"
90};
91
92new const weaponSlots[] = { -1, 2, -1, 1, 4, 1, 5, 1, 1, 4, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 4, 2, 1, 1, 3, 1 };
93new const maxBPAmmo[] = { -1, 52, -1, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120, 30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100 };
94new const ammoType[][] = { "", "357sig", "", "762nato", "", "buckshot", "", "45acp", "556nato", "", "9mm", "57mm", "45acp", "556nato", "556nato", "556nato",
95 "45acp", "9mm", "338magnum", "9mm", "556natobox", "buckshot", "556nato", "9mm", "762nato", "", "50ae", "556nato", "762nato", "", "57mm" };
96
97enum _:tempInfo { WEAPON, WEAPONS, WEAPON_ENT, EXCHANGE_PLAYER, EXCHANGE_SKIN, EXCHANGE_FOR_SKIN, GIVE_PLAYER, SALE_SKIN };
98enum _:playerInfo { ACTIVE[CSW_P90 + 1], Float:MONEY, SKIN, bool:SKINS_LOADED, bool:DATA_LOADED, bool:SKINS_DISABLED, bool:EXCHANGE_BLOCKED, bool:MENU_BLOCKED, TEMP[tempInfo], NAME[32], SAFE_NAME[64], KEY, CHEST};
99enum _:playerSkinsInfo { SKIN_ID, SKIN_COUNT };
100enum _:skinsInfo { SKIN_NAME[64], SKIN_WEAPON[32], SKIN_MODEL[64], SKIN_PRICE, SKIN_CHANCE };
101enum _:marketInfo { MARKET_ID, MARKET_SKIN, MARKET_OWNER, Float:MARKET_PRICE };
102
103new playerData[MAX_PLAYERS + 1][playerInfo], Array:playerSkins[MAX_PLAYERS + 1], Float:randomSkinPrice[WEAPON_ALL + 1], overallSkinChance[WEAPON_ALL + 1], Array:skins, Array:weapons, Array:market,
104 Handle:sql, Handle:connection, marketSkins, multipleSkins, defaultSkins, skinChance, skinChanceSVIP, Float:skinChancePerMember, maxMarketSkins, Float:marketCommision,
105 Float:killReward, Float:killHSReward, Float:bombReward, Float:defuseReward, Float:hostageReward, Float:winReward, minPlayers, bool:end, bool:sqlConnected,
106 sqlHost[64], sqlUser[64], sqlPassword[64], sqlDatabase[64];
107
108public plugin_init()
109{
110 register_plugin(PLUGIN, VERSION, AUTHOR);
111
112 register_cvar("csgo_version", VERSION, FCVAR_SERVER);
113
114 bind_pcvar_string(create_cvar("csgo_sql_host", "localhost", FCVAR_SPONLY | FCVAR_PROTECTED), sqlHost, charsmax(sqlHost));
115 bind_pcvar_string(create_cvar("csgo_sql_user", "user", FCVAR_SPONLY | FCVAR_PROTECTED), sqlUser, charsmax(sqlUser));
116 bind_pcvar_string(create_cvar("csgo_sql_pass", "password", FCVAR_SPONLY | FCVAR_PROTECTED), sqlPassword, charsmax(sqlPassword));
117 bind_pcvar_string(create_cvar("csgo_sql_db", "database", FCVAR_SPONLY | FCVAR_PROTECTED), sqlDatabase, charsmax(sqlDatabase));
118
119 bind_pcvar_num(create_cvar("csgo_multiple_skins", "1"), multipleSkins);
120 bind_pcvar_num(create_cvar("csgo_default_skins", "1"), defaultSkins);
121 bind_pcvar_num(create_cvar("csgo_min_players", "4"), minPlayers);
122 bind_pcvar_num(create_cvar("csgo_max_market_skins", "5"), maxMarketSkins);
123 bind_pcvar_num(create_cvar("csgo_skin_chance", "20"), skinChance);
124 bind_pcvar_num(create_cvar("csgo_svip_skin_chance", "25"), skinChanceSVIP);
125 bind_pcvar_float(create_cvar("csgo_market_commision", "5"), marketCommision);
126 bind_pcvar_float(create_cvar("csgo_clan_skin_chance_per_member", "1"), skinChancePerMember);
127 bind_pcvar_float(create_cvar("csgo_kill_reward", "0.35"), killReward);
128 bind_pcvar_float(create_cvar("csgo_killhs_reward", "0.15"), killHSReward);
129 bind_pcvar_float(create_cvar("csgo_bomb_reward", "2.0"), bombReward);
130 bind_pcvar_float(create_cvar("csgo_defuse_reward", "2.0"), defuseReward);
131 bind_pcvar_float(create_cvar("csgo_hostages_reward", "2.0"), hostageReward);
132 bind_pcvar_float(create_cvar("csgo_round_reward", "0.5"), winReward);
133
134 registerCommands(commandSkins, sizeof(commandSkins), "skins_menu")
135 registerCommands(commandSet, sizeof(commandSet), "set_skin_menu")
136 registerCommands(commandHelp, sizeof(commandHelp), "skins_help")
137 registerCommands(commandBuy, sizeof(commandBuy), "buy_skin_menu")
138 registerCommands(commandChest, sizeof(commandChest), "command_chest_menu")
139 registerCommands(commandExchange, sizeof(commandExchange), "exchange_skin_menu")
140 registerCommands(commandGive, sizeof(commandGive), "give_skin_menu")
141 registerCommands(commandMarket, sizeof(commandMarket), "market_menu")
142 registerCommands(commandSell, sizeof(commandSell), "market_sell_skin")
143 registerCommands(commandPurchase, sizeof(commandPurchase), "market_buy_skin")
144 registerCommands(commandWithdraw, sizeof(commandWithdraw), "market_withdraw_skin")
145
146 register_menucmd(register_menuid("Exchange"), (MENU_KEY_8 | MENU_KEY_9 | MENU_KEY_0), "exchange_question_handle");
147
148 register_concmd("CENA_SKINA", "set_skin_price");
149
150 register_concmd("csgo_add_money", "cmd_add_money", ADMIN_ADMIN, "<player> <money>");
151
152 register_logevent("log_event_operation", 3, "1=triggered");
153
154 register_event("TextMsg", "hostages_rescued", "a", "2&#All_Hostages_R");
155 register_event("SendAudio", "t_win_round" , "a", "2&%!MRAD_terwin");
156 register_event("SendAudio", "ct_win_round", "a", "2=%!MRAD_ctwin");
157 register_event("SetFOV", "set_fov" , "be");
158 register_event("Money", "event_money", "be");
159
160 register_message(SVC_INTERMISSION, "message_intermission");
161
162 register_forward(FM_SetModel, "set_model", 0);
163
164 RegisterHam(Ham_AddPlayerItem, "player", "add_player_item", 1);
165 RegisterHam(Ham_Spawn, "player", "player_spawn", 1);
166
167 new const weapons[][] = { "weapon_p228", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
168 "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil",
169 "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1",
170 "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_knife", "weapon_p90" };
171
172 for (new i = 0; i < sizeof weapons; i++) RegisterHam(Ham_Item_Deploy, weapons[i], "weapon_deploy_post", 1);
173}
174
175public plugin_precache()
176{
177 skins = ArrayCreate(skinsInfo);
178 market = ArrayCreate(marketInfo);
179 weapons = ArrayCreate(32, 32);
180
181 new file[128];
182
183 get_localinfo("amxx_configsdir", file, charsmax(file));
184 format(file, charsmax(file), "%s/csgo_skins.ini", file);
185
186 if (!file_exists(file)) set_fail_state("[CS:GO] Brak pliku csgo_skins.ini!");
187
188 new skin[skinsInfo], lineData[256], tempValue[4][64], bool:error, fileOpen = fopen(file, "r");
189
190 while (!feof(fileOpen)) {
191 fgets(fileOpen, lineData, charsmax(lineData)); trim(lineData);
192
193 if (lineData[0] == ';' || lineData[0] == '^0' || lineData[0] == '/') continue;
194
195 if (lineData[0] == '[') {
196 replace_all(lineData, charsmax(lineData), "[", "");
197 replace_all(lineData, charsmax(lineData), "]", "");
198
199 split(lineData, skin[SKIN_WEAPON], charsmax(skin[SKIN_WEAPON]), tempValue[0], charsmax(tempValue[]), " - ");
200
201 ArrayPushString(weapons, skin[SKIN_WEAPON]);
202
203 continue;
204 } else {
205 parse(lineData, tempValue[0], charsmax(tempValue[]), tempValue[1], charsmax(tempValue[]), tempValue[2], charsmax(tempValue[]), tempValue[3], charsmax(tempValue[]));
206
207 formatex(skin[SKIN_NAME], charsmax(skin[SKIN_NAME]), tempValue[0]);
208 formatex(skin[SKIN_MODEL], charsmax(skin[SKIN_MODEL]), tempValue[1]);
209
210 skin[SKIN_PRICE] = str_to_num(tempValue[2]);
211 skin[SKIN_CHANCE] = (str_to_num(tempValue[3]) > 1 ? str_to_num(tempValue[3]) : 1);
212
213 if (!file_exists(skin[SKIN_MODEL])) {
214 log_to_file("csgo-error.log", "[CS:GO] Plik %s nie istnieje!", skin[SKIN_MODEL]);
215
216 error = true;
217 } else precache_model(skin[SKIN_MODEL]);
218
219 ArrayPushArray(skins, skin);
220 }
221 }
222
223 fclose(fileOpen);
224
225 if (error) set_fail_state("[CS:GO] Nie zaladowano wszystkich skinow. Sprawdz logi bledow!");
226
227 if (!ArraySize(skins)) set_fail_state("[CS:GO] Nie zaladowano zadnego skina. Sprawdz plik konfiguracyjny csgo_skins.ini!");
228
229 for (new i = 1; i <= MAX_PLAYERS; i++) playerSkins[i] = ArrayCreate(playerSkinsInfo);
230
231 for (new i = 0; i < sizeof(defaultSkin); i++) {
232 if (!defaultSkin[i][0]) continue;
233
234 if (!file_exists(defaultSkin[i])) {
235 log_to_file("csgo-error.log", "[CS:GO] Plik %s nie istnieje!", defaultSkin[i]);
236
237 error = true;
238 } else precache_model(defaultSkin[i]);
239 }
240
241 if (error) set_fail_state("[CS:GO] Nie zaladowano wszystkich standardowych skinow. Sprawdz logi bledow!");
242
243 set_task(0.1, "load_skins_details");
244}
245
246public load_skins_details()
247{
248 new file[128];
249
250 get_localinfo("amxx_configsdir", file, charsmax(file));
251 format(file, charsmax(file), "%s/csgo_skins.ini", file);
252
253 if (!file_exists(file)) set_fail_state("[CS:GO] Brak pliku csgo_skins.ini!");
254
255 new skin[skinsInfo], lineData[256], tempValue[4][64], tempPrice[16], fileOpen = fopen(file, "r");
256
257 while (!feof(fileOpen)) {
258 fgets(fileOpen, lineData, charsmax(lineData)); trim(lineData);
259
260 if (lineData[0] == ';' || lineData[0] == '^0' || lineData[0] == '/') continue;
261
262 if (lineData[0] == '[') {
263 replace_all(lineData, charsmax(lineData), "[", "");
264 replace_all(lineData, charsmax(lineData), "]", "");
265
266 split(lineData, skin[SKIN_WEAPON], charsmax(skin[SKIN_WEAPON]), tempPrice, charsmax(tempPrice), " - ");
267
268 randomSkinPrice[equal(skin[SKIN_WEAPON], "Wszystkie") ? WEAPON_ALL : get_weapon_id(skin[SKIN_WEAPON])] = str_to_float(tempPrice);
269
270 continue;
271 } else {
272 parse(lineData, tempValue[0], charsmax(tempValue[]), tempValue[1], charsmax(tempValue[]), tempValue[2], charsmax(tempValue[]), tempValue[3], charsmax(tempValue[]));
273
274 overallSkinChance[get_weapon_id(skin[SKIN_WEAPON])] += (str_to_num(tempValue[3]) > 1 ? str_to_num(tempValue[3]) : 1);
275 }
276 }
277}
278
279public plugin_cfg()
280{
281 new configPath[64], host[32], user[32], pass[32], db[32], error[128], errorNum;
282
283 get_localinfo("amxx_configsdir", configPath, charsmax(configPath));
284
285 server_cmd("exec %s/csgo_mod.cfg", configPath);
286 server_exec();
287
288 get_cvar_string("csgo_sql_host", host, charsmax(host));
289 get_cvar_string("csgo_sql_user", user, charsmax(user));
290 get_cvar_string("csgo_sql_pass", pass, charsmax(pass));
291 get_cvar_string("csgo_sql_db", db, charsmax(db));
292
293 sql = SQL_MakeDbTuple(host, user, pass, db);
294
295 connection = SQL_Connect(sql, errorNum, error, charsmax(error));
296
297 if (errorNum) {
298 log_to_file("csgo-error.log", "Error: %s (%i)", error, errorNum);
299
300 return;
301 }
302
303 new queryData[192];
304
305 formatex(queryData, charsmax(queryData), "CREATE TABLE IF NOT EXISTS `csgo_skins` (name VARCHAR(35), weapon VARCHAR(35), skin VARCHAR(64), count INT NOT NULL DEFAULT 1, PRIMARY KEY(name, weapon, skin))");
306
307 new Handle:query = SQL_PrepareQuery(connection, queryData);
308
309 SQL_Execute(query);
310
311 formatex(queryData, charsmax(queryData), "CREATE TABLE IF NOT EXISTS `csgo_data` (name VARCHAR(35), money FLOAT NOT NULL, disabled INT NOT NULL, exchange INT NOT NULL, menu INT NOT NULL, online INT NOT NULL, klucze INT NOT NULL, skrzynie INT NOT NULL, PRIMARY KEY(name))");
312
313 query = SQL_PrepareQuery(connection, queryData);
314
315 SQL_Execute(query);
316
317 SQL_FreeHandle(query);
318
319 sqlConnected = true;
320}
321
322public plugin_natives()
323{
324 register_native("csgo_get_money", "_csgo_get_money", 1);
325 register_native("csgo_add_money", "_csgo_add_money", 1);
326 register_native("csgo_set_money", "_csgo_set_money", 1);
327
328 register_native("csgo_get_key", "_csgo_get_key", 1);
329 register_native("csgo_add_key", "_csgo_add_key", 1);
330 register_native("csgo_set_key", "_csgo_set_key", 1);
331
332 register_native("csgo_get_chest", "_csgo_get_chest", 1);
333 register_native("csgo_add_chest", "_csgo_add_chest", 1);
334 register_native("csgo_set_chest", "_csgo_set_chest", 1);
335
336 register_native("csgo_get_menu", "_csgo_get_menu", 1);
337 register_native("csgo_get_skin", "_csgo_get_skin", 1);
338 register_native("csgo_get_weapon_skin", "_csgo_get_weapon_skin", 1);
339 register_native("csgo_get_skin_name", "_csgo_get_skin_name", 1);
340 register_native("csgo_get_current_skin_name", "_csgo_get_current_skin_name", 1);
341}
342
343public plugin_end()
344{
345 SQL_FreeHandle(sql);
346 SQL_FreeHandle(connection);
347
348 ArrayDestroy(skins);
349
350 for (new i = 1; i <= MAX_PLAYERS; i++) ArrayDestroy(playerSkins[i]);
351}
352
353public client_disconnected(id)
354{
355 save_data(id, end ? 2 : 1);
356
357 remove_task(id + TASK_AIM);
358 remove_task(id + TASK_DATA);
359 remove_task(id + TASK_SKINS);
360 remove_task(id + TASK_AD);
361
362 remove_seller(id);
363}
364
365public client_putinserver(id)
366{
367 for (new i = 1; i <= CSW_P90; i++) playerData[id][ACTIVE][i] = -1;
368
369 playerData[id][MONEY] = 0.0;
370 playerData[id][SKIN] = -1;
371
372 ArrayClear(playerSkins[id]);
373
374 for (new i = SKINS_LOADED; i <= MENU_BLOCKED; i++) playerData[id][i] = false;
375
376 if (is_user_hltv(id) || is_user_bot(id)) return;
377
378 get_user_name(id, playerData[id][NAME], charsmax(playerData[][NAME]));
379
380 mysql_escape_string(playerData[id][NAME], playerData[id][SAFE_NAME], charsmax(playerData[][SAFE_NAME]));
381
382 set_task(0.1, "load_data", id + TASK_DATA);
383 set_task(0.1, "load_skins", id + TASK_SKINS);
384 set_task(15.0, "show_advertisement", id + TASK_AD);
385}
386
387public show_advertisement(id)
388{
389 id -= TASK_AD;
390
391 client_print_color(id, id, "^x04[CS:GO]^x01 Grasz na serwerze^x03 %s^x01 stworzonym przez^x03 %s^x01.", PLUGIN, AUTHOR);
392 client_print_color(id, id, "W celu uzyskania informacji o komendach wpisz^x03 /menu^x01 (klawisz^x03 ^"v^"^x01).");
393}
394
395public skins_menu(id)
396{
397 if (!csgo_check_account(id) || end) return PLUGIN_HANDLED;
398
399 if (!playerData[id][SKINS_LOADED])
400 {
401 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
402
403 return PLUGIN_HANDLED;
404 }
405
406 new menuData[64], menu = menu_create("\yMenu \rSkinow\w:", "skins_menu_handle");
407
408 menu_additem(menu, "\wUstaw \ySkin \r(/ustaw)");
409 menu_additem(menu, "\wKup \ySkin \r(/kup)");
410 menu_additem(menu, "\wOtworz \ySkrzynke \r(/otworz)");
411 menu_additem(menu, "\wRynek \ySkinow \r(/rynek)");
412 menu_additem(menu, "\wDoladuj \yPieniadze \r(/sklepsms)");
413 menu_additem(menu, "\wTransferuj \yPieniadze \r(/transfer)");
414 menu_additem(menu, "\wWymien \ySkin \r(/wymien)");
415 menu_additem(menu, "\wOddaj \ySkin \r(/oddaj)");
416
417 formatex(menuData, charsmax(menuData), "\wMenu \yKupowania \r[%s]", playerData[id][MENU_BLOCKED] ? "Standardowe" : "Nowe");
418 menu_additem(menu, menuData);
419
420 formatex(menuData, charsmax(menuData), "\wPropozycje \yWymiany \r[%s]", playerData[id][EXCHANGE_BLOCKED] ? "Wylaczone" : "Wlaczone");
421 menu_additem(menu, menuData);
422
423 formatex(menuData, charsmax(menuData), "\wWyswietlanie \ySkinow \r[%s]", playerData[id][SKINS_DISABLED] ? "Wylaczone" : "Wlaczone");
424 menu_additem(menu, menuData);
425
426 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
427 menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
428 menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
429
430 menu_display(id, menu);
431
432 return PLUGIN_HANDLED;
433}
434
435public skins_menu_handle(id, menu, item)
436{
437 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
438
439 if (item == MENU_EXIT) {
440 menu_destroy(menu);
441
442 return PLUGIN_HANDLED;
443 }
444
445 switch (item)
446 {
447 case 0, 1, 2: choose_weapon_menu(id, item);
448 case 3: market_menu(id);
449 case 4: client_cmd(id, "say /sklepsms");
450 case 5: client_cmd(id, "transfer");
451 case 6: exchange_skin_menu(id);
452 case 7: give_skin_menu(id);
453 case 8: {
454 playerData[id][MENU_BLOCKED] = !playerData[id][MENU_BLOCKED];
455
456 client_print_color(id, id, "^x04[CS:GO]^x01 Ustawiles^x03 %s^x01 menu kupowania.", playerData[id][MENU_BLOCKED] ? "standardowe" : "nowe");
457
458 save_data(id);
459
460 skins_menu(id);
461 } case 9: {
462 playerData[id][EXCHANGE_BLOCKED] = !playerData[id][EXCHANGE_BLOCKED];
463
464 client_print_color(id, id, "^x04[CS:GO]^x01 Mozliwosc wysylania ci ofert wymiany zostala^x03 %s^x01.", playerData[id][EXCHANGE_BLOCKED] ? "wylaczona" : "wlaczona");
465
466 save_data(id);
467
468 skins_menu(id);
469 } case 10: {
470 playerData[id][SKINS_DISABLED] = !playerData[id][SKINS_DISABLED];
471
472 client_print_color(id, id, "^x04[CS:GO]^x01 Wyswietlanie skinow zostalo^x03 %s^x01.", playerData[id][SKINS_DISABLED] ? "wylaczone" : "wlaczone");
473
474 save_data(id);
475
476 skins_menu(id);
477 }
478 }
479
480 menu_destroy(menu);
481
482 return PLUGIN_HANDLED;
483}
484
485public command_chest_menu(id)
486{
487 if (!playerData[id][SKINS_LOADED])
488 {
489 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
490
491 return PLUGIN_HANDLED;
492 }
493
494 choose_weapon_menu(id, 2);
495
496 return PLUGIN_HANDLED;
497}
498
499public choose_weapon_menu(id, type)
500{
501 new menuData[32], tempType[2], menu = menu_create("\yWybierz \rBron\w:", "choose_weapon_menu_handle");
502
503 num_to_str(type, tempType, charsmax(tempType));
504
505 for (new i = type == 2 ? 0 : (randomSkinPrice[WEAPON_ALL] > 0.0 ? 1 : 0); i < ArraySize(weapons); i++)
506 {
507 ArrayGetString(weapons, i, menuData, charsmax(menuData));
508
509 menu_additem(menu, menuData, tempType);
510 }
511
512 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
513 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
514 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
515
516 menu_display(id, menu);
517
518 return PLUGIN_HANDLED;
519}
520
521public choose_weapon_menu_handle(id, menu, item)
522{
523 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
524
525 if (item == MENU_EXIT) {
526 menu_destroy(menu);
527
528 return PLUGIN_HANDLED;
529 }
530
531 new itemData[32], itemType[2], itemAccess, itemCallback;
532
533 menu_item_getinfo(menu, item, itemAccess, itemType, charsmax(itemType), itemData, charsmax(itemData), itemCallback);
534
535 switch (str_to_num(itemType))
536 {
537 case 0: set_weapon_skin(id, itemData);
538 case 1: buy_weapon_skin(id, itemData);
539 case 2: open_chest_menu(id, itemData);
540 }
541
542 menu_destroy(menu);
543
544 return PLUGIN_HANDLED;
545}
546
547public open_chest_menu(id, weapon[])
548{
549 new menuData[256], Float:chance = (csgo_get_user_svip(id) ? skinChanceSVIP : skinChance) + csgo_get_clan_members(csgo_get_user_clan(id)) * skinChancePerMember;
550
551 if (equal(weapon, "Wszystkie"))
552 {
553 formatex(menuData, charsmax(menuData), "\yCzy chcesz sprobowac \rotworzyc \yskrzynke do tej broni? \w^nSzansa na wylosowanie: \y%.2f%%\w.", randomSkinPrice[WEAPON_ALL], chance);
554 }
555 else
556 {
557 formatex(menuData, charsmax(menuData), "\yCzy chcesz sprobowac \rotworzyc \yskrzynke do %s\y? \w^nSzansa na wylosowanie: \y%.2f%%\w.", weapon, chance);
558 }
559
560 new menu = menu_create(menuData, "open_chest_menu_handler");
561
562 menu_additem(menu, "\yTak", weapon);
563 menu_additem(menu, "Nie^n");
564
565 formatex(menuData, charsmax(menuData), "\wAby zwiekszyc szanse wylosowania kup \ySVIPa \r(+%i%%)^n\wlub \ydolacz do klanu \r(+%.2f%% za kazdego czlonka)\w.", skinChanceSVIP - skinChance, skinChancePerMember);
566
567 menu_addtext(menu, menuData);
568
569 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
570
571 menu_display(id, menu);
572
573 return PLUGIN_HANDLED;
574}
575
576public open_chest_menu_handler(id, menu, item)
577{
578 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
579
580 if (item == MENU_EXIT || item)
581 {
582 menu_destroy(menu);
583
584 return PLUGIN_HANDLED;
585 }
586
587 new weapon[32], itemAccess, itemCallback;
588
589 menu_item_getinfo(menu, item, itemAccess, weapon, charsmax(weapon), _, _, itemCallback);
590
591 if (!multipleSkins && !get_missing_weapon_skins_count(id, weapon))
592 {
593 if (equal(weapon, "Wszystkie"))
594 {
595 client_print_color(id, id, "^x04[CS:GO]^x01 Masz juz wszystkie dostepne skiny^x01.");
596 }
597 else
598 {
599 client_print_color(id, id, "^x04[CS:GO]^x01 Masz juz wszystkie dostepne skiny broni^x03 %s^x01.", weapon);
600 }
601
602 return PLUGIN_HANDLED;
603 }
604
605 new chance = (csgo_get_user_svip(id) ? skinChanceSVIP : skinChance) + floatround(csgo_get_clan_members(csgo_get_user_clan(id)) * skinChancePerMember, floatround_floor);
606 if(playerData[id][CHEST] > 0 && playerData[id][KEY] > 0)
607 {
608 if (random_num(1, 100) <= chance)
609 {
610 new skin[skinsInfo], skinId, skinsChance = 0, skinChance = random_num(1, multipleSkins ? get_weapon_skins_count(weapon, 1) : get_missing_weapon_skins_count(id, weapon, 1));
611
612 for (new i = 0; i < ArraySize(skins); i++)
613 {
614 ArrayGetArray(skins, i, skin);
615
616 if (equali(weapon, skin[SKIN_WEAPON]) || equal(weapon, "Wszystkie"))
617 {
618 if (!multipleSkins && has_skin(id, i)) continue;
619
620 skinsChance += skin[SKIN_CHANCE];
621
622 if (skinsChance >= skinChance)
623 {
624 skinId = i;
625
626 break;
627 }
628 }
629 }
630
631 ArrayGetArray(skins, skinId, skin);
632
633 add_skin(id, skinId, skin[SKIN_WEAPON], skin[SKIN_NAME]);
634
635 client_print_color(0, id, "^x04[CS:GO]^x03 %s^x01 wylosowal skin^x03 %s^x01 do broni^x03 %s^x01.", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON]);
636
637 log_to_file("csgo-random.log", "Gracz %s wylosowal skina %s (%s)", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON]);
638 }
639 else
640 {
641 client_print_color(id, id, "^x04[CS:GO]^x01 Nie udalo ci sie wylosowac ^x03skina^x01.")
642 }
643 playerData[id][CHEST]--;
644 playerData[id][KEY]--;
645 }
646
647 save_data(id);
648 skins_menu(id);
649
650 return PLUGIN_HANDLED;
651}
652
653public skins_help(id)
654{
655
656 show_motd(id, "skiny.txt", "CS:GO Mod - Pomoc");
657
658 skins_menu(id);
659
660 return PLUGIN_HANDLED;
661}
662
663public set_skin_menu(id)
664{
665 if (!playerData[id][SKINS_LOADED]) {
666 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
667
668 return PLUGIN_HANDLED;
669 }
670
671 choose_weapon_menu(id, 0);
672
673 return PLUGIN_HANDLED;
674}
675
676public buy_skin_menu(id)
677{
678 if (!playerData[id][SKINS_LOADED]) {
679 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
680
681 return PLUGIN_HANDLED;
682 }
683
684 choose_weapon_menu(id, 1);
685
686 return PLUGIN_HANDLED;
687}
688
689public set_weapon_skin(id, weapon[])
690{
691 new menuData[64], tempId[5], skin[skinsInfo], skinId, skinsCount, menu = menu_create("\yWybierz \rSkin\w:", "set_weapon_skin_handle"), callback = menu_makecallback("set_weapon_skin_callback");
692
693 menu_additem(menu, "Domyslny", weapon);
694
695 for (new i = 0; i < ArraySize(skins); i++) {
696 ArrayGetArray(skins, i, skin);
697
698 if (equal(weapon, skin[SKIN_WEAPON])) {
699 skinId = has_skin(id, i, 1);
700 skinsCount = 0;
701
702 if (multipleSkins && skinId != -1) skinsCount = get_player_skin_info(id, skinId, SKIN_COUNT);
703
704 if (skinsCount > 1) formatex(menuData, charsmax(menuData), "%s \y(%s) \r(%i)", skin[SKIN_NAME], skin[SKIN_WEAPON], skinsCount);
705 else formatex(menuData, charsmax(menuData), "%s \y(%s)", skin[SKIN_NAME], skin[SKIN_WEAPON]);
706
707 num_to_str(i, tempId, charsmax(tempId));
708
709 menu_additem(menu, menuData, tempId, _, callback);
710 }
711 }
712
713 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
714 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
715 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
716
717 menu_display(id, menu);
718
719 return PLUGIN_HANDLED;
720}
721
722public set_weapon_skin_callback(id, menu, item)
723{
724 static itemData[5], itemAccess, itemCallback;
725
726 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
727
728 return has_skin(id, str_to_num(itemData), 1) > -1 ? ITEM_ENABLED : ITEM_DISABLED;
729}
730
731public set_weapon_skin_handle(id, menu, item)
732{
733 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
734
735 if (item == MENU_EXIT) {
736 menu_destroy(menu);
737
738 return PLUGIN_HANDLED;
739 }
740
741 if (item) {
742 new skin[skinsInfo], itemData[5], itemAccess, itemCallback;
743
744 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
745
746 new skinId = str_to_num(itemData);
747
748 ArrayGetArray(skins, skinId, skin);
749
750 remove_active_skin(id, skin[SKIN_WEAPON]);
751
752 set_skin(id, skin[SKIN_WEAPON], skin[SKIN_NAME], skinId, 1);
753
754 client_print_color(id, id, "^x04[CS:GO]^x01 Twoj nowy skin^x03 %s^x01 to^x03 %s^x01.", skin[SKIN_WEAPON], skin[SKIN_NAME]);
755 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostanie^x03 od tego momentu^x01 ustawiony dla tej broni po kazdym zakupie^x01.");
756 } else {
757 new itemData[16], itemAccess, itemCallback;
758
759 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
760
761 remove_active_skin(id, itemData);
762
763 set_skin(id, itemData);
764
765 client_print_color(id, id, "^x04[CS:GO]^x01 Przywrociles domyslny skin broni^x03 %s^x01.", itemData);
766 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostanie^x03 od tego momentu^x01 ustawiony dla tej broni po kazdym zakupie^x01.");
767 }
768
769 menu_destroy(menu);
770
771 return PLUGIN_HANDLED;
772}
773
774public buy_weapon_skin(id, weapon[])
775{
776 new menuData[64], skin[skinsInfo], tempId[5], count, menu = menu_create("\yWybierz \rSkin\w:", "buy_weapon_skin_handle");
777
778 for (new i = 0; i < ArraySize(skins); i++) {
779 ArrayGetArray(skins, i, skin);
780
781 if (equal(weapon, skin[SKIN_WEAPON])) {
782 if (!multipleSkins && has_skin(id, i)) continue;
783
784 num_to_str(i, tempId, charsmax(tempId));
785
786 formatex(menuData, charsmax(menuData), "\y%s \w- \r%i Euro", skin[SKIN_NAME], skin[SKIN_PRICE]);
787
788 menu_additem(menu, menuData, tempId);
789
790 count++;
791 }
792 }
793
794 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
795 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
796 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
797
798 if (!count) {
799 client_print_color(id, id, "^x04[CS:GO]^x01 Do kupienia nie ma^x03 zadnych^x01 skinow tej broni.");
800
801 menu_destroy(menu);
802 } else menu_display(id, menu);
803}
804
805public buy_weapon_skin_handle(id, menu, item)
806{
807 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
808
809 if (item == MENU_EXIT) {
810 menu_destroy(menu);
811
812 return PLUGIN_HANDLED;
813 }
814
815 new itemData[32], itemAccess, itemCallback, skinId;
816
817 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
818
819 skinId = str_to_num(itemData);
820
821 menu_destroy(menu);
822
823 if (!multipleSkins && has_skin(id, skinId)) {
824 client_print_color(id, id, "^x04[CS:GO]^x01 Juz posiadasz ten skin!");
825
826 return PLUGIN_HANDLED;
827 }
828
829 new skin[skinsInfo];
830
831 ArrayGetArray(skins, skinId, skin);
832
833 if (playerData[id][MONEY] < skin[SKIN_PRICE]) {
834 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz wystarczajacej ilosci^x03 pieniedzy^x01.");
835
836 return PLUGIN_HANDLED;
837 }
838
839 playerData[id][MONEY] -= skin[SKIN_PRICE];
840
841 save_data(id);
842
843 add_skin(id, skinId, skin[SKIN_WEAPON], skin[SKIN_NAME]);
844
845 client_print_color(id, id, "^x04[CS:GO]^x01 Pomyslnie zakupiles skin^x03 %s^x01 do broni^x03 %s^x01.", skin[SKIN_NAME], skin[SKIN_WEAPON]);
846
847 log_to_file("csgo-buy.log", "Gracz %s kupil skina %s (%s)", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON]);
848
849 skins_menu(id);
850
851 return PLUGIN_HANDLED;
852}
853
854public exchange_skin_menu(id)
855{
856 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
857
858 if (!playerData[id][SKINS_LOADED]) {
859 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
860
861 return PLUGIN_HANDLED;
862 }
863
864 new menuData[128], playerId[3], skinsCount, players, menu = menu_create("\yWybierz \rGracza\y, z ktorym chcesz sie wymienic skinem\w:", "exchange_skin_menu_handle");
865
866 for (new player = 1; player <= MAX_PLAYERS; player++) {
867 if (!is_user_connected(player) || id == player || is_user_bot(player) || is_user_hltv(player) || !ArraySize(playerSkins[player]) || playerData[player][EXCHANGE_BLOCKED]) continue;
868
869 skinsCount = ArraySize(playerSkins[player]);
870
871 formatex(menuData, charsmax(menuData), "%s \y(%i Skin%s)", playerData[player][NAME], skinsCount, skinsCount % 10 == 0 ? "ow" : (skinsCount == 1 ? "" : ((skinsCount % 10 < 5 && (skinsCount < 10 || skinsCount > 20)) ? "y" : "ow")));
872
873 num_to_str(player, playerId, charsmax(playerId));
874
875 menu_additem(menu, menuData, playerId);
876
877 players++;
878 }
879
880 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
881 menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
882 menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
883
884 if (!players) {
885 menu_destroy(menu);
886
887 client_print_color(id, id, "^x04[CS:GO]^x01 Na serwerze nie ma gracza, z ktorym moglbys sie wymienic skinem!");
888 } else menu_display(id, menu);
889
890 return PLUGIN_HANDLED;
891}
892
893public exchange_skin_menu_handle(id, menu, item)
894{
895 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
896
897 if (item == MENU_EXIT) {
898 menu_destroy(menu);
899
900 return PLUGIN_HANDLED;
901 }
902
903 new playerId[3], itemAccess, itemCallback;
904
905 menu_item_getinfo(menu, item, itemAccess, playerId, charsmax(playerId), _, _, itemCallback);
906
907 new player = str_to_num(playerId);
908
909 menu_destroy(menu);
910
911 if (!is_user_connected(player)) {
912 client_print_color(id, id, "^x04[CS:GO]^x01 Wybranego gracza nie ma juz na serwerze.");
913
914 return PLUGIN_HANDLED;
915 }
916
917 if (!ArraySize(playerSkins[player])) {
918 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz nie ma zadnych skinow.");
919
920 return PLUGIN_HANDLED;
921 }
922
923 if (!ArraySize(playerSkins[id])) {
924 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz zadnych skinow.");
925
926 return PLUGIN_HANDLED;
927 }
928
929 playerData[id][TEMP][EXCHANGE_PLAYER] = player;
930
931 new menuData[64], skin[skinsInfo], tempId[5], skinId, skinsCount, menu = menu_create("\yWybierz twoj \rSkin\y, ktory chcesz wymienic\w:", "exchange_skin_handle");
932
933 for (new i = 0; i < ArraySize(playerSkins[id]); i++) {
934 skinId = get_player_skin_info(id, i, SKIN_ID), skinsCount = get_player_skin_info(id, i, SKIN_COUNT);
935
936 if (!multipleSkins && has_skin(player, skinId)) continue;
937
938 ArrayGetArray(skins, skinId, skin);
939
940 num_to_str(skinId, tempId, charsmax(tempId));
941
942 if (multipleSkins && skinsCount > 1) formatex(menuData, charsmax(menuData), "%s \y(%s) \r(%i)", skin[SKIN_NAME], skin[SKIN_WEAPON], skinsCount);
943 else formatex(menuData, charsmax(menuData), "%s \y(%s)", skin[SKIN_NAME], skin[SKIN_WEAPON]);
944
945 menu_additem(menu, menuData, tempId);
946 }
947
948 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
949 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
950 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
951
952 menu_display(id, menu);
953
954 return PLUGIN_HANDLED;
955}
956
957public exchange_skin_handle(id, menu, item)
958{
959 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
960
961 if (item == MENU_EXIT) {
962 menu_destroy(menu);
963
964 return PLUGIN_HANDLED;
965 }
966
967 new player = playerData[id][TEMP][EXCHANGE_PLAYER];
968
969 if (!is_user_connected(player)) {
970 client_print_color(id, id, "^x04[CS:GO]^x01 Wybranego gracza nie ma juz na serwerze.");
971
972 return PLUGIN_HANDLED;
973 }
974
975 if (!ArraySize(playerSkins[player])) {
976 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz nie ma zadnych skinow.");
977
978 return PLUGIN_HANDLED;
979 }
980
981 new itemData[5], itemAccess, itemCallback;
982
983 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
984
985 playerData[id][TEMP][EXCHANGE_SKIN] = str_to_num(itemData);
986
987 menu_destroy(menu);
988
989 if (has_skin(id, playerData[id][TEMP][EXCHANGE_SKIN], 1) == -1) {
990 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz juz skina, za ktory chcialbys sie zamienic.");
991
992 return PLUGIN_HANDLED;
993 }
994
995 new menuData[64], skin[skinsInfo], tempId[5], skinsCount = 0, skinId, menu = menu_create("\yWybierz \rSkin\y, za ktory chcesz sie wymienic\w:", "exchange_for_skin_handle");
996
997 for (new i = 0; i < ArraySize(playerSkins[player]); i++) {
998 skinId = get_player_skin_info(player, i, SKIN_ID);
999
1000 if (!multipleSkins && has_skin(id, skinId)) continue;
1001
1002 ArrayGetArray(skins, skinId, skin);
1003
1004 num_to_str(skinId, tempId, charsmax(tempId));
1005
1006 formatex(menuData, charsmax(menuData), "%s \y(%s)", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1007
1008 menu_additem(menu, menuData, tempId);
1009
1010 skinsCount++;
1011 }
1012
1013 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
1014 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
1015 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1016
1017 if (!skinsCount) {
1018 menu_destroy(menu);
1019
1020 client_print_color(id, id, "^x04[CS:GO]^x01 Masz juz wszystkie skiny, ktore posiada wybrany gracz!");
1021 } else menu_display(id, menu);
1022
1023 return PLUGIN_HANDLED;
1024}
1025
1026public exchange_for_skin_handle(id, menu, item)
1027{
1028 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1029
1030 if (item == MENU_EXIT) {
1031 menu_destroy(menu);
1032
1033 return PLUGIN_HANDLED;
1034 }
1035
1036 new player = playerData[id][TEMP][EXCHANGE_PLAYER];
1037
1038 if (!is_user_connected(player)) {
1039 client_print_color(id, id, "^x04[CS:GO]^x01 Wybranego gracza nie ma juz na serwerze.");
1040
1041 return PLUGIN_HANDLED;
1042 }
1043
1044 if (!ArraySize(playerSkins[player])) {
1045 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz nie ma zadnych skinow.");
1046
1047 return PLUGIN_HANDLED;
1048 }
1049
1050 new menuData[256], itemData[32], skin[skinsInfo], playerSkin[skinsInfo], itemAccess, itemCallback;
1051
1052 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
1053
1054 menu_destroy(menu);
1055
1056 playerData[id][TEMP][EXCHANGE_FOR_SKIN] = str_to_num(itemData);
1057
1058 if (playerData[id][TEMP][EXCHANGE_FOR_SKIN] == playerData[id][TEMP][EXCHANGE_SKIN]) {
1059 client_print_color(id, id, "^x04[CS:GO]^x01 Nie mozesz wymienic sie za ten sam skin.");
1060
1061 return PLUGIN_HANDLED;
1062 }
1063
1064 if (has_skin(player, playerData[id][TEMP][EXCHANGE_FOR_SKIN], 1) == -1) {
1065 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz nie ma juz tego skina.");
1066
1067 return PLUGIN_HANDLED;
1068 }
1069
1070 ArrayGetArray(skins, playerData[id][TEMP][EXCHANGE_SKIN], skin);
1071 ArrayGetArray(skins, playerData[id][TEMP][EXCHANGE_FOR_SKIN], playerSkin);
1072
1073 playerData[player][TEMP][EXCHANGE_PLAYER] = id;
1074
1075 formatex(menuData, charsmax(menuData), "\wGracz \y%s \wzaproponowal ci wymiane:^n\wTwoj skin: \r%s \y(%s)^n\wJego skin: \r%s \y(%s)\w^n^n\r8. \wWymien^n\r9. \wOdrzuc^n^n\r0. \wWyjscie",
1076 playerData[id][NAME], playerSkin[SKIN_NAME], playerSkin[SKIN_WEAPON], skin[SKIN_NAME], skin[SKIN_WEAPON]);
1077
1078 show_menu(player, (MENU_KEY_8 | MENU_KEY_9 | MENU_KEY_0), menuData, -1, "Exchange");
1079
1080 return PLUGIN_HANDLED;
1081}
1082
1083public exchange_question_handle(id, key)
1084{
1085 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1086
1087 new player = playerData[id][TEMP][EXCHANGE_PLAYER], exchangeSkin = playerData[player][TEMP][EXCHANGE_SKIN], exchangeForSkin = playerData[player][TEMP][EXCHANGE_FOR_SKIN];
1088
1089 if (!is_user_connected(player)) {
1090 client_print_color(id, id, "^x04[CS:GO]^x01 Gracza proponujacego wymiane nie ma juz na serwerze.");
1091
1092 return PLUGIN_HANDLED;
1093 }
1094
1095 if (has_skin(player, exchangeSkin, 1) == -1) {
1096 client_print_color(id, id, "^x04[CS:GO]^x01 Gracz proponujacy wymiane nie ma juz tego skina.");
1097
1098 return PLUGIN_HANDLED;
1099 }
1100
1101 if (has_skin(id, exchangeForSkin, 1) == -1) {
1102 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz juz zapronowanego w wymianie skina.");
1103
1104 return PLUGIN_HANDLED;
1105 }
1106
1107 switch (key + 1) {
1108 case 8: {
1109 new skin[skinsInfo], playerSkin[skinsInfo];
1110
1111 ArrayGetArray(skins, exchangeSkin, playerSkin);
1112 ArrayGetArray(skins, exchangeForSkin, skin);
1113
1114 remove_skin(player, exchangeSkin, playerSkin[SKIN_WEAPON], playerSkin[SKIN_NAME]);
1115 remove_skin(id, exchangeForSkin, skin[SKIN_WEAPON], skin[SKIN_NAME]);
1116
1117 add_skin(player, exchangeForSkin, skin[SKIN_WEAPON], skin[SKIN_NAME]);
1118 add_skin(id, exchangeSkin, playerSkin[SKIN_WEAPON], playerSkin[SKIN_NAME]);
1119
1120 client_print_color(player, player, "^x04[CS:GO]^x01 Wymieniles sie skinem z^x03 %s^x01. Otrzymales^x03 %s (%s)^x01.", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON]);
1121 client_print_color(id, id, "^x04[CS:GO]^x01 Wymieniles sie skinem z^x03 %s^x01. Otrzymales^x03 %s (%s)^x01.", playerData[player][NAME], playerSkin[SKIN_NAME], playerSkin[SKIN_WEAPON]);
1122
1123 log_to_file("csgo-exchange.log", "Gracz %s wymienil sie skinem %s (%s) z graczem %s za skin %s (%s)", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON], playerData[player][NAME], playerSkin[SKIN_NAME], playerSkin[SKIN_WEAPON]);
1124 } default: client_print_color(player, player, "^x04[CS:GO]^x01 Wybrany gracz nie zgodzil sie na wymiane skinami.");
1125 }
1126
1127 return PLUGIN_HANDLED;
1128}
1129
1130public give_skin_menu(id)
1131{
1132 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1133
1134 if (!playerData[id][SKINS_LOADED]) {
1135 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
1136
1137 return PLUGIN_HANDLED;
1138 }
1139
1140 new menuData[128], playerId[3], skinsCount, players, menu = menu_create("\yWybierz \rGracza\y, ktoremu chcesz oddac skina\w:", "give_skin_menu_handle");
1141
1142 for (new player = 1; player <= MAX_PLAYERS; player++) {
1143 if (!is_user_connected(player) || id == player || is_user_hltv(player) || is_user_bot(player)) continue;
1144
1145 skinsCount = ArraySize(playerSkins[player]);
1146
1147 formatex(menuData, charsmax(menuData), "%s \y(%i Skin%s)", playerData[player][NAME], skinsCount, skinsCount % 10 == 0 ? "ow" : (skinsCount == 1 ? "" : ((skinsCount % 10 < 5 && (skinsCount < 10 || skinsCount > 20)) ? "y" : "ow")));
1148
1149 num_to_str(player, playerId, charsmax(playerId));
1150
1151 menu_additem(menu, menuData, playerId);
1152
1153 players++;
1154 }
1155
1156 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1157 menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
1158 menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
1159
1160 if (!players) {
1161 menu_destroy(menu);
1162
1163 client_print_color(id, id, "^x04[CS:GO]^x01 Na serwerze nie ma gracza, ktoremu moglbys oddac skina!");
1164 } else menu_display(id, menu);
1165
1166 return PLUGIN_HANDLED;
1167}
1168
1169public give_skin_menu_handle(id, menu, item)
1170{
1171 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1172
1173 if (item == MENU_EXIT) {
1174 menu_destroy(menu);
1175
1176 return PLUGIN_HANDLED;
1177 }
1178
1179 new playerId[3], itemAccess, itemCallback;
1180
1181 menu_item_getinfo(menu, item, itemAccess, playerId, charsmax(playerId), _, _, itemCallback);
1182
1183 new player = str_to_num(playerId);
1184
1185 menu_destroy(menu);
1186
1187 if (!is_user_connected(player)) {
1188 client_print_color(id, id, "^x04[CS:GO]^x01 Wybranego gracza nie ma juz na serwerze.");
1189
1190 return PLUGIN_HANDLED;
1191 }
1192
1193 if (!ArraySize(playerSkins[id])) {
1194 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz zadnych skinow.");
1195
1196 return PLUGIN_HANDLED;
1197 }
1198
1199 playerData[id][TEMP][GIVE_PLAYER] = player;
1200
1201 new menuData[64], skin[skinsInfo], tempId[5], skinsCount = 0, skinId, skinCount, menu = menu_create("\yWybierz \rSkin\y, ktory chcesz oddac\w:", "give_skin_handle");
1202
1203 for (new i = 0; i < ArraySize(playerSkins[id]); i++) {
1204 skinId = get_player_skin_info(id, i, SKIN_ID), skinCount = get_player_skin_info(id, i, SKIN_COUNT);
1205
1206 if (!multipleSkins && has_skin(player, skinId)) continue;
1207
1208 ArrayGetArray(skins, skinId, skin);
1209
1210 num_to_str(skinId, tempId, charsmax(tempId));
1211
1212 if (multipleSkins && skinCount > 1) formatex(menuData, charsmax(menuData), "%s \y(%s) \r(%i)", skin[SKIN_NAME], skin[SKIN_WEAPON], skinCount);
1213 else formatex(menuData, charsmax(menuData), "%s \y(%s)", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1214
1215 menu_additem(menu, menuData, tempId);
1216
1217 skinsCount++;
1218 }
1219
1220 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
1221 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
1222 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1223
1224 if (!skinsCount) {
1225 menu_destroy(menu);
1226
1227 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz ma juz wszystkie skiny, ktore ty posiadasz!");
1228 } else menu_display(id, menu);
1229
1230 return PLUGIN_HANDLED;
1231}
1232
1233public give_skin_handle(id, menu, item)
1234{
1235 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1236
1237 if (item == MENU_EXIT) {
1238 menu_destroy(menu);
1239
1240 return PLUGIN_HANDLED;
1241 }
1242
1243 new player = playerData[id][TEMP][GIVE_PLAYER];
1244
1245 if (!is_user_connected(player)) {
1246 client_print_color(id, id, "^x04[CS:GO]^x01 Wybranego gracza nie ma juz na serwerze.");
1247
1248 return PLUGIN_HANDLED;
1249 }
1250
1251 new itemData[5], itemAccess, itemCallback, skinId;
1252
1253 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
1254
1255 skinId = str_to_num(itemData);
1256
1257 menu_destroy(menu);
1258
1259 if (has_skin(id, skinId, 1) == -1) {
1260 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz juz skina, ktorego mialbys oddac.");
1261
1262 return PLUGIN_HANDLED;
1263 }
1264
1265 if (!multipleSkins && has_skin(player, skinId)) {
1266 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany gracz ma juz tego skina.");
1267
1268 return PLUGIN_HANDLED;
1269 }
1270
1271 new skin[skinsInfo];
1272
1273 ArrayGetArray(skins, skinId, skin);
1274
1275 remove_skin(id, skinId, skin[SKIN_WEAPON], skin[SKIN_NAME]);
1276
1277 add_skin(player, skinId, skin[SKIN_WEAPON], skin[SKIN_NAME]);
1278
1279 client_print_color(player, player, "^x04[CS:GO]^x01 Gracz^x03 %s^x01 podarowal ci skin^x03 %s (%s)^x01.", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON]);
1280 client_print_color(id, id, "^x04[CS:GO]^x01 Podarowales skin^x03 %s (%s)^x01 graczowi^x03 %s^x01.", skin[SKIN_NAME], skin[SKIN_WEAPON], playerData[player][NAME]);
1281
1282 log_to_file("csgo-give.log", "Gracz %s oddal skina %s (%s) graczowi %s", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON], playerData[player][NAME]);
1283
1284 return PLUGIN_HANDLED;
1285}
1286
1287public market_menu(id)
1288{
1289 if (!csgo_check_account(id) || end) return PLUGIN_HANDLED;
1290
1291 if (!playerData[id][SKINS_LOADED]) {
1292 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
1293
1294 return PLUGIN_HANDLED;
1295 }
1296
1297 new menu = menu_create("\yMenu \rRynku", "market_menu_handle"), callback = menu_makecallback("market_menu_callback");
1298
1299 menu_additem(menu, "Wystaw \ySkin \r(/wystaw)", _, _, callback);
1300 menu_additem(menu, "Wykup \ySkin \r(/wykup)", _, _, callback);
1301 menu_additem(menu, "Wycofaj \ySkin \r(/wycofaj)", _, _, callback);
1302
1303 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1304
1305 menu_display(id, menu);
1306
1307 return PLUGIN_HANDLED;
1308}
1309
1310public market_menu_handle(id, menu, item)
1311{
1312 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1313
1314 if (item == MENU_EXIT) {
1315 menu_destroy(menu);
1316
1317 return PLUGIN_HANDLED;
1318 }
1319
1320 switch (item) {
1321 case 0: market_sell_skin(id);
1322 case 1: market_buy_skin(id);
1323 case 2: market_withdraw_skin(id);
1324 }
1325
1326 return PLUGIN_HANDLED;
1327}
1328
1329public market_menu_callback(id, menu, item)
1330{
1331 switch (item) {
1332 case 0: if (!ArraySize(playerSkins[id]) || get_market_skins(id) >= maxMarketSkins) return ITEM_DISABLED;
1333 case 1: if (!ArraySize(market)) return ITEM_DISABLED;
1334 case 2: if (!get_market_skins(id)) return ITEM_DISABLED;
1335 }
1336
1337 return ITEM_ENABLED;
1338}
1339
1340public market_sell_skin(id)
1341{
1342 if (!is_user_connected(id) || !csgo_check_account(id) || end) return PLUGIN_HANDLED;
1343
1344 if (!playerData[id][SKINS_LOADED]) {
1345 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
1346
1347 return PLUGIN_HANDLED;
1348 }
1349
1350 if (!ArraySize(playerSkins[id])) {
1351 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz zadnych skinow.");
1352
1353 return PLUGIN_HANDLED;
1354 }
1355
1356 if (get_market_skins(id) >= maxMarketSkins) {
1357 client_print_color(id, id, "^x04[CS:GO]^x01 Wystawiles juz maksymalne^x03 %i^x01 skinow na rynek!", maxMarketSkins);
1358
1359 return PLUGIN_HANDLED;
1360 }
1361
1362 new menuTitle[128], menuData[64], skin[skinsInfo], tempId[5], skinId, skinsCount;
1363
1364 if (marketCommision > 0.0) formatex(menuTitle, charsmax(menuTitle), "\yWybierz \rSkin\y, ktory chcesz wystawic na rynek\w:^n\yOd kazdej sprzedazy pobierana jest prowizja w wysokosci\r %.2f%%\y.^n", marketCommision);
1365 else formatex(menuTitle, charsmax(menuTitle), "\yWybierz \rSkin\y, ktory chcesz wystawic na rynek\w:");
1366
1367 new menu = menu_create(menuTitle, "market_sell_skin_handle");
1368
1369 for (new i = 0; i < ArraySize(playerSkins[id]); i++) {
1370 skinId = get_player_skin_info(id, i, SKIN_ID), skinsCount = get_player_skin_info(id, i, SKIN_COUNT);
1371
1372 ArrayGetArray(skins, skinId, skin);
1373
1374 num_to_str(skinId, tempId, charsmax(tempId));
1375
1376 if (multipleSkins && skinsCount > 1) formatex(menuData, charsmax(menuData), "%s \y(%s) \r(%i)", skin[SKIN_NAME], skin[SKIN_WEAPON], skinsCount);
1377 else formatex(menuData, charsmax(menuData), "%s \y(%s)", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1378
1379 menu_additem(menu, menuData, tempId);
1380 }
1381
1382 menu_setprop(menu, MPROP_BACKNAME, "Wroc");
1383 menu_setprop(menu, MPROP_NEXTNAME, "Dalej");
1384 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1385
1386 menu_display(id, menu);
1387
1388 return PLUGIN_HANDLED;
1389}
1390
1391public market_sell_skin_handle(id, menu, item)
1392{
1393 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1394
1395 if (item == MENU_EXIT) {
1396 menu_destroy(menu);
1397
1398 return PLUGIN_HANDLED;
1399 }
1400
1401 new itemData[5], itemAccess, itemCallback;
1402
1403 menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
1404
1405 playerData[id][SALE_SKIN] = str_to_num(itemData);
1406
1407 menu_destroy(menu);
1408
1409 if (has_skin(id, playerData[id][SALE_SKIN], 1) == -1) {
1410 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz juz tego skina.");
1411
1412 return PLUGIN_HANDLED;
1413 }
1414
1415 client_cmd(id, "messagemode CENA_SKINA");
1416
1417 client_print_color(id, id, "^x04[CS:GO]^x01 Wpisz^x03 cene^x01, za ktora chcesz sprzedac skina.");
1418
1419 client_print(id, print_center, "Wpisz cene, za ktora chcesz sprzedac skina.");
1420
1421 return PLUGIN_HANDLED;
1422}
1423
1424public set_skin_price(id)
1425{
1426 if (!csgo_check_account(id) || end) return PLUGIN_HANDLED;
1427
1428 if (has_skin(id, playerData[id][SALE_SKIN], 1) == -1) {
1429 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz juz tego skina.");
1430
1431 return PLUGIN_HANDLED;
1432 }
1433
1434 if (get_market_skins(id) >= maxMarketSkins) {
1435 client_print_color(id, id, "^x04[CS:GO]^x01 Wystawiles juz maksymalne^x03 %i^x01 skinow na rynek!", maxMarketSkins);
1436
1437 return PLUGIN_HANDLED;
1438 }
1439
1440 new priceData[16], Float:price;
1441
1442 read_args(priceData, charsmax(priceData));
1443 remove_quotes(priceData);
1444
1445 price = str_to_float(priceData);
1446
1447 if (price < 1.0 || price > 9999.0) {
1448 client_print_color(id, id, "^x04[CS:GO]^x01 Cena musi nalezec do przedzialu^x03 1 - 9999 Euro^x01!");
1449
1450 return PLUGIN_HANDLED;
1451 }
1452
1453 new marketSkin[marketInfo], skin[skinsInfo];
1454
1455 marketSkin[MARKET_ID] = marketSkins++;
1456 marketSkin[MARKET_SKIN] = playerData[id][SALE_SKIN];
1457 marketSkin[MARKET_OWNER] = id;
1458 marketSkin[MARKET_PRICE] = price;
1459
1460 ArrayPushArray(market, marketSkin);
1461
1462 ArrayGetArray(skins, playerData[id][SALE_SKIN], skin);
1463
1464 change_local_skin(id, playerData[id][SALE_SKIN]);
1465
1466 client_print_color(0, id, "^x04[CS:GO]^x03 %s^x01 wystawil^x03 %s (%s)^x01 na rynek za^x03 %.2f Euro^x01.", playerData[id][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON], price);
1467
1468 return PLUGIN_HANDLED;
1469}
1470
1471public market_buy_skin(id)
1472{
1473 if (!is_user_connected(id) || !csgo_check_account(id) || end) return PLUGIN_HANDLED;
1474
1475 if (!playerData[id][SKINS_LOADED]) {
1476 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
1477
1478 return PLUGIN_HANDLED;
1479 }
1480
1481 new marketSkin[marketInfo], skin[skinsInfo], itemData[128], skinIds[16], skinsCounts = 0, menu = menu_create("\yWybierz \rSkin\y, ktory chcesz wykupic\w:", "market_buy_skin_handle");
1482
1483 for (new i = 0; i < ArraySize(market); i++) {
1484 ArrayGetArray(market, i, marketSkin);
1485
1486 if ((marketSkin[MARKET_OWNER] == id) || (!multipleSkins && has_skin(id, marketSkin[MARKET_SKIN]))) continue;
1487
1488 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1489
1490 formatex(skinIds, charsmax(skinIds), "%i#%i#%i", marketSkin[MARKET_ID], marketSkin[MARKET_SKIN], marketSkin[MARKET_OWNER]);
1491
1492 formatex(itemData, charsmax(itemData), "\w%s \r(%s) \y(%.2f Euro)", skin[SKIN_NAME], skin[SKIN_WEAPON], marketSkin[MARKET_PRICE]);
1493
1494 menu_additem(menu, itemData, skinIds);
1495
1496 skinsCounts++;
1497 }
1498
1499 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1500 menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
1501 menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
1502
1503 if (!skinsCounts) {
1504 menu_destroy(menu);
1505
1506 client_print_color(id, id, "^x04[CS:GO]^x01 Na rynku nie ma zadnych skinow, ktore moglbys kupic!");
1507 } else menu_display(id, menu);
1508
1509 return PLUGIN_HANDLED;
1510}
1511
1512public market_buy_skin_handle(id, menu, item)
1513{
1514 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1515
1516 if (item == MENU_EXIT) {
1517 menu_destroy(menu);
1518
1519 return PLUGIN_HANDLED;
1520 }
1521
1522 new itemIds[16], skinIds[3], itemAccess, itemCallback;
1523
1524 menu_item_getinfo(menu, item, itemAccess, itemIds, charsmax(itemIds), _, _, itemCallback);
1525
1526 explode_num(itemIds, '#', skinIds, sizeof(skinIds));
1527
1528 new skinId = check_market_skin(skinIds[0], skinIds[1], skinIds[2]);
1529
1530 if (skinId < 0) {
1531 market_menu(id);
1532
1533 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostal juz wykupiony lub wycofany z rynku!");
1534
1535 return PLUGIN_HANDLED;
1536 }
1537
1538 new marketSkin[marketInfo], skin[skinsInfo], menuData[512], length = 0, maxLength = charsmax(menuData);
1539
1540 ArrayGetArray(market, skinId, marketSkin);
1541
1542 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1543
1544 length += formatex(menuData[length], maxLength - length, "\yPotwierdzenie kupna od: \r%s^n", playerData[marketSkin[MARKET_OWNER]][NAME]);
1545 length += formatex(menuData[length], maxLength - length, "\wSkin: \y%s (%s)^n", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1546 length += formatex(menuData[length], maxLength - length, "\wKoszt: \y%.2f Euro^n", marketSkin[MARKET_PRICE]);
1547 length += formatex(menuData[length], maxLength - length, "\wCzy na pewno chcesz \rkupic\w tego skina?^n^n");
1548
1549 new menu = menu_create(menuData, "market_buy_confirm_handle");
1550
1551 menu_additem(menu, "\yTak", itemIds);
1552 menu_additem(menu, "\wNie");
1553
1554 menu_setprop(menu, MPROP_EXITNAME, "\wWyjscie");
1555
1556 menu_display(id, menu);
1557
1558 return PLUGIN_CONTINUE;
1559}
1560
1561public market_buy_confirm_handle(id, menu, item)
1562{
1563 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1564
1565 if (item == MENU_EXIT || item) {
1566 menu_destroy(menu);
1567
1568 return PLUGIN_HANDLED;
1569 }
1570
1571 new itemIds[16], skinIds[3], itemAccess, itemCallback;
1572
1573 menu_item_getinfo(menu, item, itemAccess, itemIds, charsmax(itemIds), _, _, itemCallback);
1574
1575 explode_num(itemIds, '#', skinIds, sizeof(skinIds));
1576
1577 new skinId = check_market_skin(skinIds[0], skinIds[1], skinIds[2]);
1578
1579 if (skinId < 0) {
1580 market_menu(id);
1581
1582 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostal juz wykupiony lub wycofany z rynku!");
1583
1584 return PLUGIN_HANDLED;
1585 }
1586
1587 new marketSkin[marketInfo];
1588
1589 ArrayGetArray(market, skinId, marketSkin);
1590
1591 if (playerData[id][MONEY] < marketSkin[MARKET_PRICE]) {
1592 client_print_color(id, id, "^x04[CS:GO]^x01 Nie masz wystarczajacej ilosci pieniedzy!");
1593
1594 return PLUGIN_HANDLED;
1595 }
1596
1597 new skin[skinsInfo], Float:priceAfterCommision = marketSkin[MARKET_PRICE] * ((100.0 - marketCommision) / 100.0);
1598
1599 change_local_skin(marketSkin[MARKET_OWNER], marketSkin[MARKET_SKIN], 1);
1600
1601 ArrayDeleteItem(market, skinId);
1602
1603 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1604
1605 playerData[marketSkin[MARKET_OWNER]][MONEY] += priceAfterCommision;
1606 playerData[id][MONEY] -= marketSkin[MARKET_PRICE];
1607
1608 add_skin(id, marketSkin[MARKET_SKIN], skin[SKIN_WEAPON], skin[SKIN_NAME]);
1609 remove_skin(marketSkin[MARKET_OWNER], marketSkin[MARKET_SKIN], skin[SKIN_WEAPON], skin[SKIN_NAME]);
1610
1611 client_print_color(id, id, "^x04[CS:GO]^x01 Skin^x03 %s (%s)^x01 zostal pomyslnie zakupiony.", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1612
1613 client_print_color(marketSkin[MARKET_OWNER], marketSkin[MARKET_OWNER], "^x04[CS:GO]^x01 Twoj skin^x03 %s (%s)^x01 zostal zakupiony przez^x03 %s^x01.", skin[SKIN_NAME], skin[SKIN_WEAPON], playerData[id][NAME]);
1614 client_print_color(marketSkin[MARKET_OWNER], marketSkin[MARKET_OWNER], "^x04[CS:GO]^x01 Za sprzedaz otrzymujesz^x03 %.2f Euro^x01.", priceAfterCommision);
1615
1616 log_to_file("csgo-sell.log", "Gracz %s sprzedal skina %s (%s) graczowi %s za %.2f Euro", playerData[marketSkin[MARKET_OWNER]][NAME], skin[SKIN_NAME], skin[SKIN_WEAPON], playerData[id][NAME], marketSkin[MARKET_PRICE]);
1617
1618 return PLUGIN_CONTINUE;
1619}
1620
1621public market_withdraw_skin(id)
1622{
1623 if (!is_user_connected(id) || !csgo_check_account(id) || end) return PLUGIN_HANDLED;
1624
1625 if (!playerData[id][SKINS_LOADED]) {
1626 client_print_color(id, id, "^x04[CS:GO]^x01 Trwa ladowanie twoich skinow...");
1627
1628 return PLUGIN_HANDLED;
1629 }
1630
1631 new marketSkin[marketInfo], skin[skinsInfo], itemData[128], skinIds[16], skinsCounts = 0, menu = menu_create("\yWybierz \rSkin\y, ktory chcesz wycofac z rynku\w:", "market_withdraw_skin_handle");
1632
1633 for (new i = 0; i < ArraySize(market); i++) {
1634 ArrayGetArray(market, i, marketSkin);
1635
1636 if (marketSkin[MARKET_OWNER] != id) continue;
1637
1638 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1639
1640 formatex(skinIds, charsmax(skinIds), "%i#%i#%i", marketSkin[MARKET_ID], marketSkin[MARKET_SKIN], marketSkin[MARKET_OWNER]);
1641
1642 formatex(itemData, charsmax(itemData), "\w%s \r(%s) \y(%.2f Euro)", skin[SKIN_NAME], skin[SKIN_WEAPON], marketSkin[MARKET_PRICE]);
1643
1644 menu_additem(menu, itemData, skinIds);
1645
1646 skinsCounts++;
1647 }
1648
1649 menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
1650 menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
1651 menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
1652
1653 if (!skinsCounts) {
1654 menu_destroy(menu);
1655
1656 client_print_color(id, id, "^x04[CS:GO]^x01 Na rynku nie ma zadnych twoich skinow!");
1657 } else menu_display(id, menu);
1658
1659 return PLUGIN_HANDLED;
1660}
1661
1662public market_withdraw_skin_handle(id, menu, item)
1663{
1664 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1665
1666 if (item == MENU_EXIT) {
1667 menu_destroy(menu);
1668
1669 return PLUGIN_HANDLED;
1670 }
1671
1672 new itemIds[16], skinIds[3], itemAccess, itemCallback;
1673
1674 menu_item_getinfo(menu, item, itemAccess, itemIds, charsmax(itemIds), _, _, itemCallback);
1675
1676 explode_num(itemIds, '#', skinIds, sizeof(skinIds));
1677
1678 new skinId = check_market_skin(skinIds[0], skinIds[1], skinIds[2]);
1679
1680 if (skinId < 0) {
1681 market_menu(id);
1682
1683 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostal juz wykupiony!");
1684
1685 return PLUGIN_HANDLED;
1686 }
1687
1688 new marketSkin[marketInfo], skin[skinsInfo], menuData[512], length = 0, maxLength = charsmax(menuData);
1689
1690 ArrayGetArray(market, skinId, marketSkin);
1691 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1692
1693 length += formatex(menuData[length], maxLength - length, "Potwierdzenie wycofania skina z rynku:^n");
1694 length += formatex(menuData[length], maxLength - length, "\wSkin: \y%s (%s)^n", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1695 length += formatex(menuData[length], maxLength - length, "\wKoszt: \y%.2f Euro^n", marketSkin[MARKET_PRICE]);
1696 length += formatex(menuData[length], maxLength - length, "\wCzy na pewno chcesz \rwycofac\w tego skina?^n^n");
1697
1698 new menu = menu_create(menuData, "market_withdraw_confirm_handle");
1699
1700 menu_additem(menu, "\yTak", itemIds);
1701 menu_additem(menu, "\wNie");
1702
1703 menu_setprop(menu, MPROP_EXITNAME, "\wWyjscie");
1704
1705 menu_display(id, menu);
1706
1707 return PLUGIN_CONTINUE;
1708}
1709
1710public market_withdraw_confirm_handle(id, menu, item)
1711{
1712 if (!is_user_connected(id) || end) return PLUGIN_HANDLED;
1713
1714 if (item == MENU_EXIT || item) {
1715 menu_destroy(menu);
1716
1717 return PLUGIN_HANDLED;
1718 }
1719
1720 new itemIds[16], skinIds[3], itemAccess, itemCallback;
1721
1722 menu_item_getinfo(menu, item, itemAccess, itemIds, charsmax(itemIds), _, _, itemCallback);
1723
1724 explode_num(itemIds, '#', skinIds, sizeof(skinIds));
1725
1726 new skinId = check_market_skin(skinIds[0], skinIds[1], skinIds[2]);
1727
1728 if (skinId < 0) {
1729 market_menu(id);
1730
1731 client_print_color(id, id, "^x04[CS:GO]^x01 Wybrany skin zostal juz wykupiony!");
1732
1733 return PLUGIN_HANDLED;
1734 }
1735
1736 new marketSkin[marketInfo], skin[skinsInfo];
1737
1738 ArrayGetArray(market, skinId, marketSkin);
1739 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
1740
1741 change_local_skin(id, marketSkin[MARKET_SKIN], 1);
1742
1743 ArrayDeleteItem(market, skinId);
1744
1745 client_print_color(id, id, "^x04[CS:GO]^x01 Skin^x03 %s (%s)^x01 zostal pomyslnie wycofany z rynku.", skin[SKIN_NAME], skin[SKIN_WEAPON]);
1746
1747 return PLUGIN_CONTINUE;
1748}
1749
1750public cmd_add_money(id)
1751{
1752 if (!(get_user_flags(id) & ADMIN_ADMIN)) return PLUGIN_HANDLED;
1753
1754 new playerName[32], tempMoney[4];
1755
1756 read_argv(1, playerName, charsmax(playerName));
1757 read_argv(2, tempMoney, charsmax(tempMoney));
1758
1759 new Float:addedMoney = str_to_float(tempMoney), player = cmd_target(id, playerName, 0);
1760
1761 if (!player) {
1762 console_print(id, "[CS:GO] Nie znaleziono podanego gracza!", playerName);
1763
1764 return PLUGIN_HANDLED;
1765 }
1766
1767 if (addedMoney < 0.1) {
1768 console_print(id, "[CS:GO] Minimalnie mozna dodac 0.1 Euro!");
1769
1770 return PLUGIN_HANDLED;
1771 }
1772
1773 playerData[player][MONEY] += addedMoney;
1774
1775 save_data(player);
1776
1777 client_print_color(player, player, "^x04[CS:GO]^x03 %s^x01 przyznal ci^x04 %.2f Euro^x01!", playerData[id][NAME], addedMoney);
1778 client_print_color(id, id, "^x04[CS:GO]^x01 Przyznales^x04 %.2f Euro^x01 graczowi^x03 %s^x01.", addedMoney, playerData[player][NAME]);
1779
1780 log_to_file("csgo-admin.log", "%s przyznal %.2f Euro graczowi %s.", playerData[id][NAME], addedMoney, playerData[player][NAME]);
1781
1782 return PLUGIN_HANDLED;
1783}
1784
1785public client_death(killer, victim, weaponId, hitPlace, teamKill)
1786{
1787 if (!is_user_connected(killer) || !is_user_connected(victim) || !is_user_alive(killer) || get_user_team(victim) == get_user_team(killer) || get_playersnum() < minPlayers) return PLUGIN_CONTINUE;
1788
1789 playerData[killer][MONEY] += killReward * get_multiplier(killer);
1790
1791 if (hitPlace == HIT_HEAD) playerData[killer][MONEY] += killHSReward * get_multiplier(killer);
1792
1793 save_data(killer);
1794
1795 return PLUGIN_CONTINUE;
1796}
1797
1798public log_event_operation()
1799{
1800 if (get_playersnum() < minPlayers) return PLUGIN_CONTINUE;
1801
1802 new userLog[80], userAction[64], userName[32];
1803
1804 read_logargv(0, userLog, charsmax(userLog));
1805 read_logargv(2, userAction, charsmax(userAction));
1806 parse_loguser(userLog, userName, charsmax(userName));
1807
1808 new id = get_user_index(userName);
1809
1810 if (!is_user_connected(id)) return PLUGIN_CONTINUE;
1811
1812 if (equal(userAction, "Planted_The_Bomb")) {
1813 new Float:money = bombReward * get_multiplier(id);
1814
1815 playerData[id][MONEY] += money;
1816
1817 client_print_color(id, id, "^x04[CS:GO]^x01 Dostales^x03 %.2f Euro^x01 za podlozenie bomby.", money);
1818
1819 save_data(id);
1820 }
1821
1822 if (equal(userAction, "Defused_The_Bomb")) {
1823 new Float:money = defuseReward * get_multiplier(id);
1824
1825 playerData[id][MONEY] += money;
1826
1827 client_print_color(id, id, "^x04[CS:GO]^x01 Dostales^x03 %.2f Euro^x01 za rozbrojenie bomby.", money);
1828
1829 save_data(id);
1830 }
1831
1832 return PLUGIN_CONTINUE;
1833}
1834
1835public t_win_round()
1836 round_winner(1);
1837
1838public ct_win_round()
1839 round_winner(2);
1840
1841public round_winner(team)
1842{
1843 if (get_playersnum() < minPlayers) return;
1844
1845 for (new id = 1; id < MAX_PLAYERS; id++) {
1846 if (!is_user_connected(id) || get_user_team(id) != team) continue;
1847
1848 new Float:money = winReward * get_multiplier(id);
1849
1850 playerData[id][MONEY] += money;
1851
1852 client_print_color(id, id, "^x04[CS:GO]^x01 Dostales^x03 %.2f Euro^x01 za wygrana runde.", money);
1853
1854 save_data(id);
1855 }
1856}
1857
1858public hostages_rescued()
1859{
1860 if (get_playersnum() < minPlayers) return;
1861
1862 new id = get_loguser_index(), Float:money = hostageReward * get_multiplier(id);
1863
1864 playerData[id][MONEY] += money;
1865
1866 client_print_color(id, id, "^x04[CS:GO]^x01 Dostales^x03 %.2f Euro^x01 za uratowanie zakladnikow.", money);
1867
1868 save_data(id);
1869}
1870
1871stock get_loguser_index()
1872{
1873 new userLog[96], userName[32];
1874
1875 read_logargv(0, userLog, charsmax(userLog));
1876 parse_loguser(userLog, userName, charsmax(userName));
1877
1878 return get_user_index(userName);
1879}
1880
1881public message_intermission()
1882{
1883 end = true;
1884
1885 for (new id = 1; id <= MAX_PLAYERS; id++) {
1886 if (!is_user_connected(id) || is_user_hltv(id) || is_user_bot(id)) continue;
1887
1888 new Float:money;
1889
1890 playerData[id][MONEY] += (money = random_float(1.0, 3.0));
1891
1892 client_print_color(id, id, "^x04[CS:GO]^x01 Za gre na tej mapie otrzymujesz^x03 %.2f Euro^x01.", money);
1893
1894 save_data(id, 1);
1895 }
1896
1897 return PLUGIN_CONTINUE;
1898}
1899
1900public set_fov(id)
1901{
1902 if (playerData[id][SKIN] > -1 && (!playerData[id][TEMP][WEAPON_ENT] || is_valid_ent(playerData[id][TEMP][WEAPON_ENT])) && (playerData[id][TEMP][WEAPON] == CSW_AWP || playerData[id][TEMP][WEAPON] == CSW_SCOUT)) {
1903 switch (read_data(1)) {
1904 case 10..55: {
1905 if (playerData[id][TEMP][WEAPON] == CSW_AWP) set_pev(id, pev_viewmodel2, "models/v_awp.mdl");
1906 else set_pev(id, pev_viewmodel2, "models/v_scout.mdl");
1907 } case 90: {
1908 if (is_valid_ent(playerData[id][TEMP][WEAPON_ENT])) change_skin(id, playerData[id][TEMP][WEAPON], playerData[id][TEMP][WEAPON_ENT]);
1909 else change_skin(id, playerData[id][TEMP][WEAPON]);
1910 }
1911 }
1912 }
1913}
1914
1915public client_command(id)
1916{
1917 static weapons[32], weaponsNum;
1918
1919 playerData[id][TEMP][WEAPONS] = get_user_weapons(id, weapons, weaponsNum);
1920}
1921
1922public event_money(id)
1923{
1924 new oldWeapons = playerData[id][TEMP][WEAPONS];
1925
1926 client_command(id);
1927
1928 new newWeapon = playerData[id][TEMP][WEAPONS] & ~oldWeapons;
1929
1930 if (newWeapon) {
1931 new x = -1;
1932 do ++x; while ((newWeapon /= 2) >= 1);
1933
1934 ExecuteHamB(Ham_GiveAmmo, id, maxBPAmmo[x], ammoType[x], maxBPAmmo[x]);
1935 }
1936}
1937
1938public weapon_deploy_post(ent)
1939{
1940 static id; id = get_pdata_cbase(ent, 41, 4);
1941
1942 if (!is_user_alive(id)) return HAM_IGNORED;
1943
1944 playerData[id][TEMP][WEAPON] = cs_get_weapon_id(ent);
1945
1946 change_skin(id, playerData[id][TEMP][WEAPON], ent);
1947
1948 return HAM_IGNORED;
1949}
1950
1951public player_spawn(id)
1952{
1953 if (!task_exists(id + TASK_AIM)) set_task(0.1, "check_aim_weapon", id + TASK_AIM, .flags="b");
1954
1955 new weapons[32], weaponsNum, weapon;
1956
1957 get_user_weapons(id, weapons, weaponsNum);
1958
1959 for (new i = 0; i < weaponsNum; i++) {
1960 weapon = weapons[i];
1961
1962 ExecuteHamB(Ham_GiveAmmo, id, maxBPAmmo[weapon], ammoType[weapon], maxBPAmmo[weapon]);
1963 }
1964}
1965
1966public add_player_item(id, ent)
1967{
1968 if (!pev_valid(ent) || !is_user_connected(id) || is_user_bot(id) || is_user_hltv(id)) return HAM_IGNORED;
1969
1970 new owner = entity_get_int(ent, EV_INT_iuser1);
1971
1972 if (!is_user_connected(owner)) {
1973 entity_set_int(ent, EV_INT_iuser1, id);
1974 entity_set_int(ent, EV_INT_iuser2, get_weapon_skin(id, cs_get_weapon_id(ent)));
1975 }
1976
1977 return HAM_IGNORED;
1978}
1979
1980public set_model(ent, model[])
1981{
1982 if (!pev_valid(ent)) return HAM_IGNORED;
1983
1984 new id = entity_get_edict(ent, EV_ENT_owner);
1985
1986 if (!is_user_connected(id) || is_user_bot(id) || is_user_hltv(id) || !fm_get_weaponbox_type(ent)) return HAM_IGNORED;
1987
1988 new owner = entity_get_int(ent, EV_INT_iuser1);
1989
1990 if (!is_user_connected(owner)) {
1991 entity_set_int(ent, EV_INT_iuser1, id);
1992 entity_set_int(ent, EV_INT_iuser2, get_weapon_skin(id, fm_get_weaponbox_type(ent)));
1993 }
1994
1995 return HAM_IGNORED;
1996}
1997
1998public check_aim_weapon(id)
1999{
2000 id -= TASK_AIM;
2001
2002 if (!is_user_alive(id)) return FMRES_IGNORED;
2003
2004 static bool:canPickup[MAX_PLAYERS + 1], weaponHud, ent;
2005
2006 ent = fm_get_user_aiming_ent(id, "weaponbox");
2007
2008 if (!weaponHud) weaponHud = CreateHudSyncObj();
2009
2010 if (!is_valid_ent(ent) || task_exists(ent)) {
2011 if (canPickup[id]) ClearSyncHud(id, weaponHud);
2012
2013 canPickup[id] = false;
2014
2015 return FMRES_IGNORED;
2016 }
2017
2018 static Float:origin[2][3];
2019
2020 pev(id, pev_origin, origin[0]);
2021 pev(ent, pev_origin, origin[1]);
2022
2023 if (get_distance_f(origin[0], origin[1]) >= 120.0) {
2024 if (canPickup[id]) ClearSyncHud(id, weaponHud);
2025
2026 canPickup[id] = false;
2027
2028 return FMRES_IGNORED;
2029 }
2030
2031 new playerWeapon[32], weapon = fm_get_weaponbox_type(ent);
2032
2033 if ((weapon == CSW_C4 && get_user_team(id) != 1) || !weapon) return FMRES_IGNORED;
2034
2035 canPickup[id] = true;
2036
2037 get_weapon_skin_name(id, ent, playerWeapon, charsmax(playerWeapon), weapon);
2038
2039 set_hudmessage(0, 120, 250, -1.0, 0.7, 0, 1.0, 1.0, 0.1, 0.1, 3);
2040
2041 ShowSyncHudMsg(id, weaponHud, "[E] Podnies %s", playerWeapon);
2042
2043 if (get_user_button(id) & IN_USE) {
2044 static weaponName[32], data[2];
2045
2046 data[0] = id;
2047 data[1] = ent;
2048
2049 for (new i = 1; i <= CSW_P90; i++) {
2050 if (weaponSlots[i] == weaponSlots[weapon] && user_has_weapon(id, i)) {
2051 get_weaponname(i, weaponName, charsmax(weaponName));
2052
2053 engclient_cmd(id, "drop", weaponName);
2054
2055 break;
2056 }
2057 }
2058
2059 set_task(0.1, "give_weapons", ent, data, sizeof(data));
2060
2061 ClearSyncHud(id, weaponHud);
2062 }
2063
2064 return FMRES_IGNORED;
2065}
2066
2067public give_weapons(data[2])
2068{
2069 if (pev_valid(data[1]) && is_user_alive(data[0])) {
2070 ExecuteHamB(Ham_Touch, data[0], data[1]);
2071 ExecuteHamB(Ham_Touch, data[1], data[0]);
2072
2073 emit_sound(data[0], CHAN_ITEM, "items/gunpickup2.wav", 1.0, 0.8, SND_SPAWNING, PITCH_NORM);
2074 }
2075}
2076
2077stock change_skin(id, weapon, ent = 0)
2078{
2079 playerData[id][SKIN] = -1;
2080 playerData[id][TEMP][WEAPON_ENT] = 0;
2081
2082 if (!is_user_alive(id) || weapon == CSW_HEGRENADE || weapon == CSW_SMOKEGRENADE || weapon == CSW_FLASHBANG || weapon == CSW_C4 || !weapon || playerData[id][SKINS_DISABLED]) return;
2083
2084 static skin[skinsInfo];
2085
2086 if (is_valid_ent(ent) && weapon != CSW_KNIFE) {
2087 static weaponOwner, weaponSkin;
2088
2089 weaponOwner = entity_get_int(ent, EV_INT_iuser1);
2090
2091 if (is_user_connected(weaponOwner) && !is_user_hltv(weaponOwner) && !is_user_bot(weaponOwner)) {
2092 playerData[id][TEMP][WEAPON_ENT] = ent;
2093
2094 weaponSkin = entity_get_int(ent, EV_INT_iuser2);
2095
2096 if (weaponSkin > -1) {
2097 static weaponName[32];
2098
2099 ArrayGetArray(skins, weaponSkin, skin);
2100
2101 get_weaponname(weapon, weaponName, charsmax(weaponName));
2102
2103 playerData[id][SKIN] = weaponSkin;
2104
2105 set_pev(id, pev_viewmodel2, skin[SKIN_MODEL]);
2106
2107 if (weapon == get_weapon_id(skin[SKIN_WEAPON])) {
2108 playerData[id][SKIN] = weaponSkin;
2109
2110 set_pev(id, pev_viewmodel2, skin[SKIN_MODEL]);
2111 } else {
2112 entity_set_int(ent, EV_INT_iuser1, 0);
2113 entity_set_int(ent, EV_INT_iuser2, -1);
2114 }
2115 } else if (defaultSkins) set_pev(id, pev_viewmodel2, defaultSkin[weapon]);
2116
2117 return;
2118 }
2119 }
2120
2121 if (playerData[id][ACTIVE][weapon] > -1) {
2122 ArrayGetArray(skins, playerData[id][ACTIVE][weapon], skin);
2123
2124 playerData[id][SKIN] = playerData[id][ACTIVE][weapon];
2125
2126 set_pev(id, pev_viewmodel2, skin[SKIN_MODEL]);
2127 } else if (defaultSkins) set_pev(id, pev_viewmodel2, (weapon == CSW_KNIFE && get_user_team(id) == 1) ? defaultSkin[weapon + 2] : defaultSkin[weapon]);
2128}
2129
2130stock get_weapon_skin(id, weapon)
2131{
2132 if (!is_user_connected(id) || is_user_hltv(id) || is_user_bot(id) || weapon == CSW_HEGRENADE || weapon == CSW_SMOKEGRENADE || weapon == CSW_FLASHBANG || weapon == CSW_C4 || !weapon || weapon > CSW_P90) return -1;
2133
2134 if (playerData[id][ACTIVE][weapon] > -1) {
2135 static skin[skinsInfo];
2136
2137 ArrayGetArray(skins, playerData[id][ACTIVE][weapon], skin);
2138
2139 return playerData[id][ACTIVE][weapon];
2140 }
2141
2142 return -1;
2143}
2144
2145public load_data(id)
2146{
2147 if (!sqlConnected)
2148 {
2149 set_task(1.0, "load_data", id);
2150
2151 return;
2152 }
2153
2154 id -= TASK_DATA;
2155
2156 new playerId[1], queryData[128];
2157
2158 playerId[0] = id;
2159
2160 formatex(queryData, charsmax(queryData), "SELECT * FROM `csgo_data` WHERE name = ^"%s^"", playerData[id][SAFE_NAME]);
2161
2162 SQL_ThreadQuery(sql, "load_data_handle", queryData, playerId, sizeof(playerId));
2163}
2164
2165public load_data_handle(failState, Handle:query, error[], errorNum, playerId[], dataSize)
2166{
2167 if (failState) {
2168 log_to_file("csgo-error.log", "[CS:GO] SQL Error: %s (%d)", error, errorNum);
2169
2170 return;
2171 }
2172
2173 new id = playerId[0];
2174
2175 if (SQL_MoreResults(query))
2176 {
2177 SQL_ReadResult(query, SQL_FieldNameToNum(query, "money"), playerData[id][MONEY]);
2178
2179 if (SQL_ReadResult(query, SQL_FieldNameToNum(query, "disabled"))) playerData[id][SKINS_DISABLED] = true;
2180 if (SQL_ReadResult(query, SQL_FieldNameToNum(query, "exchange"))) playerData[id][EXCHANGE_BLOCKED] = true;
2181 if (SQL_ReadResult(query, SQL_FieldNameToNum(query, "menu"))) playerData[id][MENU_BLOCKED] = true;
2182 } else {
2183 new queryData[192];
2184
2185 formatex(queryData, charsmax(queryData), "INSERT INTO `csgo_data` (`name`, `money`, `disabled`, `exchange`, `menu`, `online`, `klucze`, `skrzynie`) VALUES (^"%s^", '0', '0', '0', '0', '0', '0', '0');", playerData[id][SAFE_NAME]);
2186
2187 SQL_ThreadQuery(sql, "ignore_handle", queryData);
2188 }
2189
2190 playerData[id][DATA_LOADED] = true;
2191
2192 save_data(id);
2193}
2194
2195
2196stock save_data(id, end = 0)
2197{
2198 if (!playerData[id][DATA_LOADED]) return;
2199
2200 new queryData[192];
2201
2202 formatex(queryData, charsmax(queryData), "UPDATE `csgo_data` SET `money` = %f, `disabled` = %i, `exchange` = %i, `menu` = %i, `online` = %i, `klucze` = %i, `skrzynie` = %i WHERE name = ^"%s^"",
2203 playerData[id][MONEY], playerData[id][SKINS_DISABLED], playerData[id][EXCHANGE_BLOCKED], playerData[id][MENU_BLOCKED], end ? 0 : 1, playerData[id][KEY], playerData[id][CHEST], playerData[id][SAFE_NAME]);
2204
2205 switch (end) {
2206 case 0, 1: SQL_ThreadQuery(sql, "ignore_handle", queryData);
2207 case 2: {
2208 static error[128], errorNum, Handle:query;
2209
2210 query = SQL_PrepareQuery(connection, queryData);
2211
2212 if (!SQL_Execute(query)) {
2213 errorNum = SQL_QueryError(query, error, charsmax(error));
2214
2215 log_to_file("csgo-error.log", "Save Query Nonthreaded failed. [%d] %s", errorNum, error);
2216
2217 SQL_FreeHandle(query);
2218
2219 return;
2220 }
2221
2222 SQL_FreeHandle(query);
2223 }
2224 }
2225
2226 if (end) playerData[id][DATA_LOADED] = false;
2227}
2228
2229public load_skins(id)
2230{
2231 if (!sqlConnected)
2232 {
2233 set_task(1.0, "load_skins", id);
2234
2235 return;
2236 }
2237
2238 id -= TASK_SKINS;
2239
2240 new playerId[1], queryData[128];
2241
2242 playerId[0] = id;
2243
2244 formatex(queryData, charsmax(queryData), "SELECT * FROM `csgo_skins` WHERE name = ^"%s^"", playerData[id][SAFE_NAME]);
2245
2246 SQL_ThreadQuery(sql, "load_skins_handle", queryData, playerId, sizeof(playerId));
2247}
2248
2249public load_skins_handle(failState, Handle:query, error[], errorandomNumber, playerId[], dataSize)
2250{
2251 if (failState) {
2252 log_to_file("csgo-error.log", "[CS:GO] SQL Error: %s (%d)", error, errorandomNumber);
2253
2254 return;
2255 }
2256
2257 new id = playerId[0], skin[skinsInfo];
2258
2259 while(SQL_MoreResults(query)) {
2260 SQL_ReadResult(query, SQL_FieldNameToNum(query, "skin"), skin[SKIN_NAME], charsmax(skin[SKIN_NAME]));
2261 SQL_ReadResult(query, SQL_FieldNameToNum(query, "weapon"), skin[SKIN_WEAPON], charsmax(skin[SKIN_WEAPON]));
2262
2263 if (contain(skin[SKIN_WEAPON], "ACTIVE") != -1) {
2264 replace(skin[SKIN_WEAPON], charsmax(skin[SKIN_WEAPON]), " ACTIVE", "");
2265
2266 set_skin(id, skin[SKIN_WEAPON], skin[SKIN_NAME], get_skin_id(skin[SKIN_NAME], skin[SKIN_WEAPON]));
2267 } else {
2268 new skinId = get_skin_id(skin[SKIN_NAME], skin[SKIN_WEAPON]);
2269
2270 if (skinId > -1) {
2271 static playerSkin[playerSkinsInfo];
2272
2273 playerSkin[SKIN_ID] = skinId;
2274 playerSkin[SKIN_COUNT] = SQL_ReadResult(query, SQL_FieldNameToNum(query, "count"));
2275
2276 ArrayPushArray(playerSkins[id], playerSkin);
2277 }
2278 }
2279
2280 SQL_NextRow(query);
2281 }
2282
2283 playerData[id][SKINS_LOADED] = true;
2284}
2285
2286public ignore_handle(failState, Handle:query, error[], errorandomNumber, data[], dataSize)
2287{
2288 if(failState)
2289 {
2290 if (failState == TQUERY_CONNECT_FAILED)
2291 {
2292 log_to_file("csgo-error.log", "[CS:GO] Could not connect to SQL database. [%d] %s", errorandomNumber, error);
2293 }
2294 else if (failState == TQUERY_QUERY_FAILED)
2295 {
2296 log_to_file("csgo-error.log", "[CS:GO] Query failed. [%d] %s", errorandomNumber, error);
2297 }
2298 }
2299
2300 return PLUGIN_CONTINUE;
2301}
2302
2303public Float:_csgo_get_money(id)
2304{
2305 return Float:playerData[id][MONEY];
2306}
2307
2308public _csgo_get_key(id)
2309{
2310 return playerData[id][KEY];
2311}
2312
2313public _csgo_get_chest(id)
2314{
2315 return playerData[id][CHEST];
2316}
2317
2318public _csgo_add_money(id, Float:amount)
2319{
2320 playerData[id][MONEY] = floatmax(0.0, playerData[id][MONEY] + amount);
2321
2322 save_data(id);
2323}
2324
2325public _csgo_add_key(id, amount)
2326{
2327 playerData[id][KEY] = playerData[id][KEY] + amount;
2328
2329 save_data(id);
2330}
2331
2332public _csgo_add_chest(id, amount)
2333{
2334 playerData[id][CHEST] = playerData[id][CHEST] + amount;
2335
2336 save_data(id);
2337}
2338
2339public _csgo_set_money(id, Float:amount)
2340{
2341 playerData[id][MONEY] = floatmax(0.0, amount);
2342
2343 save_data(id);
2344}
2345
2346public _csgo_set_key(id, amount)
2347{
2348 playerData[id][KEY] = amount;
2349
2350 save_data(id);
2351}
2352
2353public _csgo_set_chest(id, amount)
2354{
2355 playerData[id][CHEST] = amount;
2356
2357 save_data(id);
2358}
2359
2360public _csgo_get_menu(id)
2361{
2362 return playerData[id][MENU_BLOCKED];
2363}
2364
2365public _csgo_get_skin(id)
2366{
2367 return playerData[id][SKIN];
2368}
2369
2370public _csgo_get_weapon_skin(id, weapon)
2371{
2372 return get_weapon_skin(id, weapon);
2373}
2374
2375public _csgo_get_skin_name(skin, dataReturn[], dataLength)
2376{
2377 param_convert(2);
2378
2379 if (skin > -1) get_skin_info(skin, SKIN_NAME, dataReturn, dataLength);
2380 else formatex(dataReturn, dataLength, "Domyslny");
2381}
2382
2383public _csgo_get_current_skin_name(id, dataReturn[], dataLength)
2384{
2385 param_convert(2);
2386
2387 if (get_weapon_skin_name(id, playerData[id][TEMP][WEAPON_ENT], dataReturn, dataLength, 0, 1)) return;
2388
2389 if (playerData[id][SKIN] > -1) get_skin_info(playerData[id][SKIN], SKIN_NAME, dataReturn, dataLength);
2390 else formatex(dataReturn, dataLength, "Domyslny");
2391}
2392
2393stock get_weapon_skin_name(id, ent, dataReturn[], dataLength, weapon = 0, check = 0)
2394{
2395 static ownerName[32], weaponName[32], skinWeapon[32], weaponOwner, weaponSkin;
2396 weaponOwner = 0, weaponSkin = -1;
2397
2398 if (is_valid_ent(ent)) {
2399 weaponOwner = entity_get_int(ent, EV_INT_iuser1);
2400
2401 if (is_user_connected(weaponOwner) && !is_user_hltv(weaponOwner) && !is_user_bot(weaponOwner)) {
2402 weaponSkin = entity_get_int(ent, EV_INT_iuser2);
2403
2404 if (weaponSkin > -1) {
2405 get_skin_info(weaponSkin, SKIN_WEAPON, skinWeapon, charsmax(skinWeapon));
2406
2407 if (!weapon || weapon == get_weapon_id(skinWeapon)) get_skin_info(weaponSkin, SKIN_NAME, dataReturn, dataLength);
2408 else {
2409 entity_set_int(ent, EV_INT_iuser1, 0);
2410 entity_set_int(ent, EV_INT_iuser2, -1);
2411
2412 formatex(dataReturn, dataLength, "Domyslny");
2413 }
2414 } else formatex(dataReturn, dataLength, "Domyslny");
2415
2416 if (check && weaponOwner != id) {
2417 get_user_name(weaponOwner, ownerName, charsmax(ownerName));
2418
2419 format(dataReturn, dataLength, "%s (%s)", dataReturn, ownerName);
2420
2421 return true;
2422 }
2423 }
2424
2425 if (weapon) {
2426 get_weaponname(weapon, weaponName, charsmax(weaponName));
2427
2428 strtoupper(weaponName);
2429
2430 if (equal(dataReturn, "Domyslny") || !dataReturn[0]) formatex(dataReturn, dataLength, weaponName[7]);
2431 else format(dataReturn, dataLength, "%s | %s", weaponName[7], dataReturn);
2432 }
2433 }
2434
2435 return false;
2436}
2437
2438stock Float:get_multiplier(id)
2439{
2440 if (csgo_get_user_svip(id)) return 1.5;
2441 else if (csgo_get_user_vip(id)) return 1.25;
2442 else return 1.0;
2443}
2444
2445stock get_weapon_skins_count(weapon[], chance = 0)
2446{
2447 new skin[skinsInfo], weaponSkinsCount = 0;
2448
2449 for (new i = 0; i < ArraySize(skins); i++) {
2450 ArrayGetArray(skins, i, skin);
2451
2452 if (equal(weapon, skin[SKIN_WEAPON]) || equal(weapon, "Wszystkie")) weaponSkinsCount += chance ? skin[SKIN_CHANCE] : 1;
2453 }
2454
2455 return weaponSkinsCount;
2456}
2457
2458stock get_missing_weapon_skins_count(id, weapon[], chance = 0)
2459{
2460 new skin[skinsInfo], marketSkin[marketInfo], playerSkinsCount = 0, skinId;
2461
2462 for (new i = 0; i < ArraySize(playerSkins[id]); i++) {
2463 skinId = get_player_skin_info(id, i, SKIN_ID);
2464
2465 ArrayGetArray(skins, skinId, skin);
2466
2467 if (equal(weapon, skin[SKIN_WEAPON]) || equal(weapon, "Wszystkie")) playerSkinsCount += chance ? skin[SKIN_CHANCE] : 1;
2468 }
2469
2470 for (new i = 0; i < ArraySize(market); i++) {
2471 ArrayGetArray(market, i, marketSkin);
2472
2473 if (marketSkin[MARKET_OWNER] == id) {
2474 ArrayGetArray(skins, marketSkin[MARKET_SKIN], skin);
2475
2476 if (equal(weapon, skin[SKIN_WEAPON]) || equal(weapon, "Wszystkie")) playerSkinsCount += chance ? skin[SKIN_CHANCE] : 1;
2477 }
2478 }
2479
2480 return get_weapon_skins_count(weapon) - playerSkinsCount;
2481}
2482
2483stock get_weapon_id(weapon[])
2484{
2485 new weaponName[32];
2486
2487 formatex(weaponName, charsmax(weaponName), "weapon_%s", weapon);
2488
2489 strtolower(weaponName);
2490
2491 return get_weaponid(weaponName);
2492}
2493
2494stock has_skin(id, skin, check = 0)
2495{
2496 if (!check) {
2497 static marketSkin[marketInfo];
2498
2499 for (new i = 0; i < ArraySize(market); i++) {
2500 ArrayGetArray(market, i, marketSkin);
2501
2502 if (marketSkin[MARKET_OWNER] == id && marketSkin[MARKET_SKIN] == skin) return 1;
2503 }
2504 }
2505
2506 for (new i = 0; i < ArraySize(playerSkins[id]); i++) {
2507 if (get_player_skin_info(id, i, SKIN_ID) == skin) return check ? i : 1;
2508 }
2509
2510 return check ? -1 : 0;
2511}
2512
2513stock change_local_skin(id, skinId, add = 0)
2514{
2515 new playerSkin[playerSkinsInfo], skinIndex = has_skin(id, skinId, 1);
2516
2517 if (skinIndex > -1) {
2518 ArrayGetArray(playerSkins[id], skinIndex, playerSkin);
2519
2520 if (!add) {
2521 playerSkin[SKIN_COUNT]--;
2522
2523 if (playerSkin[SKIN_COUNT] <= 0) {
2524 ArrayDeleteItem(playerSkins[id], skinIndex);
2525
2526 return false;
2527 }
2528 } else playerSkin[SKIN_COUNT]++;
2529
2530 ArraySetArray(playerSkins[id], skinIndex, playerSkin);
2531 } else if (add) {
2532 playerSkin[SKIN_ID] = skinId;
2533 playerSkin[SKIN_COUNT] = 1;
2534
2535 ArrayPushArray(playerSkins[id], playerSkin);
2536 } else return false;
2537
2538 return true;
2539}
2540
2541stock remove_skin(id, skinId, weapon[], skin[])
2542{
2543 if (!playerData[id][SKINS_LOADED]) return;
2544
2545 new queryData[192], skinSafeName[64];
2546
2547 mysql_escape_string(skin, skinSafeName, charsmax(skinSafeName));
2548
2549 if (!change_local_skin(id, skinId)) formatex(queryData, charsmax(queryData), "DELETE FROM `csgo_skins` WHERE name = ^"%s^" AND weapon = '%s' AND skin = '%s'", playerData[id][SAFE_NAME], weapon, skinSafeName);
2550 else formatex(queryData, charsmax(queryData), "UPDATE `csgo_skins` SET count = count - 1 WHERE name = ^"%s^" AND weapon = '%s' AND skin = '%s'", playerData[id][SAFE_NAME], weapon, skinSafeName);
2551
2552 if (playerData[id][ACTIVE][get_weapon_id(weapon)] == skinId) {
2553 set_skin(id, weapon);
2554
2555 remove_active_skin(id, weapon);
2556 }
2557
2558 SQL_ThreadQuery(sql, "ignore_handle", queryData);
2559}
2560
2561stock remove_active_skin(id, weapon[])
2562{
2563 if (!playerData[id][SKINS_LOADED]) return;
2564
2565 new queryData[192];
2566
2567 formatex(queryData, charsmax(queryData), "DELETE FROM `csgo_skins` WHERE name = ^"%s^" AND weapon = '%s ACTIVE'", playerData[id][SAFE_NAME], weapon);
2568
2569 SQL_ThreadQuery(sql, "ignore_handle", queryData);
2570}
2571
2572stock add_skin(id, skinId, weapon[], skin[])
2573{
2574 if (!playerData[id][SKINS_LOADED] || (!multipleSkins && has_skin(id, skinId))) return;
2575
2576 new queryData[192], skinSafeName[64];
2577
2578 mysql_escape_string(skin, skinSafeName, charsmax(skinSafeName));
2579
2580 formatex(queryData, charsmax(queryData), "INSERT INTO `csgo_skins` (`name`, `weapon`, `skin`) VALUES (^"%s^", '%s', '%s') ON DUPLICATE KEY UPDATE count = count + 1;", playerData[id][SAFE_NAME], weapon, skinSafeName);
2581
2582 SQL_ThreadQuery(sql, "ignore_handle", queryData);
2583
2584 if (skinId > -1) {
2585 change_local_skin(id, skinId, 1);
2586
2587 if (playerData[id][ACTIVE][get_weapon_id(weapon)] == -1) set_skin(id, weapon, skin, skinId, 1);
2588 }
2589}
2590
2591stock set_skin(id, weapon[], skin[] = "", skinId = -1, active = 0)
2592{
2593 if (skinId >= ArraySize(skins) || skinId < 0) return;
2594
2595 playerData[id][ACTIVE][get_weapon_id(weapon)] = skinId;
2596
2597 if (active && playerData[id][SKINS_LOADED]) {
2598 new queryData[192], skinSafeName[64];
2599
2600 mysql_escape_string(skin, skinSafeName, charsmax(skinSafeName));
2601
2602 formatex(queryData, charsmax(queryData), "INSERT INTO `csgo_skins` (`name`, `weapon`, `skin`) VALUES (^"%s^", '%s ACTIVE', '%s');", playerData[id][SAFE_NAME], weapon, skinSafeName);
2603
2604 SQL_ThreadQuery(sql, "ignore_handle", queryData);
2605 }
2606}
2607
2608stock get_skin_id(const name[], const weapon[])
2609{
2610 static skin[skinsInfo];
2611
2612 for (new i = 0; i < ArraySize(skins); i++) {
2613 ArrayGetArray(skins, i, skin);
2614
2615 if (equal(name, skin[SKIN_NAME]) && equal(weapon, skin[SKIN_WEAPON])) return i;
2616 }
2617
2618 return -1;
2619}
2620
2621stock get_skin_info(skinId, info, dataReturn[] = "", dataLength = 0)
2622{
2623 static skin[skinsInfo];
2624
2625 ArrayGetArray(skins, skinId, skin);
2626
2627 if (info == SKIN_NAME || info == SKIN_WEAPON || info == SKIN_MODEL) {
2628 copy(dataReturn, dataLength, skin[info]);
2629
2630 return 0;
2631 }
2632
2633 return skin[info];
2634}
2635
2636stock get_player_skin_info(id, skinId, info)
2637{
2638 static playerSkin[playerSkinsInfo];
2639
2640 ArrayGetArray(playerSkins[id], skinId, playerSkin);
2641
2642 return playerSkin[info];
2643}
2644
2645stock get_market_skins(id)
2646{
2647 if (!is_user_connected(id)) return 0;
2648
2649 new marketSkin[marketInfo], amount = 0;
2650
2651 for (new i = 0; i < ArraySize(market); i++) {
2652 ArrayGetArray(market, i, marketSkin);
2653
2654 if (marketSkin[MARKET_OWNER] == id) amount++;
2655 }
2656
2657 return amount;
2658}
2659
2660stock check_market_skin(marketId, skinId, ownerId)
2661{
2662 static marketSkin[marketInfo];
2663
2664 for (new i = 0; i < ArraySize(market); i++) {
2665 ArrayGetArray(market, i, marketSkin);
2666
2667 if (marketSkin[MARKET_ID] == marketId && marketSkin[MARKET_SKIN] == skinId && marketSkin[MARKET_OWNER] == ownerId) return i;
2668 }
2669
2670 return -1;
2671}
2672
2673stock remove_seller(id)
2674{
2675 static marketSkin[marketInfo];
2676
2677 for (new i = 0; i < ArraySize(market); i++) {
2678 ArrayGetArray(market, i, marketSkin);
2679
2680 if (marketSkin[MARKET_OWNER] == id) {
2681 ArrayDeleteItem(market, i);
2682
2683 i -= 1;
2684 }
2685 }
2686}
2687
2688stock fm_get_user_aiming_ent(index, const sClassName[])
2689{
2690 new Float:vOrigin[3];
2691
2692 fm_get_aim_origin(index, vOrigin);
2693
2694 new ent, sTempClass[32], iLen = sizeof(sTempClass) - 1;
2695
2696 do {
2697 pev(ent, pev_classname, sTempClass, iLen);
2698
2699 if (equali(sClassName, sTempClass)) return ent;
2700 } while ((ent = engfunc(EngFunc_FindEntityInSphere, ent, vOrigin, 0.005)));
2701
2702 return 0;
2703}
2704
2705stock explode_num(const string[], const character, output[], const maxParts)
2706{
2707 new currentPart = 0, stringLength = strlen(string), currentLength = 0, number[32];
2708
2709 do {
2710 currentLength += (1 + copyc(number, charsmax(number), string[currentLength], character));
2711
2712 output[currentPart++] = str_to_num(number);
2713 } while(currentLength < stringLength && currentPart < maxParts);
2714}
2715
2716stock registerCommands(const array[][], arraySize, function[])
2717{
2718 #if !defined ForRange
2719
2720 #define ForRange(%1,%2,%3) for(new %1 = %2; %1 <= %3; %1++)
2721
2722 #endif
2723
2724 #if AMXX_VERSION_NUM > 183
2725
2726 ForRange(i, 0, arraySize - 1)
2727 {
2728 ForRange(j, 0, 1)
2729 {
2730 register_clcmd(fmt("%s %s", !j ? "say" : "say_team", array[i]), function);
2731 }
2732 }
2733
2734 #else
2735
2736 new newCommand[33];
2737
2738 ForRange(i, 0, arraySize - 1)
2739 {
2740 ForRange(j, 0, 1)
2741 {
2742 formatex(newCommand, charsmax(newCommand), "%s %s", !j ? "say" : "say_team", array[i]);
2743 register_clcmd(newCommand, function);
2744 }
2745 }
2746
2747 #endif
2748}