Script - Velocity Indicator

From FreeSpace Wiki
Jump to: navigation, search

Revised script which draws indicator to mark the true direction of the flight.

Table Entry

#Conditional Hooks

$Application: FS2_Open
$State: GS_STATE_GAME_PLAY
$On Frame:

[

drawvelret = function(x, y)
   gr.drawGradientLine(x+10,y+10,x+2,y+2)
   gr.drawGradientLine(x-10,y+10,x-5,y+2)
   gr.drawGradientLine(x+10,y-10,x+2,y-2)
   gr.drawGradientLine(x-10,y-10,x-2,y-2)
end

-- get mission time
if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

-- if the time is valid
if missiontime ~= nil then
   -- if we are actually doing something
   missiontime = mn.getMissionTime()

   -- only continue if the time actually progresses
   if oldmissiontime ~= missiontime then
      plr = hv.Player

      -- only continue if we can get valid player handle
      if plr:isValid() then
         local velocity = plr.Physics.Velocity
         local vlenght = velocity:getMagnitude()

         -- if we actually some velocity...
         local vvector = plr.Position + (velocity/(vlenght/2000))
         if vlenght > 5 then
            local x
            local y
            x, y = vvector:getScreenCoords()

            -- ok... so now we have the projected velocity vector
            -- if it actually is on screen then draw it
            if x ~= false then
               gr.setColor(100,100,255,160)
               drawvelret(x, y)
            end
         end
      end
   end

   -- make sure oldmissiontime is incremented
   oldmissiontime = missiontime
end

]

#End