-- cops_vs_robbers.lua
-- Place this file inside: assettocorsa/server/extension/lua/
local cops = {}
local robbers = {}
local busted = {}
-- Menu d'équipe
function script.update(dt)
for i = 0, ac.getCarCount() - 1 do
local car = ac.getCar(i)
if not cops[i] and not robbers[i] then
ui.begin("Choisissez votre équipe", true, WindowFlags.AlwaysAutoResize)
ui.text("Vous êtes : " .. car.name)
if ui.button("🚓 Rejoindre les flics") then
cops[i] = true
ac.setCarNameTag(i, "🚓 Police")
end
if ui.button("💨 Rejoindre les fuyards") then
robbers[i] = true
ac.setCarNameTag(i, "💨 Fuyard")
end
ui.endWindow()
end
end
-- Vérifier collisions
for i = 0, ac.getCarCount() - 1 do
if cops[i] then
local copCar = ac.getCar(i)
for j = 0, ac.getCarCount() - 1 do
if robbers[j] and not busted[j] then
local robberCar = ac.getCar(j)
if copCar:wasInContactWith(j) then
busted[j] = true
ac.setCarNameTag(j, "❌ Busté")
ac.sendChatMessage(string.format("💥 %s a été attrapé par %s!", robberCar.name, copCar.name))
end
end
end
end
end
-- Vérifier victoire
local remaining = 0
for i = 0, ac.getCarCount() - 1 do
if robbers[i] and not busted[i] then
remaining = remaining + 1
end
end
if remaining == 0 and tableLength(robbers) > 0 then
ac.sendChatMessage("🚨 Tous les fuyards ont été attrapés ! Victoire des flics !")
ac.setSessionOver()
end
end
function tableLength(t)
local count = 0
for _, _ in pairs(t) do count = count + 1 end
return count
end