Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: DefCynodont119 on January 28, 2017, 05:23:47 pm

Title: Super simple script request.
Post by: DefCynodont119 on January 28, 2017, 05:23:47 pm
HI! I was wondering if someone could walk me through the process of making a short script that does one simple thing:

Whenever a ship is of a certain name/class, make it fire all it's primaries once at the start of the mission.


This is partly just to help me learn scripting, any help will be appreciated!


EDIT: I know this is the kind of thing Weapon_Create is for, but the point of the script is to avoid using the same SEXPs every time this ship is in a mission. Besides, there are a few other good reasons that Weapon_Create may not do what I need it to in this highly specific case anyway.
Title: Re: Super simple script request.
Post by: DefCynodont119 on January 29, 2017, 08:13:46 pm
Nearly 24 Hours and no response, Bumping. Sorry.
Title: Re: Super simple script request.
Post by: Black Wolf on January 29, 2017, 08:36:43 pm
No need to apologise for bumping - Scripting is a really uncommon skillset, unfortunately. It might take awhile for someone who knows the system to respond.

I'd help if I could, but, excluding coding, it's the area of FS modding I know the least about.
Title: Re: Super simple script request.
Post by: Axem on January 29, 2017, 08:46:24 pm
I'd try this out and see how it works. It won't automatically fire the weapons on mission start, but you can make it do that with a script-eval-block sexp. It's always good to make scripts generic and extendable, making as little as hard-coded as possible.

So you'd save the below script where the filename ends in -sct.tbm, so fireallpri-sct.tbm for example. Then with the script-eval-block sexp you do something that looks like...
(https://ibin.co/3AcV1kLHnLbx.png)
(Single quotes there!!)

For some strange reason, when I was testing it didn't fire all the primary banks in some fighters, but it did in others... not sure what was up with that. Hopefully it works for you!

If you want to get into scripting, check out my tutorials (http://www.hard-light.net/wiki/index.php/User:Axem#Tutorials) on the wiki!

Code: [Select]
#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[

function FireAllPri(shipname)

local ship = mn.Ships[shipname]

if ship:isValid() then

for i=1, #ship.PrimaryBanks do
local thisBank = ship.PrimaryBanks[i]

if thisBank:isValid() then
thisBank.Armed = true
ship:firePrimary()
end
end

end

end

]


#End
Title: Re: Super simple script request.
Post by: DefCynodont119 on January 30, 2017, 12:31:05 am
Thanks for the reply! but. . uh, I can't get it to work for the one thing I need it to.

just to rule some things out, does it change the situation/cause problems for the script if:



1 "Fighter mounted" Type-2 beams are being used for the primary?

2 the ship has only one gun bank?

3 the gun points are not pointing forwards/have convergence?   

4 the ship class's AI is set to "none" by default?

Because all theses things are true in this case.

Thanks again!    The thing this script is for is a surprise, that's why I haven't given all the details.
Title: Re: Super simple script request.
Post by: X3N0-Life-Form on January 30, 2017, 03:59:48 am
I'm at work, so I can't test any of this, but just glancing at Axem's script :

1. I don't know, beams tend to behave differently from other weapons.

2. The script iterates through all primary banks, so there shouldn't be any issue

3. Good question, off-axis gunpoints should work fine, but I'm not sure about gun convergence.

4. It shouldn't have any incidence.


That's an intriguing suprise you are preparing :) : Something that you fires its 1 beam-equipped gunbank with off-axis gunpoints once at mission start whenever its present. And its a type 2, I don't think I've ever used that !
Title: Re: Super simple script request.
Post by: AdmiralRalwood on January 31, 2017, 02:10:28 pm
Off-axis gunpoints are actually a subset of the gun convergence code; gunpoint normals are ignored unless the ship has the "gun convergence" flag. I'm also pretty sure gun convergence/autoaim doesn't work with beams; they're basically a massive special-case in the primary-firing code.
Title: Re: Super simple script request.
Post by: xenocartographer on February 01, 2017, 05:16:28 pm
Are we sure slashing beams even work as fighter primaries?
Title: Re: Super simple script request.
Post by: AdmiralRalwood on February 01, 2017, 06:00:56 pm
...Well, they don't, but since nobody mentioned slashing beams, I'm not sure what relevance that has.
Title: Re: Super simple script request.
Post by: niffiwan on February 01, 2017, 06:21:24 pm
1 "Fighter mounted" Type-2 beams are being used for the primary?

Are type 2 beams slashers? I can't recall...
Title: Re: Super simple script request.
Post by: DefCynodont119 on February 01, 2017, 06:54:42 pm
I did my Research, Type-2 beams are the fighter-mounted ones, hence why I'm using them.

Quote
Type 0 Beams

Type 0 beams are basic, straight-firing beam weapons without any additional features. They use +Miss Factor: values for determining weapon accuracy. Generally speaking, if they hit their target, they will cause full damage. Type 0 beams do not function as fighter beams.

SGreen, BGreen and BFRed are Type 0 beams.


Type 1 Beams

Type 1 beams are slashing beams. These beams use the target's size (or more precisely, models octants) in determining the length of the slashing movement. They might also use +Miss Factor: values for determining weapon accuracy. Only on very rare occasions do slash beams inflict full damage, as they go wide off the target in both the starting and ending points of the slashing movement. However, slashing beams tend to damage target's subsystems quite efficiently, unlike Type 0 beams. Type 1 beams do not function as fighter beams.

TerSlash and VSlash are 'slashing beams'.


Type 2 Beams

Type 2 beams are direct-fire beams. When mounted on turrets, they operate as Type 0 beams. However, they can be used as fighter beams. When used as fighter beams, they disregard the +Miss Factor: value.

The only example is the Targeting Laser.



Type 3 Beams

Type 3 beams are also known as anti-fighter beams and unlike other beam types, they have different behaviors depending on the type of its target. Against small targets, or more precisely against targets defined with certain Objecttypes.tbl options, they fire a number of short beam pulses (defined with +Shots: that have their total combined lifetime equal to the defined lifetime of the beam. Against larger targets, they behave exactly like Type 0 beams. In both cases the beam uses +Miss Factor: values for its accuracy. Type 3 beams do not function as fighter beams.

AAAf and SAAA are such beams.


Type 4 Beams

Type 4 beams are direct-fire beams that fire only along the firing turret's normal. If mounted on a single-part turret, they will only fire where that turret's normal is pointing in similar manner as the unguided swarm weapons - that is, they won't hit anything unless using extremely strict mission design - but with multi-part turrets, they function quite nicely. They do not use +Miss Factor: values for determining weapon accuracy and this can make these beams exceedingly deadly. However, unlike other beam weapons, these will become inaccurate if the firing ship's weapons subsystem is damaged.

The only example is the MjolnirBeam's fixed version.



Did not know about the gun convergence flag, I'll try that. thanks.
Title: Re: Super simple script request.
Post by: xenocartographer on February 01, 2017, 07:39:43 pm
The wiki page on beams (http://hard-light.net/wiki/index.php/Beam) lists type 2 as slashers:

Quote
There are four beam types included in retail FreeSpace 2, but only the first three were used throughout the course of the game.

    1. Direct-fire beams, which are essentially standard-issue point-and-shoot weapons. These beams can be directed to target specific sections of the target ship if necessary.
    2. Slashing beams, which strike their targets across a wide arc. Slashing beams have a marginally higher damage output and faster refire rate than direct-fire beams, but are much more inaccurate and may completely miss the target on occasion.
    3. Anti-fighter beams, which can target vessels smaller than cruiser-class. These beams are capable of firing more than once per pulse, but do very little damage as compared to direct-fire or slashing beams. Under the most dire circumstances, they may be used against larger vessels as well.
    4. Targeting beams, which are never used in the game and whose purpose remains unknown. One beam of this type (the Targeting Laser) is included in the FreeSpace 2 tables, but it appears to serve no purpose due to supplementary content being cut.



So, uh, clearly one source or the other is wrong.
Title: Re: Super simple script request.
Post by: krevett62 on February 01, 2017, 07:45:22 pm
It list as type 2 but I think the index starts at 0 for direct fire beam the wiki just state that there is 4 beam type and list them that's all, more info can be found on the weapons.tbl page

Edit: i'm sure the right source is the weapons.tbl page
Title: Re: Super simple script request.
Post by: AdmiralRalwood on February 02, 2017, 02:32:41 am
So, uh, clearly one source or the other is wrong.
Neither are wrong; they're just conveying different information.
Title: Re: Super simple script request.
Post by: xenocartographer on February 02, 2017, 08:05:40 am
Edit: i'm sure the right source is the weapons.tbl page

Yyyyyyeah, I was trying to give a humorous apology for not checking that first, but tone is hard online.



Anyway. OP, you've got a number of possible problems here - it could be a scripting problem, an SEXP problem, a weapons.tbl or ships.tbl problem, or an oddity in the beam code. I'd start by changing it to a stock Ulysses firing a stock Subach and making sure that works first. If so, then change to a ship with gun convergence, then off-axis primaries, then the type 2 beam, etc., and see where it actually breaks.
Title: Re: Super simple script request.
Post by: DefCynodont119 on February 16, 2017, 09:20:14 pm
So I'm doing a workaround for this by using turrets instead of gunpoints, but I need to know- Is it possable to have two or more turrets if I only have one submodel in the .pof?

EG: I only have Detail_0, but I need two On-Normal beam firing turrets on each side.

EG:EG: like a Remote beam cannon but with two beams- one on each side. Facing opposite directions

long story, sorry. I'll explained why later.
Title: Re: Super simple script request.
Post by: xenocartographer on February 16, 2017, 09:49:53 pm
Quote
Is it possable to have two or more turrets if I only have one submodel in the .pof?
No, but you can duplicate the submodel, or alternatively import another model (BP's blip.pof comes to mind for being completely invisible) and use that as the submodel for your turret. Feel free to ping me if you need help.