diff --git a/src/zr/event.inc b/src/zr/event.inc index b3d5a56..775b25a 100644 --- a/src/zr/event.inc +++ b/src/zr/event.inc @@ -89,6 +89,7 @@ public Action:EventRoundStart(Handle:event, const String:name[], bool:dontBroadc SEffectsOnRoundStart(); ZSpawnOnRoundStart(); VolOnRoundStart(); + ZTeleOnRoundStart(); // Fire post round_start event. //CreateTimer(0.0, EventRoundStartPost); diff --git a/src/zr/ztele/cvars.inc b/src/zr/ztele/cvars.inc index 0ac920d..b97380c 100644 --- a/src/zr/ztele/cvars.inc +++ b/src/zr/ztele/cvars.inc @@ -34,6 +34,7 @@ Handle ZTeleCvar_MaxZombie; Handle ZTeleCvar_MaxHuman; Handle ZTeleCvar_AutoCancel; Handle ZTeleCvar_AutoCancelDistance; +Handle ZTeleCvar_RandomPosition; void ZTele_OnCvarsCreate() { @@ -46,6 +47,7 @@ void ZTele_OnCvarsCreate() ZTeleCvar_MaxHuman = CreateConVar("zr_ztele_max_human", "1", "Max number of times a human is allowed to use ZTele per round. [Dependency: zr_ztele_human_(before)/(after)]"); ZTeleCvar_AutoCancel = CreateConVar("zr_ztele_autocancel", "1", "Automatically cancel ZTele if player moves out of a set boundary. [Dependency: zr_ztele_(zombie)/(human)[_(before)/(after)]]"); ZTeleCvar_AutoCancelDistance = CreateConVar("zr_ztele_autocancel_distance", "20", "Maximum distance, in feet, player is allowed to travel before teleport is cancelled. [Dependency: zr_ztele_autocancel]"); + ZTeleCvar_RandomPosition = CreateConVar("zr_ztele_random_position", "0", "Teleport player to the random spawn position, not only his own one."); } bool ZTele_ZombieCanTeleport() @@ -92,3 +94,8 @@ float ZTele_GetAutoCancelDistance() { return GetConVarFloat(ZTeleCvar_AutoCancelDistance); } + +bool ZTele_IsRandomPositionEnabled() +{ + return GetConVarBool(ZTeleCvar_RandomPosition); +} \ No newline at end of file diff --git a/src/zr/ztele/ztele.inc b/src/zr/ztele/ztele.inc index 41b7c13..0051f16 100644 --- a/src/zr/ztele/ztele.inc +++ b/src/zr/ztele/ztele.inc @@ -29,6 +29,8 @@ #include "zr/ztele/cvars" +#define MAX_PLAYER_SPAWNS 128 + /** * Array to store client's spawn location. */ @@ -54,6 +56,9 @@ Handle tZTele[MAXPLAYERS + 1]; */ int g_iZTeleTimeLeft[MAXPLAYERS + 1]; +float g_vecZTeleSpawnPoints[MAX_PLAYER_SPAWNS][3]; +int g_iZTeleSpawnPointsCount = 0; + /** * Create commands specific to ZTele. */ @@ -66,6 +71,36 @@ void ZTele_OnCommandsCreate() RegConsoleCmd("zr_ztele_force", ZTele_ForceCommand, "Force ZTele on a client. Usage: zr_ztele_force "); } +void ZTeleOnRoundStart() +{ + char classname[64]; + int maxentities = GetMaxEntities(); + + g_iZTeleSpawnPointsCount = 0; + + for (int i = MaxClients; i <= maxentities; i++) + { + if (!IsValidEdict(i)) + { + continue; + } + + if (g_iZTeleSpawnPointsCount >= MAX_PLAYER_SPAWNS) + { + break; + } + + GetEdictClassname(i, classname, sizeof(classname)); + + if (StrEqual(classname, "info_player_terrorist", true) || StrEqual(classname, "info_player_counterterrorist", true)) + { + GetEntPropVector(i, Prop_Send, "m_vecOrigin", g_vecZTeleSpawnPoints[g_iZTeleSpawnPointsCount]); + + g_iZTeleSpawnPointsCount++; + } + } +} + /** * Client is joining the server. * @@ -215,7 +250,15 @@ bool ZTeleClient(int client, bool force = false) void ZTele_TeleportClient(int client) { // Teleport client. - TeleportEntity(client, g_vecZTeleSpawn[client], NULL_VECTOR, view_as({0.0, 0.0, 0.0})); + if (ZTele_IsRandomPositionEnabled()) + { + int select = Math_GetRandomInt(0, g_iZTeleSpawnPointsCount - 1); + TeleportEntity(client, g_vecZTeleSpawnPoints[select], NULL_VECTOR, view_as({0.0, 0.0, 0.0})); + } + else + { + TeleportEntity(client, g_vecZTeleSpawn[client], NULL_VECTOR, view_as({0.0, 0.0, 0.0})); + } } /**