Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: Woolie Wool on November 02, 2016, 09:53:43 am

Title: Need a script to fire a turret fire-beam style
Post by: Woolie Wool on November 02, 2016, 09:53:43 am
I was wondering if anyone could write a script that would fire a specific turret on a specific ship at a specific target and could be called via sexp. Basically this would be fire-beam for regular turrets, and would greatly increase the amount of control I have over railgun turrets in Twist of Fate (which are the predecessors of, and are used like, beams on FS2 ships). Is anybody interested?
Title: Re: Need a script to fire a turret fire-beam style
Post by: General Battuta on November 02, 2016, 10:18:54 am
Use turret-tagged-only and tag the target, hide the tag color with an iff color sexp.
Title: Re: Need a script to fire a turret fire-beam style
Post by: Black Wolf on November 02, 2016, 10:20:12 am
I remember asking for this yeeeears ago, in sexp form. There was a specific reason it wasn't possible at the time, though I can't remember why now - maybe scripting has changed that?
Title: Re: Need a script to fire a turret fire-beam style
Post by: Woolie Wool on November 02, 2016, 10:35:27 am
Use turret-tagged-only and tag the target, hide the tag color with an iff color sexp.

I've actually done this, but I really need something more flexible, and the ability to synchronize other events with the turret firing.
Title: Re: Need a script to fire a turret fire-beam style
Post by: mjn.mixael on November 02, 2016, 10:58:32 am
In BtA we gained this control over the torpedo turrets by simply locking the turrets and using weapon-create as needed. The entire last mission is actually played with the torpedo turrets locked the entire time. Using weapon-create, you can get the "firing turret's" position with get-objecy-xyz, and then get the parent ship's heading +/- whatever amount to make it fire from the broadside or whatever.

This gave us very specific control over how often the turret fired and what it's specific target would be every time.
Title: Re: Need a script to fire a turret fire-beam style
Post by: Woolie Wool on November 02, 2016, 11:51:38 am
Good lord, that sounds cumbersome, and you'd have to recalculate the position of both the firing ship and the target every single time, while with my idea you'd just call a single sexp, specify the firing turret and intended target, and the scripting and turret AI would handle the rest, and then add a repeat count so that the same turret can fire at the same target over and over, just like with fire-beam. That this is done through a sexp is especially important because in certain missions warships will overcharge their railguns, which means they will do more damage but the recoil will damage the firing ship, so the sabotage-subsystem sexp must be synchronized with the railgun firing.

Also there are two other problems, which are (a) railguns produce huge and extremely obvious muzzle flashes and to have them drawn in the wrong spot or not at all would be immediately noticeable, and (b) at one point an Orion uses overcharge, and one of the railguns is mounted on the same multipart where its BGreen is located in FS2. For the railgun to fire without the turret tracking the target would also look silly.
Title: Re: Need a script to fire a turret fire-beam style
Post by: mjn.mixael on November 02, 2016, 01:57:31 pm
You don't have to "recalculate" anything at all. The SEXP does that for you. See here.

(https://ibin.co/30cfzQc882e8.jpg)

That controls turret08 on the HLD Cardinal.  It has a trigger count and interval time. As set, it fires every 12 seconds whenever the conditions are true, which in this case involves where the Cardinal is located along its waypoints. There are similar SEXPs that control the Intepid's turrets except that the target (argument 9 in weapon-create) is a string variable and we change the variable with other SEXPs to dynamically change who that turret is firing at.

If you're worried what it looks like, go watch the cutscene "controlpart1a.ogg" in BtA's modpack. It's directly recorded from FSO using those sexps to fire the Intrepid's torpedoes at about 12 seconds in.

If you want to get suuuper specific with weapon create positions, you can also get relative positions of the turrets with get-object-xyz.
Title: Re: Need a script to fire a turret fire-beam style
Post by: Admiral MS on November 02, 2016, 02:18:11 pm
I don't see any reason why scripting can't do it. If the script doesn't check wether firing is a good idea (turret not ready to fire, wrong target, wrong side of ship, whatever) then "only" the names of the firing ship and subsystem (=turret) as well as the names of the target and target subsystem have to be passed to the script. Which is most likely too long for the usual maximum length of a scripting call (unless that limit has been bumped).

Now seeing that you want to use a multipart where only one of the weapons actually fires - while not so much of a problem, it needs even more input and the script has to be very generic to cover all the possible combinations.


I guess a sexp solution like the one mjn.mixael showed might be the better and faster way to do it...
Title: Re: Need a script to fire a turret fire-beam style
Post by: X3N0-Life-Form on November 02, 2016, 03:05:45 pm
In BtA we gained this control over the torpedo turrets by simply locking the turrets and using weapon-create as needed.
I feel better now that I know I'm not the only person doing hacks with weapon-create :P


Which is most likely too long for the usual maximum length of a scripting call (unless that limit has been bumped).
Behold, the script-eval-block SEXP ! Saying "screw you" to the 32 char limit since [insert date here].

(http://i.imgur.com/pT3aGmD.jpg)

Title: Re: Need a script to fire a turret fire-beam style
Post by: mjn.mixael on November 02, 2016, 05:52:11 pm
I love script-eval-block so much... :)