I want to make a menu as the "Ban Menu", so that an admin can give credits to a player. The menu is displayed when the admin writes the command. To simplify, I have just pasted the code of the menu:
Code:
new g_menuPosition[33]
new g_menuPlayers[33][32]
new g_menuPlayersNum[33]
new g_menuOption[33]
new g_menuCredits[33]
public plugin_init() {
register_menucmd(register_menuid("Credits Menu"),1023,"credits_menu")
return PLUGIN_CONTINUE
}
displayCreditsMenu(id,pos) {
if (pos < 0) return
get_players(g_menuPlayers[id],g_menuPlayersNum[id])
new menuBody[512]
new b = 0
new i
new name[32]
new start = pos * 7
if (start >= g_menuPlayersNum[id])
start = pos = g_menuPosition[id] = 0
new len = format(menuBody,511,"\yPage %d/%d^nKey Credits Player\w^n^n" ,pos+1,( g_menuPlayersNum[id] / 7 + ((g_menuPlayersNum[id] % 7) ? 1 : 0 )) )
new end = start + 7
new keys = MENU_KEY_0|MENU_KEY_8
if (end > g_menuPlayersNum[id])
end = g_menuPlayersNum[id]
for (new a = start; a < end; ++a) {
i = g_menuPlayers[id][a]
keys |= (1<<b)
get_user_name(i,name,31)
if ( g_credits[i]<5 ) // set credits in red if <5, if not in blue
len += format(menuBody[len],511-len,"%d. \r%d \w%s^n",++b,g_credits[i],name)
else
len += format(menuBody[len],511-len,"%d. \b%d \w%s^n",++b,g_credits[i],name)
}
if ( !g_menuCredits[id] ) // set by default the credits to 10 to give
g_menuCredits[id]=10
len += format(menuBody[len],511-len,"^n\y8. Give %d credits^n", g_menuCredits[id] )
if (end != g_menuPlayersNum[id]) {
keys |= MENU_KEY_9
format(menuBody[len],511-len,"^n\y9. Next...^n0. ...Back\w")
}
else format(menuBody[len],511-len,"^n\y0. ...Back\w")
show_menu(id,keys,menuBody,-1,"Credits Menu")
}
public credits_menu(id,key) {
switch (key) {
case 7: { // change the value of credits to give
++g_menuOption[id]
g_menuOption[id] %= 3
switch(g_menuOption[id]){
case 0: g_menuCredits[id] = 10
case 1: g_menuCredits[id] = 20
case 2: g_menuCredits[id] = 5
}
displayCreditsMenu(id,g_menuPosition[id])
}
case 8: displayCreditsMenu(id,++g_menuPosition[id]) // go to the next page
case 9: displayCreditsMenu(id,--g_menuPosition[id]) // go to the previous page
default: {
new player = g_menuPlayers[id][g_menuPosition[id] * 7 + key]
new nameplayer[32]
new nameadmin[32]
get_user_name(player,nameplayer,31)
get_user_name(id,nameadmin,31)
set_hudmessage(255, 0, 0, 0.05, 0.6, 0, 8.0, 10.0, 0.1, 0.5, 8)
g_credits[player]+=g_menuCredits[player]
show_hudmessage(0,"The ADMIN %s^nhas given %d credits to %s", nameadmin, g_menuCredits[player], nameplayer)
displayCreditsMenu(id,g_menuPosition[id])
}
}
return PLUGIN_HANDLED
}
So what is the problem? The first time, the menu works fine, I can change the credits value and give credits to players.
But the second time (when the menu has been closed and opened back), whatever the key I press, the menu closes and nothing happens! And with debug mod, AMXX says:
I've spent 4 hours with changing definitions of keys (MENU_KEY_X or 1<<X) but it does the same thing.
, 1 month on this plugin...