Thread: Item limit
View Single Post
Author Message
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South Korea
Old 01-19-2021 , 20:32   Item limit
Reply With Quote #1

Hello, I want to add limit for items.

For example:

"Napalm Nade 50 [0/2]" then if the player reached the limit

->

"Napalm Nade 50 [2/2]" and it will be grayed out and can't be pressed/selected anymore


PHP Code:
#include <amxmodx>
#include <fun>
#include <cstrike>
#include <zp50_ammopacks>
#include <zp50_core>

new limit_firenade[33], limit_frostnade[33]

native ze_give_tornado(id)
native ze_give_stun(id)
native ze_give_akbeast(id)
native ze_give_lasermg(id)
native ze_give_ethereal(id)

public 
plugin_init()
{
    
register_plugin("[ZE] VIP Menu""1.0""DemonSlayerCS")
    
register_event("HLTV""round_starts""a""1=0""2=0")
}

public 
round_starts()
{
    new 
players[32],inum,id
    get_players
(players,inum)
    for(new 
i;i<inum;i++)
    {
        
id players[i]
        
limit_firenade[id] = 0
        limit_frostnade
[id] = 0
    
}
}

public 
client_connect(id)
{
    
limit_firenade[id] = 0
    limit_frostnade
[id] = 0
}

public 
client_disconnected(id)
{
    
limit_firenade[id] = 0
    limit_frostnade
[id] = 0
}

public 
plugin_natives()
{
    
register_native("show_menu_vip""menu_show"1)   
}

public 
menu_show(id)
{
    
vip_menu(id)


public 
vip_menu(id)
{
    new 
menuz;
    static 
amenu[512];
    
formatex(amenu,charsmax(amenu),"\rVIP Menu")
    
menuz menu_create(amenu,"vip_it_menu")
    
    
formatex(amenu,charsmax(amenu),"Napalm Nade \r[FREE]")
    
menu_additem(menuz,amenu,"1")
    
    
formatex(amenu,charsmax(amenu),"Frost Nade \r[FREE]")
    
menu_additem(menuz,amenu,"2")
    
    
formatex(amenu,charsmax(amenu),"Stun Rifle \y50")
    
menu_additem(menuz,amenu,"3")
    
    
formatex(amenu,charsmax(amenu),"SF Tornado \y50")
    
menu_additem(menuz,amenu,"4")    

    
formatex(amenu,charsmax(amenu),"AK47 Beast \y50")
    
menu_additem(menuz,amenu,"5")    

    
formatex(amenu,charsmax(amenu),"Balrog Ethereal \y50")
    
menu_additem(menuz,amenu,"6")    

    
formatex(amenu,charsmax(amenu),"LaserMinigun \y50")
    
menu_additem(menuz,amenu,"7")    

    
menu_setprop(menuz,MPROP_EXIT,MEXIT_ALL)
    
menu_display(id,menuz,0)
    
    return 
PLUGIN_HANDLED
}

public 
vip_it_menu(id,menu,item)
{
    if(
item == MENU_EXIT || zp_core_is_zombie(id))
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    new 
access,callback,data[6],iname[64]
    
    
menu_item_getinfo(menu,item,access,data,5,iname,63,callback)
    
    new 
key str_to_num(data)

    if(
key == 1)
    {
        if(
limit_firenade[id] < 2)
        {
            
give_item(id"weapon_hegrenade")
            
limit_firenade[id]++
        }
        else if(
limit_firenade[id] > 2)
        {
            
client_printcolored(id"!g[=SG=] !nYou have reached the limit !t[2/2]")
        }
    }
    else if(
key == 2)
    {
        if(
limit_frostnade[id] < 2)
        {
            
give_item(id"weapon_flashbang")
            
limit_frostnade[id]++
        }
        else if(
limit_frostnade[id] > 2)
        {
            
client_printcolored(id"!g[=SG=] !nYou have reached the limit !t[2/2]")
        }
    }
    else if(
key == 3)
    {
        if(
zp_ammopacks_get(id) >= 50)
        {
            
ze_give_stun(id)
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tStun Rifle")
        }
    }
    else if(
key == 4)
    {
        if(
zp_ammopacks_get(id) >= 50)
        {
            
ze_give_tornado(id)
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tSF Tornado")
        }
    }
    else if(
key == 5)
    {
        if(
zp_ammopacks_get(id) >= 50)
        {
            
ze_give_akbeast(id)    
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tAK47 Beast")
        }
    }

    else if(
key == 6)
    {
        if(
zp_ammopacks_get(id) >= 50)
        {
            
ze_give_ethereal(id)    
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tEthereal Balrog")
        }
    }
    else if(
key == 7)
    {
        if(
zp_ammopacks_get(id) >= 50)
        {
            
ze_give_lasermg(id)    
            
zp_ammopacks_set(idzp_ammopacks_get(id) - 50)
        }
        else
        {
            
client_printcolored(id"!g[=SG=] !nYou don't have enough !gAmmoPacks !nto buy !tLaserMinigun")
        }
    }
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED
}

client_printcolored(index, const text[], any:...)
{
    new 
szMsg[128];
    
vformat(szMsgsizeof(szMsg) - 1text3);
    
    
replace_all(szMsgsizeof(szMsg) - 1"!g""^x04");
    
replace_all(szMsgsizeof(szMsg) - 1"!n""^x01");
    
replace_all(szMsgsizeof(szMsg) - 1"!t""^x03");
    
    
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _index);
    
write_byte(index);
    
write_string(szMsg);
    
message_end();

__________________

Last edited by nG_getwreck; 01-19-2021 at 20:42.
nG_getwreck is offline