Quick access mod

Quick access mod

From BeamNG

Revision as of 17:32, 16 August 2017 by Thomatoes50 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Add Quick Access functionality to your mod

This guide assume you have basic knowledge in LUA


Template

You need a LUA module for your vehicle. Bellow is a small template you can put in /vehicles/hatch/lua/example.lua

-- This Source Code Form is subject to the terms of the bCDDL, v. 1.1.
-- If a copy of the bCDDL was not distributed with this
-- file, You can obtain one at http://beamng.com/bCDDL-1.1.txt

local M = {}

local hasRegisteredQuickAccess = false

local function registerQuickAccess()
	if not hasRegisteredQuickAccess and core_quickAccess ~= nil then
		hasRegisteredQuickAccess = true

	--add stuff here

	end
end


local function onLoad()
	log('I', 'onLoad', 'myvehicule')
	registerQuickAccess()

end

local function onReset()
    onLoad()
end

local function updateGFX(dt)
end


-- public interface
M.onLoad    = onLoad
M.onReset   = onReset
M.updateGFX = updateGFX


return M

hasRegisteredQuickAccess is a check to not have duplicate entries when reloading the vehicle or changing level.


 core_quickAccess.addEntry Arguments

core_quickAccess.addEntry Arguments

The arguments are passed to the function as a table

Name Type Optional Default Value Description
level string NOk n/a The level where the entry will be added, "/" is root, do not use number to begin a folder name
title string NOk "" The title of the pie
desc string Ok "" The description displayed when selected
icon string NOk none The icon displayed, list available here
color string Ok "" Defining a color will activate the icon (white) but will not use the defined color.
goto string Ok n/a the action that will be performed, open mod42 level
onSelect function Ok n/a LUA function that will get executed when pie is activated
generator function Ok n/a LUA function called to generated pies on the fly

Adding Entries

you need to add a ‘folder’ for your entries

core_quickAccess.addEntry({ level = '/', title = 'MyFolder', desc="Description of mod", icon="material_extension", goto = '/mod42/'} )

QuickAccess tuto 1.png

now you can add entries in this folder. There is two method

Static entry

If you declare entries with this method you won't be able to change them depending of inputs

core_quickAccess.addEntry({ level = '/mod42/', desc="Desciption", title = 'titre', icon="material_extension", onSelect = function() log('I', 'onSelect', 'TEST') return {'reload'} end} )

onSelect is a LUA function that will get executed when pie is activated

returning reload will refresh the current level.

returning hide will quit/hide the menu

Dynamic entry

core_quickAccess.addEntry({ level = '/mod42/', priority = 10 , generator = function(entries)
    local e = { title = 'a', desc="a", icon="material_extension", onSelect = function() log('I', 'onSelect', 'TEST') return {'reload'} end} 
	if electrics.values.foo == 0 and electrics.values.bar == 1 then e.color = '#ffa800' end
    table.insert(entries, e)

    e = { title = 'b', desc="b", icon="material_extension", onSelect = function() log('I', 'onSelect', 'TEST') return {'reload'} end}
    table.insert(entries, e)
	
	e = { title = 'c', desc="c", icon="material_extension", onSelect = function() log('I', 'onSelect', 'TEST') return {'reload'} end}
    table.insert(entries, e)
end})

QuickAccess tuto 2.png

Every time the menu display this level is displayed or receive a reload event, the pies will be regenerated by calling the function you gave to generator

color is an argument of pies, if it's define the value displayed in game is equivalent to true.

Availables Icones

Radial-symbols.png