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); }
// common member functions public override void SUB_UseTargets(BaseEntity pActivator, UseType useType, float value = 0) { // // exit immediatly if we don't have a target or kill target // if (string.IsNullOrEmpty(Target) && string.IsNullOrEmpty(KillTarget)) { return; } // // check for a delay // if (Delay != 0) { // create a temp object to fire at a later time var pTemp = Engine.EntityRegistry.CreateInstance <BaseDelay>(); pTemp.SetNextThink(Engine.Globals.Time + Delay); pTemp.SetThink(pTemp.DelayThink); // Save the useType pTemp.Button = (int)useType; pTemp.KillTarget = KillTarget; pTemp.Delay = 0; // prevent "recursion" pTemp.Target = Target; // HACKHACK // This wasn't in the release build of Half-Life. We should have moved m_hActivator into this class // but changing member variable hierarchy would break save/restore without some ugly code. // This code is not as ugly as that code if (pActivator?.IsPlayer() == true) // If a player activates, then save it { pTemp.Owner = pActivator; } else { pTemp.Owner = null; } return; } // // kill the killtargets // if (!string.IsNullOrEmpty(KillTarget)) { Log.Alert(AlertType.AIConsole, $"KillTarget: {KillTarget}\n"); for (BaseEntity entity = null; (entity = EntUtils.FindEntityByTargetName(entity, KillTarget)) != null;) { //Remove after logging, not before Log.Alert(AlertType.AIConsole, $"killing {entity.ClassName}\n"); EntUtils.Remove(entity); } } // // fire targets // if (!string.IsNullOrEmpty(Target)) { EntUtils.FireTargets(Target, pActivator, this, useType, value); } }