daily pastebin goal
74%
SHARE
TWEET

Untitled

a guest May 16th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*================================================================================
  2.    
  3.     ----------------------
  4.     -*- [ZP] Main Menu -*-
  5.     ----------------------
  6.    
  7.     This plugin is part of Zombie Plague Mod and is distributed under the
  8.     terms of the GNU General Public License. Check ZP_ReadMe.txt for details.
  9.    
  10. ================================================================================*/
  11.  
  12. #include <amxmodx>
  13. #include <amxmisc>
  14. #include <fakemeta>
  15. #define LIBRARY_BUYMENUS "zp50_buy_menus"
  16. #include <zp50_buy_menus>
  17. #define LIBRARY_ZOMBIECLASSES "zp50_class_zombie"
  18. #include <zp50_class_zombie>
  19. #define LIBRARY_HUMANCLASSES "zp50_class_human"
  20. #include <zp50_class_human>
  21. #define LIBRARY_ITEMS "zp50_items"
  22. #include <zp50_items>
  23. #define LIBRARY_ADMIN_MENU "zp50_admin_menu"
  24. #include <zp50_admin_menu>
  25. #define LIBRARY_RANDOMSPAWN "zp50_random_spawn"
  26. #include <zp50_random_spawn>
  27. #include <zp50_colorchat>
  28.  
  29. #define TASK_WELCOMEMSG 100
  30.  
  31. // CS Player PData Offsets (win32)
  32. const OFFSET_CSMENUCODE = 205
  33.  
  34. // Menu keys
  35. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
  36.  
  37. #define flag_get(%1,%2) (%1 & (1 << (%2 & 31)))
  38. #define flag_get_boolean(%1,%2) (flag_get(%1,%2) ? true : false)
  39. #define flag_set(%1,%2) %1 |= (1 << (%2 & 31))
  40. #define flag_unset(%1,%2) %1 &= ~(1 << (%2 & 31))
  41.  
  42. new g_ChooseTeamOverrideActive
  43.  
  44. new cvar_buy_custom_primary, cvar_buy_custom_secondary, cvar_buy_custom_grenades
  45. new cvar_random_spawning
  46.  
  47. public plugin_init()
  48. {
  49.     register_plugin("[ZP] Main Menu", ZP_VERSION_STRING, "ZP Dev Team")
  50.    
  51.     register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
  52.    
  53.     register_clcmd("chooseteam", "clcmd_chooseteam")
  54.    
  55.     register_clcmd("say /zpmenu", "clcmd_zpmenu")
  56.     register_clcmd("say zpmenu", "clcmd_zpmenu")
  57.    
  58.     // Menus
  59.     register_menu("Main Menu", KEYSMENU, "menu_main")
  60. }
  61.  
  62. public plugin_natives()
  63. {
  64.     set_module_filter("module_filter")
  65.     set_native_filter("native_filter")
  66. }
  67. public module_filter(const module[])
  68. {
  69.     if (equal(module, LIBRARY_BUYMENUS) || equal(module, LIBRARY_ZOMBIECLASSES) || equal(module, LIBRARY_HUMANCLASSES) || equal(module, LIBRARY_ITEMS) || equal(module, LIBRARY_ADMIN_MENU) || equal(module, LIBRARY_RANDOMSPAWN))
  70.         return PLUGIN_HANDLED;
  71.    
  72.     return PLUGIN_CONTINUE;
  73. }
  74. public native_filter(const name[], index, trap)
  75. {
  76.     if (!trap)
  77.         return PLUGIN_HANDLED;
  78.    
  79.     return PLUGIN_CONTINUE;
  80. }
  81.  
  82. public plugin_cfg()
  83. {
  84.     cvar_buy_custom_primary = get_cvar_pointer("zp_buy_custom_primary")
  85.     cvar_buy_custom_secondary = get_cvar_pointer("zp_buy_custom_secondary")
  86.     cvar_buy_custom_grenades = get_cvar_pointer("zp_buy_custom_grenades")
  87.     cvar_random_spawning = get_cvar_pointer("zp_random_spawning_csdm")
  88. }
  89.  
  90. // Event Round Start
  91. public event_round_start()
  92. {
  93.     // Show main menu message
  94.     remove_task(TASK_WELCOMEMSG)
  95.     set_task(2.0, "task_welcome_msg", TASK_WELCOMEMSG)
  96. }
  97.  
  98. // Welcome Message Task
  99. public task_welcome_msg()
  100. {
  101.     zp_colored_print(0, "==== ^x04 eQ Zombie Plague %s^x01 ====", ZP_VERSION_STR_LONG)
  102.     zp_colored_print(0, "%L", LANG_PLAYER, "NOTICE_INFO1")
  103. }
  104.  
  105. public clcmd_chooseteam(id)
  106. {
  107.     if (flag_get(g_ChooseTeamOverrideActive, id))
  108.     {
  109.         show_menu_main(id)
  110.         return PLUGIN_HANDLED;
  111.     }
  112.    
  113.     flag_set(g_ChooseTeamOverrideActive, id)
  114.     return PLUGIN_CONTINUE;
  115. }
  116.  
  117. public clcmd_zpmenu(id)
  118. {
  119.     show_menu_main(id)
  120. }
  121.  
  122. public client_putinserver(id)
  123. {
  124.     flag_set(g_ChooseTeamOverrideActive, id)
  125. }
  126.  
  127. // Main Menu
  128. show_menu_main(id)
  129. {
  130.     static menu[250]
  131.     new len
  132.    
  133.     // Title
  134.     len += formatex(menu[len], charsmax(menu) - len, "\yeQ Zombie Plague %s^n^n", ZP_VERSION_STR_LONG)
  135.    
  136.     // 1. Buy menu
  137.     if (LibraryExists(LIBRARY_BUYMENUS, LibType_Library) && (get_pcvar_num(cvar_buy_custom_primary)
  138.     || get_pcvar_num(cvar_buy_custom_secondary) || get_pcvar_num(cvar_buy_custom_grenades)) && is_user_alive(id))
  139.         len += formatex(menu[len], charsmax(menu) - len, "\r1.\w %L^n", id, "MENU_BUY")
  140.     else
  141.         len += formatex(menu[len], charsmax(menu) - len, "\d1. %L^n", id, "MENU_BUY")
  142.    
  143.     // 2. Extra Items
  144.     if (LibraryExists(LIBRARY_ITEMS, LibType_Library) && is_user_alive(id))
  145.         len += formatex(menu[len], charsmax(menu) - len, "\r2.\w %L^n", id, "MENU_EXTRABUY")
  146.     else
  147.         len += formatex(menu[len], charsmax(menu) - len, "\d2. %L^n", id, "MENU_EXTRABUY")
  148.    
  149.     // 3. Zombie class
  150.     if (LibraryExists(LIBRARY_ZOMBIECLASSES, LibType_Library) && zp_class_zombie_get_count() > 1)
  151.         len += formatex(menu[len], charsmax(menu) - len, "\r3.\w %L^n", id, "MENU_ZCLASS")
  152.     else
  153.         len += formatex(menu[len], charsmax(menu) - len, "\d3. %L^n", id, "MENU_ZCLASS")
  154.    
  155.     // 4. Human class
  156.     if (LibraryExists(LIBRARY_HUMANCLASSES, LibType_Library) && zp_class_human_get_count() > 1)
  157.         len += formatex(menu[len], charsmax(menu) - len, "\r4.\w %L^n", id, "MENU_HCLASS")
  158.     else
  159.         len += formatex(menu[len], charsmax(menu) - len, "\d4. %L^n", id, "MENU_HCLASS")
  160.    
  161.     // 5. Unstuck
  162.     if (LibraryExists(LIBRARY_ZOMBIECLASSES, LibType_Library) && is_user_alive(id))
  163.         len += formatex(menu[len], charsmax(menu) - len, "\r5.\w %L^n", id, "MENU_UNSTUCK")
  164.     else
  165.         len += formatex(menu[len], charsmax(menu) - len, "\d5. %L^n", id, "MENU_UNSTUCK")
  166.    
  167.     // 6. Help
  168.     len += formatex(menu[len], charsmax(menu) - len, "\r6.\w %L^n^n", id, "MENU_INFO")
  169.    
  170.     // 7. Choose Team
  171.     len += formatex(menu[len], charsmax(menu) - len, "\r7.\w %L^n^n", id, "MENU_CHOOSE_TEAM")
  172.    
  173.     // 9. Admin menu
  174.     if (LibraryExists(LIBRARY_ADMIN_MENU, LibType_Library) && is_user_admin(id))
  175.         len += formatex(menu[len], charsmax(menu) - len, "\r9.\w %L", id, "MENU_ADMIN")
  176.     else
  177.         len += formatex(menu[len], charsmax(menu) - len, "\d9. %L", id, "MENU_ADMIN")
  178.    
  179.     // 0. Exit
  180.     len += formatex(menu[len], charsmax(menu) - len, "^n^n\r0.\w %L", id, "MENU_EXIT")
  181.    
  182.     // Fix for AMXX custom menus
  183.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  184.     show_menu(id, KEYSMENU, menu, -1, "Main Menu")
  185. }
  186.  
  187. // Main Menu
  188. public menu_main(id, key)
  189. {
  190.     // Player disconnected?
  191.     if (!is_user_connected(id))
  192.         return PLUGIN_HANDLED;
  193.    
  194.     switch (key)
  195.     {
  196.         case 0: // Buy Menu
  197.         {
  198.             // Custom buy menus enabled?
  199.             if (LibraryExists(LIBRARY_BUYMENUS, LibType_Library) && (get_pcvar_num(cvar_buy_custom_primary)
  200.             || get_pcvar_num(cvar_buy_custom_secondary) || get_pcvar_num(cvar_buy_custom_grenades)))
  201.             {
  202.                 // Check whether the player is able to buy anything
  203.                 if (is_user_alive(id))
  204.                     zp_buy_menus_show(id)
  205.                 else
  206.                     zp_colored_print(id, "%L", id, "CANT_BUY_WEAPONS_DEAD")
  207.             }
  208.             else
  209.                 zp_colored_print(id, "%L", id, "CUSTOM_BUY_DISABLED")
  210.         }
  211.         case 1: // Extra Items
  212.         {
  213.             // Items enabled?
  214.             if (LibraryExists(LIBRARY_ITEMS, LibType_Library))
  215.             {
  216.                 // Check whether the player is able to buy anything
  217.                 if (is_user_alive(id))
  218.                     zp_items_show_menu(id)
  219.                 else
  220.                     zp_colored_print(id, "%L", id, "CANT_BUY_ITEMS_DEAD")
  221.             }
  222.             else
  223.                 zp_colored_print(id, "%L", id, "CMD_NOT_EXTRAS")
  224.         }
  225.         case 2: // Zombie Classes
  226.         {
  227.             if (LibraryExists(LIBRARY_ZOMBIECLASSES, LibType_Library) && zp_class_zombie_get_count() > 1)
  228.                 zp_class_zombie_show_menu(id)
  229.             else
  230.                 zp_colored_print(id, "%L", id, "CMD_NOT_ZCLASSES")
  231.         }
  232.         case 3: // Human Classes
  233.         {
  234.             if (LibraryExists(LIBRARY_HUMANCLASSES, LibType_Library) && zp_class_human_get_count() > 1)
  235.                 zp_class_human_show_menu(id)
  236.             else
  237.                 zp_colored_print(id, "%L", id, "CMD_NOT_HCLASSES")
  238.         }
  239.         case 4:
  240.         {
  241.             // Check if player is stuck
  242.             if (LibraryExists(LIBRARY_ZOMBIECLASSES, LibType_Library) && is_user_alive(id))
  243.             {
  244.                 if (is_player_stuck(id))
  245.                 {
  246.                     // Move to an initial spawn
  247.                     if (get_pcvar_num(cvar_random_spawning))
  248.                         zp_random_spawn_do(id, true) // random spawn (including CSDM)
  249.                     else
  250.                         zp_random_spawn_do(id, false) // regular spawn
  251.                 }
  252.                 else
  253.                     zp_colored_print(id, "%L", id, "CMD_NOT_STUCK")
  254.             }
  255.             else
  256.                 zp_colored_print(id, "%L", id, "CMD_NOT")
  257.         }
  258.         case 5: // Help Menu
  259.         {
  260.             show_help(id)
  261.         }
  262.         case 6: // Menu override
  263.         {
  264.             flag_unset(g_ChooseTeamOverrideActive, id)
  265.             client_cmd(id, "chooseteam")
  266.         }
  267.         case 8: // Admin Menu
  268.         {
  269.             if (LibraryExists(LIBRARY_ADMIN_MENU, LibType_Library) && is_user_admin(id))
  270.                 zp_admin_menu_show(id)
  271.             else
  272.                 zp_colored_print(id, "%L", id, "NO_ADMIN_MENU")
  273.         }
  274.     }
  275.    
  276.     return PLUGIN_HANDLED;
  277. }
  278.  
  279. // Help MOTD
  280. show_help(id)
  281. {
  282.     static motd[1024]
  283.     new len
  284.    
  285.     len += formatex(motd[len], charsmax(motd) - len, "%L", id, "MOTD_INFO11", "Zombie Plague Mod", ZP_VERSION_STR_LONG, "ZP Dev Team")
  286.     len += formatex(motd[len], charsmax(motd) - len, "%L", id, "MOTD_INFO12")
  287.    
  288.     show_motd(id, motd)
  289. }
  290.  
  291. // Check if a player is stuck (credits to VEN)
  292. stock is_player_stuck(id)
  293. {
  294.     static Float:originF[3]
  295.     pev(id, pev_origin, originF)
  296.    
  297.     engfunc(EngFunc_TraceHull, originF, originF, 0, (pev(id, pev_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN, id, 0)
  298.    
  299.     if (get_tr2(0, TR_StartSolid) || get_tr2(0, TR_AllSolid) || !get_tr2(0, TR_InOpen))
  300.         return true;
  301.    
  302.     return false;
  303. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top