Make another menu function outside of the current menu function, lets call it MenuSlap. So it should be like
public MenuSlap(id) {}
In this function create a menu. The first item (item=0) is for switching. The following items are for players. So you will know if the item equals 0 then switch option is selected. If not, we will get the items info to find the data (which is player id). We will use a global boolean array to find that if the admin wants to slay or slap the players. And we will use the same variable to determine the switch items name.
it may be a little bit confusing but you will understand it with this example
PHP Code:
new bool:slay[33];
public MenuSlap(id) {
new menu = menu_create("Slay/Slap Menu","MenuSlapHandler");
// First item is for switching
menu_additem(menu, slay[id] ? "Slay" : "Slap",""); // if slay[id] == true then "Slay" else "Slap"
// Followings will be for player list
new players[32],iNum;
get_players(players,iNum) // Search for all players
static name[32], data[6],tempid;
// Loop through all players
for(new i;i<iNum;i++) {
tempid = players[i];
get_user_name(tempid,name,31);
num_to_str(tempid,data,5); // Convert the id from int to string.
menu_additem(menu,name,data);
}
menu_display(id,menu)
return PLUGIN_HANDLED;
}
public MenuSlapHandler(id,menu,item) {
if(item == MENU_EXIT) {
// Exit is selected, then we must return to the main menu.
ShowMenu(id);
menu_destroy(menu)
return PLUGIN_HANDLED
}
if(!item) { // if the first item is selected
slay[id] = !slay[id] // switch the value of the boolean
MenuSlap(id) // Display the menu again, or it will be destroyed and we will have to enter the menu again.
return PLUGIN_HANDLED
}
// if the first item is not selected then a player is selected for an action.
// lets find the id of the selected player
new name[32], data[6], access, callback;
menu_item_getinfo(menu,item,access,data,charsmax(data),name,charsmax(name),callback);
new targetId = str_to_num(data);
if(is_user_connected(targetId)) {
// then target has leaved the game
MenuSlap(id) // Maybe there are still players that we want to slay/slap, show the menu again
return PLUGIN_HANDLED
}
if(slay[id]) {
// we will kill the targetId here
}
else {
// we will slap the targetId here
}
MenuSlap(id) // optional
menu_destroy(menu)
return PLUGIN_HANDLED
}