Modding, Mission Design, and Coding > The Scripting Workshop

Super simple script request.

(1/4) > >>

DefCynodont119:
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.

DefCynodont119:
Nearly 24 Hours and no response, Bumping. Sorry.

Black Wolf:
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.

Axem:
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...

(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 on the wiki!


--- Code: ---#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
--- End code ---

DefCynodont119:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version