forked from TheDoctor0/CoDMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcod_exchange.sma
More file actions
396 lines (257 loc) · 10.9 KB
/
Copy pathcod_exchange.sma
File metadata and controls
396 lines (257 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#include <amxmodx>
#include <cod>
#define PLUGIN "CoD Exchange"
#define VERSION "1.2.0"
#define AUTHOR "O'Zone"
new const commandExchange[][] = { "wymien", "say /exchange", "say_team /exchange", "say /zamien", "say_team /zamien", "say /wymien", "say_team /wymien" };
new const commandGive[][] = { "daj", "say /give", "say_team /give", "say /oddaj", "say_team /oddaj", "say /daj", "say_team /daj" };
new bool:mapEnd, blockExchange, cooldown;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
for (new i; i < sizeof commandExchange; i++) register_clcmd(commandExchange[i], "exchange_menu");
for (new i; i < sizeof commandGive; i++) register_clcmd(commandGive[i], "give_item");
}
public cod_end_map()
mapEnd = true;
public cod_new_round()
for (new i = 1; i <= MAX_PLAYERS; i++) rem_bit(i, cooldown);
public exchange_menu(id)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new menuData[64], menu = menu_create("\yMenu \rWymiany", "exchange_menu_handle");
menu_additem(menu, "Wymien \yPrzedmiot \r(/wymien)^n");
formatex(menuData, charsmax(menuData), "Propozycje \yWymiany \d[\r%s\d]", get_bit(id, blockExchange) ? "Zablokowane" : "Odblokowane");
menu_additem(menu, menuData);
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_display(id, menu);
return PLUGIN_HANDLED;
}
public exchange_menu_handle(id, menu, item)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
menu_destroy(menu);
client_cmd(id, "spk %s", codSounds[SOUND_EXIT]);
return PLUGIN_HANDLED;
}
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
switch (item) {
case 0: exchange_item(id, 1);
case 1: {
if (get_bit(id, blockExchange)) {
rem_bit(id, blockExchange);
cod_print_chat(id, "^x03Odblokowales^x01 mozliwosc wysylania ci propozycji wymiany przedmiotu!");
} else {
set_bit(id, blockExchange);
cod_print_chat(id, "^x03Zablokowales^x01 mozliwosc wysylania ci propozycji wymiany przedmiotu!");
}
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public exchange_item(id, sound)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
if (!sound) client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new menuData[128], playerName[MAX_NAME], itemName[MAX_NAME], playerId[3], players, menu = menu_create("\yWymien \rPrzedmiot", "exchange_item_handle");
for (new player = 1; player <= MAX_PLAYERS; player++) {
if (!is_user_connected(player) || id == player || !cod_get_user_class(player) || !cod_get_user_item(player) || get_bit(player, blockExchange)) continue;
cod_get_item_name(cod_get_user_item(player), itemName, charsmax(itemName));
get_user_name(player, playerName, charsmax(playerName));
formatex(menuData, charsmax(menuData), "%s \y(%s)", playerName, itemName);
num_to_str(player, playerId, charsmax(playerId));
menu_additem(menu, menuData, playerId);
players++;
}
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
if (!players) {
menu_destroy(menu);
cod_print_chat(id, "Na serwerze nie ma gracza, z ktorym moglbys sie wymienic przedmiotem!");
} else menu_display(id, menu);
return PLUGIN_HANDLED;
}
public exchange_item_handle(id, menu, item)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
menu_destroy(menu);
client_cmd(id, "spk %s", codSounds[SOUND_EXIT]);
return PLUGIN_HANDLED;
}
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new playerId[3], itemAccess, itemCallback;
menu_item_getinfo(menu, item, itemAccess, playerId, charsmax(playerId), _, _, itemCallback);
new player = str_to_num(playerId);
menu_destroy(menu);
if (!is_user_connected(player)) {
cod_print_chat(id, "Wybranego gracza nie ma juz na serwerze.");
return PLUGIN_HANDLED;
}
if (get_bit(player, cooldown)) {
cod_print_chat(id, "Wybrany gracz musi poczekac^x03 jedna runde^x01, aby wymienic sie przedmiotem.");
return PLUGIN_HANDLED;
}
if (get_bit(id, cooldown)) {
cod_print_chat(id, "Musisz poczekac^x03 jedna runde^x01, aby wymienic sie tym przedmiotem.");
return PLUGIN_HANDLED;
}
if (!cod_get_user_item(player)) {
cod_print_chat(id, "Wybrany gracz nie ma zadnego przedmiotu.");
return PLUGIN_HANDLED;
}
if (!cod_get_user_item(id)) {
cod_print_chat(id, "Nie masz zadnego przedmiotu.");
return PLUGIN_HANDLED;
}
if (!cod_check_item(id, cod_get_user_item(player))) {
cod_print_chat(id, "Nie masz dostepu do przedmiotu, za ktory chcesz cie wymienic.");
return PLUGIN_HANDLED;
}
if (!cod_check_item(player, cod_get_user_item(id))) {
cod_print_chat(id, "Gracz, z ktorym chcesz sie wymienic nie ma dostepu do twojego przedmiotu.");
return PLUGIN_HANDLED;
}
new menuData[128], playerName[MAX_NAME], itemName[MAX_NAME];
cod_get_item_name(cod_get_user_item(id), itemName, charsmax(itemName));
get_user_name(id, playerName, charsmax(playerName));
formatex(menuData, charsmax(menuData), "\wWymien sie przedmiotem z \y%s \w(\r%s\w):", playerName, itemName);
new menu = menu_create(menuData, "exchange_item_question");
num_to_str(id, playerId, charsmax(playerId));
menu_additem(menu, "Tak", playerId);
menu_additem(menu, "Nie", playerId);
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_display(player, menu);
return PLUGIN_HANDLED;
}
public exchange_item_question(id, menu, item)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
client_cmd(id, "spk %s", codSounds[SOUND_EXIT]);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new playerId[3], itemAccess, itemCallback;
menu_item_getinfo(menu, item, itemAccess, playerId, charsmax(playerId), _, _, itemCallback);
new player = str_to_num(playerId);
menu_destroy(menu);
if (!is_user_connected(player)) {
cod_print_chat(id, "Gracza proponujacego wymiane nie ma juz na serwerze.");
return PLUGIN_HANDLED;
}
if (get_bit(player, cooldown)) {
cod_print_chat(id, "Gracz proponujacy wymiane musi poczekac^x03 jedna runde^x01, aby wymienic sie przedmiotem.");
return PLUGIN_HANDLED;
}
if (!cod_get_user_item(player)) {
cod_print_chat(id, "Gracz proponujacy wymiane nie ma juz przedmiotu.");
return PLUGIN_HANDLED;
}
if (!cod_get_user_item(id)) {
cod_print_chat(id, "Nie masz zadnego przedmiotu.");
return PLUGIN_HANDLED;
}
if (!cod_check_item(id, cod_get_user_item(player))) {
cod_print_chat(id, "Nie masz dostepu do przedmiotu, ktory posiada gracz proponujacy wymiane.");
return PLUGIN_HANDLED;
}
if (!cod_check_item(player, cod_get_user_item(id))) {
cod_print_chat(id, "Gracz proponujacy wymiane nie ma dostepu do twojego przedmiotu.");
return PLUGIN_HANDLED;
}
switch (item) {
case 0: {
new name[MAX_NAME], playerName[MAX_NAME], itemName[MAX_NAME], playerItemName[MAX_NAME],
itemValue, itemId = cod_get_user_item(id, itemValue), itemDurability = cod_get_item_durability(id),
playerItemValue, playerItemId = cod_get_user_item(player, playerItemValue), playerItemDurability = cod_get_item_durability(player);
get_user_name(player, playerName, charsmax(playerName));
get_user_name(id, name, charsmax(name));
cod_get_item_name(cod_get_user_item(player), playerItemName, charsmax(playerItemName));
cod_get_item_name(cod_get_user_item(id), itemName, charsmax(itemName));
cod_set_user_item(player, itemId, itemValue);
cod_set_user_item(id, playerItemId, playerItemValue);
cod_set_item_durability(player, itemDurability);
cod_set_item_durability(id, playerItemDurability);
set_bit(player, cooldown);
set_bit(id, cooldown);
cod_print_chat(player, "Wymieniles sie przedmiotem z^x03 %s^x01. Otrzymales^x03 %s^x01.", name, itemName);
cod_print_chat(id, "Wymieniles sie przedmiotem z^x03 %s^x01. Otrzymales^x03 %s^x01.", playerName, playerItemName);
} case 1: cod_print_chat(player, "Wybrany gracz nie zgodzil sie na wymiane przedmiotami.");
}
return PLUGIN_HANDLED;
}
public give_item(id)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new playerName[MAX_NAME], playerId[3], players, menu = menu_create("\yOddaj \rPrzedmiot", "give_item_handle");
for (new player = 1; player <= MAX_PLAYERS; player++) {
if (!is_user_connected(player) || player == id || !cod_get_user_class(player) || cod_get_user_item(player)) continue;
get_user_name(player, playerName, charsmax(playerName));
num_to_str(player, playerId, charsmax(playerId));
menu_additem(menu, playerName, playerId);
players++;
}
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_setprop(menu, MPROP_BACKNAME, "Poprzednie");
menu_setprop(menu, MPROP_NEXTNAME, "Nastepne");
if (!players) {
menu_destroy(menu);
cod_print_chat(id, "Na serwerze nie ma gracza, z ktoremu moglbys oddac przedmiot!");
} else menu_display(id, menu);
return PLUGIN_HANDLED;
}
public give_item_handle(id, menu, item)
{
if (!is_user_connected(id) || !cod_check_account(id) || mapEnd) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
client_cmd(id, "spk %s", codSounds[SOUND_EXIT]);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new playerId[3], itemAccess, itemCallback;
menu_item_getinfo(menu, item, itemAccess, playerId, charsmax(playerId), _, _, itemCallback);
new player = str_to_num(playerId);
menu_destroy(menu);
if (!is_user_connected(player)) {
cod_print_chat(id, "Wybranego gracza nie ma juz na serwerze.");
return PLUGIN_HANDLED;
}
if (get_bit(id, cooldown)) {
cod_print_chat(id, "Musisz poczekac^x03 jedna runde^x01, aby oddac ten przedmiot.");
return PLUGIN_HANDLED;
}
if (cod_get_user_item(player))
{
cod_print_chat(id, "Wybrany gracz ma juz przedmiot.");
return PLUGIN_HANDLED;
}
if (!cod_get_user_item(id)) {
cod_print_chat(id, "Nie masz zadnego przedmiotu.");
return PLUGIN_HANDLED;
}
if (!cod_check_item(player, cod_get_user_item(id))) {
cod_print_chat(id, "Gracz, ktoremu chcesz sie oddac przedmiot nie ma do niego dostepu.");
return PLUGIN_HANDLED;
}
new name[MAX_NAME], playerName[MAX_NAME], itemName[MAX_NAME],
itemValue, itemId = cod_get_user_item(id, itemValue), itemDurability = cod_get_item_durability(id);
get_user_name(id, name, charsmax(name));
get_user_name(player, playerName, charsmax(playerName));
cod_get_item_name(cod_get_user_item(id), itemName, charsmax(itemName));
set_bit(player, cooldown);
rem_bit(id, cooldown);
cod_set_user_item(player, itemId, itemValue);
cod_set_item_durability(player, itemDurability);
cod_set_user_item(id);
cod_print_chat(id, "Oddales przedmiot^x03 %s^x01 graczowi^x03 %s^x01.", itemName, name);
cod_print_chat(player, "Dostales przedmiot^x03 %s^x01 od gracza^x03 %s^x01.", itemName, playerName);
return PLUGIN_HANDLED;
}