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)
#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:
#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:
#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.