Python API

Discussion in 'Empyrion API' started by huhlig, May 25, 2017.

  1. huhlig

    huhlig Captain

    Joined:
    Nov 5, 2015
    Messages:
    160
    Likes Received:
    328
    Just to do a bit of a formal announcement. I've started working on a Server Plugin that allows you to use the almost full might of IronPython to help you run your servers. Unlike most of the other mods this one is completely open source under the Apache 2.0 License. If anyone has additional information on the api, comments, or requests please feel free to file issues against the project.

    https://github.com/huhlig/empyrion-python-api
     
    #1
  2. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    27
    Likes Received:
    6
    Hello!

    MOD working! ;)

    Thank You!

    How to restart script without restart server?
     
    #2
    Last edited: May 28, 2017
  3. huhlig

    huhlig Captain

    Joined:
    Nov 5, 2015
    Messages:
    160
    Likes Received:
    328
    I added a set of installation instructions here 'https://github.com/huhlig/empyrion-python-api/blob/master/README.md' Make sure those are done. Also note this only works on 6.x at the moment. If something isn't working send me a log please. I havent fully debugged everything yet and it is very much a work in progress.

    Restarting the script can be accomplished by poking 'GET <host>:36000/script/execute/loader.py' with postman.

    Please be warned, I am not a seasoned C# or python veteran and things are prone to randomly breaking. I will have a release later this year that is nicely packaged. If you dont know python and C# your mileage will likely vary. Pull requests are welcome.
     
    #3
    Last edited: May 28, 2017
    Dietrich and Alexandra like this.
  4. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    27
    Likes Received:
    6
    Hello!

    I found error in last release in file loader.py :)

    def playerConnected(playerInfo):
    empyrion.LogMessage("Player Connected to " + playerInfo.playfield + ": (" + str(playerInfo.entityId) + ") " + playerInfo.playerName )
    time.sleep(20) # Long enough for them to actually connect
    empyrion.SendGlobalMessage("Hello " + senderInfo.playerName)
     
    #4
    Dietrich likes this.
  5. huhlig

    huhlig Captain

    Joined:
    Nov 5, 2015
    Messages:
    160
    Likes Received:
    328
    Whoops. I think I corrected that locally and forgot to commit changes to origin. I will fix that tonight. Thanks.
     
    #5
    Dietrich likes this.
  6. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    27
    Likes Received:
    6
    Hi!
    How to connect EmpyrionAPI.cs to edit loader.py in Visual Studio?
    (To make it easier to work with classes, procedures and functions)
     
    #6
  7. huhlig

    huhlig Captain

    Joined:
    Nov 5, 2015
    Messages:
    160
    Likes Received:
    328
    I'm not really sure I understand the question. You can edit loader.py directly with a text editor. It does not require Visual Studio at all. IDLE or Pycharm are both good editors.
     
    #7
  8. Alexandra

    Alexandra Ensign

    Joined:
    Apr 9, 2017
    Messages:
    27
    Likes Received:
    6
    Help! How to use UTF-8 code in loader.py ?
    I try:
    write # -*- coding: utf-8 -*- in first line in loader.py
    write line
    ScriptSource scriptSource = _engine.CreateScriptSourceFromFile("Content/Scripts/" + script,Encoding.UTF8); in ScriptManager.cs

    Don't working (

    I have error:
    [PythonApi:Script] Error Loading 'Content/Scripts/loader.py' Script: Microsoft.Scripting.SyntaxErrorException: Non-ASCII character '\xd0' in file Content/Scripts/loader.py

    Wow! I changed format file to "UNIX UTF-8-BOM" and this works!
     
    #8
    Last edited: Jun 8, 2017

Share This Page