Example #1
0
        private void DelayThink()
        {
            // A player activated this on delay
            var activator = Owner;

            // The use type is cached (and stashed) in pev->button
            SUB_UseTargets(activator, (UseType)Button, 0);
            EntUtils.Remove(this);
        }
Example #2
0
        public static BasePlayer PlayerByIndex(int playerIndex)
        {
            BasePlayer player = null;

            if (playerIndex > 0 && playerIndex <= Engine.Globals.MaxClients)
            {
                player = EntUtils.IndexEnt <BasePlayer>(playerIndex);
            }

            return(player);
        }
Example #3
0
        //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);
        }
Example #4
0
        /// <summary>
        /// Find a player with a case-insensitive name search
        /// </summary>
        /// <param name="testName"></param>
        /// <returns></returns>
        public static BasePlayer FindPlayerByName(string testName)
        {
            if (testName == null)
            {
                throw new ArgumentNullException(nameof(testName));
            }

            for (var i = 1; i <= Engine.Globals.MaxClients; ++i)
            {
                var entity = EntUtils.IndexEnt(i);

                if (entity != null && entity?.IsPlayer() == true && entity.NetName.Equals(testName, StringComparison.OrdinalIgnoreCase))
                {
                    return((BasePlayer)entity);
                }
            }

            return(null);
        }
Example #5
0
        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);
        }
Example #6
0
        // 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);
            }
        }