Implemented the new class system. Class menu missing, only default classes working.

This commit is contained in:
richard
2009-04-11 01:56:22 +02:00
parent 1e99bd64f3
commit a8704cf90c
15 changed files with 557 additions and 269 deletions

View File

@ -37,6 +37,8 @@ bool:ClassApplyAttributes(client, bool:improved = false)
ClassApplyHealth(client, classindex, improved);
ClassApplyHealthRegen(client, classindex);
ClassApplySpeed(client, classindex);
return true;
}
/**
@ -51,18 +53,18 @@ bool:ClassApplyAttributes(client, bool:improved = false)
* ZR_CLASS_CACHE_PLAYER (default) - Player cache.
* @return True on success, false otherwise.
*/
bool:ClassApplyModel(client, classindex, cachetpye = ZR_CLASS_CACHE_PLAYER)
bool:ClassApplyModel(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
{
decl String:modelpath[256];
// Get the model path from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER)
{
ClassGetModelPath(client, modelpath, sizeof(modelpath), cachetype)
ClassGetModelPath(client, modelpath, sizeof(modelpath), cachetype);
}
else
{
ClassGetModelPath(classindex, modelpath, sizeof(modelpath), cachetype)
ClassGetModelPath(classindex, modelpath, sizeof(modelpath), cachetype);
}
// Check if the user specified a random model.
@ -94,16 +96,16 @@ bool:ClassApplyModel(client, classindex, cachetpye = ZR_CLASS_CACHE_PLAYER)
*/
bool:ClassApplyAlpha(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
{
new alpha;
// Get the alpha value from the specified cache.
new alpha;
// Get the alpha value from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER)
{
alpha = ClassGetAlphaSpawn(client, cachetype);
alpha = ClassGetAlphaInitial(client, cachetype);
}
else
{
alpha = ClassGetAlphaSpawn(classindex, cachetype);
alpha = ClassGetAlphaInitial(classindex, cachetype);
}
if (alpha < 0)
@ -111,8 +113,8 @@ bool:ClassApplyAlpha(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
return false;
}
SetPlayerAlpha(client, alpha);
return true;
SetPlayerAlpha(client, alpha);
return true;
}
/**
@ -313,7 +315,7 @@ bool:ClassApplyHealthRegen(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER
*/
bool:ClassApplySpeed(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
{
new speed;
new Float:speed;
// Get the health points from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER)

View File

@ -107,7 +107,7 @@ bool:ClassGetTeamDefault(index, cachetype = ZR_CLASS_CACHE_MODIFIED)
}
case ZR_CLASS_CACHE_MODIFIED:
{
return ClassDataCached[index][class_team_default];
return ClassDataCache[index][class_team_default];
}
case ZR_CLASS_CACHE_PLAYER:
{

View File

@ -0,0 +1,114 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: classevents.inc
* Description: Functions for handling class related events.
* Author: Richard Helgeby
*
* ============================================================================
*/
/* ------------------------------------
*
* GAME EVENTS
*
* ------------------------------------
*/
/**
* To be called when a client connect to the server.
* (OnClientPutInServer)
*/
ClassClientInit(client)
{
if (!IsFakeClient(client))
{
// Set default class indexes on the player.
ClassClientSetDefaultIndexes(client);
}
}
ClassOnClientDisconnect(client)
{
// Stop timers related to class attributes.
ClassOverlayStop(client);
}
ClassOnClientSpawn(client)
{
new bool:randomclass = GetConVarBool(gCvars[CVAR_CLASSES_RANDOM]);
new bool:showmenu = GetConVarBool(gCvars[CVAR_CLASSES_SPAWN]);
decl String:steamid[16];
decl String:classname[64];
if (showmenu && !randomclass)
{
ClassMenu(client);
}
// Assign random classes if enabled.
GetClientAuthString(client, steamid, sizeof(steamid));
if (StrEqual(steamid, "BOT") || randomclass)
{
// Old class system.
new classindex = GetRandomInt(0, classCount - 1);
Call_StartForward(hOnZClassChanged);
Call_PushCell(client);
Call_PushCell(pClass[client]);
Call_PushCell(classindex);
Call_Finish();
pClass[client] = classindex;
// New class system.
new teamid = GetClientTeam(client);
if (zombieSpawned && teamid == CS_TEAM_T)
{
classindex = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES);
ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES] = classindex;
ClassGetName(client, classname, sizeof(classname));
}
else
{
classindex = ClassGetRandomClass(ZR_CLASS_TEAM_HUMANS);
ClassSelected[client][ZR_CLASS_TEAM_HUMANS] = classindex;
ClassGetName(client, classname, sizeof(classname));
}
ZR_PrintToChat(client, "Auto-assign", classname);
}
}
ClassOnClientDeath(client)
{
ClassHealthRegenStop(client);
ClassOverlayStop(client);
}
ClassOnClientInfected(client, bool:motherzombie = false)
{
new classindex = ClassGetActiveIndex(client);
// Update the players cache with zombie attributes.
ClassReloadPlayerCache(client, classindex);
// Apply the new attributes.
ClassApplyAttributes(client, motherzombie);
}
ClassOnRoundStart()
{
}
/* ------------------------------------
*
* PLAYER COMMANDS
*
* ------------------------------------
*/

View File

@ -0,0 +1,28 @@
/*
* ============================================================================
*
* Zombie:Reloaded
*
* File: clientalpha.inc
* Description: Handles transparency on clients.
* Author: Richard Helgeby
*
* ============================================================================
*/
/**
* Updates the alpha value on a player.
*/
ClassAlphaUpdate(client)
{
new current_health = GetClientHealth(client);
new max_health = ClassGetHealth(client);
new max_damage = ClassGetAlphaDamage(client);
// Calculate if enough damage is done to change alpha.
if ((max_health - current_health) > max_damage)
{
new alpha_damaged = ClassGetAlphaDamaged(client);
SetPlayerAlpha(client, alpha_damaged);
}
}

View File

@ -35,7 +35,7 @@ bool:ClientHasOverlay(client)
return bClientHasOverlay[client];
}
ClassOverlayInitialize(client, const String:overlay)
ClassOverlayInitialize(client, const String:overlay[])
{
if (IsFakeClient(client))
{
@ -64,7 +64,7 @@ ClassOverlayStart(client)
tOverlay[client] = INVALID_HANDLE;
}
ClientCommand(client, "r_screenoverlay \"%s\"", overlay);
ClientCommand(client, "r_screenoverlay \"%s\"", ActiveOverlay[client]);
bClientOverlayOn[client] = true;
new Float:redisplay = GetConVarFloat(gCvars[CVAR_OVERLAY_REDISPLAY]);

View File

@ -13,7 +13,7 @@
/**
* Validates the team requirements in a class cache and check that theres at
* least one class for each team. Minium team requirements are zombies and
* humans. The admin team is optinal.
* humans. The admin team is optinal and not validated.
*
* @param cachetype Optional. Specifies what class cache to validate. Options:
* ZR_CLASS_CACHE_ORIGINAL (default, unchanged class data),
@ -35,7 +35,8 @@ bool:ClassValidateTeamRequirements(cachetype = ZR_CLASS_CACHE_ORIGINAL)
zombieindex = ClassGetFirstClass(ZR_CLASS_TEAM_ZOMBIES, _, cachetype);
humanindex = ClassGetFirstClass(ZR_CLASS_TEAM_HUMANS, _, cachetype);
if (zombieindex > -1 && humanindex > -1)
// Validate indexes.
if (ClassValidateIndex(zombieindex) && ClassValidateIndex(humanindex))
{
return true;
}
@ -43,6 +44,40 @@ bool:ClassValidateTeamRequirements(cachetype = ZR_CLASS_CACHE_ORIGINAL)
return false;
}
/**
* Validates that there's a class marked as team default for each team.
*
* @param cachetype Optional. Specifies what class cache to validate. Options:
* ZR_CLASS_CACHE_ORIGINAL (default, unchanged class data),
* ZR_CLASS_CACHE_MODIFIED (modified class data).
* @return True if validation was successful, false otherwise.
*/
bool:ClassValidateTeamDefaults(cachetype = ZR_CLASS_CACHE_ORIGINAL)
{
new zombieindex;
new humanindex;
// Check if there are no classes.
if (ClassCount == 0)
{
return false;
}
// Test if a default zombie and human class was found.
zombieindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ZOMBIES, _, cachetype);
humanindex = ClassGetDefaultClass(ZR_CLASS_TEAM_HUMANS, _, cachetype);
// Validate indexes.
if (ClassValidateIndex(zombieindex) && ClassValidateIndex(humanindex))
{
return true;
}
else
{
return false;
}
}
/**
* Validates all the class attributes in the original class data array, to
* check if they have invalid values. Boolean settings are not validated.
@ -111,10 +146,12 @@ ClassValidateAttributes(classindex)
// Overlay path.
decl String:overlay_path[256];
if (strcopy(overlay_path, sizeof(overlay_path), ClassData[classindex][class_overlay_path]) != 0)
decl String:overlay[256];
if (strcopy(overlay_path, sizeof(overlay_path), ClassData[classindex][class_overlay_path]) > 0)
{
// Check if the file exists.
if (!FileExists(overlay_path))
Format(overlay, sizeof(overlay), "materials/%s.vmt", overlay_path);
if (!FileExists(overlay))
{
flags += ZR_CLASS_ATTRIB_ERR_OVERLAY_PATH;
}
@ -139,13 +176,13 @@ ClassValidateAttributes(classindex)
if (!(regen_interval >= 0.0 && regen_interval <= 900.0))
{
flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_INTERVAL;
}
// Health regen amount.
new regen_amount = ClassData[classindex][class_health_regen_amount];
if (!(regen_amount > 0 && regen_amount <= 65536))
{
flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_AMOUNT;
// Health regen amount. Only validating if interval is set.
new regen_amount = ClassData[classindex][class_health_regen_amount];
if (!(regen_amount > 0 && regen_amount <= 65536))
{
flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_AMOUNT;
}
}
// Health infect gain.
@ -267,7 +304,7 @@ ClassGetIndex(const String:name[], cachetype = ZR_CLASS_CACHE_MODIFIED)
for (new classindex = 0; classindex < ClassCount; classindex++)
{
// Get its name and compare it with the specified class name.
ClassesGetName(classindex, current_name, sizeof(current_name), cachetype);
ClassGetName(classindex, current_name, sizeof(current_name), cachetype);
if (strcmp(name, current_name, false) == 0)
{
return classindex;
@ -289,7 +326,7 @@ ClassGetActiveIndex(client)
{
new teamid = GetClientTeam(client);
if (teamid == CS_TEAM_SPECTACTOR || teamid == CS_TEAM_NONE)
if (teamid == CS_TEAM_SPECTATOR || teamid == CS_TEAM_NONE)
{
// No active team.
return -1;
@ -297,17 +334,17 @@ ClassGetActiveIndex(client)
if (IsPlayerHuman(client))
{
teamid = ZR_TEAM_HUMANS;
teamid = ZR_CLASS_TEAM_HUMANS;
}
else
{
teamid = ZR_TEAM_ZOMBIES;
teamid = ZR_CLASS_TEAM_ZOMBIES;
}
// TODO: How to detect that virtual admin team?
// Return the active class for the current team.
return ClassActive[client][teamid];
return ClassSelected[client][teamid];
}
/**
@ -476,6 +513,52 @@ ClassGetFirstClass(teamfilter = -1, bool:ignoreEnabled = false, cachetype = ZR_C
return -1;
}
/**
* Gets the first class marked as default for the specified team.
*
* @param teamid The team ID.
* @param ignoreEnabled Optional. Ignore the class's enabled attribute. Default
* is false.
* @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 The first default class index. -1 on error.
*/
ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, cachetype = ZR_CLASS_CACHE_MODIFIED)
{
new Handle:classarray;
new arraycount;
new classindex;
classarray = CreateArray();
// Get all classes from the specified team.
if (!ClassAddToArray(classarray, teamid, ignoreEnabled, cachetype))
{
// Failed to get classes.
return -1;
}
// Loop through all classes and return the first class marked as team default.
arraycount = GetArraySize(classarray);
for (new i = 0; i < arraycount; i++)
{
// Get class index from the array.
classindex = GetArrayCell(classarray, i);
// Check if the current class is marked as team default.
if (ClassGetTeamDefault(classindex, cachetype))
{
// Default class found.
return classindex;
}
}
return -1;
}
/**
* Gets the default class index for the specified team configured to be used
* when players join the server.
@ -493,8 +576,6 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
{
decl String:classname[64];
new classindex;
new Handle:classarray;
new arraycount;
// Get the default class name from the correct CVAR depending on teamid.
switch (teamid)
@ -519,13 +600,13 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
}
// Check if the class name isn't empty.
if (strlen(class_name) > 0)
if (strlen(classname) > 0)
{
// Check if the user set "random" as default class.
if (strcmp(classname, "random", false) == 0)
{
// Get a list of all classes with the specified team ID.
classindex = ClassGetRandomClass(teamid, cachetype);
classindex = ClassGetRandomClass(teamid, _, cachetype);
// Validate the result, in case there were errors.
if (ClassValidateIndex(classindex))
@ -545,7 +626,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
// The user set a spesific class.
// Try to get the class index with the specified class name.
classindex = ClassGetClassIndex(classname, cachetype);
classindex = ClassGetIndex(classname, cachetype);
// Validate the class index and check if the team IDs match.
if (ClassValidateIndex(classindex) && (teamid == ClassGetTeamID(classindex, cachetype)))
@ -557,11 +638,11 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
// The class index is invalid or the team IDs didn't match.
// Because it's user input, we'll fall back to the first class
// in the specified team, and log a warning.
classindex = ClassGetFirstClass(teamid, cachetype);
classindex = ClassGetFirstClass(teamid, _, cachetype);
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES))
{
ZR_LogMessageFormatted(-1, "classes", "default spawn class", "Warning: Failed to set \"%s\" as default spawn class for team %d. The class doesn't exist or the team IDs doesn't match. Falling back to the first class in the team.", _, classname, teamid);
ZR_LogMessageFormatted(-1, "Classes", "DefaultSpawnClass", "Warning: Failed to set \"%s\" as default spawn class for team %d. The class doesn't exist or the team IDs doesn't match. Falling back to the first class in the team.", _, classname, teamid);
}
// Validate the new index.
@ -570,7 +651,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
// Log a warning.
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES))
{
ZR_LogMessageFormatted(-1, "classes", "default spawn class", "Warning: The default class name \"%s\" does not exist or matches the team ID.", _, classname);
ZR_LogMessageFormatted(-1, "Classes", "DefaultSpawnClass", "Warning: The default class name \"%s\" does not exist or matches the team ID.", _, classname);
}
return classindex;
@ -585,7 +666,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
}
else
{
// Blank class name, return a error code.
return -1;
// Blank class name, get the default class and return the index.
return ClassGetDefaultClass(teamid, _, cachetype);
}
}

View File

@ -57,7 +57,7 @@
* Total number of classes that can be stored in each cache. A total of 32
* classes should be enough. Too many classes will comfuse players.
*/
#define ZR_CLASS_MAX 31
#define ZR_CLASS_MAX 32
/**
* @section Class cache types. Specifies what data array to use.
@ -223,24 +223,26 @@ new ClassDataCache[ZR_CLASS_MAX][ClassAttributes];
new ClassPlayerCache[MAXPLAYERS + 1][ClassAttributes];
/**
* Number of classes successfully loaded.
* Number of classes loaded.
*/
new ClassCount;
/**
* Stores what class that the player have selected, for each team.
*/
new ClassActive[MAXPLAYERS + 1][ZR_CLASS_TEAMCOUNT - 1];
new ClassSelected[MAXPLAYERS + 1][ZR_CLASS_TEAMCOUNT];
#include "zr/playerclasses/filtertools"
#include "zr/playerclasses/attributes"
#include "zr/playerclasses/apply"
#include "zr/playerclasses/clientoverlays"
#include "zr/playerclasses/clientalpha"
#include "zr/playerclasses/healthregen"
#include "zr/playerclasses/classevents"
/**
* Loads class attributes from playerclasses.txt into the ClassData array. If
* any error occour, the plugin load will fail.
* any error occour the plugin load will fail.
*
* @param classfile Optional. Specifies what file to read from. Valves key/
* values format. The path is relative to the sourcemod
@ -296,6 +298,7 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt")
/* General */
ClassData[ClassCount][class_enabled] = bool:KvGetNum(kvClassData, "enabled", ZR_CLASS_DEFAULT_ENABLED);
ClassData[ClassCount][class_team] = KvGetNum(kvClassData, "team", ZR_CLASS_DEFAULT_TEAM);
ClassData[ClassCount][class_team_default] = bool:KvGetNum(kvClassData, "team_default", ZR_CLASS_DEFAULT_TEAM_DEFAULT);
KvGetString(kvClassData, "name", name, sizeof(name), ZR_CLASS_DEFAULT_NAME);
strcopy(ClassData[ClassCount][class_name], 64, name);
@ -353,7 +356,7 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt")
ZR_LogMessageFormatted(-1, "classes", "load", "Invalid class at index %d. Class error flags: %d.", LOG_FORMAT_TYPE_ERROR, ClassCount, ClassErrorFlags);
}
}
// Update the counter.
ClassCount++;
} while (KvGotoNextKey(kvClassData));
@ -363,6 +366,15 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt")
{
SetFailState("The class configuration doesn't match the team requirements.");
}
// Validate team default requirements.
if (!ClassValidateTeamDefaults())
{
SetFailState("Couldn't find a default class for one or more teams. At least one class per team must be marked as default.");
}
// Cache class data.
ClassReloadDataCache();
}
/**
@ -384,7 +396,7 @@ bool:ClassReloadDataCache()
return false;
}
for (new classindex = 0; classindex < ClassCount; clasindex++)
for (new classindex = 0; classindex < ClassCount; classindex++)
{
/* General */
ClassDataCache[classindex][class_enabled] = ClassData[classindex][class_enabled];
@ -530,3 +542,93 @@ bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIF
return true;
}
/**
* Sets default class indexes for each team on all players, or a single player
* if specified.
*
* @param client Optional. The client index.
*/
ClassClientSetDefaultIndexes(client = -1)
{
new classindex = GetDefaultClassIndex(); // Old class system. Not removed for backwards compatibility.
// Get indexes.
new zombieindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ZOMBIES);
new humanindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_HUMANS);
new adminindex = ClassGetDefaultSpawnClass(ZR_CLASS_TEAM_ADMINS);
// Validate zombie class index.
if (!ClassValidateIndex(zombieindex))
{
// Invalid class index. Fall back to default class in class config and
// log a warning.
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES))
{
ZR_LogMessageFormatted(-1, "Classes", "SetDefaultIndexes", "Warning: Failed to get default zombie class, falling back to default class. Check spelling in \"zr_classes_default_zombie\".", LOG_FORMAT_TYPE_ERROR);
}
// Use default class.
zombieindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ZOMBIES);
}
// Validate human class index.
if (!ClassValidateIndex(humanindex))
{
// Invalid class index. Fall back to default class in class config and
// log a warning.
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES))
{
ZR_LogMessageFormatted(-1, "Classes", "SetDefaultIndexes", "Warning: Failed to get default human class, falling back to default class. Check spelling in \"zr_classes_default_human\".", LOG_FORMAT_TYPE_ERROR);
}
// Use default class.
humanindex = ClassGetDefaultClass(ZR_CLASS_TEAM_HUMANS);
}
// Validate admin class index.
if (!ClassValidateIndex(adminindex))
{
// Invalid class index. Fall back to default class in class config and
// log a warning.
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES))
{
ZR_LogMessageFormatted(-1, "Classes", "SetDefaultIndexes", "Warning: Failed to get default admin class, falling back to default class. Check spelling in \"zr_classes_default_admin\".", LOG_FORMAT_TYPE_ERROR);
}
// Use default class.
adminindex = ClassGetDefaultClass(ZR_CLASS_TEAM_ADMINS);
}
// Check if a client is specified.
if (client > 0)
{
// Set the old array for backwards compatibility while introducing the
// new class system.
pClass[client] = classindex;
ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES] = zombieindex;
ClassSelected[client][ZR_CLASS_TEAM_HUMANS] = humanindex;
ClassSelected[client][ZR_CLASS_TEAM_ADMINS] = adminindex;
// Copy human class data to player cache.
ClassReloadPlayerCache(client, humanindex);
}
else
{
// No client specified. Loop through all players.
for (new clientindex = 1; clientindex <= MAXPLAYERS; clientindex++)
{
// Set the old array for backwards compatibility while introducing the
// new class system.
pClass[clientindex] = classindex;
ClassSelected[clientindex][ZR_CLASS_TEAM_ZOMBIES] = zombieindex;
ClassSelected[clientindex][ZR_CLASS_TEAM_HUMANS] = humanindex;
ClassSelected[clientindex][ZR_CLASS_TEAM_ADMINS] = adminindex;
// Copy human class data to player cache.
ClassReloadPlayerCache(client, humanindex);
}
}
}