Difference between revisions of "Script - Velocity Indicator"

From FreeSpace Wiki
Jump to: navigation, search
m
m (header)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==Function==
+
Revised script which draws indicator to mark the true direction of the flight.
Creates an additional reticle that points towards the real movement direction and also prints the actual velocity (length of the velocity vector to the screen)
 
  
 
==Table Entry==
 
==Table Entry==
<pre>#Global Hooks
+
* In [[Modular Tables|modular]] [[Scripting.tbl|scripting]] table file
 +
** For example: '''vel_ind-sct.tbm'''
  
$GameInit:
+
<pre>#Conditional Hooks
 +
 
 +
$Application: FS2_Open
 +
$State: GS_STATE_GAME_PLAY
 +
$On Frame:
  
 
[
 
[
  
 
drawvelret = function(x, y)
 
drawvelret = function(x, y)
   gr.drawGradientLine(x+20,y+20,x+5,y+5)
+
   gr.drawGradientLine(x+10,y+10,x+2,y+2)
   gr.drawGradientLine(x-20,y+20,x-5,y+5)
+
   gr.drawGradientLine(x-10,y+10,x-5,y+2)
   gr.drawGradientLine(x+20,y-20,x+5,y-5)
+
   gr.drawGradientLine(x+10,y-10,x+2,y-2)
   gr.drawGradientLine(x-20,y-20,x-5,y-5)
+
   gr.drawGradientLine(x-10,y-10,x-2,y-2)
  gr.drawGradientLine(x,y,x+6,y+6)
+
end
  gr.drawGradientLine(x,y,x+6,y-6)
+
 
   gr.drawGradientLine(x,y,x-6,y+6)
+
-- get mission time
   gr.drawGradientLine(x,y,x-6,y-6)
+
if missiontime == nil then
 +
   missiontime = mn.getMissionTime()
 +
   oldmissiontime = missiontime
 
end
 
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
  
$HUD:
+
      -- 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()
  
position = plr.Position
+
            -- ok... so now we have the projected velocity vector
velocity = plr.Velocity
+
            -- if it actually is on screen then draw it
vlenght = velocity:getMagnitude()
+
            if x ~= false then
vvector = position + (velocity/(vlenght/2000))
+
              gr.setColor(100,100,255,160)
 +
              drawvelret(x, y)
 +
            end
 +
        end
 +
      end
 +
  end
  
gr.setColor(230,230,100,255)
+
  -- make sure oldmissiontime is incremented
if vvector:getScreenCoords() ~= false and vlenght > 5 then
+
   oldmissiontime = missiontime
   X, Y = vvector:getScreenCoords()
 
  drawvelret(X, Y)
 
 
end
 
end
 
gr.drawString("True Velocity:",435,750)
 
gr.drawString(math.floor(vlenght),575,750)
 
  
 
]
 
]
  
 
#End</pre>
 
#End</pre>
 
==Notes==
 
Current version is meant for 1024 x 768 resolution. Final position of the '''True Velocity:  xxx''' gauge is yet to be determined.
 
  
 
[[Category:Scripting Examples|Velocity Indicator]]
 
[[Category:Scripting Examples|Velocity Indicator]]

Latest revision as of 19:32, 18 April 2010

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