Hello, i am trying to make a simple rally stage mod where you create 2 markers, one for start and one for finish, that part is good, but i am trying to make a timer start when you pass the start marker and stop counting when you pass the finish marker, then it should print the time in chat.
I started lua scripting today and used a bit of GPT just because all i knew was Java, so basically when i pass the start marker the Stage Started message doesn't show up, so i guess i am not getting the player position correctly maybe? not sure.
The only code not inserted here are 3 functions to create the start, the finish and to clear all markers, so i guess is not needed.
function checkStageProgress(player)
if not startMarker or not finishMarker then
return
end
local startX, startY, startZ = getElementPosition(startMarker)
local finishX, finishY, finishZ = getElementPosition(finishMarker)
local playerX, playerY, playerZ = getElementPosition(player)
local distanceToStart = getDistanceBetweenPoints2D(startX, startY, playerX, playerY)
if not raceInProgress and distanceToStart <= 3 then
raceInProgress = true
startTime = getTickCount() -- Start counting time
outputChatBox("Stage started!", player)
end
if raceInProgress then
local elapsedTime = (getTickCount() - startTime) / 1000
outputChatBox("Stage time: " .. elapsedTime .. " seconds.", player)
end
if raceInProgress and isElementWithinMarker(player, finishMarker) then
local elapsedTime = (getTickCount() - startTime) / 1000
outputChatBox("Stage finished! Time: " .. elapsedTime .. " seconds.", player)
raceInProgress = false
end
end