Modding Help [SOLVED] Open GUI window via lua

Discussion in 'Starbound Modding' started by captainrumbarrels, May 4, 2018.

  1. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    Hey folks I have a vehicle that I want to open up the vanilla teleportation menu when lounging. Is there a possible way to open a GUI window through a lua script? I haven't found any scripts when looking through the teleporter menus and warp / teleport interface etc. in the assets folder.

    The closest thing I found was for active items using:

    activeItem.interact(

    and the vehicle

    vehicle.setInteractive(

    My if statement is using what the driver can do when the AltFire button is held so the statement should something (but not exactly like):

    Code:
    if (vehicle.controlHeld("drivingSeat", "AltFire")) then
      activeItem.interact("ScriptPane", "/interface/windowconfig/teleportdialog.config")
    end
    The problem is the vehicle is not an active item. Any thoughts on how to do this? One idea I had was to "trick" the game into thinking I had an active item equipped when I press the alt fire and set up a condition that uses the code above but no results unfortunately.
     
  2. Errors4l

    Errors4l Spaceman Spiff

    Have you tried player.interact? Same usage activeItem.interact.

    If the player table isn't available either, you're going to have to use entity messaging.
    This should make it very easy if the first option doesn't work: https://github.com/Mehgugs/Starbound-RemoteInterfaces
     
    captainrumbarrels likes this.
  3. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    haven't come across player.interact.

    I use the starbounder wiki and read the docs for lua scripting. Must have overlooked it. I'll give it a shot. The entity messaging looks similar to examples I was looking at. I'll give that a go as well.

    for the remote interfaces:
    world.sendEntityMessage(entity.id(),"interact","ScriptPane","/interface/scripted/mmupgrade/mmupgradegui.config")

    Would entity.id() be the vehicle? so written as entity.id("VEHICLENAME"). The "ScriptPane", "interface/etc." I assume is the path of my config I want to activate.

    Thanks again for the help. I'll post back when I make progress.
     
  4. Errors4l

    Errors4l Spaceman Spiff

    You should stick to player.interact if it's available. I don't know if it is though.

    For Remote Interfaces, the entity.id() should be the player entity id. Maybe you'll vehicle.entityLoungingIn(loungeName) for that?

    Code:
    #### `EntityId` vehicle.entityLoungingIn(`String` loungeName)
    
    Returns the entity id of the entity currently occupying the specified lounge position, or `nil` if the lounge position is unoccupied.
    
     
  5. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    Ok I see where this is going, makes sense. Yes since I want to open a GUI interface while the player is lounging in the driver seat, so the lounge position would be:

    Code:
    driverThisFrame = vehicle.entityLoungingIn("drivingSeat")
    (taken from the hoverbike clone I made as written in the vanilla script)

    I haven't come across player.interact yet but I will employ it now that you mentioned it. Any files or types of items you know it would be mentioned in? If not that's ok.
     
  6. Errors4l

    Errors4l Spaceman Spiff

    You should check out /Starbound/doc/lua, it's in player.md.

    As for finding files that use it, I personally use Agent Ransack to find text in files. Grep for Windows might be a good option if you prefer working in a terminal.
     
    captainrumbarrels likes this.
  7. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    Awesome, thanks for the help, appreciate it. That software will be a big help I'm sure. I'll update this post when I get results on my vehicle ability.

    EDIT: I reconfigured the code a little bit so I can test whether or not the code works. I'm pleased with the result... almost! I used the AltFire as a quick template on how I want the message to work. I used the airless biome radio message the player receives when they have no EPP in an airless environment. So far the message prompt comes up like normal. So I know the condition of the alfire button triggers the prompt and send the message to the lounging driver - hurray!

    Code:
    if (vehicle.controlHeld("drivingSeat", "AltFire")) then
        world.sendEntityMessage(vehicle.entityLoungingIn("drivingSeat"), "queueRadioMessage", "biomeairless", 5.0)
    end
    But when I replaced the code it didn't work. Still trying to figure it out.

    Code:
    if (vehicle.controlHeld("drivingSeat", "AltFire")) then
    
    world.sendEntityMessage(vehicle.entityLoungingIn("drivingSeat"),"interact","ScriptPane","/interface/warping/remoteteleporter.config")
    
    end
    My vehicle file has:
    "interactAction" : "OpenTeleportDialog",
    "interactData" : "/interface/warping/remoteteleporter.config",

    I'll probably figure it out eventually but thoughts on what I might need to check? I'll keep playing around in the meantime
     
    Last edited: May 5, 2018
  8. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    @Errors4l Thank you very much for your help. I managed to piece a few things together. I now have a Delorean that activates a vanilla teleporter menu (^^,)

    The only minor problem I have now is setting the condition of opening the menu when I'm in the driver's seat. when I press "E" it opens the menu, not when I'm in the vehicle but it's a huge step forward.

    [​IMG]
     
  9. Errors4l

    Errors4l Spaceman Spiff

    Those interactAction / Data aren't meant for vehicles, they're parameters for interactive objects.
    Did you install Remote Interfaces? It's a mod that makes the interact message available. Without the mod the message won't do anything. Your above code seems correct so with Remote Interfaces installed it should work when you hit alt fire.
     
  10. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    no I didn't, that probably explains why the vehicle is treated as an object. I'll download that as well and that should hopefully solve the vehicle issue. I was playing around with logic and only allow the function interactaction(args) to update when the vehicle lights are on. entered the car as normal. nothing happened. switched the lights on. exited the vehicle, and then the vehicle opened up the menu. so I know the code works. I'll install the remote interfaces mod. I'm eager to get this space travelling car on the market! (^^,)
     
  11. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    Installed Remote Interfaces. Narrowed down a few things even further. So far the Vanilla teleporter menu still pops up when I do so much as interact with the vehicle and I cannot enter the vehicle. RI doesn't seem to change anything as far as I can see. Maybe I'm doing something incorrectly. Again here's what I'm working with.

    My code is as follows:
    Vehicle.lua
    Code:
    function controls()
    --Driver
      if (vehicle.controlHeld("drivingSeat", "AltFire")) then
        world.sendEntityMessage(vehicle.entityLoungingIn("drivingSeat"),"interact","OpenTeleportDialog","/interface/warping/shipteleporter.config")
      end
    end
    Vehicle.lua (continued) - Function that allows the user to open up the gui. Not sure if it's needed. Discovered it in the exitteleporter.lua.

    Code:
    function onInteraction(args)
    
      return {config.getParameter("interactAction"), config.getParameter("interactData")}
    end

    Car.vehicle

    Code:
      "interactAction" : "OpenTeleportDialog",
      "interactData" : "/interface/warping/shipteleporter.config",
    When I remove the Interaction function everything return to normal. Even deleted the AltFire function and for some reason the vehicle still opened up the menu when I interact with it. Also just to confirm, ran a fill scan of the assets and player.interact is not present.

    I must be missing something here and I have a feeling it's a lot simpler than what I think it is. Thoughts?
     
  12. Errors4l

    Errors4l Spaceman Spiff

    Have you tried removing the interactAction and interactData entirely? In JSON that is. Even though I don't see any occurrences where the game uses it in vehicles, perhaps it's overriding the default behaviour (that is, entering the vehicle).
     
  13. captainrumbarrels

    captainrumbarrels Subatomic Cosmonaut

    I have and sadly that renders the vehicle useless. Only with the interact action. As stated before when I used the biomeair message as a proxy to test if the function works it works like a charm, thats without the interact action/data and function interact(args). Another trick would be to set the player as lounging when I open the chat window. It would be annoying everytime I get in but at least it would work(Ihope). Then again I wouldn't be sure if that would break the lua. I'll keep playing around otherwise I made it this far with an "object" type vehicle :rofl: I'll post here when I've worked with a few soloutions. Right now it would be sensible to work with the interact function logic i.e. determining when it applies under certain conditions. I can hide it in an if statement and the vehicle works normally but again I run into the problem of it not deploying the GUI.
     

Share This Page