[Feature] Rolling starts
WilliamGawlik opened this issue · 3 comments
HI William,
So a month back or so I was playing with chat gpt and ask it to make a lua script for rolling starts. I was just f-ing around with the AI. I also ask it to add in nascar rules like deploy pace car on yellow flags. It may be complete rubbish as I don't know lua and was just playing around. Anyway here it is as you obviously know lua. Sorry if this is a waste of time but if it helps that's cool too.
-- rollingStart.lua
local startingGrid = {}
local paceCar = nil
-- Initialize the starting grid and pace car
function init()
-- Get a reference to all of the cars on the starting grid
for i = 0, AC.getCarsCount() - 1 do
local car = AC.getCar(i)
if car.isPlayer then
paceCar = car
else
table.insert(startingGrid, car)
end
end
end
-- Start the race with a rolling start
function startRace()
-- Set the pace car to lead the starting grid
paceCar.setPosition(1)
paceCar.setVisible(true)
-- Set the other cars on the starting grid to follow the pace car
for i, car in ipairs(startingGrid) do
car.setPosition(i + 1)
car.setVisible(true)
end
-- Start the race countdown timer
AC.setCountdown(5)
end
-- Update the positions of the cars on the starting grid
function update(deltaTime)
-- Update the position of the pace car
local paceCarSpeed = paceCar.getSpeed()
if paceCarSpeed > 20 then
-- If the pace car is moving too fast, slow it down
paceCar.setSpeed(20)
elseif paceCarSpeed < 5 then
-- If the pace car is moving too slow, speed it up
paceCar.setSpeed(5)
end
-- Update the positions of the other cars on the starting grid
for i, car in ipairs(startingGrid) do
car.followCar(paceCar, 1)
end
end
-- Start the race when the countdown timer reaches zero
function onCountdownEnd()
-- Hide the pace car and release the other cars on the starting grid
paceCar.setVisible(false)
for i, car in ipairs(startingGrid) do
car.setControl(true)
end
end
-- Register callbacks
AC.register("init", init)
AC.register("update", update)
AC.register("onCountdownEnd", onCountdownEnd)
Yeah this isn't worth anything to me.
None of these functions are actually in the SDK: ac.register, ac.setCountdown, car.setPosition, car.followCar, car.setSpeed
While yes I can write some of the functionality myself, some of them are impossible without SDK support.
I kinda figured. But I thought before I trash the file maybe someone with knowledge of the subject should have a look.