1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.37 Bug Reporting thread
    Solutions and more information may already be available.

Lua Command scenario issue

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by Turbotail, Feb 21, 2024.

  1. Turbotail

    Turbotail
    Expand Collapse

    Joined:
    Feb 21, 2024
    Messages:
    4
    Hello!!
    I want to ask a question.
    I want to create a scenario in which if my Vehicle A enters into the lua command box then vehicle B (which should be on the map anywhere) should be teleport automatically at a particular coordinates.
    Like not just Vehicle B but multiple vehicles effect by vehicle A. Like starts falling from sky.. and if that scenariois possible then what should be command for that... Waiting for the response.. please respond guys..
     
  2. SineMatic

    SineMatic
    Expand Collapse

    Joined:
    Nov 17, 2022
    Messages:
    68
    You can create a Lua Trigger by going to world editor, clicking 'Create Object' then 'BeamNG' and finally 'Lua Trigger' button. Then you should write some code in 'luaFunction' field (you can see this field if you click on your new trigger and go to 'Inspector' window). In your case the code would be something like this:

    Code:
    local function teleport(data)
        if data.event == 'enter' then
            be:getPlayerVehicle(0):setPosition(vec3(x, y, z)) --x, y and z coordinates of target position
        end
    end
    
    teleport
     
    #2 SineMatic, Feb 22, 2024
    Last edited: Feb 22, 2024
  3. Turbotail

    Turbotail
    Expand Collapse

    Joined:
    Feb 21, 2024
    Messages:
    4
    Hello!!
    Thanks for your response.
    Are you sure that the code is to teleport different vehicle and not to teleport the same vehicle which we are driving?
    I want to teleport different vehicle which is already somewhere on the map and when the playet (which we drive) enters the lua trigger command box then the different vehicle should teleport.
     
  4. SineMatic

    SineMatic
    Expand Collapse

    Joined:
    Nov 17, 2022
    Messages:
    68
    Code:
    local function teleport(data)
        if data.event == 'enter'
            be:getObjectByID(ID):setPosition(vec3(x, y, z))
        end
    end
    
    teleport
    You can get any vehicle ID by going to console and executing this command:
    Code:
    print(be:getPlayerVehicle(0):getID()) --get current vehicle ID
    You can also look up the ID by clicking the game engine drop-down list in console and finding your vehicle (there will be a vehicle ID and a name, which is displayed in world editor scene tree)
     
  5. Turbotail

    Turbotail
    Expand Collapse

    Joined:
    Feb 21, 2024
    Messages:
    4
    Hello!!
    Thanks for your response. I will check this tonight and i will must get back to you on this.
     
  6. Turbotail

    Turbotail
    Expand Collapse

    Joined:
    Feb 21, 2024
    Messages:
    4
    Hello!!

    Thank you so much for your help!!

    The above command has worked well but I had to make a few changes in the command. I used chatGPT for that.
    You are an expert in these things, no doubt about it, I am a noob in these commands so It must be a misunderstanding from my end.
    The working command is something like
    "
    local function teleport(data)
    if data.event == 'enter' then
    be:getObjectByID(17800):setPosition(vec3(-98.532,6.931,0.402))

    end
    end
    return teleport

    "
    I had tried with multiple vehicles also and it worked with the same command as below

    "
    local function teleport(data)
    if data.event == 'enter' then
    be:getObjectByID(17800):setPosition(vec3(-98.532,6.931,0.402))
    be:getObjectByID(18449):setPosition(vec3(-147.804,5.995,0.178))
    be:getObjectByID(18972):setPosition(vec3(-116.617,10.589,0.128))
    be:getObjectByID(18728):setPosition(vec3(-140.120,3.600,0.372))

    end
    end
    return teleport

    "

    Thank you so much for your support.
     
    • Agree Agree 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