Fixed selected class not restored after being mother zombie.

This commit is contained in:
richard 2009-07-22 14:06:18 +02:00
parent 8fc99720c7
commit 0019a52ca8
3 changed files with 111 additions and 22 deletions

View File

@ -31,24 +31,24 @@
#define ANTISTICK_COLLISIONS_OFF 2
#define ANTISTICK_COLLISIONS_ON 5
#define COLLISION_GROUP_NONE 0 /** Default; collides with static and dynamic objects. */
#define COLLISION_GROUP_DEBRIS 1 /** Collides with nothing but world and static stuff. */
#define COLLISION_GROUP_DEBRIS_TRIGGER 2 /** Same as debris, but hits triggers. */
#define COLLISION_GROUP_INTERACTIVE_DEBRIS 3 /** Collides with everything except other interactive debris or debris. */
#define COLLISION_GROUP_INTERACTIVE 4 /** Collides with everything except interactive debris or debris. */
#define COLLISION_GROUP_PLAYER 5 /** This is the default behavior expected for most prop_physics. */
#define COLLISION_GROUP_BREAKABLE_GLASS 6 /** Special group for glass debris. */
#define COLLISION_GROUP_VEHICLE 7 /** Collision group for driveable vehicles. */
#define COLLISION_GROUP_PLAYER_MOVEMENT 8 /** For HL2, same as Collision_Group_Player. */
#define COLLISION_GROUP_NPC 9 /** Generic NPC group. */
#define COLLISION_GROUP_IN_VEHICLE 10 /** For any entity inside a vehicle. */
#define COLLISION_GROUP_WEAPON 11 /** For any weapons that need collision detection. */
#define COLLISION_GROUP_VEHICLE_CLIP 12 /** Vehicle clip brush to restrict vehicle movement. */
#define COLLISION_GROUP_PROJECTILE 13 /** Projectiles. */
#define COLLISION_GROUP_DOOR_BLOCKER 14 /** Blocks entities not permitted to get near moving doors. */
#define COLLISION_GROUP_PASSABLE_DOOR 15 /** Doors that the player shouldn't collide with. */
#define COLLISION_GROUP_DISSOLVING 16 /** Things that are dissolving are in this group. */
#define COLLISION_GROUP_PUSHAWAY 17 /** Nonsolid on client and server, pushaway in player code. */
#define COLLISION_GROUP_NONE 0 /** Default; collides with static and dynamic objects. */
#define COLLISION_GROUP_DEBRIS 1 /** Collides with nothing but world and static stuff. */
#define COLLISION_GROUP_DEBRIS_TRIGGER 2 /** Same as debris, but hits triggers. */
#define COLLISION_GROUP_INTERACTIVE_DEBRIS 3 /** Collides with everything except other interactive debris or debris. */
#define COLLISION_GROUP_INTERACTIVE 4 /** Collides with everything except interactive debris or debris. */
#define COLLISION_GROUP_PLAYER 5 /** This is the default behavior expected for most prop_physics. */
#define COLLISION_GROUP_BREAKABLE_GLASS 6 /** Special group for glass debris. */
#define COLLISION_GROUP_VEHICLE 7 /** Collision group for driveable vehicles. */
#define COLLISION_GROUP_PLAYER_MOVEMENT 8 /** For HL2, same as Collision_Group_Player. */
#define COLLISION_GROUP_NPC 9 /** Generic NPC group. */
#define COLLISION_GROUP_IN_VEHICLE 10 /** For any entity inside a vehicle. */
#define COLLISION_GROUP_WEAPON 11 /** For any weapons that need collision detection. */
#define COLLISION_GROUP_VEHICLE_CLIP 12 /** Vehicle clip brush to restrict vehicle movement. */
#define COLLISION_GROUP_PROJECTILE 13 /** Projectiles. */
#define COLLISION_GROUP_DOOR_BLOCKER 14 /** Blocks entities not permitted to get near moving doors. */
#define COLLISION_GROUP_PASSABLE_DOOR 15 /** Doors that the player shouldn't collide with. */
#define COLLISION_GROUP_DISSOLVING 16 /** Things that are dissolving are in this group. */
#define COLLISION_GROUP_PUSHAWAY 17 /** Nonsolid on client and server, pushaway in player code. */
#define COLLISION_GROUP_NPC_ACTOR 18 /** Used so NPCs in scripts ignore the player. */
/**
* @endsection

View File

@ -60,6 +60,9 @@ ClassOnClientDisconnect(client)
{
// Disable class attributes with timers.
ClassHealthRegenStop(client);
// Reset previously selected class indexes.
ClassResetPreviousIndexes(client);
}
/**
@ -73,13 +76,13 @@ ClassOnClientSpawn(client)
decl String:steamid[16];
decl String:classname[64];
// Check if the player is alive.
// Check if the player is dead.
if (!IsPlayerAlive(client))
{
return;
}
// Check if there are valid classes. Block this event if classes aren't
// Check if there are no valid classes. Block this event if classes aren't
// done loading.
if (!ClassValidated)
{
@ -89,6 +92,9 @@ ClassOnClientSpawn(client)
// Reset attributes by triggering death event.
ClassOnClientDeath(client);
// Restore previously selected classes if available.
ClassRestoreIndexes(client);
// Cache original player model.
GetClientModel(client, originalmodel, sizeof(originalmodel));
strcopy(ClassOriginalPlayerModel[client], PLATFORM_MAX_PATH, originalmodel);
@ -219,6 +225,9 @@ ClassOnClientInfected(client, bool:motherzombie = false)
// class skills aren't improved.
motherzombie = false;
// Save class index to be restored next time.
ClassPrevious[client][ZR_CLASS_TEAM_ZOMBIES] = classindex;
// Change class.
classindex = motherindex;
}

View File

@ -337,10 +337,21 @@ new ClassCount;
new bool:ClassValidated;
/**
* Stores what class that the player have selected, for each team.
* Stores what class the player has selected, for each team.
*/
new ClassSelected[MAXPLAYERS + 1][ZR_CLASS_TEAMCOUNT];
/**
* Stores what class the player had selected last time, if available. Classes
* specified here will be restored on the player when he dies. In normal cases
* it should be -1 for all teams on all players.
*
* Usage example of this one is to restore the player's zombie class after
* being a mother zombie with a mother zombie class. But this feature can also
* be useful in the future.
*/
new ClassPrevious[MAXPLAYERS + 1][ZR_CLASS_TEAMCOUNT];
/**
* Cache for the currently selected team (admin menus).
*/
@ -527,6 +538,9 @@ ClassLoad(bool:keepMultipliers = false)
// Cache class data.
ClassReloadDataCache();
// Reset previously selected class indexes.
ClassResetPreviousIndexes();
// Reset attribute multipliers, if not keeping.
if (!keepMultipliers)
{
@ -542,7 +556,6 @@ ClassLoad(bool:keepMultipliers = false)
// Set config data.
ConfigSetConfigLoaded(File_Classes, true);
ConfigSetConfigReloadFunc(File_Classes, GetFunctionByName(GetMyHandle(), "ClassOnConfigReload"));
// ConfigSetConfigHandle(File_Classes, INVALID_HANDLE);
ConfigSetConfigPath(File_Classes, pathclasses);
// Remove key/value cache.
@ -774,6 +787,73 @@ ClassResetMultiplierCache()
}
}
/**
* Resets the previously selected class indexes on one or all clients.
*
* @param client Optional. Specify client to reset. Default is all.
*/
ClassResetPreviousIndexes(client = -1)
{
new teamid;
if (client > 0)
{
for (teamid = 0; teamid < ZR_CLASS_TEAMCOUNT; teamid++)
{
ClassPrevious[client][teamid] = -1;
}
}
else
{
for (client = 1; client <= MAXPLAYERS; client++)
{
for (teamid = 0; teamid < ZR_CLASS_TEAMCOUNT; teamid++)
{
ClassPrevious[client][teamid] = -1;
}
}
}
}
/**
* Restores previously selected class indexes on a player, if available.
* Note: Does not apply attributes. The classes are only marked as selected.
*
* @param client The client index.
*/
ClassRestoreIndexes(client)
{
new previouszombie = ClassPrevious[client][ZR_CLASS_TEAM_ZOMBIES];
new previoushuman = ClassPrevious[client][ZR_CLASS_TEAM_HUMANS];
new previousadmin = ClassPrevious[client][ZR_CLASS_TEAM_ADMINS];
// Validate zombie class index.
if (ClassValidateIndex(previouszombie))
{
// Mark previous zombie class as selected.
ClassSelected[client][ZR_CLASS_TEAM_ZOMBIES] = previouszombie;
}
// Validate human class index.
if (ClassValidateIndex(previoushuman))
{
// Mark previous zombie class as selected.
ClassSelected[client][ZR_CLASS_TEAM_HUMANS] = previoushuman;
}
// Validate admin class index.
if (ClassValidateIndex(previousadmin))
{
// Mark previous zombie class as selected.
ClassSelected[client][ZR_CLASS_TEAM_ADMINS] = previousadmin;
}
// Reset indexes.
ClassPrevious[client][ZR_CLASS_TEAM_ZOMBIES] = -1;
ClassPrevious[client][ZR_CLASS_TEAM_HUMANS] = -1;
ClassPrevious[client][ZR_CLASS_TEAM_ADMINS] = -1;
}
/**
* Sets default class indexes for each team on all players, or a single player
* if specified.