Jump to content

DCS stats from water, road, land, how to ?


Jexmatex

Recommended Posts

Hello guys, 

 

I have modified a time trial mission from the f-14 bundle to use it with choppers, it works fine.

Actually, as in original mission, the aircraft is supposed to stay the most over water, river in this case.

The idea is interesting but i want to do the same over road and i cannot find any instruction on this

 

below the code i use, we can see some stats = waterTime

where in the documentation can i find a list of available choice ?

obviously i have tried roadTime but it doesn't work

 

i also use this script with mist.lua but there is no water or land thinggy in it.

 

any idea ?

 

do
    local pObj = Unit.getByName('Uh-1')
    local stats = {waterTime = 0, landTime = 0, agl = 0, vel = 0}
    local pUpdateRate = 0.5 
    local startLine = mist.getGroupPoints('SL')
    local finishLine = mist.getGroupPoints('FL')
    local raceArea = mist.getGroupPoints('track')
    local zone = trigger.misc.getZone('checkFastNow')
    local endZone = trigger.misc.getZone('endZone')
    
    local active = false
    local doOnce = false
    
    local function reset()
        pObj = Unit.getByName('Uh-1')
        if pObj and pObj:getLife() > 15 then 
            stats = {waterTime = 0, landTime = 0, agl = 0, vel = 0}
            active = false
            doOnce = false
            trigger.action.outText('Stats have been reset, you may restart the race at anypoint by going through the start gate.', 20)
        else
            timer.scheduleFunction(reset, {}, timer.getTime() + 5)
        end
    end
    
    local function getTimeDisplay(tTime)
        --env.info('time display: ' .. tTime)
        local hh, mm, ss, dd, _b = 0 , 0 , 0 , 0, 0
        hh = math.modf(tTime/3600)
        mm = math.modf(tTime/60)
        ss = tTime%60
        _b, dd = math.modf(ss)
       -- env.info('HH : '  .. hh .. '  MM : ' .. mm .. '  SS : ' .. ss)
        return string.format('%02d:%02d:%02d.%03d', mist.utils.round(hh, 0), mist.utils.round(mm, 0), mist.utils.round(ss, 0), dd*1000)
        
    end
    local function displayStats()
        env.info('display stats')
--      local penalty = mist.utils.round(stats.landTime * 5, 0)
        local penalty = mist.utils.round(stats.landTime * 1, 5)

        local desc = pObj:getDesc()
        local msg = {}
        msg[#msg+1] = pObj:getPlayerName()
        msg[#msg+1] = '\n ============================================================== \n'
        msg[#msg+1] = 'Total Time: '
        msg[#msg+1] = getTimeDisplay(stats.endTime - stats.startTime)
        msg[#msg+1] = '\nEstimated Time Over Water: '
        msg[#msg+1] = getTimeDisplay(stats.waterTime)
        msg[#msg+1] = '\nEstimated Time Over Land: '
        msg[#msg+1] = getTimeDisplay(stats.landTime)
        msg[#msg+1] = '\nLand Penalty: '
        msg[#msg+1] = penalty
        msg[#msg+1] = '\nTotal Time With Penalties: '
        msg[#msg+1] = getTimeDisplay(stats.endTime - stats.startTime + penalty)
        
        msg[#msg+1] = '\n ============================================================== \n '
        msg[#msg+1] = ' Average Altitude AGL : '
        msg[#msg+1] = mist.utils.round(stats.agl, 3)
        msg[#msg+1] =  ' meters / '
        msg[#msg+1] = mist.utils.round(mist.converter('m', 'feet', stats.agl), 3)
        msg[#msg+1] = ' feet \n'
        

        msg[#msg+1] = ' Average Velocity : '
        msg[#msg+1] = mist.utils.round(stats.vel, 3)
        msg[#msg+1] =  ' mps / '
        msg[#msg+1] = mist.utils.round(mist.converter('mps', 'knot', stats.vel), 3)
        msg[#msg+1] = ' knots \n'
        
        msg[#msg+1] = ' Fuel Used  : '
        msg[#msg+1] = mist.utils.round((stats.startFuel - stats.endFuel)*desc.fuelMassMax*2.20462, 2)
        msg[#msg+1] = ' lbs \n Fuel Remaining : '
        msg[#msg+1] = mist.utils.round((stats.endFuel)*desc.fuelMassMax*2.20462, 2)
        msg[#msg+1] = ' lbs'
        trigger.action.outText(table.concat(msg), 120)
    end
    local lastCheck = timer.getAbsTime() 
    local function statsCollect(pos)
        local timeDif = timer.getAbsTime() - lastCheck
        if pObj:isExist() == true and stats.startTime and active == true then
            if land.getSurfaceType({x = pos.x, y = pos.z}) == 3 then
                stats.waterTime = stats.waterTime + timeDif
            else
                stats.landTime = stats.landTime + timeDif
            end
            --stats.agl[#stats.agl+1] = pos.y - land.getHeight({x = pos.x, y = pos.z})
            if timer.getAbsTime() > lastCheck + 0.1 then 
                if stats.agl == 0 then
                    stats.agl = pos.y - land.getHeight({x = pos.x, y = pos.z})
                else
                    stats.agl = (stats.agl + (pos.y - land.getHeight({x = pos.x, y = pos.z})))/2
                end
                
                --stats.vel[#stats.vel+1] = mist.vec.mag(pObj:getVelocity())
                if stats.vel == 0 then 
                    stats.vel = mist.vec.mag(pObj:getVelocity())
                else
                    stats.vel = (stats.vel + mist.vec.mag(pObj:getVelocity()))/2
                end
                
            end    
            lastCheck = timer.getAbsTime()

        end
        return
    end
    local function main()
        if pObj and pObj:isExist() == true then 
            local pos =  pObj:getPosition().p

            if pos then 
                if active == false then
                   
                    if mist.utils.get2DDist(zone.point, pos) < zone.radius then
                       -- trigger.action.outText('Checking Zone', 5, true)
                        if mist.pointInPolygon(pos, startLine) == true and mist.pointInPolygon(pos, raceArea) == true then
                            pUpdateRate = 0.01
                            active = true
                            stats.startTime = timer.getAbsTime()
                            stats.startFuel = pObj:getFuel()
                            trigger.action.outText('Race Start now !', 5, true)
                        end
                    end
                else
                    statsCollect(pos)
                    if mist.utils.get2DDist(endZone.point, pos) < endZone.radius then
                        if mist.pointInPolygon(pos, finishLine) == true and mist.pointInPolygon(pos, raceArea) == true then
                            active = false
                            stats.endTime = timer.getAbsTime()
                            stats.endFuel = pObj:getFuel()
                            pUpdateRate = 1
                            trigger.action.setUserFlag('1', true)
                            displayStats()
                        end
                    end
                end
              --  env.info(pObj:getLife())
                if pObj:getLife() < 15 then 
                    pUpdateRate = 0.5
                    if doOnce == false then
                       -- trigger.action.outText('The timing script is no longer tracking your aircraft. You are probably dead. You should respawn.', 30)
                        doOnce = true
                    end
                    timer.scheduleFunction(reset, {}, timer.getTime() + 5)
                end
            end
        else

            pUpdateRate = 0.5
            if doOnce == false then
               -- trigger.action.outText('The timing script is no longer tracking your aircraft. You are probably dead. You should respawn.', 30)
                doOnce = true
            end
            timer.scheduleFunction(reset, {}, timer.getTime() + 5)
                
        end
        timer.scheduleFunction(main, {}, timer.getTime() + pUpdateRate)
    end
    main()
    missionCommands.addCommand('Reset Stats/Race', nil, reset)
end

 


Edited by Jexmatex
Link to comment
Share on other sites

  • Jexmatex changed the title to DCS stats from water, road, land, how to ?

If you wanted something a bit more all encompassing you could just save the time spent over each surface type. Then do the math whenever you need to evaluate the data. For those time trial missions I just used the water as the only thing that mattered to differentiate the times for. 

 

 

local sType = land.getSurfaceType({x = pos.x, y = pos.z}) then
if not stats[sType] then
  stats[sType] = 0
end
stats[sType] = stats[sType] + timeDif

 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

On 6/11/2021 at 11:46 PM, toutenglisse said:

 

Surface type check is in this line of your script :

 

 


if land.getSurfaceType({x = pos.x, y = pos.z}) == 3 then

 

Replace 3 (water) by 4 and it will check time passed above road. ( function variables here DCS func getSurfaceType - DCS World Wiki - Hoggitworld.com )

worked perfectly ! thank you very much !

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...