It selects a random part from all the available parts you can put on the vehicle (not parts list from current vehicle).
It selects a random part from all the possible parts for the vehicle. Its not getting parts from the current vehicle part list.
Wait, all possible parts from the vehicle? I want it so it chooses a random selection from the current part. I don't want a turbo set as the door, lol. Also my lua doesn't seem to be working. I'm creating the magic that sets the random stuff, but nothing happens. The car does reload, though. I looked in the console and it just appeared to be spawning a stock pickup. Fix...? Code: local M = {} local function rolldice() print("if you see this in console that means this works") --Gets vehicle's name local carname = be:getPlayerVehicle(0):getJBeamFilename() local config = extensions.core_vehicle_partmgmt.getConfig() --Cycle through each slot for slot_name, curr_part in pairs(config.parts) do print(slot_name) --Get all available parts local all_parts = require('jbeam/io').getAvailableParts(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) print (all_parts) --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)]] config.parts.slot_name = random_part end extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) end M.rolldice = rolldice return M
All the parts that are available for their slots I think. So every part of the vehicle could change into another part that is available instead of it.
Wait nvm I think I'm getting there, but I still don't got it. It says it can't find the part "table: (insert random 64-bit string here)" wasn't found. Why is it finding some strange 64-bit string instead of a part name? Code: local M = {} local function rolldice() print("if you see this in console that means this works") --Gets vehicle's name local carname = be:getPlayerVehicle(0):getJBeamFilename() local config = extensions.core_vehicle_partmgmt.getConfig() --Cycle through each slot for slot_name, curr_part in pairs(config.parts) do print(slot_name) --Get all available parts local all_parts = require('jbeam/io').getAvailableParts(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) print (all_parts) --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)]] config.parts[slot_name] = random_part end extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) end M.rolldice = rolldice return M
Okay let me explain again. So there is a list of all the possible parts that you can put on the vehicle. And that code randomly chooses a part from that list. So the numbers you are seeing is the memory address of a Lua table. So if you want to look at the contents of the table, use the dump() function. If you want to get a random part for a specific slot, then you should filter through the "all_parts" table for parts that have that specific slot and create a subtable of said parts. And then randomly pick a part from that subtable. Use the dump() function to see how the table is structured to figure out how to implement this. I've basically given you everything you need so you should be able to implement the rest of the logic.
sorry I said "?" because you weren't responding I'm not that experienced at beamng lua, or lua in general. I know how to use pairs, but how would I be able to filter the slot? BeamNG lua is so confusing to me.
Well I think it would be best to learn some Lua before coding then: https://www.tutorialspoint.com/lua/index.htm --- Post updated --- Actually you should use this command instead as it actually gives you what parts you can be put in each vehicle's slot. Code: local all_slots = require('jbeam/io').getAvailableSlotMap(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) So all you need to do is to pick a random part for each slot.
Make sure it doesn't select 'empty' by random Some parts will be a disaster and won't even make a vehicle start, so at least make a match like, diesel engine - diesel fuel tank stuff.
--- Post updated --- Actually you should use this command instead as it actually gives you what parts you can be put in each vehicle's slot. Code: local all_slots = require('jbeam/io').getAvailableSlotMap(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) So all you need to do is to pick a random part for each slot.[/QUOTE] how would I get it to work for slot_name? --- Post updated --- also it doesn't work. table:dump() doesn't seem to exist. no idea if this is correct or not Code: local M = {} local function rolldice() print("if you see this in console that means this works") --Gets vehicle's name local carname = be:getPlayerVehicle(0):getJBeamFilename() local config = extensions.core_vehicle_partmgmt.getConfig() --Cycle through each slot for slot_name, curr_part in pairs(config.parts) do print(slot_name) --Get all available parts local all_slots = require('jbeam/io').getAvailableSlotMap(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) print (all_slots) --Get random part local keyset = {} for k in pairs(all_slots) do table.insert(keyset, k) end local go = keyset:dump() local random_part = all_slots[go[math.random(#go)]] config.parts[slot_name] = tostring(random_part) end extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) end M.rolldice = rolldice return M
how would I get it to work for slot_name? --- Post updated --- also it doesn't work. table:dump() doesn't seem to exist. no idea if this is correct or not Code: local M = {} local function rolldice() print("if you see this in console that means this works") --Gets vehicle's name local carname = be:getPlayerVehicle(0):getJBeamFilename() local config = extensions.core_vehicle_partmgmt.getConfig() --Cycle through each slot for slot_name, curr_part in pairs(config.parts) do print(slot_name) --Get all available parts local all_slots = require('jbeam/io').getAvailableSlotMap(extensions.core_vehicle_manager.getPlayerVehicleData().ioCtx) print (all_slots) --Get random part local keyset = {} for k in pairs(all_slots) do table.insert(keyset, k) end local go = keyset:dump() local random_part = all_slots[go[math.random(#go)]] config.parts[slot_name] = tostring(random_part) end extensions.core_vehicle_partmgmt.setPartsConfig(config.parts, true) end M.rolldice = rolldice return M [/QUOTE] dump() function is used to print out the contents of a variable (e.g. elements of a table). Use it like this: Code: dump(var_name) So make a subtable of available parts for a given slot, get random part from that subtable, and set the current slot to the part. Make use of the "dump" function to see how the tables are structured to see how to access elements of the table, so you can figure out how to code this logic.
dump() function is used to print out the contents of a variable (e.g. elements of a table). Use it like this: Code: dump(var_name) So make a subtable of available parts for a given slot, get random part from that subtable, and set the current slot to the part. Make use of the "dump" function to see how the tables are structured to see how to access elements of the table, so you can figure out how to code this logic.[/QUOTE] Alrighty, I see how it is structured... It's like a pc file. Code: "part", "part", "part" etc But it doesn't sort it by what part it belongs to. It's scrambled. I need some help. The problem is that I know how to code the basic lua logic, but I don't know how to code BeamNG lua. It's not clear to me, and I'm not using that outdated wiki again.