generateOpponentsGroup
Definition
-- @/lua/ge/extensions/gameplay/drag/dragBridge.lua:197
M.generateOpponentsGroup = function(vehId, dial, vehiclePermissionRules, amount, offset)
if not vehId then
log("E", logTag, "Invalid input parameters")
return
end
amount = amount or 1
offset = offset or 0.5
local configs = core_vehicles.getConfigList()
local vehicleDetails = core_vehicles.getVehicleDetails(vehId)
if not vehicleDetails then
log("E", logTag, "Could not find vehicle details for ID: " .. tostring(vehId))
return
end
if not vehicleDetails.configs["Drag Times"] then
log("E", logTag, "Vehicle has no drag times data")
return
end
local quarterMileScore = dial or vehicleDetails.configs["Drag Times"].time_1_4 or 10
local minTime = quarterMileScore - offset
local maxTime = quarterMileScore + 0.1
local eligibleVehicles = {}
local eligibleCount = 0
for _, config in pairs(configs.configs) do
if config["Drag Times"] and config["Drag Times"].time_1_4 and config["Drag Times"].time_1_4 >= minTime and config["Drag Times"].time_1_4 < maxTime then
local model = core_vehicles.getModel(config.model_key).model
if checkVehiclePermission(model, vehiclePermissionRules) and not string.match(config.key, 'simple_traffic') then
eligibleCount = eligibleCount + 1
eligibleVehicles[eligibleCount] = config
end
end
end
if eligibleCount == 0 then
eligibleVehicles[1] = vehicleDetails
eligibleCount = 1
end
math.randomseed(os.time())
local opponentsGroup = {}
for i = 1, amount do
local selectedConfig = eligibleVehicles[math.random(eligibleCount)]
local paints = tableKeys(tableValuesAsLookupDict(core_vehicles.getModel(selectedConfig.model_key).model.paints or {}))
local paintCount = #paints
table.insert(opponentsGroup, {
model = selectedConfig.model_key,
config = selectedConfig.key,
paint = paintCount > 0 and paints[math.random(paintCount)] or nil,
})
end
return opponentsGroup
end
Callers