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

293 lines
8.6 KiB
PHP
Raw Normal View History

/*
* ============================================================================
*
2008-10-04 22:59:11 +02:00
* Zombie:Reloaded
*
* File: event.inc
* Type: Core
* Description: Event hooking and forwarding.
*
* ============================================================================
2008-10-04 22:59:11 +02:00
*/
/**
* Init function for event module.
*/
EventInit()
2008-10-04 22:59:11 +02:00
{
// Hook all events used by plugin.
EventHook();
2008-10-04 22:59:11 +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
{
// 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
}
/**
* 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)
{
// Print round objective to all clients.
TranslationPrintToChatAll(true, false, "General round objective");
// Forward event to sub-modules.
OverlaysOnRoundStart();
WeaponsOnRoundStart();
RoundStartOnRoundStart();
RoundEndOnRoundStart();
InfectOnRoundStart();
SEffectsOnRoundStart();
AntiStickOnRoundStart();
2009-04-29 01:58:41 +02:00
ZSpawnOnRoundStart();
VolOnRoundStart();
2008-10-04 22:59:11 +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
{
// Forward events to modules.
RoundEndOnRoundFreezeEnd();
InfectOnRoundFreezeEnd();
2009-05-06 03:04:55 +02:00
ZSpawnOnRoundFreezeEnd();
2008-10-04 22:59:11 +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
{
// Get all required event info.
new reason = GetEventInt(event, "reason");
2008-10-04 22:59:11 +02:00
// Forward event to modules.
WeaponsOnRoundEnd();
RoundEndOnRoundEnd(reason);
InfectOnRoundEnd();
2009-05-05 07:40:15 +02:00
SEffectsOnRoundEnd();
RespawnOnRoundEnd();
2009-05-06 03:04:55 +02:00
ZSpawnOnRoundEnd();
VolOnRoundEnd();
2008-10-04 22:59:11 +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
{
// Get all required event info.
2008-10-04 22:59:11 +02:00
new index = GetClientOfUserId(GetEventInt(event, "userid"));
new team = GetEventInt(event, "team");
// Forward event to modules.
InfectOnClientTeam(index, team);
2008-10-04 22:59:11 +02:00
return Plugin_Handled;
}
/**
* 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
{
// Get all required event info.
2008-10-04 22:59:11 +02:00
new index = GetClientOfUserId(GetEventInt(event, "userid"));
// Forward event to modules.
InfectOnClientSpawn(index); // Some modules depend on this to finish first.
AccountOnClientSpawn(index); // Some modules depend on this to finish first.
ClassOnClientSpawn(index);
WeaponsOnClientSpawn(index);
SEffectsOnClientSpawn(index);
SpawnProtectOnClientSpawn(index);
RespawnOnClientSpawn(index);
ZTeleOnClientSpawn(index);
ZHPOnClientSpawn(index);
VolOnPlayerSpawn(index);
2008-10-04 22:59:11 +02:00
TranslationPrintToChat(index, "General zmenu reminder");
// 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.
*/
public Action:EventPlayerSpawnPost(Handle:timer, any:index)
{
// If client isn't in-game, then stop.
if (!IsClientInGame(index))
{
return;
}
// Forward event to modules.
SpawnProtectOnClientSpawnPost(index);
2008-10-04 22:59:11 +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
{
// 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"));
new hitgroup = GetEventInt(event, "hitgroup");
new dmg_health = GetEventInt(event, "dmg_health");
2008-10-04 22:59:11 +02:00
decl String:weapon[WEAPONS_MAX_LENGTH];
2008-10-04 22:59:11 +02:00
GetEventString(event, "weapon", weapon, sizeof(weapon));
// Forward event to modules.
ClassAlphaUpdate(index);
InfectOnClientHurt(index, attacker, weapon);
SEffectsOnClientHurt(index);
KnockbackOnClientHurt(index, attacker, weapon, hitgroup, dmg_health);
NapalmOnClientHurt(index, weapon);
ZHPOnClientHurt(index);
2008-10-04 22:59:11 +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
{
// Get the weapon name.
decl String:weapon[WEAPONS_MAX_LENGTH];
2008-10-04 22:59:11 +02:00
GetEventString(event, "weapon", weapon, sizeof(weapon));
// If client is being infected, then stop.
2008-10-04 22:59:11 +02:00
if (StrEqual(weapon, "zombie_claws_of_death", false))
{
return;
2008-10-04 22:59:11 +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);
RoundEndOnClientDeath();
2009-05-21 07:42:45 +02:00
InfectOnClientDeath(index, attacker);
SEffectsOnClientDeath(index);
SpawnProtectOnClientDeath(index);
RespawnOnClientDeath(index, attacker, weapon);
NapalmOnClientDeath(index);
2009-05-06 03:04:55 +02:00
ZSpawnOnClientDeath(index);
ZTeleOnClientDeath(index);
ZHPOnClientDeath(index);
2008-10-04 22:59:11 +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
{
// Get all required event info.
2009-04-29 01:58:41 +02:00
new index = GetClientOfUserId(GetEventInt(event, "userid"));
2009-04-29 01:58:41 +02:00
// Forward event to modules.
JumpBoostOnClientJump(index);
}
/**
* 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)
{
// Get all required event info.
decl String:weapon[32];
GetEventString(event, "weapon", weapon, sizeof(weapon));
// Forward event to modules.
NapalmOnWeaponFire(weapon);
}