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.

ModAPI

Discussion in 'Modding API' started by Jan.Nekvapil, Sep 9, 2014.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. DuneD Junior Engineer

    Messages:
    948
    http://forums.keenswh.com/post/01-049-64bit-scripts-wont-compile-could-not-load-file-or-assembly-edimadmintoolsadmintoolkit-with-workaround-7095444?pid=1284434439#post1284434439

    I think this is your issue.
     
  2. midspace Senior Engineer

    Messages:
    2,224
    Like what for instance?

    I think most of us as still experimenting since the API isn't complete, and the Script functionality doesn't yet cover in game scripting, or deployed script for servers.

    Functionality to sync API calls between client and server does not appear complete.
     
    Last edited by a moderator: Sep 29, 2014
  3. gimmilfactory Junior Engineer

    Messages:
    523
    So who is willing to help me learn this scripting method?? lol I have been going hard and still don't understand it's hierarchy or reference variables... :X
     
  4. giobs111 Trainee Engineer

    Messages:
    31
    my suggestion would be to start from beacon script, it is simple and good way to start, in it script runs every 100 millisecond and checks if player's position is in 10m range from beacon and then writes text on screen
     
  5. midspace Senior Engineer

    Messages:
    2,224
    Here's one for whoever wants it.
    http://pastebin.com/ZgB0Bi6f

    A build blocker.
    This is suitable for game scenarios where you want players to compete in something but not have access to building anything.

    Tested and works on Dedicated server.
     
  6. botelhorui Trainee Engineer

    Messages:
    53
    has anyone been able to hook up the key pressing?

    I tried using the Sandbox.Input.MyWindowsAPIWrapper

    There is also SharpDX library but I dont think it works...
     
  7. afinegan Apprentice Engineer

    Messages:
    195
    Yea, were all figuring it out together the hard way-ish, I am just trying to see how to debug my enemy AI script on dedicated (send messages to console, var_dump style, anything to help find the problem)

    This is particular mod, I am trying to debug, I removed the references to ChangeGridPermissions(known method that doesn't work on dedicated), I can post more about it if you need me to, I cant get it to push any errors, or show any other signs of life. http://steamcommunity.com/sharedfiles/filedetails/?id=318700033

    How would you go about debugging something like that (just need a push in the right direction, whenever the answer to that direction shows up)?
     
  8. midspace Senior Engineer

    Messages:
    2,224
    At the moment I'm working on a basic command to reorient a ship in a particular direction.
    I have calculated the the correct Yaw and Pitch to initiate ship movement, but I'm having trouble with getting the Roll.

    Can anyone advise on the correct calculations?
    Reading the guides on matrix and Eular calculations hurts my head. I've never been good with the math side.

    EDIT: I think I got it.
    I moved back to using a Quaternion which should be used for rotation, and I've gotten reasonably correct results. But I can't test my calculations until I get home.
     
    Last edited by a moderator: Sep 30, 2014
  9. midspace Senior Engineer

    Messages:
    2,224
    I'm still a little unsure about the whole client server thing. But here is what I think is going on.

    Some scripts, like my mega commands will initiate and run on the client, because that is where the chat traffic initiated from. This mean any changes made to Entities need to be synced back to the server so others can get it. Some things are syncing, like moving players and ships, but not creating ships or ore items.
    It will never run on the server, because the server does not initiate chat messages and it does not process the chat messages. I'm guessing they are all p2p.

    Other scripts that use MyGameLogicComponent will run on both server and client at the same time, because they constantly run while that cube/object exists.
    This is where you may run into issues, as using ShowNotification on the server is pointless, as you the client will not see it. Also certains things that may exist on the client will not exist on the server and usually throw a null reference exception and kill the server.
    This is why logging to a file generally works in this case, but there can be issues there too depending on how you approach it. (I have not yet looked at the file API)
    Either create a static class to manage the file access for all parts of your script to prevent file locks from two parts trying to open it at the same time - or - open the file with Append access and write your update before closing the file again.
     
  10. midspace Senior Engineer

    Messages:
    2,224
    Does anyone have any clear approach on properly establishing the current control state and how to tell which state we are in?
    • Player - First person. - MyAPIGateway.Session.Player.PlayerCharacter
    • Player - third person.
    • Cockpit - First person. - MyAPIGateway.Session.ControlledObject?
    • Cockpit - third person.
    • Camera.
    • Spectator freeview. - ?? (F8, F9)
    IMyCameraController.IsInFirstPersonView
     
  11. botelhorui Trainee Engineer

    Messages:
    53
    MyAPIGateway.Session.ControlledObject - Is any object the player is controlling. Character, Cockpit, RemoteControl. They are all Controllable Entities so you can control them in the your script.

    You can also search for controllable entities in the world by searching in MyAPIGateway.Entities.GetEntities and if its a CubeGrid you need to search in its blocks.

    I also tried to create a IMyPlayer entity using an object builder but it didnt work. If I am not mistaken, in the decompiled source the function body is empty. (lol)
     
  12. eobando Trainee Engineer

    Messages:
    96
    System.Array not allowed in scripts?

    MOD_ERROR: 318962526.sbm_ProductionIndicatorScript, in file: 318962526.sbm_ProductionIndicatorScript
    Type System.Array used in Replace not allowed in script

    I can certainly use a different way to perform what I need but System.Array has built in features that make things easier. Why is this not allowed?
     
    Last edited by a moderator: Oct 2, 2014
  13. Ravenal Apprentice Engineer

    Messages:
    362
    I am not sure yet, but wait until today's release, I think they white listed a lot of things and this may be one of them.
     
  14. Derthmonuter Trainee Engineer

    Messages:
    44
    So, given the new ability to save blueprints, is there an in-API way to export ships/prefabs yet?
     
  15. Ravenal Apprentice Engineer

    Messages:
    362
    I believe with a combination of MyObjectBuilderSerializer.SerializeXML you can serialize MyObjectBuilder_Definitions.

    That is all I know for now
     
  16. Wrenn Trainee Engineer

    Messages:
    14
    Has anyone mucked around with setting cube block colors? I have the following code:


    Code:
            public void FlashGrid( IMyEntity beacon )
            {
                var cubeGrid = (Sandbox.ModAPI.IMyCubeGrid)beacon.GetTopMostParent();
                var blue = VRageMath.ColorExtensions.ColorToHSV(VRageMath.Color.SkyBlue);
                var black = VRageMath.ColorExtensions.ColorToHSV(VRageMath.Color.Black);
     
                if (flip == true)
                {
                    cubeGrid.ColorBlocks(cubeGrid.Min, cubeGrid.Max, blue);
                    flip = false;
                }
                else
                {
                    cubeGrid.ColorBlocks(cubeGrid.Min, cubeGrid.Max, black);
                    flip = true;
                }
            }
    
    The first time it works fine and the color is set to sky blue. The second time it runs it does not set the grid to black, but instead a dark red color. The third time it reverts back to sky blue.

    If I change the black color to FloralWhite it instead sets the grid to an orange color.

    I tried VRageMath.Color.FromNonPremultiplied() and var black= new VRageMath.Vector3I(0, -96, -50) and a few other things with no change. I just can't seem to set some colors correctly.

    Is there something I am missing here?
     
  17. midspace Senior Engineer

    Messages:
    2,224
    I think the Color API's are broken.

    In game I've created two ore detectors.
    One with:
    Hue: 0
    Saturation: 15
    Value: 15

    The other with.
    Hue: 0
    Saturation: 100
    Value: 100


    Using block.FatBlock.GetDiffuseColor(), both report exactly the same Vector of 1,1,1.
     
  18. giobs111 Trainee Engineer

    Messages:
    31
    i have managed to make animation with colors


    here is link
    http://steamcommunity.com/sharedfiles/filedetails/?id=322170565


    only problem i have is black color
     
  19. Wrenn Trainee Engineer

    Messages:
    14
    Looks like we are doing the same thing ;) I am making a simple Display screen that will display text taken from a beacon name.

    It's going well, can display simple text messages, scroll them etc. Just can't get proper colors.
     
  20. giobs111 Trainee Engineer

    Messages:
    31
    i use this method for colors, but for some reason black color does not works, it always displayed dark red

    Code:
    var c = new Vector3();
    c = ColorExtensions.ColorToHSV(Color.FromNonPremultiplied(255, 0, 0, 255));
    
    EDIT: same with white it's light red
     
    Last edited by a moderator: Oct 4, 2014
  21. Derthmonuter Trainee Engineer

    Messages:
    44
    This is what I tried the first day of the modding API. Have they opened up more interfaces for us to use yet? Is there a list or documentation anywhere?
     
  22. tyrsis Junior Engineer

    Messages:
    862
    MyObjectBuilderSerializer is not whitelisted, nor will it ever be unfortunately.
     
  23. Jan.Nekvapil Developer Staff

    Messages:
    92
    HSV in color mask isnt absolute value, as you can see ingame in Color Picker, Hue is absolute and Saturation with Value are just offsets to texture values.
     
  24. giobs111 Trainee Engineer

    Messages:
    31
    thanks Jan tested and got correct colors (never have worked with hsv only with rgb)

    here's code if someone wants to use
    Code:
    var c = new Vector3();
    c = ColorExtensions.ColorToHSV(Color.FromNonPremultiplied(0, 0, 0, 255));
    
    c.Y = c.Y * 2 - 1;
    c.Z = c.Z * 2 - 1;
    
     
  25. midspace Senior Engineer

    Messages:
    2,224
    This means, it's the same base as the Serialized colors.
    It's much the same as in SEToolbox.
    Here's a cleaner wrapper for converting between the two.

    Code:
    using VRageMath;
    
    // convert one way.
    var col1 = Color.Red.ToHsvColor();
    var col2 = Color.FromNonPremultiplied(255, 0, 0, 255).ToHsvColor();
    
    // convert the other way.
    var col3 = col1.ToColor();
    
    public static class Extensions
    {
        public static Vector3 ToHsvColor(this Color color)
        {
            var hsvColor = ColorExtensions.ColorToHSV(color);
            return new Vector3(hsvColor.X, hsvColor.Y * 2f - 1f, hsvColor.Z * 2f - 1f);
        }
        public static Color ToColor(this Vector3 hsv)
        {
            return ColorExtensions.HSVtoColor(new Vector3(hsv.X, (hsv.Y + 1f) / 2f, (hsv.Z + 1f) / 2f));
        }
    }
    
     
  26. botelhorui Trainee Engineer

    Messages:
    53
    For those who dont know.

    If you want to know what types and methods are REALLY whitelisted, just read the following class:

    Code:
    namespace VRage.Compiler
    {
      public class IlChecker
      {
          ....
    
    No more wondering...
     
  27. Malware Master Engineer

    Messages:
    9,663
    Hey. Could someone please confirm or deny my suspicion that it is currently not possible to have a script running on a dedicated server? And if I am wrong, I have still not even been able to get a log written to the Storage area - so is there a bare-bones example somewhere?
     
  28. tyrsis Junior Engineer

    Messages:
    862
    The dedicated server does not run the script, only it's clients. It is unfortunate.
     
  29. Malware Master Engineer

    Messages:
    9,663
    Thank you tyrsis. Yes it is unfortunate indeed. But now, at least, I know.
     
  30. Ravenal Apprentice Engineer

    Messages:
    362
    This helps thanks!
     
Thread Status:
This last post in this thread was made more than 31 days old.