From 6334246ceddb150a22980ccec32ace69bc0a443f Mon Sep 17 00:00:00 2001 From: zaCade Date: Sun, 10 Mar 2019 19:59:20 +0100 Subject: [PATCH] ZSpawn: Add auto zspawn. --- .../zombiereloaded/zombiereloaded.cfg | 4 +++ .../zombiereloaded/zombiereloaded.cfg | 4 +++ src/zr/cvars.inc | 2 ++ src/zr/event.inc | 29 +++++++++++++++++++ src/zr/zspawn.inc | 25 ++++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/csgo/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg b/csgo/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg index 49fcc80..42cd41e 100644 --- a/csgo/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg +++ b/csgo/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg @@ -719,6 +719,10 @@ zr_vol_trigger_interval "1.0" // Default: "1" zr_zspawn "1" +// Should zspawn spawn joining players? +// Default: "1" +zr_zspawn_auto "1" + // Override spawn team when spawning by means of ZSpawn. // Default: "1" zr_zspawn_team_override "1" diff --git a/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg b/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg index 49fcc80..42cd41e 100644 --- a/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg +++ b/cstrike/cfg/sourcemod/zombiereloaded/zombiereloaded.cfg @@ -719,6 +719,10 @@ zr_vol_trigger_interval "1.0" // Default: "1" zr_zspawn "1" +// Should zspawn spawn joining players? +// Default: "1" +zr_zspawn_auto "1" + // Override spawn team when spawning by means of ZSpawn. // Default: "1" zr_zspawn_team_override "1" diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 17da431..19bf8ae 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -174,6 +174,7 @@ enum CvarsList Handle:CVAR_VOL_UPDATE_INTERVAL, Handle:CVAR_VOL_TRIGGER_INTERVAL, Handle:CVAR_ZSPAWN, + Handle:CVAR_ZSPAWN_AUTO, Handle:CVAR_ZSPAWN_TEAM_OVERRIDE, Handle:CVAR_ZSPAWN_TEAM_ZOMBIE, Handle:CVAR_ZSPAWN_BLOCK_REJOIN, @@ -498,6 +499,7 @@ CvarsCreate() // ZSpawn (module) // =========================== g_hCvarsList[CVAR_ZSPAWN] = CreateConVar("zr_zspawn", "1", "Allow players to spawn into the game late."); + g_hCvarsList[CVAR_ZSPAWN_AUTO] = CreateConVar("zr_zspawn_auto", "1", "Should zspawn spawn joining players?"); g_hCvarsList[CVAR_ZSPAWN_TEAM_OVERRIDE] = CreateConVar("zr_zspawn_team_override", "1", "Override spawn team when spawning by means of ZSpawn."); g_hCvarsList[CVAR_ZSPAWN_TEAM_ZOMBIE] = CreateConVar("zr_zspawn_team_zombie", "0", "Spawn player on zombie team when spawning by means of ZSpawn. [Dependency: zr_zspawn_team_override | Override: zr_respawn_team_zombie]"); diff --git a/src/zr/event.inc b/src/zr/event.inc index 420c6a7..f550f94 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -54,6 +54,9 @@ EventHook(bool:unhook = false) UnhookEvent("player_death", EventPlayerDeath); UnhookEvent("player_jump", EventPlayerJump); + // Unhook all listeners. + RemoveCommandListener(CommandPlayerClass, "joinclass"); + // Stop after unhooking events. return; } @@ -67,6 +70,9 @@ EventHook(bool:unhook = false) HookEvent("player_hurt", EventPlayerHurt); HookEvent("player_death", EventPlayerDeath); HookEvent("player_jump", EventPlayerJump); + + // Hook all listeners used by plugin. + AddCommandListener(CommandPlayerClass, "joinclass"); } /** @@ -148,6 +154,12 @@ public Action:EventPlayerTeam(Handle:event, const String:name[], bool:dontBroadc InfectOnClientTeam(index, team); ImmunityOnClientTeam(index); + // Bots dont call `joinclass`. So call here. + if (IsFakeClient(index)) + { + ZSpawnOnClientTeam(index); + } + return Plugin_Handled; } @@ -317,3 +329,20 @@ public Action:EventPlayerJumpPost(Handle:timer, any:client) // Forward event to modules. JumpBoostOnClientJumpPost(client); } + +/** + * Command callback (joinclass) + * Client is joining a class. + * + * @param client The client. + * @param command The command performed. + * @param argc The amount of arguments. + */ +public Action:CommandPlayerClass(int client, const char[] command, int argc) +{ + if (IsFakeClient(client)) + return; + + // Forward event to modules. + ZSpawnOnClientTeam(client); +} diff --git a/src/zr/zspawn.inc b/src/zr/zspawn.inc index 23cb9ba..f2fdfd0 100644 --- a/src/zr/zspawn.inc +++ b/src/zr/zspawn.inc @@ -115,6 +115,31 @@ ZSpawnOnClientDeath(client) // Add client to the SteamID cache. SteamidCacheAddClient(g_hZSpawnSteamIDCache, client); } +/** + * Client is joining a team/class. + * + * @param client The client index. + */ +ZSpawnOnClientTeam(client) +{ + // Is auto zspawn enabled and is the client death? + new bool:autozspawn = GetConVarBool(g_hCvarsList[CVAR_ZSPAWN_AUTO]); + if (autozspawn && !IsPlayerAlive(client)) + { + // Get our zspawn condition. + new ZSpawnCondition:condition = GetZSpawnCondition(); + + switch(condition) + { + case ZSpawn_Human, ZSpawn_Zombie: + { + // Respawn client. + CS_RespawnPlayer(client); + } + + } + } +} /** * Client is spawning into the game.