I'm thinking of making an app that chooses a random part for each slot in the vehicle. Imagine how many crazy contraptions will be made from that! Sadly, I don't know how to code apps. Is there anything that will direct me in the right way?
If you want, you could use the wiki to find how to make a mod like that but it's kinda hard to learn anything from there.
I think the best way is to look at other people's UI app mods and the game's own UI apps (that's basically how I learned). This wiki article basically highlights the basic structure of the app: https://wiki.beamng.com/My_First_App I found some files that deal with vehicle customizing here: "BeamNG.drive\ui\modules\vehicleconfig\vehicleconfig.js" "BeamNG.drive\lua\ge\extensions\core\vehicle\partmgmt.lua" And I found some functions/variables in them that probably will be helpful to get and set config parts: Code: --Gets the current vehicle's config local config = extensions.core_vehicle_partmgmt.getConfig() --Contains parts of vehicles config.parts --Sets the current vehicle with the new config extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) Here's an example of getting the parts list of the ETK800, removing the FL door, and applying the new config (you can use GameEngine Lua console to execute these functions): Code: --Get current config of ETK 800 config = extensions.core_vehicle_partmgmt.getConfig() --Sets FL door to empty config.parts.etk800_door_FL = "" --Set new config extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) Good luck!
Thanks for the info, but it doesn't seem to work for me. No new configs get generated, nothing happens. Also here's some things i need to figure out. Get current vehicle name Get all parts (table.insert) Cycle through each part (for i, v in ipairs(config.parts) do?) Edit: Also get all available part options for the part. Is there a way to make a table including all part options? Choose random part (Maybe math.random? I don't know how to make it choose a random part though.
Its not supposed to generate any new config files anyways. Did you run those 3 commands in the GE-Lua (GameEngine Lua) console since it doesn't work in Vehicle Lua console? Code: --Gets vehicle's name be:getPlayerVehicle(0):getJBeamFilename() --Cycle through each slot for slot_name, curr_part in pairs(config.parts) do print(slot_name) end --Get all available parts local all_parts = require('jbeam/io').getAvailableParts(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) --Get random part local keyset = {} for k in pairs(all_parts) do table.insert(keyset, k) end local random_part = all_parts[keyset[math.random(#keyset)]]
Woops, thought I had to run all the code at once. Also how would I be able to fit this code into an app? I've noticed that app code runs on a different language (JavaScript), is there a way to make it load the lua inside the js?
You can call GameEngine Lua commands with JS using the following (they need to be inserted as a string): Code: --This runs game engine lua command bngApi.engineLua('the game engine lua command') --This runs game engine lua command and retrieves it returned value bngApi.engineLua('the game engine lua command', function(data) { var val_returned = data });
Well you could create a separate Lua file and do most of the Lua logic there by putting all these Lua commands into larger functions and call those functions from JS so you wouldn't have to make so many bngApi.engineLua JS calls. So create a folder directory in the mod folder like so: "your_mod_name/scripts/your_mod_name" and create two Lua files in there: modScript.lua Code: registerCoreModule('scripts/your_mod_name/extension') extension.lua Code: local M = {} local function someFunction() end M.someFunction = someFunction return M And then you would call these Lua functions in JS like so: Code: bngApi.engineLua('scripts_your__mod__name_extension.someFunction()')
Yeah basically or however you want to structure the code to have more public interfaces (more someFunction functions) to call if you need to or to have more local functions to organize the code.
i have no idea what i'm doing the button wont appear and im getitng this the app is called crazycontraptions .js Code: angular.module('beamng.apps') .directive('crazycontraptions', ['bngApi', function (bngApi) { return { template: 'modules/apps/crazycontraptions/template.html', replace: true, restrict: 'EA', link: function (scope, element, attrs) { scope.scrambleconfig = function () { bngApi.engineLua('scripts_crazycontraptions.test()') }; } }; }]) .json Code: { "name" : "Crazy Contraptions", "author": "beamng", "version": "0.2", "description": "Creates a crazy thing out of random parts.", "directive": "crazycontraptions", "domElement": "<crazycontraptions></crazycontraptions>", "css": { "width": "200px", "height": "200px", "min-width": "100px", "min-height": "100px", "top": "200px", "right": "200px"} } .html Code: <div style="height:100%; width: 100%;"layout="column"> <md-button ng-click="scramble('scrambleconfig');" class="md-raised md-primary" flexmd-no-ink>Scramble Config</md-button> </div>
You had some missing ending brackets so it couldn't compile. And I'm not so sure what your whole folder directory looks like so just in case you did something wrong I added a zip file of what it should look like.
ok I got the button to show up now it doesn't want to work in the lua I told it to print slot_name and all_parts but nothing happens no error help? (btw i used some code from bread's random spawner)
In the html file, the md-button ng-click part is written wrong so change it to: Code: <md-button ng-click="scrambleconfig()" class="md-raised md-primary" flexmd-no-ink>Scramble Config</md-button>
I downloaded the zip and it still has the old html code. It worked for me when I used Code: <md-button ng-click="scrambleconfig()" class="md-raised md-primary" flexmd-no-ink>Scramble Config</md-button> instead of Code: <md-button ng-click="scramble('scrambleconfig');" class="md-raised md-primary" flexmd-no-ink>Scramble Config</md-button>
weird, thought i put that there also what does "random_part" do? if it just selects a random slot in the part list then i don't need that, i need it to go through all available parts, then for each slot, select a random part for that slot.