Solved Not able to buy extra on freeze

Unpaid Requests, Public Plugins
Post Reply
User avatar
Mark
VIP
VIP
United States of America
Posts: 283
Joined: 5 years ago
Location: Des Moines/USA
Contact:

Not able to buy extra on freeze

#1

Post by Mark » 5 years ago

Not sure if this has been asked but did someone make a edit or plugin to prevent anyone from buying extra items before zombie has been choozen?

So No Buying Extra Items in Frozen but can pick from weapon menu....

Ive looked quick but did not see nothing yet.

:D

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#2

Post by Raheem » 5 years ago

Discussed before how to block for only specific item, but if you need general block we will need to edit the items manager plugins as following(ze_items_manager.sma):

  1. #include <zombie_escape>
  2.  
  3. // Setting File
  4. new const ZE_EXTRAITEM_FILE[] = "ze_extraitems.ini"
  5.  
  6. // Defines
  7. #define MENU_PAGE_ITEMS g_iMenuData[id]
  8.  
  9. // Const
  10. const OFFSET_CSMENUCODE = 205
  11.  
  12. // Forwards
  13. enum _:TOTAL_FORWARDS
  14. {
  15.     FW_ITEM_SELECT_PRE = 0,
  16.     FW_ITEM_SELECT_POST
  17. }
  18.  
  19. new g_iForwards[TOTAL_FORWARDS],
  20.     g_iForwardReturn
  21.  
  22. // Variables
  23. new Array:g_szItemRealName,
  24.     Array:g_szItemName,  
  25.     Array:g_iItemCost,
  26.     Array:g_iItemLimit
  27.  
  28. new g_iItemCount,
  29.     g_szAdditionalMenuText[32],
  30.     g_iMenuData[33]
  31.    
  32. new bool:g_bBlockBuy
  33.  
  34. public plugin_init()
  35. {
  36.     register_plugin("[ZE] Items Manager", ZE_VERSION, AUTHORS)
  37.    
  38.     // Commands
  39.     register_clcmd("say /items", "Cmd_Items")
  40.    
  41.     // Forwards (In Pre Return Values important)
  42.     g_iForwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("ze_select_item_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  43.     g_iForwards[FW_ITEM_SELECT_POST] = CreateMultiForward("ze_select_item_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
  44. }
  45.  
  46. public plugin_natives()
  47. {
  48.     register_native("ze_register_item", "native_ze_register_item")
  49.     register_native("ze_show_items_menu", "native_ze_show_items_menu")
  50.     register_native("ze_force_buy_item", "native_ze_force_buy_item")
  51.     register_native("ze_get_item_id", "native_ze_get_item_id")
  52.     register_native("ze_get_item_cost", "native_ze_get_item_cost")
  53.     register_native("ze_add_text_to_item", "native_ze_add_text_to_item")
  54.     register_native("ze_get_item_limit", "native_ze_get_item_limit")
  55.     register_native("ze_is_valid_itemid", "native_ze_is_valid_itemid")
  56.     register_native("ze_get_item_name", "native_ze_get_item_name")
  57.    
  58.     g_szItemRealName = ArrayCreate(32, 1)
  59.     g_szItemName = ArrayCreate(32, 1)
  60.     g_iItemCost = ArrayCreate(1, 1)
  61.     g_iItemLimit = ArrayCreate(1, 1)
  62. }
  63.  
  64. public ze_game_started()
  65. {
  66.     g_bBlockBuy = true
  67. }
  68.  
  69. public ze_zombie_release()
  70. {
  71.     g_bBlockBuy = false
  72. }
  73.  
  74. public client_disconnected(id)
  75. {
  76.     MENU_PAGE_ITEMS = 0
  77. }
  78.  
  79. public Cmd_Items(id)
  80. {
  81.     if (!is_user_alive(id))
  82.         return
  83.    
  84.     Show_Items_Menu(id)
  85. }
  86.  
  87. // Items Menu
  88. Show_Items_Menu(id)
  89. {
  90.     static menu[128], name[32], cost, transkey[64]
  91.     new menuid, index, itemdata[2]
  92.    
  93.     // Title
  94.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
  95.     menuid = menu_create(menu, "Extra_Items_Menu")
  96.    
  97.     // Item List
  98.     for (index = 0; index < g_iItemCount; index++)
  99.     {
  100.         // Additional text to display
  101.         g_szAdditionalMenuText[0] = 0
  102.        
  103.         // Execute item select attempt forward
  104.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
  105.        
  106.         // Show item to player?
  107.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW || g_bBlockBuy)
  108.             continue;
  109.        
  110.         // Add Item Name and Cost
  111.         ArrayGetString(g_szItemName, index, name, charsmax(name))
  112.         cost = ArrayGetCell(g_iItemCost, index)
  113.        
  114.         // ML support for item name
  115.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
  116.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
  117.        
  118.         // Item available to player?
  119.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  120.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
  121.         else
  122.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
  123.        
  124.         itemdata[0] = index
  125.         itemdata[1] = 0
  126.         menu_additem(menuid, menu, itemdata)
  127.     }
  128.    
  129.     // No items to display?
  130.     if (menu_items(menuid) <= 0)
  131.     {
  132.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
  133.         menu_destroy(menuid)
  134.         return;
  135.     }
  136.    
  137.     // Back - Next - Exit
  138.     formatex(menu, charsmax(menu), "%L", id, "BACK")
  139.     menu_setprop(menuid, MPROP_BACKNAME, menu)
  140.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
  141.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
  142.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
  143.     menu_setprop(menuid, MPROP_EXITNAME, menu)
  144.    
  145.     // If remembered page is greater than number of pages, clamp down the value
  146.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
  147.    
  148.     // Fix for AMXX custom menus
  149.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  150.     menu_display(id, menuid, MENU_PAGE_ITEMS)
  151. }
  152.  
  153. // Items Menu
  154. public Extra_Items_Menu(id, menuid, item)
  155. {
  156.     // Menu was closed
  157.     if (item == MENU_EXIT)
  158.     {
  159.         MENU_PAGE_ITEMS = 0
  160.         menu_destroy(menuid)
  161.         return PLUGIN_HANDLED;
  162.     }
  163.    
  164.     // Remember items menu page
  165.     MENU_PAGE_ITEMS = item / 7
  166.    
  167.     // Dead players are not allowed to buy items
  168.     if (!is_user_alive(id))
  169.     {
  170.         menu_destroy(menuid)
  171.         return PLUGIN_HANDLED;
  172.     }
  173.    
  174.     // Retrieve item id
  175.     new itemdata[2], dummy, itemid
  176.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
  177.     itemid = itemdata[0]
  178.    
  179.     // Attempt to buy the item
  180.     Buy_Item(id, itemid)
  181.     menu_destroy(menuid)
  182.     return PLUGIN_HANDLED;
  183. }
  184.  
  185. // Buy Item
  186. Buy_Item(id, itemid, ignorecost = 0)
  187. {
  188.     // Execute item select attempt forward
  189.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
  190.    
  191.     // Item available to player?
  192.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  193.         return;
  194.    
  195.     // Execute item selected forward
  196.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
  197. }
  198.  
  199. // Natives
  200. public native_ze_register_item(plugin_id, num_params)
  201. {
  202.     new szItem_Name[32], iItem_Cost, iItem_Limit
  203.    
  204.     // Get the Data from first Parameter in the native (Item Name)
  205.     get_string(1, szItem_Name, charsmax(szItem_Name))
  206.    
  207.     // Get the Second Parameter (Item Cost)
  208.     iItem_Cost = get_param(2)
  209.    
  210.     // Get limit third parameter
  211.     iItem_Limit = get_param(3)
  212.    
  213.     if (strlen(szItem_Name) < 1)
  214.     {
  215.         // Can't leave item name empty
  216.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
  217.         return ZE_WRONG_ITEM // Same as return -1
  218.     }
  219.    
  220.     new iIndex, szItemName[32]
  221.    
  222.     // Loop from 0 to max items amount
  223.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
  224.     {
  225.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
  226.        
  227.         if (equali(szItem_Name, szItemName))
  228.         {
  229.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
  230.             return ZE_WRONG_ITEM; // Return -1
  231.         }
  232.     }
  233.    
  234.     // Load settings from extra items file
  235.     new szItemRealName[32]
  236.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
  237.     ArrayPushString(g_szItemRealName, szItemRealName)
  238.    
  239.     // Name
  240.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
  241.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
  242.     ArrayPushString(g_szItemName, szItem_Name)
  243.    
  244.     // Cost
  245.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
  246.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
  247.     ArrayPushCell(g_iItemCost, iItem_Cost)
  248.    
  249.     // Limit
  250.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
  251.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
  252.     ArrayPushCell(g_iItemLimit, iItem_Limit)
  253.    
  254.     g_iItemCount++
  255.     return g_iItemCount - 1
  256. }
  257.  
  258. public native_ze_show_items_menu(plugin_id, num_params)
  259. {
  260.     new id = get_param(1)
  261.    
  262.     if (!is_user_connected(id))
  263.     {
  264.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  265.         return false;
  266.     }
  267.    
  268.     Cmd_Items(id)
  269.     return true
  270. }
  271.  
  272. public native_ze_force_buy_item(plugin_id, num_params)
  273. {
  274.     new id = get_param(1)
  275.    
  276.     if (!is_user_connected(id))
  277.     {
  278.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  279.         return false;
  280.     }
  281.    
  282.     new item_id = get_param(2)
  283.    
  284.     if (item_id < 0 || item_id >= g_iItemCount)
  285.     {
  286.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  287.         return false;
  288.     }
  289.    
  290.     new ignorecost = get_param(3)
  291.    
  292.     Buy_Item(id, item_id, ignorecost)
  293.     return true;
  294. }
  295.  
  296. public native_ze_get_item_id(plugin_id, num_params)
  297. {
  298.     new szRealName[32]
  299.     get_string(1, szRealName, charsmax(szRealName))
  300.  
  301.     new index, szItemName[32]
  302.    
  303.     for (index = 0; index < g_iItemCount; index++)
  304.     {
  305.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
  306.        
  307.         if (equali(szRealName, szItemName))
  308.             return index
  309.     }
  310.    
  311.     return ZE_WRONG_ITEM
  312. }
  313.  
  314. public native_ze_get_item_cost(plugin_id, num_params)
  315. {
  316.     new item_id = get_param(1)
  317.    
  318.     if (item_id < 0 || item_id >= g_iItemCount)
  319.     {
  320.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  321.         return ZE_WRONG_ITEM;
  322.     }
  323.    
  324.     return ArrayGetCell(g_iItemCost, item_id);
  325. }
  326.  
  327. public native_ze_add_text_to_item(plugin_id, num_params)
  328. {
  329.     new szText[32]
  330.     get_string(1, szText, charsmax(szText))
  331.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
  332. }
  333.  
  334. public native_ze_get_item_limit(plugin_id, num_params)
  335. {
  336.     new item_id = get_param(1)
  337.    
  338.     if (item_id < 0 || item_id >= g_iItemCount)
  339.     {
  340.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  341.         return ZE_WRONG_ITEM;
  342.     }
  343.    
  344.     return ArrayGetCell(g_iItemLimit, item_id);
  345. }
  346.  
  347. public native_ze_is_valid_itemid(plugin_id, num_params)
  348. {
  349.     new item_id = get_param(1)
  350.    
  351.     if (item_id < 0 || item_id >= g_iItemCount)
  352.     {
  353.         return false;
  354.     }
  355.    
  356.     return true;
  357. }
  358.  
  359. public native_ze_get_item_name(plugin_id, num_params)
  360. {
  361.     new item_id = get_param(1)
  362.    
  363.     if (item_id < 0 || item_id >= g_iItemCount)
  364.     {
  365.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  366.         return ZE_WRONG_ITEM;
  367.     }
  368.    
  369.     new szName[32]
  370.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
  371.    
  372.     new iLen = get_param(3)
  373.     set_string(2, szName, iLen)
  374.     return true;
  375. }

OH, i found this topic: viewtopic.php?f=17&t=3208 also discussed how to block buying generally but with external plugin so no need for core files editing.
He who fails to plan is planning to fail

User avatar
Mark
VIP
VIP
United States of America
Posts: 283
Joined: 5 years ago
Location: Des Moines/USA
Contact:

#3

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Discussed before how to block for only specific item, but if you need general block we will need to edit the items manager plugins as following(ze_items_manager.sma):

  1. #include <zombie_escape>
  2.  
  3. // Setting File
  4. new const ZE_EXTRAITEM_FILE[] = "ze_extraitems.ini"
  5.  
  6. // Defines
  7. #define MENU_PAGE_ITEMS g_iMenuData[id]
  8.  
  9. // Const
  10. const OFFSET_CSMENUCODE = 205
  11.  
  12. // Forwards
  13. enum _:TOTAL_FORWARDS
  14. {
  15.     FW_ITEM_SELECT_PRE = 0,
  16.     FW_ITEM_SELECT_POST
  17. }
  18.  
  19. new g_iForwards[TOTAL_FORWARDS],
  20.     g_iForwardReturn
  21.  
  22. // Variables
  23. new Array:g_szItemRealName,
  24.     Array:g_szItemName,  
  25.     Array:g_iItemCost,
  26.     Array:g_iItemLimit
  27.  
  28. new g_iItemCount,
  29.     g_szAdditionalMenuText[32],
  30.     g_iMenuData[33]
  31.    
  32. new bool:g_bBlockBuy
  33.  
  34. public plugin_init()
  35. {
  36.     register_plugin("[ZE] Items Manager", ZE_VERSION, AUTHORS)
  37.    
  38.     // Commands
  39.     register_clcmd("say /items", "Cmd_Items")
  40.    
  41.     // Forwards (In Pre Return Values important)
  42.     g_iForwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("ze_select_item_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  43.     g_iForwards[FW_ITEM_SELECT_POST] = CreateMultiForward("ze_select_item_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
  44. }
  45.  
  46. public plugin_natives()
  47. {
  48.     register_native("ze_register_item", "native_ze_register_item")
  49.     register_native("ze_show_items_menu", "native_ze_show_items_menu")
  50.     register_native("ze_force_buy_item", "native_ze_force_buy_item")
  51.     register_native("ze_get_item_id", "native_ze_get_item_id")
  52.     register_native("ze_get_item_cost", "native_ze_get_item_cost")
  53.     register_native("ze_add_text_to_item", "native_ze_add_text_to_item")
  54.     register_native("ze_get_item_limit", "native_ze_get_item_limit")
  55.     register_native("ze_is_valid_itemid", "native_ze_is_valid_itemid")
  56.     register_native("ze_get_item_name", "native_ze_get_item_name")
  57.    
  58.     g_szItemRealName = ArrayCreate(32, 1)
  59.     g_szItemName = ArrayCreate(32, 1)
  60.     g_iItemCost = ArrayCreate(1, 1)
  61.     g_iItemLimit = ArrayCreate(1, 1)
  62. }
  63.  
  64. public ze_game_started()
  65. {
  66.     g_bBlockBuy = true
  67. }
  68.  
  69. public ze_zombie_release()
  70. {
  71.     g_bBlockBuy = false
  72. }
  73.  
  74. public client_disconnected(id)
  75. {
  76.     MENU_PAGE_ITEMS = 0
  77. }
  78.  
  79. public Cmd_Items(id)
  80. {
  81.     if (!is_user_alive(id))
  82.         return
  83.    
  84.     Show_Items_Menu(id)
  85. }
  86.  
  87. // Items Menu
  88. Show_Items_Menu(id)
  89. {
  90.     static menu[128], name[32], cost, transkey[64]
  91.     new menuid, index, itemdata[2]
  92.    
  93.     // Title
  94.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
  95.     menuid = menu_create(menu, "Extra_Items_Menu")
  96.    
  97.     // Item List
  98.     for (index = 0; index < g_iItemCount; index++)
  99.     {
  100.         // Additional text to display
  101.         g_szAdditionalMenuText[0] = 0
  102.        
  103.         // Execute item select attempt forward
  104.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
  105.        
  106.         // Show item to player?
  107.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW || g_bBlockBuy)
  108.             continue;
  109.        
  110.         // Add Item Name and Cost
  111.         ArrayGetString(g_szItemName, index, name, charsmax(name))
  112.         cost = ArrayGetCell(g_iItemCost, index)
  113.        
  114.         // ML support for item name
  115.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
  116.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
  117.        
  118.         // Item available to player?
  119.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  120.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
  121.         else
  122.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
  123.        
  124.         itemdata[0] = index
  125.         itemdata[1] = 0
  126.         menu_additem(menuid, menu, itemdata)
  127.     }
  128.    
  129.     // No items to display?
  130.     if (menu_items(menuid) <= 0)
  131.     {
  132.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
  133.         menu_destroy(menuid)
  134.         return;
  135.     }
  136.    
  137.     // Back - Next - Exit
  138.     formatex(menu, charsmax(menu), "%L", id, "BACK")
  139.     menu_setprop(menuid, MPROP_BACKNAME, menu)
  140.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
  141.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
  142.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
  143.     menu_setprop(menuid, MPROP_EXITNAME, menu)
  144.    
  145.     // If remembered page is greater than number of pages, clamp down the value
  146.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
  147.    
  148.     // Fix for AMXX custom menus
  149.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  150.     menu_display(id, menuid, MENU_PAGE_ITEMS)
  151. }
  152.  
  153. // Items Menu
  154. public Extra_Items_Menu(id, menuid, item)
  155. {
  156.     // Menu was closed
  157.     if (item == MENU_EXIT)
  158.     {
  159.         MENU_PAGE_ITEMS = 0
  160.         menu_destroy(menuid)
  161.         return PLUGIN_HANDLED;
  162.     }
  163.    
  164.     // Remember items menu page
  165.     MENU_PAGE_ITEMS = item / 7
  166.    
  167.     // Dead players are not allowed to buy items
  168.     if (!is_user_alive(id))
  169.     {
  170.         menu_destroy(menuid)
  171.         return PLUGIN_HANDLED;
  172.     }
  173.    
  174.     // Retrieve item id
  175.     new itemdata[2], dummy, itemid
  176.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
  177.     itemid = itemdata[0]
  178.    
  179.     // Attempt to buy the item
  180.     Buy_Item(id, itemid)
  181.     menu_destroy(menuid)
  182.     return PLUGIN_HANDLED;
  183. }
  184.  
  185. // Buy Item
  186. Buy_Item(id, itemid, ignorecost = 0)
  187. {
  188.     // Execute item select attempt forward
  189.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
  190.    
  191.     // Item available to player?
  192.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  193.         return;
  194.    
  195.     // Execute item selected forward
  196.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
  197. }
  198.  
  199. // Natives
  200. public native_ze_register_item(plugin_id, num_params)
  201. {
  202.     new szItem_Name[32], iItem_Cost, iItem_Limit
  203.    
  204.     // Get the Data from first Parameter in the native (Item Name)
  205.     get_string(1, szItem_Name, charsmax(szItem_Name))
  206.    
  207.     // Get the Second Parameter (Item Cost)
  208.     iItem_Cost = get_param(2)
  209.    
  210.     // Get limit third parameter
  211.     iItem_Limit = get_param(3)
  212.    
  213.     if (strlen(szItem_Name) < 1)
  214.     {
  215.         // Can't leave item name empty
  216.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
  217.         return ZE_WRONG_ITEM // Same as return -1
  218.     }
  219.    
  220.     new iIndex, szItemName[32]
  221.    
  222.     // Loop from 0 to max items amount
  223.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
  224.     {
  225.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
  226.        
  227.         if (equali(szItem_Name, szItemName))
  228.         {
  229.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
  230.             return ZE_WRONG_ITEM; // Return -1
  231.         }
  232.     }
  233.    
  234.     // Load settings from extra items file
  235.     new szItemRealName[32]
  236.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
  237.     ArrayPushString(g_szItemRealName, szItemRealName)
  238.    
  239.     // Name
  240.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
  241.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
  242.     ArrayPushString(g_szItemName, szItem_Name)
  243.    
  244.     // Cost
  245.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
  246.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
  247.     ArrayPushCell(g_iItemCost, iItem_Cost)
  248.    
  249.     // Limit
  250.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
  251.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
  252.     ArrayPushCell(g_iItemLimit, iItem_Limit)
  253.    
  254.     g_iItemCount++
  255.     return g_iItemCount - 1
  256. }
  257.  
  258. public native_ze_show_items_menu(plugin_id, num_params)
  259. {
  260.     new id = get_param(1)
  261.    
  262.     if (!is_user_connected(id))
  263.     {
  264.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  265.         return false;
  266.     }
  267.    
  268.     Cmd_Items(id)
  269.     return true
  270. }
  271.  
  272. public native_ze_force_buy_item(plugin_id, num_params)
  273. {
  274.     new id = get_param(1)
  275.    
  276.     if (!is_user_connected(id))
  277.     {
  278.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  279.         return false;
  280.     }
  281.    
  282.     new item_id = get_param(2)
  283.    
  284.     if (item_id < 0 || item_id >= g_iItemCount)
  285.     {
  286.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  287.         return false;
  288.     }
  289.    
  290.     new ignorecost = get_param(3)
  291.    
  292.     Buy_Item(id, item_id, ignorecost)
  293.     return true;
  294. }
  295.  
  296. public native_ze_get_item_id(plugin_id, num_params)
  297. {
  298.     new szRealName[32]
  299.     get_string(1, szRealName, charsmax(szRealName))
  300.  
  301.     new index, szItemName[32]
  302.    
  303.     for (index = 0; index < g_iItemCount; index++)
  304.     {
  305.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
  306.        
  307.         if (equali(szRealName, szItemName))
  308.             return index
  309.     }
  310.    
  311.     return ZE_WRONG_ITEM
  312. }
  313.  
  314. public native_ze_get_item_cost(plugin_id, num_params)
  315. {
  316.     new item_id = get_param(1)
  317.    
  318.     if (item_id < 0 || item_id >= g_iItemCount)
  319.     {
  320.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  321.         return ZE_WRONG_ITEM;
  322.     }
  323.    
  324.     return ArrayGetCell(g_iItemCost, item_id);
  325. }
  326.  
  327. public native_ze_add_text_to_item(plugin_id, num_params)
  328. {
  329.     new szText[32]
  330.     get_string(1, szText, charsmax(szText))
  331.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
  332. }
  333.  
  334. public native_ze_get_item_limit(plugin_id, num_params)
  335. {
  336.     new item_id = get_param(1)
  337.    
  338.     if (item_id < 0 || item_id >= g_iItemCount)
  339.     {
  340.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  341.         return ZE_WRONG_ITEM;
  342.     }
  343.    
  344.     return ArrayGetCell(g_iItemLimit, item_id);
  345. }
  346.  
  347. public native_ze_is_valid_itemid(plugin_id, num_params)
  348. {
  349.     new item_id = get_param(1)
  350.    
  351.     if (item_id < 0 || item_id >= g_iItemCount)
  352.     {
  353.         return false;
  354.     }
  355.    
  356.     return true;
  357. }
  358.  
  359. public native_ze_get_item_name(plugin_id, num_params)
  360. {
  361.     new item_id = get_param(1)
  362.    
  363.     if (item_id < 0 || item_id >= g_iItemCount)
  364.     {
  365.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  366.         return ZE_WRONG_ITEM;
  367.     }
  368.    
  369.     new szName[32]
  370.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
  371.    
  372.     new iLen = get_param(3)
  373.     set_string(2, szName, iLen)
  374.     return true;
  375. }

OH, i found this topic: viewtopic.php?f=17&t=3208 also discussed how to block buying generally but with external plugin so no need for core files editing.
So this will block all extra items not the weapon menu?

nevermind i read the code and the answer is yes :D

User avatar
Mark
VIP
VIP
United States of America
Posts: 283
Joined: 5 years ago
Location: Des Moines/USA
Contact:

#4

Post by Mark » 5 years ago

Mark wrote: 5 years ago
Raheem wrote: 5 years ago Discussed before how to block for only specific item, but if you need general block we will need to edit the items manager plugins as following(ze_items_manager.sma):

  1. #include <zombie_escape>
  2.  
  3. // Setting File
  4. new const ZE_EXTRAITEM_FILE[] = "ze_extraitems.ini"
  5.  
  6. // Defines
  7. #define MENU_PAGE_ITEMS g_iMenuData[id]
  8.  
  9. // Const
  10. const OFFSET_CSMENUCODE = 205
  11.  
  12. // Forwards
  13. enum _:TOTAL_FORWARDS
  14. {
  15.     FW_ITEM_SELECT_PRE = 0,
  16.     FW_ITEM_SELECT_POST
  17. }
  18.  
  19. new g_iForwards[TOTAL_FORWARDS],
  20.     g_iForwardReturn
  21.  
  22. // Variables
  23. new Array:g_szItemRealName,
  24.     Array:g_szItemName,  
  25.     Array:g_iItemCost,
  26.     Array:g_iItemLimit
  27.  
  28. new g_iItemCount,
  29.     g_szAdditionalMenuText[32],
  30.     g_iMenuData[33]
  31.    
  32. new bool:g_bBlockBuy
  33.  
  34. public plugin_init()
  35. {
  36.     register_plugin("[ZE] Items Manager", ZE_VERSION, AUTHORS)
  37.    
  38.     // Commands
  39.     register_clcmd("say /items", "Cmd_Items")
  40.    
  41.     // Forwards (In Pre Return Values important)
  42.     g_iForwards[FW_ITEM_SELECT_PRE] = CreateMultiForward("ze_select_item_pre", ET_CONTINUE, FP_CELL, FP_CELL, FP_CELL)
  43.     g_iForwards[FW_ITEM_SELECT_POST] = CreateMultiForward("ze_select_item_post", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL)
  44. }
  45.  
  46. public plugin_natives()
  47. {
  48.     register_native("ze_register_item", "native_ze_register_item")
  49.     register_native("ze_show_items_menu", "native_ze_show_items_menu")
  50.     register_native("ze_force_buy_item", "native_ze_force_buy_item")
  51.     register_native("ze_get_item_id", "native_ze_get_item_id")
  52.     register_native("ze_get_item_cost", "native_ze_get_item_cost")
  53.     register_native("ze_add_text_to_item", "native_ze_add_text_to_item")
  54.     register_native("ze_get_item_limit", "native_ze_get_item_limit")
  55.     register_native("ze_is_valid_itemid", "native_ze_is_valid_itemid")
  56.     register_native("ze_get_item_name", "native_ze_get_item_name")
  57.    
  58.     g_szItemRealName = ArrayCreate(32, 1)
  59.     g_szItemName = ArrayCreate(32, 1)
  60.     g_iItemCost = ArrayCreate(1, 1)
  61.     g_iItemLimit = ArrayCreate(1, 1)
  62. }
  63.  
  64. public ze_game_started()
  65. {
  66.     g_bBlockBuy = true
  67. }
  68.  
  69. public ze_zombie_release()
  70. {
  71.     g_bBlockBuy = false
  72. }
  73.  
  74. public client_disconnected(id)
  75. {
  76.     MENU_PAGE_ITEMS = 0
  77. }
  78.  
  79. public Cmd_Items(id)
  80. {
  81.     if (!is_user_alive(id))
  82.         return
  83.    
  84.     Show_Items_Menu(id)
  85. }
  86.  
  87. // Items Menu
  88. Show_Items_Menu(id)
  89. {
  90.     static menu[128], name[32], cost, transkey[64]
  91.     new menuid, index, itemdata[2]
  92.    
  93.     // Title
  94.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
  95.     menuid = menu_create(menu, "Extra_Items_Menu")
  96.    
  97.     // Item List
  98.     for (index = 0; index < g_iItemCount; index++)
  99.     {
  100.         // Additional text to display
  101.         g_szAdditionalMenuText[0] = 0
  102.        
  103.         // Execute item select attempt forward
  104.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
  105.        
  106.         // Show item to player?
  107.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW || g_bBlockBuy)
  108.             continue;
  109.        
  110.         // Add Item Name and Cost
  111.         ArrayGetString(g_szItemName, index, name, charsmax(name))
  112.         cost = ArrayGetCell(g_iItemCost, index)
  113.        
  114.         // ML support for item name
  115.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
  116.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
  117.        
  118.         // Item available to player?
  119.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  120.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
  121.         else
  122.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
  123.        
  124.         itemdata[0] = index
  125.         itemdata[1] = 0
  126.         menu_additem(menuid, menu, itemdata)
  127.     }
  128.    
  129.     // No items to display?
  130.     if (menu_items(menuid) <= 0)
  131.     {
  132.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
  133.         menu_destroy(menuid)
  134.         return;
  135.     }
  136.    
  137.     // Back - Next - Exit
  138.     formatex(menu, charsmax(menu), "%L", id, "BACK")
  139.     menu_setprop(menuid, MPROP_BACKNAME, menu)
  140.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
  141.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
  142.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
  143.     menu_setprop(menuid, MPROP_EXITNAME, menu)
  144.    
  145.     // If remembered page is greater than number of pages, clamp down the value
  146.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
  147.    
  148.     // Fix for AMXX custom menus
  149.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  150.     menu_display(id, menuid, MENU_PAGE_ITEMS)
  151. }
  152.  
  153. // Items Menu
  154. public Extra_Items_Menu(id, menuid, item)
  155. {
  156.     // Menu was closed
  157.     if (item == MENU_EXIT)
  158.     {
  159.         MENU_PAGE_ITEMS = 0
  160.         menu_destroy(menuid)
  161.         return PLUGIN_HANDLED;
  162.     }
  163.    
  164.     // Remember items menu page
  165.     MENU_PAGE_ITEMS = item / 7
  166.    
  167.     // Dead players are not allowed to buy items
  168.     if (!is_user_alive(id))
  169.     {
  170.         menu_destroy(menuid)
  171.         return PLUGIN_HANDLED;
  172.     }
  173.    
  174.     // Retrieve item id
  175.     new itemdata[2], dummy, itemid
  176.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
  177.     itemid = itemdata[0]
  178.    
  179.     // Attempt to buy the item
  180.     Buy_Item(id, itemid)
  181.     menu_destroy(menuid)
  182.     return PLUGIN_HANDLED;
  183. }
  184.  
  185. // Buy Item
  186. Buy_Item(id, itemid, ignorecost = 0)
  187. {
  188.     // Execute item select attempt forward
  189.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
  190.    
  191.     // Item available to player?
  192.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
  193.         return;
  194.    
  195.     // Execute item selected forward
  196.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
  197. }
  198.  
  199. // Natives
  200. public native_ze_register_item(plugin_id, num_params)
  201. {
  202.     new szItem_Name[32], iItem_Cost, iItem_Limit
  203.    
  204.     // Get the Data from first Parameter in the native (Item Name)
  205.     get_string(1, szItem_Name, charsmax(szItem_Name))
  206.    
  207.     // Get the Second Parameter (Item Cost)
  208.     iItem_Cost = get_param(2)
  209.    
  210.     // Get limit third parameter
  211.     iItem_Limit = get_param(3)
  212.    
  213.     if (strlen(szItem_Name) < 1)
  214.     {
  215.         // Can't leave item name empty
  216.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
  217.         return ZE_WRONG_ITEM // Same as return -1
  218.     }
  219.    
  220.     new iIndex, szItemName[32]
  221.    
  222.     // Loop from 0 to max items amount
  223.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
  224.     {
  225.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
  226.        
  227.         if (equali(szItem_Name, szItemName))
  228.         {
  229.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
  230.             return ZE_WRONG_ITEM; // Return -1
  231.         }
  232.     }
  233.    
  234.     // Load settings from extra items file
  235.     new szItemRealName[32]
  236.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
  237.     ArrayPushString(g_szItemRealName, szItemRealName)
  238.    
  239.     // Name
  240.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
  241.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
  242.     ArrayPushString(g_szItemName, szItem_Name)
  243.    
  244.     // Cost
  245.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
  246.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
  247.     ArrayPushCell(g_iItemCost, iItem_Cost)
  248.    
  249.     // Limit
  250.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
  251.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
  252.     ArrayPushCell(g_iItemLimit, iItem_Limit)
  253.    
  254.     g_iItemCount++
  255.     return g_iItemCount - 1
  256. }
  257.  
  258. public native_ze_show_items_menu(plugin_id, num_params)
  259. {
  260.     new id = get_param(1)
  261.    
  262.     if (!is_user_connected(id))
  263.     {
  264.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  265.         return false;
  266.     }
  267.    
  268.     Cmd_Items(id)
  269.     return true
  270. }
  271.  
  272. public native_ze_force_buy_item(plugin_id, num_params)
  273. {
  274.     new id = get_param(1)
  275.    
  276.     if (!is_user_connected(id))
  277.     {
  278.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
  279.         return false;
  280.     }
  281.    
  282.     new item_id = get_param(2)
  283.    
  284.     if (item_id < 0 || item_id >= g_iItemCount)
  285.     {
  286.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  287.         return false;
  288.     }
  289.    
  290.     new ignorecost = get_param(3)
  291.    
  292.     Buy_Item(id, item_id, ignorecost)
  293.     return true;
  294. }
  295.  
  296. public native_ze_get_item_id(plugin_id, num_params)
  297. {
  298.     new szRealName[32]
  299.     get_string(1, szRealName, charsmax(szRealName))
  300.  
  301.     new index, szItemName[32]
  302.    
  303.     for (index = 0; index < g_iItemCount; index++)
  304.     {
  305.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
  306.        
  307.         if (equali(szRealName, szItemName))
  308.             return index
  309.     }
  310.    
  311.     return ZE_WRONG_ITEM
  312. }
  313.  
  314. public native_ze_get_item_cost(plugin_id, num_params)
  315. {
  316.     new item_id = get_param(1)
  317.    
  318.     if (item_id < 0 || item_id >= g_iItemCount)
  319.     {
  320.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  321.         return ZE_WRONG_ITEM;
  322.     }
  323.    
  324.     return ArrayGetCell(g_iItemCost, item_id);
  325. }
  326.  
  327. public native_ze_add_text_to_item(plugin_id, num_params)
  328. {
  329.     new szText[32]
  330.     get_string(1, szText, charsmax(szText))
  331.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
  332. }
  333.  
  334. public native_ze_get_item_limit(plugin_id, num_params)
  335. {
  336.     new item_id = get_param(1)
  337.    
  338.     if (item_id < 0 || item_id >= g_iItemCount)
  339.     {
  340.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  341.         return ZE_WRONG_ITEM;
  342.     }
  343.    
  344.     return ArrayGetCell(g_iItemLimit, item_id);
  345. }
  346.  
  347. public native_ze_is_valid_itemid(plugin_id, num_params)
  348. {
  349.     new item_id = get_param(1)
  350.    
  351.     if (item_id < 0 || item_id >= g_iItemCount)
  352.     {
  353.         return false;
  354.     }
  355.    
  356.     return true;
  357. }
  358.  
  359. public native_ze_get_item_name(plugin_id, num_params)
  360. {
  361.     new item_id = get_param(1)
  362.    
  363.     if (item_id < 0 || item_id >= g_iItemCount)
  364.     {
  365.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
  366.         return ZE_WRONG_ITEM;
  367.     }
  368.    
  369.     new szName[32]
  370.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
  371.    
  372.     new iLen = get_param(3)
  373.     set_string(2, szName, iLen)
  374.     return true;
  375. }

OH, i found this topic: viewtopic.php?f=17&t=3208 also discussed how to block buying generally but with external plugin so no need for core files editing.
So this will block all extra items not the weapon menu?

nevermind i read the code and the answer is yes :D
This is what i really wanted not after zombie release but after zombie choosen
  1. public ze_game_started()
  2. {
  3.     g_bBlockBuy = true
  4. }
  5.  
  6. public ze_zombie_appear()
  7. {
  8.     g_bBlockBuy = false
  9. }
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