[mod] Empyrion Scripting Mod

Discussion in 'Empyrion API' started by ASTIC, May 25, 2019.

Tags:
  1. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    Thanks!

    And here the next question: :)
    Code:
    CsRoot.Items(E.S,"*").ForEach(item => {
    CsRoot.Fill(item, E.S,StructureTankType.Fuel,50);
    });
    Works fine, but:

    Code:
    CsRoot.Items(E.S,"*").ForEach(item => {
    CsRoot.Fill(item, E.S,StructureTankType.Fuel,50);
    CsRoot.Fill(item, E.S,StructureTankType.Oxygen,30);
    CsRoot.Fill(item, E.S,StructureTankType.Pentaxid,40);
    });
    brings the error message: Only allowed on SaveGameScripts.

    Code:
    CsRoot.Items(E.S,"*").ForEach(item => {
    CsRoot.Fill(item, E.S,StructureTankType.Oxygen,30);
    });
    brings this error mesage, too.
    Is the constant "Oxygen" and "Pentaxid" the wrong spelling? Or is it a bug?
     
    #41
  2. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    It's not a bug, just (incorrectly) not released for player scripts. If you are in [EGS]\Saves\Games\[SaveGame]\Mods\EmpyrionScripting\ sCompilerConfiguration.json
    the "WithinLearnMode": true, if you turn on all unknown things are automatically written into the SaveGame section and you can move the entries you need into the Player section
    eg here you need a "EmpyrionScripting.Interface.StructureTankType.*", in the player section.
    The wildcard * allows everything in this type

    I have updates this in the current 5.6.1 ;-)
     
    #42
    Last edited: Jul 12, 2020
  3. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    Thanks again, the afternoon is saved :D
     
    #43
  4. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    I got memory usage warnings from my server after start using C# scripts.
    Is a garbage collector in place?
    Is it "safe" to use the "new" operator in the scripts?
     
    #44
  5. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    I set "WithinLearnMode: true" but unfortunately nothing is added to the "SaveGame" section.
    I get a "allowed in SaveGameScript" message at trying to use "item.GetType()" but no Entry appears in the "SaveGame" Section.
    Additionally I'm not even sure if "GetType" is what I need.
    I want to read the "group" of the item. "ammo" for example.
     
    #45
  6. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    You dont need 'ammo' (it is a special internal) - from "ConfigById" you can get the group
     
    #46
  7. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    For the group issue::
    "Group" seems not to be a valuable "Attr" in "ConfigById".
    I tried to read the attribute list of several item-ids and found no "Group" attribute or value in one of it.

    For the memory issue:
    I removed the script-demo-vessel from my playfield and the memory-usage stays constant
    even with the "new" operator in several of my scripts.
    Whatever produces the memory leak it must be in one of the scripts of the demo-vessel.

    For the rights issue I added to "Player":
    "System.Environment.*",
    "System.Math.*",
    "System.double.*",
     
    #47
  8. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Code:
    { Block Id: 53, Name: SathiumResource
      Material: resourcehard
      Group: resource
      { Child DropOnDestroy
        Count: "2,4"
        Prob: 0.2
      }
    }
    upload_2020-7-14_18-2-24.png
    Note: You need Playeraccess for "EcfParser.*"
    or in HBS
    upload_2020-7-14_18-2-52.png
     
    #48
  9. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    hmmmm, there is a inconsistence in the config attribute structure.
    Try to read the group of id 2248 for example. There is no group.

    Maybe I miss some basics but how to link the "high-level" ids of the ingame-visible items
    to the "low-level" ids in the parent structure of the items?
    The groups in your example only exists in the low-level item ids.

    Most ingame-visible Items have no Group:

    The Testcode:
    Code:
    CsRoot.Items(E.S,"*").ForEach(I=>{
    Console.WriteLine(I.Name+": "+
    CsRoot.ConfigFindAttribute(I.Id,"Group"));
    });
    shows no Groups:
    [​IMG]
     
    #49
  10. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    I'm not at all sure if there is such an assignment directly - maybe it is also hard-coded in the game?!?
    @Sephrajin has created many lists that I have built into the standard and which can be called up via the "Ids" directory.
     
    #50
  11. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    "Ids" is protected in savegamescripts :). Where is it located? Maybe "System.Ids.*", "EcfParser.Ids.*" or "EmpyrionScripting.Ids.*" ?
    I searched the description of "Ids" without success on the EmpyrionScripting GitHub Page. Do I need glasses? :D

    Next Question. :) I try to use the "IContainer" class interface:
    Code:
    var C = CsRoot.GetDevices<IContainer>(
    CsRoot.Devices(E.S,"*"));
    Console.WriteLine(C.Count());
    C.ForEach(D=>{Console.WriteLine(D.CustomName);
    });
    On GitHub I found that IContainer should have a member called "CustomName" but ingame I got the compiler error "no such member". I have "Eleon.Modding.IContainer.*" placed in the player section. Where is my fault?
     
    #51
  12. shadowiviper

    shadowiviper Commander

    Joined:
    Apr 13, 2020
    Messages:
    89
    Likes Received:
    144
    I've not tried the C# scripting yet, but if its anything like the handlebars version CustomName doesn't get populated until you actually set a name for a component - the game itself doesn't populate that field when it's still the 'default' name and there isn't a "regular" name field in the same way (you can pull out some things by delving through the config then feeding it through the localisation with "i18n")

    So for example, you put down a standard cargo box and in the control panel device list it shows as "Cargo Box", when you select it the text area where you rename it is empty by default - that is where CustomName pulls from - so when you rename it to "Weapons Box" then customname becomes populated
     
    #52
    Last edited: Jul 17, 2020
  13. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    upload_2020-7-17_16-54-53.png

    "Ids" is a Dictionary at root level ;-)
    CustomName ich NOT a property of IContainer, only of IBlock and a small doc for the ModApi you will find here
    [EGS]\Content\Extras\Modding Doc

    Code:
    Console.WriteLine(Ids["AmmoPlayer"]);
    
    var C = CsRoot.Devices(E.S,"*")
    .Select(B => new {
    B,
    D=E.S.GetCurrent()
    .GetDevice<IContainer>(B.Position)
    })
    .Where(C => C.D != null);
    Console.WriteLine(C.Count());
    C.ForEach(D=>{
    Console.WriteLine(D.B.CustomName);
    });
     
    #53
  14. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    But with which Id? I try to get a "identification element" from "D" without success. No "CustomName", no "Name", no "Id". I do not find the correct spelling for any identification member to use in other lookup-methods.

    This I cannot retrace. The "Name" field in the controlpanel is never empty. Even at a newly placed device (container) the field is filled with a "standard name". So how can CustomName not be populated if I do not clear this field manually? And even if its empty, a user filled field should not lead to a non- existing class member.

    Wow, I have to learn much more about the concatenated standard methos of C#. The possibilities are interessing. Thanks

    But your "container example part" and the "Ids example part" both run in "only allowed in savegamescript" message.
    I get gradual annoyed by this message. :mad: Is it possible to "set everything allowed by default"?
     
    #54
    Last edited: Jul 17, 2020
  15. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    At this point, I prefer to be careful, because if you accidentally release too much, you can do a lot of damage on a server.

    Therefore, entries are sometimes missing, which you can simply add yourself and then please let me know so that I can add them to the standard.
     
    #55
  16. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    My problem is to identify the correct missing entry. The "WithinLearnMode: true" entry does nothing in my file.
    Would it be possible to let the ingame message show the missing entry name path?
     
    #56
  17. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    Found the next:
    Code:
    ....if(V.Id!=E.Id&&V.EntityType!=EntityType.Base){...
    The EntityType constant is not allowed.
     
    #57
  18. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    you placed it here?
    upload_2020-7-18_0-8-3.png
     
    #58
  19. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    123
    Likes Received:
    25
    [​IMG]

    I don't have to place the entry. It was already there. I just changed "false" to "true".
    But my file has a little different name. "CsCompilerConfiguration.json" does not exist in my directory.
    I only have a file named "DefaultCsCompilerConfiguration.json". Maybe that's the reason?
    Adding the correct namespace path to this file activates the permission as you mentioned, but the LearnMode doesn't work.
     
    #59
  20. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    The CsCompilerConfiguration.json have to be in your savegame mod folder ?!?
     
    #60

Share This Page