Author Topic: [SOLVED] SEXP-triggerd Escort Reticle  (Read 2048 times)

0 Members and 1 Guest are viewing this topic.

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
[SOLVED] SEXP-triggerd Escort Reticle
EDIT: see 6th post for complete script.


I know that this is a noob question, but I need some help making a SEXP-triggered version of the Escort-reticle script: http://www.hard-light.net/wiki/index.php/Script_-_Escort_Reticle The goal is to have it apply only to one mission./turn it on and off on command.

I checked the Wiki and the forums, (including this thread: http://www.hard-light.net/forums/index.php?topic=67711.0 ) as well as looked at some other examples of scripts, however none of that has been of much use beyond a certain point.
I have a rough idea of what i need to do, but i could very easily be wrong.  :blah:

EX. Should I replace
Code: [Select]
$On Game Init: with
Code: [Select]
$State: GS_STATE_GAME_PLAY

$On State Start:

and if so, what I do with
Code: [Select]
$On HUD Draw:
[

if missiontime == nil then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end
  ?
I'm new to this in case you haven't noticed :p



If someone could be so kind as to explain to me how to modify the script accordingly, or at least make the script and post it below, It would help me a lot.





Thanks in advance -DefCynodont119
« Last Edit: June 08, 2016, 02:09:27 pm by DefCynodont119 »
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 

Offline Axem

  • 211
Re: Basic SEXP-triggerd script help
What I would do is add in a EscortRetEnabled variable into the conditional with if missiontime ~= nil then

so its like

Code: [Select]
if (missiontime ~= nil) and EscortRetEnabled then
Then in the mission you want it to only appear, do a script-eval where you do

Code: [Select]
EscortRetEnabled = true
And then it should turn on. But keep in mind that variable would stay on until the game closes, so you would need to turn it off manually with a script-eval of

Code: [Select]
EscortRetEnabled = nil
Hope that helps!

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: [REQUEST/HELP] SEXP-triggerd Escort Reticle
That Helps a lot Axem! didn't expect a response that fast but two things: the correct way to implement this in the table would be:
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) and EscortRetEnabled then
   missiontime = mn.getMissionTime()
   oldmissiontime = missiontime
end

if (missiontime ~= nil) and EscortRetEnabled 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
Right? or am I missing something obvious. because just doing that (and adding script-eval SEXPs) doesn't seem to work.
EDIT: so i didn't want to replace (missiontime == nil) with the other one, just (missiontime ~= nil). got it. it works now.

Also, what should I do if the player decides to quit mid-mission? well. . . I could add an event with EscortRetEnabled = nil to the start of every other mission in the game, buuut. . .  :warp:



Once again, thank you!
« Last Edit: June 08, 2016, 01:37:24 pm by DefCynodont119 »
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 

Offline niffiwan

  • 211
  • Eluder Class
Re: [REQUEST/HELP] SEXP-triggerd Escort Reticle
Also, what should I do if the player decides to quit mid-mission? well. . . I could add an event with EscortRetEnabled = nil to the start of every other mission in the game, buuut. . .  :warp:

What about setting EscortRetEnabled to nil in the "$On Mission End:" hook?
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
----
Debian Packages (testing/unstable): Freespace2 | wxLauncher
----
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...

 

Offline m!m

  • 211
Re: [REQUEST/HELP] SEXP-triggerd Escort Reticle
Also, what should I do if the player decides to quit mid-mission? well. . . I could add an event with EscortRetEnabled = nil to the start of every other mission in the game, buuut. . .  :warp:

What about setting EscortRetEnabled to nil in the "$On Mission End:" hook?
It would be better to initialize the variables in the $On Gameplay Start: hook. Then all variables always have the right value on mission start so if the player quits the mission the next mission start will reset the variables to the initial values again.

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: [REQUEST/HELP] SEXP-triggerd Escort Reticle
@m!m That's what I was thinking of doing, but I never worked with FSO scripts or LUA and despite my best efforts of reading the wiki, I'm still not sure how to add most of the above mentioned stuff without braking the script.


Still, all of this helps so far. thank you all of you.


My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: [REQUEST/HELP] SEXP-triggerd Escort Reticle
I got it!  ;)
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 Gameplay Start:
[

if EscortRetEnabled then
   EscortRetEnabled = nil
end

]


$On HUD Draw:
[

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

if (missiontime ~= nil) and EscortRetEnabled 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
what I needed to do was add
Code: [Select]
$On Gameplay Start:
[

if EscortRetEnabled then
   EscortRetEnabled = nil
end

]
and fix the misplaced ~ I had. It works now! Thanks Everyone!


-DefCynodont119
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299