Author Topic: EScort Reticle script  (Read 8641 times)

0 Members and 1 Guest are viewing this topic.

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
EScort Reticle script
ChronoReverse tried to revamp the Escort reticle script found on the wiki. 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?
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: EScort Reticle script
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
Do not meddle in the affairs of coders for they are soggy and hard to light

 
Re: EScort Reticle script
It works now!  Thanks a bunch. 

  

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
Re: EScort Reticle script
So, what does the final script look like?
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: EScort Reticle script
Check the wiki. It's uploaded there.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: EScort Reticle script
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.

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
Re: EScort Reticle script
And I, uh, don't actually see anything different going on with this scrip present vs when it's not.
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: EScort Reticle script
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
« Last Edit: January 25, 2010, 02:08:24 am by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
Re: EScort Reticle script
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

]
« Last Edit: January 25, 2010, 02:39:47 am by Zacam »
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: EScort Reticle script
Yes, I think I do.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
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)
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
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!

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
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.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Zacam

  • Magnificent Bastard
  • Administrator
  • 211
  • I go Sledge-O-Matic on Spammers
    • Minecraft
    • Steam
    • Twitter
    • ModDB Feature
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
Report MediaVP issues, now on the MediaVP Mantis! Read all about it Here!
Talk with the community on Discord
"If you can keep a level head in all this confusion, you just don't understand the situation"

¤[D+¬>

[08/01 16:53:11] <sigtau> EveningTea: I have decided that I am a 32-bit registerkin.  Pronouns are eax, ebx, ecx, edx.
[08/01 16:53:31] <EveningTea> dhauidahh
[08/01 16:53:32] <EveningTea> sak
[08/01 16:53:40] * EveningTea froths at the mouth
[08/01 16:53:40] <sigtau> i broke him, boys

 

Offline Enioch

  • 210
  • Alternative History Word Writer
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.
'Violence is the last refuge of the incompetent'  -Salvor Hardin, "Foundation"

So don't take a hammer to your computer. ;-)

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
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
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: EScort Reticle script
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?
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline m!m

  • 211
Re: EScort Reticle script
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.
« Last Edit: June 26, 2012, 03:03:47 pm by m!m »

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: EScort Reticle script
http://imagebin.org/218507
There's some redundancy when you have the ship on the escort list and targeted at the same time.
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline m!m

  • 211
Re: EScort Reticle script
I changed the script accordingly, now the rectangle shouldn't be drawn for the currently targeted ship.