Hi there. I was trying to make a mod for the ai that adds personalities for the ai drivers Normal: Drives normally, obeying the speed limit and with experience. Rarely causes accidents. Elderly/Beginner: Drives very slowly and has difficulty parking and maneuvering. Often causes minor accidents, such as fender benders, due to inexperience. Karen: Drives slightly over the speed limit, tends to get very angry, cuts off other drivers, and drives recklessly. Often causes moderate accidents and always flees if it is their fault. Aggressive 1: Always exceeds the speed limit and drives recklessly. They are inexperienced and can cause serious accidents. They also often weave through traffic and avoid traffic jams by driving on the wrong side of the road. Aggressive 2: Always exceeds the speed limit and drives recklessly. They are very experienced and don't cause accidents, but they do cause a few scares. They also tend to weave through traffic and avoid traffic jams by driving on the wrong side of the road. The thing is that I need help with the code. Ik this may seem stupid if you are an experienced modder, but I'm not the most skilled one... This is the code I wrote [KEEP IN MIND THAT STRUCTURE VARIATES FROM NOTEPAD++ TO HERE] -- Define AI personalities local personalities = { "aggressive", "defensive", "normal" } -- Function to initialize AI personalities for vehicles local function onAIInit(vehicle) -- Add AI personality based on a random choice local personality = personalities[math.random(#personalities)] vehicle.AI_Personality = personality print("AI Personality assigned: " .. personality) -- Set a base speed and behavior vehicle:setThrottle(1) -- Full speed for demonstration -- Start behavioral updates checkAIBehaviors(vehicle) end -- Function to check AI behaviors based on the personality local function checkAIBehaviors(vehicle) local personality = vehicle.AI_Personality if personality == "aggressive" then aggressiveBehavior(vehicle) elseif personality == "defensive" then defensiveBehavior(vehicle) else normalBehavior(vehicle) end end function aggressiveBehavior(vehicle) -- Simple aggressive behavior, maintaining high speed, -- and attempting to overtake other vehicles vehicle:setThrottle(1) -- Full throttle -- Logic to find nearby vehicles local nearbyVehicles = findNearbyVehicles(vehicle) for _, otherVehicle in ipairs(nearbyVehicles) do if otherVehicle ~= vehicle then -- Logic to cut off other vehicles if vehicle:getSpeed() > otherVehicle:getSpeed() then vehicle:setSteering(-1) -- Steer left, example end end end end function defensiveBehavior(vehicle) -- Defensive behavior, maintaining safe speed and distance vehicle:setThrottle(0.5) -- Half throttle -- Logic to slow down when close to other vehicles local nearbyVehicles = findNearbyVehicles(vehicle) for _, otherVehicle in ipairs(nearbyVehicles) do if otherVehicle ~= vehicle then if vehicle:getDistance(otherVehicle) < 20 then -- 20 meters as an example vehicle:setThrottle(0.2) -- Slow down end end end end function normalBehavior(vehicle) -- Normal behavior, maintaining a balanced speed vehicle:setThrottle(0.7) -- Maintain a decent speed end function findNearbyVehicles(vehicle) local nearbyVehicles = {} local position = vehicle:getPosition() -- Check a certain radius (e.g., 100 meters) for other vehicles local radius = 100 for _, otherVehicle in pairs(be:getAllVehicles()) do if otherVehicle ~= vehicle then local otherPos = otherVehicle:getPosition() local distance = (position - otherPos):length() if distance <= radius then table.insert(nearbyVehicles, otherVehicle) end end end return nearbyVehicles end -- Hook into the AI initialization event addEventHandler('AI.onInit', function(vehicle) onAIInit(vehicle) end) ------------------------------------------------------------------------------------------------------------------------------------------------------------------- Ik know this may seem STUPID but I need help pls.
i have some things like: Street Racer - Always has some sort of sporty car and tries to race with you, gets mad if he loses. Reckless - A driver who runs red lights and doesn't use turn signals, also goes a little bit off the speed limit. Careless - A driver who does noy have any care in the world, speeds all the time. Road Rager - Gets mad at speeders and cuts them off to try and "teach the them a lesson". --- Post updated --- Gets mad if you bump them.
one new one that i came up with Civilian Police - Acts like BeamNG Police. Drunk - Swerves across the road and runs red lights most of the time. New - A little bit off the speed limit and sometimes doesn't use turn signals sometimes.
Ok! I'll add them. But I think that's a bit too much for first release. I'll put the in next update maybe --- Post updated --- But the thing is, I can't get the script to work... I can't figure it out...