Lench Scripter Mod [Besiege v0.42]

Discussion in 'Besiege: Modding' started by Lench, Mar 29, 2016.

Tags:
  1. Lench

    Lench Active Member

    [​IMG]

    This mod enables you to control your Besiege machine with Python 2.7/3.0 scripts.
    Changing sliders or toggles and triggering actions allows you to create controllers, stabilizers, autopilots or anything you can dream up to guide your machines.

    NOTE: This mod requires some basic programming knowledge.


    Place your scripts in .../Besiege_Data/Scripts/ directory with .py extension with the same name as machine.

    my-machine.bsg -> my-machine.py

    They will be ran automatically when simulation starts.
    Read the wiki for more information on running scripts.

    [​IMG]

    This script simply controls the speed of an automatic wheel.
    When U is held down, the wheel spins with speed 1.
    If you press I, spinning direction is inverted.


    # get block reference

    wheel = Besiege.GetBlock("WHEEL 1")
    direction = 1

    # set wheel toggle mode
    wheel.SetToggleMode("AUTOMATIC", True)

    def Update():
    """ updates the speed on every frame """
    # direction variable is defined globally
    global direction

    # if U is held down, speed is 1
    if Input.GetKey(KeyCode.U):
    speed = 1 # set speed to 1 if U is pressed down
    else:

    speed = 0
    # invert direction if I is pressed

    if Input.GetKeyDown(KeyCode.I):
    direction *= -1
    # set wheel speed slider

    wheel.SetSliderValue("SPEED", speed * direction)
    For more examples, read the tutorials.

    Read getting started guides here.
    Read full documentation here.


    Read about mod integration here.
    Requires Spaar's Mod Loader


    DOWNLOAD
    Previous versions

    [​IMG][​IMG]

    Source code available on GitHub.
    Feedback, suggestions and contributions are very welcome.

    See the examples on the workshop.


    Join the community Discord chat for help!
     
    Last edited: Mar 10, 2017
  2. ITR

    ITR l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ Staff Member

    Nice! Btw, have you joined the modding slack team yet?
     
  3. Spideric115

    Spideric115 New Member

    what is the block identifier for the firework rocket thing
     
  4. Lench

    Lench Active Member

    Hover your mouse over it and press left shift. It will dump it into the console (Ctrl+K).
    Every block ID looks like <block name><sequential number>. For rockets, it will be ROCKET 1, ROCKET 2, etc. for all the rockets you have.
     
  5. ITR

    ITR l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ Staff Member

    You might want to consider allowing the use of GUIDS in addition to "ROCKET 1" etc., as the order or amount of rockets could change.
    Maybe some "replace all blockID's with GUIDS" button or something, alongside that?
     
  6. Lench

    Lench Active Member

    I can easily implement addressing with different identifiers. Will look into it, thanks.
     
  7. Lench

    Lench Active Member

    Selecting blocks by GUID as requested! You're welcome to try it out.
     
  8. BCMM

    BCMM New Member

    Is there a concise list somewhere of changes that break compatibility with Rtbwrrr's and Lachcim's mods?

    Don't get me wrong BTW, the breaking changes I've noticed so far are certainly good things (position as a vector just makes more sense; dealing with multiple sliders is a must due to Besiege changes; stable block identification was sorely needed). Its just that a list of such changes might take some of the trial and error out of porting existing scripts.
     
  9. rbtwrrr

    rbtwrrr New Member

    Thanks for this. I only started working on updating mine a couple of days ago, but I don't really know enough C# or Unity at the moment.
     
  10. Lench

    Lench Active Member

  11. BCMM

    BCMM New Member

    Thanks, that's really useful! I've already started porting my guided bombs (and after it's ported, I should be able to delete quite a lot of code due to new features).

    By the way, is there a way to get in-game time? It looks like
    Code:
    getTime()
    advances in real-world time regardless of simulation speed.

    It's probably not terribly important now, since there is a way to get block velocity directly, which is the main thing I was using time for before (I had to place spinning objects in game and measure them to calculate time).
     
  12. Lench

    Lench Active Member

    Good noticing, you are right.

    I'm working on a new release that will include a function getScaledTime(), which returns time consistent with timescale slider, and some other nice features.

    By the way, you have access to UnityEngine itself, so you can actually just call Time.time to get what you want.
     
  13. ITR

    ITR l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ Staff Member

    If you have access to &quot;Time&quot;, just use Time.deltaTime and add it to a timer.
     
  14. Lench

    Lench Active Member

    Release v0.50 with Lua watchlist!
    [​IMG]
     
  15. ITR

    ITR l̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ֍̫̜̥̭͖̱̟̟͉͙̜̰ͅl̺̤͈̘̰̺͉̳͉̖̝̱̻̠̦͈ͅ Staff Member

    Formatting totally isn't just the .ToString() of it >.> :p
     
  16. Lench

    Lench Active Member

    Why do it when someone has done it already?
     
  17. Lench

    Lench Active Member

    Release v0.53: Lua watchlist edit global variable feature - scripting unchanged
    [​IMG]
     
  18. Lench

    Lench Active Member

    Release v0.60: Call block mods public methods!
    Code:
    
    drum = besiege:getBlockScript("WAR DRUM 1")
    time = 0
    
    function onUpdate()
        --- strike drum every second
        time = time + Time.deltaTime
        if time > 1 then
            drum:StrikeDrum()
            time = time - 1
        end
    end
    
     
  19. BCMM

    BCMM New Member

    I don't really know .NET or Unity - does this enable us to do things like activate cannons, decouplers and so on?
     
  20. Lench

    Lench Active Member

    Unfortunately not. Only modded blocks, loaded by TGYD's Block Loader, who have exposed public methods like the war drum for example. I know Pixali is working on his laser mod to allow you to get laser hit position etc. to script.

    The only way that I know of activating cannons and such is by simulating key presses, and that is tricky.
     

Share This Page