FreeSpace Releases > Scripting Releases
Script: flicker glowmaps of dying ships
zookeeper:
--- Quote from: mjn.mixael on January 17, 2012, 09:07:11 am ---Resurrecting this to ask it'd be possible to get it to affect glowpoints too.
--- End quote ---
Well, sure, that's easy...
--- Code: ---#Conditional Hooks
$Application: FS2_Open
$On Game Init: [
-- For how long the glowmaps should flicker, in seconds
flicker_duration = 4.0
glowmap_replacement = gr.createTexture(16, 16, TEXTURE_DYNAMIC)
if glowmap_replacement == nil or not glowmap_replacement:isValid() then
ba.warning("Error in initializing glowmap flickering script: could not create helper texture! Flicker effect won't work.")
else
gr.setTarget(glowmap_replacement)
gr.clearScreen()
gr.setTarget()
end
]
$State: GS_STATE_GAME_PLAY
$On State Start: [
flickering_glowmaps = {}
]
$On State End: [
flickering_glowmaps = {}
]
$On Death: [
ship = hv.Self
if ship ~= nil and ship:isValid() and glowmap_replacement ~= nil and glowmap_replacement:isValid() then
textures_num = #ship.Textures
for i=1,textures_num do
filename = ship.Textures[i]:getFilename()
if string.find(filename, "-glow") ~= nil and string.find(filename, "debris-glow") == nil then
table.insert(flickering_glowmaps, { ship_signature = ship:getSignature(), tex_i = i, tex = ship.Textures[i], start_time = mn.getMissionTime() } )
end
end
end
]
$On Frame: [
if table.maxn(flickering_glowmaps) > 0 then
for i=1,table.maxn(flickering_glowmaps) do
flicker_time_elapsed = mn.getMissionTime() - flickering_glowmaps[i].start_time
if flicker_time_elapsed < flicker_duration then
ship = mn.getObjectFromSignature(flickering_glowmaps[i].ship_signature)
if (math.random() * flicker_duration) > flicker_time_elapsed then
ship.Textures[flickering_glowmaps[i].tex_i] = flickering_glowmaps[i].tex
mn.runSEXP("activate-glow-points !" .. ship.Name .. "!")
else
ship.Textures[flickering_glowmaps[i].tex_i] = glowmap_replacement
mn.runSEXP("deactivate-glow-points !" .. ship.Name .. "!")
end
else
table.remove(flickering_glowmaps, i)
-- Removing an element might make the loop break, so let's just
-- bail out for this frame rather than do something fancy...
break;
end
end
end
]
#End
--- End code ---
Only added the two mn.runSEXP lines. Untested, though.
Navigation
[0] Message Index
[*] Previous page
Go to full version