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. judochop27 Trainee Engineer

    Messages:
    5
    Hi, i'm new to coding and i sometimes can't find a code format that makes it easier to make a mod but i see other people make mods that is thrusters, armor, doors, and etc. Basicly i can't find the formulas for anything than the ones that they/you (developer's) have put out. I mainly know java coding. But if you can help me out then thank you for your time.

    P.S. I can sometimes be stupid and over look things so i might of missed something.

    ---------------
    Steam: judochop27
     
    Last edited by a moderator: Dec 10, 2014
  2. Ravenal Apprentice Engineer

    Messages:
    362
    Okay the way to do it is I think... IMyEntities contains an event for OnEntityRemove event, this you can get the IMyEntity function which means when the entity is removed from the game entirely it will call this, and then I think you can actually do something like

    IMySlimBlock slimBlock = entity as IMySlimBlock; of this sort because CubeBlock which is a block that can be destroyed, has "IMySlimBlock" so if you can figure out how to access the SlimBlock from Entity being Removed you can then do this check.

    bool IsDestroyed { get; }
     
  3. Sp[a]cemarine Apprentice Engineer

    Messages:
    101
    Yeah, this might be possible but you don't have the information about the environment.

    By the way, I asked for something similar late October (can be found on the first page) and this was the answer:

    I'm not sure what the result of the discussion was, so maybe Joe could tell us about the current situation. :)
    And what is with the possibility to request whether the player is an admin or not? Joe, I'm sure you said you'll take a look at it... So are there any plans to realize it soon?
     
    Last edited by a moderator: Dec 10, 2014
  4. tyrsis Junior Engineer

    Messages:
    862
    Figuring out if a cubeblock or player is destroyed / dead is not the issue. The issue is figuring out HOW it was destroyed or killed. There needs to be a playerid attached internally if it comes from something owned by a player, and even though there is a damage type, the damage type isn't really descriptive of where that damage originated from.
     
  5. Ravenal Apprentice Engineer

    Messages:
    362
    I agree, I suppose the event would cover that, pass information about what, who, where, how, and when it was all destroyed. This can help with a lot of future calculations
     
  6. Ravenal Apprentice Engineer

    Messages:
    362
    Can we get the following Whitelisted?


    System.Buffer
    System.Runtime.InteropServices.StructLayoutAttribute
    System.Runtime.InteropServices.LayoutKind
    System.Runtime.InteropServices.CharSet
    System.FlagAttribute
    System.Attribute
    System.AttributeUsageAttribute
    System.AttributeTargets
    System.BitConverter

    System.Type.IsSubclassOf
    System.Type.IsInstanceOfType
    System.Type.IsAssignableFrom
    System.Type.IsEquivalentTo
    System.Type.ToString
    System.Type.IsDefined
    System.Type.GetCustomAttributes


    And finally, when compiling do you guys allow /unsafe code? This would help for something I am doing.


    The ability to have our own attributes and being able to grab those custom attributes can open a lot of doors for more flexibility the code base. I am pretty sure those methods for System.Type should not propose any problems as they are mainly "Checks" against another type.
     
  7. pipakin Apprentice Engineer

    Messages:
    182
    Can we get system.threading.interlocked whitelisted? Without it we can't define events, which makes some things very difficult.

    Pretty please? :)

    Also System.IO.StringReader? I can make my own implementation, but this class should be harmless.
     
    Last edited by a moderator: Dec 13, 2014
  8. Ravenal Apprentice Engineer

    Messages:
    362
    I'd say StringReader and Writer are not any harm as there is no file writing involved
     
  9. joeblack616 Apprentice Engineer

    Messages:
    225

    Hi, no plan for "special" API methods yet. Currently we are still only giving you access to existing things.
     
  10. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi I can consider whitelisting, but unsafe code is no-go. You know. We Are Paranoid.
     
  11. Ravenal Apprentice Engineer

    Messages:
    362
    Unsafe I can understand why, but considering the list above makes me smile =)
     
  12. midspace Senior Engineer

    Messages:
    2,224
    Joe,
    We have Actions which represent in game actions of clicking on toolbar icons, but is it possible to get actions which do more like what the Control interfaces do?

    Ie, set Rotor to a specific turn Velocity?
    Or set the Torque or Breaking Torque?
     
  13. Sp[a]cemarine Apprentice Engineer

    Messages:
    101
    Ok, just to be sure, you won't implement it at the moment but you don't completely give up the idea, right?
    And what about a method or field like "bool IMyPlayer.IsAdmin"? Would this be some kind of special method? I don't think so because the client knows who is an admin and who is not... Or do I get it wrong?
     
  14. joeblack616 Apprentice Engineer

    Messages:
    225
    Hi,
    no currently you can use only terminal actions. It's mainly because of synchronization. I will write about it later
     
  15. blilli Trainee Engineer

    Messages:
    19
    Add a possibility to change a font size of text (need smaller size to be able to accommodate more output info) in IMyHudObjectiveLine, please. Or add a possibility to use more than 1 line of text in it.
    Thank you.
     
  16. Krutchen Apprentice Engineer

    Messages:
    159
    Hey uh, Does anyone know if it's possible to fire a weapon group via a script yet?
    There are several halfway decent Ai scripts on the workshop, and if we could have AI ships use weapons that aren't just the automated turrets, That'd be just dandy.
     
  17. midspace Senior Engineer

    Messages:
    2,224
    This is an Extension I wrote to check if a player is an Admin.
    I've been running it for a month now, and have had no issues (or complaints).

    Code:
    /// <summary>
    /// Determines if the player is an Administrator of the active game session.
    /// </summary>
    public static bool IsAdmin(this IMyPlayer player)
    {
        // Offline mode. You are the only player.
        if (MyAPIGateway.Session.OnlineMode == MyOnlineModeEnum.OFFLINE)
        {
            return true;
        }
    
        // Hosted game, and the player is hosting the server.
        if (MyAPIGateway.Multiplayer.IsServerPlayer(player.Client))
        {
            return true;
        }
    
        // determine if client is admin of Dedicated server.
        var clients = MyAPIGateway.Session.GetCheckpoint("null").Clients;
        if (clients != null)
        {
            var client = clients.FirstOrDefault(c => c.SteamId == player.SteamUserId && c.IsAdmin);
            return client != null;
            // If user is not in the list, automatically assume they are not an Admin.
        }
    
        // clients is null when it's not a dedicated server.
        // Otherwise Treat everyone as Normal Player.
    
        return false;
    }
    
     
  18. Sp[a]cemarine Apprentice Engineer

    Messages:
    101
    Thank you, midspace! That's very useful.
     
  19. Gwindalmir Senior Engineer

    Messages:
    1,006
    Oh please, please, please!
    We would love information on multiplayer syncing.

    Aside from that:
    I'd like the StringComparison enumerator, and the String extensions required to do:

    Code:
    x.FatBlock.BlockDefinition.SubtypeId.Contains("Cockpit", StringComparison.InvariantCultureIgnoreCase)
    It currently throws this error:
    Code:
    2014-12-31 00:48:49.641 - Thread:   1 ->          Type System.StringExtensions used in <GetShipReference>b__9 not allowed in script
    
    Thanks.
     
    Last edited by a moderator: Dec 31, 2014
  20. midspace Senior Engineer

    Messages:
    2,224
    StringExtensions.Contains(this string text, string testSequence, StringComparison comparison);
    Is actually in the VRage.Library.dll Assembly under the System namespace.
    This is NOT whitelisted.
    To Joe: Is it possible to just get the System.StringExtensions type whitelisted?

    Phoenix84, I really don't suggest testing subtypes for names (unless you are looking for a specific name).
    You probably should be checking the definition of the cube to make sure it is what you want.

    Code:
    var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(x.FatBlock.BlockDefinition);
    var cockpitDefintion = definition as MyCockpitDefinition;
    var remoteDefintion = definition as MyRemoteControlDefinition;
    if ((cockpitDefintion == null || !cockpitDefintion.EnableShipControl)
      && (remoteDefintion == null || !remoteDefintion.EnableShipControl))
    {
     return; // Player cannot be Passenger!
    }
    
     
    Last edited by a moderator: Dec 31, 2014
  21. blilli Trainee Engineer

    Messages:
    19
    Add overload to ShowNotification so that will play any sound. Something like that:
    Code:
    MyAPIGateway.Utilities.ShowNotification(msg, 5000, MyFontEnum.Red, MyNotifySoundEnum.Beep);
    
    Thank you.
     
  22. qthree Trainee Engineer

    Messages:
    3
    Is there a way to get all "visible points" (like beacons, antennas, broadcasted detected ores), relative to entity (player/cube/cubegrid)? No matter with modding api or ingame.
     
  23. zeejfps Trainee Engineer

    Messages:
    23
    Custom Definitions / Make the definitions load before loading the .sb files
     
    Last edited by a moderator: Jan 2, 2015
  24. Gwindalmir Senior Engineer

    Messages:
    1,006
    Thanks.
    I wasn't sure of another way to check for non-passenger seats.

    EDIT: Will that work from an anonymous function in CubeGrid.GetBlocks()?

    This is what I currently have:
    Code:
                // Get a list of non-passenger cockpit/remote control blocks
                // Might not work with modded cockpits
                m_ftl.CubeGrid.GetBlocks(blocks,
                    (x) => x.FatBlock != null
                    && (
                        (x.FatBlock.BlockDefinition.TypeIdString == "MyObjectBuilder_Cockpit"
                            && x.FatBlock.BlockDefinition.SubtypeId.Contains("Cockpit")
                        )
                        || x.FatBlock.BlockDefinition.TypeIdString == "MyObjectBuilder_RemoteControl"
                       )
                    );
    
    Would it still be more efficient to let GetBlocks return more than I need, and filter it later?
     
    Last edited by a moderator: Jan 3, 2015
  25. midspace Senior Engineer

    Messages:
    2,224
    GetBlocks is simply filtering an existing in-memory list, and adding them to a new list.
    So there should not be any performance issues from filtering later.
    It really comes down to how effective and efficient your filter is.

    I would certainly advise doing a type check on the definition rather than a string check. Strings can be mistyped too easily, using types will allow you catch those issues. The Type check should also be a little faster than a string comparison.
    The only time I think you need to check it as a string, is if you are looking for a dynamically built block definition. Since we don't have Reflection, you have to build the string name in this case.
    if (f.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Cockpit))

    There should be no issue with anonymous functions. You could even write a mini library of anonymous functions to be reused all over your code.
    Code:
     // ... your code
    cubeGrid.GetBlocks(blocks, CubeFinders.IsValidCockpit);
    // ...
    
    <div>public static class CubeFinders
    {
        internal static bool IsValidCockpit(Sandbox.ModAPI.Ingame.IMySlimBlock block)
        {
            if (block.FatBlock == null)
                return false;
     
            if (block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_Cockpit)
                || block.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_RemoteControl))
            {
                var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(block.FatBlock.BlockDefinition);
                var cockpitDefintion = definition as MyCockpitDefinition;
                if (cockpitDefintion != null &amp;&amp; cockpitDefintion.EnableShipControl)
                    return true;
     
                var remoteDefintion = definition as MyRemoteControlDefinition;
                if (remoteDefintion != null &amp;&amp; remoteDefintion.EnableShipControl)
                    return true;
            }
     
            return false; // Player cannot be Passenger!
        }
    }
    </div>
     
    Last edited by a moderator: Jan 4, 2015
  26. seeker0003 Trainee Engineer

    Messages:
    49
    Ok, didn't see it on a search, and can't believe it hasn't been posted yet, but the power grid needs access functions. At present, there is no way (haven't seen one, correct me if wrong) to find out how much power a grid has access to, what percent of that power is being used, or add power requirements to actions. Considering that increased power requirements is one of the best balancing tools a script mod can have, this seems very necessary. With access to electricity via code, one could make a field that recharges suit power, very useful for an interior. One could balance a jump drive, a super weapon, tonnes of things. To me, one of the most needed API changes.

    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
    
     
  27. CptTwinkie Master Engineer

    Messages:
    4,458
    Those would be convenient but I've got another suggestion to add
    Code:
    myBattery.IsCharging(); //read-only bool
    This would be much more user friendly than parsing the detailed info. That is unless I missed something
     
    Last edited by a moderator: Jan 16, 2015
  28. CyberVic Apprentice Engineer

    Messages:
    106
    I REALLY REALLY would like to be able to interact with batteries more (as was stated in the above post), specifically I REALLY would like to deduct power from them for specific programmatic actions in mods.

    In general, as discussed in previous posts, more events we can attach event handlers to the better. As I'm sure KSH is aware, in a game, the real interesting stuff happens when you start responding to events the player or the environment makes happen. So being able to respond to events is paramount to giving the mod api coding community the ability to do all kinds of amazing, magical stuff.

    I would love to be able to handle chat events recieved from other users for example. Session A types something, Session B (which is the server) can respond to what Session A typed. I'm sure Midspace would also be interested in that.
     
    Last edited by a moderator: Jan 16, 2015
  29. CyberVic Apprentice Engineer

    Messages:
    106
    One other feature request I forgot to make.

    It would be nice if there was an event fired when a player tried to drag an item from one inventory to another or from the inventory to their inventory. Also another event when trying to drag TO an inventory. I dunno maybe it's the same event, just different arguements passed to the handler (like source inventory, target inventory).

    It would also include a separate variable that the handler could set to true or something like "CancelTransfer" that if set to true by the handler, that it would not complete. Thus allowing you to deny pragmatically certain kinds of blocks transferring to or from modded objects with inventories.

    That way if we had custom blocks, let's say a special container that only was able to hold a special unique kind of item or group of items, we could restrict what could be put in it. Furthermore if we had a special weapon which once ammo is put in, that maybe it can't be taken back out we could handle that too.
     
  30. CyberVic Apprentice Engineer

    Messages:
    106
    Finally, I want programmatic access to the global chat history and direct tells through the API.

    Specifically I want to be able for one session (a player) to be able to send a communication message directly to another session (the server). Then I want the ability to setup an event handler on the server's session and when I see a communication message to be able to respond to it.

    If done correctly, the chat history and direct tells can be used as a method for client / server communication.


    And to those who might suggest I run / utilize SESE. I say to you, is it not better that we have this or even something better built into the core API?
     
    Last edited by a moderator: Jan 16, 2015
Thread Status:
Not open for further replies.
This last post in this thread was made more than 31 days old.