View Single Post
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 02-29-2016 , 19:54   Re: [CSS]Dynamic menu with values
Reply With Quote #2

Here's a basic concept:
PHP Code:
#pragma semicolon 1

int        g_iValue    0;
int        g_iValTemp    0;    //Let's not edit the actual value right away, let's edit this one and apply it to the actual one when we're done.
Handle    g_hMenu INVALID_HANDLE;

public 
void OnPluginStart(){

    
RegAdminCmd("sm_editvalue"Command_EditValue0"Open a menu to edit the value");

}

public 
Action Command_EditValue(int clientint args){

    if(
client 1)
        return 
Plugin_Handled;

    
//Save the value to out temporary one.
    
g_iValTemp g_iValue;

    
g_hMenu Menu_Build();
    
DisplayMenu(g_hMenuclientMENU_TIME_FOREVER);
    
    return 
Plugin_Handled;
    

}

//We'll trigger this function each time we'd like to update the menu.
Handle Menu_Build(){

    
Handle hMenu CreateMenu(Menu_Manager);
    
    
SetMenuTitle(hMenu"Edit Value (Current: %d, Temporary: %d)"g_iValueg_iValTemp);
    
    
AddMenuItem(hMenu"""+");
    
AddMenuItem(hMenu"""-");
    
AddMenuItem(hMenu"""Apply");
    
AddMenuItem(hMenu"""Apply and Close");
    
    return 
hMenu;

}

public 
int Menu_Manager(Handle hMenuMenuAction maActionint clientint iPos){

    
//We want this function to run only when client selects something.
    
if(maAction != MenuAction_Select)
        return 
0;

    switch(
iPos){
    
        case 
0:{    //Selected "+"
    
            
g_iValTemp++;
            
            
//Let's update the menu and display it back up
            
g_hMenu Menu_Build();
            
DisplayMenu(g_hMenuclientMENU_TIME_FOREVER);
        
        }
    
        case 
1:{    //Selected "-"
    
            
g_iValTemp--;
            
            
//Let's update the menu and display it back up
            
g_hMenu Menu_Build();
            
DisplayMenu(g_hMenuclientMENU_TIME_FOREVER);
        
        }
    
        case 
2:{    //Selected "Apply"
    
            
g_iValue g_iValTemp;
            
UpdateValue();
            
            
//Let's update the menu and display it back up
            
g_hMenu Menu_Build();
            
DisplayMenu(g_hMenuclientMENU_TIME_FOREVER);
        
        }
    
        case 
3:{    //Selected "Apply and Close"
    
            
g_iValue g_iValTemp;
            
UpdateValue();
        
        }
    
    }
    
    return 
1;

}

void UpdateValue(){

    
PrintToChatAll("Sending %d to MySQL"g_iValue);
    
//Do the MySQL magic here.


Phil25 is offline