| |
 RSS
  • OnLine

    : 3
    : 2
    : -
    : crawl Bot

    ?

    • AMX Mod X
    • up.org.ua


  • : Nesquik : 20-10-2014, 20:28 : 3776

    shop_api

    : Nesquik
    : 1.0 http://amxxmodx.ru/
    : API

    shop_api















    :
    Amxx
    Cstrike

    shop_api.inc
    //     
    #define TEAM_ALL0 //
    #define TEAM_T 1 //
    #define TEAM_CT2 //

    #define SHOP_ITEM_DISABLED 97 // UserChooseItem

    //
    // @param id
    // @param item
    forward UserChooseItem(id, item)

    //
    forward UserOpenMenu(id)

    //
    // @param id
    // @param page
    native OpenShopMenu(const id, const page)

    //
    // @param Name
    // @param cost
    // @param team
    // @return
    native RegisterItem(Name[], cost, team)


    :
    amxx_cvar_enable_round_shop = 0

    3 3

    amxx_cvar_buy_max_items = 10


    :
    #include <amxmodx>
    #include <cstrike>

    #define TEAM_ALL0
    #define SHOP_ITEM_DISABLED97

    enum _:EXEC_FORWARD
    {
    ForwardItemChoose=0,
    ForwardMenuOpen
    }

    new Array:ItemName, Array:ItemCost, Array:ItemTeam
    new pCvarRoundEnable, pCvarBuyMaxItems
    new RoundNumber, szResult
    new gForward[EXEC_FORWARD]
    new szBuyItems[33]

    new szButtonName[][] = {"MENU_EXIT", "MENU_NEXT", "MENU_BACK"}
    new szButtonIndex[] = {MPROP_EXITNAME, MPROP_NEXTNAME, MPROP_BACKNAME}

    public plugin_init()
    {
    register_plugin("Shop Api for amxxmodx.ru", "1.0", "Nesquik")

    register_clcmd("say /shop", "ShowShopMenu")
    register_clcmd("say_team /shop", "ShowShopMenu")

    pCvarRoundEnable = register_cvar("amxx_cvar_enable_round_shop", "0")
    pCvarBuyMaxItems = register_cvar("amxx_cvar_buy_max_items", "10")

    gForward[ForwardItemChoose] = CreateMultiForward("UserChooseItem", ET_CONTINUE, FP_CELL, FP_CELL)
    gForward[ForwardMenuOpen] = CreateMultiForward("UserOpenMenu", ET_CONTINUE, FP_CELL)

    register_event("HLTV", "EventHLTV", "a", "1=0", "2=0")
    register_event("TextMsg", "EventTextMsg", "a", "2=#Game_Commencing", "2=#Game_will_restart_in")

    register_dictionary("shop_api.txt")
    }

    public ShowShopMenu(id)
    return ShopMenuSub(id, 0)

    public ShopMenuSub(id, page)
    {
    new cvar[2]
    cvar[0] = get_pcvar_num(pCvarRoundEnable)
    cvar[1] = get_pcvar_num(pCvarBuyMaxItems)

    if(cvar[0] && (cvar[0] > RoundNumber))
    {
    client_print(id, print_chat, "%L", LANG_PLAYER, "CANT_BUY_IN_ROUND", cvar[0])
    return 0
    }

    if(cvar[1] && (szBuyItems[id] >= cvar[1]))
    {
    client_print(id, print_chat, "%L", LANG_PLAYER, "YOU_BUY_MAX_ITEMS_IN_ROUND", cvar[1])
    return 0
    }

    new szMenu[96], szName[64], szHostName[64], szKey[3]
    new szCreateMenuShop, szBackMenuShop, szCost, szTeam
    new szSize = ArraySize(ItemName), szUserTeam = get_user_team(id), szMoney = cs_get_user_money(id)

    get_cvar_string("hostname", szHostName, charsmax(szHostName))
    ExecuteForward(gForward[ForwardMenuOpen], szResult, id)

    format(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "SHOP_TITLE", szHostName)
    szCreateMenuShop = menu_create(szMenu, "MenuFuncShop")
    szBackMenuShop = menu_makecallback("MenuBackShop")

    for(new i = 0; i < szSize; i++)
    {
    num_to_str(i, szKey, charsmax(szKey))

    ArrayGetString(ItemName, i, szName, charsmax(szName))
    szCost = ArrayGetCell(ItemCost, i)
    szTeam = ArrayGetCell(ItemTeam, i)

    if(szTeam == szUserTeam || szTeam == TEAM_ALL)
    {
    if(szMoney >= szCost)
    formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "INFO_ITEM", szName, szCost)
    else
    formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, "NO_MONEY", szName, szCost - szMoney)
    }

    menu_additem(szCreateMenuShop, szMenu, szKey, 0, szBackMenuShop)
    }

    for(new i = 0; i < sizeof szButtonName; i++)
    {
    formatex(szMenu, charsmax(szMenu), "%L", LANG_PLAYER, szButtonName[i])
    menu_setprop(szCreateMenuShop, szButtonIndex[i], szMenu)
    }

    if(szSize)
    return menu_display(id, szCreateMenuShop, page)
    else
    client_print(id, print_chat, "%L", LANG_PLAYER, "NO_ITEM_IN_MENU")

    return 0
    }

    public MenuFuncShop(id, szMenu, szItem)
    {
    if(szItem == MENU_EXIT)
    return menu_destroy(szMenu)

    new szData[3]
    new szDummy
    new szCost, szMoney = cs_get_user_money(id)

    menu_item_getinfo(szMenu, szItem, szDummy, szData, charsmax(szData), _, _, szDummy)
    szItem = str_to_num(szData)

    szCost = ArrayGetCell(ItemCost, szItem)
    cs_set_user_money(id, szMoney - szCost, 1)

    ExecuteForward(gForward[ForwardItemChoose], szResult, id, szItem)

    if(szResult == SHOP_ITEM_DISABLED)
    cs_set_user_money(id, szMoney, 1)

    return 1
    }

    public MenuBackShop(id, szMenu, szItem)
    {
    new szData[3]
    new szDummy
    new szMoney = cs_get_user_money(id)

    menu_item_getinfo(szMenu, szItem, szDummy, szData, charsmax(szData), _, _, szDummy)
    szItem = str_to_num(szData)

    if(szMoney < ArrayGetCell(ItemCost, szItem))
    return ITEM_DISABLED

    return ITEM_ENABLED
    }

    public EventHLTV()
    {
    arrayset(szBuyItems, 0, 33)
    RoundNumber++
    }

    public EventTextMsg()
    {
    arrayset(szBuyItems, 0, 33)
    RoundNumber=0
    }

    public plugin_precache()
    {
    ItemName = ArrayCreate(64, 1)
    ItemCost = ArrayCreate(1, 1)
    ItemTeam = ArrayCreate(1, 1)
    }

    public plugin_natives()
    {
    register_native("RegisterItem", "NativeRegisterItem", 1)
    register_native("OpenShopMenu", "NativeOpenShopMenu", 1)
    }

    public NativeRegisterItem(const Name[], const Cost, const Team)
    {
    param_convert(1)

    ArrayPushString(ItemName, Name)
    ArrayPushCell(ItemCost, Cost)
    ArrayPushCell(ItemTeam, Team)

    return (ArraySize(ItemName) - 1)
    }

    public NativeOpenShopMenu(id, page)
    return ShopMenuSub(id, page)


    say /shop

    :
    #include <amxmodx>
    #include <shop_api> //
    #include <fun>

    new ItemId //

    public plugin_precache()
    ItemId = RegisterItem("He ", 500, TEAM_ALL) // He , 500 $ ,

    public UserChooseItem(id, item)
    {
    if(item == ItemId) //
    {
    if(!user_has_weapon(id, CSW_HEGRENADE)) // He
    give_item(id, "weapon_hegrenade") // He
    else
    return SHOP_ITEM_DISABLED // He
    }

    return 1
    }





    /

    Admin - 23-10-2014, 00:23
    : .
    , .
    .
    shop_api
    droads

    --
    ICQ: --
    : 0
    : 0
    : -  0  +

    ItemId = RegisterItem("He ", 500, TEMA_ALL)
    TEAM_ALL

    ..
    OtherWorld7

    --
    ICQ: --
    : 0
    : 0
    : -  0  +

    - ? ))
    gavrilyuc

    --
    ICQ: --
    : 0
    : 0
    : -  0  +

    enum.
    enum _:Item {
    Name[64],
    ItemTeam,
    ItemCost
    }


    OtherWorld7, , ( )
    ... - 2 ...
    -- get_ammo(id);
    -- set_ammo(id, num);

    , . cstrike Money .


    //
    // @param id    
    // @param item
    forward UserChooseItem(id, item)


    , ... - 40 ...
    ? sub ...
    ...

    "Item Menu" Callback .

    , , .