2009-04-14 23:33:06 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: classmenus.inc
|
|
|
|
* Description: Provides functions for managing class menus.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
/* ------------------------------------
|
|
|
|
*
|
|
|
|
* MAIN CLASS MENU
|
|
|
|
*
|
|
|
|
* ------------------------------------
|
|
|
|
*/
|
|
|
|
|
2009-04-14 23:33:06 +02:00
|
|
|
/**
|
|
|
|
* Displays the main class menu with the players class settings.
|
2009-04-15 23:40:45 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
2009-04-14 23:33:06 +02:00
|
|
|
*/
|
|
|
|
ClassMenuMain(client)
|
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
new Handle:menu = CreateMenu(ClassMenuMainHandle);
|
2009-04-14 23:33:06 +02:00
|
|
|
|
|
|
|
SetGlobalTransTarget(client);
|
2009-04-15 23:40:45 +02:00
|
|
|
SetMenuTitle(menu, "%t\n", "!zclass title");
|
2009-04-14 23:33:06 +02:00
|
|
|
|
|
|
|
decl String:zombieclass[128];
|
|
|
|
decl String:humanclass[128];
|
|
|
|
decl String:adminclass[128];
|
|
|
|
|
|
|
|
decl String:zombieselect[128];
|
|
|
|
decl String:humanselect[128];
|
|
|
|
decl String:adminselect[128];
|
|
|
|
|
|
|
|
decl String:inadminmnode[128];
|
2009-04-15 23:40:45 +02:00
|
|
|
decl String:adminmode[128];
|
|
|
|
decl String:toggleadminmode[128];
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-18 02:22:13 +02:00
|
|
|
// Get number of enabled classes per team.
|
|
|
|
new zombiecount = ClassCountTeam(ZR_CLASS_TEAM_ZOMBIES);
|
|
|
|
new humancount = ClassCountTeam(ZR_CLASS_TEAM_ZOMBIES);
|
|
|
|
new admincount = ClassCountTeam(ZR_CLASS_TEAM_ZOMBIES);
|
|
|
|
|
|
|
|
// Set draw style on class options depending on number of enabled classes.
|
|
|
|
new zombie_itemdraw = (zombiecount > 1) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
|
|
|
|
new human_itemdraw = (humancount > 1) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
|
|
|
|
new admin_itemdraw = (admincount > 1) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
|
|
|
|
|
2009-04-14 23:33:06 +02:00
|
|
|
// Check if the player is in admin mode.
|
2009-04-15 23:40:45 +02:00
|
|
|
if (ClassPlayerInAdminMode[client])
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
|
|
|
// Notify the player.
|
2009-04-15 23:40:45 +02:00
|
|
|
Format(inadminmnode, sizeof(inadminmnode), "%t\n", "!zclass admin mode enabled");
|
|
|
|
AddMenuItem(menu, "", inadminmnode, ITEMDRAW_RAWLINE);
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// List zombie class options.
|
2009-04-15 23:40:45 +02:00
|
|
|
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES], zombieclass, sizeof(zombieclass), ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
Format(zombieselect, sizeof(zombieselect), "%t\n %s", "!zclass zombie", zombieclass);
|
2009-04-18 02:22:13 +02:00
|
|
|
AddMenuItem(menu, "", zombieselect, zombie_itemdraw);
|
2009-04-14 23:33:06 +02:00
|
|
|
|
|
|
|
// List human class options.
|
2009-04-15 23:40:45 +02:00
|
|
|
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_HUMANS], humanclass, sizeof(humanclass), ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
Format(humanselect, sizeof(humanselect), "%t\n %s", "!zclass human", humanclass);
|
2009-04-18 02:22:13 +02:00
|
|
|
AddMenuItem(menu, "", humanselect, human_itemdraw);
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Only display admin class options for admins, and if admin classes exist.
|
|
|
|
if (ZRIsClientAdmin(client) && ClassCountTeam(ZR_CLASS_TEAM_ADMINS))
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
// List admin class options.
|
|
|
|
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_ADMINS], adminclass, sizeof(adminclass), ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
Format(adminselect, sizeof(adminselect), "%t\n %s", "!zclass admin", adminclass);
|
2009-04-18 02:22:13 +02:00
|
|
|
AddMenuItem(menu, "", adminselect, admin_itemdraw);
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
// Set admin mode status string.
|
2009-04-14 23:33:06 +02:00
|
|
|
if (ClassPlayerAdminMode[client])
|
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
Format(adminmode, sizeof(adminmode), "%t", "On");
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
Format(adminmode, sizeof(adminmode), "%t", "Off");
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 02:22:13 +02:00
|
|
|
// Spacer. ITEMDRAW_SPACER not used because it use a slot.
|
|
|
|
AddMenuItem(menu, "", " ", ITEMDRAW_RAWLINE);
|
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
// Show admin mode toggle option.
|
|
|
|
Format(toggleadminmode, sizeof(toggleadminmode), "%t\n %s", "!zclass admin mode toggle", adminmode);
|
2009-04-18 02:22:13 +02:00
|
|
|
AddMenuItem(menu, "", toggleadminmode, admin_itemdraw);
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
SetMenuExitBackButton(menu, true);
|
|
|
|
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main class menu handle.
|
|
|
|
*/
|
|
|
|
public ClassMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
|
|
|
|
{
|
|
|
|
switch (action)
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
case MenuAction_Select:
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
switch(slot)
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
ClassMenuSelect(client, ZR_CLASS_TEAM_ZOMBIES);
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
ClassMenuSelect(client, ZR_CLASS_TEAM_HUMANS);
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
ClassMenuSelect(client, ZR_CLASS_TEAM_ADMINS);
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
2009-04-18 02:22:13 +02:00
|
|
|
// ClassToggleAdminMode(client);
|
|
|
|
ClassMenuMain(client);
|
2009-04-15 23:40:45 +02:00
|
|
|
}
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-15 23:40:45 +02:00
|
|
|
case MenuAction_End:
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-15 23:40:45 +02:00
|
|
|
CloseHandle(menu);
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
2009-04-15 23:40:45 +02:00
|
|
|
case MenuAction_Cancel:
|
|
|
|
{
|
|
|
|
if (slot == MenuCancel_ExitBack)
|
|
|
|
{
|
2009-04-29 01:58:41 +02:00
|
|
|
MenuMain(client);
|
2009-04-15 23:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------
|
|
|
|
*
|
|
|
|
* ZOMBIE CLASS SELECTION MENU
|
|
|
|
*
|
|
|
|
* ------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays the class selection menu.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param teamid What class types to display.
|
|
|
|
*/
|
|
|
|
ClassMenuSelect(client, teamid)
|
|
|
|
{
|
|
|
|
new Handle:menu = CreateMenu(ClassMenuSelectHandle);
|
|
|
|
new arraycount;
|
|
|
|
new classindex;
|
|
|
|
|
|
|
|
decl String:title[64];
|
|
|
|
decl String:classname[64];
|
|
|
|
decl String:description[256];
|
|
|
|
decl String:menuitem[320];
|
|
|
|
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Set correct menu title depending on team ID.
|
|
|
|
switch (teamid)
|
|
|
|
{
|
|
|
|
case ZR_CLASS_TEAM_ZOMBIES:
|
|
|
|
{
|
|
|
|
Format(title, sizeof(title), "%t\n", "!zclass zombie");
|
|
|
|
}
|
|
|
|
case ZR_CLASS_TEAM_HUMANS:
|
|
|
|
{
|
|
|
|
Format(title, sizeof(title), "%t\n", "!zclass human");
|
|
|
|
}
|
|
|
|
case ZR_CLASS_TEAM_ADMINS:
|
|
|
|
{
|
|
|
|
Format(title, sizeof(title), "%t\n", "!zclass admin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetMenuTitle(menu, title);
|
|
|
|
|
|
|
|
// Create buffer array.
|
|
|
|
new Handle:classarray = CreateArray();
|
|
|
|
|
|
|
|
// Copy all class indexes into the array, with the specified team filter.
|
|
|
|
if (ClassAddToArray(classarray, teamid))
|
|
|
|
{
|
|
|
|
// Get number of classes.
|
|
|
|
arraycount = GetArraySize(classarray);
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
// Loop through each class.
|
|
|
|
for (new i = 0; i < arraycount; i++)
|
|
|
|
{
|
|
|
|
// Get index, name and description.
|
|
|
|
classindex = GetArrayCell(classarray, i);
|
|
|
|
ClassGetName(classindex, classname, sizeof(classname), ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
ClassGetDescription(classindex, description, sizeof(description), ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
|
|
|
|
// Add menu item.
|
|
|
|
Format(menuitem, sizeof(menuitem), "%s\n %s", classname, description);
|
|
|
|
AddMenuItem(menu, classname, menuitem);
|
|
|
|
}
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
2009-04-15 23:40:45 +02:00
|
|
|
else
|
2009-04-18 02:22:13 +02:00
|
|
|
{
|
|
|
|
// No classes found. Display message. The main class menu should
|
|
|
|
// prevent this from happening, but we print a message just in case.
|
|
|
|
Format(menuitem, sizeof(menuitem), "%t\n", "!zclass not found");
|
|
|
|
AddMenuItem(menu, classname, menuitem, ITEMDRAW_RAWLINE);
|
|
|
|
}
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
SetMenuExitBackButton(menu, true);
|
|
|
|
DisplayMenu(menu, client, MENU_TIME_FOREVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class selection menu handle.
|
|
|
|
*/
|
|
|
|
public ClassMenuSelectHandle(Handle:menu, MenuAction:action, client, slot)
|
|
|
|
{
|
|
|
|
decl String:classname[64];
|
|
|
|
new classindex;
|
|
|
|
new teamid;
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:autoclose = GetConVarBool(g_hCvarsList[CVAR_MENU_AUTOCLOSE]);
|
2009-04-15 23:40:45 +02:00
|
|
|
|
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case MenuAction_Select:
|
|
|
|
{
|
|
|
|
// Get class name from the information string.
|
|
|
|
GetMenuItem(menu, slot, classname, sizeof(classname));
|
|
|
|
|
|
|
|
// Solve class index from the name.
|
|
|
|
classindex = ClassGetIndex(classname);
|
|
|
|
|
|
|
|
// Solve teamid from the class index.
|
|
|
|
teamid = ClassGetTeamID(classindex, ZR_CLASS_CACHE_MODIFIED);
|
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Check if the class is a admin class.
|
|
|
|
if (teamid == ZR_CLASS_TEAM_ADMINS)
|
|
|
|
{
|
|
|
|
// Set the admin class to be used on next admin spawn.
|
|
|
|
ClassPlayerNextAdminClass[client] = classindex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set the players active class to the specified class.
|
|
|
|
ClassSelected[client][teamid] = classindex;
|
|
|
|
}
|
2009-04-15 23:40:45 +02:00
|
|
|
}
|
|
|
|
case MenuAction_Cancel:
|
|
|
|
{
|
|
|
|
if (slot == MenuCancel_ExitBack)
|
|
|
|
{
|
|
|
|
ClassMenuMain(client);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case MenuAction_End:
|
|
|
|
{
|
|
|
|
CloseHandle(menu);
|
2009-04-29 01:58:41 +02:00
|
|
|
|
|
|
|
// Stop so menu doesn't reopen.
|
|
|
|
return;
|
2009-04-15 23:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-14 23:33:06 +02:00
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
// Redisplay the main class menu if autoclose is disabled.
|
|
|
|
if (!autoclose)
|
|
|
|
{
|
|
|
|
ClassMenuMain(client);
|
|
|
|
}
|
2009-04-14 23:33:06 +02:00
|
|
|
}
|
|
|
|
|
2009-04-18 02:22:13 +02:00
|
|
|
ClassToggleAdminMode(client)
|
2009-04-14 23:33:06 +02:00
|
|
|
{
|
2009-04-18 02:22:13 +02:00
|
|
|
// TODO: Move to new file, adminmode.inc.
|
2009-04-15 23:40:45 +02:00
|
|
|
}
|