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

Annotation of /restmenu.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 44 - (view) (download)

1 : ian 44 /* 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 CS_InternalCommand(id, const cmd[])
627 :     {
628 :     new a = 0
629 :    
630 :     do
631 :     {
632 :     if (equali(g_Aliases[g_AliasBlock[a]], cmd) || equali(g_Aliases2[g_AliasBlock[a]], cmd))
633 :     {
634 :     client_print(id, print_center, "%s", g_Restricted)
635 :     return PLUGIN_HANDLED
636 :     }
637 :     } while (++a < g_AliasBlockNum)
638 :    
639 :     return PLUGIN_CONTINUE
640 :     }
641 :    
642 :     public client_command(id)
643 :     {
644 :     if (g_AliasBlockNum)
645 :     {
646 :     new arg[13]
647 :    
648 :     if (read_argv(0, arg, 12) > 11) /* Longest buy command has 11 chars so if command is longer then don't care */
649 :     {
650 :     return PLUGIN_CONTINUE
651 :     }
652 :    
653 :     if (equali(arg, "menuselect") && is_user_connected(id))
654 :     {
655 :     new menu, newmenu
656 :     new inMenu = player_menu_info(id, menu, newmenu)
657 :    
658 :     if (!inMenu && g_InBuyMenu[id])
659 :     {
660 :     new key[12], num
661 :    
662 :     read_argv(1, key, 11)
663 :     num = str_to_num(key) - 1
664 :    
665 :     return checkRest(id, g_InBuyMenu[id], num)
666 :     } else if ((!menu || newmenu != -1)
667 :     || !IsOurMenuID(menu)) {
668 :     g_InBuyMenu[id] = 0
669 :     }
670 :    
671 :     return PLUGIN_CONTINUE
672 :     }
673 :    
674 :     new a = 0
675 :    
676 :     do
677 :     {
678 :     if (equali(g_Aliases[g_AliasBlock[a]], arg) || equali(g_Aliases2[g_AliasBlock[a]], arg))
679 :     {
680 :     client_print(id, print_center, "%s", g_Restricted)
681 :     return PLUGIN_HANDLED
682 :     }
683 :     } while (++a < g_AliasBlockNum)
684 :     }
685 :    
686 :     return PLUGIN_CONTINUE
687 :     }
688 :    
689 :     public blockcommand(id)
690 :     {
691 :     client_print(id, print_center, "%s", g_Restricted)
692 :     return PLUGIN_HANDLED
693 :     }
694 :    
695 :     public cmdMenu(id, level, cid)
696 :     {
697 :     if (cmd_access(id, level, cid, 1))
698 :     {
699 :     displayMenu(id, g_Position[id] = 0)
700 :     }
701 :    
702 :     return PLUGIN_HANDLED
703 :     }
704 :    
705 :     checkRest(id, menu, key)
706 :     {
707 :     new team = get_user_team(id)
708 :    
709 :     if (team != 1 && team != 2)
710 :     {
711 :     return PLUGIN_HANDLED
712 :     }
713 :    
714 :     new pos = (menu * 8 + key) + (get_user_team(id) - 1) * 56
715 :    
716 :     if (pos < 0 || pos >= 112)
717 :     {
718 :     return PLUGIN_CONTINUE
719 :     }
720 :    
721 :     if (g_blockPos[pos])
722 :     {
723 :     engclient_cmd(id, "menuselect", "10")
724 :     client_print(id, print_center, "%s", g_Restricted)
725 :    
726 :     return PLUGIN_HANDLED
727 :     }
728 :    
729 :     return PLUGIN_CONTINUE
730 :     }
731 :    
732 :     public ammoRest1(id) return checkRest(id, 0, 5)
733 :     public ammoRest2(id) return checkRest(id, 0, 6)
734 :     public menuBuy(id, key) return checkRest(id, 0, key)
735 :     public menuPistol(id, key) return checkRest(id, 1, key)
736 :     public menuShotgun(id, key) return checkRest(id, 2, key)
737 :     public menuSub(id, key) return checkRest(id, 3, key)
738 :     public menuRifle(id, key) return checkRest(id, 4, key)
739 :     public menuMachine(id, key) return checkRest(id, 5, key)
740 :     public menuItem(id, key) return checkRest(id, 6, key)
741 :    
742 :     saveSettings(filename[])
743 :     {
744 :     if (file_exists(filename))
745 :     delete_file(filename)
746 :    
747 :     if (!write_file(filename, "; Generated by Restrict Weapons Plugin. Do not modify!^n; value name"))
748 :     return 0
749 :    
750 :     new text[64]
751 :    
752 :     for (new a = 0; a < MAXMENUPOS; ++a)
753 :     {
754 :     if (positionBlocked(a))
755 :     {
756 :     format(text, 63, "%-16.15s ; %s", g_Aliases[a], g_WeaponNames[a])
757 :     write_file(filename, text)
758 :     }
759 :     }
760 :    
761 :     return 1
762 :     }
763 :    
764 :     loadSettings(filename[])
765 :     {
766 :     if (!file_exists(filename))
767 :     return 0
768 :    
769 :     new text[16]
770 :     new a, pos = 0
771 :    
772 :     format(g_szEquipAmmoRestr, 9, "000000000")
773 :     format(g_szWeapRestr, 26, "00000000000000000000000000")
774 :    
775 :     while (read_file(filename, pos++, text, 15, a))
776 :     {
777 :     if (text[0] == ';' || !a)
778 :     continue // line is a comment
779 :    
780 :     parse(text, text, 15)
781 :    
782 :     if ((a = findAliasId(text)) != -1)
783 :     {
784 :     setWeapon(a, 1)
785 :     if (a < 24) g_szWeapRestr[a + 1] = '1' // primary and secondary weapons
786 :     else if ((a >= 24) && (a < 31)) g_szEquipAmmoRestr[a - 24] = '1' // equipments
787 :     else if (a == 31) g_szWeapRestr[25] = '1' // shield
788 :     else if ((a > 31) && (a < 34)) g_szEquipAmmoRestr[a - 25] = '1' // primary and secondary ammo
789 :     }
790 :     }
791 :     set_cvar_string("amx_restrweapons", g_szWeapRestr)
792 :     set_cvar_string("amx_restrequipammo", g_szEquipAmmoRestr)
793 :    
794 :     return 1
795 :     }
796 :    
797 :     // JGHG
798 :     public fn_setautobuy(id)
799 :     {
800 :     // Empty user's autobuy prefs. (unnecessary?)
801 :     g_Autobuy[id][0] = '^0'
802 :    
803 :     new argCount = read_argc()
804 :     new arg[128]
805 :     new autobuyLen = 0
806 :    
807 :     for (new i = 1; i < argCount; i++) // Start at parameter 1; parameter 0 is just "cl_setautobuy"
808 :     {
809 :     read_argv(i, arg, 127)
810 :     // Add this parameter to user's autobuy prefs
811 :     autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH - autobuyLen, "%s", arg)
812 :    
813 :     // If we detect more parameters, add a space
814 :     if (i + 1 < argCount)
815 :     autobuyLen += format(g_Autobuy[id][autobuyLen], AUTOBUYLENGTH - autobuyLen, " ")
816 :     }
817 :    
818 :     if (g_AliasBlockNum)
819 :     {
820 :     // Strip any blocked items
821 :     new strippedItems[AUTOBUYLENGTH + 1]
822 :    
823 :     if (!StripBlockedItems(g_Autobuy[id], strippedItems))
824 :     return PLUGIN_CONTINUE // don't touch anything if we didn't strip anything...
825 :    
826 :     //server_print("Stripped items: ^"%s^"", strippedItems)
827 :     engclient_cmd(id, "cl_setautobuy", strippedItems)
828 :    
829 :     return PLUGIN_HANDLED
830 :     }
831 :    
832 :     return PLUGIN_CONTINUE
833 :     }
834 :    
835 :     // Returns true if this strips any items, else false.
836 :     StripBlockedItems(inString[AUTOBUYLENGTH + 1], outString[AUTOBUYLENGTH + 1])
837 :     {
838 :     // First copy string
839 :     format(outString, AUTOBUYLENGTH, inString)
840 :    
841 :     // After that convert all chars in string to lower case (fix by VEN)
842 :     strtolower(outString)
843 :    
844 :     // Then strip those that are blocked.
845 :     for (new i = 0; i < g_AliasBlockNum; i++)
846 :     {
847 :     while (containi(outString, g_Aliases[g_AliasBlock[i]]) != -1)
848 :     replace(outString, AUTOBUYLENGTH, g_Aliases[g_AliasBlock[i]], "")
849 :     while (containi(outString, g_Aliases2[g_AliasBlock[i]]) != -1)
850 :     replace(outString, AUTOBUYLENGTH, g_Aliases2[g_AliasBlock[i]], "")
851 :     }
852 :    
853 :     // We COULD trim white space from outString here, but I don't think it really is necessary currently...
854 :     if (strlen(outString) < strlen(inString))
855 :     return true // outstring is shorter: we stripped items, return true
856 :    
857 :     return false // else end here, return false, no items were stripped
858 :     }
859 :    
860 :     public fn_autobuy(id)
861 :     {
862 :     // Don't do anything if no items are blocked.
863 :     if (!g_AliasBlockNum)
864 :     return PLUGIN_CONTINUE
865 :    
866 :     // Strip any blocked items
867 :     new strippedItems[AUTOBUYLENGTH + 1]
868 :    
869 :     if (!StripBlockedItems(g_Autobuy[id], strippedItems))
870 :     return PLUGIN_CONTINUE // don't touch anything if we didn't strip anything...
871 :    
872 :     engclient_cmd(id, "cl_setautobuy", strippedItems)
873 :    
874 :     return PLUGIN_HANDLED
875 :     }
876 :    
877 :     public HookEvent_ShowMenu(id)
878 :     {
879 :     new menustring[24]
880 :    
881 :     read_data(4, menustring, 23)
882 :    
883 :     /* Early breakouts */
884 :     new curidx
885 :     if (menustring[curidx++] != '#')
886 :     {
887 :     g_InBuyMenu[id] = 0
888 :     return
889 :     }
890 :    
891 :     /* Strip D */
892 :     if (menustring[curidx] == 'D')
893 :     {
894 :     curidx++
895 :     }
896 :    
897 :     /* Strip AS_ */
898 :     if (menustring[curidx] == 'A'
899 :     && menustring[curidx+1] == 'S'
900 :     && menustring[curidx+2] == '_')
901 :     {
902 :     curidx += 3
903 :     }
904 :    
905 :     /* Strip any team tags */
906 :     if (menustring[curidx] == 'C'
907 :     && menustring[curidx+1] == 'T'
908 :     && menustring[curidx+2] == '_')
909 :     {
910 :     curidx += 3
911 :     } else if (menustring[curidx] == 'T'
912 :     && menustring[curidx+1] == '_') {
913 :     curidx += 2
914 :     }
915 :    
916 :     if (menustring[curidx] != 'B')
917 :     {
918 :     g_InBuyMenu[id] = 0
919 :     return
920 :     }
921 :    
922 :     for (new i=0; i<6; i++)
923 :     {
924 :     if (equali(menustring[curidx], g_menuStrings[i]))
925 :     {
926 :     g_InBuyMenu[id] = i+1
927 :     return
928 :     }
929 :     }
930 :    
931 :     g_InBuyMenu[id] = 0
932 :     }
933 :    
934 :     RegisterMenuID(const menuname[])
935 :     {
936 :     new id = register_menuid(menuname, 1)
937 :     g_RegisteredMenus[++g_RegisteredMenus[0]] = id
938 :     return id
939 :     }
940 :    
941 :     public plugin_init()
942 :     {
943 :     register_plugin("Restrict Weapons", AMXX_VERSION_STR, "AMXX Dev Team")
944 :     register_dictionary("restmenu.txt")
945 :     register_dictionary("common.txt")
946 :     register_clcmd("buyammo1", "ammoRest1")
947 :     register_clcmd("buyammo2", "ammoRest2")
948 :     register_clcmd("cl_setautobuy", "fn_setautobuy")
949 :     register_clcmd("cl_autobuy", "fn_autobuy")
950 :     register_clcmd("amx_restmenu", "cmdMenu", ADMIN_CFG, "- displays weapons restriction menu")
951 :     register_menucmd(register_menuid("#Buy", 1), 511, "menuBuy")
952 :     register_menucmd(register_menuid("Restrict Weapons"), 1023, "actionMenu")
953 :     register_menucmd(RegisterMenuID("BuyPistol"), 511, "menuPistol")
954 :     register_menucmd(RegisterMenuID("BuyShotgun"), 511, "menuShotgun")
955 :     register_menucmd(RegisterMenuID("BuySub"), 511, "menuSub")
956 :     register_menucmd(RegisterMenuID("BuyRifle"), 511, "menuRifle")
957 :     register_menucmd(RegisterMenuID("BuyMachine"), 511, "menuMachine")
958 :     register_menucmd(RegisterMenuID("BuyItem"), 511, "menuItem")
959 :     register_menucmd(-28, 511, "menuBuy")
960 :     register_menucmd(-29, 511, "menuPistol")
961 :     register_menucmd(-30, 511, "menuShotgun")
962 :     register_menucmd(-32, 511, "menuSub")
963 :     register_menucmd(-31, 511, "menuRifle")
964 :     register_menucmd(-33, 511, "menuMachine")
965 :     register_menucmd(-34, 511, "menuItem")
966 :     register_concmd("amx_restrict", "cmdRest", ADMIN_CFG, "- displays help for weapons restriction")
967 :    
968 :     register_cvar("amx_restrweapons", "00000000000000000000000000")
969 :     register_cvar("amx_restrequipammo", "000000000")
970 :    
971 :     register_event("ShowMenu", "HookEvent_ShowMenu", "b")
972 :    
973 :     new configsDir[64];
974 :     get_configsdir(configsDir, 63);
975 :     #if defined MAPSETTINGS
976 :     new mapname[32]
977 :     get_mapname(mapname, 31)
978 :     format(g_saveFile, 63, "%s/weaprest_%s.ini", configsDir, mapname)
979 :     #else
980 :     format(g_saveFile, 63, "%s/weaprest.ini", configsDir)
981 :     #endif
982 :     loadSettings(g_saveFile)
983 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4