Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: Wanderer on January 30, 2007, 10:24:35 am

Title: Flashy deaths
Post by: Wanderer on January 30, 2007, 10:24:35 am
Something little brighten up the ship deaths...

Code: [Select]
#Global Hooks

$Simulation:

[

missiontime = mn.getMissionTime()
frametime = ba.getFrametime(true)

if missiontime < 1 then
   flaktexture = gr.loadTexture("lglow3")
   nullvec = ba.createVector(0,0,0)
   detotexture = gr.loadTexture("EXP_flash", true)
   detotimes = { 2000000 }
   detoinfo = {}
   detoshipdead = {}
   math.randomseed( os.time() )
end

for i=1,#mn.Ships do
   detoship = mn.Ships[i]
   detoshipname = detoship.Name
   detoshiphp = detoship.HitpointsLeft
   if detoshiphp < 1 and detoshipdead[detoshipname] == nil then
      detoshipdead[detoshipname] = 1
      detoshiptype = detoship.Class.Type.Name
      if detoshiptype == "Freighter" then
         detoshipvel = detoship.Physics.Velocity
         detoshippos = detoship.Position
         detonum = math.floor(10+2*math.random())
         for k=1,detonum do
            detorandtimer = 1+2*math.random()
            detorandvector = ba.createVector(100*(math.random()-0.5),100*(math.random()-0.5),100*(math.random()-0.5))
            detoprojection = detoshippos + detorandvector + (detoshipvel/(1/detorandtimer))
            detotime = detorandtimer + missiontime
            table.insert(detotimes,detotime)
            table.insert(detoinfo,math.floor(detotime*10000),detoprojection)
         end
         table.sort(detotimes)
      end
   end
end

while detotimes[1] < missiontime do
   detotimer = detotimes[1]
   ts.createParticle(detoinfo[math.floor(detotimer*10000)],nullvec,frametime,math.random(50,200),PARTICLE_BITMAP,-1,false,detotexture)
   table.remove(detoinfo,math.floor(detotimer*10000))
   table.remove(detotimes,1)
   table.sort(detotimes)
end

]

#End

Basically it creates series of flashes (animation) around (or inside) the ship when it dies. 'lglow3' is a standard bitmap graphic and 'exp_flash' is an animation (eff)
Title: Re: Flashy deaths
Post by: Mobius on February 03, 2007, 02:28:47 am
Wow. I think I will try it!
Title: Re: Flashy deaths
Post by: Wanderer on February 04, 2007, 08:52:05 am
You should note that the particular script posted above draws effect only if the dying ship is of 'Freighter' type. It is relatively straightforward to modify that for other shiptypes (like capital) - or to use shipclasses (like GTFr Triton) instead - as well.

Also the effect i used it isnt really that pretty.. However if you can get it from here (http://koti.mbnet.fi/vekkup/FS2/EXP_flash.rar)
Title: Re: Flashy deaths
Post by: Snail on February 04, 2007, 09:36:35 am
I'm gunna have a look....
Title: Re: Flashy deaths
Post by: Snail on February 04, 2007, 09:42:10 am
help. ::) <-- Annoyed with self

LUA ERROR: attempt to call a string value

LUA Debug:
------------------------------------------------------------------
Name:      (null)
Name of:   
Function type:   C
Defined on:   -1
Upvalues:   0

Source:      =[C]
Short source:   [C]
Current line:   -1
------------------------------------------------------------------

LUA Stack:
------------------------------------------------------------------

------------------------------------------------------------------
Title: Re: Flashy deaths
Post by: Wanderer on February 04, 2007, 11:37:15 am
What build did you use? This script needs new HEAD branch CVS build.. like this http://www.hard-light.net/forums/index.php/topic,45175.0.html

EDIT: Also... some short video clips (http://koti.mbnet.fi/vekkup/flash.rar) (ogg) to show the effect... use for example VLC player.. Enlarged ones are just tests and the 'standard' ones use the same values as the script above
Title: Re: Flashy deaths
Post by: Snail on February 04, 2007, 02:05:57 pm
Damn, I really am CLUELESS (n00b squad) "How do you fire teh lasers?".
Title: Re: Flashy deaths
Post by: Wanderer on February 04, 2007, 02:37:49 pm
Errr... So did you still have issues with it?
Title: Re: Flashy deaths
Post by: Snail on February 12, 2007, 09:17:46 am
no no. :)
Title: Re: Flashy deaths
Post by: Wanderer on October 14, 2007, 02:59:15 am
:bump::bump:

I think this long comatose state requires two bums :P


Decided to alter the script a bit and remake it as well.


Now the script 'supports' most of the Terran and Vasudan ships of FreeSpace 2 - and it ain't exactly rocket science to expend that. In package there is also a script for scripted flak effects. The scripts, graphic effects and required builds are in the download. It comes as a mod directory (might be worth checking that the mod.ini inside the directory points to your 'mediavps' directory) and three HEAD branch builds. Remember to use NEW and SEPARATE pilot files with these builds.

Download link (http://koti.mbnet.fi/vekkup/FS2/FreeSpaceOpenScriptingThings.7z)

If people would like to test and comment these it would be great. As for missions... Any mission with dying terran or vasudan ship listed in the mod will do.

Should you want to disable either of the scripts just rename the related .tbm file(s) to .txt.
Title: Re: Flashy deaths
Post by: Mav on October 18, 2007, 03:06:49 pm
Thanks for this scripting example :) .
Now it seems to me Lua is much more like C++ then I initially expected - please don't look at my first example script, I'd get very deep red of being ashamed...  :shaking:

I hope now I'll be able to get some scripting working myself within the "foreseeable future" (don't nail me down to specify this, please :nervous: ;) ).
Title: Re: Flashy deaths
Post by: Nuke on October 18, 2007, 04:21:47 pm
lua's nothing like c++. no bracket hell, no needing to call special functions to use dynamic memory, no semicolons, and no pointers. if lua is rocket science, then c++ is m theory.
Title: Re: Flashy deaths
Post by: Wanderer on October 19, 2007, 04:14:55 pm
If you run into probs with the scripts just ask for help here.. I mean some of the Lua errors (ie. the error message is next to useless) are rather cryptic.
Title: Re: Flashy deaths
Post by: Starman01 on October 21, 2007, 01:34:23 am
Sorry for the newb question, but what do I have to do to try out this script here in our own data ? :)
Title: Re: Flashy deaths
Post by: Cobra on October 21, 2007, 01:37:41 am
I can't view the files videos. Winamp is refusing to play them. :doubt:
Title: Re: Flashy deaths
Post by: Wanderer on October 21, 2007, 02:30:45 am
Sorry for the newb question, but what do I have to do to try out this script here in our own data ? :)
Umh? Extract the archive into the FreeSpace dir... Assuming you have allowed paths to be created it creates mod directory named 'Scripting' and places few HEAD branch exe files into the 'main FreeSpace directory'. Use launcher to select the mod and try a mission where Terran/Vasudan capital ship gets destroyed. If you mean by 'our own data' a mod or TC data then there is little more to do. First you need to clear the current FreeSpace ship references from the script and replace these with values that are suitable for the models in use.

These for each ship... First three define the 'box' where the detonations are allowed to happen. Fourth defines the radius of a detonation effect (-+ 50%) and last defines the flash that appears when the ship truly gets removed from 'ship index list' ie. die.
Code: [Select]
      arrayShipW["GTD Orion"] = 500
      arrayShipH["GTD Orion"] = 500
      arrayShipL["GTD Orion"] = 1900
      arrayShipDetRadius["GTD Orion"] = 500
      arrayShipFlashRadius["GTD Orion"] = 2500

I can't view the files videos. Winamp is refusing to play them. :doubt:
As said 'OGG' (theora) files. Get VLC player or something like it that isn't as inept as WinAmp - at least  i haven't had much luck getting WinAmp to play theora clips.
Title: Re: Flashy deaths
Post by: Wanderer on October 22, 2007, 11:47:02 am
So that cleared the questions? Please if you have questions about that post those here or PM me.
Title: Re: Flashy deaths
Post by: Cobra on October 22, 2007, 12:09:45 pm
I'm kind of liking the effect that you're using, but at the same time I'm not really sure I do, it looks like cheese. :nervous:
Title: Re: Flashy deaths
Post by: Wanderer on October 22, 2007, 01:08:08 pm
Well.. I'm sorta proud of the graphics :P And kinda proves i am not exactly a graphics wiz...  But that kinda shows the limits of my graphics skills.

But you can always change the effect to any animation the game accepts that you want to. Also it is trivial to change the script to use randomly selected explosion flashes or species specific explosions - like having different sets for vasudans and terrans - should you want to have more variance for the explosions.
Title: Re: Flashy deaths
Post by: Cobra on October 22, 2007, 01:15:38 pm
It's a huge improvement though. :)
Title: Re: Flashy deaths
Post by: Turambar on March 15, 2008, 10:19:43 am
we should get this in-game and looking pretty ASAP for the .vp's
Title: Re: Flashy deaths
Post by: Wanderer on March 15, 2008, 11:42:04 am
You think this should be included to the mediavps?

The script itself (one in the linked FreeSpaceOpenScriptingThings.7z) should work with taylor's new XT builds. However i'm not sure if any scripts should be included into any mediavp package as long as the code support for the scripting is not in committed to the stable branch.
Title: Re: Flashy deaths
Post by: WMCoolmon on March 15, 2008, 03:08:54 pm
I just committed it to SVN last night, along with the new warp effects code, although people seem to have problems in general with stable builds right now. There's a lot of problems that'll be fixed when taylor commits his Xt branch.
Title: Re: Flashy deaths
Post by: Wanderer on March 15, 2008, 03:16:17 pm
NOO! My long standing excuse to wave off all the script just got removed...  ;)


:yes: Great :D
Title: Re: Flashy deaths
Post by: Shade on March 15, 2008, 03:20:21 pm
Better deaths for big ships would definitely spice things up :)