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 - new requests

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. midspace Senior Engineer

    Messages:
    2,224
    TL;DR Access to power grid from script.

    Some example properties and methods:
    Code:
     IMyCubeGrid myGrid; myGrid.currentPowerAvailable; //read-only in MW myGrid.electricityInUse; //read-only in MW myGrid.electricityPercentInUse; //read-only 1=100% bool myGrid.RequestElectricityUse(float amount, float milliseconds = 1000); //attempts to use power from the grid, amount in MW, milliseconds if a timeframe is involved. returns true if successful IMyReactor myReactor; myReactor.maxElectricityOutput; //read-only in MW myReactor.currentElectricityOutput; //read-only in MW IMyBatteryBlock myBattery; myBattery.maxStoredPower; //read-only in MWh myBattery.currentStoredPower; //read-only in MWh myBattery.maxInput; //same as Max Required Input, read-only myBattery.maxOutput; //same as Max Ouput, read-only myBattery.addPower(float amount); //adds amount in MW to currentStoredPower. ignores input and output limits. negatives decrement power. myBattery.addPowerByInput(float amount); //same as addPower(), but clamped by maxInput and maxOutput 
    [/QUOTE]

    and SolarPanel.
    mySolarPanel.currentElectricityOutput;
    mySolarPanel.maxElectricityOutput;
     
  2. CptTwinkie Master Engineer

    Messages:
    4,458
    I was doing something today that I wasn't allowed to do and I thought to myself I should really be allowed to do this so i'm back here with complaints. :D

    Code:
    blocks[i].BlockDefinition.SubtypeId.Contains("LargeShipMergeBlock")
    I was using a mod (status blocks or whatever it's called) and they're built on merge blocks but with a different SubtypeId. I simply wanted to test the Subtype to differentiate them from real merge blocks (ingame). Why is that not allowed? Can I suggest that it be allowed? If the BlockDefinition stuff is locked out for a reason how about adding a getBlockSubtype method of some kind?
     
  3. midspace Senior Engineer

    Messages:
    2,224
    Contains() is a string extension method that Keen wrote.
    It is not a standard .Net method.
    I'm not sure it is whitelisted for use in game code.
     
  4. CptTwinkie Master Engineer

    Messages:
    4,458
    Your saying it's the extension that's the problem but I could still use the subtype in another way?
     
  5. midspace Senior Engineer

    Messages:
    2,224
    I've had a look. It is the BlockDefinition that is not allowed.
    Code:
    Sandbox.Common.ObjectBuilders.Definitions.SerializableDefinitionId used in Main not allowed in script
    Which to be blunt, is stupid.
    Considering it is defined in the Sandbox.ModAPI.Ingame.IMyCubeBlock interface.
    I'm logging this in the CTG.
     
    Last edited by a moderator: Jan 17, 2015
  6. CptTwinkie Master Engineer

    Messages:
    4,458
    As far as I can tell there's no way to select or assign a sound from the list for sound blocks. It would be nice to be able to change the sound. Right now there is some trouble with sound blocks retaining their selection anyway so this would be nice to fall back on.

    I'm thinking maybe add a read only list to get all the available sounds and then have a read/write property for the index value. Just so long as there's no possibility of an index out of range crashing things.
     
  7. midspace Senior Engineer

    Messages:
    2,224
    Can we have some APIs to kill and or affect the health of a specified player?

    For scenarios where:
    Escape the radition leak.
    Player punishment.
    Escape the deadly maze.
     
  8. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi, for die try this one :
    Sandbox.ModAPI.Interfaces.IMyControllableEntity.Die()
     
  9. midspace Senior Engineer

    Messages:
    2,224
    Die() puts up a large dialog on the specified player's screen.

    Code:
    Please Confirm
    Are you sure you want to commit suicide?
    Yes   No
    
    I was looking for an API that does not prompt the user in question.



    EDIT:
    Never mind. I've found it after digging through the IL. :D
    Code:
    ((IMyDestroyableObject)player.Controller.ControlledEntity).DoDamage(1000f, MyDamageType.Environment, true);
    
    Though there isn't any API for healing?
     
    Last edited by a moderator: Jan 22, 2015
  10. CptTwinkie Master Engineer

    Messages:
    4,458
    Can we have a string IMyInventoryItem.Content.TypeName that is similar to IMyInventoryItem.Content.SubtypeName?
     
  11. Gwindalmir Senior Engineer

    Messages:
    1,004
    I'd like request access the new GPS system. Currently the MyObjectBuilder_Gps instance appears to be hidden inside of a SerializableDictionary.

    An aside, is there a reason SerializableDictionary is locked down, even for read-only access?
    Thanks, I've been looking for that too.
     
    Last edited by a moderator: Jan 24, 2015
  12. BlueG Apprentice Engineer

    Messages:
    119
    Please add ArgumentOutOfRangeException to the whitelist. I assume, but haven't yet tested, that ArgumentException and ArgumentNullException are already on the whitelist. If not, then they should also be added.
     
  13. fabricator77 Apprentice Engineer

    Messages:
    399
    Can I get a method for creating a new NPC player, with a certain name ?
    Returns the PlayerID.
    What ever method the Cargo Ships use already use would do, if it's not too complex for you guys.

    I want to move away from having to add things to mission worlds,I can add all the factions and their relationships, but cannot add the NPCs themselves.
     
  14. Gwindalmir Senior Engineer

    Messages:
    1,004
    I'd like System.BitConverter added to the whitelist.

    I want to serialize a small amount of numeric data, but I don't want it in XML. MemoryStream is also not whitelisted, but I can live without that if BitConverter is ok.

    This is because MyAPIGateway.Multiplayer.SendMessageToOthers and ilk accept a byte[], and I need to convert my data to one.

    Unless there's another way to serialize I'm not aware of.
     
    Last edited by a moderator: Jan 31, 2015
  15. Belthize Apprentice Engineer

    Messages:
    273
    Do you have any intention of every releasing standard basic AI pathing strategies: seek(), avoid(), evade(), patrol(), arrive(), etc or is that left as an exercise for the reader. I know one or two folks were working on them (Uniphx) and there are probably multiple who are and while I have no objections to sharing public code these are so basic they really ought to be part of an AI package.

    If you are and they're months away great, if you're not or you are but they're a year away I'll just futz with making my own.

    On a related note to any mod authors, if you already have them fleshed out and don't object to sharing them I'm all ears. I'd rather plug them in and work on higher level issues.
     
  16. midspace Senior Engineer

    Messages:
    2,224
    I thought base64 encoding would make more sense.
    https://msdn.microsoft.com/en-us/library/dhx0d524(v=vs.110).aspx
     
  17. Digi Senior Engineer

    Messages:
    2,385
    I'm currently using Encoding.Unicode.GetBytes()/GetString() in a test build, it works fine so far, I don't know if it's succeptible to issues.
     
  18. Gwindalmir Senior Engineer

    Messages:
    1,004
    I'm not dealing with string data.
    I have a structure of numeric values (long & short), that I want to copy into the network buffer. They're already numbers, so I don't want to have to convert to strings and back again if I don't need to.

    I don't know what kind of data the game actually transmits on the network, but I hope it's not XML. Too bloated.
    I wouldn't mine base64 myself, but I need to get my data into the byte[] first. That's where my problem is.
     
    Last edited by a moderator: Feb 2, 2015
  19. midspace Senior Engineer

    Messages:
    2,224
    yes, serializing to XML sounds like it would be too much overhead.

    Hmm, it does sound like we need MemoryStream to be whitelisted.
    Considering we already have ProtoBuf in the VRage.Library, and hopefully whitelisted also, we could do the following then.
    http://stackoverflow.com/questions/7442164/c-sharp-and-net-how-to-serialize-a-structure-into-a-byte-array-using-binary
     
  20. Gwindalmir Senior Engineer

    Messages:
    1,004
    I saw that. I tried to use it, but ran into issues (could be my lack of experience with protobuf though).
     
    Last edited by a moderator: Feb 2, 2015
  21. midspace Senior Engineer

    Messages:
    2,224
    Threw this togeather.
    This works stand alone. Just add VRage.Library reference.
    Inside of SE, I have no idea.

    Code:
    class Program
    {
        static void Main(string[] args)
        {
            var cust = new Customer() { Name = "blah", Orders = new List<long>() { 1, 2, 12308, 2348934 } };
            var base64String = Encode(cust);
            var cust2 = Decode<Customer>(base64String);
        }
    
        private static string Encode(object obj)
        {
            byte[] data;
            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, obj);
                data = ms.ToArray();
            }
            return System.Convert.ToBase64String(data, 0, data.Length);
        }
        private static T Decode<T>(string base64)
        {
            byte[] data = System.Convert.FromBase64String(base64);
            
            using (var ms = new MemoryStream(data))
            {
                return Serializer.Deserialize<T>(ms);
            }
        }
    }
    [ProtoContract]
    public class Customer
    {
        [ProtoMember(1)]
        public List<long> Orders { get; set; }
        [ProtoMember(2)]
        public string Name { get; set; }
    }
    
     
  22. Digi Senior Engineer

    Messages:
    2,385
    Hmm, I've also used MyAPIGateway.Multiplayer.SendMessage*() methods and while testing I found that sometimes it does actually return false, I suspect being too much data sent, so does anyone know the exact limit ? And in what other cases can they return false ?
     
    Last edited by a moderator: Feb 2, 2015
  23. tyrsis Junior Engineer

    Messages:
    862
    4k limit on sends
     
  24. ozarkamax Junior Engineer

    Messages:
    542
    is there a way to access projectors so that we can count blocks and go .... over 1000 blocks? remove from projector and send server compliance message.

    If not here is my request for api access to projectors.
     
    Last edited by a moderator: Feb 10, 2015
  25. DuneD Junior Engineer

    Messages:
    948
    Hey, can the Sandbox.Graphics.TransparentGeometry.Particles be unlocked ? Even better, the whole MyRenderComponentBase, so we can create, spawn, modify particles/sprites/(maybe screenspace effects?) being able to define our own volumetric lights, access to changing the skybox ingame, all those things could bring light and a lot of interested artist into the modding api, but I would be happy with only being able to create my own particle effects using script :)
     
  26. Digi Senior Engineer

    Messages:
    2,385
    Thanks for allowing voxelmaps in mods!

    Just another small request.
    It seems that an asteroid spawned with SpawnGroups as encounter will be renamed with the "Asteroid_" prefix just like procedural asteroids.
    And my request is to keep the original asteroid name in the voxelmap StorageName so we can know it's not actually a procedural asteroid.
     
  27. fabricator77 Apprentice Engineer

    Messages:
    399
    Yeah I can see this being annoying with anything asteroid base like, even for Exploration finds. Would be better to have "<StorageName>_12345".
    I'm suspecting however the asteroid file names are part of the Sector storage file format. The ones in my save certainly have sector numbers in the name.
     
  28. Sp[a]cemarine Apprentice Engineer

    Messages:
    101
    Hey Joe, I have a request concerning the new 'message methods' in MyAPIGateway.Multiplayer: Would it be possible to get a list with the currently registered ids? Just to prevent duplicate registrations.
    BTW: Those methods are very useful. ;)

    Edit:
    Another request: Currently we have the mission screen available in the API but there is an editable dialog available ingame. That one that is used by the text panels. Would it be possible to have access to that? Usage would be the same as the mission screen only the callback should get another argument, that contains the text. This request isn't really important because we have the chat to get input, but for longer text that contain line breaks, such as a message of the day, it would be really useful.
     
    Last edited by a moderator: Feb 16, 2015
  29. Digi Senior Engineer

    Messages:
    2,385
    Well, after two weeks of research I haven't found any good way of triggering a custom hand tool (other than using dampeners or lights :/ ).

    So my request is: an empty hand tool definition + a scripting event that triggers when you click/hold click (preferably with secondary click as well).
     
    Last edited by a moderator: Feb 17, 2015
  30. midspace Senior Engineer

    Messages:
    2,224
    Could we have an API to access the players' ship blueprints?
     
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.