Advertisement
Sugisaki

[AMXX] Shop by natives

Jun 24th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.97 KB | None | 0 0
  1. /*
  2. ///////////////////////
  3. Require:
  4. [AMXX] Chat color base "http://pastebin.com/r55Tpurq"
  5. ///////////////////////
  6. Include: "http://pastebin.com/7jWH3Y0Z"
  7.  
  8. Example of use: "http://pastebin.com/4bYw71e4"
  9. */
  10.  
  11.  
  12.  
  13.  
  14.  
  15. #include <amxmodx>
  16. #include <fun>
  17. #include <cstrike>
  18. #include <chatcolor>
  19.  
  20. #define PLUGIN "Shop"
  21. #define VERSION "1.0"
  22. #define AUTHOR "Sugisaki"
  23.  
  24. #define MAX_ITEMS   15
  25.  
  26. #define AVAIBLE     "y"
  27. #define UNAVAIBLE   "r"
  28.  
  29. enum _:ITEM_DATA
  30. {
  31.     ITEM_NAME[32],
  32.     ITEM_COST,
  33.     ITEM_TEAM
  34. }
  35. enum _: TEAMS
  36. {
  37.     TEAM_TT = 1,
  38.     TEAM_CT,
  39.     TEAM_ALL
  40. }
  41.  
  42. new g_szItems[MAX_ITEMS][ITEM_DATA];
  43. new g_iTotalItems
  44. new g_iForward
  45. new g_iNumIteamsTeam[TEAMS+1]
  46.  
  47. public plugin_init()
  48. {
  49.     register_plugin(PLUGIN, VERSION, AUTHOR)
  50.    
  51.     register_clcmd("say /buy", "client_buy_open")
  52.     register_clcmd("say buy", "client_buy_open")
  53.     register_clcmd("say_team /buy", "client_buy_open")
  54.     register_clcmd("say_team buy", "client_buy_open")
  55.     g_iForward = CreateMultiForward("shop_item_selected", ET_STOP, FP_CELL, FP_CELL, FP_STRING, FP_CELL)
  56.     set_task(300.0, "fw_announcer", _, _, _, "b")
  57. }
  58. public fw_announcer()
  59. {
  60.     //client_print(0, print_chat, "[SHOP] Escribe /buy para abrir la tienda")
  61.     chat_color(0,0, "!n[!tSHOP!n] Escribe !t/buy !npara abrir la tienda")
  62. }
  63. public plugin_natives()
  64. {
  65.     register_native("shop_add_item", "_native_add_item")
  66.    
  67. }
  68. public _native_add_item(pid, par)
  69. {
  70.     if(g_iTotalItems >= MAX_ITEMS)
  71.         return log_amx("[SHOP] Numero de Items al maximo [ Max %i ] [p2]", MAX_ITEMS, pid)
  72.        
  73.     get_string(1, g_szItems[g_iTotalItems][ITEM_NAME], charsmax(g_szItems[][ITEM_NAME]))
  74.     g_szItems[g_iTotalItems][ITEM_COST] = get_param(2)
  75.     g_szItems[g_iTotalItems][ITEM_TEAM] = get_param(3)
  76.    
  77.     log_amx("Item agregado %s", g_szItems[g_iTotalItems][ITEM_NAME])
  78.  
  79.     g_iTotalItems++
  80.     g_iNumIteamsTeam[get_param(3)]++
  81.     return (g_iTotalItems - 1)
  82. }
  83. public client_buy_open(id)
  84. {
  85.     if(!is_user_alive(id) || !is_user_connected(id)) return PLUGIN_HANDLED
  86.    
  87.     if(g_iTotalItems  <=0)
  88.     {
  89.         //client_print(id, print_chat, "No hay items en la tienda")
  90.         chat_color(id, MSG_ONE, "!n[!tSHOP!n] No hay !gitems !nen la tienda")
  91.         return PLUGIN_HANDLED
  92.     }
  93.     new team = get_user_team(id)
  94.    
  95.     if(g_iNumIteamsTeam[get_user_team(id)] <= 0 && !(g_iNumIteamsTeam[TEAM_ALL]))
  96.     {
  97.         chat_color(id, MSG_ONE, "!n[!tSHOP!n] No hay !gitems !ndisponibles para tu !tequipo")
  98.         //client_print(id, print_chat, "No hay items disponibles")
  99.         return PLUGIN_HANDLED
  100.     }
  101.     static item[128], num[3]
  102.     new menu = menu_create("\rBuy menu", "buymenu_handle")
  103.     for(new i = 0; i < g_iTotalItems; i++)
  104.     {
  105.        
  106.         if(team == g_szItems[i][ITEM_TEAM] || g_szItems[i][ITEM_TEAM] == TEAM_ALL)
  107.         {
  108.             formatex(item, charsmax(item), "\w%s  [\%s$%i\w]", g_szItems[i][ITEM_NAME], (cs_get_user_money(id) < g_szItems[i][ITEM_COST] ? UNAVAIBLE : AVAIBLE), g_szItems[i][ITEM_COST]);
  109.             num_to_str(i, num, charsmax(num));
  110.             menu_additem(menu, item, num);
  111.         }
  112.     }
  113.     menu_display(id, menu)
  114.     return PLUGIN_HANDLED
  115. }
  116. public buymenu_handle(id, menu, item)
  117. {
  118.     if(!is_user_alive(id) || !is_user_connected(id))
  119.     {
  120.         return PLUGIN_HANDLED
  121.     if(item == MENU_EXIT)
  122.     {
  123.     }
  124.         menu_destroy(menu)
  125.         return PLUGIN_HANDLED
  126.     }
  127.     new access, callback, num[3];
  128.     menu_item_getinfo(menu, item, access, num, charsmax(num), _, _, callback);
  129.     menu_destroy(menu);
  130.  
  131.     new itemid = str_to_num(num);
  132.    
  133.     new money = cs_get_user_money(id)
  134.     if(g_szItems[itemid][ITEM_COST] > money)
  135.     {
  136.         //client_print(id, print_chat, "[SHOP] No tienes dinero suficientes")
  137.         chat_color(id, MSG_ONE, "!n[!tSHOP!n] No tienes !gdinero !nsuficiente")
  138.         return PLUGIN_HANDLED
  139.     }
  140.     new ret
  141.     if(is_user_alive(id))
  142.     {
  143.         ExecuteForward(g_iForward, ret, id, itemid, g_szItems[itemid][ITEM_NAME], g_szItems[itemid][ITEM_COST])
  144.         cs_set_user_money(id, money - g_szItems[itemid][ITEM_COST])
  145.         //client_print(id, print_chat, "[SHOP] Has comprado %s", g_szItems[itemid][ITEM_NAME])
  146.         chat_color(id, MSG_ONE, "!n[!tSHOP!n] Has !gcomprado !t%s", g_szItems[itemid][ITEM_NAME])
  147.     }
  148.     return PLUGIN_CONTINUE
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement