2008-10-04 22:59:11 +02:00
|
|
|
/**
|
|
|
|
* ====================
|
|
|
|
* Zombie:Reloaded
|
|
|
|
* File: events.inc
|
|
|
|
* Author: Greyscale
|
|
|
|
* ====================
|
|
|
|
*/
|
|
|
|
|
|
|
|
HookEvents()
|
|
|
|
{
|
|
|
|
HookEvent("round_start", RoundStart);
|
|
|
|
HookEvent("round_freeze_end", RoundFreezeEnd);
|
|
|
|
HookEvent("round_end", RoundEnd);
|
|
|
|
HookEvent("player_team", PlayerTeam, EventHookMode_Pre);
|
|
|
|
HookEvent("player_spawn", PlayerSpawn);
|
|
|
|
HookEvent("player_hurt", PlayerHurt);
|
|
|
|
HookEvent("player_death", PlayerDeath);
|
|
|
|
HookEvent("player_jump", PlayerJump);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnhookEvents()
|
|
|
|
{
|
|
|
|
UnhookEvent("round_start", RoundStart);
|
|
|
|
UnhookEvent("round_freeze_end", RoundFreezeEnd);
|
|
|
|
UnhookEvent("round_end", RoundEnd);
|
|
|
|
UnhookEvent("player_team", PlayerTeam, EventHookMode_Pre);
|
|
|
|
UnhookEvent("player_spawn", PlayerSpawn);
|
|
|
|
UnhookEvent("player_hurt", PlayerHurt);
|
|
|
|
UnhookEvent("player_death", PlayerDeath);
|
|
|
|
UnhookEvent("player_jump", PlayerJump);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
ChangeLightStyle();
|
2009-02-15 22:25:17 +01:00
|
|
|
AmbienceRestartAll();
|
2009-04-05 23:20:35 +02:00
|
|
|
AntiStickRestart();
|
2008-10-04 22:59:11 +02:00
|
|
|
RefreshList();
|
|
|
|
|
|
|
|
if (tRound != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tRound);
|
2008-10-04 22:59:11 +02:00
|
|
|
tRound = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tInfect != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tInfect);
|
2008-10-04 22:59:11 +02:00
|
|
|
tInfect = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZR_PrintToChat(0, "Round objective");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:RoundFreezeEnd(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
RemoveObjectives();
|
|
|
|
|
|
|
|
if (tRound != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tRound);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
new Float:roundlen = GetConVarFloat(FindConVar("mp_roundtime")) * 60.0;
|
|
|
|
tRound = CreateTimer(roundlen, RoundOver, _, TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
|
|
|
|
if (tInfect != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tInfect);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
new Float:min = GetConVarFloat(gCvars[CVAR_SPAWN_MIN]);
|
|
|
|
new Float:max = GetConVarFloat(gCvars[CVAR_SPAWN_MAX]);
|
|
|
|
new Float:randlen = GetRandomFloat(min, max);
|
|
|
|
tInfect = CreateTimer(randlen, MotherZombie, _, TIMER_FLAG_NO_MAPCHANGE);
|
2008-12-20 20:46:05 +01:00
|
|
|
|
|
|
|
ZTeleEnable();
|
|
|
|
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Action:RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
if (tRound != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tRound);
|
2008-10-04 22:59:11 +02:00
|
|
|
tRound = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tInfect != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tInfect);
|
2008-10-04 22:59:11 +02:00
|
|
|
tInfect = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
zombieSpawned = false;
|
|
|
|
|
|
|
|
new maxplayers = GetMaxClients();
|
|
|
|
for (new x = 1; x<= maxplayers; x++)
|
|
|
|
{
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gZombie[x] = false;
|
|
|
|
|
|
|
|
new bool:consecutive_infect = GetConVarBool(gCvars[CVAR_CONSECUTIVE_INFECT]);
|
|
|
|
gBlockMotherInfect[x] = consecutive_infect ? false : motherZombie[x];
|
|
|
|
}
|
|
|
|
|
|
|
|
BalanceTeams();
|
|
|
|
|
|
|
|
new reason = GetEventInt(event, "reason");
|
|
|
|
|
|
|
|
if (reason == CTs_PreventEscape)
|
|
|
|
{
|
|
|
|
ShowOverlays(5.0, Human);
|
|
|
|
}
|
|
|
|
else if (reason == Terrorists_Escaped)
|
|
|
|
{
|
|
|
|
ShowOverlays(5.0, Zombie);
|
|
|
|
}
|
2008-12-20 20:46:05 +01:00
|
|
|
|
|
|
|
ZTeleReset();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Action:PlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new team = GetEventInt(event, "team");
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
if (team == CS_TEAM_SPECTATOR)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
gZombie[index] = false;
|
|
|
|
motherZombie[index] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
new bool:allow_player_team = GetConVarBool(gCvars[CVAR_ALLOW_PLAYER_TEAM]);
|
|
|
|
if (allow_player_team && !IsPlayerInList(index))
|
|
|
|
{
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
|
|
|
|
for (new x = 0; x < MAXTIMERS; x++)
|
|
|
|
{
|
|
|
|
if (x == TRESPAWN)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tHandles[index][x] != INVALID_HANDLE)
|
|
|
|
{
|
2009-03-30 00:35:51 +02:00
|
|
|
KillTimer(tHandles[index][x]);
|
2008-10-04 22:59:11 +02:00
|
|
|
tHandles[index][x] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gZombie[index] = false;
|
|
|
|
motherZombie[index] = false;
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Reset FOV and overlay.
|
2008-10-04 22:59:11 +02:00
|
|
|
SetPlayerFOV(index, 90);
|
|
|
|
ClientCommand(index, "r_screenoverlay \"\"");
|
|
|
|
|
2009-04-15 11:27:03 +02:00
|
|
|
// Stop here if client isn't on a team.
|
2008-10-04 22:59:11 +02:00
|
|
|
new team = GetClientTeam(index);
|
|
|
|
if (team != CS_TEAM_T && team != CS_TEAM_CT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new bool:cashfill = GetConVarBool(gCvars[CVAR_CASHFILL]);
|
|
|
|
if (cashfill)
|
|
|
|
{
|
|
|
|
new cash = GetConVarInt(gCvars[CVAR_CASHAMOUNT]);
|
|
|
|
SetPlayerMoney(index, cash);
|
|
|
|
}
|
2008-12-20 20:46:05 +01:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Remove night vision.
|
2008-10-04 22:59:11 +02:00
|
|
|
NightVisionOn(index, false);
|
|
|
|
NightVision(index, false);
|
|
|
|
|
|
|
|
if (zombieSpawned)
|
|
|
|
{
|
|
|
|
if (team == CS_TEAM_T)
|
|
|
|
{
|
|
|
|
CS_SwitchTeam(index, CS_TEAM_CT);
|
|
|
|
CS_RespawnPlayer(index);
|
|
|
|
}
|
|
|
|
}
|
2008-10-04 23:02:25 +02:00
|
|
|
else
|
|
|
|
{
|
2008-11-13 17:03:28 +01:00
|
|
|
SetPlayerAlpha(index, 255);
|
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Forward event to modules.
|
|
|
|
ClassOnClientSpawn(index);
|
2009-04-15 11:27:03 +02:00
|
|
|
SpawnProtectPlayerSpawn(index);
|
2009-04-11 01:56:22 +02:00
|
|
|
ZTeleClientSpawned(index);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
ZR_PrintToChat(index, "!zmenu reminder");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
|
|
|
|
|
2009-04-15 03:24:02 +02:00
|
|
|
new hitgroup = GetEventInt(event, "hitgroup");
|
|
|
|
|
2009-04-14 22:05:20 +02:00
|
|
|
new dmg_health = GetEventInt(event, "dmg_health");
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
decl String:weapon[32];
|
|
|
|
GetEventString(event, "weapon", weapon, sizeof(weapon));
|
|
|
|
|
2009-04-14 22:05:20 +02:00
|
|
|
// Forward event to modules.
|
2009-04-15 03:24:02 +02:00
|
|
|
KnockbackPlayerHurt(index, attacker, weapon, hitgroup, dmg_health);
|
2009-04-14 22:05:20 +02:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Check if the attacker is a player.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (attacker != 0)
|
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
// Check if a zombie attacks a human.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (IsPlayerHuman(index) && IsPlayerZombie(attacker))
|
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
// Check if spawn protection is disabled and the weapon is a knife.
|
2008-10-04 23:02:25 +02:00
|
|
|
if (!pProtect[index] && StrEqual(weapon, "knife"))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
Zombify(index, attacker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-11 01:56:22 +02:00
|
|
|
|
|
|
|
// Check if the player is a human.
|
|
|
|
if (IsPlayerHuman(index))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
// We're done now. Nothing more to do on humans.
|
2008-10-04 22:59:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Play a random zombie hurt sound.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (GetRandomInt(1, 5) == 1)
|
|
|
|
{
|
|
|
|
decl String:sound[64];
|
|
|
|
new randsound = GetRandomInt(1, 6);
|
|
|
|
|
|
|
|
Format(sound, sizeof(sound), "npc/zombie/zombie_pain%d.wav", randsound);
|
|
|
|
|
|
|
|
PrecacheSound(sound);
|
|
|
|
EmitSoundToAll(sound, index);
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Napalm effect.
|
|
|
|
new Float:napalm_time = ClassGetNapalmTime(index);
|
|
|
|
if (StrEqual(weapon, "hegrenade", false) && napalm_time > 0.0)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
IgniteEntity(index, napalm_time);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Forward event to modules.
|
|
|
|
ClassAlphaUpdate(index);
|
2008-10-04 22:59:11 +02:00
|
|
|
UpdateHPDisplay(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
|
2009-04-11 01:56:22 +02:00
|
|
|
decl String:weapon[32];
|
2008-12-28 00:50:39 +01:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Reset field of view and extinguish fire.
|
2008-10-04 22:59:11 +02:00
|
|
|
SetPlayerFOV(index, DEFAULT_FOV);
|
|
|
|
ExtinguishEntity(index);
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Get the weapon name.
|
2008-10-04 22:59:11 +02:00
|
|
|
GetEventString(event, "weapon", weapon, sizeof(weapon));
|
2009-04-11 01:56:22 +02:00
|
|
|
|
|
|
|
// Check if the player was infected.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (StrEqual(weapon, "zombie_claws_of_death", false))
|
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
// Add a death count to the players score.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (index)
|
|
|
|
{
|
|
|
|
AddPlayerDeath(index, 1);
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Give a point to the attacker.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (attacker)
|
|
|
|
{
|
|
|
|
AddPlayerScore(attacker, 1);
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
new healthgain = ClassGetHealthInfectGain(attacker);
|
2008-10-04 22:59:11 +02:00
|
|
|
new health = GetClientHealth(attacker);
|
|
|
|
|
|
|
|
SetEntityHealth(attacker, health + healthgain);
|
|
|
|
|
|
|
|
UpdateHPDisplay(attacker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (IsPlayerZombie(index))
|
|
|
|
{
|
|
|
|
decl String:sound[64];
|
|
|
|
|
|
|
|
new randsound = GetRandomInt(1, 3);
|
|
|
|
Format(sound, sizeof(sound), "npc/zombie/zombie_die%d.wav", randsound);
|
|
|
|
|
|
|
|
PrecacheSound(sound);
|
|
|
|
EmitSoundToAll(sound, index);
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Give kill bonus.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (attacker)
|
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
new bonus = ClassGetKillBonus(attacker);
|
2008-10-04 22:59:11 +02:00
|
|
|
AddPlayerScore(attacker, bonus);
|
|
|
|
}
|
2008-12-28 00:50:39 +01:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Check if the player was killed by world damage.
|
2008-12-28 00:50:39 +01:00
|
|
|
if (!IsClientPlayer(attacker))
|
|
|
|
{
|
|
|
|
gKilledByWorld[index] = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gKilledByWorld[index] = false;
|
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Kill various timers.
|
2008-10-04 22:59:11 +02:00
|
|
|
for (new x = 0; x < MAXTIMERS; x++)
|
|
|
|
{
|
|
|
|
if (tHandles[index][x] != INVALID_HANDLE)
|
|
|
|
{
|
2008-10-29 22:02:46 +01:00
|
|
|
KillTimer(tHandles[index][x]);
|
2008-10-04 22:59:11 +02:00
|
|
|
tHandles[index][x] = INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Create respawn timer if enabled.
|
2008-10-04 22:59:11 +02:00
|
|
|
new bool:respawn = GetConVarBool(gCvars[CVAR_RESPAWN]);
|
|
|
|
if (respawn)
|
|
|
|
{
|
|
|
|
new Float:delay = GetConVarFloat(gCvars[CVAR_RESPAWN_DELAY]);
|
|
|
|
tHandles[index][TRESPAWN] = CreateTimer(delay, RespawnTimer, index, TIMER_FLAG_NO_MAPCHANGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Forward event to modules.
|
|
|
|
ClassOnClientDeath(index);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
new ZTeam:team = IsRoundOver();
|
2008-10-04 22:59:11 +02:00
|
|
|
RoundWin(team);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action:PlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
|
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
new client = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new Float:distance = ClassGetJumpDistance(client);
|
|
|
|
new Float:height = ClassGetJumpHeight(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
JumpBoost(client, distance, height);
|
|
|
|
}
|