12/01/2019, 09:10 PM
(Última modificación: 12/01/2019, 09:15 PM por injurefect. Edited 1 time in total.)
Es un menu de habilidades, queria saber si es posible optimizarlo en uno solo, para luego agregar el caso y el menu al menu principal de mi mod con un solo titulo y 2 submenus.
Código PHP:
public show_menu_upgrades_human(id)
{
static menu[999], len; len = 0
len += formatex(menu[len], sizeof menu - 1 - len, "\yMejoras Humanos^n^n") // Titulo
len += formatex(menu[len], sizeof menu - 1 - len, "\r-\y Tenes\w %s\y puntos humanos y\w %s\y gastados^n^n", add_point(g_puntos[id][0]), add_point(g_gastados[id][0]))
for (new i; i < sizeof hab_hm; i++)
{
if (g_habilidad[id][0][i] < hab_hm[i][MAX_HAB_H])
{
if (g_puntos[id][0] >= ammount_cost(g_habilidad[id][0][i]))
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s \r[\w%d-%d\r][\w%s punto%s\r]^n", i+1, hab_hm[i][Nameh], g_habilidad[id][0][i], hab_hm[i][MAX_HAB_H], add_point(ammount_cost(g_habilidad[id][0][i])), ammount_cost(g_habilidad[id][0][i]) == 1 ? "" : "s")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\d %s \r[\d%d-%d\r][\d%s punto%s\r]^n", i+1, hab_hm[i][Nameh], g_habilidad[id][0][i], hab_hm[i][MAX_HAB_H], add_point(ammount_cost(g_habilidad[id][0][i])), ammount_cost(g_habilidad[id][0][i]) == 1 ? "" : "s")
}
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\d %s \r[\dMAX\r]^n", i+1, hab_hm[i][Nameh])
}
len += formatex(menu[len], sizeof menu - 1 - len, "^n\r8.\w Resetear mejoras^n^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r0.\w Salir")
show_menu(id, KEYSMENU, menu, -1, "Menu Upgrades Human")
}
public show_menu_upgrades_zombie(id)
{
static menu[999], len; len = 0
len += formatex(menu[len], sizeof menu - 1 - len, "\yMejoras Zombie^n^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r-\y Tenes\w %s\y puntos zombie y\w %s\y gastados^n^n", add_point(g_puntos[id][1]), add_point(g_gastados[id][1]))
for (new i; i < sizeof hab_zm; i++)
{
if (g_habilidad[id][1][i] < hab_zm[i][MAX_HAB])
{
if (g_puntos[id][1] >= ammount_cost(g_habilidad[id][1][i]))
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s \r[\w%d-%d\r][\w%s punto%s\r]^n", i+1, hab_zm[i][Name], g_habilidad[id][1][i], hab_zm[i][MAX_HAB], add_point(ammount_cost(g_habilidad[id][1][i])), ammount_cost(g_habilidad[id][1][i]) == 1 ? "" : "s")
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\d %s \r[\d%d-%d\r][\d%s punto%s\r]^n", i+1, hab_zm[i][Name], g_habilidad[id][1][i], hab_zm[i][MAX_HAB], add_point(ammount_cost(g_habilidad[id][1][i])), ammount_cost(g_habilidad[id][1][i]) == 1 ? "" : "s")
}
else
len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\d %s \r[\dMAX\r]^n", i+1, hab_zm[i][Name])
}
len += formatex(menu[len], sizeof menu - 1 - len, "^n\r8.\w Resetear mejoras^n^n")
len += formatex(menu[len], sizeof menu - 1 - len, "\r0.\w Salir")
show_menu(id, KEYSMENU, menu, -1, "Menu Upgrades Zombie")
}
// EL key de las mejoras humanas
public menu_upgrades_human(id, Key)
{
switch (Key)
{
case 7:
{
if (g_gastados[id][0] >= 1)
{
for (new i; i < sizeof hab_hm; i++)
{
g_habilidad[id][0][i] = 0
g_puntos[id][0] += g_gastados[id][0]
g_gastados[id][0] = 0
}
show_menu_upgrades_human(id)
}
else
{
show_menu_upgrades_human(id)
}
}
}
if (g_habilidad[id][0][Key] < hab_hm[Key][MAX_HAB_H])
{
if (g_puntos[id][0] >= ammount_cost(g_habilidad[id][0][Key]))
{
g_puntos[id][0] -= ammount_cost(g_habilidad[id][0][Key])
g_gastados[id][0] += ammount_cost(g_habilidad[id][0][Key])
g_habilidad[id][0][Key]++
show_menu_upgrades_human(id)
}
else
{
show_menu_upgrades_human(id)
}
}
else
{
show_menu_upgrades_human(id)
}
return PLUGIN_HANDLED;
}
public menu_upgrades_zombie(id, Key)
{
switch (Key)
{
case 7:
{
if (g_gastados[id][1] >= 1)
{
for (new i; i < sizeof hab_zm; i++)
{
g_habilidad[id][1][i] = 0
g_puntos[id][1] += g_gastados[id][1]
g_gastados[id][1] = 0
}
show_menu_upgrades_zombie(id)
}
else
{
show_menu_upgrades_zombie(id)
}
}
}
if (g_habilidad[id][1][Key] < hab_zm[Key][MAX_HAB])
{
if (g_puntos[id][1] >= ammount_cost(g_habilidad[id][1][Key]))
{
g_puntos[id][1] -= ammount_cost(g_habilidad[id][1][Key])
g_gastados[id][1] += ammount_cost(g_habilidad[id][1][Key])
g_habilidad[id][1][Key]++
show_menu_upgrades_zombie(id)
}
else
{
show_menu_upgrades_zombie(id)
}
}
else
{
show_menu_upgrades_zombie(id)
}
return PLUGIN_HANDLED;
}