Gameengine-Classes

class ground_model

class ground_model
ground_model()

Example: creates a new ground_model and prints the roughness Coefficient into the console.

local gmodel = ground_model()
print(tostring(gmodel:as_table().roughnessCoefficient)) -- prints 0
TABLE as_table()
local gmodel = ground_model()
print(tostring(gmodel:as_table().roughnessCoefficient)) -- prints 0
from_table(table)

Members of the ground_model:

Value Name Description
float roughnessCoefficient an indicator of how rough a surface is. Range: [0-1]
float defaultDepth the depth of the model if not overriden by the terrain
float staticFrictionCoefficient static friction coefficient
float slidingFrictionCoefficient sliding friction coefficient
float hydrodynamicFriction hydrodynamic friction (s/m)
float stribeckVelocity stribeck velocity (m/s)
float strength ground strength
int collisiontype material id for particles and sounds
float fluidDensity Density of liquid
float flowConsistencyIndex general drag coefficient
float flowBehaviorIndex  
float shearStrength

if flow_behavior_index<1 then liquid is Pseudoplastic (ketchup, whipped cream, paint)

if =1 then liquid is Newtonian fluid

if >1 then liquid is Dilatant fluid (less common)

float dragAnisotropy Upwards/Downwards drag anisotropy
float skidMarks spawn particles yes/no
float name  

You can get them by this:

local gmodel = ground_model()
print(tostring(gmodel:as_table().roughnessCoefficient))

Class GameEngineLua

class GameEngineLua
log(string level, string origin, string msg)

Logs a text into the console.

Parameters:

  • string level: {E = Error , I = Info, W = Warning, D = Debug}
  • string origin: name of the lua module and the function ( GELua. is prepended when in GE VM)
  • string msg: Message/data to print

Example:

Lua:log("E", "test", "This is a crazy test")
-- prints |E|GELua.test|This is a crazy test
blacklistLogLevel(string str)
exec(string str)

Executes a LUA file

Parameters:

  • string str: The path to the lua-File (f.e. testing.lua, if its in Documents/BeamNG.drive/)

Info: Its allways the relative path from “Documents/BeamNG.drive/”

Example Prints a text from another file (testing.lua)

lua code:

Lua:exec("testing.lua")

testing.lua:

print("This is a cool test") -- prints |A|GELua.print|This is a cool test
requestReload()

Request a Lua reload

Example: Reloads the complete Lua

Lua:requestReload()
queueLuaCommand(string str)

queue the command given by argument

Parameters:

  • string str: The Lua Command as String

Example

Lua:queueLuaCommand("print(\"Hi\")") --prints "Hi"
dumpStack(string logLevel)

dump the current stack

int getMemoryUsageKB()
enableStackTraceFile(string filename, bool full)

dump the stack in a specific file

Parameters:

  • string filename: The path where it should be stored
  • bool full: Do you want to save the whole stack?

Example

Lua:enableStackTraceFile("levels.log", true)
table findObjectByNameAsTable(string name)

Finds an Object By its name and returns a table

Parameters:

  • string name: The name of the Object
Returns:the object or false if not found

Example //TODO: Game crashes if I try

print(tostring(Lua:findObjectByNameAsTable("SimObject")))
bool findObjectByIdAsTable(int id)

try to find the SimObject with this name

Returns:the object or false if not found
int getAllObjects(table)

Parameters:

  • table: A table
Returns:(int) Number of all objects in the level
int findObjectsByClassAsTable(string className, table)

Get all object which have the class className SimObject in a table

Example:

local table = {}
print(Lua:findObjectsByClassAsTable("SimObject", table))
bool castSimObject(ConsoleObject obj, table)
bool saveFunctionOpcode(string filename, v)
string getSelectedLanguage()

Gets the selected Language of the Player

Returns:(string) the language

Example

local language = Lua:getSelectedLanguage()
print(language) --prints f.e. en-US
string getSteamLanguage()

Gets the language, that is used at Steam interface

Returns:(string) the language used for the steam interface

Example

print(Lua:getSteamLanguage()) --prints f.e: en-US
string getOSLanguage()
Returns:(string) the language used by the OS

Example:

local lang = Lua:getOSLanguage()
print(lang) --prints f.e. en-US
reloadLanguages()

Reloads the languages

Example:

Lua:reloadLanguages()
Point3F lastDebugFocusPos
print(Lua.lastDebugFocusPos) --prints f.e. 0.00326664, -1.52147, 0

Class BeamEngine

class BeamEngine
BeamNGVehicle getObject(int objectId)
BeamNGVehicle getObjectByID(int id)

Parameters:

  • int id: the id of the Object you want to get
Returns:the BeamNGVehicle which have the id

Example: Gets the number of existing BeamNGVehicle and prints it to console.

local number = be:getObjectCount()
print(tostring(number))
int getObjectCount()

Gets the Count of all BeamNGVehicle’s

Returns:(int) the number of BeamNGVehicle

Example: Gets the number of existing BeamNGVehicle and prints it to console.

local number = be:getObjectCount()
print(tostring(number))
BeamNGVehicle getPlayerVehicle(int id)

Parameters:

  • int id: the Player ID: mostly it is 0
Returns:the BeamNGVehicle which have the player id

Example: Gets the Vehicle and prints its Position

local veh = be:getPlayerVehicle(0)
print(tostring(veh:getPosition()))
int getPlayerVehicleID(int player)

Gets the ID of the Vehicle Model of the Player

Parameters:

  • int id: the Player you want to get the VehicleID from ( 0 = normal player)
Returns:(int) the id of the Vehicle driver by the player
local number = be:getPlayerVehicleID(0) -- prints f.e. 5616
print(tostring(veh:number()))
string getFFBConfig(int ffid)
queueAllObjectLua(string str)

Add a command to the queue of every objects

Parameters:

  • string str: Command to execute
queueAllObjectLuaExcept(string str, int exceptId)

Add a command to the queue of every objects except the object that have the id exceptId

Parameters:

  • string str: Command to execute
  • int exceptId: The Object id where the command won’t be executed
executeJS(string js)

Executes a Javascript-Script.

Parameters:

  • string js: The Javascript-Code, you want to execute

Example: This example opens via Javascript an alert-window.

local js = "alert(\"ok\")"
be:executeJS(js);
queueJS(string ref, string js)

Same as executeJS() , backward compatibility

executeStreamJS(string ref, string js)
queueStreamJS(string ref, string js)

Same as executeStreamJS() , backward compatibility

setEnabled(bool v)

Parameters:

  • bool v: true to enable, false to disable

Example: Disbles be and prints it to the console

be:setEnabled(false);
print(tostring(be:getEnabled()))
bool getEnabled()
Returns:true if its enabled, false otherwise

Example See: BeamEngine::setEnabled()

reloadVehicle(int player)

Reloads the Vehicle and sets Reload-Position to curent position

Parameters:

  • int player: The player ID (normal player = 0)

Example: Reloads the Vehicle

be:reloadVehicle(0)
print("Vehicle reload success")
resetVehicle(int player)

Resets the Car to his Reload-Position.

Parameters:

  • int player: The player ID (normal player = 0)

Example: Resets the car

be:resetVehicle(0)
print("Vehicle reset success")
toggleEnabled()

Deprecated since version 0.9.

Deprecated API call toggleEnabled(). Please use lua bullettime::togglePause() from now on

exitVehicle(int player)

Function to leave the car

Parameters:

  • int player: The player ID (normal player = 0)

Example: Exits the Car

be:exitVehicle(0)
enterNextVehicle(int player, int nextStep)

Parameters:

  • int player: The player ID (normal player = 0)
  • int nextStep: Up to which car is to be skipped

Example: Changes to the next car

be:enterNextVehicle(0, 1)
enterVehicle(int player, BeamNGVehicle vehicle)

The function places the player in the vehicle with ID 2.

Parameters:

  • int player: The player ID (normal player = 0)
  • BeamNGVehicle vehicle: The vehicle in which the player is to be placed.

Example: Gets the Car with ID 2 and places the player in it.

local car = be:getObject(2)
be:enterVehicle(0, car)
reloadStaticCollision(bool debug = false)

Reloads the collision of static objects

Parameters:

  • bool debug: true if it should be started in debug-mode, false otherwise

Example: Reloads the static collision.

be:reloadStaticCollision(true)
bool isBlockedByFirewall()

Gets if the BeamEngine is blocked by the firewall.

Returns:true if its blocked, false otherwise

Example: Gets if the firewall is blocked and prints the result to console.

local isblocked = be:isBlockedByFirewall()
print(tostring(isblocked))
addFirewallException()

Adds a Firewall Exception to the BeamEngine

Example: adds Firewall Exception and prints the state to console

be:addFirewallException()
local isblocked = be:isBlockedByFirewall()
print(tostring(isblocked))
resetGroundModels()

Resets all Ground models

Example

be:resetGroundModels()
print("Ground models resetted")
table getGroundModel(string name)
int getGroundModelCount()

Gets the number of ground models in the Level.

Returns:(int) number of ground models

Example: Prints the number of ground models into the console

print(be:getGroundModelCount()) -- prints f.e 46
int getGroundModelIDByName(string name)
table getGroundModelByID(int id)
float castRay(Point3F origin, Point3F target)
notifyMissionLoaded()
notifyMissionUnloaded()
bool physicsInitWorld()
physicsDestroyWorld()
physicsStartSimulation()
physicsStopSimulation()
setGroundModel(string name, BeamNG::ground_model_t g)
setSeaLevelTemperatureK(float seaLevelTemperatureKelvin)

Sets the Sea-level-temperatur to a float.

Parameters:

  • float seaLevelTemperatureKelvin: the new temperature

Example:

be:setSeaLevelTemperatureK(298.15)
setSimulationTimeScale(float v)

Sets the Speed of the Game

Parameters:

  • float v: The new Speed

Example: Changes the Speed of the game to the double and prints it to console

be:setSimulationTimeScale(2)
print(be:getSimulationTimeScale())
float getSimulationTimeScale()

Gets the Speed-Scale of the Game

Returns:(float) Speed of the Game

Example See: BeamEngine::setSimulationTimeScale()

string sfxGetAvailableDevices()

Gets all compitable Audidevices

Returns:(string) all audio devices

Example

print(be:sfxGetAvailableDevices())

Prints for example:

../../../../_images/example_sfxDevices.png
reloadCollision(bool withDebug = false)

Function to reload the Collision

Parameters:

  • bool withDebug: if its called in Debug-Mode (Standard: false)

Example: Reloads Collision

be:reloadCollision()
string makeRelativePath(string path, string to)

Parameters:

  • string path: The curent path
  • string to: where does it goes to?
Returns:(string) the relative path

Example:

local path = be:makeRelativePath("levels/derby/info.json", "/C/")
print(path)
-- prints f.e.: C:/Users/erik/Desktop/BeamNG/levels/derby/info.json
string getWorkingDirectory()

Gets the Working Directory path

Returns:(string) the path

Example:

local path = be:getWorkingDirectory()
print(path)
--prints C:/Users/supercooluser/Desktop/BeamNG
bool decalManagerLoad(string fileName)
deleteDataBlocks()
string persistenceLuaData

//TODO All almost all member are nil?

BeamNGNodeStreamPhysFS nodeStream
bool interpolateCenter
bool interpolateNodes
bool interpolateCircles
bool interpolateLua
BeamNGNodeGrabber nodeGrabber
bool physicsMaxSpeed
float physicsSimSpeedUp
float camY
float camX
float zoomInSpeed
float zoomOutSpeed