sm-zombiereloaded-3/src/zr/event.inc

308 lines
8.1 KiB
PHP
Raw Normal View History

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);
HookEvent("weapon_fire", WeaponFire);
2008-10-04 22:59:11 +02:00
}
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);
UnhookEvent("weapon_fire", WeaponFire);
2008-10-04 22:59:11 +02:00
}
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
ChangeLightStyle();
if (tInfect != INVALID_HANDLE)
{
KillTimer(tInfect);
2008-10-04 22:59:11 +02:00
tInfect = INVALID_HANDLE;
}
g_bZombieSpawned = false;
for (new x = 1; x<= MaxClients; x++)
{
if (!IsClientInGame(x))
{
continue;
}
bZombie[x] = false;
}
2008-10-04 22:59:11 +02:00
ZR_PrintToChat(0, "Round objective");
// Forward event to sub-modules.
RoundEndOnRoundStart();
SEffectsOnRoundStart();
AntiStickOnRoundStart();
2008-10-04 22:59:11 +02:00
}
public Action:RoundFreezeEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
RemoveObjectives();
if (tInfect != INVALID_HANDLE)
{
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);
// Forward events to modules.
RoundEndOnRoundFreezeEnd();
ZTeleEnable();
2008-10-04 22:59:11 +02:00
}
public Action:RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
new reason = GetEventInt(event, "reason");
2008-10-04 22:59:11 +02:00
if (tInfect != INVALID_HANDLE)
{
KillTimer(tInfect);
2008-10-04 22:59:11 +02:00
tInfect = INVALID_HANDLE;
}
g_bZombieSpawned = false;
2008-10-04 22:59:11 +02:00
for (new x = 1; x<= MaxClients; x++)
2008-10-04 22:59:11 +02:00
{
if (!IsClientInGame(x))
{
continue;
}
bZombie[x] = false;
2008-10-04 22:59:11 +02:00
}
// Forward event to modules.
RoundEndOnRoundEnd(reason);
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");
if (team == CS_TEAM_SPECTATOR)
2008-10-04 22:59:11 +02:00
{
bZombie[index] = false;
2008-10-04 22:59:11 +02:00
}
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 (tHandles[index][x] != INVALID_HANDLE)
{
KillTimer(tHandles[index][x]);
2008-10-04 22:59:11 +02:00
tHandles[index][x] = INVALID_HANDLE;
}
}
bZombie[index] = false;
2008-10-04 22:59:11 +02:00
// Reset FOV and overlay.
2008-10-04 22:59:11 +02:00
SetPlayerFOV(index, 90);
ClientCommand(index, "r_screenoverlay \"\"");
// Check if client is on a team.
if (ZRIsClientOnTeam(index))
2008-10-04 22:59:11 +02:00
{
new bool:cashfill = GetConVarBool(gCvars[CVAR_CASHFILL]);
if (cashfill)
2008-10-04 22:59:11 +02:00
{
new cash = GetConVarInt(gCvars[CVAR_CASHAMOUNT]);
SetPlayerMoney(index, cash);
}
// Remove night vision.
NightVisionOn(index, false);
NightVision(index, false);
if (g_bZombieSpawned)
{
if (ZRIsClientOnTeam(index, CS_TEAM_T))
{
CS_SwitchTeam(index, CS_TEAM_CT);
CS_RespawnPlayer(index);
}
}
else
{
SetPlayerAlpha(index, 255);
2008-10-04 22:59:11 +02:00
}
}
2008-10-04 22:59:11 +02:00
// Forward event to modules.
ClassOnClientSpawn(index);
SEffectsOnClientSpawn(index);
SpawnProtectOnClientSpawn(index);
RespawnOnClientSpawn(index);
ZHPOnClientSpawn(index);
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"));
new hitgroup = GetEventInt(event, "hitgroup");
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));
// Check if the attacker is a player.
if (ZRIsValidClient(attacker))
2008-10-04 22:59:11 +02:00
{
// Check if a zombie attacks a human.
2008-10-04 22:59:11 +02:00
if (IsPlayerHuman(index) && IsPlayerZombie(attacker))
{
// Check if spawn protection is disabled and the weapon is a knife.
if (!pSpawnProtect[index] && StrEqual(weapon, "knife"))
2008-10-04 22:59:11 +02:00
{
InfectPlayer(index, attacker);
2008-10-04 22:59:11 +02:00
}
}
}
// Forward event to modules.
ClassAlphaUpdate(index);
SEffectsOnClientHurt(index);
KnockbackOnClientHurt(index, attacker, weapon, hitgroup, dmg_health);
NapalmOnClientHurt(index, weapon);
ZHPOnClientHurt(index);
2008-10-04 22:59:11 +02:00
}
public Action:PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new index = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
// Reset field of view and extinguish fire.
2008-10-04 22:59:11 +02:00
SetPlayerFOV(index, DEFAULT_FOV);
ExtinguishEntity(index);
// Get the weapon name.
decl String:weapon[32];
2008-10-04 22:59:11 +02:00
GetEventString(event, "weapon", weapon, sizeof(weapon));
// Check if the player was infected.
2008-10-04 22:59:11 +02:00
if (StrEqual(weapon, "zombie_claws_of_death", false))
{
// Add a death count to the players score.
if (ZRIsValidClient(index))
2008-10-04 22:59:11 +02:00
{
AddPlayerDeath(index, 1);
}
// Give a point to the attacker.
if (ZRIsValidClient(attacker))
2008-10-04 22:59:11 +02:00
{
AddPlayerScore(attacker, 1);
new healthgain = ClassGetHealthInfectGain(attacker);
2008-10-04 22:59:11 +02:00
new health = GetClientHealth(attacker);
SetEntityHealth(attacker, health + healthgain);
// Forward event to modules.
ZHPOnHealthInfectGain(attacker);
2008-10-04 22:59:11 +02:00
}
}
else
{
if (IsPlayerZombie(index))
{
// Give kill bonus.
if (ZRIsValidClient(attacker))
2008-10-04 22:59:11 +02:00
{
new bonus = ClassGetKillBonus(attacker);
2008-10-04 22:59:11 +02:00
AddPlayerScore(attacker, bonus);
}
}
// Kill various timers.
2008-10-04 22:59:11 +02:00
for (new x = 0; x < MAXTIMERS; x++)
{
if (tHandles[index][x] != INVALID_HANDLE)
{
KillTimer(tHandles[index][x]);
2008-10-04 22:59:11 +02:00
tHandles[index][x] = INVALID_HANDLE;
}
}
}
// Forward event to modules.
ClassOnClientDeath(index);
SEffectsOnClientDeath(index);
SpawnProtectOnClientDeath(index);
RespawnOnClientDeath(index, attacker, weapon);
ZHPOnClientDeath(index);
2008-10-04 22:59:11 +02:00
new RoundEndOutcome:outcome;
if (RoundEndGetRoundStatus(outcome))
{
RoundEndTerminateRound(outcome);
}
2008-10-04 22:59:11 +02:00
}
public Action:PlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new Float:distance = ClassGetJumpDistance(client);
new Float:height = ClassGetJumpHeight(client);
2008-10-04 22:59:11 +02:00
JumpBoost(client, distance, height);
}
public Action:WeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon));
// Forward event to modules.
NapalmOnWeaponFire(weapon);
}