Difference between revisions of "Script - Velocity Indicator"
From FreeSpace Wiki
m (→Notes) |
m (header) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | + | Revised script which draws indicator to mark the true direction of the flight. | |
| − | |||
==Table Entry== | ==Table Entry== | ||
| − | + | * In [[Modular Tables|modular]] [[Scripting.tbl|scripting]] table file | |
| + | ** For example: '''vel_ind-sct.tbm''' | ||
| − | $ | + | <pre>#Conditional Hooks |
| + | |||
| + | $Application: FS2_Open | ||
| + | $State: GS_STATE_GAME_PLAY | ||
| + | $On Frame: | ||
[ | [ | ||
drawvelret = function(x, y) | drawvelret = function(x, y) | ||
| − | gr.drawGradientLine(x+ | + | gr.drawGradientLine(x+10,y+10,x+2,y+2) |
| − | gr.drawGradientLine(x- | + | gr.drawGradientLine(x-10,y+10,x-5,y+2) |
| − | gr.drawGradientLine(x+ | + | gr.drawGradientLine(x+10,y-10,x+2,y-2) |
| − | gr.drawGradientLine(x- | + | gr.drawGradientLine(x-10,y-10,x-2,y-2) |
| − | + | end | |
| − | + | ||
| − | + | -- get mission time | |
| − | + | 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 | ||
| − | + | -- 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 | ||
| − | |||
| − | |||
| − | |||
] | ] | ||
#End</pre> | #End</pre> | ||
| − | |||
| − | |||
| − | |||
[[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