2009-04-27 04:00:38 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-04-27 04:00:38 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: event.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Event hooking and forwarding.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-27 04:00:38 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Init function for event module.
|
|
|
|
*/
|
|
|
|
EventInit()
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-27 04:00:38 +02:00
|
|
|
// Hook all events used by plugin.
|
|
|
|
EventHook();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Hook events used by plugin.
|
|
|
|
*
|
|
|
|
* @param unhook If true, then unhook all events, if false, then hook.
|
|
|
|
*/
|
|
|
|
EventHook(bool:unhook = false)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-27 04:00:38 +02:00
|
|
|
// If unhook is true, then continue.
|
|
|
|
if (unhook)
|
|
|
|
{
|
|
|
|
// Unhook all events.
|
|
|
|
UnhookEvent("round_start", EventRoundStart);
|
|
|
|
UnhookEvent("round_freeze_end", EventRoundFreezeEnd);
|
|
|
|
UnhookEvent("round_end", EventRoundEnd);
|
|
|
|
UnhookEvent("player_team", EventPlayerTeam, EventHookMode_Pre);
|
|
|
|
UnhookEvent("player_spawn", EventPlayerSpawn);
|
|
|
|
UnhookEvent("player_hurt", EventPlayerHurt);
|
|
|
|
UnhookEvent("player_death", EventPlayerDeath);
|
|
|
|
UnhookEvent("player_jump", EventPlayerJump);
|
|
|
|
UnhookEvent("weapon_fire", EventWeaponFire);
|
|
|
|
|
|
|
|
// Stop after unhooking events.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hook all events used by plugin.
|
|
|
|
HookEvent("round_start", EventRoundStart);
|
|
|
|
HookEvent("round_freeze_end", EventRoundFreezeEnd);
|
|
|
|
HookEvent("round_end", EventRoundEnd);
|
|
|
|
HookEvent("player_team", EventPlayerTeam, EventHookMode_Pre);
|
|
|
|
HookEvent("player_spawn", EventPlayerSpawn);
|
|
|
|
HookEvent("player_hurt", EventPlayerHurt);
|
|
|
|
HookEvent("player_death", EventPlayerDeath);
|
|
|
|
HookEvent("player_jump", EventPlayerJump);
|
|
|
|
HookEvent("weapon_fire", EventWeaponFire);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (round_start)
|
|
|
|
* The round is starting.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
|
2009-04-24 05:02:19 +02:00
|
|
|
{
|
2009-04-18 01:44:41 +02:00
|
|
|
// Forward event to sub-modules.
|
2009-05-14 02:28:26 +02:00
|
|
|
OverlaysOnRoundStart();
|
2009-05-20 06:24:43 +02:00
|
|
|
RoundStartOnRoundStart();
|
2009-04-18 01:44:41 +02:00
|
|
|
RoundEndOnRoundStart();
|
2009-04-22 04:53:19 +02:00
|
|
|
InfectOnRoundStart();
|
2009-04-18 01:44:41 +02:00
|
|
|
SEffectsOnRoundStart();
|
2009-04-29 01:58:41 +02:00
|
|
|
ZSpawnOnRoundStart();
|
2009-05-16 01:37:23 +02:00
|
|
|
VolOnRoundStart();
|
2009-06-16 20:20:56 +02:00
|
|
|
|
|
|
|
// Fire post round_start event.
|
2009-08-21 21:47:32 +02:00
|
|
|
//CreateTimer(0.0, EventRoundStartPost);
|
2009-06-16 20:20:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event callback (round_start)
|
|
|
|
* The round is starting. *Post
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
2009-08-21 21:47:32 +02:00
|
|
|
//public Action:EventRoundStartPost(Handle:timer)
|
|
|
|
//{
|
2009-06-16 20:20:56 +02:00
|
|
|
// Forward event to modules.
|
2009-08-21 21:47:32 +02:00
|
|
|
//}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (round_freeze_end)
|
|
|
|
* The freeze time is ending.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventRoundFreezeEnd(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-17 01:09:52 +02:00
|
|
|
// Forward events to modules.
|
2009-04-18 01:44:41 +02:00
|
|
|
RoundEndOnRoundFreezeEnd();
|
2009-04-22 04:53:19 +02:00
|
|
|
InfectOnRoundFreezeEnd();
|
2009-05-06 03:04:55 +02:00
|
|
|
ZSpawnOnRoundFreezeEnd();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (round_end)
|
|
|
|
* The round is ending.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2009-04-18 01:44:41 +02:00
|
|
|
new reason = GetEventInt(event, "reason");
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-04-18 01:44:41 +02:00
|
|
|
// Forward event to modules.
|
2009-06-27 03:33:09 +02:00
|
|
|
WeaponsOnRoundEnd();
|
2009-04-18 01:44:41 +02:00
|
|
|
RoundEndOnRoundEnd(reason);
|
2009-04-22 04:53:19 +02:00
|
|
|
InfectOnRoundEnd();
|
2009-05-05 07:40:15 +02:00
|
|
|
SEffectsOnRoundEnd();
|
2009-04-27 04:00:38 +02:00
|
|
|
RespawnOnRoundEnd();
|
2009-05-06 03:04:55 +02:00
|
|
|
ZSpawnOnRoundEnd();
|
2009-05-16 01:37:23 +02:00
|
|
|
VolOnRoundEnd();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (player_team)
|
|
|
|
* Client is joining a team.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerTeam(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2008-10-04 22:59:11 +02:00
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new team = GetEventInt(event, "team");
|
|
|
|
|
2009-04-22 04:53:19 +02:00
|
|
|
// Forward event to modules.
|
|
|
|
InfectOnClientTeam(index, team);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (player_spawn)
|
|
|
|
* Client is spawning into the game.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2008-10-04 22:59:11 +02:00
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Forward event to modules.
|
2009-05-21 07:13:51 +02:00
|
|
|
InfectOnClientSpawn(index); // Some modules depend on this to finish first.
|
2009-06-05 05:58:48 +02:00
|
|
|
AccountOnClientSpawn(index); // Some modules depend on this to finish first.
|
2009-05-21 04:15:55 +02:00
|
|
|
ClassOnClientSpawn(index);
|
2009-06-05 05:58:48 +02:00
|
|
|
WeaponsOnClientSpawn(index);
|
2009-06-26 02:10:45 +02:00
|
|
|
RoundStartOnClientSpawn(index);
|
2009-04-17 01:09:52 +02:00
|
|
|
SEffectsOnClientSpawn(index);
|
2009-04-16 22:21:32 +02:00
|
|
|
RespawnOnClientSpawn(index);
|
2009-05-05 06:56:34 +02:00
|
|
|
ZTeleOnClientSpawn(index);
|
2009-04-16 22:21:32 +02:00
|
|
|
ZHPOnClientSpawn(index);
|
2009-05-30 04:17:01 +02:00
|
|
|
VolOnPlayerSpawn(index);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-15 07:25:07 +02:00
|
|
|
// Fire post player_spawn event.
|
|
|
|
CreateTimer(0.0, EventPlayerSpawnPost, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event callback (player_spawn)
|
|
|
|
* Client is spawning into the game. *Post
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
2009-06-23 01:37:26 +02:00
|
|
|
public Action:EventPlayerSpawnPost(Handle:timer, any:client)
|
2009-05-15 07:25:07 +02:00
|
|
|
{
|
2009-05-19 08:14:18 +02:00
|
|
|
// If client isn't in-game, then stop.
|
2009-06-23 01:37:26 +02:00
|
|
|
if (!IsClientInGame(client))
|
2009-05-19 08:14:18 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-15 07:25:07 +02:00
|
|
|
// Forward event to modules.
|
2009-06-23 01:37:26 +02:00
|
|
|
WeaponsOnClientSpawnPost(client);
|
|
|
|
SEffectsOnClientSpawnPost(client);
|
|
|
|
SpawnProtectOnClientSpawnPost(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (player_hurt)
|
|
|
|
* Client is being hurt.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2008-10-04 22:59:11 +02:00
|
|
|
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
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
decl String:weapon[WEAPONS_MAX_LENGTH];
|
2008-10-04 22:59:11 +02:00
|
|
|
GetEventString(event, "weapon", weapon, sizeof(weapon));
|
|
|
|
|
2009-04-11 01:56:22 +02:00
|
|
|
// Forward event to modules.
|
|
|
|
ClassAlphaUpdate(index);
|
2009-04-22 04:53:19 +02:00
|
|
|
InfectOnClientHurt(index, attacker, weapon);
|
2009-06-16 20:20:56 +02:00
|
|
|
AccountOnClientHurt(attacker, dmg_health);
|
2009-04-17 01:09:52 +02:00
|
|
|
SEffectsOnClientHurt(index);
|
2009-04-16 22:21:32 +02:00
|
|
|
KnockbackOnClientHurt(index, attacker, weapon, hitgroup, dmg_health);
|
2009-06-14 19:10:30 +02:00
|
|
|
NapalmOnClientHurt(index, attacker, weapon);
|
2009-04-17 10:20:04 +02:00
|
|
|
ZHPOnClientHurt(index);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (player_death)
|
|
|
|
* Client has been killed.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-11 01:56:22 +02:00
|
|
|
// Get the weapon name.
|
2009-04-27 04:00:38 +02:00
|
|
|
decl String:weapon[WEAPONS_MAX_LENGTH];
|
2008-10-04 22:59:11 +02:00
|
|
|
GetEventString(event, "weapon", weapon, sizeof(weapon));
|
2009-04-11 01:56:22 +02:00
|
|
|
|
2009-04-22 04:53:19 +02:00
|
|
|
// If client is being infected, then stop.
|
2008-10-04 22:59:11 +02:00
|
|
|
if (StrEqual(weapon, "zombie_claws_of_death", false))
|
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
return;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-04-22 04:53:19 +02:00
|
|
|
|
|
|
|
// Get all required event info.
|
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
|
|
|
|
|
|
|
|
// Forward event to modules.
|
|
|
|
ClassOnClientDeath(index);
|
2009-05-21 07:42:45 +02:00
|
|
|
InfectOnClientDeath(index, attacker);
|
2009-06-08 06:05:50 +02:00
|
|
|
VEffectsOnClientDeath(index);
|
2009-04-22 04:53:19 +02:00
|
|
|
SEffectsOnClientDeath(index);
|
|
|
|
SpawnProtectOnClientDeath(index);
|
|
|
|
RespawnOnClientDeath(index, attacker, weapon);
|
2009-05-21 07:39:24 +02:00
|
|
|
NapalmOnClientDeath(index);
|
2009-05-06 03:04:55 +02:00
|
|
|
ZSpawnOnClientDeath(index);
|
2009-05-05 06:56:34 +02:00
|
|
|
ZTeleOnClientDeath(index);
|
2009-04-22 04:53:19 +02:00
|
|
|
ZHPOnClientDeath(index);
|
2009-07-17 18:15:44 +02:00
|
|
|
VolOnPlayerDeath(index);
|
2009-08-04 00:13:36 +02:00
|
|
|
RoundEndOnClientDeath();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (player_jump)
|
|
|
|
* Client is jumping.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerJump(Handle:event, const String:name[], bool:dontBroadcast)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2009-04-29 01:58:41 +02:00
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
2009-04-22 04:53:19 +02:00
|
|
|
|
2009-06-23 01:37:26 +02:00
|
|
|
// Fire post player_jump event.
|
|
|
|
CreateTimer(0.0, EventPlayerJumpPost, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event callback (player_jump)
|
|
|
|
* Client is jumping. *Post
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventPlayerJumpPost(Handle:timer, any:client)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:58:41 +02:00
|
|
|
// Forward event to modules.
|
2009-06-23 01:37:26 +02:00
|
|
|
JumpBoostOnClientJumpPost(client);
|
2009-04-11 01:56:22 +02:00
|
|
|
}
|
2009-04-17 10:20:04 +02:00
|
|
|
|
2009-04-27 04:00:38 +02:00
|
|
|
/**
|
|
|
|
* Event callback (weapon_fire)
|
|
|
|
* Weapon has been fired.
|
|
|
|
*
|
|
|
|
* @param event The event handle.
|
|
|
|
* @param name Name of the event.
|
|
|
|
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
|
|
|
|
*/
|
|
|
|
public Action:EventWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
|
2009-04-17 10:20:04 +02:00
|
|
|
{
|
2009-04-22 04:53:19 +02:00
|
|
|
// Get all required event info.
|
2009-06-14 19:10:30 +02:00
|
|
|
new index = GetClientOfUserId(GetEventInt(event, "userid"));
|
2009-04-17 10:20:04 +02:00
|
|
|
decl String:weapon[32];
|
|
|
|
GetEventString(event, "weapon", weapon, sizeof(weapon));
|
|
|
|
|
|
|
|
// Forward event to modules.
|
2009-06-14 19:10:30 +02:00
|
|
|
NapalmOnWeaponFire(index, weapon);
|
2009-04-17 10:20:04 +02:00
|
|
|
}
|