Author Topic: Missile particle script  (Read 4727 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
Missile particle script

Yes, yet another script. This script tries to imitate that a missile with $FreeFlighTime set actually ignites when is launches as seen in the screenshot above.
To use create a file called missilePart-sct.tbm in your data/tables directory and paste the following text into it:
Code: (missilePart-sct.tbm) [Select]
#Conditional Hooks

$Application: FS2_Open
$On Game Init:
[
function getLivingTime(maxLife, lifeLeft)
if (maxLife == nil or lifeLeft == nil) then
return -1
end

local time = maxLife - lifeLeft

return time
end

function weaponLivingTime(weapon)
if (weapon == nil or not weapon:isValid()) then
return -1
end

local maxLife = weapon.Class.LifeMax
local lifeLeft = weapon.LifeLeft

if (weapon.Class:isMissile() and weapon.HomingObject:isValid()) then
maxLife = maxLife * 1.2 -- "fix" for LiveLeft altering in code/weapons.cpp:4664
end

return getLivingTime(maxLife, lifeLeft)
end

function createWeaponParticle(weapon, velocity, lifeTime, radiusScale, texture)
if (weapon == nil or not weapon:isValid()) then
return
end

local model = weapon.Class.Model
local thrusters = model.Thrusters
for i=1, #thrusters do
local bank = thrusters[i]
if (bank:isValid()) then
for j=1, #bank do
local glow = bank[j]
if (glow:isValid()) then
local realVec = weapon.Orientation:unrotateVector(glow.Position)
local globalVec = weapon.Position + realVec

ts.createParticle(globalVec, velocity, lifeTime, glow.Radius * radiusScale, PARTICLE_BITMAP, -1, false, texture)
end
end
end
end
end

nullVector = ba.createVector(0, 0, 0)
maxFrameTime = 1 / 10
]

$State: GS_STATE_GAME_PLAY
$On Frame:
[
if ba.getFrametime() > maxFrameTime then
return -- If FPS is already low don't lower it with even more load
end

if (trailTexture == nil or not trailTexture:isValid()) then
return
end

if (ignitionAnim == nil or not ignitionAnim:isValid()) then
return
end

for i=1, #mn.Weapons do
local weapon = mn.Weapons[i]

if (weapon:isValid() and weapon.Class:isMissile() and weapon.HomingObject:isValid() and weaponLivingTime(weapon) > weapon.Class.FreeFlightTime) then
local velVec = weapon.Physics.Velocity - weapon:getfvec(true) * 200
if ((weapon:getfvec(true) * 200):getMagnitude() > weapon.Physics.Velocity:getMagnitude()) then
velVec = velVec / 20
end

local radius = (1 - (weapon.Class.Speed / weapon.Physics.Velocity:getMagnitude())) * 1.5
if (radius > 3) then
radius = 3
end

createWeaponParticle(weapon, velVec, particleLifeTime, radius * 3, trailTexture)

if (weapon.Class.FreeFlightTime > 0 and weaponLivingTime(weapon) >= weapon.Class.FreeFlightTime and (weaponLivingTime(weapon) - ba.getFrametime()) <= weapon.Class.FreeFlightTime) then
createWeaponParticle(weapon, nullVector, ingitionLifeTime, radius * 5, ignitionAnim)
end
end
end
]

$Application: FS2_Open
$On Mission Start:
[
trailTexture = gr.loadTexture("capflash", true)
if (trailTexture ~= nil and trailTexture:isValid()) then
particleLifeTime = trailTexture:getFramesLeft() / trailTexture:getFPS()
end

ignitionAnim = gr.loadTexture("exp20", true)
if (ignitionAnim ~= nil and ignitionAnim:isValid()) then
ingitionLifeTime =  ignitionAnim:getFramesLeft() / ignitionAnim:getFPS()
end

if (trailTexture == nil or not trailTexture:isValid()) then
ba.warning("Invalid trail texture!")
elseif (ignitionAnim == nil or not ignitionAnim:isValid()) then
ba.warning("Invalid ignition texture!")
end
]

$Application: FS2_Open
$On Mission End:
[
if (trailTexture ~= nil) then
trailTexture:unload()
trailTexture = nil
end
if (ignitionAnim ~= nil) then
ignitionAnim:unload()
ignitionAnim = nil
end
]

#End

Feel free to criticize and I'm always open for new feature requests :nod:

Regards,
m!m

EDIT: I should say that this script requires a build of Revision 7011 or later
« Last Edit: February 14, 2011, 10:46:39 am by m!m »

 

Offline Fury

  • The Curmudgeon
  • 213
Re: Missile particle script
Can you extend this to do the same with trails?

 

Offline m!m

  • 211
Re: Missile particle script
I'm not entirely sure what you mean. Could you please explain what you mean in detail? :)

 

Offline Fury

  • The Curmudgeon
  • 213
Re: Missile particle script
Nevermind. I thought what this script does is prevent particle spews until free flight time expires, but it's apparently exact opposite.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Missile particle script
Yes.. Well traditionally the booster rocket makes the most of the smoke and it burns only in initial launch / flight sequence
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline m!m

  • 211
Re: Missile particle script
That's the effects this script should create. It only needs a better effect :nervous: :D

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Missile particle script
that looks pretty cool.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Missile particle script
That looks interesting, but I'd like to see a script that would allow making missiles which spend first part of their flight time unpowered, then start tracking and ignite their engine after their free flight time is expired. Booster rocket for these could be done with a muzzleflash (as they're ussualy fighter missiles). That would be really helpfull for atmospheric mods.

 

Offline m!m

  • 211
Re: Missile particle script
If I understand you correctly, this is exactly what this script does :p.
This script creates a specified particle when the free flight time of a weapon runs of. Then it creates another type of particle as long as the missile accelerates.

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Missile particle script
No, I meant something like switching on the trail and PSpew  (which are disabled at launch) when the FreeFlightTime runs out.

  

Offline m!m

  • 211
Re: Missile particle script
That would need to be done inside the engine. It's currently not possible with scripting.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Re: Missile particle script
Well.. spawn 1 type weapon with fixed minimum spawn angle might do the trick - though you would still likely need scripting to make sure ai would fire the weapon as it should and that the 'swap' would happen when it should.
Do not meddle in the affairs of coders for they are soggy and hard to light

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
Re: Missile particle script
you know this gets me thinking, i should add some features to my particle system for missiles. should add a tag to indicate what stage(s) of flight in which a spewer will be allowed to emit.
i can think of the following stages:

all
free flight
powered flight
has lock
lost lock
armed
disarmed
emp

-this would probibly be done as a flag list. you would list the modes you want the effect to be active.
 example: $active_during_stage: ("free flight" "emp") ;only used when just launched or dead in the water
-'all' would be defaulted to on unless the tag is used, once used it will be assumed to be off and you would need to set the flag manually if you wanted to use it.
-would also call for an +override for xmt compatibility
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Missile particle script
Could you modify this script to use a config for defining spew textures on a per-weapon basis?

 

Offline m!m

  • 211
Re: Missile particle script
That could be possible and I could use my particle trail script which already has all functionality required for this :D

 

Offline Droid803

  • Trusted poster of legit stuff
  • 213
  • /人 ◕ ‿‿ ◕ 人\ Do you want to be a Magical Girl?
    • Skype
    • Steam
Re: Missile particle script
This script crashes FSO upon exit for me.
(´・ω・`)
=============================================================

 

Offline Luis Dias

  • 211
Re: Missile particle script
Is it possible for it to spawn different sized and with different speeds?

It needn't a random quantifier or anything of the sort. But rather than just one single equal emission, it would consist of, say, 6 emmissions. Three different sizes and two different speeds.

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Missile particle script
That could be possible and I could use my particle trail script which already has all functionality required for this :D
Incorporating this into particle trail script seems like a good idea.

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: Missile particle script
does the particle trail still not work with corkscrew missiles?
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 

Offline m!m

  • 211
Re: Missile particle script
I didn't test that case specifically but I can't imagine why it shouldn't work :nervous: