Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Modding API - changes in modding interface

Discussion in 'Modding API' started by joeblack616, Oct 22, 2014.

Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.
  1. Ravenal Apprentice Engineer

    Messages:
    362
    Thanks, so far so good!
     
  2. tyrsis Junior Engineer

    Messages:
    862
    Uhm, MyAPIGateway.Session.Factions doesn't have an enumerator? Or did you want us to go through the checkpoint object builder?
     
    Last edited by a moderator: Dec 8, 2014
  3. Ravenal Apprentice Engineer

    Messages:
    362
    I agree with Tyrsis, I think it would be logical to allow us to know the total count of factions that changes when the collection entry is added, I guess logically it would make sense to create a wrapper where the faction data would store locally on our end, and what not. Although that means more code compilation and more memory storage within the RAM.

    Guess its up to Keen
     
  4. Gwindalmir Senior Engineer

    Messages:
    1,006
    I have a request for KeenSWH regarding the ModAPI.

    Please be careful when making ModAPI changes.

    Before I sound entitled, please hear me out.

    Here's what I mean:
    The last update changed the prototype for MyAPIGateway.Entities.GetEntitiesInAABB.

    The previous one was:
    List<IMyEntity> GetEntitiesInAABB(ref BoundingBox boundingBox);

    It was changed (thankfully) to:
    <div> List&lt;IMyEntity> GetEntitiesInAABB(ref BoundingBo:woot: boundingBox);

    However, why remove the old one? Why can't there be two methods?
    I brought this particular method to attention a month or so ago, right after the first Double Update. I was told then there would be another update 'in the future' and that we'd be told in advance.
    I may have missed that notice (forgive me if I did, there's many places one could check), however there was no reason to abruptly remove the old method, thereby breaking mods without notice.

    .NET has a mechanism for marking methods and objects obsolete: http://msdn.microsoft.com/en-us/library/system.obsoleteattribute%28v=vs.110%29.aspx
    If you could consider using that, at least for a patch or two, before removing said method it would be greatly appreciated. :D

    At least those who are using VS would get notified right away (I use VS to test compile the code before loading the game) of deprecated methods and can switch in advance of removal. This would allow modders to get ahead of the ball, so to speak, and push out updates as you do, while not having any breakage during the transition period.

    PS.
    One reason why this is such an issue is that some modders (like myself) sometimes work with others on a mod. One of the mods I work on, for example, was not mine initially. Since I don't own the workshop mod, I cannot update it myself. However I'm the programmer for the mod, so if the ModAPI changes, I can't push out an update until my partner signs online to push it out, which could be a day or more sometimes.
    </div>
     
    Last edited by a moderator: Dec 13, 2014
  5. Ravenal Apprentice Engineer

    Messages:
    362
    Phoenix they are changing a lot of stuff from Vector3 based to Vector3D. BoundingBox is using floating points where BoundingBo:woot: is using double points. They already said that things we're changing to be double persicions
     
  6. Gwindalmir Senior Engineer

    Messages:
    1,006
    I know, I already said that.
    What wasn't known was WHEN specifically they were making those changes.

    My request is simple:
    Either let us know a day or two in advance of the patch WHICH methods/interfaces are changing, or mark the old ones as deprecated.
    This gives modders some time to fix their scripts and push out an update at the same time as Keen, not hours or days later. This minimizes downtime with servers.

    I can't anticipate what will change with the next update.
     
    Last edited by a moderator: Dec 14, 2014
  7. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    you are correct. But let me explain this. I'm trying to keep track of mod API changes (that's why I created this topic), but I'm not alone here and sometimes people won't say that change was made. Also sometimes I don't even know when change will be released to public. And last couple of days/weeks I was really busy.
    As I said in different threads mod API are basically our exposed interfaces. We are also using them, so when there was change in GetEntitiesInAABB, our code didn't use it anymore and it was removed. That is also reason why there was change to doubles in first place in interfaces (because we are using them).

    So I will try to keep up with changes and I will try to notify you in advance.
     
  8. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi sorry, didn't think about that. I will try to fix it in near future.
     
  9. Gwindalmir Senior Engineer

    Messages:
    1,006
    Thank you for your reply, and your explanation.

    I understand things get busy. I was unaware that you are also using those same interfaces. Typically, once an interface is public, it's 'set in stone' as it were.

    I hope as the game matures more that the ModAPI, if changed, is handled carefully. Please don't take that as criticism, it's not intended as such. :)
    My goal is to provide constructive feedback to you guys. If I haven't been, please let me know.

    Anyway, if this is the thread to monitor for such changes, I shall do so.
     
    Last edited by a moderator: Dec 18, 2014
  10. midspace Senior Engineer

    Messages:
    2,224
    When a player is remote controlling a ship, how do we get the Player entity details, ie location, or cockpit they are sitting in, or even their location?

    MyAPIGateway.Session.Player.Controller.ControlledEntity only returns the remote controlled ship.
    MyAPIGateway.Session.Player.GetPosition() will only return the position of the remote controlled ship.
     
    Last edited by a moderator: Jan 1, 2015
  11. midspace Senior Engineer

    Messages:
    2,224
    Is there some way of getting a list of all in range Grids that are contactable by Radio Antenna by the player?

    Ie., Every ship/grid group that is listed as 'Remote access' in the Terminal Window.
    [​IMG]
     
  12. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi guys, lot of stuff today. As you know there is new programmable block in game. First there is "guide",
    please read it : http://steamcommunity.com/sharedfiles/filedetails/?id=360966557 (You can skip limitation and GUI overview). There is also list of all block and action names for them (very handy). Every block should have interface now and inheritance was fixed. (So now it more mirror our block structure).

    And best thing is : you have also access to everything that programmable block can offer. You can get IMyGridTerminalSystem interface By calling Sandbox.ModAPI.Ingame.IMyGridTerminalSystem GetTerminalSystemForGrid(Sandbox.ModAPI.IMyCubeGrid grid) at MyAPIGateway.TerminalActionsHelper.

    It will represent terminal for current grid logical group (e.g. when you have two grids connected with merge block or any other connecting block, you will have access to block for both grids). Basically you have access to every block that you can see in terminal for given group.
     
    Last edited by a moderator: Jan 2, 2015
  13. midspace Senior Engineer

    Messages:
    2,224
    Using the IMyGridTerminalSystem in the ModAPI, the BlockGroups do not appear to accurately represent the Terminal system. It is not grouping multiple grids, like rotors or pistons. At most, I am seeing only 2 in the collection, when there should be much more.
     
  14. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi guys,
    lot of things, as you we introduced ingame programming,
    sadly we realized that first version was too powerful for players to have, so we needed to put some things down. But don't worry we didn't restrict any of modAPI functionality. We just moved some stuff from ModAPI.Ingame to ModAPI namespaces.This can lead to some ambiguities in your scripts. So please check them. Also for you its always better to use ModAPI interface than ModAPI.Ingame. To be more clear please take IMySensorBlock : There is ModAPI.Ingame.IMySensorBlock that have only read-only properties and ModAPI.IMySensorBlock that has event Action&lt;bool> StateChanged;

    If you need this action you need to cast to ModAPI.IMySensorBlock, ModAPI.IMySensorBlock derives from ModAPI.Ingame.IMySensorBlock, so it has all properties of ModAPI.Ingame.IMySensorBlock.


    Also TransferItemTo and From now respects conveyors.If you want to teleport things you need to use

    bool TransferItemTo(Sandbox.ModAPI.Interfaces.IMyInventory dst, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection = true);
    bool TransferItemFrom(Sandbox.ModAPI.Interfaces.IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection = true);

    From ModAPI.IMyInventory.

     
  15. Gwindalmir Senior Engineer

    Messages:
    1,006
    Is the difference between ModAPI.Ingame and ModAPI described anywhere else? I didn't know I was just supposed to use ModAPI.

    Another question though: With the most recent update, can we determine the speed limit in the ModAPI?
     
  16. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    not yet but we are thinking about it. Basic difference between ModAPI.Ingame and ModAPI is that ModAPI versions have more stuff. ModAPI.Ingame versions are meant to be read-only, you cannot set any values directly nor subscribe to events. You should be able to only what can you do inside of game. With ModAPI, you can do whatever you want ;)
     
  17. blilli Trainee Engineer

    Messages:
    19
    It works. And it is very useful. Thank you.
     
  18. hellokeith Apprentice Engineer

    Messages:
    335
    Is this available to any player in vanilla version? [bad/exploit]

    Or only available through a mod? [good]
     
  19. Digi Senior Engineer

    Messages:
    2,393
    Only through modding... or it should be.

    Try it in-game, cast GetInventory() to Sandbox.ModAPI.IMyInventory, it most likely will tell you that interface is not allowed in the in-game programming.
     
    Last edited by a moderator: Jan 17, 2015
  20. joeblack616 Apprentice Engineer

    Messages:
    225
    Added interfaces for Floating objects and meteors IMyFloatingObject and IMyMeteor.
     
  21. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    AddPlayerToFaction of IMyFactionCollection is internal method of Faction, please use SendJoinRequest instead, AddPlayer will be mark as obsolete and removed in future. Same thing for KickPlayerFromFaction
     
  22. BlueG Apprentice Engineer

    Messages:
    119
    I went looking for the IMyFloatingObject interface today and was unable to find it. Has it been removed? Is there another way to determine if an entity is a floating object? The only way I know of right now is to look at the object builder, but that would not be a good idea in this scenario (my radar mod) since I'm searching through all entities.
     
  23. midspace Senior Engineer

    Messages:
    2,224
    IMyFloatingObject is in the Sandbox.ModAPI namespace.

    This is how I've been using it in code.
    Code:
    var sphere = new BoundingSphereD(centerPoint, range);
    var floatingList = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
    floatingList = floatingList.Where(e => (e is Sandbox.ModAPI.IMyFloatingObject)).ToList();
    foreach (var item in floatingList)
    {
        // Check for null physics and IsPhantom, to prevent picking up primitives.
        if (item.Physics != null &amp;&amp; !item.Physics.IsPhantom)
        {
    
     
  24. BlueG Apprentice Engineer

    Messages:
    119
    Yeah, that's where I was expecting to find it, and with that exact name, but inside VS it wasn't showing up in Intellisense or the Object Browser. I just tried using it in Space Engineers using that name, though, and it worked. So, I was able to track down the problem. I was referencing the 64-bit assemblies for SE and, apparently, those didn't expose that interface. I wonder what else I've been missing... *sighs* time for some coffee and then I'll sit down with the good old Object Browser for a while. First up on my list of things to check: the text panel.

    Thank you, midspace, for your help. I appreciate how clear it was. Knowing that you had similar code working led me straight to the problem. Now I can get the next version of my mod released.
     
    Last edited by a moderator: Jan 29, 2015
  25. midspace Senior Engineer

    Messages:
    2,224
    I only use the 64-bit binaries, and they show up for me.
    I can only suggest rechecking the binary references in your project, just incase you've referenced an old copy of SE.
    I would also mark the Sanbox and Vrage references "copy local" as False.
    Unless you've used Keen's special batch file to create the project.
     
  26. DuneD Junior Engineer

    Messages:
    948
    Hey, something has changed with the new update, my script isnt working anymore, this function here was working fine before the update:

    Code:
     public static List&lt;Sandbox.ModAPI.IMySlimBlock> GetPlanets()
            {
                HashSet&lt;IMyEntity> hash = new HashSet&lt;IMyEntity>();
                List &lt;Sandbox.ModAPI.IMySlimBlock> planetList = new List&lt;Sandbox.ModAPI.IMySlimBlock>();
                Sandbox.ModAPI.MyAPIGateway.Entities.GetEntities(hash, (p) => p is Sandbox.ModAPI.IMyCubeGrid);
              
                foreach (var planet in hash)
                {
                    List&lt;Sandbox.ModAPI.IMySlimBlock> blocks = new List&lt;Sandbox.ModAPI.IMySlimBlock>();
                    Sandbox.ModAPI.IMyCubeGrid grid = planet as Sandbox.ModAPI.IMyCubeGrid;
                    grid.GetBlocks(blocks, (p) => p.FatBlock is IMyGravityGeneratorSphere &amp;&amp;
                        (p.FatBlock.BlockDefinition.SubtypeId.Contains("Dune") || 
                        p.FatBlock.BlockDefinition.SubtypeId.Contains("Antares")
                        || p.FatBlock.BlockDefinition.SubtypeId.Contains("Aphrodite")));
                    
                        foreach (var block in blocks)
                        {
                            planetList.Add(block);
                        }
                       
                }
                return planetList;
            }
    
    Now its throwing the "Object reference not set to an instance of an object." error.

    Edit: I added a check to see if the entities were phantom or physics was null, it doesnt throw the exception at the function anymore, it throws it at the start of UpdateBeforeSimulation10(), here is the error:
    Code:
    015-01-29 16:55:23.085 - Thread:   1 ->  Exception occured: System.NullReferenceException: Object reference not set to an instance of an object.
       at DuneCubes.DuneCubes.UpdateBeforeSimulation10()
       at 6DDCED906C852CFDABA0B56B84D0BD74.CCFD704C70C3F20F7E84E8EA42D7A730.UpdateBeforeSimulation10()
       at 5BCAC68007431E61367F5B2CF24E2D6F.CAF1EB435F77C7B77580E2E16F988BED.E6A3963C266FEBCE0C49A1FEADE1933C()
       at AAC05F537A6F0F6775339593FBDFC564.CBB94D06E8011132FF514442B0A88989.UpdateBeforeSimulation()
       at AAC05F537A6F0F6775339593FBDFC564.D580AE7552E79DAB03A3D64B1F7B67F9.F672BBF9E192151CE8FD7E91E62B997D()
       at AAC05F537A6F0F6775339593FBDFC564.D580AE7552E79DAB03A3D64B1F7B67F9.EC90B1C44E3C361983D093F355FF0CC8(MyTimeSpan 9916A9BA14FB0BB1A36908E2E8C15A74)
       at B337879D0C82A5F9C44D51D954769590.B3531963E948FB4FA1D057C4340C61B4.8C5D81757881E56F89E5680B2AAD14FF()
       at 168638249D29224100DB50BB468E7C07.7BAD4AFD06B91BCD63EA57F7C0D4F408.2457E95BE2F0D1F1A4A009B2B1DBBDA4()
       at 168638249D29224100DB50BB468E7C07.398AD1E315E6E4D570C424BD0D168FC1.858DA51EB20785A82D9A03614304088A.0187A29A24275EC024A192E7E235CC2E.9C41E76459B99591F991CBA0833BD17E()
       at 168638249D29224100DB50BB468E7C07.6E0E814918D8AD6B2DC9CA5005102256.9B0C287E2241DCCFF80A45639E4FB214(9AA159E6C22F64A542015EED199D04B9 148A5BA193EB90E55F5E805EF96CAD48)
       at 168638249D29224100DB50BB468E7C07.398AD1E315E6E4D570C424BD0D168FC1.9B0C287E2241DCCFF80A45639E4FB214(9AA159E6C22F64A542015EED199D04B9 148A5BA193EB90E55F5E805EF96CAD48)
       at B337879D0C82A5F9C44D51D954769590.B3531963E948FB4FA1D057C4340C61B4.246E732EE67F7F6F88C4FF63B3901107(Boolean FF8E4184144DE7049FF5EC07D594DAB6, Action 8CF1B812E214DD1C51DD894D4C05D44A)
       at 83BCBFA49B3A2A6EC1BC99583DA2D399.49BCFF86BA276A9C7C0D269C2924DE2D.523C8831DA5DAB3A19F6D33A2C6437B5(String[] 954514EA42AFFE4302240CE14E5D6683)
       at 83BCBFA49B3A2A6EC1BC99583DA2D399.49BCFF86BA276A9C7C0D269C2924DE2D.0D8AAA624C2EEA412F85ABB3AEFAF743(String[] 954514EA42AFFE4302240CE14E5D6683)
    
    Edit3: I accidentally discovered that now 2 static blocks can occupy the same space if forced through script :/

    Edit4: Ok, I dont have any idea how, but the script partially works, I can find the entities, but for some reason, this function, returns 0 asteroids found:
    Code:
    public static List&lt;Sandbox.ModAPI.IMyVoxelMap> GetAteroids()
            {
                List&lt;Sandbox.ModAPI.IMyVoxelMap> asteroidList = new List&lt;Sandbox.ModAPI.IMyVoxelMap>();
                var asteroids = new List&lt;IMyVoxelMap>();
                MyAPIGateway.Session.VoxelMaps.GetInstances(asteroids, v => v != null);
                foreach(var asteroid in asteroids) {
                    asteroidList.Add(asteroid);
                }
                return asteroidList;
            }
    
    Edit5: I just dont know whats going on anymore, sometimes it loads the script but doesnt work properly, sometimes it crashes to desk... too random, im just going to lay down, take a deep breath and let my frustration fade.. Tomorrow will be another day.
     
    Last edited by a moderator: Jan 29, 2015
  27. joeblack616 Apprentice Engineer

    Messages:
    225
    Could you please post link to your workshop script ? Or upload script to some place ? I will check it.Thanks.
     
  28. DuneD Junior Engineer

    Messages:
    948
    Its not uploaded to the workshop yet, but here it is. Basically its meant to find 3 custom asteroids and place 3 custom gravity generators in the center. Also applies gravity to all the objects inside the field's generator, here is the script:

    Code:
    namespace DuneCubes
    {
        [MyEntityComponentDescriptor(typeof(MyObjectBuilder_GravityGeneratorSphere))]
        class DuneCubes : MyGameLogicComponent
        {
            MyObjectBuilder_EntityBase _objectBuilder;
            Sandbox.ModAPI.IMySlimBlock dune;
            Sandbox.ModAPI.IMySlimBlock aphrodite;
            Sandbox.ModAPI.IMySlimBlock antares;
            VRageMath.Vector3D centerPosD;
            VRageMath.Vector3D centerPosA;
            VRageMath.Vector3D centerPosAp;
            IMyVoxelMap duneV;
            IMyVoxelMap antaresV;
            IMyVoxelMap aphroditeV;
            BoundingSphereD sphereD;
            BoundingSphereD sphereA;
            BoundingSphereD sphereAp;
            bool isInit;
            public override void Init(MyObjectBuilder_EntityBase objectBuilder)
            {
                _objectBuilder = objectBuilder;
                Entity.NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
                
            }
            public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
            {
                return _objectBuilder;
            }
            public static List&lt;Sandbox.ModAPI.IMySlimBlock> GetPlanets()
            {
                HashSet&lt;IMyEntity> hash = new HashSet&lt;IMyEntity>();
                List &lt;Sandbox.ModAPI.IMySlimBlock> planetList = new List&lt;Sandbox.ModAPI.IMySlimBlock>();
                Sandbox.ModAPI.MyAPIGateway.Entities.GetEntities(hash, (p) => p is Sandbox.ModAPI.IMyCubeGrid);
              
                foreach (var planet in hash)
                {
                    List&lt;Sandbox.ModAPI.IMySlimBlock> blocks = new List&lt;Sandbox.ModAPI.IMySlimBlock>();
                    Sandbox.ModAPI.IMyCubeGrid grid = planet as Sandbox.ModAPI.IMyCubeGrid;
                    grid.GetBlocks(blocks, (p) => p.FatBlock is IMyGravityGeneratorSphere &amp;&amp;
                        (p.FatBlock.BlockDefinition.SubtypeId.Contains("Dune") || 
                        p.FatBlock.BlockDefinition.SubtypeId.Contains("Antares")
                        || p.FatBlock.BlockDefinition.SubtypeId.Contains("Aphrodite")));
                   
                        foreach (var block in blocks)
                        {
                            planetList.Add(block);
                        }
                    
                }
                return planetList;
            }
            public static List&lt;Sandbox.ModAPI.IMyVoxelMap> GetAteroids()
            {
                List&lt;Sandbox.ModAPI.IMyVoxelMap> asteroidList = new List&lt;Sandbox.ModAPI.IMyVoxelMap>();
                var asteroids = new List&lt;IMyVoxelMap>();
                MyAPIGateway.Session.VoxelMaps.GetInstances(asteroids, v => v.StorageName == "Dune");
                foreach(var asteroid in asteroids) {
                    asteroidList.Add(asteroid);
                }
                return asteroidList;
            }
            public override void UpdateBeforeSimulation10()
            {
                
                if (!isInit)
                {
                    List &lt;Sandbox.ModAPI.IMySlimBlock> planetList = GetPlanets();
                    foreach(var planet in planetList) {
                        if (planet.FatBlock.BlockDefinition.SubtypeId.Contains("Dune")) {
                            dune = planet;
                            
                        }
                        if (planet.FatBlock.BlockDefinition.SubtypeId.Contains("Antares")) {
                            antares = planet;
                        }
                        if (planet.FatBlock.BlockDefinition.SubtypeId.Contains("Aphrodite")) {
                            aphrodite = planet;
                        }
                    }
                   
                    List&lt;IMyVoxelMap> asteroidList = GetAteroids();
                    foreach (var asteroid in asteroidList)
                    {
                        if (asteroid.StorageName.Contains("Dune"))
                        {
                            duneV = asteroid;
                            VRageMath.Vector3D size;
                            size.X = 1140.33;
                            size.Y = 1167.05;
                            size.Z = 1228.12;
                            var center = new BoundingBoxD(asteroid.PositionLeftBottomCorner, asteroid.PositionLeftBottomCorner + size);
                            centerPosD.X = center.Center.X;
                            centerPosD.Y = center.Center.Y;
                            centerPosD.Z = center.Center.Z;
                            sphereD.Radius = 1200;
                            sphereD.Center.X = centerPosD.X;
                            sphereD.Center.Y = centerPosD.Y;
                            sphereD.Center.Z = centerPosD.Z;
                            MyAPIGateway.Utilities.ShowNotification("we found dune", 100000);
                        }
                        if (asteroid.StorageName.Contains("Antares"))
                        {
                            antaresV = asteroid;
                            VRageMath.Vector3D size;
                            size.X = 1207.12;
                            size.Y = 1156.85;
                            size.Z = 1129.78;
                            var center = new BoundingBoxD(asteroid.PositionLeftBottomCorner, asteroid.PositionLeftBottomCorner + size);
                            centerPosA.X = center.Center.X;
                            centerPosA.Y = center.Center.Y;
                            centerPosA.Z = center.Center.Z;
                            sphereA.Radius = 1200;
                            sphereA.Center.X = centerPosA.X;
                            sphereA.Center.Y = centerPosA.Y;
                            sphereA.Center.Z = centerPosA.Z;
                        }
                        if (asteroid.StorageName.Contains("Aphrodite"))
                        {
                            aphroditeV = asteroid;
                            VRageMath.Vector3D size;
                            size.X = 1204.15;
                            size.Y = 1187.89;
                            size.Z = 1197.98;
                            var center = new BoundingBoxD(asteroid.PositionLeftBottomCorner, asteroid.PositionLeftBottomCorner + size);
                            centerPosAp.X = center.Center.X;
                            centerPosAp.Y = center.Center.Y;
                            centerPosAp.Z = center.Center.Z;
                            sphereAp.Radius = 1200;
                            sphereAp.Center.X = centerPosAp.X;
                            sphereAp.Center.Y = centerPosAp.Y;
                            sphereAp.Center.Z = centerPosAp.Z;
                        }
                    }
                    dune.CubeGrid.SetPosition(centerPosD);
                    antares.CubeGrid.SetPosition(centerPosA);
                    aphrodite.CubeGrid.SetPosition(centerPosAp);
                    isInit = true;
                    MyAPIGateway.Utilities.ShowNotification("AsteroidCount:" + asteroidList.Count, 100000);
                   
                }
                
                var entsD = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphereD);
                foreach (var ent in entsD)
                {
                    if ((ent.GetObjectBuilder() is MyObjectBuilder_CubeGrid) &amp;&amp; ent.Physics != null &amp;&amp; !ent.Physics.IsPhantom)
                    {
                        VRageMath.Vector3 angVel;
                        VRageMath.Vector3 dirForce;
                        VRageMath.Vector3D entPos = ent.GetPosition();
                        double X = entPos.X - centerPosD.X;
                        double Y = entPos.Y - centerPosD.Y;
                        double Z = entPos.Z - centerPosD.Z;
                        double lenght = Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
                        angVel.X = ent.Physics.AngularVelocity.X;
                        angVel.Y = ent.Physics.AngularVelocity.Y;
                        angVel.Z = ent.Physics.AngularVelocity.Z;
                        dirForce.X = (float)X/(float)lenght;
                        dirForce.Y = (float)Y/(float)lenght;
                        dirForce.Z = (float)Z/(float)lenght;
                        
                        ent.Physics.AddForce(Sandbox.Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, dirForce * (ent.Physics.Mass)*-((float)Math.Pow(9.8,2)), entPos, angVel);
                            
                        }
                        
                }
                var entsA = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphereA);
                foreach (var ent in entsA)
                {
                    if ((ent.GetObjectBuilder() is MyObjectBuilder_CubeGrid) &amp;&amp; ent.Physics != null &amp;&amp; !ent.Physics.IsPhantom)
                    {
                        VRageMath.Vector3 angVel;
                        VRageMath.Vector3 dirForce;
                        VRageMath.Vector3D entPos = ent.GetPosition();
                        double X = entPos.X - centerPosA.X;
                        double Y = entPos.Y - centerPosA.Y;
                        double Z = entPos.Z - centerPosA.Z;
                        double lenght = Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
                        angVel.X = ent.Physics.AngularVelocity.X;
                        angVel.Y = ent.Physics.AngularVelocity.Y;
                        angVel.Z = ent.Physics.AngularVelocity.Z;
                        dirForce.X = (float)X / (float)lenght;
                        dirForce.Y = (float)Y / (float)lenght;
                        dirForce.Z = (float)Z / (float)lenght;
                        ent.Physics.AddForce(Sandbox.Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, dirForce * (ent.Physics.Mass) * -((float)Math.Pow(9.8, 2)), entPos, angVel);
                    }
                }
               var entsAp = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphereAp);
                foreach (var ent in entsAp)
                {
                    if ((ent.GetObjectBuilder() is MyObjectBuilder_CubeGrid) &amp;&amp; ent.Physics != null &amp;&amp; !ent.Physics.IsPhantom)
                    {
                        VRageMath.Vector3 angVel;
                        VRageMath.Vector3 dirForce;
                        VRageMath.Vector3D entPos = ent.GetPosition();
                        double X = entPos.X - centerPosAp.X;
                        double Y = entPos.Y - centerPosAp.Y;
                        double Z = entPos.Z - centerPosAp.Z;
                        double lenght = Math.Sqrt((X * X) + (Y * Y) + (Z * Z));
                        angVel.X = ent.Physics.AngularVelocity.X;
                        angVel.Y = ent.Physics.AngularVelocity.Y;
                        angVel.Z = ent.Physics.AngularVelocity.Z;
                        dirForce.X = (float)X / (float)lenght;
                        dirForce.Y = (float)Y / (float)lenght;
                        dirForce.Z = (float)Z / (float)lenght;
                        ent.Physics.AddForce(Sandbox.Engine.Physics.MyPhysicsForceType.APPLY_WORLD_FORCE, dirForce * (ent.Physics.Mass) * -((float)Math.Pow(9.8, 2)), entPos, angVel);
                    }
                }
            }
            
        }
    }
    
    it was working perfectly fine before today's update :/
     
    Last edited by a moderator: Jan 29, 2015
  29. midspace Senior Engineer

    Messages:
    2,224
    I'll mention this now as a warning to spare anyone some grief as to why their script is not working, or stops working.
    If you are using MyAPIGateway.Utilities or MyAPIGateway.Multiplayer in UpdateBeforeSimulation()

    Code:
    public override void UpdateBeforeSimulation()
    {
        if (MyAPIGateway.Utilities.IsDedicated &amp;&amp; MyAPIGateway.Multiplayer.IsServer)
    

    Both Utilities and Multiplayer may have to be null checked.

    Code:
    public override void UpdateBeforeSimulation()
    {
        if (MyAPIGateway.Utilities != null &amp;&amp; MyAPIGateway.Multiplayer != null 
            &amp;&amp; MyAPIGateway.Utilities.IsDedicated &amp;&amp; MyAPIGateway.Multiplayer.IsServer)
     
    
     
  30. DuneD Junior Engineer

    Messages:
    948
    Thanks midspace, that solves one of my issues, but I cant still get a list of all the asteroids present :/

    Edit: nvm.. I found out the issue, I actually feel like an idiot now :idea:
     
    Last edited by a moderator: Jan 29, 2015
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.