Hace 1 año y medio, tuve la duda de como hacer un menú con una prop personalizada, y bueno, hoy me he puesto a pensar y lo he resuelto.
Si alguien quiere hacer un tutorial explicando cada parte de este código es libre hacerlo
Os dejo un ejemplo muy sencillo. Las opciones del menu son mensajes, y la prop decide si printarlos en el chat, center, o console
EDIT: Si no usais AMXX 1.8.3 tenéis que definir MAX_PLAYERS:
CODIGO: (debajo está la descarga)
Click en las imágenes para aumentarlas
Si alguien quiere hacer un tutorial explicando cada parte de este código es libre hacerlo
Os dejo un ejemplo muy sencillo. Las opciones del menu son mensajes, y la prop decide si printarlos en el chat, center, o console
EDIT: Si no usais AMXX 1.8.3 tenéis que definir MAX_PLAYERS:
Código PHP:
#define MAX_PLAYERS 32
CODIGO: (debajo está la descarga)
Código PHP:
#include <amxmodx>
#include <amxmisc>
#define PLUGIN "Prop"
#define VERSION "1.1"
#define AUTHOR "sNezz"
new option[MAX_PLAYERS];
new const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
new const g_eMensajes[][] = {
"Pagina 1",
"Hola",
"Adios",
"sNezz",
"Jaja",
"Mas cosas",
"Pagina 2",
"jwuaizl",
"jaiziwb",
"viva zonazero",
"hehexd",
"no se que poner",
"Pagina 3",
"ya queda poco",
"te amo raulitop",
"al fin se acaba"
};
new max_paginas, g_pagina[MAX_PLAYERS] = 0, ult_pagina_items;
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /menu", "ShowMenuProp");
/* a partir del numero de mensajes calculamos el numero de paginas que necesitaremos, sabiendo que mostraremos maximo 6 items por pagina */
new Float:resultado = sizeof g_eMensajes / float(6);
new IntResultado = floatround(Float:resultado, floatround_floor);
new Float:ult_pagina_res = (resultado - IntResultado) * float(6);
if( float(IntResultado) == resultado )
max_paginas = IntResultado;
else
{
ult_pagina_items = floatround(Float:ult_pagina_res , floatround_round);
max_paginas = ++IntResultado;
}
register_menu("Menu Prop", KEYSMENU, "menuprop_handler");
}
public ShowMenuProp(id, pagina){
static iLen, szData[512], optionText[MAX_PLAYERS][8], espacios[13];
if( pagina > max_paginas )
return PLUGIN_HANDLED;
switch(option[id]){
case 0:
optionText[id] = "Chat";
case 1:
optionText[id] = "Center";
case 2:
optionText[id] = "Console";
}
iLen = 0
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\wMenu \yProp \w(Pagina %i/%i)^n^n", pagina+1, max_paginas);
for(new i; i < max_paginas; i++){
if(pagina == i)
{
for(new j; j < 10; j++){
if( j < getItemsPerPage(id) )
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r%i. %s%s^n", j+1, !(j%2) ? "\w":"\y", g_eMensajes[j + i*6]);
else if( j == getItemsPerPage(id) ){
espacios = "";
for(new k; k < 7-getItemsPerPage(id); k++)
formatex(espacios, 31, "%s^n", espacios);
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r%i. %s%s%s", j+1, !(j%2) ? "\w":"\y", g_eMensajes[j + i*6], espacios);
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r7. %s^n^n", optionText[id]);
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r8. %sVolver^n", !i ? "\d":"\y");
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r9. %sSig. Pagina^n", ++i >= max_paginas ? "\d":"\y");
iLen += formatex(szData[iLen], charsmax(szData) - iLen, "\r0. \ySalir");
}
}
}
}
show_menu(id, KEYSMENU, szData, -1, "Menu Prop");
return PLUGIN_HANDLED;
}
getItemsPerPage(id)
{
if(g_pagina[id]+1 == max_paginas)
return ult_pagina_items-1;
else
return 5;
}
public menuprop_handler(id, key)
{
if(!is_user_connected(id) || key == 9)
{
g_pagina[id] = 0;
return PLUGIN_HANDLED;
}
new print_option = !option[id] ? print_chat:(option[id] == 1 ? print_center:print_console)
if(key == 6)
{
if(option[id] < 2)
option[id]++;
else
option[id] = 0;
ShowMenuProp(id, g_pagina[id]);
}
for(new i; i < max_paginas; i++){
if(g_pagina[id] == i)
{
if( 0 <= key <= getItemsPerPage(id) )
{
client_print(id, print_option, "%s", g_eMensajes[key + i*6]);
g_pagina[id] = 0;
}
else if( key > getItemsPerPage(id) && key < 7 )
ShowMenuProp(id, g_pagina[id]);
else{
switch(key)
{
case 7:
{
if(i)
g_pagina[id]--;
ShowMenuProp(id, g_pagina[id]);
}
case 8:
{
if(++i < max_paginas)
g_pagina[id]++;
ShowMenuProp(id, g_pagina[id]);
}
}
}
}
}
return PLUGIN_HANDLED;
}
Click en las imágenes para aumentarlas
Dejad de reportarme diciendo que mis plugins no son mios ayyylmao