Available Vip extra Item Discounts

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

#11

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Try now: viewtopic.php?p=8362#p8362
  1. //// ze_items_manager.sma
  2. //
  3. // C:\Users\marcu\Desktop\Compiler v1.8.3\Compiler v1.8.3\scripting\ze_items_manager.sma(385) : warning 213: tag mismatch
  4. // Header size:           2044 bytes
  5. // Code size:            11748 bytes
  6. // Data size:             9172 bytes
  7. // Stack/heap size:      16384 bytes
  8. // Total requirements:   39348 bytes
  9. //
  10. // 1 Warning.
  11. // Done.
  12. //
  13. // Compilation Time: 0.67 sec
  14. // ----------------------------------------
  1. //// ze_items_escape_coins.sma
  2. //
  3. // C:\Users\marcu\Desktop\Compiler v1.8.3\Compiler v1.8.3\scripting\ze_items_escape_coins.sma(24) : warning 213: tag mismatch
  4. // C:\Users\marcu\Desktop\Compiler v1.8.3\Compiler v1.8.3\scripting\ze_items_escape_coins.sma(46) : warning 213: tag mismatch
  5. // Header size:            824 bytes
  6. // Code size:             1844 bytes
  7. // Data size:              764 bytes
  8. // Stack/heap size:      16384 bytes
  9. // Total requirements:   19816 bytes
  10. //
  11. // 2 Warnings.
  12. // Done.
  13. //
  14. // Compilation Time: 0.64 sec
  15. // ----------------------------------------

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

#12

Post by Raheem » 5 years ago

Wait

Edit: Try now viewtopic.php?p=8362#p8362
He who fails to plan is planning to fail

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

#13

Post by Raheem » 5 years ago

Try with this and tell me what printed when you choose this item:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    25.     }
    26.     else
    27.     {
    28.         g_iRequiredEC = ze_get_item_cost(itemid)
    29.     }
    30.    
    31.     if (g_iCurrentEC < g_iRequiredEC)
    32.         return ZE_ITEM_UNAVAILABLE
    33.    
    34.     return ZE_ITEM_AVAILABLE
    35. }
    36.  
    37. public ze_select_item_post(id, itemid, ignorecost)
    38. {
    39.     if (ignorecost)
    40.         return
    41.    
    42.     g_iCurrentEC = ze_get_escape_coins(id)
    43.    
    44.     client_print(0, print_chat, "%i", ze_has_vip_discount(itemid))
    45.     client_print(0, print_chat, "%f", ze_get_item_discount(itemid))
    46.    
    47.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    48.     {
    49.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    50.     }
    51.     else
    52.     {
    53.         g_iRequiredEC = ze_get_item_cost(itemid)
    54.     }
    55.    
    56.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    57. }
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:

#14

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Try with this and tell me what printed when you choose this item:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    25.     }
    26.     else
    27.     {
    28.         g_iRequiredEC = ze_get_item_cost(itemid)
    29.     }
    30.    
    31.     if (g_iCurrentEC < g_iRequiredEC)
    32.         return ZE_ITEM_UNAVAILABLE
    33.    
    34.     return ZE_ITEM_AVAILABLE
    35. }
    36.  
    37. public ze_select_item_post(id, itemid, ignorecost)
    38. {
    39.     if (ignorecost)
    40.         return
    41.    
    42.     g_iCurrentEC = ze_get_escape_coins(id)
    43.    
    44.     client_print(0, print_chat, "%i", ze_has_vip_discount(itemid))
    45.     client_print(0, print_chat, "%f", ze_get_item_discount(itemid))
    46.    
    47.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    48.     {
    49.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    50.     }
    51.     else
    52.     {
    53.         g_iRequiredEC = ze_get_item_cost(itemid)
    54.     }
    55.    
    56.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    57. }
Here
20180915211736_1.jpg

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

#15

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Try now: viewtopic.php?p=8362#p8362
Well shit you did it!

20180915212854_1.jpg

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

#16

Post by Raheem » 5 years ago

Let's finish it... Try with text ADDED:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(ze_get_item_discount(itemid) * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else
    31.     {
    32.         g_iRequiredEC = ze_get_item_cost(itemid)
    33.     }
    34.    
    35.     if (g_iCurrentEC < g_iRequiredEC)
    36.         return ZE_ITEM_UNAVAILABLE
    37.    
    38.     return ZE_ITEM_AVAILABLE
    39. }
    40.  
    41. public ze_select_item_post(id, itemid, ignorecost)
    42. {
    43.     if (ignorecost)
    44.         return
    45.    
    46.     g_iCurrentEC = ze_get_escape_coins(id)
    47.    
    48.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    49.     {
    50.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    51.     }
    52.     else
    53.     {
    54.         g_iRequiredEC = ze_get_item_cost(itemid)
    55.     }
    56.    
    57.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    58. }
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:

#17

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Let's finish it... Try with text ADDED:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(ze_get_item_discount(itemid) * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else
    31.     {
    32.         g_iRequiredEC = ze_get_item_cost(itemid)
    33.     }
    34.    
    35.     if (g_iCurrentEC < g_iRequiredEC)
    36.         return ZE_ITEM_UNAVAILABLE
    37.    
    38.     return ZE_ITEM_AVAILABLE
    39. }
    40.  
    41. public ze_select_item_post(id, itemid, ignorecost)
    42. {
    43.     if (ignorecost)
    44.         return
    45.    
    46.     g_iCurrentEC = ze_get_escape_coins(id)
    47.    
    48.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    49.     {
    50.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid)) // 50 % discount
    51.     }
    52.     else
    53.     {
    54.         g_iRequiredEC = ze_get_item_cost(itemid)
    55.     }
    56.    
    57.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    58. }
Yep works!

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

#18

Post by Raheem » 5 years ago

Can you post a pic for the text? :D
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:

#19

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Can you post a pic for the text? :D
I put a some spaces so it looked better but here.
20180915215551_1.jpg

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

#20

Post by Raheem » 5 years ago

So if anyone need to add discount for VIPs on any item he should follow the following:

1. Update your ze_items_manager.sma with:
    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_bHasDiscount[MAX_EXTRA_ITEMS],
    32.     Float:g_flDiscountValue[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_vip_discount", "native_ze_set_vip_discount", 1)
    58.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    59.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    60.     register_native("ze_get_item_discount", "native_ze_get_item_discount", 1)
    61.    
    62.     g_szItemRealName = ArrayCreate(32, 1)
    63.     g_szItemName = ArrayCreate(32, 1)
    64.     g_iItemCost = ArrayCreate(1, 1)
    65.     g_iItemLimit = ArrayCreate(1, 1)
    66. }
    67.  
    68. public client_disconnected(id)
    69. {
    70.     MENU_PAGE_ITEMS = 0
    71. }
    72.  
    73. public Cmd_Items(id)
    74. {
    75.     if (!is_user_alive(id))
    76.         return
    77.    
    78.     Show_Items_Menu(id)
    79. }
    80.  
    81. // Items Menu
    82. Show_Items_Menu(id)
    83. {
    84.     static menu[128], name[32], cost, transkey[64]
    85.     new menuid, index, itemdata[2]
    86.    
    87.     // Title
    88.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
    89.     menuid = menu_create(menu, "Extra_Items_Menu")
    90.    
    91.     // Item List
    92.     for (index = 0; index < g_iItemCount; index++)
    93.     {
    94.         // Additional text to display
    95.         g_szAdditionalMenuText[0] = 0
    96.        
    97.         // Execute item select attempt forward
    98.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
    99.        
    100.         // Show item to player?
    101.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW)
    102.             continue;
    103.        
    104.         // Add Item Name and Cost
    105.         ArrayGetString(g_szItemName, index, name, charsmax(name))
    106.         cost = ArrayGetCell(g_iItemCost, index)
    107.        
    108.         // ML support for item name
    109.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
    110.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
    111.        
    112.         // Item available to player?
    113.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    114.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
    115.         else
    116.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
    117.        
    118.         itemdata[0] = index
    119.         itemdata[1] = 0
    120.         menu_additem(menuid, menu, itemdata)
    121.     }
    122.    
    123.     // No items to display?
    124.     if (menu_items(menuid) <= 0)
    125.     {
    126.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
    127.         menu_destroy(menuid)
    128.         return;
    129.     }
    130.    
    131.     // Back - Next - Exit
    132.     formatex(menu, charsmax(menu), "%L", id, "BACK")
    133.     menu_setprop(menuid, MPROP_BACKNAME, menu)
    134.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
    135.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
    136.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
    137.     menu_setprop(menuid, MPROP_EXITNAME, menu)
    138.    
    139.     // If remembered page is greater than number of pages, clamp down the value
    140.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
    141.    
    142.     // Fix for AMXX custom menus
    143.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    144.     menu_display(id, menuid, MENU_PAGE_ITEMS)
    145. }
    146.  
    147. // Items Menu
    148. public Extra_Items_Menu(id, menuid, item)
    149. {
    150.     // Menu was closed
    151.     if (item == MENU_EXIT)
    152.     {
    153.         MENU_PAGE_ITEMS = 0
    154.         menu_destroy(menuid)
    155.         return PLUGIN_HANDLED;
    156.     }
    157.    
    158.     // Remember items menu page
    159.     MENU_PAGE_ITEMS = item / 7
    160.    
    161.     // Dead players are not allowed to buy items
    162.     if (!is_user_alive(id))
    163.     {
    164.         menu_destroy(menuid)
    165.         return PLUGIN_HANDLED;
    166.     }
    167.    
    168.     // Retrieve item id
    169.     new itemdata[2], dummy, itemid
    170.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
    171.     itemid = itemdata[0]
    172.    
    173.     // Attempt to buy the item
    174.     Buy_Item(id, itemid)
    175.     menu_destroy(menuid)
    176.     return PLUGIN_HANDLED;
    177. }
    178.  
    179. // Buy Item
    180. Buy_Item(id, itemid, ignorecost = 0)
    181. {
    182.     // Execute item select attempt forward
    183.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
    184.    
    185.     // Item available to player?
    186.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    187.         return;
    188.    
    189.     // Execute item selected forward
    190.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
    191. }
    192.  
    193. // Natives
    194. public native_ze_register_item(plugin_id, num_params)
    195. {
    196.     new szItem_Name[32], iItem_Cost, iItem_Limit
    197.    
    198.     // Get the Data from first Parameter in the native (Item Name)
    199.     get_string(1, szItem_Name, charsmax(szItem_Name))
    200.    
    201.     // Get the Second Parameter (Item Cost)
    202.     iItem_Cost = get_param(2)
    203.    
    204.     // Get limit third parameter
    205.     iItem_Limit = get_param(3)
    206.    
    207.     if (strlen(szItem_Name) < 1)
    208.     {
    209.         // Can't leave item name empty
    210.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
    211.         return ZE_WRONG_ITEM // Same as return -1
    212.     }
    213.    
    214.     new iIndex, szItemName[32]
    215.    
    216.     // Loop from 0 to max items amount
    217.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
    218.     {
    219.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
    220.        
    221.         if (equali(szItem_Name, szItemName))
    222.         {
    223.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
    224.             return ZE_WRONG_ITEM; // Return -1
    225.         }
    226.     }
    227.    
    228.     // Load settings from extra items file
    229.     new szItemRealName[32]
    230.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
    231.     ArrayPushString(g_szItemRealName, szItemRealName)
    232.    
    233.     // Name
    234.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
    235.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
    236.     ArrayPushString(g_szItemName, szItem_Name)
    237.    
    238.     // Cost
    239.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
    240.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
    241.     ArrayPushCell(g_iItemCost, iItem_Cost)
    242.    
    243.     // Limit
    244.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
    245.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
    246.     ArrayPushCell(g_iItemLimit, iItem_Limit)
    247.    
    248.     g_iItemCount++
    249.     return g_iItemCount - 1
    250. }
    251.  
    252. public native_ze_show_items_menu(plugin_id, num_params)
    253. {
    254.     new id = get_param(1)
    255.    
    256.     if (!is_user_connected(id))
    257.     {
    258.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    259.         return false;
    260.     }
    261.    
    262.     Cmd_Items(id)
    263.     return true
    264. }
    265.  
    266. public native_ze_force_buy_item(plugin_id, num_params)
    267. {
    268.     new id = get_param(1)
    269.    
    270.     if (!is_user_connected(id))
    271.     {
    272.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    273.         return false;
    274.     }
    275.    
    276.     new item_id = get_param(2)
    277.    
    278.     if (item_id < 0 || item_id >= g_iItemCount)
    279.     {
    280.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    281.         return false;
    282.     }
    283.    
    284.     new ignorecost = get_param(3)
    285.    
    286.     Buy_Item(id, item_id, ignorecost)
    287.     return true;
    288. }
    289.  
    290. public native_ze_get_item_id(plugin_id, num_params)
    291. {
    292.     new szRealName[32]
    293.     get_string(1, szRealName, charsmax(szRealName))
    294.  
    295.     new index, szItemName[32]
    296.    
    297.     for (index = 0; index < g_iItemCount; index++)
    298.     {
    299.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
    300.        
    301.         if (equali(szRealName, szItemName))
    302.             return index
    303.     }
    304.    
    305.     return ZE_WRONG_ITEM
    306. }
    307.  
    308. public native_ze_get_item_cost(plugin_id, num_params)
    309. {
    310.     new item_id = get_param(1)
    311.    
    312.     if (item_id < 0 || item_id >= g_iItemCount)
    313.     {
    314.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    315.         return ZE_WRONG_ITEM;
    316.     }
    317.    
    318.     return ArrayGetCell(g_iItemCost, item_id);
    319. }
    320.  
    321. public native_ze_add_text_to_item(plugin_id, num_params)
    322. {
    323.     new szText[32]
    324.     get_string(1, szText, charsmax(szText))
    325.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
    326. }
    327.  
    328. public native_ze_get_item_limit(plugin_id, num_params)
    329. {
    330.     new item_id = get_param(1)
    331.    
    332.     if (item_id < 0 || item_id >= g_iItemCount)
    333.     {
    334.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    335.         return ZE_WRONG_ITEM;
    336.     }
    337.    
    338.     return ArrayGetCell(g_iItemLimit, item_id);
    339. }
    340.  
    341. public native_ze_is_valid_itemid(plugin_id, num_params)
    342. {
    343.     new item_id = get_param(1)
    344.    
    345.     if (item_id < 0 || item_id >= g_iItemCount)
    346.     {
    347.         return false;
    348.     }
    349.    
    350.     return true;
    351. }
    352.  
    353. public native_ze_get_item_name(plugin_id, num_params)
    354. {
    355.     new item_id = get_param(1)
    356.    
    357.     if (item_id < 0 || item_id >= g_iItemCount)
    358.     {
    359.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    360.         return ZE_WRONG_ITEM;
    361.     }
    362.    
    363.     new szName[32]
    364.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
    365.    
    366.     new iLen = get_param(3)
    367.     set_string(2, szName, iLen)
    368.     return true;
    369. }
    370.  
    371. public native_ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount)
    372. {
    373.     g_bHasDiscount[iItemid] = bSet;
    374.     g_flDiscountValue[iItemid] = flDiscount;
    375. }
    376.  
    377. public native_ze_has_vip_discount(iItemid)
    378. {
    379.     return g_bHasDiscount[iItemid]
    380. }
    381.  
    382. public Float:native_ze_get_item_discount(iItemid)
    383. {
    384.     return g_flDiscountValue[iItemid]
    385. }
2. Update your ze_items_escape_coins.sma with:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - ze_get_item_discount(itemid)))
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(ze_get_item_discount(itemid) * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else
    31.     {
    32.         g_iRequiredEC = ze_get_item_cost(itemid)
    33.     }
    34.    
    35.     if (g_iCurrentEC < g_iRequiredEC)
    36.         return ZE_ITEM_UNAVAILABLE
    37.    
    38.     return ZE_ITEM_AVAILABLE
    39. }
    40.  
    41. public ze_select_item_post(id, itemid, ignorecost)
    42. {
    43.     if (ignorecost)
    44.         return
    45.    
    46.     g_iCurrentEC = ze_get_escape_coins(id)
    47.    
    48.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    49.     {
    50.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - ze_get_item_discount(itemid)))
    51.     }
    52.     else
    53.     {
    54.         g_iRequiredEC = ze_get_item_cost(itemid)
    55.     }
    56.    
    57.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    58. }
Now to add discount to any item for VIPs you will need to use this native:
  • bSet - set discount to this item or not. Make it true.
  • flDiscount - from 0 to 1, to make discount 10% use 0.1 to make 80 % use 0.8 and so on.
Now let's make 40 % discount on Fire nades for VIPs:
    1. #include <zombie_escape>
    2.  
    3. native ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount);
    4.  
    5. // Default Sound
    6. new const g_szBuyAmmoSound[] = "items/9mmclip1.wav"
    7.  
    8. // Variables
    9. new g_iItemID
    10.  
    11. public plugin_init()
    12. {
    13.     register_plugin("[ZE] Items: Fire Nade", ZE_VERSION, AUTHORS)
    14.    
    15.     // Register our item
    16.     g_iItemID = ze_register_item("Fire Nade", 30, 0)
    17.     ze_set_vip_discount(g_iItemID, true, 0.4)
    18. }
    19.  
    20. public ze_select_item_pre(id, itemid)
    21. {
    22.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    23.     if (itemid != g_iItemID)
    24.         return ZE_ITEM_AVAILABLE
    25.    
    26.     // Available for Humans only, So don't show it for zombies
    27.     if (ze_is_user_zombie(id))
    28.         return ZE_ITEM_DONT_SHOW
    29.    
    30.     return ZE_ITEM_AVAILABLE
    31. }
    32.  
    33. public ze_select_item_post(id, itemid)
    34. {
    35.     // This is not our item, Block it here
    36.     if (itemid != g_iItemID)
    37.         return
    38.    
    39.     // Get Weapon ID
    40.     new iWpnID = get_weaponid("weapon_hegrenade")
    41.    
    42.     // Player Don't have Frost Grenade then give him
    43.     if (rg_get_user_bpammo(id, WeaponIdType:iWpnID) == 0)
    44.     {
    45.         rg_give_item(id, "weapon_hegrenade", GT_APPEND)
    46.     }
    47.     else
    48.     {
    49.         // Player have, Increase his Back Pack Ammo, And play buy BP sound + Hud Flash
    50.         rg_set_user_bpammo(id, WeaponIdType:iWpnID, rg_get_user_bpammo(id, WeaponIdType:iWpnID) + 1)
    51.         emit_sound(id, CHAN_ITEM, g_szBuyAmmoSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
    52.         Show_Given_BPAmmo(id, 12, 1) // HE Grenade AmmoType Const = 12
    53.     }
    54. }
Just added ze_set_vip_discount(g_iItemID, true, 0.4) under g_iItemID = ze_register_item("Fire Nade", 30, 0).

Important: You must run latest VIP System in order this to run!
Last edited by Raheem 5 years ago, edited 1 time in total.
Reason: Updated
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:

#21

Post by Mark » 5 years ago

Raheem wrote: 5 years ago So if anyone need to add discount for VIPs on any item he should follow the following:

1. Update your ze_items_manager.sma with:
    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_bHasDiscount[MAX_EXTRA_ITEMS],
    32.     Float:g_flDiscountValue[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_vip_discount", "native_ze_set_vip_discount", 1)
    58.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    59.     register_native("ze_has_vip_discount", "native_ze_has_vip_discount", 1)
    60.     register_native("ze_get_item_discount", "native_ze_get_item_discount", 1)
    61.    
    62.     g_szItemRealName = ArrayCreate(32, 1)
    63.     g_szItemName = ArrayCreate(32, 1)
    64.     g_iItemCost = ArrayCreate(1, 1)
    65.     g_iItemLimit = ArrayCreate(1, 1)
    66. }
    67.  
    68. public client_disconnected(id)
    69. {
    70.     MENU_PAGE_ITEMS = 0
    71. }
    72.  
    73. public Cmd_Items(id)
    74. {
    75.     if (!is_user_alive(id))
    76.         return
    77.    
    78.     Show_Items_Menu(id)
    79. }
    80.  
    81. // Items Menu
    82. Show_Items_Menu(id)
    83. {
    84.     static menu[128], name[32], cost, transkey[64]
    85.     new menuid, index, itemdata[2]
    86.    
    87.     // Title
    88.     formatex(menu, charsmax(menu), "%L:\r", id, "BUY_EXTRAITEM")
    89.     menuid = menu_create(menu, "Extra_Items_Menu")
    90.    
    91.     // Item List
    92.     for (index = 0; index < g_iItemCount; index++)
    93.     {
    94.         // Additional text to display
    95.         g_szAdditionalMenuText[0] = 0
    96.        
    97.         // Execute item select attempt forward
    98.         ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, index, 0)
    99.        
    100.         // Show item to player?
    101.         if (g_iForwardReturn >= ZE_ITEM_DONT_SHOW)
    102.             continue;
    103.        
    104.         // Add Item Name and Cost
    105.         ArrayGetString(g_szItemName, index, name, charsmax(name))
    106.         cost = ArrayGetCell(g_iItemCost, index)
    107.        
    108.         // ML support for item name
    109.         formatex(transkey, charsmax(transkey), "ITEMNAME %s", name)
    110.         if (GetLangTransKey(transkey) != TransKey_Bad) formatex(name, charsmax(name), "%L", id, transkey)
    111.        
    112.         // Item available to player?
    113.         if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    114.             formatex(menu, charsmax(menu), "\d%s %d %s", name, cost, g_szAdditionalMenuText)
    115.         else
    116.             formatex(menu, charsmax(menu), "%s \y%d \w%s", name, cost, g_szAdditionalMenuText)
    117.        
    118.         itemdata[0] = index
    119.         itemdata[1] = 0
    120.         menu_additem(menuid, menu, itemdata)
    121.     }
    122.    
    123.     // No items to display?
    124.     if (menu_items(menuid) <= 0)
    125.     {
    126.         ze_colored_print(id, "%L", id, "NO_EXTRA_ITEMS")
    127.         menu_destroy(menuid)
    128.         return;
    129.     }
    130.    
    131.     // Back - Next - Exit
    132.     formatex(menu, charsmax(menu), "%L", id, "BACK")
    133.     menu_setprop(menuid, MPROP_BACKNAME, menu)
    134.     formatex(menu, charsmax(menu), "%L", id, "NEXT")
    135.     menu_setprop(menuid, MPROP_NEXTNAME, menu)
    136.     formatex(menu, charsmax(menu), "%L", id, "EXIT")
    137.     menu_setprop(menuid, MPROP_EXITNAME, menu)
    138.    
    139.     // If remembered page is greater than number of pages, clamp down the value
    140.     MENU_PAGE_ITEMS = min(MENU_PAGE_ITEMS, menu_pages(menuid)-1)
    141.    
    142.     // Fix for AMXX custom menus
    143.     set_pdata_int(id, OFFSET_CSMENUCODE, 0)
    144.     menu_display(id, menuid, MENU_PAGE_ITEMS)
    145. }
    146.  
    147. // Items Menu
    148. public Extra_Items_Menu(id, menuid, item)
    149. {
    150.     // Menu was closed
    151.     if (item == MENU_EXIT)
    152.     {
    153.         MENU_PAGE_ITEMS = 0
    154.         menu_destroy(menuid)
    155.         return PLUGIN_HANDLED;
    156.     }
    157.    
    158.     // Remember items menu page
    159.     MENU_PAGE_ITEMS = item / 7
    160.    
    161.     // Dead players are not allowed to buy items
    162.     if (!is_user_alive(id))
    163.     {
    164.         menu_destroy(menuid)
    165.         return PLUGIN_HANDLED;
    166.     }
    167.    
    168.     // Retrieve item id
    169.     new itemdata[2], dummy, itemid
    170.     menu_item_getinfo(menuid, item, dummy, itemdata, charsmax(itemdata), _, _, dummy)
    171.     itemid = itemdata[0]
    172.    
    173.     // Attempt to buy the item
    174.     Buy_Item(id, itemid)
    175.     menu_destroy(menuid)
    176.     return PLUGIN_HANDLED;
    177. }
    178.  
    179. // Buy Item
    180. Buy_Item(id, itemid, ignorecost = 0)
    181. {
    182.     // Execute item select attempt forward
    183.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_PRE], g_iForwardReturn, id, itemid, ignorecost)
    184.    
    185.     // Item available to player?
    186.     if (g_iForwardReturn >= ZE_ITEM_UNAVAILABLE)
    187.         return;
    188.    
    189.     // Execute item selected forward
    190.     ExecuteForward(g_iForwards[FW_ITEM_SELECT_POST], g_iForwardReturn, id, itemid, ignorecost)
    191. }
    192.  
    193. // Natives
    194. public native_ze_register_item(plugin_id, num_params)
    195. {
    196.     new szItem_Name[32], iItem_Cost, iItem_Limit
    197.    
    198.     // Get the Data from first Parameter in the native (Item Name)
    199.     get_string(1, szItem_Name, charsmax(szItem_Name))
    200.    
    201.     // Get the Second Parameter (Item Cost)
    202.     iItem_Cost = get_param(2)
    203.    
    204.     // Get limit third parameter
    205.     iItem_Limit = get_param(3)
    206.    
    207.     if (strlen(szItem_Name) < 1)
    208.     {
    209.         // Can't leave item name empty
    210.         log_error(AMX_ERR_NATIVE, "[ZE] Can't register item with an empty name")
    211.         return ZE_WRONG_ITEM // Same as return -1
    212.     }
    213.    
    214.     new iIndex, szItemName[32]
    215.    
    216.     // Loop from 0 to max items amount
    217.     for (iIndex = 0; iIndex < g_iItemCount; iIndex++)
    218.     {
    219.         ArrayGetString(g_szItemRealName, iIndex, szItemName, charsmax(szItemName))
    220.        
    221.         if (equali(szItem_Name, szItemName))
    222.         {
    223.             log_error(AMX_ERR_NATIVE, "[ZE] Item already registered (%s)", szItemName)
    224.             return ZE_WRONG_ITEM; // Return -1
    225.         }
    226.     }
    227.    
    228.     // Load settings from extra items file
    229.     new szItemRealName[32]
    230.     copy(szItemRealName, charsmax(szItemRealName), szItem_Name)
    231.     ArrayPushString(g_szItemRealName, szItemRealName)
    232.    
    233.     // Name
    234.     if (!amx_load_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name, charsmax(szItem_Name)))
    235.         amx_save_setting_string(ZE_EXTRAITEM_FILE, szItemRealName, "NAME", szItem_Name)
    236.     ArrayPushString(g_szItemName, szItem_Name)
    237.    
    238.     // Cost
    239.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost))
    240.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "COST", iItem_Cost)
    241.     ArrayPushCell(g_iItemCost, iItem_Cost)
    242.    
    243.     // Limit
    244.     if (!amx_load_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit))
    245.         amx_save_setting_int(ZE_EXTRAITEM_FILE, szItemRealName, "LIMIT", iItem_Limit)
    246.     ArrayPushCell(g_iItemLimit, iItem_Limit)
    247.    
    248.     g_iItemCount++
    249.     return g_iItemCount - 1
    250. }
    251.  
    252. public native_ze_show_items_menu(plugin_id, num_params)
    253. {
    254.     new id = get_param(1)
    255.    
    256.     if (!is_user_connected(id))
    257.     {
    258.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    259.         return false;
    260.     }
    261.    
    262.     Cmd_Items(id)
    263.     return true
    264. }
    265.  
    266. public native_ze_force_buy_item(plugin_id, num_params)
    267. {
    268.     new id = get_param(1)
    269.    
    270.     if (!is_user_connected(id))
    271.     {
    272.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid Player (%d)", id)
    273.         return false;
    274.     }
    275.    
    276.     new item_id = get_param(2)
    277.    
    278.     if (item_id < 0 || item_id >= g_iItemCount)
    279.     {
    280.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    281.         return false;
    282.     }
    283.    
    284.     new ignorecost = get_param(3)
    285.    
    286.     Buy_Item(id, item_id, ignorecost)
    287.     return true;
    288. }
    289.  
    290. public native_ze_get_item_id(plugin_id, num_params)
    291. {
    292.     new szRealName[32]
    293.     get_string(1, szRealName, charsmax(szRealName))
    294.  
    295.     new index, szItemName[32]
    296.    
    297.     for (index = 0; index < g_iItemCount; index++)
    298.     {
    299.         ArrayGetString(g_szItemRealName, index, szItemName, charsmax(szItemName))
    300.        
    301.         if (equali(szRealName, szItemName))
    302.             return index
    303.     }
    304.    
    305.     return ZE_WRONG_ITEM
    306. }
    307.  
    308. public native_ze_get_item_cost(plugin_id, num_params)
    309. {
    310.     new item_id = get_param(1)
    311.    
    312.     if (item_id < 0 || item_id >= g_iItemCount)
    313.     {
    314.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    315.         return ZE_WRONG_ITEM;
    316.     }
    317.    
    318.     return ArrayGetCell(g_iItemCost, item_id);
    319. }
    320.  
    321. public native_ze_add_text_to_item(plugin_id, num_params)
    322. {
    323.     new szText[32]
    324.     get_string(1, szText, charsmax(szText))
    325.     format(g_szAdditionalMenuText, charsmax(g_szAdditionalMenuText), "%s%s", g_szAdditionalMenuText, szText)
    326. }
    327.  
    328. public native_ze_get_item_limit(plugin_id, num_params)
    329. {
    330.     new item_id = get_param(1)
    331.    
    332.     if (item_id < 0 || item_id >= g_iItemCount)
    333.     {
    334.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    335.         return ZE_WRONG_ITEM;
    336.     }
    337.    
    338.     return ArrayGetCell(g_iItemLimit, item_id);
    339. }
    340.  
    341. public native_ze_is_valid_itemid(plugin_id, num_params)
    342. {
    343.     new item_id = get_param(1)
    344.    
    345.     if (item_id < 0 || item_id >= g_iItemCount)
    346.     {
    347.         return false;
    348.     }
    349.    
    350.     return true;
    351. }
    352.  
    353. public native_ze_get_item_name(plugin_id, num_params)
    354. {
    355.     new item_id = get_param(1)
    356.    
    357.     if (item_id < 0 || item_id >= g_iItemCount)
    358.     {
    359.         log_error(AMX_ERR_NATIVE, "[ZE] Invalid item id (%d)", item_id)
    360.         return ZE_WRONG_ITEM;
    361.     }
    362.    
    363.     new szName[32]
    364.     ArrayGetString(g_szItemName, item_id, szName, charsmax(szName))
    365.    
    366.     new iLen = get_param(3)
    367.     set_string(2, szName, iLen)
    368.     return true;
    369. }
    370.  
    371. public native_ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount)
    372. {
    373.     g_bHasDiscount[iItemid] = bSet;
    374.     g_flDiscountValue[iItemid] = flDiscount;
    375. }
    376.  
    377. public native_ze_has_vip_discount(iItemid)
    378. {
    379.     return g_bHasDiscount[iItemid]
    380. }
    381.  
    382. public Float:native_ze_get_item_discount(iItemid)
    383. {
    384.     return g_flDiscountValue[iItemid]
    385. }
2. Update your ze_items_escape_coins.sma with:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - ze_get_item_discount(itemid)))
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(ze_get_item_discount(itemid) * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else
    31.     {
    32.         g_iRequiredEC = ze_get_item_cost(itemid)
    33.     }
    34.    
    35.     if (g_iCurrentEC < g_iRequiredEC)
    36.         return ZE_ITEM_UNAVAILABLE
    37.    
    38.     return ZE_ITEM_AVAILABLE
    39. }
    40.  
    41. public ze_select_item_post(id, itemid, ignorecost)
    42. {
    43.     if (ignorecost)
    44.         return
    45.    
    46.     g_iCurrentEC = ze_get_escape_coins(id)
    47.    
    48.     if (ze_is_user_vip(id) && ze_has_vip_discount(itemid))
    49.     {
    50.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * ze_get_item_discount(itemid))
    51.     }
    52.     else
    53.     {
    54.         g_iRequiredEC = ze_get_item_cost(itemid)
    55.     }
    56.    
    57.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    58. }
Now to add discount to any item for VIPs you will need to use this native:
  • bSet - set discount to this item or not. Make it true.
  • flDiscount - from 0 to 1, to make discount 10% use 0.1 to make 80 % use 0.8 and so on.
Now let's make 40 % discount on Fire nades for VIPs:
    1. #include <zombie_escape>
    2.  
    3. native ze_set_vip_discount(iItemid, bool:bSet, Float:flDiscount);
    4.  
    5. // Default Sound
    6. new const g_szBuyAmmoSound[] = "items/9mmclip1.wav"
    7.  
    8. // Variables
    9. new g_iItemID
    10.  
    11. public plugin_init()
    12. {
    13.     register_plugin("[ZE] Items: Fire Nade", ZE_VERSION, AUTHORS)
    14.    
    15.     // Register our item
    16.     g_iItemID = ze_register_item("Fire Nade", 30, 0)
    17.     ze_set_vip_discount(g_iItemID, true, 0.4)
    18. }
    19.  
    20. public ze_select_item_pre(id, itemid)
    21. {
    22.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    23.     if (itemid != g_iItemID)
    24.         return ZE_ITEM_AVAILABLE
    25.    
    26.     // Available for Humans only, So don't show it for zombies
    27.     if (ze_is_user_zombie(id))
    28.         return ZE_ITEM_DONT_SHOW
    29.    
    30.     return ZE_ITEM_AVAILABLE
    31. }
    32.  
    33. public ze_select_item_post(id, itemid)
    34. {
    35.     // This is not our item, Block it here
    36.     if (itemid != g_iItemID)
    37.         return
    38.    
    39.     // Get Weapon ID
    40.     new iWpnID = get_weaponid("weapon_hegrenade")
    41.    
    42.     // Player Don't have Frost Grenade then give him
    43.     if (rg_get_user_bpammo(id, WeaponIdType:iWpnID) == 0)
    44.     {
    45.         rg_give_item(id, "weapon_hegrenade", GT_APPEND)
    46.     }
    47.     else
    48.     {
    49.         // Player have, Increase his Back Pack Ammo, And play buy BP sound + Hud Flash
    50.         rg_set_user_bpammo(id, WeaponIdType:iWpnID, rg_get_user_bpammo(id, WeaponIdType:iWpnID) + 1)
    51.         emit_sound(id, CHAN_ITEM, g_szBuyAmmoSound, 1.0, ATTN_NORM, 0, PITCH_NORM)
    52.         Show_Given_BPAmmo(id, 12, 1) // HE Grenade AmmoType Const = 12
    53.     }
    54. }
Just added ze_set_vip_discount(g_iItemID, true, 0.4) under g_iItemID = ze_register_item("Fire Nade", 30, 0).

Important: You must run latest VIP System in order this to run!
is this possible?
  1. public ze_discounts
  2. {
  3.     if ((ze_get_vip_flags(id) & VIP_A) && (ze_get_vip_flags(id) & VIP_B) && (ze_get_vip_flags(id) & VIP_C))
  4.     {
  5.         ze_set_vip_discount(g_iItemID, true, 0.1)
  6.         return;
  7.     }
  8.     else if ((ze_get_vip_flags(id) & VIP_A) && (ze_get_vip_flags(id) & VIP_B))
  9.     {
  10.         ze_set_vip_discount(g_iItemID, true, 0.2)
  11.         return;
  12.     }
  13.     else if (ze_get_vip_flags(id) & VIP_A)
  14.     {
  15.         ze_set_vip_discount(g_iItemID, true, 0.3)
  16.         return;
  17.     }
  18. }

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

#22

Post by Raheem » 5 years ago

No, what you try to do?
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:

#23

Post by Mark » 5 years ago

Raheem wrote: 5 years ago No, what you try to do?
I want to be able to set different prices based off flags lol.

I have 3 tiers

VIP 10%
VIP+ 20%
VIP++ 30%

if this is alot of work dont worry.

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

#24

Post by Raheem » 5 years ago

What we did will make it just for all vips. So in this case we will need to edit the natives. Maybe 3 natives required for your idea.

Will give you example soon.
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:

#25

Post by Mark » 5 years ago

Raheem wrote: 5 years ago What we did will make it just for all vips. So in this case we will need to edit the natives. Maybe 3 natives required for your idea.

Will give you example soon.
I think the percents not right


Bought a firenade with cost set to 100 with a 10% discount

20180916203809_1.jpg
20180916203816_1.jpg
in pics you will see it cost 100 but it takes 10 off which is 90% yes?


so now i set it to 100 percent off by 1.0
20180916204437_1.jpg
20180916204441_1.jpg
Last edited by Mark 5 years ago, edited 1 time in total.

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

#26

Post by Raheem » 5 years ago

Yes i fixed it here: viewtopic.php?p=8396#p8396

Update yours.
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:

#27

Post by Mark » 5 years ago

Raheem wrote: 5 years ago Yes i fixed it here: viewtopic.php?p=8396#p8396

Update yours.
I did like 3x lol still same also file size was same that i had on server :D

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

#28

Post by Raheem » 5 years ago

Wait i forget something
He who fails to plan is planning to fail

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

#29

Post by Raheem » 5 years ago

This hardcode for the 3 cases:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if ((ze_get_vip_flags(id) & VIP_A) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.1))
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.1 * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else if ((ze_get_vip_flags(id) & VIP_B) && ze_has_vip_discount(itemid))
    31.     {
    32.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.2))
    33.        
    34.         new szText[32]
    35.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.2 * 100))
    36.         ze_add_text_to_item(szText)
    37.     }
    38.     else if ((ze_get_vip_flags(id) & VIP_C) && ze_has_vip_discount(itemid))
    39.     {
    40.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.3))
    41.        
    42.         new szText[32]
    43.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.3 * 100))
    44.         ze_add_text_to_item(szText)
    45.     }
    46.     else
    47.     {
    48.         g_iRequiredEC = ze_get_item_cost(itemid)
    49.     }
    50.    
    51.     if (g_iCurrentEC < g_iRequiredEC)
    52.         return ZE_ITEM_UNAVAILABLE
    53.    
    54.     return ZE_ITEM_AVAILABLE
    55. }
    56.  
    57. public ze_select_item_post(id, itemid, ignorecost)
    58. {
    59.     if (ignorecost)
    60.         return
    61.    
    62.     g_iCurrentEC = ze_get_escape_coins(id)
    63.    
    64.     if ((ze_get_vip_flags(id) & VIP_A) && ze_has_vip_discount(itemid))
    65.     {
    66.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.1))
    67.     }
    68.     if ((ze_get_vip_flags(id) & VIP_B) && ze_has_vip_discount(itemid))
    69.     {
    70.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.2))
    71.     }
    72.     if ((ze_get_vip_flags(id) & VIP_C) && ze_has_vip_discount(itemid))
    73.     {
    74.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.3))
    75.     }
    76.     else
    77.     {
    78.         g_iRequiredEC = ze_get_item_cost(itemid)
    79.     }
    80.    
    81.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    82. }
Try it.

Edit: Also i updated this: viewtopic.php?p=8396#p8396
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:

#30

Post by Mark » 5 years ago

Raheem wrote: 5 years ago This hardcode for the 3 cases:
    1. #include <zombie_escape>
    2. #include <ze_vip>
    3.  
    4. native ze_has_vip_discount(iItemid)
    5. native Float:ze_get_item_discount(iItemid)
    6.  
    7. new g_iCurrentEC,
    8.     g_iRequiredEC
    9.  
    10. public plugin_init()
    11. {
    12.     register_plugin("[ZE] Items Manager: Escape Coins", ZE_VERSION, AUTHORS)
    13. }
    14.  
    15. public ze_select_item_pre(id, itemid, ignorecost)
    16. {
    17.     if (ignorecost)
    18.         return ZE_ITEM_AVAILABLE
    19.    
    20.     g_iCurrentEC = ze_get_escape_coins(id)
    21.    
    22.     if ((ze_get_vip_flags(id) & VIP_A) && ze_has_vip_discount(itemid))
    23.     {
    24.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.1))
    25.        
    26.         new szText[32]
    27.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.1 * 100))
    28.         ze_add_text_to_item(szText)
    29.     }
    30.     else if ((ze_get_vip_flags(id) & VIP_B) && ze_has_vip_discount(itemid))
    31.     {
    32.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.2))
    33.        
    34.         new szText[32]
    35.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.2 * 100))
    36.         ze_add_text_to_item(szText)
    37.     }
    38.     else if ((ze_get_vip_flags(id) & VIP_C) && ze_has_vip_discount(itemid))
    39.     {
    40.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.3))
    41.        
    42.         new szText[32]
    43.         formatex(szText, charsmax(szText), " \w(\r%i %% OFF\w)", floatround(0.3 * 100))
    44.         ze_add_text_to_item(szText)
    45.     }
    46.     else
    47.     {
    48.         g_iRequiredEC = ze_get_item_cost(itemid)
    49.     }
    50.    
    51.     if (g_iCurrentEC < g_iRequiredEC)
    52.         return ZE_ITEM_UNAVAILABLE
    53.    
    54.     return ZE_ITEM_AVAILABLE
    55. }
    56.  
    57. public ze_select_item_post(id, itemid, ignorecost)
    58. {
    59.     if (ignorecost)
    60.         return
    61.    
    62.     g_iCurrentEC = ze_get_escape_coins(id)
    63.    
    64.     if ((ze_get_vip_flags(id) & VIP_A) && ze_has_vip_discount(itemid))
    65.     {
    66.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.1))
    67.     }
    68.     if ((ze_get_vip_flags(id) & VIP_B) && ze_has_vip_discount(itemid))
    69.     {
    70.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.2))
    71.     }
    72.     if ((ze_get_vip_flags(id) & VIP_C) && ze_has_vip_discount(itemid))
    73.     {
    74.         g_iRequiredEC = floatround(ze_get_item_cost(itemid) * (1.0 - 0.3))
    75.     }
    76.     else
    77.     {
    78.         g_iRequiredEC = ze_get_item_cost(itemid)
    79.     }
    80.    
    81.     ze_set_escape_coins(id, g_iCurrentEC - g_iRequiredEC)
    82. }
Try it.

Edit: Also i updated this: viewtopic.php?p=8396#p8396
ok percent works now ill try vip flags

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 2 guests