[Half-Life AMXX] / restmenu.sma Repository:
ViewVC logotype

Annotation of /restmenu.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : ian 1 /* AMX Mod X
2 :     * Restrict Weapons Plugin
3 :     *
4 :     * by the AMX Mod X Development Team
5 :     * originally developed by OLO
6 :     *
7 :     * This file is part of AMX Mod X.
8 :     *
9 :     *
10 :     * This program is free software; you can redistribute it and/or modify it
11 :     * under the terms of the GNU General Public License as published by the
12 :     * Free Software Foundation; either version 2 of the License, or (at
13 :     * your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful, but
16 :     * WITHOUT ANY WARRANTY; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 :     * General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program; if not, write to the Free Software Foundation,
22 :     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 :     * In addition, as a special exception, the author gives permission to
25 :     * link the code of this program with the Half-Life Game Engine ("HL
26 :     * Engine") and Modified Game Libraries ("MODs") developed by Valve,
27 :     * L.L.C ("Valve"). You must obey the GNU General Public License in all
28 :     * respects for all of the code used other than the HL Engine and MODs
29 :     * from Valve. If you modify this file, you may extend this exception
30 :     * to your version of the file, but you are not obligated to do so. If
31 :     * you do not wish to do so, delete this exception statement from your
32 :     * version.
33 :     */
34 :    
35 :     // Uncomment if you want to have seperate settings for each map
36 :     //#define MAPSETTINGS
37 :    
38 :     #include <amxmodx>
39 :     #include <amxmisc>
40 :    
41 :     #define MAXMENUPOS 34
42 :    
43 :     new g_Position[33]
44 :     new g_Modified
45 :     new g_blockPos[112]
46 :     new g_saveFile[64]
47 :     new g_Restricted[] = "* This item is restricted *"
48 :     new g_szWeapRestr[27] = "00000000000000000000000000"
49 :     new g_szEquipAmmoRestr[10] = "000000000"
50 :     new g_InBuyMenu[33]
51 :     new g_RegisteredMenus[10]
52 :    
53 :     new g_menuStrings[6][] =
54 :     {
55 :     "BuyPistol",
56 :     "BuyShotgun",
57 :     "BuySubMachineGun",
58 :     "BuyRifle",
59 :     "BuyMachineGun",
60 :     "BuyItem"
61 :     }
62 :    
63 :     new g_menusNames[7][] =
64 :     {
65 :     "pistol",
66 :     "shotgun",
67 :     "sub",
68 :     "rifle",
69 :     "machine",
70 :     "equip",
71 :     "ammo"
72 :     }
73 :    
74 :     new g_MenuTitle[7][] =
75 :     {
76 :     "Handguns",
77 :     "Shotguns",
78 :     "Sub-Machine Guns",
79 :     "Assault & Sniper Rifles",
80 :     "Machine Guns",
81 :     "Equipment",
82 :     "Ammunition"
83 :     }
84 :    
85 :     new g_menusSets[7][2] =
86 :     {
87 :     {0, 6}, {6, 8}, {8, 13}, {13, 23}, {23, 24}, {24, 32}, {32, 34}
88 :     }
89 :    
90 :     new g_AliasBlockNum
91 :     new g_AliasBlock[MAXMENUPOS]
92 :    
93 :     // First position is a position of menu (0 for ammo, 1 for pistols, 6 for equipment etc.)
94 :     // Second is a key for TERRORIST (all is key are minus one, 1 is 0, 2 is 1 etc.)
95 :     // Third is a key for CT
96 :     // Position with -1 doesn't exist
97 :    
98 :     new g_Keys[MAXMENUPOS][3] =
99 :     {
100 :     {1, 1, 1}, // H&K USP .45 Tactical
101 :     {1, 0, 0}, // Glock18 Select Fire
102 :     {1, 3, 3}, // Desert Eagle .50AE
103 :     {1, 2, 2}, // SIG P228
104 :     {1, 4, -1}, // Dual Beretta 96G Elite
105 :     {1, -1, 4}, // FN Five-Seven
106 :     {2, 0, 0}, // Benelli M3 Super90
107 :     {2, 1, 1}, // Benelli XM1014
108 :     {3, 1, 1}, // H&K MP5-Navy
109 :     {3, -1, 0}, // Steyr Tactical Machine Pistol
110 :     {3, 3, 3}, // FN P90
111 :     {3, 0, -1}, // Ingram MAC-10
112 :     {3, 2, 2}, // H&K UMP45
113 :     {4, 1, -1}, // AK-47
114 :     {4, 0, -1}, // Gali
115 :     {4, -1, 0}, // Famas
116 :     {4, 3, -1}, // Sig SG-552 Commando
117 :     {4, -1, 2}, // Colt M4A1 Carbine
118 :     {4, -1, 3}, // Steyr Aug
119 :     {4, 2, 1}, // Steyr Scout
120 :     {4, 4, 5}, // AI Arctic Warfare/Magnum
121 :     {4, 5, -1}, // H&K G3/SG-1 Sniper Rifle
122 :     {4, -1, 4}, // Sig SG-550 Sniper
123 :     {5, 0, 0}, // FN M249 Para
124 :     {6, 0, 0}, // Kevlar Vest
125 :     {6, 1, 1}, // Kevlar Vest & Helmet
126 :     {6, 2, 2}, // Flashbang
127 :     {6, 3, 3}, // HE Grenade
128 :     {6, 4, 4}, // Smoke Grenade
129 :     {6, -1, 6}, // Defuse Kit
130 :     {6, 5, 5}, // NightVision Goggles
131 :     {6, -1, 7}, // Tactical Shield
132 :     {0, 5, 5}, // Primary weapon ammo
133 :     {0, 6, 6} // Secondary weapon ammo
134 :     }
135 :    
136 :     new g_WeaponNames[MAXMENUPOS][] =
137 :     {
138 :     "H&K USP .45 Tactical",
139 :     "Glock18 Select Fire",
140 :     "Desert Eagle .50AE",
141 :     "SIG P228",
142 :     "Dual Beretta 96G Elite",
143 :     "FN Five-Seven",
144 :     "Benelli M3 Super90",
145 :     "Benelli XM1014",
146 :     "H&K MP5-Navy",
147 :     "Steyr Tactical Machine Pistol",
148 :     "FN P90",
149 :     "Ingram MAC-10",
150 :     "H&K UMP45",
151 :     "AK-47",
152 :     "Gali",
153 :     "Famas",
154 :     "Sig SG-552 Commando",
155 :     "Colt M4A1 Carbine",
156 :     "Steyr Aug",
157 :     "Steyr Scout",
158 :     "AI Arctic Warfare/Magnum",
159 :     "H&K G3/SG-1 Sniper Rifle",
160 :     "Sig SG-550 Sniper",
161 :     "FN M249 Para",
162 :     "Kevlar Vest",
163 :     "Kevlar Vest & Helmet",
164 :     "Flashbang",
165 :     "HE Grenade",
166 :     "Smoke Grenade",
167 :     "Defuse Kit",
168 :     "NightVision Goggles",
169 :     "Tactical Shield",
170 :     "Primary weapon ammo",
171 :     "Secondary weapon ammo"
172 :     }
173 :    
174 :     new g_MenuItem[MAXMENUPOS][] =
175 :     {
176 :     "\yHandguns^n\w^n%d. %s\y\R%L^n\w",
177 :     "%d. %s\y\R%L^n\w",
178 :     "%d. %s\y\R%L^n\w",
179 :     "%d. %s\y\R%L^n\w",
180 :     "%d. %s\y\R%L^n\w",
181 :     "%d. %s\y\R%L^n\w^n",
182 :    
183 :     "\yShotguns^n\w^n%d. %s\y\R%L^n\w",
184 :     "%d. %s\y\R%L^n\w^n",
185 :    
186 :     "\ySub-Machine Guns^n\w^n%d. %s\y\R%L^n\w",
187 :     "%d. %s\y\R%L^n\w",
188 :     "%d. %s\y\R%L^n\w",
189 :     "%d. %s\y\R%L^n\w",
190 :     "%d. %s\y\R%L^n\w^n",
191 :    
192 :     "\yAssault Rifles^n\w^n%d. %s\y\R%L^n\w",
193 :     "%d. %s\y\R%L^n\w",
194 :     "%d. %s\y\R%L^n\w",
195 :     "%d. %s\y\R%L^n\w",
196 :     "%d. %s\y\R%L^n\w",
197 :     "%d. %s\y\R%L^n\w^n",
198 :    
199 :     "\ySniper Rifles^n\w^n%d. %s\y\R%L^n\w",
200 :     "%d. %s\y\R%L^n\w",
201 :     "%d. %s\y\R%L^n\w",
202 :     "%d. %s\y\R%L^n\w^n",
203 :    
204 :     "\yMachine Guns^n\w^n%d. %s\y\R%L^n\w^n",
205 :    
206 :     "\yEquipment^n\w^n%d. %s\y\R%L^n\w",
207 :     "%d. %s\y\R%L^n\w",
208 :     "%d. %s\y\R%L^n\w",
209 :     "%d. %s\y\R%L^n\w",
210 :     "%d. %s\y\R%L^n\w",
211 :     "%d. %s\y\R%L^n\w",
212 :     "%d. %s\y\R%L^n\w",
213 :     "%d. %s\y\R%L^n\w^n",
214 :    
215 :     "\yAmmunition^n\w^n%d. %s\y\R%L^n\w",
216 :     "%d. %s\y\R%L^n\w"
217 :     }
218 :    
219 :     new g_Aliases[MAXMENUPOS][] =
220 :     {
221 :     "usp", //Pistols
222 :     "glock",
223 :     "deagle",
224 :     "p228",
225 :     "elites",
226 :     "fn57",
227 :    
228 :     "m3", //Shotguns
229 :     "xm1014",
230 :    
231 :     "mp5", //SMG
232 :     "tmp",
233 :     "p90",
234 :     "mac10",
235 :     "ump45",
236 :    
237 :     "ak47", //Rifles
238 :     "galil",
239 :     "famas",
240 :     "sg552",
241 :     "m4a1",
242 :     "aug",
243 :     "scout",
244 :     "awp",
245 :     "g3sg1",
246 :     "sg550",
247 :    
248 :     "m249", //Machine Gun
249 :    
250 :     "vest", //Equipment
251 :     "vesthelm",
252 :     "flash",
253 :     "hegren",
254 :     "sgren",
255 :     "defuser",
256 :     "nvgs",
257 :     "shield",
258 :    
259 :     "primammo", //Ammo
260 :     "secammo"
261 :     }
262 :    
263 :     new g_Aliases2[MAXMENUPOS][] =
264 :     {
265 :     "km45", //Pistols
266 :     "9x19mm",
267 :     "nighthawk",
268 :     "228compact",
269 :     "elites",
270 :     "fiveseven",
271 :    
272 :     "12gauge", //Shotguns
273 :     "autoshotgun",
274 :    
275 :     "smg", //SMG
276 :     "mp",
277 :     "c90",
278 :     "mac10",
279 :     "ump45",
280 :    
281 :     "cv47", //Rifles
282 :     "defender",
283 :     "clarion",
284 :     "krieg552",
285 :     "m4a1",
286 :     "bullpup",
287 :     "scout",
288 :     "magnum",
289 :     "d3au1",
290 :     "krieg550",
291 :    
292 :     "m249", //Machine Gun
293 :    
294 :     "vest", //Equipment
295 :     "vesthelm",
296 :     "flash",
297 :     "hegren",
298 :     "sgren",
299 :     "defuser",
300 :     "nvgs",
301 :     "shield",
302 :     "primammo", //Ammo
303 :     "secammo"
304 :     }
305 :    
306 :     #define AUTOBUYLENGTH 511
307 :     new g_Autobuy[33][AUTOBUYLENGTH + 1]
308 :     //new g_Rebuy[33][AUTOBUYLENGTH + 1]
309 :    
310 :     bool:IsOurMenuID(id)
311 :     {
312 :     for (new i=1; i<=g_RegisteredMenus[0]; i++)
313 :     {
314 :     if (g_RegisteredMenus[i] == id)
315 :     {
316 :     return true
317 :     }
318 :     }
319 :    
320 :     return false
321 :     }
322 :    
323 :     setWeapon(a, action)
324 :     {
325 :     new b, m = g_Keys[a][0] * 8
326 :    
327 :     if (g_Keys[a][1] != -1)
328 :     {
329 :     b = m + g_Keys[a][1]
330 :    
331 :     if (action == 2)
332 :     g_blockPos[b] = 1 - g_blockPos[b]
333 :     else
334 :     g_blockPos[b] = action
335 :     }
336 :    
337 :     if (g_Keys[a][2] != -1)
338 :     {
339 :     b = m + g_Keys[a][2] + 56
340 :    
341 :     if (action == 2)
342 :     g_blockPos[b] = 1 - g_blockPos[b]
343 :     else
344 :     g_blockPos[b] = action
345 :     }
346 :    
347 :     for (new i = 0; i < g_AliasBlockNum; ++i)
348 :     if (g_AliasBlock[i] == a)
349 :     {
350 :     if (!action || action == 2)
351 :     {
352 :     --g_AliasBlockNum
353 :    
354 :     for (new j = i; j < g_AliasBlockNum; ++j)
355 :     g_AliasBlock[j] = g_AliasBlock[j + 1]
356 :     }
357 :    
358 :     return
359 :     }
360 :    
361 :     if (action && g_AliasBlockNum < MAXMENUPOS)
362 :     g_AliasBlock[g_AliasBlockNum++] = a
363 :     }
364 :    
365 :     findMenuId(name[])
366 :     {
367 :     for (new i = 0; i < 7 ; ++i)
368 :     if (equali(name, g_menusNames[i]))
369 :     return i
370 :    
371 :     return -1
372 :     }
373 :    
374 :     findAliasId(name[])
375 :     {
376 :     for (new i = 0; i < MAXMENUPOS ; ++i)
377 :     if (equali(name, g_Aliases[i]))
378 :     return i
379 :    
380 :     return -1
381 :     }
382 :    
383 :     switchCommand(id, action)
384 :     {
385 :     new c = read_argc()
386 :    
387 :     if (c < 3)
388 :     {
389 :     for (new x = 0; x < MAXMENUPOS; x++)
390 :     setWeapon(x, action)
391 :    
392 :     console_print(id, "%L", id, action ? "EQ_WE_RES" : "EQ_WE_UNRES")
393 :     g_Modified = true
394 :     } else {
395 :     new arg[32], a
396 :     new bool:found = false
397 :    
398 :     for (new b = 2; b < c; ++b)
399 :     {
400 :     read_argv(b, arg, 31)
401 :    
402 :     if ((a = findMenuId(arg)) != -1)
403 :     {
404 :     c = g_menusSets[a][1]
405 :    
406 :     for (new i = g_menusSets[a][0]; i < c; ++i)
407 :     setWeapon(i, action)
408 :    
409 :     console_print(id, "%s %L %L", g_MenuTitle[a], id, (a < 5) ? "HAVE_BEEN" : "HAS_BEEN", id, action ? "RESTRICTED" : "UNRESTRICTED")
410 :     g_Modified = found = true
411 :     }
412 :     else if ((a = findAliasId(arg)) != -1)
413 :     {
414 :     g_Modified = found = true
415 :     setWeapon(a, action)
416 :     console_print(id, "%s %L %L", g_WeaponNames[a], id, "HAS_BEEN", id, action ? "RESTRICTED" : "UNRESTRICTED")
417 :     }
418 :     }
419 :    
420 :     if (!found)
421 :     console_print(id, "%L", id, "NO_EQ_WE")
422 :     }
423 :     }
424 :    
425 :     positionBlocked(a)
426 :     {
427 :     new m = g_Keys[a][0] * 8
428 :     new d = (g_Keys[a][1] == -1) ? 0 : g_blockPos[m + g_Keys[a][1]]
429 :    
430 :     d += (g_Keys[a][2] == -1) ? 0 : g_blockPos[m + g_Keys[a][2] + 56]
431 :    
432 :     return d
433 :     }
434 :    
435 :     public cmdRest(id, level, cid)
436 :     {
437 :     if (!cmd_access(id, level, cid, 1))
438 :     return PLUGIN_HANDLED
439 :    
440 :     new cmd[8]
441 :    
442 :     read_argv(1, cmd, 7)
443 :    
444 :     if (equali("on", cmd))
445 :     switchCommand(id, 1)
446 :     else if (equali("off", cmd))
447 :     switchCommand(id, 0)
448 :     else if (equali("list", cmd))
449 :     {
450 :     new arg1[8]
451 :     new start = read_argv(2, arg1, 7) ? str_to_num(arg1) : 1
452 :    
453 :     if (--start < 0)
454 :     start = 0
455 :    
456 :     if (start >= MAXMENUPOS)
457 :     start = MAXMENUPOS - 1
458 :    
459 :     new end = start + 10
460 :    
461 :     if (end > MAXMENUPOS)
462 :     end = MAXMENUPOS
463 :    
464 :     new lName[16], lValue[16], lStatus[16], lOnOff[16]
465 :    
466 :     format(lName, 15, "%L", id, "NAME")
467 :     format(lValue, 15, "%L", id, "VALUE")
468 :     format(lStatus, 15, "%L", id, "STATUS")
469 :    
470 :     console_print(id, "^n----- %L: -----", id, "WEAP_RES")
471 :     console_print(id, " %-32.31s %-10.9s %-9.8s", lName, lValue, lStatus)
472 :    
473 :     if (start != -1)
474 :     {
475 :     for (new a = start; a < end; ++a)
476 :     {
477 :     format(lOnOff, 15, "%L", id, positionBlocked(a) ? "ON" : "OFF")
478 :     console_print(id, "%3d: %-32.31s %-10.9s %-9.8s", a + 1, g_WeaponNames[a], g_Aliases[a], lOnOff)
479 :     }
480 :     }
481 :    
482 :     console_print(id, "----- %L -----", id, "REST_ENTRIES_OF", start + 1, end, MAXMENUPOS)
483 :    
484 :     if (end < MAXMENUPOS)
485 :     console_print(id, "----- %L -----", id, "REST_USE_MORE", end + 1)
486 :     else
487 :     console_print(id, "----- %L -----", id, "REST_USE_BEGIN")
488 :     }
489 :     else if (equali("save", cmd))
490 :     {
491 :     if (saveSettings(g_saveFile))
492 :     {
493 :     console_print(id, "%L", id, "REST_CONF_SAVED", g_saveFile)
494 :     g_Modified = false
495 :     }
496 :     else
497 :     console_print(id, "%L", id, "REST_COULDNT_SAVE", g_saveFile)
498 :     }
499 :     else if (equali("load", cmd))
500 :     {
501 :     setc(g_blockPos, 112, 0) // Clear current settings
502 :     new arg1[64]
503 :    
504 :     if (read_argv(2, arg1, 63))
505 :     {
506 :     new configsdir[32]
507 :     get_configsdir(configsdir, 31)
508 :    
509 :     format(arg1, 63, "%s/%s", configsdir, arg1)
510 :     }
511 :    
512 :     if (loadSettings(arg1))
513 :     {
514 :     console_print(id, "%L", id, "REST_CONF_LOADED", arg1)
515 :     g_Modified = true
516 :     }
517 :     else
518 :     console_print(id, "%L", id, "REST_COULDNT_LOAD", arg1)
519 :     } else {
520 :     console_print(id, "%L", id, "COM_REST_USAGE")
521 :     console_print(id, "%L", id, "COM_REST_COMMANDS")
522 :     console_print(id, "%L", id, "COM_REST_ON")
523 :     console_print(id, "%L", id, "COM_REST_OFF")
524 :     console_print(id, "%L", id, "COM_REST_ONV")
525 :     console_print(id, "%L", id, "COM_REST_OFFV")
526 :     console_print(id, "%L", id, "COM_REST_LIST")
527 :     console_print(id, "%L", id, "COM_REST_SAVE")
528 :     console_print(id, "%L", id, "COM_REST_LOAD")
529 :     console_print(id, "%L", id, "COM_REST_VALUES")
530 :     console_print(id, "%L", id, "COM_REST_TYPE")
531 :     }
532 :    
533 :     return PLUGIN_HANDLED
534 :     }
535 :    
536 :     displayMenu(id, pos)
537 :     {
538 :     if (pos < 0)
539 :     return
540 :    
541 :     new menubody[512], start = pos * 7
542 :    
543 :     if (start >= MAXMENUPOS)
544 :     start = pos = g_Position[id] = 0
545 :    
546 :     new len = format(menubody, 511, "\y%L\R%d/5^n^n\w", id, "REST_WEAP", pos + 1)
547 :     new end = start + 7, keys = MENU_KEY_0|MENU_KEY_8, k = 0
548 :    
549 :     if (end > MAXMENUPOS)
550 :     end = MAXMENUPOS
551 :    
552 :     for (new a = start; a < end; ++a)
553 :     {
554 :     keys |= (1<<k)
555 :     len += format(menubody[len], 511 - len, g_MenuItem[a], ++k, g_WeaponNames[a], id, positionBlocked(a) ? "ON" : "OFF")
556 :     }
557 :    
558 :     len += format(menubody[len], 511 - len, "^n8. %L \y\R%s^n\w", id, "SAVE_SET", g_Modified ? "*" : "")
559 :    
560 :     if (end != MAXMENUPOS)
561 :     {
562 :     format(menubody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
563 :     keys |= MENU_KEY_9
564 :     }
565 :     else
566 :     format(menubody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
567 :    
568 :     show_menu(id, keys, menubody, -1, "Restrict Weapons")
569 :     }
570 :    
571 :     public actionMenu(id, key)
572 :     {
573 :     switch (key)
574 :     {
575 :     case 7:
576 :     {
577 :     if (saveSettings(g_saveFile))
578 :     {
579 :     g_Modified = false
580 :     client_print(id, print_chat, "* %L", id, "CONF_SAV_SUC")
581 :     }
582 :     else
583 :     client_print(id, print_chat, "* %L", id, "CONF_SAV_FAIL")
584 :    
585 :     displayMenu(id, g_Position[id])
586 :     }
587 :     case 8: displayMenu(id, ++g_Position[id])
588 :     case 9: displayMenu(id, --g_Position[id])
589 :     default:
590 :     {
591 :     setWeapon(g_Position[id] * 7 + key, 2)
592 :     g_Modified = true
593 :     displayMenu(id, g_Position[id])
594 :    
595 :     new a = g_Position[id] * 7 + key
596 :     new sz[1]
597 :    
598 :     if (a < 24)
599 :     {
600 :     sz[0] = g_szWeapRestr[a + 1]
601 :     g_szWeapRestr[a + 1] = (sz[0] == '0') ? '1' : '0' // primary and secondary weapons
602 :     }
603 :     else if ((a >= 24) && (a < 31))
604 :     {
605 :     sz[0] = g_szEquipAmmoRestr[a - 24]
606 :     g_szEquipAmmoRestr[a - 24] = (sz[0] == '0') ? '1' : '0' // equipments
607 :     }
608 :     else if (a == 31)
609 :     {
610 :     sz[0] = g_szWeapRestr[25]
611 :     g_szWeapRestr[25] = (sz[0] == '0') ? '1' : '0' // shield
612 :     }
613 :     else if ((a > 31) && (a < 34))
614 :     {
615 :     sz[0] = g_szEquipAmmoRestr[a - 25]
616 :     g_szEquipAmmoRestr[a - 25] = (sz[0] == '0') ? '1' : '0' // primary and secondary ammo
617 :     }
618 :     set_cvar_string("amx_restrweapons", g_szWeapRestr)
619 :     set_cvar_string("amx_restrequipammo", g_szEquipAmmoRestr)
620 :     }
621 :     }
622 :    
623 :     return PLUGIN_HANDLED
624 :     }
625 :    
626 :     public client_command(id)
627 :     {
628 :     if (g_AliasBlockNum)
629 :     {
630 :     new arg[13]
631 :    
632 :     if (read_argv(0, arg, 12) > 11) /* Longest buy command has 11 chars so if command is longer then don't care */
633 :     {
634 :     return PLUGIN_CONTINUE
635 :     }
636 :    
637 :     if (equali(arg, "menuselect") && is_user_connected(id))
638 :     {
639 :     new menu, newmenu
640 :     new inMenu = player_menu_info(id, menu, newmenu)
641 :    
642 :     if (!inMenu && g_InBuyMenu[id])
643 :     {
644 :     new key[12], num
645 :    
646 :     read_argv(1, key, 11)
647 :     num = str_to_num(key) - 1
648 :    
649 :     return checkRest(id, g_InBuyMenu[id], num)
650 :     } else if ((!menu || newmenu != -1)
651 :     || !IsOurMenuID(menu)) {
652 :     g_InBuyMenu[id] = 0
653 :     }
654 :    
655 :     return PLUGIN_CONTINUE
656 :     }
657 :    
658 :     new a = 0
659 :    
660 :     do
661 :     {
662 :     if (equali(g_Aliases[g_AliasBlock[a]], arg) || equali(g_Aliases2[g_AliasBlock[a]], arg))
663 :     {
664 :     client_print(id, print_center, "%s", g_Restricted)
665 :     return PLUGIN_HANDLED
666 :     }
667 :     } while (++a < g_AliasBlockNum)
668 :     }
669 :    
670 :     return PLUGIN_CONTINUE
671 :     }
672 :    
673 :     public blockcommand(id)
674 :     {
675 :     client_print(id, print_center, "%s", g_Restricted)
676 :     return PLUGIN_HANDLED
677 :     }
678 :    
679 :     public cmdMenu(id, level, cid)
680 :     {
681 :     if (cmd_access(id, level, cid, 1))
682 :     {
683 :     displayMenu(id, g_Position[id] = 0)
684 :     }
685 :    
686 :     return PLUGIN_HANDLED
687 :     }
688 :    
689 :     checkRest(id, menu, key)
690 :     {
691 :     new team = get_user_team(id)
692 :    
693 :     if (team != 1 && team != 2)
694 :     {
695 :     return PLUGIN_HANDLED
696 :     }
697 :    
698 :     new pos = (menu * 8 + key) + (get_user_team(id) - 1) * 56
699 :    
700 :     if (pos < 0 || pos >= 112)
701 :     {
702 :     return PLUGIN_CONTINUE
703 :     }
704 :    
705 :     if (g_blockPos[pos])
706 :     {
707 :     engclient_cmd(id, "menuselect", "10")
708 :     client_print(id, print_center, "%s", g_Restricted)
709 :    
710 :     return PLUGIN_HANDLED
711 :     }
712 :    
713 :     return PLUGIN_CONTINUE
714 :     }
715 :    
716 :     public ammoRest1(id) return checkRest(id, 0, 5)
717 :     public ammoRest2(id) return checkRest(id, 0, 6)
718 :     public menuBuy(id, key) return checkRest(id, 0, key)
719 :     public menuPistol(id, key) return checkRest(id, 1, key)
720 :     public menuShotgun(id, key) return checkRest(id, 2, key)
721 :     public menuSub(id, key) return checkRest(id, 3, key)
722 :     public menuRifle(id, key) return checkRest(id, 4, key)
723 :     public menuMachine(id, key) return checkRest(id, 5, key)
724 :     public menuItem(id, key) return checkRest(id, 6, key)
725 :    
726 :     saveSettings(filename[])
727 :     {
728 :     if (file_exists(filename))
729 :     delete_file(filename)
730 :    
731 :     if (!write_file(filename, "; Generated by Restrict Weapons Plugin. Do not modify!^n; value name"))
732 :     return 0
733 :    
734 :     new text[64]
735 :    
736 :     for (new a = 0; a < MAXMENUPOS; ++a)
737 :     {
738 :     if (positionBlocked(a))
739 :     {
740 :     format(text, 63, "%-16.15s ; %s", g_Aliases[a], g_WeaponNames[a])
741 :     write_file(filename, text)
742 :     }
743 :     }
744 :    
745 :     return 1
746 :     }
747 :    
748 :     loadSettings(filename[])
749 :     {
750 :     if (!file_exists(filename))
751 :     return 0
752 :    
753 :     new text[16]
754 :     new a, pos = 0
755 :    
756 :     format(g_szEquipAmmoRestr, 9, "000000000")
757 :     format(g_szWeapRestr, 26, "00000000000000000000000000")
758 :    
759 :     while (read_file(filename, pos++, text, 15, a))
760 :     {
761 :     if (text[0] == ';' || !a)
762 :     continue // line is a comment
763 :    
764 :     parse(text, text, 15)
765 :    
766 :     if ((a = findAliasId(text)) != -1)
767 :     {
768 :     setWeapon(a, 1)
769 :     if (a < 24) g_szWeapRestr[a + 1] = '1' // primary and secondary weapons
770 :     else if ((a >= 24) && (a < 31)) g_szEquipAmmoRestr[a - 24] = '1' // equipments
771 :     else if (a == 31) g_szWeapRestr[25] = '1' // shield
772 :     else if ((a > 31) && (a < 34)) g_szEquipAmmoRestr[a - 25] = '1' // primary and secondary ammo
773 :     }
774 :     }
775 :     set_cvar_string("amx_restrweapons", g_szWeapRestr)
776 :     set_cvar_string("amx_restrequipammo", g_szEquipAmmoRestr)
777 :    
778 :     return 1
779 :     }
780 :    
781 :     // JGHG
782 :     public fn_setautobuy(id)
783 :     {
784 :     // Empty user's autobuy prefs. (unnecessary?)
785 :     g_Autobuy[id][0] = '^0'
786 :    
787 :     new argCount = read_argc()
788 :     new arg[128]
789 :     new autobuyLen = 0
790 :    
791 :     for (new i = 1; i < argCount; i++) // Start at parameter 1; parameter 0 is just "cl_setautobuy"
792 :     {
793 :     read_argv(i, arg, 127)
794 :     // Add this parameter to user's autobuy prefs
795 :     autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH - autobuyLen, "%s", arg)
796 :    
797 :     // If we detect more parameters, add a space
798 :     if (i + 1 < argCount)
799 :     autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH - autobuyLen, " ")
800 :     }
801 :    
802 :     if (g_AliasBlockNum)
803 :     {
804 :     // Strip any blocked items
805 :     new strippedItems[AUTOBUYLENGTH + 1]
806 :    
807 :     if (!StripBlockedItems(g_Autobuy[id], strippedItems))
808 :     return PLUGIN_CONTINUE // don't touch anything if we didn't strip anything...
809 :    
810 :     //server_print("Stripped items: ^"%s^"", strippedItems)
811 :     engclient_cmd(id, "cl_setautobuy", strippedItems)
812 :    
813 :     return PLUGIN_HANDLED
814 :     }
815 :    
816 :     return PLUGIN_CONTINUE
817 :     }
818 :    
819 :     // Returns true if this strips any items, else false.
820 :     StripBlockedItems(inString[AUTOBUYLENGTH + 1], outString[AUTOBUYLENGTH + 1])
821 :     {
822 :     // First copy string
823 :     format(outString, AUTOBUYLENGTH, inString)
824 :    
825 :     // After that convert all chars in string to lower case (fix by VEN)
826 :     strtolower(outString)
827 :    
828 :     // Then strip those that are blocked.
829 :     for (new i = 0; i < g_AliasBlockNum; i++)
830 :     {
831 :     while (containi(outString, g_Aliases[g_AliasBlock[i]]) != -1)
832 :     replace(outString, AUTOBUYLENGTH, g_Aliases[g_AliasBlock[i]], "")
833 :     while (containi(outString, g_Aliases2[g_AliasBlock[i]]) != -1)
834 :     replace(outString, AUTOBUYLENGTH, g_Aliases2[g_AliasBlock[i]], "")
835 :     }
836 :    
837 :     // We COULD trim white space from outString here, but I don't think it really is necessary currently...
838 :     if (strlen(outString) < strlen(inString))
839 :     return true // outstring is shorter: we stripped items, return true
840 :    
841 :     return false // else end here, return false, no items were stripped
842 :     }
843 :    
844 :     public fn_autobuy(id)
845 :     {
846 :     // Don't do anything if no items are blocked.
847 :     if (!g_AliasBlockNum)
848 :     return PLUGIN_CONTINUE
849 :    
850 :     // Strip any blocked items
851 :     new strippedItems[AUTOBUYLENGTH + 1]
852 :    
853 :     if (!StripBlockedItems(g_Autobuy[id], strippedItems))
854 :     return PLUGIN_CONTINUE // don't touch anything if we didn't strip anything...
855 :    
856 :     engclient_cmd(id, "cl_setautobuy", strippedItems)
857 :    
858 :     return PLUGIN_HANDLED
859 :     }
860 :    
861 :     public HookEvent_ShowMenu(id)
862 :     {
863 :     new menustring[24]
864 :    
865 :     read_data(4, menustring, 23)
866 :    
867 :     /* Early breakouts */
868 :     new curidx
869 :     if (menustring[curidx++] != '#')
870 :     {
871 :     g_InBuyMenu[id] = 0
872 :     return
873 :     }
874 :    
875 :     /* Strip D */
876 :     if (menustring[curidx] == 'D')
877 :     {
878 :     curidx++
879 :     }
880 :    
881 :     /* Strip AS_ */
882 :     if (menustring[curidx] == 'A'
883 :     && menustring[curidx+1] == 'S'
884 :     && menustring[curidx+2] == '_')
885 :     {
886 :     curidx += 3
887 :     }
888 :    
889 :     /* Strip any team tags */
890 :     if (menustring[curidx] == 'C'
891 :     && menustring[curidx+1] == 'T'
892 :     && menustring[curidx+2] == '_')
893 :     {
894 :     curidx += 3
895 :     } else if (menustring[curidx] == 'T'
896 :     && menustring[curidx+1] == '_') {
897 :     curidx += 2
898 :     }
899 :    
900 :     if (menustring[curidx] != 'B')
901 :     {
902 :     g_InBuyMenu[id] = 0
903 :     return
904 :     }
905 :    
906 :     for (new i=0; i<6; i++)
907 :     {
908 :     if (equali(menustring[curidx], g_menuStrings[i]))
909 :     {
910 :     g_InBuyMenu[id] = i+1
911 :     return
912 :     }
913 :     }
914 :    
915 :     g_InBuyMenu[id] = 0
916 :     }
917 :    
918 :     RegisterMenuID(const menuname[])
919 :     {
920 :     new id = register_menuid(menuname, 1)
921 :     g_RegisteredMenus[++g_RegisteredMenus[0]] = id
922 :     return id
923 :     }
924 :    
925 :     public plugin_init()
926 :     {
927 :     register_plugin("Restrict Weapons", AMXX_VERSION_STR, "AMXX Dev Team")
928 :     register_dictionary("restmenu.txt")
929 :     register_dictionary("common.txt")
930 :     register_clcmd("buyammo1", "ammoRest1")
931 :     register_clcmd("buyammo2", "ammoRest2")
932 :     register_clcmd("cl_setautobuy", "fn_setautobuy")
933 :     register_clcmd("cl_autobuy", "fn_autobuy")
934 :     register_clcmd("amx_restmenu", "cmdMenu", ADMIN_CFG, "- displays weapons restriction menu")
935 :     register_menucmd(register_menuid("#Buy", 1), 511, "menuBuy")
936 :     register_menucmd(register_menuid("Restrict Weapons"), 1023, "actionMenu")
937 :     register_menucmd(RegisterMenuID("BuyPistol"), 511, "menuPistol")
938 :     register_menucmd(RegisterMenuID("BuyShotgun"), 511, "menuShotgun")
939 :     register_menucmd(RegisterMenuID("BuySub"), 511, "menuSub")
940 :     register_menucmd(RegisterMenuID("BuyRifle"), 511, "menuRifle")
941 :     register_menucmd(RegisterMenuID("BuyMachine"), 511, "menuMachine")
942 :     register_menucmd(RegisterMenuID("BuyItem"), 511, "menuItem")
943 :     register_menucmd(-28, 511, "menuBuy")
944 :     register_menucmd(-29, 511, "menuPistol")
945 :     register_menucmd(-30, 511, "menuShotgun")
946 :     register_menucmd(-32, 511, "menuSub")
947 :     register_menucmd(-31, 511, "menuRifle")
948 :     register_menucmd(-33, 511, "menuMachine")
949 :     register_menucmd(-34, 511, "menuItem")
950 :     register_concmd("amx_restrict", "cmdRest", ADMIN_CFG, "- displays help for weapons restriction")
951 :    
952 :     register_cvar("amx_restrweapons", "00000000000000000000000000")
953 :     register_cvar("amx_restrequipammo", "000000000")
954 :    
955 :     register_event("ShowMenu", "HookEvent_ShowMenu", "b")
956 :    
957 :     new configsDir[64];
958 :     get_configsdir(configsDir, 63);
959 :     #if defined MAPSETTINGS
960 :     new mapname[32]
961 :     get_mapname(mapname, 31)
962 :     format(g_saveFile, 63, "%s/weaprest_%s.ini", configsDir, mapname)
963 :     #else
964 :     format(g_saveFile, 63, "%s/weaprest.ini", configsDir)
965 :     #endif
966 :     loadSettings(g_saveFile)
967 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4