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_EditValue, 0, "Open a menu to edit the value");
}
public Action Command_EditValue(int client, int args){
if(client < 1)
return Plugin_Handled;
//Save the value to out temporary one.
g_iValTemp = g_iValue;
g_hMenu = Menu_Build();
DisplayMenu(g_hMenu, client, MENU_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_iValue, g_iValTemp);
AddMenuItem(hMenu, "", "+");
AddMenuItem(hMenu, "", "-");
AddMenuItem(hMenu, "", "Apply");
AddMenuItem(hMenu, "", "Apply and Close");
return hMenu;
}
public int Menu_Manager(Handle hMenu, MenuAction maAction, int client, int 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_hMenu, client, MENU_TIME_FOREVER);
}
case 1:{ //Selected "-"
g_iValTemp--;
//Let's update the menu and display it back up
g_hMenu = Menu_Build();
DisplayMenu(g_hMenu, client, MENU_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_hMenu, client, MENU_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.
}