Improved handling of missing classes in class menus. Fixed bots not getting default class config (removed IsFakeClient check). Made new ClassCountTeam function for customized counting.

This commit is contained in:
richard 2009-04-18 02:22:13 +02:00
parent 1659d24c4a
commit 72c6e9f632
5 changed files with 93 additions and 36 deletions

View File

@ -466,6 +466,11 @@
{
"en" "Toggle Admin Mode"
}
"!zclass not found"
{
"en" "No classes found."
}
// ===========================
// ZAdmin Menu

View File

@ -112,9 +112,9 @@ CreateCvars()
gCvars[CVAR_CLASSES] = CreateConVar("zr_classes", "1", "Enable zombie classes");
gCvars[CVAR_CLASSES_SPAWN] = CreateConVar("zr_classes_spawn", "0", "Classmenu is re-displayed every spawn (0: Disable)");
gCvars[CVAR_CLASSES_RANDOM] = CreateConVar("zr_classes_random", "0", "A random class is assigned to each player every round. Overrides zr_classes_spawn and default classes. (0: Disable)");
gCvars[CVAR_CLASSES_DEFAULT_ZOMBIE] = CreateConVar("zr_classes_default_zombie", "", "Default zombie class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_CLASSES_DEFAULT_HUMAN] = CreateConVar("zr_classes_default_human", "", "Default human class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_CLASSES_DEFAULT_ADMIN] = CreateConVar("zr_classes_default_admin", "", "Default admin-only class selected for admins when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_CLASSES_DEFAULT_ZOMBIE] = CreateConVar("zr_classes_default_zombie", "random", "Default zombie class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_CLASSES_DEFAULT_HUMAN] = CreateConVar("zr_classes_default_human", "random", "Default human class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_CLASSES_DEFAULT_ADMIN] = CreateConVar("zr_classes_default_admin", "random", "Default admin-only class selected for admins when they connect. Use \"random\" to select a random class, or blank to use class config defaults.");
gCvars[CVAR_ZOMBIE_HEALTH] = CreateConVar("zr_zombie_health", "5000", "The default health of a zombie");
gCvars[CVAR_ZOMBIE_SPEED] = CreateConVar("zr_zombie_speed", "350", "How fast zombies travel (300: Default speed, 600: Double speed)");
gCvars[CVAR_ZOMBIE_JUMP_DISTANCE] = CreateConVar("zr_zombie_jump_distance", "0.1", "How far the zombie jumps, (0: Regular jump distance)");

View File

@ -22,7 +22,7 @@
*/
ClassClientInit(client)
{
if (!IsFakeClient(client))
if (ZRIsValidClient(client))
{
// Set default class indexes on the player.
ClassClientSetDefaultIndexes(client);

View File

@ -9,30 +9,6 @@
* ============================================================================
*/
/*
Menu layouts
---------------------------------------
Class selection:
Admin mode is enabled!
1. Select Zombie Class
- Classic
2. Select Human Class
- Regular Human
3. Select Admin Class <-- Only active for admins
- Hidden Admin
(spacer)
4. Toggle Admin Mode
- Disabled
0. Exit
---------------------------------------
*/
/* ------------------------------------
*
* MAIN CLASS MENU
@ -48,7 +24,6 @@ Admin mode is enabled!
ClassMenuMain(client)
{
new Handle:menu = CreateMenu(ClassMenuMainHandle);
new itemdraw = (ZRIsClientAdmin(client)) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED;
SetGlobalTransTarget(client);
SetMenuTitle(menu, "%t\n", "!zclass title");
@ -65,6 +40,16 @@ ClassMenuMain(client)
decl String:adminmode[128];
decl String:toggleadminmode[128];
// 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;
// Check if the player is in admin mode.
if (ClassPlayerInAdminMode[client])
{
@ -76,19 +61,20 @@ ClassMenuMain(client)
// List zombie class options.
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES], zombieclass, sizeof(zombieclass), ZR_CLASS_CACHE_MODIFIED);
Format(zombieselect, sizeof(zombieselect), "%t\n %s", "!zclass zombie", zombieclass);
AddMenuItem(menu, "", zombieselect);
AddMenuItem(menu, "", zombieselect, zombie_itemdraw);
// List human class options.
ClassGetName(ClassSelected[client][ZR_CLASS_TEAM_HUMANS], humanclass, sizeof(humanclass), ZR_CLASS_CACHE_MODIFIED);
Format(humanselect, sizeof(humanselect), "%t\n %s", "!zclass human", humanclass);
AddMenuItem(menu, "", humanselect);
AddMenuItem(menu, "", humanselect, human_itemdraw);
// Only display admin class options for admins.
if (ZRIsClientAdmin(client))
{
// 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);
AddMenuItem(menu, "", adminselect, itemdraw);
AddMenuItem(menu, "", adminselect, admin_itemdraw);
// Set admin mode status string.
if (ClassPlayerAdminMode[client])
@ -100,9 +86,12 @@ ClassMenuMain(client)
Format(adminmode, sizeof(adminmode), "%t", "Off");
}
// Spacer. ITEMDRAW_SPACER not used because it use a slot.
AddMenuItem(menu, "", " ", ITEMDRAW_RAWLINE);
// Show admin mode toggle option.
Format(toggleadminmode, sizeof(toggleadminmode), "%t\n %s", "!zclass admin mode toggle", adminmode);
AddMenuItem(menu, "", toggleadminmode);
AddMenuItem(menu, "", toggleadminmode, admin_itemdraw);
}
SetMenuExitBackButton(menu, true);
@ -134,7 +123,8 @@ public ClassMenuMainHandle(Handle:menu, MenuAction:action, client, slot)
}
case 3:
{
// ClassMenuToggleAdmin(client);
// ClassToggleAdminMode(client);
ClassMenuMain(client);
}
}
}
@ -219,6 +209,12 @@ ClassMenuSelect(client, teamid)
}
}
else
{
// 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);
}
SetMenuExitBackButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
@ -270,7 +266,7 @@ public ClassMenuSelectHandle(Handle:menu, MenuAction:action, client, slot)
}
}
ClassMenuToggleAdmin(client)
ClassToggleAdminMode(client)
{
// TODO: Move to new file, adminmode.inc.
}

View File

@ -421,6 +421,62 @@ bool:ClassAddToArray(Handle:array, teamfilter = -1, bool:ignoreEnabled = false,
}
}
/**
* Counts total classes or classes in the specified team.
*
* @param teamfilter Optional. The team ID to filter. Negative value for
* no filter (default).
* @param ignoreEnabled Ignore the enabled attribute.
* @param cachetype Optional. Specifies what class cache to read from.
* Options:
* ZR_CLASS_CACHE_ORIGINAL - Unchanced class data.
* ZR_CLASS_CACHE_MODIFIED (default) - Changed/newest
* class data.
* @return Number of total classes or classes in the specified team.
*/
ClassCountTeam(teamfilter = -1, bool:ignoreEnabled = false, cachetype = ZR_CLASS_CACHE_MODIFIED)
{
// Check if there are no classes.
if (ClassCount == 0)
{
return 0;
}
// Store a local boolean that says if the user specified a team filter or not.
new bool:has_filter = bool:(teamfilter >= 0);
new count;
// Loop through all classes.
for (new classindex = 0; classindex < ClassCount; classindex++)
{
if (!ignoreEnabled && !ClassIsEnabled(classindex, cachetype))
{
// The class is disabled and the enabled attribute is NOT ignored.
// Skip to the next class.
continue;
}
// Check team filtering.
if (has_filter)
{
// Only add classes with matching team ID.
if (ClassGetTeamID(classindex, cachetype) == teamfilter)
{
// Team ID match. Increment counter.
count++;
}
}
else
{
// No filter. Increment counter.
count++;
}
}
// Return number of classes found.
return count;
}
/**
* Gets a random class index from a specified team or from all classes.
*