Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: The E on January 22, 2010, 06:37:58 pm

Title: EScort Reticle script
Post by: The E on January 22, 2010, 06:37:58 pm
ChronoReverse tried to revamp the Escort reticle script found on the wiki (http://www.hard-light.net/wiki/index.php/Script_-_Escort_Reticle). Unfortunately, he met with little success. I gave it a try, modified his original, and came up with this:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init:
[

escortReticle = function(x1, y1, name)
   gr.drawGradientLine(x1, y1+36, x1+8, y1+24)
   gr.drawGradientLine(x1, y1+36, x1-8, y1+24)
   gr.drawGradientLine(x1+24, y1, x1+16, y1+12)
   gr.drawGradientLine(x1-24, y1, x1-16, y1+12)
   gr.drawGradientLine(x1, y1-36, x1+8, y1-24)
   gr.drawGradientLine(x1, y1-36, x1-8, y1-24)
   gr.drawGradientLine(x1+24, y1, x1+16, y1-12)
   gr.drawGradientLine(x1-24, y1, x1-16, y1-12)
   gr.drawString(name,x1-36,y1+48)
end

]

$On HUD Draw:
[

missiontime = mn.getMissionTime()
if missiontime > 0.5 then
if mn.EscortShips ~= nil then
NumberEscorted = #mn.EscortShips
for i= 1,NumberEscorted do
  escortedship = mn.EscortShips[i]
  X, Y = escortedship.Position:getScreenCoords()
  if escortedship.Position:getScreenCoords() ~= false and escortedship.Team.Name == "Hostile" then
 gr.setColor(255,50,50,255)
 escortReticle(X, Y, escortedship.Name)
  end
  if escortedship.Position:getScreenCoords() ~= false and escortedship.Team.Name == "Friendly" then
 gr.setColor(0,255,0,255)
 escortReticle(X, Y, escortedship.Name)
  end
  if escortedship.Position:getScreenCoords() ~= false and escortedship.Team.Name == "Unknown" then
 gr.setColor(255,255,0,255)
 escortReticle(X, Y, escortedship.Name)
  end
end
end
end

]

#End

This doesn't work, instead the following error is spawned:
Code: [Select]
__indexer: Argument 1 is an invalid type 'userdata'; number expected

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name: (null)
Name of: (null)
Function type: (null)
Defined on: 0
Upvalues: 0

Source: (null)
Short source:
Current line: 0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

1: Userdata [EscortShips]
2: Number [1.000000]
------------------------------------------------------------------

Any hints about what is going wrong here?
Title: Re: EScort Reticle script
Post by: Wanderer on January 23, 2010, 12:19:14 am
In lua.cpp line 9900 change

Change
Code: [Select]
-if(!ade_get_args(L, "i", &idx))
+if(!ade_get_args(L, "*i", &idx))

Second in the actual script, try using the gr.drawTargetingBrackets function
Title: Re: EScort Reticle script
Post by: ChronoReverse on January 23, 2010, 01:55:24 am
It works now!  Thanks a bunch. 
Title: Re: EScort Reticle script
Post by: Zacam on January 24, 2010, 04:29:28 am
So, what does the final script look like?
Title: Re: EScort Reticle script
Post by: The E on January 24, 2010, 08:40:50 am
Check the wiki. It's uploaded there.
Title: Re: EScort Reticle script
Post by: ChronoReverse on January 24, 2010, 03:06:54 pm
The E,

I'd like for the manually drawn reticule version of the script to be posted as well since it does demonstrate a few more useful things for reference.  Also, the original script wrote out the name of the escorted ship underneath the bracket which was an interesting trick.
Title: Re: EScort Reticle script
Post by: Zacam on January 24, 2010, 09:11:39 pm
And I, uh, don't actually see anything different going on with this scrip present vs when it's not.
Title: Re: EScort Reticle script
Post by: The E on January 25, 2010, 01:08:47 am
And I, uh, don't actually see anything different going on with this scrip present vs when it's not.

That seems to be a problem with the mn.EscortShips list. It doesn't seem to get updated with the regular escortlist.

I'd like for the manually drawn reticule version of the script to be posted as well since it does demonstrate a few more useful things for reference.  Also, the original script wrote out the name of the escorted ship underneath the bracket which was an interesting trick.

The name thing I'll add back in, but the manual drawing stuff I will not. Why? Simply because it's way more efficient to use built-in functions than create your own. The only thing that that showed was how to declare functions, and that can be done elsewhere as well.

Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init:
[
drawReticle = function(ship)
if     ship.Team.Name == "Hostile"  then gr.setColor(255,50,50,255)
elseif ship.Team.Name == "Friendly" then gr.setColor(0,255,0,255)
elseif ship.Team.Name == "Unknown"  then gr.setColor(255,255,0,255)
end
local x
local y
local x1
local y1
x,y,x1,y1 = gr.drawTargetingBrackets(ship, true)
if x ~= nil and y1 ~= nil then gr.drawString(ship.Name, x, y1 + 4) end
end
]

$On HUD Draw:
[

if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if missiontime ~= nil then
if hu.HUDDrawn then
                if oldmissiontime ~= missiontime then
        if mn.EscortShips ~= nil then
        NumberEscorted = #mn.EscortShips
        for i= 1,NumberEscorted do
        escortedship = mn.EscortShips[i]
        if escortedship.Position:getScreenCoords() ~= false then
        drawReticle(escortedship)
        end
          end
        end
                 end
end
oldmissiontime = missiontime
end

]

#End
Title: Re: EScort Reticle script
Post by: Zacam on January 25, 2010, 02:19:52 am
I think you mean
Code: [Select]
$On HUD Draw:
[

if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if missiontime ~= nil then
if hu.HUDDrawn then
missiontime = mn.getMissionTime()
if oldmissiontime ~= missiontime then
        if mn.EscortShips ~= nil then
        NumberEscorted = #mn.EscortShips
        for i= 1,NumberEscorted do
        escortedship = mn.EscortShips[i]
        if escortedship.Position:getScreenCoords() ~= false then
        drawReticle(escortedship)
        end
          end
        end
end
end
oldmissiontime = missiontime
end

]
Title: Re: EScort Reticle script
Post by: The E on January 25, 2010, 02:41:14 am
Yes, I think I do.
Title: Re: EScort Reticle script
Post by: Zacam on January 25, 2010, 04:41:48 am
Additionally, this one will put ship name AND ship class just as if the ship was actually targeted. (Still working on displaying Hull Strength and Distance)

Just showing the part I changed to make that happen rather than the whole rest of the script.
Code: [Select]
if x ~= nil and y1 ~= nil then
gr.drawString(ship.Name, x1 +3, y)
gr.drawString(ship.Class.Name, x1 +3, y + 9)
Title: Re: EScort Reticle script
Post by: Aardwolf on January 25, 2010, 04:16:32 pm
In lua.cpp line 9900 change

Change
Code: [Select]
-if(!ade_get_args(L, "i", &idx))
+if(!ade_get_args(L, "*i", &idx))

Second in the actual script, try using the gr.drawTargetingBrackets function

Heehee! That's MY function!
Title: Re: EScort Reticle script
Post by: Nuke on January 26, 2010, 06:37:57 am
i found a couple errors like that in lua.cpp. cant remember what functions they were in, but i know my fixes got committed. its something to look out for when a lua function doesnt work.
Title: Re: EScort Reticle script
Post by: Zacam on January 30, 2010, 11:40:59 pm
Here is my current itteration, could probably use some work.

Displays along the upper-left bracket (on the inside) the following:
Ship Name
Ship Class
Hitpoints (based on percentage like the targeting information)
Distance.

The distance part could use the most help, as I want it to return the same distance as the standard targeting box (bottom left) but I haven't figured it out yet.

The -- lines are a different way of achieving distance calculations and would be used together (place a -- for the currently active line!)
Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Game Init:
[
drawReticle = function(ship)
if     ship.Team.Name == "Hostile"  then gr.setColor(255,50,50,255)
elseif ship.Team.Name == "Friendly" then gr.setColor(0,255,0,255)
elseif ship.Team.Name == "Unknown"  then gr.setColor(255,255,0,255)
end
local x
local y
local x1
local y1
plr = hv.Player
if plr:isValid() then
distance = ship.Position:getDistance(plr.Position)
-- collision_pos = ship:checkRayCollision(plr.Position, ship.Position, false)
-- distance = collision_pos:getDistance(plr.Position)
end
hippo_pct = math.floor((ship.HitpointsLeft / ship.Class.HitpointsMax) * 100)
x,y,x1,y1 = gr.drawTargetingBrackets(ship, true)
if x ~= nil and y1 ~= nil then
gr.drawString(ship.Name, x+3, y+2)
gr.drawString(ship.Class.Name, x+3, y+11)
gr.drawString(hippo_pct, x+3, y+20)
gr.drawString(distance, x+3, y+29)
end
end
]

$On HUD Draw:
[

if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if missiontime ~= nil then
if hu.HUDDrawn then
missiontime = mn.getMissionTime()
if oldmissiontime ~= missiontime then
         if mn.EscortShips ~= nil then
        NumberEscorted = #mn.EscortShips
        for i= 1,NumberEscorted do
        escortedship = mn.EscortShips[i]
         if escortedship.Position:getScreenCoords() ~= false then
        drawReticle(escortedship)
        end
         end
        end
end
end
oldmissiontime = missiontime
end

]

#End
Title: Re: EScort Reticle script
Post by: Enioch on February 01, 2010, 09:21:59 am
The distance issue is a known 'problem'. Distance in Scripting: Distance between centerpoints of ships. Distance in mission: Distance between closest polygons of ships.

Dunno if there is a solution.
Title: Re: EScort Reticle script
Post by: Wanderer on February 01, 2010, 01:25:31 pm
The distance issue is a known 'problem'. Distance in Scripting: Distance between centerpoints of ships. Distance in mission: Distance between closest polygons of ships.

Dunno if there is a solution.

Not actually between closest polygons... its wee bit more complicated than that... Its based on boundingbox limits or subsystems depending what is being targeted
Title: Re: EScort Reticle script
Post by: Spoon on June 26, 2012, 09:30:33 am
Warning: this topic has not been posted in for at least 30 days.
You don't say!


I've picked up on this old scripty and actually found it quite neat. It adds situational awareness for the player on what needs to be protected or destroyed.
But I have one thing I would like to see changed and I was wondering if anyone could help me with that.
http://imagebin.org/218460
As shown in this screenshot, this script displays everything that comes behind the #, can we make it not do this?
Title: Re: EScort Reticle script
Post by: m!m on June 26, 2012, 01:14:44 pm
Here you go:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$On Game Init:
[
function string.filterInvisible(str)
    local index = str:find("#", 0, true)

    if (index ~= nil) then
        str = str:sub(1, index - 1)
    end

    return str
end

function drawReticle(ship)
local r, g, b = ship.Team:getColor()
gr.setColor(r, g, b, 120)

local l, t, r, b = gr.drawTargetingBrackets(ship, true)

if l ~= nil then
local dist = ship.Position:getDistance(hv.Player.Position)
local distString = string.format("%.0fm", dist)

gr.drawString(ship.Name:filterInvisible(), r + 3, t)
gr.drawString(ship.Class.Name:filterInvisible())

local hit_x = r + 3
local hit_y = b - gr.CurrentFont.Height
local percentage = ship.HitpointsLeft / ship.HitpointsMax

local hitpointsString

if (percentage <= 0) then
percentage = 0
end

hitpointsString = string.format("%.1f%%", percentage * 100)

if (t + 2 * gr.CurrentFont.Height > b - gr.CurrentFont.Height) then
gr.drawString(hitpointsString)
else
gr.drawString(hitpointsString, hit_x, hit_y)
end

gr.drawString(distString, r - gr.getStringWidth(distString), b + 3)
end
end
]

$On HUD Draw:
[
if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if missiontime ~= nil then
if hu.HUDDrawn then
missiontime = mn.getMissionTime()

if oldmissiontime ~= missiontime then
if mn.EscortShips ~= nil then
local NumberEscorted = #mn.EscortShips
for i= 1,NumberEscorted do
local escortedship = mn.EscortShips[i]
if escortedship.Position:getScreenCoords() ~= false and escortedship ~= hv.Player.Target then
drawReticle(escortedship)
end
end
end
end
end

oldmissiontime = missiontime
end
]

#End
 

Disclaimer: Script not tested in current state but used code has been in use for some time so it should work.
Title: Re: EScort Reticle script
Post by: Spoon on June 26, 2012, 02:49:21 pm
http://imagebin.org/218507
There's some redundancy when you have the ship on the escort list and targeted at the same time.
Title: Re: EScort Reticle script
Post by: m!m on June 26, 2012, 03:06:13 pm
I changed the script accordingly, now the rectangle shouldn't be drawn for the currently targeted ship.
Title: Re: EScort Reticle script
Post by: Spoon on June 26, 2012, 05:15:00 pm
m!m you are a king.
Thanks mate.
Title: Re: EScort Reticle script
Post by: Droid803 on July 09, 2012, 10:54:24 pm
Things after a # are shown on the script...
I don't think that should be happening or people can see right through the microjump tricks etc.

Notice that the ship "FRX-00#1" in the escort list appears as FRX-00 as it should, but appears on the reticle boxing thingy as FRX-00#1

(http://i728.photobucket.com/albums/ww286/TSADestiny/Stuff.png)

that and it still appears to be drawing for the targeted ship (I got this off the Wiki not so long ago)
Title: Re: EScort Reticle script
Post by: BlasterNT on July 09, 2012, 11:49:52 pm
m!m updated the script a couple posts back

Here you go:
Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$On Game Init:
[
function string.filterInvisible(str)
    local index = str:find("#", 0, true)

    if (index ~= nil) then
        str = str:sub(1, index - 1)
    end

    return str
end

function drawReticle(ship)
local r, g, b = ship.Team:getColor()
gr.setColor(r, g, b, 120)

local l, t, r, b = gr.drawTargetingBrackets(ship, true)

if l ~= nil then
local dist = ship.Position:getDistance(hv.Player.Position)
local distString = string.format("%.0fm", dist)

gr.drawString(ship.Name:filterInvisible(), r + 3, t)
gr.drawString(ship.Class.Name:filterInvisible())

local hit_x = r + 3
local hit_y = b - gr.CurrentFont.Height
local percentage = ship.HitpointsLeft / ship.HitpointsMax

local hitpointsString

if (percentage <= 0) then
percentage = 0
end

hitpointsString = string.format("%.1f%%", percentage * 100)

if (t + 2 * gr.CurrentFont.Height > b - gr.CurrentFont.Height) then
gr.drawString(hitpointsString)
else
gr.drawString(hitpointsString, hit_x, hit_y)
end

gr.drawString(distString, r - gr.getStringWidth(distString), b + 3)
end
end
]

$On HUD Draw:
[
if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if missiontime ~= nil then
if hu.HUDDrawn then
missiontime = mn.getMissionTime()

if oldmissiontime ~= missiontime then
if mn.EscortShips ~= nil then
local NumberEscorted = #mn.EscortShips
for i= 1,NumberEscorted do
local escortedship = mn.EscortShips[i]
if escortedship.Position:getScreenCoords() ~= false and escortedship ~= hv.Player.Target then
drawReticle(escortedship)
end
end
end
end
end

oldmissiontime = missiontime
end
]

#End
 

Disclaimer: Script not tested in current state but used code has been in use for some time so it should work.
Title: Re: EScort Reticle script
Post by: Droid803 on July 10, 2012, 01:21:54 am
Well why isn't that on the wiki? :/
Title: Re: EScort Reticle script
Post by: Spoon on July 12, 2012, 11:00:02 am
Well you could have read the first page before posting  :p
Title: Re: EScort Reticle script
Post by: Droid803 on July 12, 2012, 11:44:26 am
I did, and I thought that the Wiki would have been updated, seeing as well, it is linked on the first page >.>
Title: Re: EScort Reticle script
Post by: Droid803 on September 04, 2012, 11:00:45 pm
Okay, did some more test runs with the script and noted several deficiencies:

- Alt name isn't being read, the class name is always the default
- Brackets are not sensitive to change-IFF-color sexps (they always stay the team color)

That really wrecks a lot of the "FRED hacks" for missions...
Title: Re: EScort Reticle script
Post by: Droid803 on September 24, 2012, 11:58:17 pm
Okay, did some more test runs with the script and noted several deficiencies:

- Alt name isn't being read, the class name is always the default
- Brackets are not sensitive to change-IFF-color sexps (they always stay the team color)

That really wrecks a lot of the "FRED hacks" for missions...

*bump*
Title: Re: EScort Reticle script
Post by: AndrewofDoom on September 25, 2012, 11:13:22 am
That's because neither of these have accessors in scripting, so you're out of luck in those until someone adds them to the scripting API.