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:
    116
    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:
    716
    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 2
  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!
     
  5. DeWorD

    DeWorD
    Expand Collapse

    Joined:
    Jan 20, 2017
    Messages:
    152
    Hi. Sorry to wake up older topic, but wondering does any of you know lua code what would change users car when driving in area?
     
  6. MegaKnight

    MegaKnight
    Expand Collapse

    Joined:
    Sep 12, 2024
    Messages:
    255
    Hi
    I don't know exactly what you mean, but I guess it's one of these two things:

    1. Switching the active vehicle when there are multiple spawned vehicles: be:enterNextVehicle(0, 1)
    - the second number is the amount of switches to do, in this example 1 ( = pressing tab once)


    2. Changing the vehicle of the player / spawning a new vehicle: local veh = getPlayerVehicle(0) core_vehicles.replaceVehicle(model, config, veh)
    - model is the name of a vehicle's model in the game files, eg. "pickup" for the D-Series
    - config is the file path of a .pc-config, eg. 'vehicles/pickup/d10_4wd_A.pc'
    - a full command would look like this: local veh = getPlayerVehicle(0) core_vehicles.replaceVehicle("pickup", {config = 'vehicles/pickup/d10_4wd_A.pc'}, veh)
    - short lag/pause due to the vehicle loading
     
    • Like Like x 1
  7. DeWorD

    DeWorD
    Expand Collapse

    Joined:
    Jan 20, 2017
    Messages:
    152
    Thanks for answering :)

    Yea i meant like when you drive in a garage with a d-series and the lua trigger box is in the garage then it just replaces that with like t-series and no need to go to menu...

    this would go to my random carkour vehicles map what ive been doing so ppl won't need to think that much what car and where it is :)
     
    • Like Like x 2
  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