Welcome to my Lua scripting tutorial for beginners in BeamNG.drive modding! This guide will walk you through everything you need to know to get started with Lua—the language behind BeamNG's powerful modding system. What is Lua? Lua is a lightweight scripting language used by BeamNG.drive to control game logic, behaviors, UI apps, and more. It's easy to read and write, making it perfect for creating mods like custom sounds, vehicle AI, scenarios, UI apps, and full gameplay features. Basic Concepts Variables local speed = 100 local isCrashed = false Functions local function greetPlayer(name) print("Welcome, " .. name .. "!") end greetPlayer("Jack The Fox") If Statements if [Put something here] then print("A message") end Loops for i = 1, 5 do print("This is loop number " .. i) end File Structure Mods with Lua often follow this pattern: lua/vehicle/extensions/auto/ The /auto/ folder ensures the script loads automatically for all vehicles. Exported Functions in Extensions local M = {} function M.onInit() print("Vehicle script loaded") end function M.onUpdate(dt) -- Your update code here end return M Testing Your Script Save your .lua file inside /lua/vehicle/extensions/auto/. Press Ctrl+L in BeamNG to reload Lua scripts. Use log() or print() to debug: log("D", "MyMod", "This is a debug message.") Common Globals be - BeamNG engine interface obj - The vehicle object v.data - Vehicle part and node data playerInfo - Info about player status (e.g., seated) damageTracker - Tracks vehicle damage states Other Cool Tricks Manually Create a Radiator Leak damageTracker.setDamage("engine", "radiatorLeak", true) Refuel Vehicle energyStorage.getStorage('mainTank'):setRemainingRatio(1) AI Chase Behavior ai.setTarget("targetID", "chase") Tips for Beginners Start small: Try logging messages. Use Ctrl+L to reload Lua without restarting the game. Look in /lua/vehicle/extensions/ for examples. Don’t give up! Everyone starts somewhere. Even the pros have many trials and errors. Final Thoughts Lua is a fantastic tool for making BeamNG mods feel alive and interactive. Whether you're building custom alarms, creating a refuel system, or making wild weather effects, Lua lets your imagination run wild. Feel free to ask questions (If you have questions reply to this post), share your mods, and most importantly—keep experimenting. Happy modding! – Jack The Fox
A good start! Thank you. Debugging with vs code works well too (if it works )There is an addon for it.