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

[CSS]Dynamic menu with values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
keygens
Senior Member
Join Date: Mar 2010
Location: Somewhere
Old 02-29-2016 , 18:57   [CSS]Dynamic menu with values
Reply With Quote #1

Hello guys. How do i can create menu, where i choice menu items, and after that press "apply" button, and this value will update my mysql base in specific table?
Example what i need:
-----------------------------
Test menu
1. 10 [+ / -] - can be dynamically change this value if i press button 1.
2. Apply button - If i will press this button, it will update my db for 10 value and etc.
-----------------------------
I need just a sample code. Thanks in advance.
keygens is offline
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
keygens
Senior Member
Join Date: Mar 2010
Location: Somewhere
Old 02-29-2016 , 20:00   Re: [CSS]Dynamic menu with values
Reply With Quote #3

Quote:
Originally Posted by Phil25 View Post
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.


Fantastic! Thanks you!
keygens 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 18:34.


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