Need Help in Admin Menu

Coding Help/Re-API Supported
Post Reply
PunisheR
Member
Member
Pakistan
Posts: 17
Joined: 3 years ago
Location: Karachi
Contact:

Need Help in Admin Menu

#1

Post by PunisheR » 2 years ago

Hello,
So, I added Respawn Menu in an Admin Menu Plugin made by @Night Fury
But the problem is when I respawn a player, it's showing Weapons Menu to other players who has already bought the weapons.
Here is my code:
  1. #include <zombie_escape>
  2. #include <cstrike>
  3.  
  4. // Setting File
  5. new const ZE_SETTINGS_FILE[] = "zombie_escape.ini"
  6.  
  7. // Keys
  8. const OFFSET_CSMENUCODE = 205
  9. 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
  10.  
  11. // Access
  12. new g_szAccess_Make_Zombie[2] = "d"
  13. new g_szAccess_Make_Human[2] = "d"
  14. new g_szAccess_Make_Respawn[2] = "d"
  15. new g_iMaxPlayers, g_pCvarLogAdminCmds, bool:g_bIsZombieReleased, bool:g_bIsRoundEnded
  16.  
  17. public plugin_precache()
  18. {
  19.     if (!amx_load_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Make Zombie", g_szAccess_Make_Zombie, charsmax(g_szAccess_Make_Zombie)))
  20.         amx_save_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Make Zombie", g_szAccess_Make_Zombie)
  21.  
  22.     if (!amx_load_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Make Human", g_szAccess_Make_Human, charsmax(g_szAccess_Make_Human)))
  23.         amx_save_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Make Human", g_szAccess_Make_Human)
  24.  
  25.     if (!amx_load_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Respawn Player", g_szAccess_Make_Respawn, charsmax(g_szAccess_Make_Respawn)))
  26.         amx_save_setting_string(ZE_SETTINGS_FILE, "Access Flags", "Respawn Player", g_szAccess_Make_Respawn)
  27. }
  28.  
  29. public plugin_init()
  30. {
  31.     register_plugin("[ZE] Addons: Admin szMenu", "1.0", "Jack GamePlay")
  32.  
  33.     // Cvars
  34.     g_pCvarLogAdminCmds = register_cvar("ze_log_admin_commands", "1")
  35.  
  36.     // Menu Command
  37.     register_clcmd("ze_am", "Open_Admin_Menu")
  38.  
  39.     // Commands
  40.     register_concmd("ze_zombie", "Zombie_Cmd", _, "<target> - Turn someone into a zombie", 0)
  41.     register_concmd("ze_human", "Human_Cmd", _, "<target> - Turn someone back to human", 0)
  42.  
  43.     // Menu
  44.     register_menu("Admin Menu", KEYSMENU, "Admin_Menu")
  45.  
  46.     // Max Players
  47.     g_iMaxPlayers = get_member_game(m_nMaxPlayers)
  48. }
  49.  
  50. public ze_zombie_appear()
  51. {
  52.     g_bIsZombieReleased = false
  53.     g_bIsRoundEnded = false
  54. }
  55.  
  56. public ze_game_started()
  57. {
  58.     g_bIsZombieReleased = false
  59.     g_bIsRoundEnded = false
  60. }
  61.  
  62. public ze_zombie_release()
  63. {
  64.     g_bIsZombieReleased = true
  65.     g_bIsRoundEnded = false
  66. }
  67.  
  68. public ze_roundend()
  69. {
  70.     g_bIsRoundEnded = true
  71.     g_bIsZombieReleased = false
  72. }
  73.  
  74. public Open_Admin_Menu(id)
  75. {
  76.     static szMenu[250]
  77.     new iLen
  78.  
  79.     // Title
  80.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\wAdmin Menu^n^n")
  81.  
  82.     // 1. Make Zombie/Human
  83.     if (get_user_flags(id) & (read_flags(g_szAccess_Make_Zombie) | read_flags(g_szAccess_Make_Human)))
  84.     {
  85.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w1. \wMake Zombie/Human^n")
  86.     }
  87.  
  88.     // 2. Respawn Menu
  89.     if (get_user_flags(id) & (read_flags(g_szAccess_Make_Respawn)))
  90.     {
  91.         iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\w2. Respawn Menu^n")
  92.     }
  93.  
  94.     // 0. Exit
  95.     iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "^n^n\w0. %L", id, "EXIT")
  96.  
  97.     // Fix for AMXX custom menus
  98.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  99.     show_menu(id, KEYSMENU, szMenu, -1, "Admin Menu")
  100. }
  101.  
  102. public Admin_Menu(id, key)
  103. {
  104.     // Player disconnected?
  105.     if (!is_user_connected(id))
  106.         return PLUGIN_HANDLED
  107.  
  108.     switch (key)
  109.     {
  110.         case 0: // Make Zombie/Human
  111.         {
  112.             if (get_user_flags(id) & (read_flags(g_szAccess_Make_Zombie) | read_flags(g_szAccess_Make_Human)))
  113.             {
  114.                 Make_ZMHM(id)
  115.             }
  116.             else
  117.             {
  118.                 ze_colored_print(id, "!tYou have no access!y.")
  119.             }
  120.         }
  121.         case 1: // Respawn Menu
  122.         {
  123.             if (get_user_flags(id) & (read_flags(g_szAccess_Make_Respawn)))
  124.             {
  125.                 RespawnMenu(id)
  126.             }
  127.             else
  128.             {
  129.                 ze_colored_print(id, "!tYou have no access!y.")
  130.             }
  131.         }
  132.     }
  133.  
  134.     return PLUGIN_HANDLED
  135. }
  136.  
  137. public Make_ZMHM(id)
  138. {
  139.     static szMenu[128], szAdminName[32], szPlayerName[32]
  140.     new iIndex, iMenuID, iItemData[2]
  141.  
  142.     get_user_name(id, szAdminName, charsmax(szAdminName))
  143.  
  144.     formatex(szMenu, charsmax(szMenu), "\wMake Zombie/Human^n")
  145.     iMenuID = menu_create(szMenu, "Make_ZMHM_Handler")
  146.  
  147.     for (iIndex = 0; iIndex <= g_iMaxPlayers; iIndex++)
  148.     {
  149.         if (!is_user_connected(iIndex))
  150.             continue
  151.  
  152.         get_user_name(iIndex, szPlayerName, charsmax(szPlayerName))
  153.  
  154.         if (ze_is_user_zombie(iIndex))
  155.         {
  156.             if ((get_user_flags(id) & read_flags(g_szAccess_Make_Human)) && is_user_alive(iIndex) && g_bIsZombieReleased && !g_bIsRoundEnded)
  157.             {
  158.                 if (equali(szPlayerName, szAdminName))
  159.                 {
  160.                     formatex(szMenu, charsmax(szMenu), "\y%s \d[\rZombie\d]", szPlayerName)
  161.                 }
  162.                 else
  163.                 {
  164.                     formatex(szMenu, charsmax(szMenu), "\w%s \d[\rZombie\d]", szPlayerName)
  165.                 }
  166.             }
  167.             else
  168.             {
  169.                 formatex(szMenu, charsmax(szMenu), "\d%s [Zombie]", szPlayerName)
  170.             }
  171.         }
  172.         else
  173.         {
  174.             if ((get_user_flags(id) & read_flags(g_szAccess_Make_Zombie)) && is_user_alive(iIndex) && g_bIsZombieReleased && !g_bIsRoundEnded)
  175.             {
  176.                 if (equali(szPlayerName, szAdminName))
  177.                 {
  178.                     formatex(szMenu, charsmax(szMenu), "\y%s \d[\rHuman\d]", szPlayerName)
  179.                 }
  180.                 else
  181.                 {
  182.                     formatex(szMenu, charsmax(szMenu), "\w%s \d[\rHuman\d]", szPlayerName)
  183.                 }
  184.             }
  185.             else
  186.             {
  187.                 formatex(szMenu, charsmax(szMenu), "\d%s [Human]", szPlayerName)
  188.             }
  189.         }
  190.  
  191.         iItemData[0] = iIndex
  192.         iItemData[1] = 0
  193.         menu_additem(iMenuID, szMenu, iItemData)
  194.     }
  195.  
  196.     // Back - Next - Exit
  197.     formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "BACK")
  198.     menu_setprop(iMenuID, MPROP_BACKNAME, szMenu)
  199.     formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "NEXT")
  200.     menu_setprop(iMenuID, MPROP_NEXTNAME, szMenu)
  201.     formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "EXIT")
  202.     menu_setprop(iMenuID, MPROP_EXITNAME, szMenu)
  203.     menu_display(id, iMenuID, 0, 30)
  204. }
  205.  
  206. public Make_ZMHM_Handler(id, iMenuID, iKey)
  207. {
  208.     if (iKey == MENU_EXIT)
  209.     {
  210.         menu_destroy(iMenuID)
  211.         Open_Admin_Menu(id)
  212.         return PLUGIN_HANDLED
  213.     }
  214.  
  215.     new iItemData[2], iDummy, iPlayer
  216.     menu_item_getinfo(iMenuID, iKey, iDummy, iItemData, charsmax(iItemData), _, _, iDummy)
  217.     iPlayer = iItemData[0]
  218.  
  219.     if (is_user_connected(iPlayer))
  220.     {
  221.         if (ze_is_user_zombie(iPlayer))
  222.         {
  223.             if ((get_user_flags(id) & read_flags(g_szAccess_Make_Human)) && is_user_alive(iPlayer) && g_bIsZombieReleased && !g_bIsRoundEnded)
  224.             {
  225.                 ze_admin_command_human(id, iPlayer)
  226.                 Make_ZMHM(id)
  227.             }
  228.             else
  229.             {
  230.                 ze_colored_print(id, "!tThis command is not available!y!")
  231.             }
  232.         }
  233.         else
  234.         {
  235.             if ((get_user_flags(id) & read_flags(g_szAccess_Make_Zombie)) && is_user_alive(iPlayer) && g_bIsZombieReleased && !g_bIsRoundEnded)
  236.             {
  237.                 ze_admin_command_zombie(id, iPlayer)
  238.                 Make_ZMHM(id)
  239.             }
  240.             else
  241.             {
  242.                 ze_colored_print(id, "!tThis command is not available!y!")
  243.             }
  244.         }
  245.     }
  246.  
  247.     menu_destroy(iMenuID)
  248.     return PLUGIN_HANDLED
  249. }
  250.  
  251. public ze_admin_command_human(Admin_ID, Player_ID)
  252. {
  253.     if (!is_user_connected(Admin_ID))
  254.     {
  255.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", Admin_ID)
  256.         return false
  257.     }
  258.  
  259.     if (!is_user_alive(Player_ID))
  260.     {
  261.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", Player_ID)
  262.         return false
  263.     }
  264.  
  265.     Cmd_Human(Admin_ID, Player_ID)
  266.     return true
  267. }
  268.  
  269. public ze_admin_command_zombie(Admin_ID, Player_ID)
  270. {
  271.     if (!is_user_connected(Admin_ID))
  272.     {
  273.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", Admin_ID)
  274.         return false
  275.     }
  276.  
  277.     if (!is_user_alive(Player_ID))
  278.     {
  279.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", Player_ID)
  280.         return false
  281.     }
  282.  
  283.     Cmd_Zombie(Admin_ID, Player_ID)
  284.     return true
  285. }
  286.  
  287. public Human_Cmd(Admin_ID, level, cid)
  288. {
  289.     // Check for access flag - Make Human
  290.     if (!cmd_access(Admin_ID, read_flags(g_szAccess_Make_Human), cid, 2))
  291.         return PLUGIN_HANDLED
  292.  
  293.     // Retrieve arguments
  294.     new szArg[32], Player_ID
  295.     read_argv(1, szArg, charsmax(szArg))
  296.     Player_ID = cmd_target(Admin_ID, szArg, (CMDTARGET_ONLY_ALIVE | CMDTARGET_ALLOW_SELF))
  297.  
  298.     // Invalid target
  299.     if (!Player_ID || !g_bIsZombieReleased || g_bIsRoundEnded)
  300.         return PLUGIN_HANDLED
  301.  
  302.     // Target not allowed to be human
  303.     if (!ze_is_user_zombie(Player_ID))
  304.     {
  305.         new szPlayerName[32]
  306.         get_user_name(Player_ID, szPlayerName, charsmax(szPlayerName))
  307.         client_print(Admin_ID, print_console, "[WGCS] %s is already human", szPlayerName)
  308.         return PLUGIN_HANDLED
  309.     }
  310.  
  311.     Cmd_Human(Admin_ID, Player_ID)
  312.     return PLUGIN_HANDLED
  313. }
  314.  
  315. public Zombie_Cmd(Admin_ID, level, cid)
  316. {
  317.     // Check for access flag - Make Human
  318.     if (!cmd_access(Admin_ID, read_flags(g_szAccess_Make_Zombie), cid, 2))
  319.         return PLUGIN_HANDLED
  320.  
  321.     // Retrieve arguments
  322.     new szArg[32], Player_ID
  323.     read_argv(1, szArg, charsmax(szArg))
  324.     Player_ID = cmd_target(Admin_ID, szArg, (CMDTARGET_ONLY_ALIVE | CMDTARGET_ALLOW_SELF))
  325.  
  326.     // Invalid target
  327.     if (!Player_ID || !g_bIsZombieReleased || g_bIsRoundEnded)
  328.         return PLUGIN_HANDLED
  329.  
  330.     // Target not allowed to be human
  331.     if (ze_is_user_zombie(Player_ID))
  332.     {
  333.         new szPlayerName[32]
  334.         get_user_name(Player_ID, szPlayerName, charsmax(szPlayerName))
  335.         client_print(Admin_ID, print_console, "[WGCS] %s is already zombie.", szPlayerName)
  336.         return PLUGIN_HANDLED
  337.     }
  338.  
  339.     Cmd_Zombie(Admin_ID, Player_ID)
  340.     return PLUGIN_HANDLED
  341. }
  342.  
  343. public Cmd_Human(Admin_ID, Player_ID)
  344. {
  345.     // Prevent infecting last zombie
  346.     if (ze_get_zombies_number() == 1)
  347.     {
  348.         ze_colored_print(Admin_ID, "!tCan't apply this action on the last zombie!y.")
  349.         return
  350.     }
  351.  
  352.     // Zombies have not been released yet
  353.     if (!g_bIsZombieReleased)
  354.     {
  355.         ze_colored_print(Admin_ID, "!tThis command is available only after zombie appear!y.")
  356.         return
  357.     }
  358.  
  359.     ze_set_user_human(Player_ID)
  360.  
  361.     // Get user names
  362.     new szAdminName[32], szPlayerName[32]
  363.     get_user_name(Admin_ID, szAdminName, charsmax(szAdminName))
  364.     get_user_name(Player_ID, szPlayerName, charsmax(szPlayerName))
  365.  
  366.     ze_cprint(0, "!yADMIN !g%s !tturn !g%s !tinto !gHuman", szAdminName, szPlayerName)
  367.  
  368.     // Log to Zombie Escape log file?
  369.     if (get_pcvar_num(g_pCvarLogAdminCmds))
  370.     {
  371.         new szAuthid[32], szIP[16]
  372.         get_user_authid(Admin_ID, szAuthid, charsmax(szAuthid))
  373.         get_user_ip(Admin_ID, szIP, charsmax(szIP), 1)
  374.         ze_log("ADMIN [%s (%s - %s)] turned %s into human", szAdminName, szAuthid, szIP, szPlayerName)
  375.     }
  376. }
  377.  
  378. public Cmd_Zombie(Admin_ID, Player_ID)
  379. {
  380.     // Prevent infecting last zombie
  381.     if (ze_get_humans_number() == 1)
  382.     {
  383.         ze_colored_print(Admin_ID, "!tCan't apply this action on the last human!y!")
  384.         return
  385.     }
  386.  
  387.     // Game is already started
  388.     if (ze_is_game_started())
  389.     {
  390.         // Zombie released
  391.         if (!g_bIsZombieReleased)
  392.         {
  393.             ze_colored_print(Admin_ID, "!tThis command is available only after zombie appear!y.")
  394.             return
  395.         }
  396.     }
  397.  
  398.     ze_set_user_zombie(Player_ID)
  399.  
  400.     // Get user names
  401.     new szAdminName[32], szPlayerName[32]
  402.     get_user_name(Admin_ID, szAdminName, charsmax(szAdminName))
  403.     get_user_name(Player_ID, szPlayerName, charsmax(szPlayerName))
  404.  
  405.     ze_cprint(0, "!yADMIN !g%s !tturn !g%s !tinto !gZombie", szAdminName, szPlayerName)
  406.  
  407.     // Log to Zombie Escape log file?
  408.     if (get_pcvar_num(g_pCvarLogAdminCmds))
  409.     {
  410.         new szAuthid[32], szIP[16]
  411.         get_user_authid(Admin_ID, szAuthid, charsmax(szAuthid))
  412.         get_user_ip(Admin_ID, szIP, charsmax(szIP), 1)
  413.         ze_log("ADMIN [%s (%s - %s)] turned %s into zombie", szAdminName, szAuthid, szIP, szPlayerName)
  414.     }
  415. }
  416.  
  417. public RespawnMenu(id)
  418. {
  419.     new RespawnPlayer = menu_create ("\wRespawn Menu", "RespawnMenu_Handler")
  420.     new num, players[32], tempid, szTempID [10], tempname [32]
  421.     get_players (players, num, "b")
  422.  
  423.     for (new i = 0; i < num; i++)
  424.     {
  425.         tempid = players [ i ]
  426.         get_user_name (tempid, tempname, 31)
  427.         num_to_str (tempid, szTempID, 9)
  428.         menu_additem (RespawnPlayer, tempname, szTempID, 0)
  429.     }
  430.  
  431.     menu_display (id, RespawnPlayer)
  432.     return PLUGIN_HANDLED
  433. }
  434.  
  435. public RespawnMenu_Handler(id, menu, item)
  436. {
  437.     if(item == MENU_EXIT)
  438.     {
  439.         menu_destroy(menu)
  440.         Open_Admin_Menu(id)
  441.         return PLUGIN_HANDLED
  442.     }
  443.  
  444.     new data[6], name[64]
  445.     new access, callback
  446.     menu_item_getinfo (menu, item, access, data, 5, name, 63, callback)
  447.     new tempid = str_to_num (data)
  448.  
  449.     new szName[32], szAdminName[32]
  450.     get_user_name(id, szName, charsmax(szName))
  451.     get_user_name(tempid, szAdminName, charsmax(szAdminName))
  452.  
  453.     ze_colored_print(0, "!yADMIN !g%s !trespawned !g%s", szName, szAdminName)
  454.  
  455.     if(ze_is_game_started())
  456.     {
  457.         ExecuteHamB(Ham_CS_RoundRespawn, tempid)
  458.         ze_set_user_human(id)
  459.     }
  460.     else if(g_bIsRoundEnded)
  461.     {
  462.         ze_colored_print(id, "!tYou cannot respawn the player when round ended!y!")
  463.     }
  464.     else
  465.     {
  466.         ExecuteHamB(Ham_CS_RoundRespawn, tempid)
  467.         ze_set_user_human(id)
  468.         rg_set_user_team(id, TEAM_CT)
  469.     }
  470.  
  471.     RespawnMenu(id)
  472.  
  473.     /*Log to Zombie Escape log file?
  474.     if (get_pcvar_num(g_pCvarLogAdminCmds))
  475.     {
  476.         new szAuthid[32], szIP[16]
  477.         get_user_authid(id, szAuthid, charsmax(szAuthid))
  478.         get_user_ip(id, szIP, charsmax(szIP), 1)
  479.         ze_log("ADMIN [%s (%s - %s)] respawned %s", szAdminName, szAuthid, szIP, szName)
  480.     }*/
  481.  
  482.     return PLUGIN_CONTINUE
  483. }

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 473
Joined: 5 years ago
Location: The Red City ❤
Contact:

#2

Post by z0h1r-LK » 1 year ago

Solved?

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 3 guests