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
-
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:
#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: __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?
-
In lua.cpp line 9900 change
Change
-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
-
It works now! Thanks a bunch.
-
So, what does the final script look like?
-
Check the wiki. It's uploaded there.
-
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.
-
And I, uh, don't actually see anything different going on with this scrip present vs when it's not.
-
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.
#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
-
I think you mean
$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
]
-
Yes, I think I do.
-
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.
if x ~= nil and y1 ~= nil then
gr.drawString(ship.Name, x1 +3, y)
gr.drawString(ship.Class.Name, x1 +3, y + 9)
-
In lua.cpp line 9900 change
Change
-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!
-
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.
-
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!)
#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
-
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.
-
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
-
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?
-
Here you go:
#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.
-
http://imagebin.org/218507
There's some redundancy when you have the ship on the escort list and targeted at the same time.
-
I changed the script accordingly, now the rectangle shouldn't be drawn for the currently targeted ship.
-
m!m you are a king.
Thanks mate.
-
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)
-
m!m updated the script a couple posts back
Here you go:
#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.
-
Well why isn't that on the wiki? :/
-
Well you could have read the first page before posting :p
-
I did, and I thought that the Wiki would have been updated, seeing as well, it is linked on the first page >.>
-
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...
-
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*
-
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.