//checks if the spot is clear of players public static bool IsSpawnPointValid(BaseEntity pPlayer, BaseEntity pSpot) { if (!pSpot.IsTriggered(pPlayer)) { return(false); } for (BaseEntity ent = null; (ent = EntUtils.FindEntityInSphere(ent, pSpot.Origin, 128)) != null;) { // if ent is a client, don't spawn on 'em if (ent.IsPlayer() && ent != pPlayer) { return(false); } } return(true); }
private static BaseEntity EntDetermineSpawnPoint(BaseEntity pPlayer) { BaseEntity pSpot; // choose a info_player_deathmatch point if (Engine.GameRules.IsCoOp()) { pSpot = EntUtils.FindEntityByClassName(g_pLastSpawn, "info_player_coop"); if (pSpot != null) { return(pSpot); } pSpot = EntUtils.FindEntityByClassName(g_pLastSpawn, "info_player_start"); if (pSpot != null) { return(pSpot); } } else if (Engine.GameRules.IsDeathmatch()) { pSpot = g_pLastSpawn; // Randomize the start spot for (var i = EngineRandom.Long(1, 5); i > 0; i--) { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } if (pSpot == null) // skip over the null point { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } var pFirstSpot = pSpot; do { if (pSpot != null) { // check if pSpot is valid if (IsSpawnPointValid(pPlayer, pSpot)) { if (pSpot.Origin == WorldConstants.g_vecZero) { pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); continue; } // if so, go to pSpot return(pSpot); } } // increment pSpot pSpot = EntUtils.FindEntityByClassName(pSpot, "info_player_deathmatch"); } while (pSpot != pFirstSpot); // loop if we're not back to the start // we haven't found a place to spawn yet, so kill any guy at the first spawn point and spawn there if (pSpot != null) { for (BaseEntity ent = null; (ent = EntUtils.FindEntityInSphere(ent, pSpot.Origin, 128)) != null;) { // if ent is a client, kill em (unless they are ourselves) if (ent.IsPlayer() && ent != pPlayer) { ent.TakeDamage(World.WorldInstance, World.WorldInstance, 300, DamageTypes.Generic); } } return(pSpot); } } // If startspot is set, (re)spawn there. if (string.IsNullOrEmpty(Engine.Globals.StartSpot)) { pSpot = EntUtils.FindEntityByClassName(null, "info_player_start"); if (pSpot != null) { return(pSpot); } } else { pSpot = EntUtils.FindEntityByTargetName(null, Engine.Globals.StartSpot); if (pSpot != null) { return(pSpot); } } Log.Alert(AlertType.Error, "PutClientInServer: no info_player_start on level"); return(null); }