Criar menus tanto em cleo quando em lua é algo até chato, ficar pondo DUMMY em entradas invalidas, cria arquivo gxt ou usar add_text_label sempre complica mais, então para facilitar na criação de menus criei esta função. não notei bugs no uso dela.
Função
Basta copiar a função e por no script que esteja fazendo. Ela é completa, des de pegar o resultado a congelar o player enquanto seleciona uma opção.
Código: Selecionar tudo
-- descrição
-- table_name: table com entradas do menu.
-- pos_x: posição X
-- pos_y : posição Y
-- return_text: [true] = o menu retornara o texto da opção escolhida, [false] = o menu retornara numero da opção.
-- button: defina o botão que ativa o menu.
function simple_menu(table_name,pos_x,pos_y,return_text,button)
if button == nil then button = 11 end -- yes
local labels = {};
setPlayerControl(PLAYER_HANDLE,false);
setCameraBehindPlayer();
for i=1, #table_name do
if table_name[i] then
labels[i] = setFreeGxtEntry(table_name[i]);
else
labels[i] = "DUMMY";
end
end
local menu = createMenu(labels[1],pos_x,pos_y,300.0,1,true,true,1);
setMenuColumn(menu,0,labels[2],labels[3],labels[4],labels[5],labels[6],labels[7],labels[8],labels[9],labels[10],labels[11],labels[12],labels[13]);
while not isButtonPressed(PLAYER_HANDLE,button) do
wait(0);
end
local option = getMenuItemSelected(menu);
deleteMenu(menu);
while isButtonPressed(PLAYER_HANDLE,button) do
wait(0);
end
setPlayerControl(PLAYER_HANDLE,true);
restoreCamera();
for i=1, #labels do
if labels[i]~="DUMMY" then
clearGxtEntry(labels[i]);
end
end
if return_text then
return table_name[option+3];
end
return option;
end
Uso
Basta criar uma table com titulo, descrição e opções
Código: Selecionar tudo
local meu_menu = {
[1] = "meu titulo";
[2] = "minha descricao";
[3] = "opt 1";
[4] = "opt 2";
[5] = "opt 3";
[6] = "opt 4";
}
Na função fica assim
Código: Selecionar tudo
function main()
while true do
wait(80);
if testCheat('teste') then
local result = simple_menu(meu_menu,90.0,90.0,true,15);
printStringNow(result,1500);
end
end
end
**Adicionado o argumento button
para definir o botão de confirmar.