2009-04-11 01:56:22 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: classevents.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Functions for handling class related events.
|
2009-04-11 01:56:22 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ------------------------------------
|
|
|
|
*
|
|
|
|
* GAME EVENTS
|
|
|
|
*
|
|
|
|
* ------------------------------------
|
|
|
|
*/
|
|
|
|
|
2009-06-21 21:24:24 +02:00
|
|
|
/**
|
|
|
|
* Create class-related cookies here.
|
|
|
|
*/
|
|
|
|
ClassOnCookiesCreate()
|
|
|
|
{
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
ClassOverlayOnCookiesCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when all modules are done loading.
|
|
|
|
*/
|
|
|
|
ClassOnModulesLoaded()
|
|
|
|
{
|
|
|
|
// Set default classes on all player slots.
|
|
|
|
ClassClientSetDefaultIndexes();
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
/**
|
2009-06-18 03:33:09 +02:00
|
|
|
* Called when a client connects to the server (OnClientPutInServer).
|
2009-04-11 01:56:22 +02:00
|
|
|
*/
|
|
|
|
ClassClientInit(client)
|
|
|
|
{
|
2009-05-10 18:49:47 +02:00
|
|
|
// Check if there are valid classes and the client is valid.
|
2009-06-18 02:09:55 +02:00
|
|
|
// To prevent bots or SourceTV causing errors. If classes are invalid this
|
|
|
|
// event was executed before classes were loaded.
|
2009-05-10 18:49:47 +02:00
|
|
|
if (ClassValidated && ZRIsClientValid(client))
|
2009-04-11 01:56:22 +02:00
|
|
|
{
|
|
|
|
// Set default class indexes on the player.
|
|
|
|
ClassClientSetDefaultIndexes(client);
|
|
|
|
}
|
2009-05-14 02:28:26 +02:00
|
|
|
|
|
|
|
// Forward event to sub-modules
|
|
|
|
ClassOverlayClientInit(client);
|
|
|
|
}
|
|
|
|
|
2009-06-18 03:33:09 +02:00
|
|
|
/**
|
|
|
|
* Called a client disconnects.
|
|
|
|
*/
|
2009-04-11 01:56:22 +02:00
|
|
|
ClassOnClientDisconnect(client)
|
|
|
|
{
|
2009-05-10 18:49:47 +02:00
|
|
|
// Disable class attributes with timers.
|
|
|
|
ClassHealthRegenStop(client);
|
2009-04-11 01:56:22 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 02:28:26 +02:00
|
|
|
/**
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-11 01:56:22 +02:00
|
|
|
ClassOnClientSpawn(client)
|
|
|
|
{
|
2009-05-10 18:49:47 +02:00
|
|
|
// Check if the player is alive.
|
2009-04-29 02:50:25 +02:00
|
|
|
if (!IsPlayerAlive(client))
|
|
|
|
{
|
2009-05-10 18:49:47 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there are valid classes. Block this event if classes aren't
|
|
|
|
// done loading.
|
|
|
|
if (!ClassValidated)
|
|
|
|
{
|
2009-04-29 02:50:25 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-04-22 04:53:19 +02:00
|
|
|
|
2009-06-18 02:09:55 +02:00
|
|
|
// Reset attributes by triggering death event.
|
|
|
|
ClassOnClientDeath(client);
|
|
|
|
|
2009-04-20 02:56:26 +02:00
|
|
|
new bool:randomclass = GetConVarBool(g_hCvarsList[CVAR_CLASSES_RANDOM]);
|
2009-04-29 02:50:25 +02:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
decl String:steamid[16];
|
|
|
|
decl String:classname[64];
|
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Assign random classes if enabled. Always do it for bots.
|
|
|
|
GetClientAuthString(client, steamid, sizeof(steamid));
|
|
|
|
if (randomclass || StrEqual(steamid, "BOT"))
|
2009-04-11 01:56:22 +02:00
|
|
|
{
|
2009-04-29 02:50:25 +02:00
|
|
|
// Get random classes for each type.
|
|
|
|
new randomzombie = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES);
|
|
|
|
new randomhuman = ClassGetRandomClass(ZR_CLASS_TEAM_HUMANS);
|
|
|
|
|
|
|
|
// Mark zombie class as selected.
|
|
|
|
ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES] = randomzombie;
|
|
|
|
ClassGetName(randomzombie, classname, sizeof(classname), ZR_CLASS_TEAM_ZOMBIES);
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Classes random assignment", classname);
|
2009-04-29 02:50:25 +02:00
|
|
|
|
|
|
|
// Mark human class as selected.
|
|
|
|
ClassSelected[client][ZR_CLASS_TEAM_HUMANS] = randomhuman;
|
|
|
|
ClassGetName(randomhuman, classname, sizeof(classname), ZR_CLASS_TEAM_HUMANS);
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChat(client, "Classes random assignment", classname);
|
2009-04-29 02:50:25 +02:00
|
|
|
|
|
|
|
// Update player cache with the human class data, and apply it.
|
|
|
|
ClassReloadPlayerCache(client, randomhuman);
|
|
|
|
ClassApplyAttributes(client);
|
2009-04-11 01:56:22 +02:00
|
|
|
}
|
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Check if the player should spawn in admin mode.
|
|
|
|
if (ClassPlayerAdminMode[client])
|
2009-04-11 01:56:22 +02:00
|
|
|
{
|
2009-04-29 02:50:25 +02:00
|
|
|
// Mark player as in admin mode.
|
|
|
|
ClassPlayerInAdminMode[client] = true;
|
2009-04-14 23:16:31 +02:00
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Update player cache with the admin class and apply attributes.
|
|
|
|
new adminindex = ClassPlayerNextAdminClass[client];
|
|
|
|
ClassReloadPlayerCache(client, adminindex);
|
|
|
|
ClassApplyAttributes(client);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Mark player as not in admin mode.
|
|
|
|
ClassPlayerInAdminMode[client] = false;
|
2009-04-11 01:56:22 +02:00
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Apply class attributes for the currently active class.
|
|
|
|
ClassReloadPlayerCache(client, ClassGetActiveIndex(client));
|
|
|
|
ClassApplyAttributes(client);
|
2009-04-11 01:56:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-18 03:33:09 +02:00
|
|
|
/**
|
|
|
|
* Client died. Stops timers and reset certain attributes. Call this event to
|
|
|
|
* clean up class related stuff.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-11 01:56:22 +02:00
|
|
|
ClassOnClientDeath(client)
|
|
|
|
{
|
2009-05-10 18:49:47 +02:00
|
|
|
// Disable class attributes with timers.
|
2009-04-11 01:56:22 +02:00
|
|
|
ClassHealthRegenStop(client);
|
2009-05-14 02:28:26 +02:00
|
|
|
|
2009-04-29 02:50:25 +02:00
|
|
|
// Set client's FOV back to normal.
|
|
|
|
ToolsSetClientDefaultFOV(client, 90);
|
2009-05-21 07:13:51 +02:00
|
|
|
|
|
|
|
// Forward event to sub-modules.
|
|
|
|
ClassOverlayOnClientDeath(client);
|
2009-04-11 01:56:22 +02:00
|
|
|
}
|
|
|
|
|
2009-06-18 03:33:09 +02:00
|
|
|
/**
|
|
|
|
* Client got infected. Reloads class attributes.
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
*/
|
2009-04-11 01:56:22 +02:00
|
|
|
ClassOnClientInfected(client, bool:motherzombie = false)
|
|
|
|
{
|
|
|
|
new classindex = ClassGetActiveIndex(client);
|
2009-06-22 01:09:51 +02:00
|
|
|
new isadmin;
|
|
|
|
new motherindex;
|
|
|
|
|
|
|
|
decl String:motherzombiesetting[64];
|
2009-04-11 01:56:22 +02:00
|
|
|
|
2009-05-10 18:49:47 +02:00
|
|
|
// Disable class attributes with timers.
|
|
|
|
ClassHealthRegenStop(client);
|
|
|
|
|
2009-06-22 01:09:51 +02:00
|
|
|
// Check if it's a mother zombie.
|
|
|
|
if (motherzombie)
|
|
|
|
{
|
|
|
|
// Set negative admin flag if client is admin, so it's removed in
|
|
|
|
// special class flags.
|
|
|
|
isadmin = ZRIsClientAdmin(client) ? -ZR_CLASS_FLAG_ADMIN_ONLY : 0;
|
|
|
|
|
|
|
|
// Get default mother zombie setting.
|
|
|
|
GetConVarString(g_hCvarsList[CVAR_CLASSES_DEFAULT_M_ZOMB], motherzombiesetting, sizeof(motherzombiesetting));
|
|
|
|
|
|
|
|
if (StrEqual(motherzombiesetting, "disabled", false))
|
|
|
|
{
|
|
|
|
// Do nothing. Keep current class.
|
|
|
|
}
|
|
|
|
else if (StrEqual(motherzombiesetting, "random", false))
|
|
|
|
{
|
|
|
|
// Get random regular zombie class. Remove admin flag if admin.
|
|
|
|
motherindex = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES, _, _, ZR_CLASS_SPECIALFLAGS + isadmin);
|
|
|
|
}
|
|
|
|
else if (StrEqual(motherzombiesetting, "motherzombies", false))
|
|
|
|
{
|
|
|
|
// Get random mother zombie class.
|
|
|
|
motherindex = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES, _, ZR_CLASS_FLAG_MOTHER_ZOMBIE, isadmin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Assume it's a class name. Get index for the specified class name.
|
|
|
|
motherindex = ClassGetIndex(motherzombiesetting);
|
|
|
|
|
|
|
|
// Validate index.
|
|
|
|
if (ClassValidateIndex(motherindex))
|
|
|
|
{
|
|
|
|
// Change class.
|
|
|
|
classindex = motherindex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Update the players cache with zombie attributes.
|
|
|
|
ClassReloadPlayerCache(client, classindex);
|
|
|
|
|
|
|
|
// Apply the new attributes.
|
|
|
|
ClassApplyAttributes(client, motherzombie);
|
|
|
|
}
|