How to block item give and show message?

Helping Topics
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1793
Joined: 2 Years Ago
Location: Egypt
Has thanked: 31 times
Been thanked: 89 times
Age: 21
Contact:

How to block item give and show message?

#1

Post by Raheem » 9 Months Ago

Hello,

How we can block the give item code in ze_select_item_post() forward and show message. If you tried do something like:
    1. #include <zombie_escape>
    2.  
    3. // Default Sound
    4. new const g_szBuyAmmoSound[] = "items/9mmclip1.wav"
    5.  
    6. // Variables
    7. new g_iItemID
    8.  
    9. public plugin_init()
    10. {
    11.     register_plugin("[ZE] Items: Fire Nade", ZE_VERSION, AUTHORS)
    12.    
    13.     // Register our item
    14.     g_iItemID = ze_register_item("Frost Nade", 50, 0)
    15. }
    16.  
    17. public ze_select_item_pre(id, itemid)
    18. {
    19.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    20.     if (itemid != g_iItemID)
    21.         return ZE_ITEM_AVAILABLE
    22.    
    23.     // Available for Humans only, So don't show it for zombies
    24.     if (ze_is_user_zombie(id))
    25.         return ZE_ITEM_DONT_SHOW
    26.    
    27.     return ZE_ITEM_AVAILABLE
    28. }
    29.  
    30. public ze_select_item_post(id, itemid)
    31. {
    32.     // This is not our item, Block it here
    33.     if (itemid != g_iItemID)
    34.         return
    35.    
    36.     // Attempt to block the give item code, and show message
    37.     if (Anything)
    38.     {
    39.         show message here
    40.         return
    41.     }
    42.    
    43.     // Get Weapon ID
    44.     new iWpnID = get_weaponid("weapon_smokegrenade")
    45.    
    46.     // Player Don't have Frost Grenade then give him
    47.     if (rg_get_user_bpammo(id, WeaponIdType:iWpnID) == 0)
    48.     {
    49.         rg_give_item(id, "weapon_smokegrenade", GT_APPEND)
    50.     }
    51.     else
    52.     {
    53.         // Player have, Increase his Back Pack Ammo, And play buy BP sound + Hud Flash
    54.         rg_set_user_bpammo(id, WeaponIdType:iWpnID, rg_get_user_bpammo(id, WeaponIdType:iWpnID) + 1)
    55.         emit_sound(id, CHAN_ITEM, g_szBuyAmmoSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
    56.         Show_Given_BPAmmo(id, 13, 1) // Smoke Grenade AmmoType Const = 13
    57.     }
    58. }
It will not give the item, and will show the message but the problem is it will take coins from player. For this reason i'm writing this topic.
The idea is that in specific condition we must ignore the cost and show whatever we need.

First you will need to edit your ze_items_manager.sma to be like:
    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.     bool:g_bIgnoreCost[MAX_EXTRA_ITEMS],
    32.     bool:g_bSetUsed[MAX_EXTRA_ITEMS]
    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.     register_native("ze_set_ignorecost", "native_ze_set_ignorecost", 1)
    58.     register_native("ze_get_ignorecost", "native_ze_get_ignorecost", 1)
    59.    
    60.     g_szItemRealName = ArrayCreate(32, 1)
    61.     g_szItemName = ArrayCreate(32, 1)
    62.     g_iItemCost = ArrayCreate(1, 1)
    63.     g_iItemLimit = ArrayCreate(1, 1)
    64. }
    65.  
    66. public client_disconnected(id)
    67. {
    68.     MENU_PAGE_ITEMS = 0
    69. }
    70.  
    71. public Cmd_Items(id)
    72. {
    73.     if (!is_user_alive(id))
    74.         return
    75.    
    76.     Show_Items_Menu(id)
    77. }
    78.  
    79. // Items Menu
    80. Show_Items_Menu(id)
    81. {
    82.     static menu[128], name[32], cost, transkey[64]
    83.     new menuid, index, itemdata[2]
    84.    
    85.     // Title
    86.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
    87.     menuid = menu_create(menu, "Extra_Items_Menu")
    88.    
    89.     // Item List
    90.     for (index = 0; index < g_iItemCount; index++)
    91.     {
    92.         // Additional text to display
    93.         g_szAdditionalMenuText[0] = 0
    94.        
    95.         // Execute item select attempt forward
    96.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
    97.        
    98.         // Show item to player?
    99.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW)
    100.             continue;
    101.        
    102.         // Add Item Name and Cost
    103.         ArrayGetString(g_szItemName, index, name, charsmax(name))
    104.         cost = ArrayGetCell(g_iItemCost, index)
    105.        
    106.         // ML support for item name
    107.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
    108.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
    109.        
    110.         // Item available to player?
    111.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    112.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
    113.         else
    114.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
    115.        
    116.         itemdata[0] = index
    117.         itemdata[1] = 0
    118.         menu_additem(menuid, menu, itemdata)
    119.     }
    120.    
    121.     // No items to display?
    122.     if (menu_items(menuid) <= 0)
    123.     {
    124.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
    125.         menu_destroy(menuid)
    126.         return;
    127.     }
    128.    
    129.     // Back - Next - Exit
    130.     formatex(menu, charsmax(menu), "%L", id, "BACK")
    131.     menu_setprop(menuid, MPROP_BACKNAME, menu)
    132.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
    133.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
    134.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
    135.     menu_setprop(menuid, MPROP_EXITNAME, menu)
    136.    
    137.     // If remembered page is greater than number of pages, clamp down the value
    138.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
    139.    
    140.     // Fix for AMXX custom menus
    141.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    142.     menu_display(id, menuid, MENU_PAGE_ITEMS)
    143. }
    144.  
    145. // Items Menu
    146. public Extra_Items_Menu(id, menuid, item)
    147. {
    148.     // Menu was closed
    149.     if (item == MENU_EXIT)
    150.     {
    151.         MENU_PAGE_ITEMS = 0
    152.         menu_destroy(menuid)
    153.         return PLUGIN_HANDLED;
    154.     }
    155.    
    156.     // Remember items menu page
    157.     MENU_PAGE_ITEMS = item / 7
    158.    
    159.     // Dead players are not allowed to buy items
    160.     if (!is_user_alive(id))
    161.     {
    162.         menu_destroy(menuid)
    163.         return PLUGIN_HANDLED;
    164.     }
    165.    
    166.     // Retrieve item id
    167.     new itemdata[2], dummy, itemid
    168.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
    169.     itemid = itemdata[0]
    170.    
    171.     // Attempt to buy the item
    172.     Buy_Item(id, itemid)
    173.     menu_destroy(menuid)
    174.     return PLUGIN_HANDLED;
    175. }
    176.  
    177. // Buy Item
    178. Buy_Item(id, itemid, ignorecost = 0)
    179. {
    180.     if (g_bSetUsed[itemid])
    181.     {
    182.         ignorecost = g_bIgnoreCost[itemid]
    183.     }
    184.    
    185.     // Execute item select attempt forward
    186.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
    187.    
    188.     // Item available to player?
    189.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    190.         return;
    191.    
    192.     // Execute item selected forward
    193.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
    194. }
    195.  
    196. // Natives
    197. public native_ze_register_item(plugin_id, num_params)
    198. {
    199.     new szItem_Name[32], iItem_Cost, iItem_Limit
    200.    
    201.     // Get the Data from first Parameter in the native (Item Name)
    202.     get_string(1, szItem_Name, charsmax(szItem_Name))
    203.    
    204.     // Get the Second Parameter (Item Cost)
    205.     iItem_Cost = get_param(2)
    206.    
    207.     // Get limit third parameter
    208.     iItem_Limit = get_param(3)
    209.    
    210.     if (strlen(szItem_Name) < 1)
    211.     {
    212.         // Can't leave item name empty
    213.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
    214.         return ZE_WRONG_ITEM // Same as return -1
    215.     }
    216.    
    217.     new iIndex, szItemName[32]
    218.    
    219.     // Loop from 0 to max items amount
    220.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
    221.     {
    222.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
    223.        
    224.         if (equali(szItem_Name, szItemName))
    225.         {
    226.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
    227.             return ZE_WRONG_ITEM; // Return -1
    228.         }
    229.     }
    230.    
    231.     // Load settings from extra items file
    232.     new szItemRealName[32]
    233.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
    234.     ArrayPushString(g_szItemRealName, szItemRealName)
    235.    
    236.     // Name
    237.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
    238.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
    239.     ArrayPushString(g_szItemName, szItem_Name)
    240.    
    241.     // Cost
    242.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
    243.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
    244.     ArrayPushCell(g_iItemCost, iItem_Cost)
    245.    
    246.     // Limit
    247.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
    248.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
    249.     ArrayPushCell(g_iItemLimit, iItem_Limit)
    250.    
    251.     g_iItemCount++
    252.     return g_iItemCount - 1
    253. }
    254.  
    255. public native_ze_show_items_menu(plugin_id, num_params)
    256. {
    257.     new id = get_param(1)
    258.    
    259.     if (!is_user_connected(id))
    260.     {
    261.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    262.         return false;
    263.     }
    264.    
    265.     Cmd_Items(id)
    266.     return true
    267. }
    268.  
    269. public native_ze_force_buy_item(plugin_id, num_params)
    270. {
    271.     new id = get_param(1)
    272.    
    273.     if (!is_user_connected(id))
    274.     {
    275.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    276.         return false;
    277.     }
    278.    
    279.     new item_id = get_param(2)
    280.    
    281.     if (item_id < 0 || item_id >= g_iItemCount)
    282.     {
    283.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    284.         return false;
    285.     }
    286.    
    287.     new ignorecost = get_param(3)
    288.    
    289.     g_bIgnoreCost[item_id] = ignorecost;
    290.    
    291.     Buy_Item(id, item_id, ignorecost)
    292.     return true;
    293. }
    294.  
    295. public native_ze_get_item_id(plugin_id, num_params)
    296. {
    297.     new szRealName[32]
    298.     get_string(1, szRealName, charsmax(szRealName))
    299.  
    300.     new index, szItemName[32]
    301.    
    302.     for (index = 0; index < g_iItemCount; index++)
    303.     {
    304.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
    305.        
    306.         if (equali(szRealName, szItemName))
    307.             return index
    308.     }
    309.    
    310.     return ZE_WRONG_ITEM
    311. }
    312.  
    313. public native_ze_get_item_cost(plugin_id, num_params)
    314. {
    315.     new item_id = get_param(1)
    316.    
    317.     if (item_id < 0 || item_id >= g_iItemCount)
    318.     {
    319.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    320.         return ZE_WRONG_ITEM;
    321.     }
    322.    
    323.     return ArrayGetCell(g_iItemCost, item_id);
    324. }
    325.  
    326. public native_ze_add_text_to_item(plugin_id, num_params)
    327. {
    328.     new szText[32]
    329.     get_string(1, szText, charsmax(szText))
    330.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
    331. }
    332.  
    333. public native_ze_get_item_limit(plugin_id, num_params)
    334. {
    335.     new item_id = get_param(1)
    336.    
    337.     if (item_id < 0 || item_id >= g_iItemCount)
    338.     {
    339.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    340.         return ZE_WRONG_ITEM;
    341.     }
    342.    
    343.     return ArrayGetCell(g_iItemLimit, item_id);
    344. }
    345.  
    346. public native_ze_is_valid_itemid(plugin_id, num_params)
    347. {
    348.     new item_id = get_param(1)
    349.    
    350.     if (item_id < 0 || item_id >= g_iItemCount)
    351.     {
    352.         return false;
    353.     }
    354.    
    355.     return true;
    356. }
    357.  
    358. public native_ze_get_item_name(plugin_id, num_params)
    359. {
    360.     new item_id = get_param(1)
    361.    
    362.     if (item_id < 0 || item_id >= g_iItemCount)
    363.     {
    364.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    365.         return ZE_WRONG_ITEM;
    366.     }
    367.    
    368.     new szName[32]
    369.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
    370.    
    371.     new iLen = get_param(3)
    372.     set_string(2, szName, iLen)
    373.     return true;
    374. }
    375.  
    376. public native_ze_set_ignorecost(iItemid, bool:bSet)
    377. {
    378.     g_bSetUsed[iItemid] = true;
    379.     g_bIgnoreCost[iItemid] = bSet;
    380. }
    381.  
    382. public native_ze_get_ignorecost(iItemid)
    383. {
    384.     return g_bIgnoreCost[iItemid];
    385. }
I just added two natives, we will use ze_set_ignorecost(iItemid, bool:bSet) so we ignore the cost in some cases.

Example: In the Weapons Ammo extra item we need to block user from buying weapon ammo for knife and grenades and show a message that he can't buy when he holding knife or grenades.

We will do the check in two places, in the pre buy we will check if he carry knife/grenades we will set ignorecost to true. Then in the post buy we will check again same conditions and if he holding knife/grenades we will show message and return.

Here is the final code:
    1. #include <zombie_escape>
    2.  
    3. native ze_set_ignorecost(iItemid, bool:bSet)
    4.  
    5. new const g_iClipSize[] =
    6. {
    7.     0,
    8.     13,  //CSW_P228
    9.     0,
    10.     10,  //CSW_SCOUT
    11.     0,   //CSW_HEGRENADE
    12.     7,   //CSW_XM1014
    13.     0,   //CSW_C4
    14.     30,  //CSW_MAC10
    15.     30,  //CSW_AUG
    16.     0,   //CSW_SMOKEGRENADE
    17.     30,  //CSW_ELITE
    18.     20,  //CSW_FIVESEVEN
    19.     25,  //CSW_UMP45
    20.     30,  //CSW_SG550
    21.     35,  //CSW_GALIL
    22.     25,  //CSW_FAMAS
    23.     12,  //CSW_USP
    24.     20,  //CSW_GLOCK18
    25.     10,  //CSW_AWP
    26.     30,  //CSW_MP5NAVY
    27.     100, //CSW_M249
    28.     8,   //CSW_M3
    29.     30,  //CSW_M4A1
    30.     30,  //CSW_TMP
    31.     20,  //CSW_G3SG1
    32.     0,   //CSW_FLASHBANG
    33.     7,   //CSW_DEAGLE
    34.     30,  //CSW_SG552
    35.     30,  //CSW_AK47
    36.     0,   //CSW_KNIFE
    37.     50   //CSW_P90
    38. }
    39.  
    40. new const g_iAmmoType[] =
    41. {
    42.     0,
    43.     9,  //CSW_P228
    44.     0,
    45.     2,  //CSW_SCOUT
    46.     12, //CSW_HEGRENADE
    47.     5,  //CSW_XM1014
    48.     14, //CSW_C4
    49.     6,  //CSW_MAC10
    50.     4,  //CSW_AUG
    51.     13, //CSW_SMOKEGRENADE
    52.     10, //CSW_ELITE
    53.     7,  //CSW_FIVESEVEN
    54.     6,  //CSW_UMP45
    55.     4,  //CSW_SG550
    56.     4,  //CSW_GALIL
    57.     4,  //CSW_FAMAS
    58.     6,  //CSW_USP
    59.     10, //CSW_GLOCK18
    60.     1,  //CSW_AWP
    61.     10, //CSW_MP5NAVY
    62.     3,  //CSW_M249
    63.     5,  //CSW_M3
    64.     4,  //CSW_M4A1
    65.     10, //CSW_TMP
    66.     2,  //CSW_G3SG1
    67.     11, //CSW_FLASHBANG
    68.     8,  //CSW_DEAGLE
    69.     4,  //CSW_SG552
    70.     2,  //CSW_AK47
    71.     0,  //CSW_KNIFE
    72.     7   //CSW_P90
    73. }
    74.  
    75. // Default Sound
    76. new const g_szBuyAmmoSound[] = "items/9mmclip1.wav"
    77.  
    78. // Variables
    79. new g_iItemID
    80.  
    81. public plugin_init()
    82. {
    83.     register_plugin("[ZE] Items: Weapon Ammo", ZE_VERSION, AUTHORS)
    84.    
    85.     // Register our item
    86.     g_iItemID = ze_register_item("Weapon Ammo", 5, 0)
    87. }
    88.  
    89. public ze_select_item_pre(id, itemid)
    90. {
    91.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    92.     if (itemid != g_iItemID)
    93.         return ZE_ITEM_AVAILABLE
    94.    
    95.     // Available for Humans only, So don't show it for zombies
    96.     if (ze_is_user_zombie(id))
    97.         return ZE_ITEM_DONT_SHOW
    98.    
    99.     // Itemid is our item?
    100.     if (itemid == g_iItemID)
    101.     {
    102.         // Get Weapon ID
    103.         new iWpnID, iAmmo
    104.         iWpnID = get_user_weapon(id, _, iAmmo)
    105.        
    106.         //  Here if player weapon is any of this we will ignore cost, so we can show message in post and no coins reduced from player
    107.         if (iWpnID == CSW_KNIFE || iWpnID == CSW_FLASHBANG || iWpnID == CSW_HEGRENADE || iWpnID == CSW_SMOKEGRENADE)
    108.         {
    109.             ze_set_ignorecost(g_iItemID, true)
    110.         }
    111.         else
    112.         {
    113.             // If not don't ignore cost - normal proccess
    114.             ze_set_ignorecost(g_iItemID, false)
    115.         }
    116.     }
    117.    
    118.     return ZE_ITEM_AVAILABLE
    119. }
    120.  
    121. public ze_select_item_post(id, itemid)
    122. {
    123.     // This is not our item, Block it here
    124.     if (itemid != g_iItemID)
    125.         return
    126.    
    127.     // Get Weapon ID
    128.     new iWpnID, iAmmo
    129.     iWpnID = get_user_weapon(id, _, iAmmo)
    130.    
    131.     // Here we send any messages, and use return to block item give and no coins will be reduced as we ignored cost in this case
    132.     if (iWpnID == CSW_KNIFE)
    133.     {
    134.         ze_colored_print(id, "!tYou can't buy ammo for knife!y!")
    135.         return
    136.     }
    137.  
    138.     if (iWpnID == CSW_FLASHBANG || iWpnID == CSW_HEGRENADE || iWpnID == CSW_SMOKEGRENADE)
    139.     {
    140.         ze_colored_print(id, "!tYou can't buy ammo for grenades!y!")
    141.         return
    142.     }
    143.  
    144.     // Increase his Back Pack Ammo, And play buy BP sound + Hud Flash
    145.     rg_set_user_bpammo(id, WeaponIdType:iWpnID, iAmmo + g_iClipSize[iWpnID])
    146.     emit_sound(id, CHAN_ITEM, g_szBuyAmmoSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
    147.     Show_Given_BPAmmo(id, g_iAmmoType[iWpnID], g_iClipSize[iWpnID])
    148. }
So in general the idea is:
  1. You need to ignorecost in ze_select_item_pre() in specific condition
  2. In ze_select_item_post() you will block whatever you need in same specific condition as pre.
So all what we did in fact is a block of coins deduction, player does not get the item so why we reduce his coins? so this is the right way to post a message in the post buy forward.

A general example:
    1. #include <zombie_escape>
    2.  
    3. // Default Sound
    4. new const g_szBuyAmmoSound[] = "items/9mmclip1.wav"
    5.  
    6. // Variables
    7. new g_iItemID
    8.  
    9. public plugin_init()
    10. {
    11.     register_plugin("[ZE] Items: Fire Nade", ZE_VERSION, AUTHORS)
    12.    
    13.     // Register our item
    14.     g_iItemID = ze_register_item("Frost Nade", 50, 0)
    15. }
    16.  
    17. public ze_select_item_pre(id, itemid)
    18. {
    19.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    20.     if (itemid != g_iItemID)
    21.         return ZE_ITEM_AVAILABLE
    22.    
    23.     // Verify first it's our item
    24.     if (itemid == g_iItemID)
    25.     {
    26.         if (Your condition == true)
    27.         {
    28.             // Ignore the cost
    29.             ze_set_ignorecost(g_iItemID, true)
    30.         }
    31.         else
    32.         {
    33.             // Here your condition not true, so we will not ignore the cost
    34.             ze_set_ignorecost(g_iItemID, false)
    35.         }
    36.     }
    37.    
    38.     // Available for Humans only, So don't show it for zombies
    39.     if (ze_is_user_zombie(id))
    40.         return ZE_ITEM_DONT_SHOW
    41.    
    42.     return ZE_ITEM_AVAILABLE
    43. }
    44.  
    45. public ze_select_item_post(id, itemid)
    46. {
    47.     // This is not our item, Block it here
    48.     if (itemid != g_iItemID)
    49.         return
    50.    
    51.     // Attempt to block the give item code, and show message
    52.     if (Your condition == true)
    53.     {
    54.         // This is the right way
    55.         show message here
    56.         return
    57.     }
    58.    
    59.     // Get Weapon ID
    60.     new iWpnID = get_weaponid("weapon_smokegrenade")
    61.    
    62.     // Player Don't have Frost Grenade then give him
    63.     if (rg_get_user_bpammo(id, WeaponIdType:iWpnID) == 0)
    64.     {
    65.         rg_give_item(id, "weapon_smokegrenade", GT_APPEND)
    66.     }
    67.     else
    68.     {
    69.         // Player have, Increase his Back Pack Ammo, And play buy BP sound + Hud Flash
    70.         rg_set_user_bpammo(id, WeaponIdType:iWpnID, rg_get_user_bpammo(id, WeaponIdType:iWpnID) + 1)
    71.         emit_sound(id, CHAN_ITEM, g_szBuyAmmoSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
    72.         Show_Given_BPAmmo(id, 13, 1) // Smoke Grenade AmmoType Const = 13
    73.     }
    74. }]
You don't know? Learn and you will know.

User avatar
th3_king
VIP
VIP
Egypt
Posts: 33
Joined: 2 Years Ago
Location: Egypt
Has thanked: 9 times
Been thanked: 2 times
Age: 16
Contact:

#2

Post by th3_king » 9 Months Ago

Good Job :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest