• Dear visitors,

    The email issue has been finally solved.
    Thank you for your patience and happy browsing.

    Team ACM.

How to make a simple countdown apps (lua)?

vv31212

New Member
Code:
Countdown = ui.MediaPlayer('sounds/countdown.mp3')
function script.startingSequence(dt)

    if not INI.countdown then return end
    if (SIM.isPaused or SIM.isInMainMenu) and Countdown then
        Countdown:pause()
    end

    local centery = ac.getUI().windowSize.y / 2
    local centerx = ac.getUI().windowSize.x / 2
    local textToWrite = math.floor(SIM.timeToSessionStart / 1000) + 1
    local firstCount = (SIM.timeToSessionStart / 1000 + 1) % 1

    if textToWrite > 3 or textToWrite < 1 then return end

    if textToWrite == 3 and INI.countdownSound then
        Countdown:setVolume(ac.getAudioVolume(ac.AudioChannel.Main) * (INI.countdownSoundMulti + 0.35))
        Countdown:play()
    end

    ui.setCursor(vec2(centerx - scale(240), centery - scale(240)))
    ui.image('img/countdown-stripes.png', scaledVec2(480, 480), rgbm.colors.white)
    local easeInValue = inSine(firstCount * 1000, 0, 1, 1000)
    local easeOutValue = outInSine(firstCount * 1000, 0, 1, 1000)

    if firstCount > 0.5 then
        ui.pathArcTo(vec2(centerx, centery), scale(240 - (12 / 2)),
            getAngle(0),
            getAngle(360 - 360 * (((easeInValue - 0.5) / 0.5 * 1))), 80)
    else
        ui.pathArcTo(vec2(centerx, centery), scale(240 - (12 / 2)),
            getAngle(360 - 360 * easeOutValue / 0.5 * 1),
            getAngle(360), 80)
    end
    ui.pathStroke(rgbm.colors.white, false, scale(12))
    ui.pushDWriteFont('Arkitech:\\fonts;Weight=Regular')
    ui.setCursor(vec2(centerx - scale(400), centery - scale(240)))

    ui.dwriteTextAligned(textToWrite, scale(160), ui.Alignment.Center, ui.Alignment.Center,
        scaledVec2(800, 480), false, rgbm.colors.white)
    ui.popDWriteFont()

end

AnimTimer = 0

local CarDimToAdd = vec2(CAR.aabbSize.x / 2, CAR.aabbSize.y * 1.4)
local waitingPosS1 = vec3(-2 - CarDimToAdd.x, 1, 1.5 + CarDimToAdd.y)
local waitingPosE1 = vec3(-2 - CarDimToAdd.x, 1, 3 + CarDimToAdd.y)
local waitingPosS2 = vec3(-1 - CarDimToAdd.x, 1, -3 - CarDimToAdd.y)
local waitingPosE2 = vec3(1 + CarDimToAdd.x, 0.4, -3 - CarDimToAdd.y)
local waitingPosS3 = vec3(-1 - CarDimToAdd.x, 1, 3 + CarDimToAdd.y)
local waitingPosE3 = vec3(1 + CarDimToAdd.x, 0.4, 3 + CarDimToAdd.y)


function countdownCamera(dt)

    if SIM.isPaused or SIM.isInMainMenu then
        if CameraMotion then
            CameraMotion.transform = CameraMotion.transformOriginal
            CameraMotion:dispose()
        end
        INITCAM = false
        ACTIVECAMERAPOINT = 0
        return
    end
    if SIM.timeToSessionStart < -2000 then return end
    if SIM.timeToSessionStart > 19000 then
        INITCAM = false
        ACTIVECAMERAPOINT = 0
        return
    end
    if CAR.isInPit and CameraMotion then
        if CameraMotion then
            CameraMotion.transform = CameraMotion.transformOriginal
            CameraMotion:dispose()
        end
        return
    end


    if not INITCAM then
        if CameraMotion then CameraMotion:dispose() end
        CameraMotion = ac.grabCamera('starting anim')
        INITCAM = true
    end

    if SIM.timeToSessionStart > 0 and ACTIVECAMERAPOINT == 0 then
        ACTIVECAMERAPOINT = 4
        AnimTimer = SIM.timeToSessionStart / 1000 - 3
    end


    if ACTIVECAMERAPOINT == 1 then
        if AnimTimer > 0 then
            AnimTimer = AnimTimer - dt
            if CameraMotion then
                local localPos = math.lerp(waitingPosS1, waitingPosE1, (1 - AnimTimer))
                CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
                CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
                CameraMotion.transform.up = vec3(0, 1, 0)
            end
        else
            ACTIVECAMERAPOINT = 2
            AnimTimer = 1
        end
    end

    if ACTIVECAMERAPOINT == 2 then cameraTransition(dt, waitingPosS2, waitingPosE2, 3) end
    if ACTIVECAMERAPOINT == 3 then cameraTransition(dt, waitingPosS3, waitingPosE3, 4) end

    if ACTIVECAMERAPOINT == 4 then
        if AnimTimer > 0 then
            AnimTimer = AnimTimer - dt / 1
            if CameraMotion then
                local localPos = waitingPosE3
                CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
                CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
                CameraMotion.transform.up = vec3(0, 1, 0)
                CameraMotion.ownShare = math.smoothstep(math.lerpInvSat(AnimTimer, 0, 1))
            end

        else
            ACTIVECAMERAPOINT = 0
            CameraMotion:dispose()
        end
    end
end

function cameraTransition(dt, startPos, endPos, nextPoint)

    if AnimTimer > 0 then
        AnimTimer = AnimTimer - dt

        if CameraMotion then
            local localPos = math.lerp(startPos, endPos, (1 - AnimTimer) ^ 0.4)
            CameraMotion.transform.position = CAR.transform:transformPoint(localPos)
            CameraMotion.transform.look = -CAR.transform:transformVector(localPos)
            CameraMotion.transform.up = vec3(0, 1, 0)
        end
    else
        ACTIVECAMERAPOINT = nextPoint
        AnimTimer = 1
    end
function physics.engageGear(carIndex, gearToEngage)
physics.awakeCar(0)
physics.engageGear(0, 1)
awakeFor = awakeFor + 5
end


I notice that Lua apps can get the exact starting time(SIM.timeToSessionStart), How I use it to make a simple app that let car auto gear up when race starts? anyone can teach me how to use both function?
 
Last edited:

fughettaboutit

aka leBluem aka Please Stop This
Code:
if physics.allowed() then
   physics.engageGear(0, 1)
else
  ac.debug("Extendend Physics not enabled", "for this car")
end
 

fughettaboutit

aka leBluem aka Please Stop This
Code:
local sim = ac.getSim()
local startDone = false
local SessionSwitched = true
local previousSessionStartTimer = sim.sessionTimeLeft-0.002

function script.update(dt)
    -- do only once after racestart
    if not startDone and sim.timeToSessionStart<=0.0 then
        startDone = true
        -- do your stuff here
        if physics.allowed() then
           physics.engageGear(0, 1)
        else
          ac.debug("Extendend Physics not enabled", "for this car")
        end
    end

    -- to reset
    if previousSessionStartTimer < sim.sessionTimeLeft then
        startDone = false
        SessionSwitched = true
    elseif SessionSwitched then
        SessionSwitched = false
    end
    previousSessionStartTimer = sim.sessionTimeLeft-0.002
end
 
Last edited:

fughettaboutit

aka leBluem aka Please Stop This
actually no idea if
sim.timeToSessionStart
is what you want to check
ok, its in ms and goes below 0 after green

edit: tested that code just now and happy it just works (copied together from examples)
 
Last edited:

vv31212

New Member
Code:
[ABOUT]
NAME = start
AUTHOR =
VERSION =
DESCRIPTION =
URL =

[CORE]
LAZY = FULL

[WINDOW_...]
ID = main
NAME = start
ICON =
FUNCTION_MAIN = windowMain
FUNCTION_ON_HIDE = onHideWindowMain
FLAGS = FIXED_SIZE
SIZE = 250, 140
the code i post here are copied from gt7 lua.

how to combine yours and gt7's to make it work? I copied your code into a lua file with manifest.ini and only got blank
 
Last edited:
Top