1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

[Solved] Any way to access vehicle lua from Lua Trigger?

Discussion in 'Programming' started by bluerider598, Feb 5, 2018.

  1. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    It seems like lua triggers only execute code under the ge lua rather than the vehicle lua.. Is there any workaround to access v.lua from these triggers? Any help is appreciated.
     
  2. Fera

    Fera
    Expand Collapse

    Joined:
    Sep 24, 2016
    Messages:
    2,936
    What are you trying to do?
     
  3. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    I'd like to place the lua trigger at a gas station so that when I pull up to the pump it will fill up the gas tank
     
    • Like Like x 1
  4. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    ... Anyone else?
     
  5. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    5,908
    Could you set global variable that vehicle lua would then read and based on it's value do fillup?

    Of course it would be more efficient if you could just trigger and then run action only once, but if not possible, that might maybe work? I'm not really competent with Lua though, so even my idea might not work at all.
     
  6. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    Hmm.. well I did some more digging and found that you can execute vehicle lua in GE lua like this as an example:
    Code:
    be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('print('..electrics.values['fuelVolume']..')')")
    But I can't seem to be able to set a fuel amount using the same method, I try the following and it doesn't work:
    Code:
    be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('energyStorage.getStorage('mainTank'):setRemainingVolume(2)')")
    I need to know how to write to vehicle lua from GE lua.
     
    #6 bluerider598, Feb 6, 2018
    Last edited: Feb 9, 2018
  7. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    If there's anybody out there who can help with this, I'd appreciate it...
     
  8. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    1,154
    Why are you sending the code you want to be executed first from GE to vehicle Lua and then back to GE?
    You just need the first queueing, not the second one.
     
  9. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    I thought I had to do it this way, I was looking at post #2 of this article to see how to do it: https://www.beamng.com/threads/a-way-to-get-a-value-from-system-lua-t3d-lua-gameengine-lua.25139/
    Sorry, not sure exactly what you mean by this.. I'm testing it in ge lua in the console and no matter how I type it, I can't get it to set the fuel amount.
     
    #9 bluerider598, Feb 10, 2018
    Last edited: Feb 11, 2018
  10. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
  11. Diamondback

    Diamondback
    Expand Collapse
    Moderator
    Staff Member

    Joined:
    Apr 8, 2014
    Messages:
    1,154
    Hm sorry, didn't get notified about your first answer.
    Try this:
    Code:
    be:getPlayerVehicle(0):queueLuaCommand("energyStorage.getStorage('mainTank'):setRemainingVolume(2)")
     
    • Like Like x 3
  12. bluerider598

    bluerider598
    Expand Collapse

    Joined:
    Aug 13, 2016
    Messages:
    212
    It works, thanks!
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice