Hard Light Productions Forums

FreeSpace Releases => Scripting Releases => Topic started by: FelixJim on September 06, 2013, 04:21:17 pm

Title: Visible Waypoints Script
Post by: FelixJim on September 06, 2013, 04:21:17 pm
A really simple little script which shows up waypoints in-game that might be useful for FREDers. Or might not be; to be honest, having finished implementing it it now feels like one of those ' "Sounds useful!" *Uses for 10 minutes* "lol, no this just gets in the way." ' things. But it's finished now and it might as well be released in case anyone does find it useful.

Installation:

EITHER:

Download attached file to [mymod]\data\tables, and press "Alt-1" in-game to activate.

OR:

Create a text file vws-sct.tbm in [mymod]\data\tables and copy and paste the following code into it. Then press "Alt-1" in-game to activate.
Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$On Game Init:
[

vws = {} --Set up the global table for this script

vws.active = false --Start off with script inactive
vws.waypointradius = 20 --Radius of waypoints
vws.textbuffer = 5 --Spacing between waypoint and text
vws.key = "Alt-1" --Key pressed to (de)activate script

vws.waypointred = 128 --Red value of waypoint
vws.waypointgreen = 0 --Green value of waypoint
vws.waypointblue = 128 --Blue value of waypoint
vws.waypointalpha = 128 --Alpha value of waypoint

vws.linered = 128 --Red value of lines
vws.linegreen = 0 --Green value of lines
vws.lineblue = 128 --Blue value of lines
vws.linealpha = 128 --Alpha value of lines

vws.textred = 128 --Red value of lines
vws.textgreen = 0 --Green value of lines
vws.textblue = 128 --Blue value of lines
vws.textalpha = 255 --Alpha value of lines

]

$Application: FS2_Open
$On Key Pressed:
[

if hv.Key == vws.key then
vws.active = not vws.active
end

]

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

local vws = vws --Get a local handle on the global table to speed up access

if vws and vws.active then --If the script is active

local wplists = mn.WaypointLists --Local version of waypoint lists
local wplist --Current waypoint list
local listname --Name of current waypoint list
local num --Number of waypoints in the list
local wp --Current waypoint
local wpname --Current waypoint name
local nextwp --Next waypoint
local pos, nextpos --Positions of waypoints
local plrpos = hv.Player.Position --Player position
local dist --Distance between player and waypoint
local x, y --Screen coords of current waypoint
local nextx, nexty --Screen coords of next waypoint
local namex, namey --Screen coords for name text
local distx, disty --Screen coords for distance text

for i=1,#wplists do --For each waypoint list

wplist = wplists[i]
listname = wplist.Name
num = #wplist

for j=1,num do --For each waypoint

wp = wplist[j] --Waypoint
nextwp = wplist[j+1] --Next waypoint

--Get waypoint positions
pos = wp.Position
nextpos = nextwp.Position

--Get screen coords
x, y = pos:getScreenCoords()
nextx, nexty = nextpos:getScreenCoords()

--Draw waypoint
if x then
gr.setColor(vws.waypointred, vws.waypointgreen, vws.waypointblue, vws.waypointalpha)
gr.drawSphere(vws.waypointradius, wp.Position)
end

--Draw line between this and next waypoint (unless this is the last waypoint)
if x and nextx and j ~= num then
gr.setColor(vws.linered, vws.linegreen, vws.lineblue, vws.linealpha)
gr.drawLine(x, y, nextx, nexty)
end

--Get waypoint name, distance and text position, and then draw it
if x then

wpname = listname..": "..j --Name
namex = x - gr.getStringWidth(wpname)/2 --Get the string's x position
namey = y - vws.waypointradius - vws.textbuffer --Get the string's y position

dist = math.floor(pos:getDistance(plrpos)+0.5) --Get distance of waypoint from player
dist = "Distance: "..dist --Turn into a string
distx = x - gr.getStringWidth(dist)/2 --Get the string's x position
disty = y + vws.waypointradius + vws.textbuffer --Get the string's y position

gr.setColor(vws.textred, vws.textgreen, vws.textblue, vws.textalpha) --Set the colour
gr.drawString(wpname, namex, namey) --Draw the name text
gr.drawString(dist, distx, disty) --Draw the distance text

end

end

end

end

]

$Application: FS2_Open
$On Mission End:
[

vws.active = false --Stops the waypoints showing up during the loading screen after a mission restart; delete this line if you don't care about this and want the script always on

]

#End

Near the beginning are some options which should be simple enough for you to figure out if you want to tweak things.

[attachment deleted by ninja]
Title: Re: Visible Waypoints Script
Post by: X3N0-Life-Form on September 07, 2013, 05:05:13 pm
Guess I won't need to place nav buoys on dynamic waypoints anymore. Thanks :)
Title: Re: Visible Waypoints Script
Post by: FelixJim on September 08, 2013, 04:19:12 am
I completely forgot we had dynamic waypoints! If you or someone else could get back to me on whether this script plays nicely with them (it should, but that's not always the same as does) that would be great. I tried to test it myself just now and couldn't get any of the sexps to do anything (except crash FSO once), so I must be doing something wrong.