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