public static IMyPlayer GetPlayer(this IMyPlayerCollection Players, long ID)
        {
            List <IMyPlayer> player = new List <IMyPlayer>(1);

            Players.GetPlayers(player, x => x.IdentityId == ID);
            return(player.FirstOrDefault());
        }
        public static IMyPlayer GetPlayerByID(this IMyPlayerCollection Players, long PlayerID)
        {
            List <IMyPlayer> players = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(players, x => x.IdentityId == PlayerID);
            return(players.FirstOrDefault());
        }
Exemple #3
0
        public static List <ulong> GetClientIDs(this IMyPlayerCollection Collection)
        {
            List <IMyPlayer> players = new List <IMyPlayer>();

            Collection.GetPlayers(players);
            return(players.Select(x => x.SteamUserId).ToList());
        }
Exemple #4
0
        public static IMyPlayer GetPlayerById(this IMyPlayerCollection players, long playerId)
        {
            List <IMyPlayer> myPlayers = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(myPlayers, x => x.IdentityId == playerId);
            return(myPlayers.FirstOrDefault());
        }
        public static IMyPlayer FindPlayerBySteamId(this IMyPlayerCollection collection, ulong steamId)
        {
            var listplayers = new List <IMyPlayer>();

            MyAPIGateway.Players.GetPlayers(listplayers, p => p.SteamUserId == steamId);
            return(listplayers.FirstOrDefault());
        }
Exemple #6
0
        public ulong GetSteamId(long playerEntityId)
        {
            if (BackingObject == null)
            {
                return(0);
            }

            if (!(BackingObject is IMyPlayerCollection))
            {
                return(0);
            }

            IMyPlayerCollection collection = (IMyPlayerCollection)BackingObject;

            List <IMyPlayer> players = new List <IMyPlayer>();

            //collection.GetPlayers(players, x => x.Controller.ControlledEntity.Entity.EntityId == playerEntityId);
            collection.GetPlayers(players, x => x.Controller != null && x.Controller.ControlledEntity != null && x.Controller.ControlledEntity.Entity != null && x.Controller.ControlledEntity.Entity.EntityId == playerEntityId);
            if (players != null && players.Count > 0)
            {
                return(players.First().SteamUserId);
            }

            return(0);
        }
        public static IMyPlayer GetPlayer(this IMyPlayerCollection Players, Func <IMyPlayer, bool> filter)
        {
            List <IMyPlayer> list = new List <IMyPlayer>();

            Players.GetPlayers(list, filter);
            return(list.FirstOrDefault());
        }
Exemple #8
0
        public static IMyPlayer GetPlayer(this IMyPlayerCollection collection, ulong steamId)
        {
            var players = new List <IMyPlayer>();

            collection.GetPlayers(players, p => p.SteamUserId == steamId);
            return(players.FirstOrDefault());
        }
Exemple #9
0
        public long GetPlayerEntityId(ulong steamId)
        {
            long result = 0;

            try
            {
                IMyPlayerCollection collection = (IMyPlayerCollection)BackingObject;

                List <IMyPlayer> players = new List <IMyPlayer>();
                collection.GetPlayers(players, x => x.SteamUserId == steamId);

                if (players.Count > 0)
                {
                    IMyPlayer player = players.FirstOrDefault();
                    if (player != null)
                    {
                        if (player.Controller != null && player.Controller.ControlledEntity != null && player.Controller.ControlledEntity.Entity != null)
                        {
                            result = player.Controller.ControlledEntity.Entity.EntityId;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
            return(result);
        }
        public static bool TryGetIdentity(this IMyPlayerCollection collection, long identityId, out IMyIdentity identity)
        {
            var listIdentites = new List <IMyIdentity>();

            MyAPIGateway.Players.GetAllIdentites(listIdentites, p => p.IdentityId == identityId);
            identity = listIdentites.FirstOrDefault();
            return(identity != null);
        }
Exemple #11
0
        public static bool TryGetPlayer(this IMyPlayerCollection collection, long playerId, out IMyPlayer player)
        {
            var players = new List <IMyPlayer>();

            collection.GetPlayers(players, p => p.IdentityId == playerId);
            player = players.FirstOrDefault();
            return(player != null);
        }
 /**
  * Add a by-id lookup to the Player list.
  */
 public static IMyPlayer GetPlayerByID(this IMyPlayerCollection playersIn, long playerID) {
   List<IMyPlayer> players = new List<IMyPlayer>();
   playersIn.GetPlayers(players, x => x.IdentityId == playerID);
   if (players.Count > 0) {
     return players[0];
   }
   return null;
 }
 public static bool IsValidPlayer(this IMyPlayerCollection players, long playerId, out IMyPlayer player, bool checkNonBot = true)
 {
     player = MyAPIGateway.Players.GetPlayerById(playerId);
     if (player == null)
     {
         return(false);
     }
     return(!checkNonBot || !player.IsBot);
 }
 public static bool IsValidPlayer(this IMyPlayerCollection Players, long PlayerID, out IMyPlayer Player, bool CheckNonBot = true)
 {
     Player = MyAPIGateway.Players.GetPlayerByID(PlayerID);
     if (Player == null)
     {
         return(false);
     }
     return(CheckNonBot ? !Player.IsBot : true);
 }
Exemple #15
0
 public static void Clean()
 {
     Session               = null;
     Entities              = null;
     Players               = null;
     CubeBuilder           = null;
     TerminalActionsHelper = null;
     Utilities             = null;
     Parallel              = null;
     Multiplayer           = null;
     PrefabManager         = null;
 }
 /**
  * Return the player closest to the target location.
  */
 public static IMyPlayer GetClosestPlayer(this IMyPlayerCollection playersIn, Vector3D target) {
   List<IMyPlayer> players = new List<IMyPlayer>();
   playersIn.GetPlayers(players);
   IMyPlayer closest = null;
   double dist = double.MaxValue;
   foreach(IMyPlayer player in players) {
     double curdist = player.GetPosition().DistanceTo(target);
     if (curdist < dist) {
       dist = curdist;
       closest = player;
     }
   }
   return closest;
 }
Exemple #17
0
        public static bool TryGetPlayer(this IMyPlayerCollection collection, ulong steamId, out IMyPlayer player)
        {
            var players = new List <IMyPlayer>();

            collection.GetPlayers(players, p => p != null);

            player = players.FirstOrDefault(p => p.SteamUserId == steamId);
            if (player == null)
            {
                return(false);
            }

            return(true);
        }
Exemple #18
0
        public static IMyPlayer GetPlayerBySteamId(this IMyPlayerCollection collection, ulong steamId)
        {
            var list = PlayerListPool.Get();

            try
            {
                list.Clear();
                collection.GetPlayers(list, (x) => x.SteamUserId == steamId);
                return(list.Count > 0 ? list[0] : null);
            }
            finally
            {
                list.Clear();
                PlayerListPool.Return(list);
            }
        }
Exemple #19
0
        public static IMyPlayer GetPlayerById(this IMyPlayerCollection collection, long id)
        {
            var list = PlayerListPool.Get();

            try
            {
                list.Clear();
                collection.GetPlayers(list, (x) => x.IdentityId == id);
                return(list.Count > 0 ? list[0] : null);
            }
            finally
            {
                list.Clear();
                PlayerListPool.Return(list);
            }
        }
        public static bool TryGetPlayer(this IMyPlayerCollection collection, string name, out IMyPlayer player)
        {
            player = null;
            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }
            var players = new List <IMyPlayer>();

            collection.GetPlayers(players, p => p != null);

            player = players.FirstOrDefault(p => p.DisplayName.Equals(name, StringComparison.InvariantCultureIgnoreCase));
            if (player == null)
            {
                return(false);
            }

            return(true);
        }
Exemple #21
0
 public static void Clean()
 {
     Session     = null;
     Entities    = null;
     Players     = null;
     CubeBuilder = null;
     if (IngameScripting != null)
     {
         IngameScripting.Clean();
     }
     IngameScripting       = null;
     TerminalActionsHelper = null;
     Utilities             = null;
     Parallel         = null;
     Physics          = null;
     Multiplayer      = null;
     PrefabManager    = null;
     Input            = null;
     TerminalControls = null;
 }
        public static List <IMyPlayer> getPlayersNearPoint(this IMyPlayerCollection self, Vector3D point, float radius)
        {
            log("Getting players within " + radius + " of " + point, "getPlayersNearPoint");

            var allPlayers = new List <IMyPlayer>();

            self.GetPlayers(allPlayers);

            float distanceFromPoint = 0.0f;
            var   nearbyPlayers     = new List <IMyPlayer>();

            foreach (IMyPlayer player in allPlayers)
            {
                distanceFromPoint = VRageMath.Vector3.Distance(player.GetPosition(), point);
                if (distanceFromPoint < radius)
                {
                    nearbyPlayers.Add(player);
                }
            }

            log(nearbyPlayers.Count + " Nearby players.", "getPlayersNearPoint");
            return(nearbyPlayers);
        }
Exemple #23
0
        public static bool CheckPlayerIsInWorld(ulong steamID)
        {
            IMyPlayerCollection allPlayers  = MyAPIGateway.Players;
            List <IMyPlayer>    listPlayers = new List <IMyPlayer>();

            allPlayers.GetPlayers(listPlayers);
            foreach (IMyPlayer currentPlayer in listPlayers)
            {
                if (currentPlayer.SteamUserId == steamID)
                {
                    String ControlledEntity = currentPlayer.Controller.ControlledEntity.ToString();
                    if (ControlledEntity.Contains("Astronau"))
                    {
                        return(true);
                    }
                    else
                    {
                        ChatUtil.SendPrivateChat(steamID, "Please exit cockpit and try again.");
                        return(false);
                    }
                }
            }
            return(false);
        }
        public static bool IsValidPlayer(this IMyPlayerCollection Players, long PlayerID, bool CheckNonBot = true)
        {
            IMyPlayer Player;

            return(IsValidPlayer(Players, PlayerID, out Player));
        }
 public static void Clean()
 {
     Session = null;
     Entities = null;
     Players = null;
     CubeBuilder = null;
     TerminalActionsHelper = null;
     Utilities = null;
     Parallel = null;
     Multiplayer = null;
     PrefabManager = null;
     Input = null;
 }
Exemple #26
0
        public void UpdateManually()
        {
            //     Log.Info("updating manually: turret");
            try
            {
                bool localPlayerEntered = false;


                IMyPlayerCollection allPlayers    = MyAPIGateway.Players;
                IMyPlayer           currentPlayer = null;
                List <IMyPlayer>    playerList    = new List <IMyPlayer>();
                allPlayers.GetPlayers(playerList);
                // Log.Info("update manually:");
                //   Log.Info("" + allPlayers + currentPlayer + playerList);
                foreach (IMyPlayer player in playerList)
                {
                    // Log.Info("iterating over player : " + player);
                    //    Log.Info("iterating over player " + player);

                    if ((player != null) && (player.Controller != null) && (player.Controller.ControlledEntity != null) && (player.Controller.ControlledEntity.Entity != null))
                    {
                        //   Log.Info("first if");
                        //      Log.Info("a controlled entity was not zero");

                        if (player.Controller.ControlledEntity.Entity.EntityId == Entity.EntityId)
                        {
                            // Log.Info("second if");
                            currentPlayer = player;
                            // Log.Info("currentplayer found");
                            //      Log.Info("set current player");
                            if (MyAPIGateway.Session.Player == player)
                            {
                                //  Log.Info("third if");
                                //currentPlayer = player;
                                if (localPlayerEntered == false)
                                {
                                    localPlayerEntered = true;
                                }
                            }
                        }
                    }
                }
                //  string pId = "";
                bool   success    = false;
                string targetName = "NoTargetFound";
                if (currentPlayer != null)
                {
                    // Log.Info("fouth if");
                    //    Log.Info("currentplayer wasnt null");
                    //   if (currentPlayer.Controller.ControlledEntity.Entity != null) pId = currentPlayer.Controller.ControlledEntity.Entity.ToString();

                    BoundingSphereD sphere = new BoundingSphereD(Entity.GetPosition() + Vector3.Normalize(Entity.WorldMatrix.Up) * 2, 25);

                    // MyAPIGateway.Entities.EnableEntityBoundingBoxDraw(Entity, true, new Vector4(255, 100, 100, 100), 0.01f, null);
                    List <IMyEntity> entitiesFound = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);


                    foreach (IMyEntity ent in entitiesFound)
                    {
                        //   Log.Info("found an entity around me " + ent.GetType().ToString());
                        // if (ent is Sandbox.Game.Weapons.MyMissile)
                        if (ent.GetType().ToString() == GuidedMissileSingleton.SandboxGameWeaponsMyMissile) //CHECK FOR OWNER OR SOMETHING ;_;
                        {
                            bool isActualMissile = false;
                            if ((Entity.Physics != null) && ((ent.Physics.LinearVelocity - Entity.Physics.LinearVelocity).Length() > 450f))
                            {
                                Log.Info("physics wasnt null and speed was sufficient");
                                isActualMissile = true;
                            }
                            else if ((Entity.Physics == null))
                            {
                                Log.Info("physics was null!");
                                Log.Info("ent speed was: " + ent.Physics.LinearVelocity.Length());
                                if (ent.Physics.LinearVelocity.Length() > 450f)
                                {
                                    isActualMissile = true;
                                }
                            }
                            if (isActualMissile)
                            {
                                Log.Info("found a missile");
                                Ray directionRay = new Ray(ent.GetPosition(), Vector3.Normalize(ent.Physics.LinearVelocity));

                                IMyEntity bestTarget = GuidedMissileCore.GetClosestTargetAlongRay(directionRay, 5000, 7.5, Entity.GetTopMostParent());
                                //   Log.Info("assign target, trying to call with : " + bestTarget);

                                if (bestTarget != null)
                                {
                                    success    = AssignTarget(bestTarget);
                                    targetName = bestTarget.DisplayName;
                                }
                            }
                            ent.Close();
                        }
                    }
                }

                /**      if (localPlayerEntered != this.playerEntered)
                 *    {
                 *        SetPlayerStatus(localPlayerEntered);
                 *    } **/
                if (localPlayerEntered)
                {
                    if (success)
                    {
                        MyAPIGateway.Utilities.ShowNotification(targetName + " was set as missile target!", 1000, MyFontEnum.Red);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                MyAPIGateway.Utilities.ShowNotification("" + e, 1000, MyFontEnum.Red);
            }
        }
        protected override IMyEntity GetTarget(IMyEntity missile)
        {
            //IMyEntity targetGrid = GuidedMissileTargetGridHook.GetMissileTargetForGrid(Entity.GetTopMostParent());


            Ray       ray        = new Ray(missile.GetPosition(), Vector3.Normalize(missile.WorldMatrix.Forward));
            IMyEntity targetGrid = GuidedMissileCore.GetClosestTargetAlongRay(ray, 3000, 7, Entity.GetTopMostParent());
            IMyEntity target     = GuidedMissileTargetGridHook.GetRandomBlockInGrid(targetGrid);

            if (target == null)
            {
                //  Log.Info("target was null...");
                //   if (targetGrid == null) Log.Info("targetgrid was null as well!");
                target = targetGrid;
                Log.Info("target was null, now set to grid");
                //  IMyEntity grid = target;
            }

            //  Log.Info("got a target: " + target.ToString());

            if (target != null)
            {
                IMyPlayerCollection allPlayers = MyAPIGateway.Players;

                List <IMyPlayer> playerList = new List <IMyPlayer>();

                HashSet <IMyEntity> componentSet = new HashSet <IMyEntity>();

                Entity.GetTopMostParent().Hierarchy.GetChildrenRecursive(componentSet);
                List <IMyEntity> componentList = new List <IMyEntity>();
                componentList.AddRange(componentSet);

                allPlayers.GetPlayers(playerList);
                componentSet.Clear();


                foreach (IMyEntity component in componentList)
                {
                    if (component is IMyCockpit)
                    {
                        componentSet.Add(component);
                    }
                }

                foreach (IMyPlayer player in playerList)
                {
                    if (MyAPIGateway.Session.Player == player)
                    {
                        if ((player != null) && (player.Controller != null) && (player.Controller.ControlledEntity != null) && (player.Controller.ControlledEntity.Entity != null))
                        {
                            foreach (IMyEntity entity in componentSet)
                            {
                                if (player.Controller.ControlledEntity.Entity.EntityId == entity.EntityId)
                                {
                                    MyAPIGateway.Utilities.ShowNotification("" + target.GetTopMostParent().DisplayName + " was set as missile target!", 2000, MyFontEnum.Red);
                                }
                            }
                        }
                    }
                }
            }
            return(target);
        }
        private void DisplayWarningMessage(IMyEntity target)
        {
            IMyEntity grid             = target.GetTopMostParent();
            bool      alreadyContained = false;

            foreach (WarningMessageContainer container in _warningGridSet)
            {
                if (container.Grid == grid)
                {
                    alreadyContained = true;
                }
            }
            if (!alreadyContained)
            {
                IMyPlayerCollection allPlayers = MyAPIGateway.Players;

                List <IMyPlayer> playerList = new List <IMyPlayer>();

                if (grid.Hierarchy == null)
                {
                    return;
                }
                if (grid.Hierarchy.Children == null)
                {
                    return;
                }
                HashSet <IMyEntity> componentSet = new HashSet <IMyEntity>();

                grid.Hierarchy.GetChildrenRecursive(componentSet);
                List <IMyEntity> componentList = new List <IMyEntity>();
                componentList.AddRange(componentSet);

                allPlayers.GetPlayers(playerList);
                componentSet.Clear();


                foreach (IMyEntity component in componentList)
                {
                    if (component is IMyCockpit)
                    {
                        componentSet.Add(component);
                    }
                }

                foreach (IMyPlayer player in playerList)
                {
                    if (MyAPIGateway.Session.Player == player)
                    {
                        if ((player != null) && (player.Controller != null) && (player.Controller.ControlledEntity != null) && (player.Controller.ControlledEntity.Entity != null))
                        {
                            foreach (IMyEntity entity in componentSet)
                            {
                                if (player.Controller.ControlledEntity.Entity.EntityId == entity.EntityId)
                                {
                                    MyAPIGateway.Utilities.ShowNotification("WARNING! MISSILE LOCKON DETECTED!", 5000, MyFontEnum.Red);

                                    _warningGridSet.Add(new WarningMessageContainer(grid));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
            }
        }
 public static void Clean()
 {
     Session = null;
     Entities = null;
     Players = null;
     CubeBuilder = null;
     if (IngameScripting != null)
     {
         IngameScripting.Clean();
     }
     IngameScripting = null;
     TerminalActionsHelper = null;
     Utilities = null;
     Parallel = null;
     Physics = null;
     Multiplayer = null;
     PrefabManager = null;
     Input = null;
     TerminalControls = null;
 }