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

Max Usage Of A Item In Shop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DON KHAN 1
Senior Member
Join Date: Mar 2019
Location: Pakistan
Old 03-24-2021 , 04:47   Max Usage Of A Item In Shop
Reply With Quote #1

Hello.
I am running a RECSDM mod.
I have added a Shop plugin.
I want to add limit of each item and limit get reset after getting killed.
Thank You
__________________
Facebook
My YouTube
Ro{Y}aL WarLanD CommuniTy
Selling Zombie CSO 4.3 Money System Mod
DON KHAN 1 is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 03-24-2021 , 09:33   Re: Max Usage Of A Item In Shop
Reply With Quote #2

Suggestions / Requests , wrong section buddy and provide sma to the item shop next time.
AnimalMonster is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-24-2021 , 09:40   Re: Max Usage Of A Item In Shop
Reply With Quote #3

Quote:
Originally Posted by AnimalMonster View Post
Suggestions / Requests , wrong section buddy and provide sma to the item shop next time.
How is it the wrong section when he's asking how to do it?

--------------

Create a global variable with 2 dimensions - the player index and item index.
Increase [id][item] by 1 when buying the item.
Check if [id][item] reached your desired limit, stop the code if it did.
When the player dies, loop through all player indexes and use arrayset() to reset the limit for each item.
__________________

Last edited by OciXCrom; 03-24-2021 at 09:40.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
AnimalMonster
Senior Member
Join Date: May 2020
Old 03-24-2021 , 15:23   Re: Max Usage Of A Item In Shop
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
How is it the wrong section when he's asking how to do it?

--------------

Create a global variable with 2 dimensions - the player index and item index.
Increase [id][item] by 1 when buying the item.
Check if [id][item] reached your desired limit, stop the code if it did.
When the player dies, loop through all player indexes and use arrayset() to reset the limit for each item.
Umm, i thought we wanted us to edit the plugin? + he didn't provide any sma either
AnimalMonster is offline
DON KHAN 1
Senior Member
Join Date: Mar 2019
Location: Pakistan
Old 03-24-2021 , 15:34   Re: Max Usage Of A Item In Shop
Reply With Quote #5

Can u define me with some examples? it would be great.
__________________
Facebook
My YouTube
Ro{Y}aL WarLanD CommuniTy
Selling Zombie CSO 4.3 Money System Mod
DON KHAN 1 is offline
Crackhead69
Member
Join Date: Feb 2021
Old 03-25-2021 , 06:35   Re: Max Usage Of A Item In Shop
Reply With Quote #6

That's just one way of doing it
PHP Code:
#include <amxmodx>

new ItemUsed // its purpose is Global
new ItemId[33// its purpose is to hold the items

public plugin_init()    
    
register_clcmd"say /menu","AwesomeMenu" );

public 
AwesomeMenuid )
{
    new 
menu menu_create"Look at this awesome Menu!:""menu_handler" );

    
menu_additemmenu"I'm Selection #1""");
    
menu_additemmenu"I'm Selection #2""");

    
menu_setpropmenuMPROP_EXITMEXIT_ALL );

    
menu_displayidmenu);

}

public 
menu_handleridmenuitem )
{
    if(
ItemId[item] == ItemUsed//if the selected item equals 5 (gItemUsed) we return
    
{
        
client_print(id,print_chat,"Limit reached")
        return
    }
    
    
ItemId[item]++ //we increase the picked item's number by 1

    
switch(item)
    {
        case 
0:client_printidprint_chat"Item 1 can be used: %i/%i times"ItemId[item],ItemUsed)
        case 
1:client_printidprint_chat"Item 2 can be used: %i/%i times"ItemId[item],ItemUsed)
    }

Crackhead69 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-25-2021 , 08:29   Re: Max Usage Of A Item In Shop
Reply With Quote #7

That's a global limit for all items, not per player.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 03-25-2021 , 10:55   Re: Max Usage Of A Item In Shop
Reply With Quote #8

Normally you would do something like this instead.

PHP Code:
enum _:eShopItems {

        
ITEM_NAME[32],
        
ITEM_COST,
        
ITEM_MAX_USES,
        
etc...
};

// Here are your item definitions
new const g_ShopItems[MAX_ITEMS][eShopItems] {

        { 
"Item 1"160005etc.}, 
        { 
"Second item"80003etc.}, 
        
etc.

Then accordingly acces each element using the enumeration for better coordination. What you did there was define a max usage for every item.

Last edited by redivcram; 03-25-2021 at 12:30. Reason: Minor corrections
redivcram is offline
Crackhead69
Member
Join Date: Feb 2021
Old 03-25-2021 , 11:59   Re: Max Usage Of A Item In Shop
Reply With Quote #9

Yes, my bad.
Ideally then it should be somewhat like this
PHP Code:
#include <amxmodx>

new ItemUsed[33][33]

enum _:Items
{
    
Name[64],
    
Limit[33]
}

new const 
szItemInfo[2][Items] =
{
    {
"Item 1"5},
    {
"Item 2"3}
}

public 
plugin_init()
    
register_clcmd("say /menu","openmenu")

public 
openmenu(id)
{
    new 
menu menu_create("Testing","menu_handle")
    for(new 
ii<2i++)
    {
        static 
szMenuTitle[64], szInfo[3]
        
        
formatex(szMenuTitlecharsmax(szMenuTitle), "%s",szItemInfo[i][Name])
        
num_to_str(iszInfocharsmax(szInfo))
        
menu_additem(menuszMenuTitleszInfo)
    }
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    
menu_display(idmenu0);
    return 
PLUGIN_HANDLED
}

public 
menu_handle(id,menu,item){
    if(
item == MENU_EXIT || !is_user_alive(id))
    {
        
menu_cancel(id)
        return
    }
    if(
ItemUsed[id][item]++ >=  szItemInfo[item][Limit])
    {
        
client_print(id,print_chat,"Item limit reached")
        return
    }
    switch(
item){
        case 
0:client_print(idprint_chat"Option 1");
        case 
1:client_print(idprint_chat"Option 2");
    }

Crackhead69 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 03-25-2021 , 12:28   Re: Max Usage Of A Item In Shop
Reply With Quote #10

PHP Code:
enum _:Items
{
    
Name[64],
    
Limit[33]

Why is Limit an array? It only takes one number. Name is an array of characters or a string with a maximum of 64 characters available in this case.


If you're on AMXX 1.9 or greater, consider ditching the formatex function and using fmt(). You'd get this:
PHP Code:
    for(new ii<2i++)
    {
        static 
szInfo[3]
        
        
num_to_str(iszInfocharsmax(szInfo))
        
menu_additem(menufmt("%s"szItemInfo[i][Name]), szInfo)
    } 
Be careful though, if you were to use fmt inside another fmt, you'd get errors, but this is a much better approach in your case.


Also, there is no need to increment ItemUsed in there if the condition results in false, just put it under the switch statement.

Last edited by redivcram; 03-25-2021 at 12:29.
redivcram is offline
Reply



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 17:51.


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