[mod] Empyrion Scripting Mod

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

Tags:
  1. Mycroft_Groks

    Mycroft_Groks Lieutenant

    Joined:
    Aug 17, 2018
    Messages:
    43
    Likes Received:
    7
    So, something like...
    {{#items @root.ES 'Hold -Pentaxid*'}}
    {{#test Id eq (whatever the refined Pentaxid item ID is}}
    {{move this @root.ES 'Antimatter Tank' 1000}}
    {{SourceE.Name}}:{ {Source}}->
    {{~DestinationE.Name}}:{{Destination}}
    {{format Count '{0,5}'}} : {{i18n Id}}
    {{/move}}
    {{else} }
    {{move this @root.ES 'Antimatter Tank'}}
    {{SourceE.Name}}:{{Source}}->
    {{~DestinationE.Name}}:{{Destination}}
    {{format Count '{0,5}'}} : {{i18n Id}}
    {{/move}}
    {{/test}}
    {{/items}}

    If I'm understanding you correctly, the above should work by moving 1000 refined pentaxid from the 'Hold -Pentaxid*' containers to the
    'Antimatter Tank' if the tank is empty and hold the amount at 1000, right?

    Or can I use the Fill command with the Antimatter tank and code it as
    {{#fill this @root.E.S 'Antimatter Tank' 100}}?
     
    #321
    Last edited: Jan 7, 2023
  2. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    The first solution with the move will work
     
    #322
    Mycroft_Groks likes this.
  3. MrGReaper

    MrGReaper Lieutenant

    Joined:
    Jun 27, 2015
    Messages:
    55
    Likes Received:
    13
    I loaded in the steam workshop example and found the C# scripts (and wooted...I understand c#....lua not so much)
    There is a script for moving items from one box to another... dead simple script:

    var sItems = CsRoot.Items(E.S, "SourceBox");

    sItems.ForEach(I => {
    var miList = CsRoot.Move(I, E.S, "DestBox");
    miList.ForEach(mi =>
    Console.WriteLine(
    $"{mi.Id}\n"+
    $"{mi.Count}\n"+
    $"\n"+
    ""
    ));
    });

    This leads me to some questions:
    1st is there an extension or api I can load into visual studio so i can see what options there are in CsRoot. for example.

    2nd I see the script creates a list of all items in "sourcebox" and that it then iterates through that list to create a new list which it moves while creating (stuck me as odd so not sure i have that right) but leads me to my second question;
    while its itterating through the sItems list, can I have it check if the item matches a specific id or type to then be transfered to a specific box?

    ie:
    var sItems = CsRoot.Items(E.S, "SourceBox");

    sItems.ForEach(I => {
    if (I.Id==4314 || I.Id==4421 ){
    var fuelList = CsRoot.Move(I, E.S, "fuelBox");
    continue;
    }
    if (I.Id==5648 || I.Id==5649 || I.Id==5650){
    var fuelList = CsRoot.Move(I, E.S, "ammoBox");
    continue;
    }
    var miList = CsRoot.Move(I, E.S, "DestBox");
    miList.ForEach(mi =>
    Console.WriteLine(
    $"{mi.Id}\n"+
    $"{mi.Count}\n"+
    $"\n"+
    ""
    ));
    });

    so I am assuming item ID is got from I.Id (I dont know if thats right?)
    I am assuming that this is a standard c# for Each loop where I is the individual item in the list and continue; skips the rest of the code for that list.
    and I am assuming that theres no better way to identify items than by the ID?

    Thats a lot of assumptions so want to check before I potentially crash our server lol

    and 3rd final question (though I get theres a lot of questions in number 2 lol) Is there a good way to get IDS? I looked at the itemsConfig of the scenario we use and the item Ids do not match with whats in game... only way I have been able to get the Ids is to put an item in the Source or dest box of the demo script workshop object and have it show the ID on the box....got to be a better way lol

    Thanks in advance
     
    #323
  4. me777

    me777 Commander

    Joined:
    Aug 18, 2020
    Messages:
    384
    Likes Received:
    131
  5. MrGReaper

    MrGReaper Lieutenant

    Joined:
    Jun 27, 2015
    Messages:
    55
    Likes Received:
    13
    Appreciated.
    Made me have a few more questions though
    Looking at the example, I took my example further up and pasted it in to a new public void function (see image)
    Things that work in game do not have a reference in visual studio, CsRoot and E.S, I was also wrong about the loop.

    E.S is easy to see as there is an example :
    var E= g.E;
    using that example I tried replacing CsRoot with g.CsRoot it made logical sense and worked..... thing is the game does not require those so no idea how the game will handle them being in it, not had a chance to test but figure you guys are likely to know lol (guessing we remove the reference g. when we put the script in game as IScriptModData would be a given.. i could be wrong

    So here is a quick redo of what i had further up...

    public void test (IScriptModData g)
    {
    var E = g.E;

    var sItems = g.CsRoot.Items(E.S, "SourceBox");


    foreach (var item in sItems)
    {
    if (item.Id == 4314 || item.Id == 4421)
    {
    var fuelList = g.CsRoot.Move(item, E.S, "fuelBox");
    continue;
    }
    if (item.Id == 5648 || item.Id == 5649 || item.Id == 5650)
    {
    var fuelList = g.CsRoot.Move(item, E.S, "ammoBox");
    continue;
    }
    var miList = g.CsRoot.Move(item, E.S, "DestBox");
    miList.ForEach(mi =>
    Console.WriteLine(
    $"{mi.Id}\n" +
    $"{mi.Count}\n" +
    $"\n" +
    ""));
    }
    }


    *****************************EDIT**********************
    refining the above code...


    public void test (IScriptModData g)
    {
    var E = g.E;
    var CsRoot = g.CsRoot;

    int[] ammoList = { 4152, 4258, 5722, 7106 };
    int[] fuelList = { 4176, 4314, 4335, 4421 };

    var sItems = CsRoot.Items(E.S, "SourceBox");


    foreach (var item in sItems)
    {
    if (fuelList.Contains(item.Id))
    {
    var fuel = CsRoot.Move(item, E.S, "fuelBox");
    continue;
    }
    if (ammoList.Contains(item.Id))
    {
    var ammo = CsRoot.Move(item, E.S, "ammoBox");
    continue;
    }
    var miList = CsRoot.Move(item, E.S, "DestBox");
    miList.ForEach(mi =>
    Console.WriteLine(
    $"{mi.Id}\n" +
    $"{mi.Count}\n" +
    $"\n" +
    ""));
    }
    }

    The code to paste into a LCD is :

    int[] ammoList = { 4152, 4258, 5722, 7106 };
    int[] fuelList = { 4176, 4314, 4335, 4421 };

    var sItems = CsRoot.Items(E.S, "SourceBox");


    foreach (var item in sItems)
    {
    if (fuelList.Contains(item.Id))
    {
    var fuel = CsRoot.Move(item, E.S, "fuelBox");
    continue;
    }
    if (ammoList.Contains(item.Id))
    {
    var ammo = CsRoot.Move(item, E.S, "ammoBox");
    continue;
    }
    var miList = CsRoot.Move(item, E.S, "DestBox");
    miList.ForEach(mi =>
    Console.WriteLine(
    $"{mi.Id}\n" +
    $"{mi.Count}\n" +
    $"\n" +
    ""));
    }

    called it C#:DaveTest
    added a new lcd called DaveTest
    added 4 cargo boxes named SourceBox, DestBoc, ammoBox, fuelBox

    dumped some test items into the spurce box.... a few seconds the items matching ammo went into ammo, the items matching fuel went into fuel and the rest went into the destbox.... feeling very happy with that!

    Ok got to go to work but another question.... i note that some c# scripts have a [number] in the name, is that a timing delay of some kind?

    **************************EDIT 2***********************************
    at work but its quiet enough I could pull my server files. I was looking for a way to find the item Ids as there is a lot of them.
    ItemConfig from the scenario folder has item Ids but they dont match up with the game....
    so I looked at some examples:
    15mm bullets is 4152 in game but id 56 in the files
    L3 heavy plasma cell is 4258 in game but 162 in the files
    406mm High-explosive Artillery shell is 5722 in game but 1626 ingame

    I had a Huh moment... there was a pattern here.... every number was offset by 4096, this may be common knowledge? may be unique to the scenario I am using? or even unique to the save file?
    but figured it was worth a mention to others who may be looking at understanding the code.


    SIDE NOTE: HUGE THANK YOU TO THE DEVELOPER FOR ADDING C# SCRIPT ABILITY!
    You have no idea how much easier it is than Lua for most of us :)

    *********EDIT 3**********
    I wrote a console app to take make the ItemsConfig.ecf a bit easier to read (yeah I spent an hour writting code to save me some hassle later lol)

    Ok to use this, load up visual studio and create a new console app (c#) called IDCalculate, THIS IS NOT AN INGAME SCRIPT

    paste in the following:

    using System;
    using System.IO;
    using System.Text.RegularExpressions;
    public class Program
    {
    public static void Main()
    {
    using (var infile = new StreamReader("ItemsConfig.ecf"))
    {
    string line = "";
    string name = "";
    string itemId = "";
    string category = "";
    string output = "";
    string oldOutput = " ";
    int offset = 4096;
    int num;
    while ((line = infile.ReadLine()) != null)
    {
    string[] words = line.Split(',');
    foreach (string word in words)
    {
    if (word.Contains("+Item"))
    {
    Regex regex = new Regex(@"\d+");
    num = int.Parse(regex.Match(word).Value);
    num += 4096;
    itemId = regex.Replace(word, num.ToString()); ;
    }
    if (word.Contains("Name:"))
    {
    name = word;
    }
    if (word.Contains("Category:"))
    {
    category = word;
    }
    }
    output = String.Format("{0}, {1}, {2}", name ?? "", itemId ?? "", category ?? "");
    if (!output.Equals(oldOutput))
    {
    if (!output.Contains("Name")) //we only want lines with Name in them after all
    {
    continue;
    }
    Console.WriteLine(output); //to console
    File.AppendAllText("log.txt", output + Environment.NewLine); //to logfile
    }
    oldOutput = output; // so we dont repeat ourselves
    }
    }
    }
    }

    change your offset to what ever offset your ids are at....my guess is they are all at 4096, but just incase....
    build it,
    go to c:\users\YOU\source\repos\IDCalculate\IDCalculate\bin\Debug\net6.0
    place in your ItemsConfig.ecf from the scenario folder your server is using
    run the application, youll get a Log.txt file with the following:

    Name: MeleePlayer, ,
    Name: Flashlight, { +Item Id: 4098,
    Name: Flashlight, { +Item Id: 4098, Category: Weapons/Items
    Name: Pistol, { +Item Id: 4099, Category: Weapons/Items
    Name: Shotgun, { +Item Id: 4100, Category: Weapons/Items
    Name: Minigun, { +Item Id: 4101, Category: Weapons/Items
    Name: PulseRifle, { +Item Id: 4102, Category: Weapons/Items
    Name: Sniper, { +Item Id: 4103, Category: Weapons/Items
    Name: Drill, { +Item Id: 4104, Category: Weapons/Items
    Name: Shotgun2, { +Item Id: 4105, Category: Weapons/Items
    Name: RocketLauncher #T1, { +Item Id: 4106, Category: Weapons/Items
    Name: MultiTool, { +Item Id: 4107, Category: Weapons/Items
    Name: Fillertool, { +Item Id: 4107, Category: Weapons/Items
    Name: ChangeTool, { +Item Id: 4107, Category: Weapons/Items
    Name: LaserPistol, { +Item Id: 4110, Category: Weapons/Items
    Name: AssaultRifle # T1, { +Item Id: 4111, Category: Weapons/Items
    Name: LaserRifle, { +Item Id: 4112, Category: Weapons/Items
    Name: ScifiCannon, { +Item Id: 4113, Category: Weapons/Items
    .......... and so on

    Its not perfect, but then its a helper so who cares about perfect?
    Hopefully that will help more people than just me and thus justify the time i put in to code it lol

    This is a cleaned up version of the ID's for RE Atlantis from our server (may match all RE Atlantis servers assuming the offset is the same) NOTE: my code wasnt perfec so there are some missing IDS, not many but still :(
     
    #325
    Last edited: Jan 23, 2023
  6. Mycroft_Groks

    Mycroft_Groks Lieutenant

    Joined:
    Aug 17, 2018
    Messages:
    43
    Likes Received:
    7
    I'm trying to modify my autorearm script for rearming docked SV/HVs. I can get the ammo into the docked ships, but regardless of if the ship has a weapon to use the ammo, all ammo in the script is refilled. Example. All docked ships get 48 bombs loaded,even if they don't have bomb launchers. Is there a device check that I can do to get the script to only fill the docked ships with ammo needed for the weapons available? If/then statement checking on either an attached weapon or a custom name I name each weapon?
     
    #326
  7. Shadowpheonix

    Shadowpheonix Lieutenant

    Joined:
    May 19, 2022
    Messages:
    44
    Likes Received:
    11
    Does Empyrion Scripting support Handlebars' Inline Partials?

    If so, what is the trick to making them work? Everything I have tried results in a "Failure has occurred while loading a type" error.

    If not, any chance on getting support for it added (or adding an alternate method of reusing code sections such as functions or gosubs)?
     
    #327
  8. Shadowpheonix

    Shadowpheonix Lieutenant

    Joined:
    May 19, 2022
    Messages:
    44
    Likes Received:
    11
    Is there documentation somewhere that explains (or at least lists) the different "@Root" items? Meaning what exactly are the "E" in "@root.E" the "S" in "@root.E.S", the "Docked" in "@root.E.S.Docked", etcetera?
     
    #328
  9. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    There is no "explicit" documentation of the structures but ALL facets/elements are used/built in the DemoCV so that you can have a look and try it out right there.
     
    #329
  10. Mycroft_Groks

    Mycroft_Groks Lieutenant

    Joined:
    Aug 17, 2018
    Messages:
    43
    Likes Received:
    7
    Is there an way to display a ship's faction name? Like {{E.FactionName}}? or something like that?
     
    #330
  11. Shadowpheonix

    Shadowpheonix Lieutenant

    Joined:
    May 19, 2022
    Messages:
    44
    Likes Received:
    11
    I found a post over on StackOverflow talking about looping through properties of an object in Handlebars.js, and decided to try that solution in Empyrion Scripting. I was pleased to discover that it worked, and that I now have a way to get a list of referenceable sub-items (for most things anyway - there are some entries it doesn't work on, with @Root itself being one of them). Here's what I came up with...
    Code:
    {{#each @root.E}}
    Entry # {{@index}} is "{{@key}}" = "{{@value}}"
    {{/each}}
    
    Replace the "@root.E" with whatever your need a sub-list for, such as "@root.E.S.DockedE", "@root.P.Players", etcetera.
    For example, if you use "@root.E", you will get output like the following...
    Code:
    Entry # 0 is "S" = "EmpyrionScripting.DataWrapper.StructureData"
    Entry # 1 is "DeviceNames" = "System.String[]"
    Entry # 2 is "Id" = "28001"
    Entry # 3 is "Name" = "LCDInfo-Demo"
    Entry # 4 is "EntityType" = "CV"
    Entry # 5 is "IsLocal" = "True"
    Entry # 6 is "IsPoi" = "False"
    
    Any items with a "something.something" style value (IE: "EmpyrionScripting.DataWrapper.StructureData" or "System.String[]") can be broken down further by appending the key to your previous "each" query (IE: to get more details on entry 0 above, you would change "@root.E" to "@root.E.S").
    Any entries with a blank key field can be referenced by index. For example,
    "@root.E.S.DockedE" returns a single line for each docked ship...
    Code:
    Entry # 0 is "" = "EmpyrionScripting.DataWrapper.EntityData"
    Entry # 1 is "" = "EmpyrionScripting.DataWrapper.EntityData"
    Entry # 2 is "" = "EmpyrionScripting.DataWrapper.EntityData"
    
    Those sub-items would be referenced as "@root.E.S.DockedE.0", "@root.E.S.DockedE.1", etcetera.
     
    #331
    Last edited: Mar 8, 2023
    eggofevil and ASTIC like this.
  12. Mycroft_Groks

    Mycroft_Groks Lieutenant

    Joined:
    Aug 17, 2018
    Messages:
    43
    Likes Received:
    7
    I'm trying to write a script to display a ship's name and faction on a banner LCD on the outside of the ship.

    I can get the ship name by using {{E.Name}} and I can get the faction number with {{E.Faction}}, but I have yet to find a way to display the 3 character faction abbreviation. Anyone know if this is possible? What's the command?
     
    #332
    Sephrajin likes this.
  13. Mycroft_Groks

    Mycroft_Groks Lieutenant

    Joined:
    Aug 17, 2018
    Messages:
    43
    Likes Received:
    7
    Astic, a user on the server I admin has reported that after we upgraded to last week's version of your mod, the decon function won't return Alien blocks(alien core, npc turrets..that catagory). We use them on the server and users are allowed to use them.

    Is this new or do we have a config issue?
     
    #333
  14. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Yes, this is set in the standard and is desired. But you can control which blocks are to be ignored or replaced in the configuration file via the ID list "RemoveBlocks" or via the "DeconstructBlockSubstitution".
     
    #334
  15. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Not at the moment, but a good idea. I will think about it.
     
    #335
  16. Sephrajin

    Sephrajin Rear Admiral

    Joined:
    Dec 22, 2017
    Messages:
    916
    Likes Received:
    2,917
    It would be great if one could show the faction name as full, not only abrevihation.. oh yeah!

    I was thinking something similar, if would be possible to check wether players are of the same faction or another one?
    As in, for my bio scanner, so I could make a :) for faction players, and something like a :confused: for non-faction players.
     
    #336
  17. Shadowpheonix

    Shadowpheonix Lieutenant

    Joined:
    May 19, 2022
    Messages:
    44
    Likes Received:
    11
    Does the {{replace}} tag support RegEx? If so, how do I tell {{replace}} that is what I am using?
    If not, is there some other way to replace an unknown value? (I am looking for a way to replace all instances of "<size=#>" in a string obtained via {{gettext}}, regardless of what the # value is).
     
    #337
  18. ASTIC

    ASTIC Captain

    Joined:
    Dec 11, 2016
    Messages:
    991
    Likes Received:
    707
    Not yet, but's a good idea and i will implement a RegEx usage
     
    #338
  19. bbk.3164

    bbk.3164 Commander

    Joined:
    May 17, 2016
    Messages:
    235
    Likes Received:
    85
    If it works but I can't set it up (!)
    Detailed instructions needed:
    1) how to assign a box from which the transfer of items will begin?!
    2) how to assign boxes to which items will be transferred?!
    3) how to set a list of items that should be transferred "each item to a specific box" ?!
    Thank you :)
     
    #339
  20. me777

    me777 Commander

    Joined:
    Aug 18, 2020
    Messages:
    384
    Likes Received:
    131
    The version in the old post is a old version, still the basics stayed the same.
    I accumulate orders from lcds on a structure and execute the first few of them each run.
    I atach my current Version and try to explain how it works... (the part in programming I dislike is documentation and manuals)

    -the script binds the source to the structure it find a lcd "AutoTransferList*" (* being a wildcard i.e. left away or 1 or 2)
    the source structurtre for the commands in that lcds is not changeable, if you need a different structure you must place a lcd "AutoTransferList* there too.

    -You can have 1 or more lcds names "AutoTransferInfo*"
    Here the output (log of transfers, erors) will be written



    the syntax for the lcd "AutoTransferList* is as follows:

    line starts with "@" sets the source container "@SOURCE" sets container "SOURCE" as source.

    line starts with "+" sets target container name "+TARGET" sets container "TARGET" as target.

    line starts with "!" sets target structure needs ID of the target "!1234" sets structure with ID1234 as target; "!" sets current structure as target. (if the target is not closeby transfer will not work and is ignored)

    line starts with "." fills oxygen tanks, fuel or pentaxid of target ".Dual Fuel Cell,100" takes "Dual Fuel Cell" from current source and fills fuel tank to 100% (I think filling less than 100% is broken somehow) valid fuel types are "Fuel Cell", "Dual Fuel Cell", "Promethium Hydrocell", "Refined Pentaxid" and "Oxygen Bottle"

    line starts with "#" Comment, is not processed.

    all other lines are parsed as move commands with the syntax being "itemname,target amount" (I think only the basename works, not translated ones) i.e "Titanium Ingot,0" moves all titanium ingots from the current source to the current target.



    an example:
    !
    +1 Zutaten
    @CC-Eisen
    Iron Ingot,500
    @CC-Erestrum
    Erestrum ingot,500

    setts this structure as target
    target container is "1 Zutaten"
    source is "CC-Eisen"
    moves up to 500 iron ingots
    source is CC-Erestrum
    moves up to 500 Erestrum ingots

    you can download the current version:
    https://me777.de/Empyrion/Sort.cs

    it is a savegame script, so needs to be put into the script folder inside the savegame
    example: "C:\empyrionserver\Saves\Games\DediGame\Mods\EmpyrionScripting\Scripts\"

    note spelling, including case matters and is not consistant (Iron Ingot / Erestrum ingot)

    and last note: i only tested with reforged eden, but only thing that could be a problem are the names for fuel.
     
    #340

Share This Page