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