Author Topic: Super simple script request.  (Read 4492 times)

0 Members and 1 Guest are viewing this topic.

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Super simple script request.
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.
« Last Edit: January 28, 2017, 05:51:53 pm by DefCynodont119 »
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: Super simple script request.
Nearly 24 Hours and no response, Bumping. Sorry.
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 

Offline Black Wolf

  • Twisted Infinities
  • 212
  • Hey! You! Get off-a my cloud!
    • Visit the TI homepage!
Re: Super simple script request.
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.
« Last Edit: January 30, 2017, 01:17:29 am by Black Wolf »
TWISTED INFINITIES · SECTORGAME· FRONTLINES
Rarely Updated P3D.
Burn the heretic who killed F2S! Burn him, burn him!!- GalEmp

 

Offline Axem

  • 211
Re: Super simple script request.
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: [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

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: Super simple script request.
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.
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 
Re: Super simple script request.
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 !

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Super simple script request.
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.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Super simple script request.
Are we sure slashing beams even work as fighter primaries?

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Super simple script request.
...Well, they don't, but since nobody mentioned slashing beams, I'm not sure what relevance that has.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline niffiwan

  • 211
  • Eluder Class
Re: Super simple script request.
1 "Fighter mounted" Type-2 beams are being used for the primary?

Are type 2 beams slashers? I can't recall...
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 DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: Super simple script request.
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.
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

  
Re: Super simple script request.
The wiki page on beams 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.

 
Re: Super simple script request.
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

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Super simple script request.
So, uh, clearly one source or the other is wrong.
Neither are wrong; they're just conveying different information.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Super simple script request.
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.

 

Offline DefCynodont119

  • 210
  • Ascended GTSC-Faustus Artist
    • Steam
Re: Super simple script request.
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.
My gift from Freespace to Cities Skylines:  http://steamcommunity.com/sharedfiles/filedetails/?id=639891299

 
Re: Super simple script request.
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.