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

@ -116,16 +116,8 @@ public OnMapStart()
LoadModelData(); LoadModelData();
LoadDownloadData(); LoadDownloadData();
// Weapon restrict // Forward event to modules.
WeaponRestrictMapStart(); WeaponRestrictMapStart();
new i;
new classindex = GetDefaultClassIndex();
for (i = 1; i <= MAXPLAYERS; i++)
{
pClass[i] = classindex;
}
Anticamp_Startup(); Anticamp_Startup();
} }
@ -136,11 +128,6 @@ public OnMapEnd()
public OnConfigsExecuted() public OnConfigsExecuted()
{ {
FindMapSky();
LoadClassData();
LoadAmbienceData();
decl String:mapconfig[PLATFORM_MAX_PATH]; decl String:mapconfig[PLATFORM_MAX_PATH];
GetCurrentMap(mapconfig, sizeof(mapconfig)); GetCurrentMap(mapconfig, sizeof(mapconfig));
@ -152,8 +139,17 @@ public OnConfigsExecuted()
if (FileExists(path)) if (FileExists(path))
{ {
ServerCommand("exec %s", mapconfig); ServerCommand("exec %s", mapconfig);
LogMessage("Executed map config file: %s", mapconfig); if (LogFlagCheck(LOG_CORE_EVENTS))
{
LogMessage("Executed map config file: %s", mapconfig);
}
} }
FindMapSky();
ClassLoad();
LoadClassData();
LoadAmbienceData();
} }
public OnClientPutInServer(client) public OnClientPutInServer(client)
@ -167,8 +163,9 @@ public OnClientPutInServer(client)
new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]); new bool:zhp = GetConVarBool(gCvars[CVAR_ZHP_DEFAULT]);
dispHP[client] = zhp; dispHP[client] = zhp;
// Weapon restrict // Forward event to modules.
WeaponRestrictClientInit(client); WeaponRestrictClientInit(client);
ClassClientInit(client);
ClientHookAttack(client); ClientHookAttack(client);
@ -185,12 +182,12 @@ public OnClientPutInServer(client)
public OnClientDisconnect(client) public OnClientDisconnect(client)
{ {
// Weapon restrict
WeaponRestrictClientDisconnect(client);
ClientUnHookAttack(client); ClientUnHookAttack(client);
PlayerLeft(client); PlayerLeft(client);
// Forward event to modules.
WeaponRestrictClientDisconnect(client);
ClassOnClientDisconnect(client);
ZTeleResetClient(client); ZTeleResetClient(client);
AmbienceStop(client); AmbienceStop(client);
@ -232,6 +229,8 @@ ZREnd()
UnhookCvars(); UnhookCvars();
UnhookEvents(); UnhookEvents();
// TODO: Disable all modules! Teleport, ambience, overlays, antistick, etc.
new maxplayers = GetMaxClients(); new maxplayers = GetMaxClients();
for (new x = 1; x <= maxplayers; x++) for (new x = 1; x <= maxplayers; x++)
{ {

View File

@ -169,22 +169,22 @@ GetDefaultClassIndex()
} }
} }
GetClassModel(classindex, String:model[], maxlen) /*GetClassModel(classindex, String:model[], maxlen)
{ {
strcopy(model, maxlen, arrayClasses[classindex][data_model]); strcopy(model, maxlen, arrayClasses[classindex][data_model]);
} }*/
GetClassMenuDescription(classindex, String:menudescription[], maxlen) GetClassMenuDescription(classindex, String:menudescription[], maxlen)
{ {
strcopy(menudescription, maxlen, arrayClasses[classindex][data_menu_description]); strcopy(menudescription, maxlen, arrayClasses[classindex][data_menu_description]);
} }
GetClassZVision(classindex, String:zvision[], maxlen) /*GetClassZVision(classindex, String:zvision[], maxlen)
{ {
strcopy(zvision, maxlen, arrayClasses[classindex][data_zvision]); strcopy(zvision, maxlen, arrayClasses[classindex][data_zvision]);
} }*/
GetClassHealth(classindex) /*GetClassHealth(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -193,9 +193,9 @@ GetClassHealth(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_HEALTH]); return GetConVarInt(gCvars[CVAR_ZOMBIE_HEALTH]);
} }*/
Float:GetClassSpeed(classindex) /*Float:GetClassSpeed(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -204,9 +204,9 @@ Float:GetClassSpeed(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_SPEED]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_SPEED]);
} }*/
Float:GetClassJumpDistance(classindex) /*Float:GetClassJumpDistance(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -215,9 +215,9 @@ Float:GetClassJumpDistance(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_JUMP_DISTANCE]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_JUMP_DISTANCE]);
} }*/
Float:GetClassJumpHeight(classindex) /*Float:GetClassJumpHeight(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -226,9 +226,9 @@ Float:GetClassJumpHeight(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_JUMP_HEIGHT]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_JUMP_HEIGHT]);
} }*/
Float:GetClassKnockback(classindex) /*Float:GetClassKnockback(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -237,9 +237,9 @@ Float:GetClassKnockback(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_KNOCKBACK]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_KNOCKBACK]);
} }*/
bool:GetClassNVGs(classindex) /*bool:GetClassNVGs(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
@ -257,9 +257,9 @@ bool:GetClassNVGs(classindex)
} }
return IntToBool(GetConVarInt(gCvars[CVAR_ZOMBIE_NVGS])); return IntToBool(GetConVarInt(gCvars[CVAR_ZOMBIE_NVGS]));
} }*/
GetClassFOV(classindex) /*GetClassFOV(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -268,9 +268,9 @@ GetClassFOV(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_FOV]); return GetConVarInt(gCvars[CVAR_ZOMBIE_FOV]);
} }*/
bool:GetClassRegen(classindex) /*bool:GetClassRegen(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -279,9 +279,9 @@ bool:GetClassRegen(classindex)
} }
return GetConVarBool(gCvars[CVAR_ZOMBIE_REGEN]); return GetConVarBool(gCvars[CVAR_ZOMBIE_REGEN]);
} }*/
GetClassRegenHealth(classindex) /*GetClassRegenHealth(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -290,9 +290,9 @@ GetClassRegenHealth(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_REGEN_HEALTH]); return GetConVarInt(gCvars[CVAR_ZOMBIE_REGEN_HEALTH]);
} }*/
Float:GetClassRegenInterval(classindex) /*Float:GetClassRegenInterval(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -301,9 +301,9 @@ Float:GetClassRegenInterval(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_REGEN_INTERVAL]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_REGEN_INTERVAL]);
} }*/
bool:GetClassNapalm(classindex) /*bool:GetClassNapalm(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -312,9 +312,9 @@ bool:GetClassNapalm(classindex)
} }
return GetConVarBool(gCvars[CVAR_ZOMBIE_NAPALM]); return GetConVarBool(gCvars[CVAR_ZOMBIE_NAPALM]);
} }*/
Float:GetClassNapalmTime(classindex) /*Float:GetClassNapalmTime(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -323,9 +323,9 @@ Float:GetClassNapalmTime(classindex)
} }
return GetConVarFloat(gCvars[CVAR_ZOMBIE_NAPALM_TIME]); return GetConVarFloat(gCvars[CVAR_ZOMBIE_NAPALM_TIME]);
} }*/
bool:GetClassNoFallDamage(classindex) /*bool:GetClassNoFallDamage(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -334,9 +334,9 @@ bool:GetClassNoFallDamage(classindex)
} }
return GetConVarBool(gCvars[CVAR_ZOMBIE_NOFALLDAMAGE]); return GetConVarBool(gCvars[CVAR_ZOMBIE_NOFALLDAMAGE]);
} }*/
GetClassKillBonus(classindex) /*GetClassKillBonus(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -345,9 +345,9 @@ GetClassKillBonus(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_KILL_BONUS]); return GetConVarInt(gCvars[CVAR_ZOMBIE_KILL_BONUS]);
} }*/
GetClassInfectHealth(classindex) /*GetClassInfectHealth(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -356,9 +356,9 @@ GetClassInfectHealth(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_INFECT_HEALTH]); return GetConVarInt(gCvars[CVAR_ZOMBIE_INFECT_HEALTH]);
} }*/
GetClassAlphaSpawn(classindex) /*GetClassAlphaSpawn(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -367,9 +367,9 @@ GetClassAlphaSpawn(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_SPAWN]); return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_SPAWN]);
} }*/
GetClassAlphaDamaged(classindex) /*GetClassAlphaDamaged(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -378,9 +378,9 @@ GetClassAlphaDamaged(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_DAMAGED]); return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_DAMAGED]);
} }*/
GetClassAlphaDamage(classindex) /*GetClassAlphaDamage(classindex)
{ {
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]);
if (classes) if (classes)
@ -389,5 +389,4 @@ GetClassAlphaDamage(classindex)
} }
return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_DAMAGE]); return GetConVarInt(gCvars[CVAR_ZOMBIE_ALPHA_DAMAGE]);
} }*/

View File

@ -20,7 +20,9 @@ enum ZRSettings
Handle:CVAR_CLASSES_SPAWN, Handle:CVAR_CLASSES_SPAWN,
Handle:CVAR_CLASSES_RANDOM, Handle:CVAR_CLASSES_RANDOM,
Handle:CVAR_CLASSES_DEFAULT, Handle:CVAR_CLASSES_DEFAULT,
Handle:CVAR_CLASSES_SAVE, Handle:CVAR_CLASSES_DEFAULT_ZOMBIE,
Handle:CVAR_CLASSES_DEFAULT_HUMAN,
Handle:CVAR_CLASSES_DEFAULT_ADMIN,
Handle:CVAR_ZOMBIE_HEALTH, Handle:CVAR_ZOMBIE_HEALTH,
Handle:CVAR_ZOMBIE_SPEED, Handle:CVAR_ZOMBIE_SPEED,
Handle:CVAR_ZOMBIE_JUMP_DISTANCE, Handle:CVAR_ZOMBIE_JUMP_DISTANCE,
@ -98,7 +100,7 @@ new gCvars[ZRSettings];
CreateCvars() CreateCvars()
{ {
gCvars[CVAR_ENABLE] = CreateConVar("zr_enable", "1", "Enable zombie gameplay (0: Disable)"); gCvars[CVAR_ENABLE] = CreateConVar("zr_enable", "1", "Enable zombie gameplay (0: Disable)");
gCvars[CVAR_LOG] = CreateConVar("zr_log", "65", "Logging flags. Log messages to sourcemod logs, server console or client console. Use zr_log_flags to see a list of flags. (0: Disable)"); gCvars[CVAR_LOG] = CreateConVar("zr_log", "331", "Logging flags. Log messages to sourcemod logs, server console or client console. Use zr_log_flags to see a list of flags. (0: Disable)");
gCvars[CVAR_ALLOW_PLAYER_TEAM] = CreateConVar("zr_allow_player_team", "0", "This will allow the player_team event to be fired on first team join, enable when using mani model menu (0: Disable)"); gCvars[CVAR_ALLOW_PLAYER_TEAM] = CreateConVar("zr_allow_player_team", "0", "This will allow the player_team event to be fired on first team join, enable when using mani model menu (0: Disable)");
gCvars[CVAR_AMBIENCE] = CreateConVar("zr_ambience", "1", "Enable creepy ambience to be played throughout the game (0: Disable)"); gCvars[CVAR_AMBIENCE] = CreateConVar("zr_ambience", "1", "Enable creepy ambience to be played throughout the game (0: Disable)");
gCvars[CVAR_AMBIENCE_FILE] = CreateConVar("zr_ambience_file", "ambient/zr/zr_ambience.mp3", "Path to ambient sound file that will be played throughout the game, when zr_ambience is 1"); gCvars[CVAR_AMBIENCE_FILE] = CreateConVar("zr_ambience_file", "ambient/zr/zr_ambience.mp3", "Path to ambient sound file that will be played throughout the game, when zr_ambience is 1");
@ -107,8 +109,11 @@ CreateCvars()
gCvars[CVAR_EMITSOUNDS] = CreateConVar("zr_emitsounds", "50", "How often a zombie emits a sound, in seconds (0: Disable)"); gCvars[CVAR_EMITSOUNDS] = CreateConVar("zr_emitsounds", "50", "How often a zombie emits a sound, in seconds (0: Disable)");
gCvars[CVAR_CLASSES] = CreateConVar("zr_classes", "1", "Enable zombie classes"); 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_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. (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] = CreateConVar("zr_classes_default", "classic", "Default class selected for all players when they connect, or \"random\" to select a random class. Usage zr_classes_default <class name|\"random\">"); gCvars[CVAR_CLASSES_DEFAULT] = CreateConVar("zr_classes_default", "classic", "Default class selected for all players when they connect, or \"random\" to select a random class. Usage zr_classes_default <class name|\"random\">");
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_ZOMBIE_HEALTH] = CreateConVar("zr_zombie_health", "5000", "The default health of a zombie"); 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_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)"); gCvars[CVAR_ZOMBIE_JUMP_DISTANCE] = CreateConVar("zr_zombie_jump_distance", "0.1", "How far the zombie jumps, (0: Regular jump distance)");

View File

@ -88,7 +88,7 @@ public OnTakeDamage(client, inflictor, attacker, damage, damagetype, ammotype)
return Hacks_Continue; return Hacks_Continue;
} }
new bool:blockfalldamage = GetClassNoFallDamage(pClass[client]); new bool:blockfalldamage = ClassGetNoFallDamage(client);
if (!blockfalldamage) if (!blockfalldamage)
{ {
return Hacks_Continue; return Hacks_Continue;

View File

@ -129,7 +129,7 @@ public Action:PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
new index = GetClientOfUserId(GetEventInt(event, "userid")); new index = GetClientOfUserId(GetEventInt(event, "userid"));
new team = GetEventInt(event, "team"); new team = GetEventInt(event, "team");
if (team == 1) if (team == CS_TEAM_SPECTATOR)
{ {
gZombie[index] = false; gZombie[index] = false;
motherZombie[index] = false; motherZombie[index] = false;
@ -165,8 +165,8 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
gZombie[index] = false; gZombie[index] = false;
motherZombie[index] = false; motherZombie[index] = false;
// Reset FOV and overlay.
SetPlayerFOV(index, 90); SetPlayerFOV(index, 90);
ClientCommand(index, "r_screenoverlay \"\""); ClientCommand(index, "r_screenoverlay \"\"");
new team = GetClientTeam(index); new team = GetClientTeam(index);
@ -182,8 +182,7 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
SetPlayerMoney(index, cash); SetPlayerMoney(index, cash);
} }
ZTeleClientSpawned(index); // Remove night vision.
NightVisionOn(index, false); NightVisionOn(index, false);
NightVision(index, false); NightVision(index, false);
@ -241,38 +240,11 @@ public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
SetPlayerAlpha(index, 255); SetPlayerAlpha(index, 255);
} }
new bool:randomclass = GetConVarBool(gCvars[CVAR_CLASSES_RANDOM]); // Forward event to modules.
new bool:classes = GetConVarBool(gCvars[CVAR_CLASSES]); ClassOnClientSpawn(index);
if (classes) ZTeleClientSpawned(index);
{
new bool:showmenu = GetConVarBool(gCvars[CVAR_CLASSES_SPAWN]);
if (showmenu && !randomclass)
{
ClassMenu(index);
}
}
ZR_PrintToChat(index, "!zmenu reminder"); ZR_PrintToChat(index, "!zmenu reminder");
decl String:steamid[16];
GetClientAuthString(index, steamid, sizeof(steamid));
if (StrEqual(steamid, "BOT") || randomclass)
{
new class = GetRandomInt(0, classCount - 1);
Call_StartForward(hOnZClassChanged);
Call_PushCell(index);
Call_PushCell(pClass[index]);
Call_PushCell(class);
Call_Finish();
pClass[index] = class;
decl String:classname[32];
GetClassName(class, classname, sizeof(classname));
ZR_PrintToChat(index, "Auto-assign", classname);
}
} }
public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast) public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
@ -285,50 +257,63 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
decl String:weapon[32]; decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon)); GetEventString(event, "weapon", weapon, sizeof(weapon));
// Check if the attacker is a player.
if (attacker != 0) if (attacker != 0)
{ {
// Check if a zombie attacks a human.
if (IsPlayerHuman(index) && IsPlayerZombie(attacker)) if (IsPlayerHuman(index) && IsPlayerZombie(attacker))
{ {
// Check if spawn protection is disabled and the weapon is a knife.
if (!pProtect[index] && StrEqual(weapon, "knife")) if (!pProtect[index] && StrEqual(weapon, "knife"))
{ {
Zombify(index, attacker); Zombify(index, attacker);
} }
} }
else if (IsPlayerHuman(attacker))
// Check if a human attacks a zombie.
if (IsPlayerZombie(index) && IsPlayerHuman(attacker))
{ {
new Float:knockback = GetClassKnockback(pClass[index]); // Get zombie knockback value.
new Float:knockback = ClassGetKnockback(index);
new Float:clientloc[3]; new Float:clientloc[3];
new Float:attackerloc[3]; new Float:attackerloc[3];
GetClientAbsOrigin(index, clientloc); GetClientAbsOrigin(index, clientloc);
if (!StrEqual(weapon, "hegrenade")) // Check if a grenade was thrown.
if (StrEqual(weapon, "hegrenade"))
{
// Get the location of the grenade.
FindExplodingGrenade(attackerloc);
// Give knockback on the victim.
KnockBack(index, clientloc, attackerloc, knockback, dmg, true);
}
else
{ {
GetPlayerEyePosition(attacker, attackerloc); GetPlayerEyePosition(attacker, attackerloc);
new Float:attackerang[3]; new Float:attackerang[3];
GetPlayerEyeAngles(attacker, attackerang); GetPlayerEyeAngles(attacker, attackerang);
// Calculate victim location.
TR_TraceRayFilter(attackerloc, attackerang, MASK_ALL, RayType_Infinite, TraceRayFilter); TR_TraceRayFilter(attackerloc, attackerang, MASK_ALL, RayType_Infinite, TraceRayFilter);
TR_GetEndPosition(clientloc); TR_GetEndPosition(clientloc);
KnockBack(index, clientloc, attackerloc, knockback, dmg, false); KnockBack(index, clientloc, attackerloc, knockback, dmg, false);
} }
else
{
FindExplodingGrenade(attackerloc);
KnockBack(index, clientloc, attackerloc, knockback, dmg, true);
}
} }
} }
if (!IsPlayerZombie(index)) // Check if the player is a human.
if (IsPlayerHuman(index))
{ {
// We're done now. Nothing more to do on humans.
return; return;
} }
// Play a random zombie hurt sound.
if (GetRandomInt(1, 5) == 1) if (GetRandomInt(1, 5) == 1)
{ {
decl String:sound[64]; decl String:sound[64];
@ -340,28 +325,16 @@ public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
EmitSoundToAll(sound, index); EmitSoundToAll(sound, index);
} }
new bool:napalm = GetClassNapalm(pClass[index]); // Napalm effect.
if (napalm) new Float:napalm_time = ClassGetNapalmTime(index);
if (StrEqual(weapon, "hegrenade", false) && napalm_time > 0.0)
{ {
if (StrEqual(weapon, "hegrenade", false)) IgniteEntity(index, napalm_time);
{
new Float:napalm_time = GetClassNapalmTime(pClass[index]);
IgniteEntity(index, napalm_time);
}
} }
// Forward event to modules.
ClassAlphaUpdate(index);
UpdateHPDisplay(index); UpdateHPDisplay(index);
if (GetClassRegen(pClass[index]))
{
if (tHandles[index][TREGEN] == INVALID_HANDLE)
{
new Float:interval = GetClassRegenInterval(pClass[index]);
tHandles[index][TREGEN] = CreateTimer(interval, Regenerate, index, TIMER_REPEAT);
}
}
UpdateAlphaDamaged(index);
} }
public bool:TraceRayFilter(entity, contentsMask) public bool:TraceRayFilter(entity, contentsMask)
@ -403,26 +376,30 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{ {
new index = GetClientOfUserId(GetEventInt(event, "userid")); new index = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker")); new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
decl String:weapon[32];
// Reset field of view and extinguish fire.
SetPlayerFOV(index, DEFAULT_FOV); SetPlayerFOV(index, DEFAULT_FOV);
ExtinguishEntity(index); ExtinguishEntity(index);
decl String:weapon[32]; // Get the weapon name.
GetEventString(event, "weapon", weapon, sizeof(weapon)); GetEventString(event, "weapon", weapon, sizeof(weapon));
// Check if the player was infected.
if (StrEqual(weapon, "zombie_claws_of_death", false)) if (StrEqual(weapon, "zombie_claws_of_death", false))
{ {
// Add a death count to the players score.
if (index) if (index)
{ {
AddPlayerDeath(index, 1); AddPlayerDeath(index, 1);
} }
// Give a point to the attacker.
if (attacker) if (attacker)
{ {
AddPlayerScore(attacker, 1); AddPlayerScore(attacker, 1);
new healthgain = GetClassInfectHealth(pClass[attacker]); new healthgain = ClassGetHealthInfectGain(attacker);
new health = GetClientHealth(attacker); new health = GetClientHealth(attacker);
SetEntityHealth(attacker, health + healthgain); SetEntityHealth(attacker, health + healthgain);
@ -442,12 +419,14 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
PrecacheSound(sound); PrecacheSound(sound);
EmitSoundToAll(sound, index); EmitSoundToAll(sound, index);
// Give kill bonus.
if (attacker) if (attacker)
{ {
new bonus = GetClassKillBonus(pClass[index]); new bonus = ClassGetKillBonus(attacker);
AddPlayerScore(attacker, bonus); AddPlayerScore(attacker, bonus);
} }
// Check if the player was killed by world damage.
if (!IsClientPlayer(attacker)) if (!IsClientPlayer(attacker))
{ {
gKilledByWorld[index] = true; gKilledByWorld[index] = true;
@ -458,6 +437,7 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
} }
} }
// Kill various timers.
for (new x = 0; x < MAXTIMERS; x++) for (new x = 0; x < MAXTIMERS; x++)
{ {
if (tHandles[index][x] != INVALID_HANDLE) if (tHandles[index][x] != INVALID_HANDLE)
@ -467,6 +447,7 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
} }
} }
// Create respawn timer if enabled.
new bool:respawn = GetConVarBool(gCvars[CVAR_RESPAWN]); new bool:respawn = GetConVarBool(gCvars[CVAR_RESPAWN]);
if (respawn) if (respawn)
{ {
@ -475,26 +456,18 @@ public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
} }
} }
new ZTeam:team = IsRoundOver(); // Forward event to modules.
if (team == Neither) ClassOnClientDeath(index);
{
ClientCommand(index, "r_screenoverlay \"\"");
return;
}
new ZTeam:team = IsRoundOver();
RoundWin(team); RoundWin(team);
} }
public Action:PlayerJump(Handle:event, const String:name[], bool:dontBroadcast) public Action:PlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
{ {
new index = GetClientOfUserId(GetEventInt(event, "userid")); new client = GetClientOfUserId(GetEventInt(event, "userid"));
new Float:distance = ClassGetJumpDistance(client);
if (IsPlayerZombie(index)) new Float:height = ClassGetJumpHeight(client);
{
new Float:distance = GetClassJumpDistance(pClass[index]);
new Float:height = GetClassJumpHeight(pClass[index]);
JumpBoost(index, distance, height); JumpBoost(client, distance, height);
} }
}

View File

@ -116,7 +116,7 @@ LoadDownloadData()
CloseHandle(arrayDownloads); CloseHandle(arrayDownloads);
} }
ApplyZombieModel(client) /*ApplyZombieModel(client)
{ {
decl String:modelpath[256]; decl String:modelpath[256];
@ -136,4 +136,4 @@ ApplyZombieModel(client)
Format(modelpath, sizeof(modelpath), "%s.mdl", modelpath); Format(modelpath, sizeof(modelpath), "%s.mdl", modelpath);
SetPlayerModel(client, modelpath); SetPlayerModel(client, modelpath);
} }*/

View File

@ -37,6 +37,8 @@ bool:ClassApplyAttributes(client, bool:improved = false)
ClassApplyHealth(client, classindex, improved); ClassApplyHealth(client, classindex, improved);
ClassApplyHealthRegen(client, classindex); ClassApplyHealthRegen(client, classindex);
ClassApplySpeed(client, classindex); ClassApplySpeed(client, classindex);
return true;
} }
/** /**
@ -51,18 +53,18 @@ bool:ClassApplyAttributes(client, bool:improved = false)
* ZR_CLASS_CACHE_PLAYER (default) - Player cache. * ZR_CLASS_CACHE_PLAYER (default) - Player cache.
* @return True on success, false otherwise. * @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]; decl String:modelpath[256];
// Get the model path from the specified cache. // Get the model path from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER) if (cachetype == ZR_CLASS_CACHE_PLAYER)
{ {
ClassGetModelPath(client, modelpath, sizeof(modelpath), cachetype) ClassGetModelPath(client, modelpath, sizeof(modelpath), cachetype);
} }
else else
{ {
ClassGetModelPath(classindex, modelpath, sizeof(modelpath), cachetype) ClassGetModelPath(classindex, modelpath, sizeof(modelpath), cachetype);
} }
// Check if the user specified a random model. // 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) bool:ClassApplyAlpha(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
{ {
new alpha; new alpha;
// Get the alpha value from the specified cache. // Get the alpha value from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER) if (cachetype == ZR_CLASS_CACHE_PLAYER)
{ {
alpha = ClassGetAlphaSpawn(client, cachetype); alpha = ClassGetAlphaInitial(client, cachetype);
} }
else else
{ {
alpha = ClassGetAlphaSpawn(classindex, cachetype); alpha = ClassGetAlphaInitial(classindex, cachetype);
} }
if (alpha < 0) if (alpha < 0)
@ -111,8 +113,8 @@ bool:ClassApplyAlpha(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER)
return false; return false;
} }
SetPlayerAlpha(client, alpha); SetPlayerAlpha(client, alpha);
return true; return true;
} }
/** /**
@ -313,7 +315,7 @@ bool:ClassApplyHealthRegen(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER
*/ */
bool:ClassApplySpeed(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. // Get the health points from the specified cache.
if (cachetype == ZR_CLASS_CACHE_PLAYER) 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: case ZR_CLASS_CACHE_MODIFIED:
{ {
return ClassDataCached[index][class_team_default]; return ClassDataCache[index][class_team_default];
} }
case ZR_CLASS_CACHE_PLAYER: 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]; return bClientHasOverlay[client];
} }
ClassOverlayInitialize(client, const String:overlay) ClassOverlayInitialize(client, const String:overlay[])
{ {
if (IsFakeClient(client)) if (IsFakeClient(client))
{ {
@ -64,7 +64,7 @@ ClassOverlayStart(client)
tOverlay[client] = INVALID_HANDLE; tOverlay[client] = INVALID_HANDLE;
} }
ClientCommand(client, "r_screenoverlay \"%s\"", overlay); ClientCommand(client, "r_screenoverlay \"%s\"", ActiveOverlay[client]);
bClientOverlayOn[client] = true; bClientOverlayOn[client] = true;
new Float:redisplay = GetConVarFloat(gCvars[CVAR_OVERLAY_REDISPLAY]); 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 * 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 * 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: * @param cachetype Optional. Specifies what class cache to validate. Options:
* ZR_CLASS_CACHE_ORIGINAL (default, unchanged class data), * 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); zombieindex = ClassGetFirstClass(ZR_CLASS_TEAM_ZOMBIES, _, cachetype);
humanindex = ClassGetFirstClass(ZR_CLASS_TEAM_HUMANS, _, cachetype); humanindex = ClassGetFirstClass(ZR_CLASS_TEAM_HUMANS, _, cachetype);
if (zombieindex > -1 && humanindex > -1) // Validate indexes.
if (ClassValidateIndex(zombieindex) && ClassValidateIndex(humanindex))
{ {
return true; return true;
} }
@ -43,6 +44,40 @@ bool:ClassValidateTeamRequirements(cachetype = ZR_CLASS_CACHE_ORIGINAL)
return false; 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 * Validates all the class attributes in the original class data array, to
* check if they have invalid values. Boolean settings are not validated. * check if they have invalid values. Boolean settings are not validated.
@ -111,10 +146,12 @@ ClassValidateAttributes(classindex)
// Overlay path. // Overlay path.
decl String:overlay_path[256]; 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. // 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; flags += ZR_CLASS_ATTRIB_ERR_OVERLAY_PATH;
} }
@ -139,13 +176,13 @@ ClassValidateAttributes(classindex)
if (!(regen_interval >= 0.0 && regen_interval <= 900.0)) if (!(regen_interval >= 0.0 && regen_interval <= 900.0))
{ {
flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_INTERVAL; flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_INTERVAL;
}
// Health regen amount. Only validating if interval is set.
// Health regen amount. new regen_amount = ClassData[classindex][class_health_regen_amount];
new regen_amount = ClassData[classindex][class_health_regen_amount]; if (!(regen_amount > 0 && regen_amount <= 65536))
if (!(regen_amount > 0 && regen_amount <= 65536)) {
{ flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_AMOUNT;
flags += ZR_CLASS_ATTRIB_ERR_HEALTH_REGEN_AMOUNT; }
} }
// Health infect gain. // Health infect gain.
@ -267,7 +304,7 @@ ClassGetIndex(const String:name[], cachetype = ZR_CLASS_CACHE_MODIFIED)
for (new classindex = 0; classindex < ClassCount; classindex++) for (new classindex = 0; classindex < ClassCount; classindex++)
{ {
// Get its name and compare it with the specified class name. // 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) if (strcmp(name, current_name, false) == 0)
{ {
return classindex; return classindex;
@ -289,7 +326,7 @@ ClassGetActiveIndex(client)
{ {
new teamid = GetClientTeam(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. // No active team.
return -1; return -1;
@ -297,17 +334,17 @@ ClassGetActiveIndex(client)
if (IsPlayerHuman(client)) if (IsPlayerHuman(client))
{ {
teamid = ZR_TEAM_HUMANS; teamid = ZR_CLASS_TEAM_HUMANS;
} }
else else
{ {
teamid = ZR_TEAM_ZOMBIES; teamid = ZR_CLASS_TEAM_ZOMBIES;
} }
// TODO: How to detect that virtual admin team? // TODO: How to detect that virtual admin team?
// Return the active class for the current 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; 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 * Gets the default class index for the specified team configured to be used
* when players join the server. * when players join the server.
@ -493,8 +576,6 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
{ {
decl String:classname[64]; decl String:classname[64];
new classindex; new classindex;
new Handle:classarray;
new arraycount;
// Get the default class name from the correct CVAR depending on teamid. // Get the default class name from the correct CVAR depending on teamid.
switch (teamid) switch (teamid)
@ -519,13 +600,13 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
} }
// Check if the class name isn't empty. // 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. // Check if the user set "random" as default class.
if (strcmp(classname, "random", false) == 0) if (strcmp(classname, "random", false) == 0)
{ {
// Get a list of all classes with the specified team ID. // 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. // Validate the result, in case there were errors.
if (ClassValidateIndex(classindex)) if (ClassValidateIndex(classindex))
@ -545,7 +626,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
// The user set a spesific class. // The user set a spesific class.
// Try to get the class index with the specified class name. // 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. // Validate the class index and check if the team IDs match.
if (ClassValidateIndex(classindex) && (teamid == ClassGetTeamID(classindex, cachetype))) 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. // 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 // Because it's user input, we'll fall back to the first class
// in the specified team, and log a warning. // in the specified team, and log a warning.
classindex = ClassGetFirstClass(teamid, cachetype); classindex = ClassGetFirstClass(teamid, _, cachetype);
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES)) 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. // Validate the new index.
@ -570,7 +651,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
// Log a warning. // Log a warning.
if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES)) 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; return classindex;
@ -585,7 +666,7 @@ ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED)
} }
else else
{ {
// Blank class name, return a error code. // Blank class name, get the default class and return the index.
return -1; 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 * 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. * 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. * @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]; new ClassPlayerCache[MAXPLAYERS + 1][ClassAttributes];
/** /**
* Number of classes successfully loaded. * Number of classes loaded.
*/ */
new ClassCount; new ClassCount;
/** /**
* Stores what class that the player have selected, for each team. * 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/filtertools"
#include "zr/playerclasses/attributes" #include "zr/playerclasses/attributes"
#include "zr/playerclasses/apply" #include "zr/playerclasses/apply"
#include "zr/playerclasses/clientoverlays" #include "zr/playerclasses/clientoverlays"
#include "zr/playerclasses/clientalpha"
#include "zr/playerclasses/healthregen" #include "zr/playerclasses/healthregen"
#include "zr/playerclasses/classevents"
/** /**
* Loads class attributes from playerclasses.txt into the ClassData array. If * 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/ * @param classfile Optional. Specifies what file to read from. Valves key/
* values format. The path is relative to the sourcemod * values format. The path is relative to the sourcemod
@ -296,6 +298,7 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt")
/* General */ /* General */
ClassData[ClassCount][class_enabled] = bool:KvGetNum(kvClassData, "enabled", ZR_CLASS_DEFAULT_ENABLED); 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] = 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); KvGetString(kvClassData, "name", name, sizeof(name), ZR_CLASS_DEFAULT_NAME);
strcopy(ClassData[ClassCount][class_name], 64, 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); ZR_LogMessageFormatted(-1, "classes", "load", "Invalid class at index %d. Class error flags: %d.", LOG_FORMAT_TYPE_ERROR, ClassCount, ClassErrorFlags);
} }
} }
// Update the counter. // Update the counter.
ClassCount++; ClassCount++;
} while (KvGotoNextKey(kvClassData)); } 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."); 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; return false;
} }
for (new classindex = 0; classindex < ClassCount; clasindex++) for (new classindex = 0; classindex < ClassCount; classindex++)
{ {
/* General */ /* General */
ClassDataCache[classindex][class_enabled] = ClassData[classindex][class_enabled]; ClassDataCache[classindex][class_enabled] = ClassData[classindex][class_enabled];
@ -530,3 +542,93 @@ bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIF
return true; 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);
}
}
}

View File

@ -46,15 +46,22 @@ public Action:Command_NightVision(client, argc)
return; return;
} }
bZVisionOn[client] = !bZVisionOn[client]; //bZVisionOn[client] = !bZVisionOn[client];
bClientOverlayOn[client] = !bClientOverlayOn[client];
if (bZVisionOn[client]) decl String:overlay[256];
ClassGetOverlayPath(client, overlay, sizeof(overlay));
if (strlen(overlay) > 0)
{ {
ZVisionPreCheck(client); if (bClientOverlayOn[client])
} {
else ClassOverlayInitialize(client, overlay);
{ }
ZVisionStop(client); else
{
ClassOverlayStop(client);
}
} }
} }
@ -163,25 +170,26 @@ Zombify_Mother(client)
gZombie[client] = true; gZombie[client] = true;
motherZombie[client] = true; motherZombie[client] = true;
ApplyZombieHealth(client,true); //ApplyZombieHealth(client,true);
ApplyZombieSpeed(client); //ApplyZombieSpeed(client);
CS_SwitchTeam(client, CS_TEAM_T); CS_SwitchTeam(client, CS_TEAM_T);
RemoveAllPlayersWeapons(client); RemoveAllPlayersWeapons(client);
GivePlayerItem(client, "weapon_knife"); GivePlayerItem(client, "weapon_knife");
ApplyZombieNightVision(client); //ApplyZombieNightVision(client);
ZVisionPreCheck(client);
ApplyZombieFOV(client); //ZVisionPreCheck(client);
ApplyZombieModel(client); //ApplyZombieFOV(client);
ApplyZombieAlpha(client); //ApplyZombieModel(client);
//ApplyZombieAlpha(client);
ClassOnClientInfected(client, true);
InfectionEffects(client); InfectionEffects(client);
ztele_count[client] = 0; ztele_count[client] = 0;
@ -249,23 +257,24 @@ Zombify(client, attacker)
gZombie[client] = true; gZombie[client] = true;
ApplyZombieHealth(client, false); //ApplyZombieHealth(client, false);
ApplyZombieSpeed(client); //ApplyZombieSpeed(client);
RemoveAllPlayersWeapons(client); RemoveAllPlayersWeapons(client);
GivePlayerItem(client, "weapon_knife"); GivePlayerItem(client, "weapon_knife");
ApplyZombieNightVision(client); //ApplyZombieNightVision(client);
ZVisionPreCheck(client); //ZVisionPreCheck(client);
ApplyZombieFOV(client); //ApplyZombieFOV(client);
ApplyZombieModel(client); //ApplyZombieModel(client);
ApplyZombieAlpha(client); //ApplyZombieAlpha(client);
ClassOnClientInfected(client);
InfectionEffects(client); InfectionEffects(client);
ztele_count[client] = 0; ztele_count[client] = 0;
@ -387,7 +396,7 @@ InfectionEffects(client)
} }
} }
ApplyZombieHealth(client, bool:mother) /*ApplyZombieHealth(client, bool:mother)
{ {
new health = GetClassHealth(pClass[client]); new health = GetClassHealth(pClass[client]);
@ -397,15 +406,15 @@ ApplyZombieHealth(client, bool:mother)
} }
SetEntityHealth(client, health); SetEntityHealth(client, health);
} }*/
ApplyZombieSpeed(client) /*ApplyZombieSpeed(client)
{ {
new Float:speed = GetClassSpeed(pClass[client]); new Float:speed = GetClassSpeed(pClass[client]);
SetPlayerSpeed(client, speed); SetPlayerSpeed(client, speed);
} }*/
ApplyZombieNightVision(client) /*ApplyZombieNightVision(client)
{ {
new bool:nvgs = GetClassNVGs(pClass[client]); new bool:nvgs = GetClassNVGs(pClass[client]);
NightVision(client, nvgs); NightVision(client, nvgs);
@ -414,19 +423,19 @@ ApplyZombieNightVision(client)
{ {
NightVisionOn(client, nvgs); NightVisionOn(client, nvgs);
} }
} }*/
ApplyZombieFOV(client) /*ApplyZombieFOV(client)
{ {
new fov = GetClassFOV(pClass[client]); new fov = GetClassFOV(pClass[client]);
SetPlayerFOV(client, fov); SetPlayerFOV(client, fov);
} }*/
ApplyZombieAlpha(client) /*ApplyZombieAlpha(client)
{ {
new alpha = GetClassAlphaSpawn(pClass[client]); new alpha = GetClassAlphaSpawn(pClass[client]);
SetPlayerAlpha(client, alpha); SetPlayerAlpha(client, alpha);
} }*/
KnockBack(client, const Float:clientloc[3], const Float:attackerloc[3], Float:power, dmg, bool:grenade) KnockBack(client, const Float:clientloc[3], const Float:attackerloc[3], Float:power, dmg, bool:grenade)
{ {
@ -650,7 +659,7 @@ RemoveObjectives()
} }
} }
ZVisionPreCheck(client) /*ZVisionPreCheck(client)
{ {
if (IsFakeClient(client)) if (IsFakeClient(client))
{ {
@ -671,24 +680,24 @@ ZVisionPreCheck(client)
ZVisionStart(client); ZVisionStart(client);
} }
} }*/
ZVisionStart(client) /*ZVisionStart(client)
{ {
/*if (tHandles[client][TZVISION] != INVALID_HANDLE) //if (tHandles[client][TZVISION] != INVALID_HANDLE)
{ //{
KillTimer(tHandles[client][TZVISION]); // KillTimer(tHandles[client][TZVISION]);
tHandles[client][TZVISION] = INVALID_HANDLE; // tHandles[client][TZVISION] = INVALID_HANDLE;
}*/ //}
DisplayClientOverlay(client, ZVisionOverlay[client]); DisplayClientOverlay(client, ZVisionOverlay[client]);
bZVisionOn[client] = true; bZVisionOn[client] = true;
//new Float:redisplay = GetConVarFloat(gCvars[CVAR_ZVISION_REDISPLAY]); //new Float:redisplay = GetConVarFloat(gCvars[CVAR_ZVISION_REDISPLAY]);
//tHandles[client][TZVISION] = CreateTimer(redisplay, ZVisionTimer, client, TIMER_REPEAT); //tHandles[client][TZVISION] = CreateTimer(redisplay, ZVisionTimer, client, TIMER_REPEAT);
} }*/
ZVisionStop(client) /*ZVisionStop(client)
{ {
if (tHandles[client][TZVISION] != INVALID_HANDLE) if (tHandles[client][TZVISION] != INVALID_HANDLE)
{ {
@ -698,7 +707,7 @@ ZVisionStop(client)
ClientCommand(client, "r_screenoverlay \"\""); ClientCommand(client, "r_screenoverlay \"\"");
bZVisionOn[client] = false; bZVisionOn[client] = false;
} }*/
/*public Action:ZVisionTimer(Handle:timer, any:client) /*public Action:ZVisionTimer(Handle:timer, any:client)
{ {
@ -737,7 +746,7 @@ public Action:ZombieMoanTimer(Handle:timer, any:index)
return Plugin_Continue; return Plugin_Continue;
} }
public Action:Regenerate(Handle:timer, any:index) /*public Action:Regenerate(Handle:timer, any:index)
{ {
if (!IsClientInGame(index) || !IsPlayerZombie(index)) if (!IsClientInGame(index) || !IsPlayerZombie(index))
{ {
@ -769,7 +778,7 @@ public Action:Regenerate(Handle:timer, any:index)
UpdateHPDisplay(index); UpdateHPDisplay(index);
return Plugin_Continue; return Plugin_Continue;
} }*/
UpdateHPDisplay(client) UpdateHPDisplay(client)
{ {
@ -793,18 +802,6 @@ UpdateHPDisplay(client)
ZR_HudHint(client, "Display HP", health); ZR_HudHint(client, "Display HP", health);
} }
UpdateAlphaDamaged(client)
{
new current_health = GetClientHealth(client);
new max_health = GetClassHealth(pClass[client]);
new max_damage = GetClassAlphaDamage(pClass[client]);
if (max_health - current_health > max_damage)
{
new alpha_damaged = GetClassAlphaDamaged(pClass[client]);
SetPlayerAlpha(client, alpha_damaged);
}
}
public Action:ZHPTimer(Handle:timer, any:index) public Action:ZHPTimer(Handle:timer, any:index)
{ {
if (!IsClientInGame(index)) if (!IsClientInGame(index))

View File

@ -63,8 +63,8 @@ new bool:motherZombie[MAXPLAYERS+1];
new bool:gZombie[MAXPLAYERS+1]; new bool:gZombie[MAXPLAYERS+1];
new bool:gBlockMotherInfect[MAXPLAYERS+1]; new bool:gBlockMotherInfect[MAXPLAYERS+1];
new bool:bZVision[MAXPLAYERS+1]; new bool:bZVision[MAXPLAYERS+1];
new bool:bZVisionOn[MAXPLAYERS+1]; //new bool:bZVisionOn[MAXPLAYERS+1];
new String:ZVisionOverlay[MAXPLAYERS+1][PLATFORM_MAX_PATH]; //new String:ZVisionOverlay[MAXPLAYERS+1][PLATFORM_MAX_PATH];
new bool:dispHP[MAXPLAYERS+1]; new bool:dispHP[MAXPLAYERS+1];
new bool:pProtect[MAXPLAYERS+1]; new bool:pProtect[MAXPLAYERS+1];
new bool:gKilledByWorld[MAXPLAYERS+1] = {false, ...}; new bool:gKilledByWorld[MAXPLAYERS+1] = {false, ...};
@ -211,18 +211,6 @@ bool:IsPlayerInList(client)
return false; return false;
} }
bool:IntToBool(intval)
{
if (intval == 0)
{
return false;
}
else
{
return true;
}
}
bool:IsClientPlayer(client) bool:IsClientPlayer(client)
{ {
if (client > 0 && client <= maxclients) if (client > 0 && client <= maxclients)