View Single Post
Mesharsky How2Kill
AlliedModders Donor
Join Date: May 2017
Location: Poland
Old 05-08-2019 , 00:38   Re: Getting first value of the menu function and take points.
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
If you ever plan on changing the point values on this menu, you may want to add MenuAction_DrawItem to the actions list and then use that action in your menu handler to check the items. Something like this:

PHP Code:
//When you create the menu
Menu next = new Menu(PointAct_MenuHandlerMENU_ACTIONS_DEFAULT|MenuAction_DrawItem);

// In your menu handler
switch (action)
{
    
// code to retrieve the client here

    
case MenuAction_Select:
    {
        
// Your other existing menu code here
    
}

    case 
MenuAction_End:
    {
        
delete menu;
    }

    
// param1 is the admin calling the menu, param2 is the menu item
    // If you changed these variable names in your handler declaration, change them here too
    
case MenuAction_DrawItem:
    {
        
char item[9];
        
int style;
        
menu.GetItem(param2itemsizeof(item), style);

        if (
StrEqual(item"-SELECT-") || StrEqual(item"-CLIENT-"))
            return 
style;

        
int itemValue StringToInt(item);
        if (
g_iPoints[client] < itemValue)
            
style ITEMDRAW_DISABLED;

        return 
style;
    }

    return 
0;

Thank you for fast reply, your code doesn`t really work for me, but i never createdmenu in sourcepawn like you in my life im still going to study that method.

My whole code for this is down below, i actually tried to rewrite for your method, but i got lots of errors, so i just keeped it my way.

PHP Code:
#define LoopItemCount(%1) for(int %1 = 0; %1 < menu.ItemCount; %1++)

public Action CreateMenu_AddRemovePoints(int adminint clientint iSelect)
{
    
Menu next = new Menu(PointAct_MenuHandler);
    
char frm[128];
    
char pname[MAX_NAME_LENGTH 1];
    
GetClientName(clientpnamesizeof pname);
    
Format(frmsizeof frm"Ranks - %s"pname);
    
next.SetTitle(frm);
    
    
next.AddItem("1""1 points");
    
next.AddItem("5""5 points");
    
next.AddItem("10""10 points");
    
next.AddItem("20""20 points");
    
next.AddItem("50""50 points");
    
next.AddItem("1000""1000 points");
    
next.AddItem("2500""2500 points");
    
next.AddItem("5000""5000 points");
    
    
char sInfo[12];

    
Format(sInfosizeof(sInfo), "%d"iSelect);
    
next.AddItem("-SELECT-"sInfoITEMDRAW_IGNORE);
    
Format(sInfosizeof(sInfo), "%d"client);
    
next.AddItem("-CLIENT-"sInfoITEMDRAW_IGNORE);
    
    
next.ExitButton true;
    
next.Display(admin60);
}

public 
int PointAct_MenuHandler(Menu menuMenuAction actionint param1int param2)
{
    
char sInfo[12], sDane[12];
    
int iSelectclient;
    
LoopItemCount(i)
    {
        
menu.GetItem(isInfosizeof(sInfo), _sDanesizeof(sDane));

        if (
StrEqual(sInfo"-SELECT-"))
            
iSelect StringToInt(sDane);
        
        if (
StrEqual(sInfo"-CLIENT-"))
            
client StringToInt(sDane);
    }
    if (
action == MenuAction_Select)
    {
        
char item[32];
        
menu.GetItem(param2itemsizeof(item));
        if (
IsValidClient(client))
        {
            if (
iSelect == 1)
                
g_iPoints[client] +=StringToInt(item);
            else if (
iSelect == 2)
                if(
g_iPoints[client] < StringToInt(item))
                {
                    
CPrintToChat(client"{darkred}[✖] {yellow}You can't choose this option because player will get points < 0"g_iPoints[client]);
                }
                else
                {
                    
g_iPoints[client] -= StringToInt(item);
                }
            
            
CreateMenu_AddRemovePoints(param1clientiSelect);
            
CheckRank(client);
        }
    }
    else if (
action == MenuAction_End)
        
delete menu;


Last edited by Mesharsky How2Kill; 06-17-2019 at 20:37.
Mesharsky How2Kill is offline