Raised This Month: $12 Target: $400
 3% 

Item limit


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
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
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-20-2021 , 03:02   Re: Item limit
Reply With Quote #2

Code:
enum _:eItemData
{
	ITEM_NUMBER_ONE = 0,
	ITEM_NUMBER_TWO,
	ITEM_NUMBER_THREE
};

new g_item_counter[eItemData][33];


// later

if(g_item_counter[ITEM_NUMBER_ONE][id] > max_limit)
{
	console_print(id, "max limit reach");
	return PLUGIN_HANDLED;
}
__________________
LondoN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-20-2021 , 03:03   Re: Item limit
Reply With Quote #3

Use menu callbacks to disable menu items for the items that a player is not allowed to get. In the callback, you can check for anything that you want. In your example, it would be a check to see if the player is full on that item and return ITEM_DISABLED.

A little advice:
Instead of the "if else if else..." for the variable "key", use a switch. It will be more efficient and be easier to read/understand.

Also, this if else if doesn't account for the case where limit_firenade[id] is equal to 2. However, if you do the menu item disabling with the callbacks, you can basically remove that check anyways.

Code:
        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]")
        }
__________________
fysiks is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-20-2021 , 03:07   Re: Item limit
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
Use menu callbacks to disable menu items for the items that a player is not allowed to get. In the callback, you can check for anything that you want. In your example, it would be a check to see if the player is full on that item and return ITEM_DISABLED.

A little advice:
Instead of the "if else if else..." for the variable "key", use a switch. It will be more efficient and be easier to read/understand.

Also, this if else if doesn't account for the case where limit_firenade[id] is equal to 2. However, if you do the menu item disabling with the callbacks, you can basically remove that check anyways.

Code:
        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]")
        }
i think he can use a code such like this, i'm not use, i do not tested ever, but i think it will works

Code:
firename_limit[id] < max_limit ? give_item(id, "weapon_hegrenade") : return ITEM_DISABLED;
__________________
LondoN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-20-2021 , 03:09   Re: Item limit
Reply With Quote #5

Quote:
Originally Posted by LondoN View Post
i think he can use a code such like this, i'm not use, i do not tested ever, but i think it will works

Code:
firename_limit[id] < max_limit ? give_item(id, "weapon_hegrenade") : return ITEM_DISABLED;
No, you cannot do that. The callback is called when the menu is being shown, not when an item is selected. So, doing that would give the item to the player just for opening the menu. The only action that should occur in the callback is to return either disabled or ignore. Everything else should just be determining which value to return.
__________________

Last edited by fysiks; 01-20-2021 at 03:10.
fysiks is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-20-2021 , 03:13   Re: Item limit
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
No, you cannot do that. The callback is called when the menu is being shown, not when an item is selected. So, doing that would give the item to the player just for opening the menu. The only action that should occur in the callback is to return either disabled or ignore. Everything else should just be determining which value to return.
how about using in case?

case 1: item_counter[id] < max_limit ? give_item(id, "weapon_hegrenade") : return ITEM_DISABLED;

hmm, i think the code will execute only by pressing the 1 from the menu, and no if/else if/switch or other, i will test this syntax and come back with an output
__________________
LondoN is offline
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
Old 01-20-2021 , 05:23   Re: Item limit
Reply With Quote #7

I'm not sure, what I'm doing but this one will it work?

PHP Code:
formatex(amenu,charsmax(amenu),"LaserMinigun \y50"
--- >>

PHP Code:
formatex(amenu,charsmax(amenu),"LaserMinigun \y50 [%d/%d]",limit_lasermg[id],2
__________________
nG_getwreck is offline
LondoN
Senior Member
Join Date: Dec 2015
Location: Roman, Romania.
Old 01-20-2021 , 05:35   Re: Item limit
Reply With Quote #8

Code:
formatex(amenu, charsmax(amenu), "Laserminigun \y50 (%d/2)", limit_lasermg[id])
__________________
LondoN is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-21-2021 , 00:39   Re: Item limit
Reply With Quote #9

Quote:
Originally Posted by LondoN View Post
how about using in case?

case 1: item_counter[id] < max_limit ? give_item(id, "weapon_hegrenade") : return ITEM_DISABLED;

hmm, i think the code will execute only by pressing the 1 from the menu, and no if/else if/switch or other, i will test this syntax and come back with an output
Umm, that doesn't make any sense. Please stop trying to give advice unless you have tested it in a server yourself since you clearly don't know how this type of code works.

Quote:
Originally Posted by nG_getwreck View Post
I'm not sure, what I'm doing but this one will it work?

PHP Code:
formatex(amenu,charsmax(amenu),"LaserMinigun \y50"
--- >>

PHP Code:
formatex(amenu,charsmax(amenu),"LaserMinigun \y50 [%d/%d]",limit_lasermg[id],2
You can easily test that yourself since it's just formatting text and you can see if it works. Were you able to get the callback working?
__________________

Last edited by fysiks; 01-21-2021 at 00:45.
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode