Hello, I need to make a race, I started by placing checkpoints through the loop, but I ran into the fact that I do not understand how to correctly delete a checkpoint and then create a new one after the car has passed through the marker
I'm newbie, 3 days in lua and I don't know English well, so I use a translator when creating a topic
Code:
function checkpointHit(hitElement, matchingDimension)
if getElementType(hitElement)=="vehicle" then
return true
end
end
function Racing( thePlayer )
local x,y,z = getElementPosition(thePlayer) -- получаем позицию игрока
x = x - 2 -- прибавляем число 5 к позиции по оси x
local RaceVehicle = createVehicle ( 411, x, y, z ) -- create a vehicle.
z, y, x = getElementRotation(RaceVehicle)
setElementRotation ( RaceVehicle, z,y,x+180)
warpPedIntoVehicle ( thePlayer, RaceVehicle )
local checkpoints = {
{ -316.20703125, 1398.3125, 71.81689453125 },
{ -410.787109375, 1697.8046875, 39.512222290039 }
}
for k,v in pairs( checkpoints ) do
local marker = createMarker ( v[1],v[2],v[3], 'checkpoint', 2.0, 209, 13, 13, 100 )
local blip = createBlipAttachedTo (marker, 0)
addEventHandler("onMarkerHit", marker, function(hitElement, matchingDimension)
if(checkpointHit(hitElement, matchingDimension) == true) then
destroyElement ( marker )
destroyElement( blip )
end
end)
end
end
addEventHandler("onMarkerHit", raceStart, function(thePlayer)
spawnPlayer(thePlayer, -303.2841796875, 1521.22265625, 75.359375)
fadeCamera(thePlayer, true)
setCameraTarget(thePlayer, source)
Racing(thePlayer)
end)