API FAQ

Discussion in 'Empyrion API' started by Xango2000, Apr 27, 2017.

  1. joemorin73

    joemorin73 Captain

    Joined:
    Aug 24, 2016
    Messages:
    319
    Likes Received:
    170
    #21
  2. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    22
    Likes Received:
    2
    Q: How to know which coordinate-area is in that area file? Example '281474926379010.area'
    A: ...
     
    #22
    Last edited: Jun 13, 2017
  3. Jascha

    Jascha Administrator

    • Moderator
    Joined:
    Jan 22, 2016
    Messages:
    1,141
    Likes Received:
    713
    The data in the file or how to know which coordinate-area is in that area file?
     
    #23
  4. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    22
    Likes Received:
    2
    Sorry, I mean "How to know which coordinate-area is in that area file?"
     
    #24
  5. Jascha

    Jascha Administrator

    • Moderator
    Joined:
    Jan 22, 2016
    Messages:
    1,141
    Likes Received:
    713
    If you just want to calculate it once. Our EAH-Tool has a calculator in the Functions-Area.

    If you want to calculate it yourself...
    Well it seems complicated, but once you understood it, its easy. I paste you hear my excel sheet how I figured the whole thing out (took me quite a while :) ):

    upload_2017-6-13_9-46-58.png

    Out of that you can build your own formula. Its not difficult at all.
    See that marked area as your Map. left is east, right is west. Up is north... (i know was mirrored, but took me long to track all).
    The numbers are the last digits of the area file. The numbers on the left the first digits. On the topü and left/right of that map, you see the coordinates in chunks of 500.

    Each area file contains an chunk of 500*500*500

    In the middle you see a 0 that is also where the coordinate 0,0 is. From there its starts with area 0 and goes to the east always 1 further. (it stops with 7 since there is the green barrier (its the map of the planet). But it would go further until ~800000 and then count further in the same row from west to the middle. When reached middle (next to the 0) its already at an areafile 16777215.
    Now you go to the next row and do the same.
    If you go south you see that you start at the highest value possible. Norht south would meet one day in numbers, as east and west would do.

    If you just want to calculate a row further then add 16777216 for north or -16777216 for south. (Keep in mind though that below 0 comes this big number)

    Hope that helps. :)

    This calculation does not consider height... But it would be very similar to the whole thing. You will figure it out :). Just go to empty space without area files and see which area files come up when you fly north / south and draw yourself such a map as I did.

    Here would be the code in VB:

    Code:
    Public Shared Function GetAreaFileName(Coordinates As clsCoordinates) As String
        Dim NSFaktor As Long = 16777216
        Dim NorthSouthRow As Integer
        Dim EastWestRow As Integer
        Dim FileNumber As Long = 0
        GetAreaFileName = ""
        Try
            'North/South
            If Coordinates.NS >= 0 Then
                NorthSouthRow = Math.Floor(Coordinates.NS / 500)
                FileNumber = NorthSouthRow * NSFaktor
            Else
                NorthSouthRow = Math.Floor(Coordinates.NS * (-1) / 500)
                FileNumber = 281474959933440 - (NorthSouthRow * NSFaktor)
            End If
    
            'East/West
            If Coordinates.EW >= 0 Then
                EastWestRow = Math.Floor(Coordinates.EW / 500)
                FileNumber = FileNumber + EastWestRow
            Else
                EastWestRow = Math.Floor(Coordinates.EW * (-1) / 500)
                FileNumber = FileNumber + NSFaktor - 1 - EastWestRow
            End If
            GetAreaFileName = Trim(Str(FileNumber) & ".area")
    
        Catch ex As Exception
            Log.Log_Exception(ex)
        End Try
    End Function
     
    #25
    Alexandra likes this.
  6. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    22
    Likes Received:
    2
    THANK YOU Jascha!
    Now my program is working correctly!
     
    #26
  7. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    Q: I've created my DLL file and put it in the
    ...\Empyrion - Dedicated Server\EmpyrionDedicated_Data\Managed
    folder, then started my server but it doesn't appear to be loading.
    am I missing a step?

    A:
     
    #27
  8. Jascha

    Jascha Administrator

    • Moderator
    Joined:
    Jan 22, 2016
    Messages:
    1,141
    Likes Received:
    713
    A:
     
    #28
  9. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    oi, I'm such an idiot
    Thank you

    That was definitely the problem, it's working now. Thank you.
     
    #29
    Last edited: Jul 13, 2017
  10. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    What am I doing wrong here?
    I'm just trying to get the Event_Player_Info to trigger and say "Data Received" but nothing happens.

    I log in and say something in chat and get "Data Sent" as an alert then Nothing...
    I imagine the part where it says "ci.playerId" (evaluates to an Int 28) is the part that is wrong but I cant figure it out.

    Code:
                        case CmdId.Event_Player_Info:
                            MessagePlayer("Data Received", 1);
                            break;
                        case CmdId.Event_ChatMessage:
                            ChatInfo ci = (ChatInfo)data;
                            GameAPI.Game_Request(CmdId.Request_Player_Info, (ushort)CmdId.Request_Player_Info, ci.playerId);
                            MessagePlayer("Data Sent", 1);
                            break;
    
     
    #30
  11. jmcburn

    jmcburn Rear Admiral

    Joined:
    Jan 15, 2017
    Messages:
    1,110
    Likes Received:
    1,753
    You need to use ci.playerId as a parameter to 'Eleon.Modding.Id'

    That way it should work:
    GameAPI.Game_Request(CmdId.Request_Player_Info, (ushort)CmdId.Request_Player_Info, new Eleon.Modding.Id(ci.playerId));

    /jmc
     
    #31
    Jascha likes this.
  12. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    tried, doesnt work. program stops running when it hits that line.
    I dont get it, even whem I just type my playerId into that parameter it doesnt work.
    Code:
    GameAPI.Game_Request(CmdId.Request_Player_Info, (ushort)CmdId.Request_Player_Info, new Eleon.Modding.Id(28));
    
    This doesn't work, it even prevents the chat message from displaying in the chat window
     
    #32
    Last edited: Jul 14, 2017
  13. jmcburn

    jmcburn Rear Admiral

    Joined:
    Jan 15, 2017
    Messages:
    1,110
    Likes Received:
    1,753
    What error do you get when you debug the program and it gets to that line?
     
    #33
  14. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    good idea. Class libraries cant be debugged directly is what it says when I run Visual Studio's Debugger though.
    um, I'll work on adding error coding when I get off work tonight.
     
    #34
    jmcburn likes this.
  15. jmcburn

    jmcburn Rear Admiral

    Joined:
    Jan 15, 2017
    Messages:
    1,110
    Likes Received:
    1,753
    I don't know, if it works with empyrion that way, but when i code AutoCAD Application modules, i can add the .exe as startup program for the .dll and the debugging usually works. Try adding empyrion.exe as startup program.

    Otherwise just use GameApi.Console_Write for basic debugging, to see what the values are before sending the GameAPI_Game_Request command.

    EDIT: If you use the empyrion.exe as startup program to debug the modl dll in visual studio, you would also have to set the Debug output path of the .dll to Empyrion's mod folder, so visual studio uses the same .dll the game does.
     
    #35
  16. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    OMFG, Really?!?!
    Proto-Buff.dll was missing from the dedicated server DLLs folder
    that is what was causing the thing to fail
     
    #36
    jmcburn likes this.
  17. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    Q: Is it possible to connect a SQLite database to an API mod?
    A: No... my mod fails to load if I have even One reference to SQLite in it.
     
    #37
  18. Jascha

    Jascha Administrator

    • Moderator
    Joined:
    Jan 22, 2016
    Messages:
    1,141
    Likes Received:
    713
    Thats not really true. But you might not be able to do it if you build a Mod directly connected to the game. As mentioned we suggest a TCP connection instead.
     
    #38
  19. Xango2000

    Xango2000 Captain

    Joined:
    Jun 15, 2016
    Messages:
    385
    Likes Received:
    202
    Q: Is there a way to construct an ItemStack[] ?
    A: Not Directly, as far as I can tell. There is a workaround though.

    copy your bag ItemStack[] to a variable
    then give yourself an Empty ItemStack[]
    then use Request_Player_AddItem to give yourself the items you want in the new ItemStack[] in their proper slots
    copy that bag ItemStack[] to another variable
    then restore your original bag ItemStack[]

    Why is this useful?
    Request_Player_ItemExchange requires an ItemStack[]
     
    #39
  20. Jascha

    Jascha Administrator

    • Moderator
    Joined:
    Jan 22, 2016
    Messages:
    1,141
    Likes Received:
    713
    Why don't you just create a ItemStack array?
    Code:
      Eleon.Modding.ItemStack[] itStack = new Eleon.Modding.ItemStack[] { new Eleon.Modding.ItemStack(2053, 1) };
    Just take a look at the example project. It has most Requests implemented
     
    #40

Share This Page