Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ///////////////////////
- Require:
- [AMXX] Chat color base "http://pastebin.com/r55Tpurq"
- ///////////////////////
- Include: "http://pastebin.com/7jWH3Y0Z"
- Example of use: "http://pastebin.com/4bYw71e4"
- */
- #include <amxmodx>
- #include <fun>
- #include <cstrike>
- #include <chatcolor>
- #define PLUGIN "Shop"
- #define VERSION "1.0"
- #define AUTHOR "Sugisaki"
- #define MAX_ITEMS 15
- #define AVAIBLE "y"
- #define UNAVAIBLE "r"
- enum _:ITEM_DATA
- {
- ITEM_NAME[32],
- ITEM_COST,
- ITEM_TEAM
- }
- enum _: TEAMS
- {
- TEAM_TT = 1,
- TEAM_CT,
- TEAM_ALL
- }
- new g_szItems[MAX_ITEMS][ITEM_DATA];
- new g_iTotalItems
- new g_iForward
- new g_iNumIteamsTeam[TEAMS+1]
- public plugin_init()
- {
- register_plugin(PLUGIN, VERSION, AUTHOR)
- register_clcmd("say /buy", "client_buy_open")
- register_clcmd("say buy", "client_buy_open")
- register_clcmd("say_team /buy", "client_buy_open")
- register_clcmd("say_team buy", "client_buy_open")
- g_iForward = CreateMultiForward("shop_item_selected", ET_STOP, FP_CELL, FP_CELL, FP_STRING, FP_CELL)
- set_task(300.0, "fw_announcer", _, _, _, "b")
- }
- public fw_announcer()
- {
- //client_print(0, print_chat, "[SHOP] Escribe /buy para abrir la tienda")
- chat_color(0,0, "!n[!tSHOP!n] Escribe !t/buy !npara abrir la tienda")
- }
- public plugin_natives()
- {
- register_native("shop_add_item", "_native_add_item")
- }
- public _native_add_item(pid, par)
- {
- if(g_iTotalItems >= MAX_ITEMS)
- return log_amx("[SHOP] Numero de Items al maximo [ Max %i ] [p2]", MAX_ITEMS, pid)
- get_string(1, g_szItems[g_iTotalItems][ITEM_NAME], charsmax(g_szItems[][ITEM_NAME]))
- g_szItems[g_iTotalItems][ITEM_COST] = get_param(2)
- g_szItems[g_iTotalItems][ITEM_TEAM] = get_param(3)
- log_amx("Item agregado %s", g_szItems[g_iTotalItems][ITEM_NAME])
- g_iTotalItems++
- g_iNumIteamsTeam[get_param(3)]++
- return (g_iTotalItems - 1)
- }
- public client_buy_open(id)
- {
- if(!is_user_alive(id) || !is_user_connected(id)) return PLUGIN_HANDLED
- if(g_iTotalItems <=0)
- {
- //client_print(id, print_chat, "No hay items en la tienda")
- chat_color(id, MSG_ONE, "!n[!tSHOP!n] No hay !gitems !nen la tienda")
- return PLUGIN_HANDLED
- }
- new team = get_user_team(id)
- if(g_iNumIteamsTeam[get_user_team(id)] <= 0 && !(g_iNumIteamsTeam[TEAM_ALL]))
- {
- chat_color(id, MSG_ONE, "!n[!tSHOP!n] No hay !gitems !ndisponibles para tu !tequipo")
- //client_print(id, print_chat, "No hay items disponibles")
- return PLUGIN_HANDLED
- }
- static item[128], num[3]
- new menu = menu_create("\rBuy menu", "buymenu_handle")
- for(new i = 0; i < g_iTotalItems; i++)
- {
- if(team == g_szItems[i][ITEM_TEAM] || g_szItems[i][ITEM_TEAM] == TEAM_ALL)
- {
- 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]);
- num_to_str(i, num, charsmax(num));
- menu_additem(menu, item, num);
- }
- }
- menu_display(id, menu)
- return PLUGIN_HANDLED
- }
- public buymenu_handle(id, menu, item)
- {
- if(!is_user_alive(id) || !is_user_connected(id))
- {
- return PLUGIN_HANDLED
- if(item == MENU_EXIT)
- {
- }
- menu_destroy(menu)
- return PLUGIN_HANDLED
- }
- new access, callback, num[3];
- menu_item_getinfo(menu, item, access, num, charsmax(num), _, _, callback);
- menu_destroy(menu);
- new itemid = str_to_num(num);
- new money = cs_get_user_money(id)
- if(g_szItems[itemid][ITEM_COST] > money)
- {
- //client_print(id, print_chat, "[SHOP] No tienes dinero suficientes")
- chat_color(id, MSG_ONE, "!n[!tSHOP!n] No tienes !gdinero !nsuficiente")
- return PLUGIN_HANDLED
- }
- new ret
- if(is_user_alive(id))
- {
- ExecuteForward(g_iForward, ret, id, itemid, g_szItems[itemid][ITEM_NAME], g_szItems[itemid][ITEM_COST])
- cs_set_user_money(id, money - g_szItems[itemid][ITEM_COST])
- //client_print(id, print_chat, "[SHOP] Has comprado %s", g_szItems[itemid][ITEM_NAME])
- chat_color(id, MSG_ONE, "!n[!tSHOP!n] Has !gcomprado !t%s", g_szItems[itemid][ITEM_NAME])
- }
- return PLUGIN_CONTINUE
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement