[mod] Empyrion Scripting Mod

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

Tags:
  1. me777

    me777 Commander

    Joined:
    Aug 18, 2020
    Messages:
    405
    Likes Received:
    138
    ASTIC, sorry aber ich habe eine Frgae ;)

    Ich will einen Teleport auf ein anderes playfield machen.
    Der Teleport Befehl nimmt ja ein anderes playfield an, aber wenn das nicht geladen ist funktioniert es wohl nicht.
    Kann ich aus einem savegamescript ein playfield starten?
    Ich denke das braucht die legacy api, aber ich habe leider nicht rausgefunden wie ich auf die zugreife.

    Vielen Dank.
     
    #341
  2. Blood Cloud

    Blood Cloud Ensign

    Joined:
    Sep 7, 2022
    Messages:
    10
    Likes Received:
    0
    Is there a way of figuring out why scripts randomly stop working after a while ?

    (a relog fixes this often)
    [​IMG]
     
    #342
    Last edited: Apr 3, 2023
  3. Blood Cloud

    Blood Cloud Ensign

    Joined:
    Sep 7, 2022
    Messages:
    10
    Likes Received:
    0
    Looking ahead at the Keybinds for SIGNALS and the CUSTOM Switches (p menu),

    is there a way to display the state of the "GENERAL" and "CUSTOM" switches ?
    I found
    {{~signals @root.E.S '*'}} and
    {{~getswitches @root.E.S '*'}} but no "General" or "Custom" Block in P Menu


    [​IMG]
     
    #343
  4. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    Das geht (leider) nicht so einfach denn die legacy API steht nur im DedicatedServer zur Verfügung und nicht im Playfieldserver - somit braucht man eine Kommunikation zwischen den beiden. So was habe ich schon rudimentär eingebaut, aber es führt natürlich dazu das diese Teile NUR ein einem Serversetting laufen :-(
    Ich schaue mal ob ich den Teleporter dahingehend erweitern kann da hier schon der (rudimentäre) Einbau gemacht ist
     
    #344
  5. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    Strange, that's the first time I've seen something like that. :-O
     
    #345
  6. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    Unfortunately, the API does not provide the "switches" of "General" and "Custom".
     
    #346
  7. Blood Cloud

    Blood Cloud Ensign

    Joined:
    Sep 7, 2022
    Messages:
    10
    Likes Received:
    0
    :(

    Thanks for the reply
     
    #347
  8. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    Hi Astic,

    i found interesting movement methods in the eleon Api IEntity interface:
    [​IMG]
    [​IMG]

    Is it correct that your mod wrap this interface into the IEntityData interface?
    And therefore I have no direct access to the IEntity interface, correct?

    So can you explain why the IEntityData interface does not provide the movement methods?
    Is it a authorization problem to prevent exploits?
    Or is the Api Wiki incredibly outdated?

    And another Question:
    I found the property "ShieldLevel" in the IStructureData interface.
    But unfortunately this is not the shield level. It is the actual shield value.
    Is there a property somewhere else with the shield max value to calculate the real shield level?

    And another Question: :)
    I noticed the IEntityData property "Faction" now delivers a combined id tag like "player.1234".
    I would assume I need a database query method to fetch the attached name tag from somewhere.
    Has any of your interface a method for this?
     
    #348
    Last edited: Apr 5, 2023
  9. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    Finally I found at least a vague rule to this problem.
    It seems that if I change one name to a custom one "something" needs at least several seconds to update.
    If I change directly another device name, its not saved.
    If I wait more then 30 seconds with closed control panel before changing another device, the first change attempt is succesful in 100% of the cases.

    It looks like that changing one name fires some "data base update event" which takes several seconds to complete and blocks any other change while updating the first change.

    I don't know if it is something that has its root cause in the api or the underlying game internal data base management.
     
    #349
  10. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    I tracked down a strange behaviour on big structures:

    Here the cycleCounter stays 0:

    Code:
    //CsRoot.Items(E.S, "*");     //   <- commented out
    int cycleCounter = 0;
    CsRoot.Items(E.S, "*").ForEach(item =>
    {
          cycleCounter++;
          if (iFuelLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Fuel, iFuelLimit); }
          if (iOxygenLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Oxygen, iOxygenLimit); }
          if (iPentaxidLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Pentaxid, iPentaxidLimit); }
    });
    
    Here the cycleCounter counts up:

    Code:
    CsRoot.Items(E.S, "*");       //   <- not commented out
    int cycleCounter = 0;
    CsRoot.Items(E.S, "*").ForEach(item =>
    {
         cycleCounter++;
         if (iFuelLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Fuel, iFuelLimit); }
         if (iOxygenLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Oxygen, iOxygenLimit); }
         if (iPentaxidLimit != null) { CsRoot.Fill(item, E.S, StructureTankType.Pentaxid, iPentaxidLimit); }
    });
    
    I seems that "CsRoot.Items" return nothing at the first call, if the structure is "too big".
    But at the second call the method returns the items even on big structures.
    Does this work as intended?
    On small structures the counter counts up in both cases.
     
    #350
  11. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    1. I have not yet "passed through" these functions as I do not (yet) see any effective use for them because, on the one hand, the scripts may not run fast enough and, on the other hand, you cannot find out anything about your surroundings, e.g. terrain height, etc.
      But if you have a concrete idea, let me know and I will implement the functions in the scripting.

    2. I only pass the ShieldLevel through 1:1 from the API, so if this doesn't work we need to write a bugticket for Eleon
    3. This ist native in the ModAPI from Eleon Faction: ToString() => $"{Group}.{Id}"
     
    #351
  12. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    I have included code like this 'if (root.TimeLimitReached) return ...' in many places in the functions so that the scripts do not consume too much computing time at once, since in many cases they are (have to be) executed synchronously in 'Game_Update()'.
    But I will investigate this further, and thanks for the analysis :-D
     
    #352
  13. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    I already asked myself how much "load" I can produce by growing structures until such thing happens. :)
    If the result would be relient, it would be ok. I hope you will find the reason for this not predictable behaviour.
    The second call seems to work relient. So something seems to change between the first and the second call. And the structure was it not. :)
     
    #353
    ASTIC likes this.
  14. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    Can you put the "large" structure in the workshop or send me the ebp file so that I can test it directly?
     
    #354
    Preston likes this.
  15. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    1. I planned to use the position information of the Entity in the hope in combination with security distances and explicitly defined coordinates (i.e. for auto miners) it would be good enough for a transportation drone vessel. But of course its still a early idea. I am at least not even sure if this would work to gather something in another playfield if the playfield is in standby. If the implementation needs two much work i'm fine to wait. :)

    2. Yes, the value is passed through. But I was wondering about the inconsistence compared to the power properties. For power there is a "actual value" and a "max value". So i have all options to use the values or to calculate a "level". For Shield there is a property named "level", containing the actual value but the max value is missing. I just asked myself if this property is just misslabeled and the "max shield value" can be found somewhere else.

    3. Maybe I don't get the point but how do I get the faction long or short name? Or has the Api still no acces to query the game data base where the faction data is stored?
     
    #355
  16. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    #356
  17. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    1. Ok, I will add the functions so that you can "play around" with them.
    2. Unfortunately, this is all that the API "provides" here:
      Code:
      Assembly ModApi, Version=0.0.0.0, Culture=neutral, namespace Eleon.Modding
      {
          public interface IStructure
          {
      ...
              int PowerOutCapacity { get; }
      
              int PowerConsumption { get; }
      
      ...
              bool IsShieldActive { get; }
      
              int ShieldLevel { get; }
      ...
      }
    3. Unfortunately, the faction information can ONLY be obtained via the (old) API via the "dedicatedServer" and not from the database or the new API. And I have so far shied away from the effort of getting this from the "dedicated" via inter-process communication, especially as this would only work in MP server mode :-(
     
    #357
  18. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    Thanks for implementing the movement methods.

    Ok, then "shield plan B". I hope determining the shield max value by examining the shield device id will not be too awkward. :p

    Ok, then we hope eleon will deliver the faction data in the next 20 years. :p
     
    #358
  19. ASTIC

    ASTIC Rear Admiral

    Joined:
    Dec 11, 2016
    Messages:
    1,074
    Likes Received:
    729
    #359
    Last edited: Apr 8, 2023
    Preston likes this.
  20. Preston

    Preston Commander

    Joined:
    Jul 6, 2017
    Messages:
    124
    Likes Received:
    25
    I had just a thought to the timeout mechanic. Would it be much work to throw an exception if a method call takes too much time?
    Instead of returning nothing the cause would be visible then.
     
    #360

Share This Page