LUA Triggers Help...

Discussion in 'World Editor' started by havocNG 2, Jun 21, 2024.

  1. havocNG 2

    havocNG 2
    Expand Collapse

    Joined:
    Jun 21, 2024
    Messages:
    4
    I want to create a LUA Trigger that will "Break" or "Explode" a vehicle when it enters the LUA. I have made a Fire LUA, and I understand the Gravity LUA Trigger, and I understand how to Teleport, but I cant figure out the Script for a Break/Explode LUA triger? Can anyone help me...Thanks to all
     
  2. Peregrinus

    Peregrinus
    Expand Collapse

    Joined:
    Mar 29, 2024
    Messages:
    114
    Check the core_vehicle "package" in the lua folder. Probably there are a few functions to do similar things to what you want.

    Alternatively, you can do a comprehensive search for specifics words within files. On windows:
    1. Open powershell as admin;
    2. Navigate to the Lua folder inside the game folder
    3. Run the powershell code below, changing the "dummy" word to what you are looking for.
    4. Study the files (and functions) before calling them inside the game
    Code:
     
    Get-ChildItem -Recurse | Select-String "dummy" -List | Select Path
    
    I hope that helps!
     
  3. Barbent Servo GT

    Barbent Servo GT
    Expand Collapse

    Joined:
    Jun 4, 2023
    Messages:
    667
    Hi,
    in the trigger event code block insert the following:
    Code:
    vehObj = be:getObjectByID(data.subjectID)    --  Get Vehicle Object
    vehObj:queueLuaCommand('beamstate.breakAllBreakgroups()')    -- Break
    vehObj:queueLuaCommand('fire.explodeVehicle()')    -- Explode
    
    that's all...
     
    • Like Like x 1
  4. Ivan_UA

    Ivan_UA
    Expand Collapse

    Joined:
    Jun 21, 2025
    Messages:
    4
    Hello BeamNG.drive community,

    I've been trying for quite some time to create a way to dynamically detach specific vehicle parts, such as a single wheel (e.g., wheel_FL), through a Lua trigger script in the World Editor.
    I tried different commands in my Lua trigger scripts.
    Error 1 in console: attempt to call global 'be' (a nil value)
    Error 2 in console: (R): Unknown command setDamage.
    (My understanding was that maybe these commands weren't being used in the right way or in the right context within the trigger script itself.)
    Current Lua Trigger Script I'm Testing:
    This is the latest script I'm trying in a World Editor trigger zone. I'm trying to use beamstate.breakGroup() to detach a specific wheel, similar to how the explosion command works.
    local function detachFrontLeftWheelTrigger(data)


    if data.event == 'enter' and data.subjectName and data.subjectName ~= '' and data.subjectName ~= 'scenario_player0' then

    local veh = be:getPlayerVehicle(0)

    if veh then

    local breakGroupName = "wheel_FL"

    local luaCommandToExecute = string.format(

    'local success, err = pcall(function() beamstate.breakGroup("%s") end);' ..

    'if success then ' ..

    ' -- print("Lua Script (Trigger): Success - Wheel \\"%s\\" detached!"); ' ..

    'else ' ..

    ' -- print("Lua Script (Trigger): Error detaching wheel \\"%s\\": " .. tostring(err)); ' ..

    'end;',

    breakGroupName, breakGroupName, breakGroupName

    )

    veh:queueLuaCommand(luaCommandToExecute)

    end

    end

    end

    return detachFrontLeftWheelTrigger

    Problem with this script: When I use this, I get the following in the console:
    Lua (FL) Помилка: [string "string"]:1: attempt to call field 'breakGroup' (a nil value)
    (This seems to mean that beamstate.breakGroup is not found or cannot be called in this way, even though a general "break all breakgroups" function exists elsewhere in the game.)
    My Question to the Community:
    I can successfully make a car explode using veh:queueLuaCommand('fire.explodeVehicle()'). However, I cannot figure out how to specifically detach a single part like wheel_FL using a Lua trigger script.
    Given that a general "break all breakgroups" function seems to exist in the game's code:
    How can I correctly write a Lua trigger script to detach/break a specific breakGroup (like "wheel_FL")?
    Is there a different command or a specific way to call functions for individual parts? Any simple working code examples or advice would be greatly appreciated.
    Thank you for your time and help!
     
  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