Author Topic: Gun Flash / Exhaust  (Read 2969 times)

0 Members and 1 Guest are viewing this topic.

Is it possible with scripting to, basically have some effect that happens everytime a gun fires? But not like, a muzzle flash, but rather the venting of gases or exhaust at a point on the gun that is not near the barrel? I first thought maybe a person could do that with animated gunflash but I'm guessing that it would only look "correct" from a certain angle.


Like just, particle generation? Maybe for example a gun fires a big conventional round, and then after the firing, an empty shell casing is ejected/generated from a breach? Or another possibility is maybe a large round is fired, and then smoke is temporarily generated from a few points, one could even use something similar or identical to the "damage" smoke currently seen?

Not sure if Nuke has done anything like this yet

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Right now, it'd be difficult to check if the weapon had just been created, but making particles would be easy.

Here's a quick script... (untested)
Code: [Select]
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [
--Weapon instances known by script
g_weaponInstances = {}
g_numWeaponInstances = 0

function isInstanceNew(weaponInstance)
if not weaponInstance or not weaponInstance:isValid() then
return false
end

--Prune dead weapons and check for the current one
local cwi = nil
local firstEmptySpot = 0
for i=1,g_numWeaponInstances do
cwi = g_WeaponInstances[i]
if cwi == nil and firstEmptySpot < 1 then
--Mark first spot in case weaponInstance is new
firstEmptySpot = i
else
--This weapon already exists, ignore it
if cwi == weaponInstance then
return false
end

--If this weapon is gone, get it out of
--the table
if not cwi:isValid() then
g_WeaponInstances[i] = nil
g_numWeaponInstances = g_numWeaponInstances - 1
end
end
end

--Weapon is new, add it to known weapon instances
if firstEmptySpot > 0 then
g_weaponInstances[firstEmptySpot] = weaponInstance
else
table.insert(g_weaponInstances, weaponInstance)
end
g_numWeaponInstances = g_numWeaponInstances + 1

--Weapon is new
return true
end
]

$Application: Freespace 2
$Weapon Class: yourweaponhere
$On Object Render: [
--Should never ever happen, but check anyway for
--showing how to. I'd recommend disabling this check
--for speed in a real situation.
if not hv.Self or not hv.Self:isValid() then
return
end

--See if we can skip weapon because it's too far from ship
--Presumably, new weapons will be right next to the ship that
--created them.
local weapon = hv.Self
if weapon.Parent:isValid() then
local parent = weapon.Parent

--If we are outside parent ship model's radius, skip this weapon
if weapon.Position:getDistance(parent.Position) > parent.Class.Model.Radius then
return
end
end

--Go through the list and check if this weapon is new
if isInstanceNew(weapon) then
--Generate particles
end
]
#End

Nearly all of that script is because there's no way, with the current hooks, to tell if a weapon object is newly created or simply existing.

Here's the script if I implement an "$On Primary Fire" hook:
Code: [Select]
#Condtional Hooks
$Application: Freespace 2
$Object Type: Ship
$On Primary Fire: [
if hv.Weapon.Class.Name == "yourweaponhere" then
--Generate particles
end
]
#End

Or with an $On Object Create hook:
Code: [Select]
#Condtional Hooks
$Application: Freespace 2
$Weapon class: yourweaponhere
$On Object Create: [
--Generate particles
]
#End

Right now ts.createParticle is the only particle creation function, but you can use that to make the particle move in any which way. Damage smoke is, IIRC, nothing more than a bunch of particles.

The only reason I haven't implemented the above hooks is because it'll take some time to figure out where, exactly, to put them internally and I wanted to see some interest before I did that. I'll add these to my todo for the next build, along with the light functions in the other thread.
« Last Edit: August 28, 2008, 04:38:36 am by WMCoolmon »
-C

 
Sweet. Good to know.
The model I have in mind for this is still in the conceptualizing phase so if there's any delay in adding some functionality it's not at all a problem. I imagine it will be some months before I can get a chance to put it to good use. Being able to move the particles in any which way sounds like exactly what I need too.

 

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Well there is the lifetime which can be used to check for the weapons existance/creation

One example is if the desired lifetime for the weapon is say 2.0 s is to set the value in the table to 3.0 s or so and then simply trigger the script should a weapon of the defined class have current lifetime higher than 2.0s and then after script has been triggered then reduce the lifetime to 2.0s.
Do not meddle in the affairs of coders for they are soggy and hard to light

 
Well there is the lifetime which can be used to check for the weapons existance/creation

One example is if the desired lifetime for the weapon is say 2.0 s is to set the value in the table to 3.0 s or so and then simply trigger the script should a weapon of the defined class have current lifetime higher than 2.0s and then after script has been triggered then reduce the lifetime to 2.0s.

      As a related issue, I assume that someone could randomnly generate particles on any given ship at a given time? One effect I always liked was from Macross Plus where Isamu's Veritech exits a fold and a bunch of particle come off his ships (similar to this: http://www.youtube.com/watch?v=1N3HbsdlkQg at 0:30).

       Something I thought about doing for Renegade Legion if I ever get interested in working on that MOD again. Right now got something else in mind.

  

Offline Wanderer

  • Wiki Warrior
  • 211
  • Mostly harmless
Well... you need to define the particle start point quite carefully as ATM it is not possible to access the model itself and assign the particle to the surface. So instead you will need to dig up the vector (in respect to models centerpoint) and apply the the effect there (after adjusting for the ships rotation and the ships centerpoints location in respect to mission centerpoint).

But i can't see why it couldnt be done
Do not meddle in the affairs of coders for they are soggy and hard to light