Hard Light Productions Forums
FreeSpace Releases => Scripting Releases => Topic started by: m!m on February 14, 2011, 06:11:15 am
-
(http://img714.imageshack.us/img714/5835/missilescript.jpg)
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:
#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
-
Can you extend this to do the same with trails?
-
I'm not entirely sure what you mean. Could you please explain what you mean in detail? :)
-
Nevermind. I thought what this script does is prevent particle spews until free flight time expires, but it's apparently exact opposite.
-
Yes.. Well traditionally the booster rocket makes the most of the smoke and it burns only in initial launch / flight sequence
-
That's the effects this script should create. It only needs a better effect :nervous: :D
-
that looks pretty cool.
-
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.
-
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.
-
No, I meant something like switching on the trail and PSpew (which are disabled at launch) when the FreeFlightTime runs out.
-
That would need to be done inside the engine. It's currently not possible with scripting.
-
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.
-
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
-
Could you modify this script to use a config for defining spew textures on a per-weapon basis?
-
That could be possible and I could use my particle trail script which already has all functionality required for this :D
-
This script crashes FSO upon exit for me.
-
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.
-
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.
-
does the particle trail still not work with corkscrew missiles?
-
I didn't test that case specifically but I can't imagine why it shouldn't work :nervous:
-
Well, it's not really that it doesn't work, it just flies in straight line instead of behind the missile, due to the way corkscrew missiles work. It was only fixed for default spew type, then Nuke implemented his particle code and broke it again. I don't know how scripts will handle this though.
-
The script simply takes the position of the object, a missile in this case and creates the particles at the point of its thruster(s). I'll integrate this into the particle trail script, after that I'll check if it works for corkscrew missiles. :nod:
-
Well, I'm still not sure if it'll work "position of the object", IIRC, goes in straight line, but thruster point is attached to missile model, which does the corkscrew. I'd like a coder to give a better answer, but that's how I understand how the system works, so I may be wrong.