Effects
Moderator: Moderators
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Effects
Okay, I've put this off for far too long. I'd like to know how to add effects to my units. If effects isn't the right term, then I mean stuff like dirt fling, jet exhaust coming from planes, welding animations for workers, that kind of stuff.
I looked on the Lua Wiki and it seems pretty straightforward with the emit SFX command, but the big hang-up is that I don't know how to specify which effect, what these effect files even are or where they go, how to make them (if I can), that stuff. So, could someone please enlighten me or show me where I can see an example of how it works?
I looked in CA, at that roach animation Lua file, and I didn't get far.
I looked on the Lua Wiki and it seems pretty straightforward with the emit SFX command, but the big hang-up is that I don't know how to specify which effect, what these effect files even are or where they go, how to make them (if I can), that stuff. So, could someone please enlighten me or show me where I can see an example of how it works?
I looked in CA, at that roach animation Lua file, and I didn't get far.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Effects
Have a look at evolution rts unitdefs or gundam rts unitdefs. You'll get a lot farther.
TO emit cegs,
emit-sfx 1024 from piecenum; << this is for effect 1 (defined in the sfx section of the unitdef)
emit-sfx 1025 from piecenum; << this is for effect 2 (defined in the sfx section of the unitdef)
etc.
TO emit weapons,
emit-sfx 2048 from piecenum; << weapon 1
emit-sfx 2049 from piecenum; << weapon 2
etc.
TO emit cegs,
emit-sfx 1024 from piecenum; << this is for effect 1 (defined in the sfx section of the unitdef)
emit-sfx 1025 from piecenum; << this is for effect 2 (defined in the sfx section of the unitdef)
etc.
TO emit weapons,
emit-sfx 2048 from piecenum; << weapon 1
emit-sfx 2049 from piecenum; << weapon 2
etc.
Re: Effects
Damned has some examples;
CEG defs:
http://petro.darkstars.co.uk/damned/gam ... xplosions/
Example unitdef that uses a CEG:
http://petro.darkstars.co.uk/damned/uni ... rrior1.lua
Example script for said unit:
http://petro.darkstars.co.uk/damned/scr ... arrior.lua
Note that you can use SFX.CEG as syntactic sugar for 1024, when using lua unit scripts (and SFX.FIRE_WEAPON and SFX.DETONATE_WEAPON for 2048 and 4096 respectively
)
CEG defs:
http://petro.darkstars.co.uk/damned/gam ... xplosions/
Example unitdef that uses a CEG:
http://petro.darkstars.co.uk/damned/uni ... rrior1.lua
Example script for said unit:
http://petro.darkstars.co.uk/damned/scr ... arrior.lua
Note that you can use SFX.CEG as syntactic sugar for 1024, when using lua unit scripts (and SFX.FIRE_WEAPON and SFX.DETONATE_WEAPON for 2048 and 4096 respectively

Last edited by FLOZi on 08 Apr 2010, 19:56, edited 1 time in total.
-
- MC: Legacy & Spring 1944 Developer
- Posts: 1948
- Joined: 21 Sep 2004, 08:25
Re: Effects
Its complicated.
First you have to make the effect. These typically look like this (for an example S44 tank cannon muzzleflash):
"LARGE_MUZZLEFLASH" is its name for future use.
Then you have to go to the unitdef of the unit you want to use this FX. There are lots of examples from other games/mods, but in general it uses the [sfxtype] section:
Then finally, in the unit's script file you have to #define the effect properly (and then of course emit it wherever in your script, such as when a weapon fires). To #define it, you'll make a line like this:
#define MEDIUMLARGE_Muzzleflash 1024+1
this allows the script to "detect" the FX; by using the "1024+[the FX included in the sfxtypes section of the unitdef] it will then use that effect when told to, for instance "emit-sfx MEDIUMLARGE_Muzzleflash from flare;"
In S44 we also use emit-sfx to reproduce tracer fire for machineguns, since there's no native way to do that with the engine (and with machineguns, only 1/3 or so bullets fired are actually tracers with the rest being "invisible"). So we made a weapon that effectively does 0 damage which fires little tracer-like lasers, and use the script to force-fire this weapon when the actual machinegun fires.
This is done similarly to above. Make the weapon you want to fire, and include it as a weapon in the unit's unitdef. It doesn't need any parameters, just weapon#=sfxweapon; or whatever.
In your script you'll want a line like this:
#define SMALL_TRACER 2048+4
The '2048' tells the script that "SMALL_TRACER" is a weapon the unit has (in its unitdef file), with the +# telling it which weapon. To figure out this number, take the weapon# (ie in this instance weapon5) and subtract 1 (I have no fucking clue why) -- in this instance in the line above, 2048+4 would define the unit's weapon5. Then you just emit-sfx as normal when you want:
emit-sfx SMALL_TRACER from coaxflare;
Note that the weapon will fire according to the global orientation of the emit piece, so weapons with high tolerances (that appear to shoot slightly sideways out of their barrels) will look kinda silly as the script-emit'd weapon will only fire directly straight. This is most apparent in S44 from sandbag machineguns, when placed on elevated terrain, their emit-sfx tracers will fire straight out above targets that are actually on lower terrain below.
Hope this helps you (and anyone else).
First you have to make the effect. These typically look like this (for an example S44 tank cannon muzzleflash):
Code: Select all
[LARGE_MUZZLEFLASH]
{
[BitmapMuzzleFlame]
{
class = CBitmapMuzzleFlame;
[properties]
{
dir = dir;
colorMap=1 1 0.5 0.01 1 0.7 0 0.01 0 0 0 0.01;
size=0.5;
length=1;
sizeGrowth=70;
ttl=5;
frontOffset=0.3;
sideTexture=plasma2;
frontTexture=plasma0029;
alwaysvisible=1;
}
water=1;
air=1;
underwater=1;
ground=1;
count=1;
}
[muzzlesmoke]
{
class=CSimpleParticleSystem;
[properties]
{
sizeGrowth=0;
sizeMod=1.0;
pos=0, 0, 0;
emitVector=dir;
gravity=0, 0, 0;
colorMap=0 0 0 0.01 0.5 0.5 0.5 0.5 0 0 0 0.01;
Texture=smokesmall;
airdrag=0.8;
particleLife=20;
particleLifeSpread=0;
numParticles=1;
particleSpeed=10 i-1;
particleSpeedSpread=1;
particleSize=7 i-0.4;
particleSizeSpread=1;
emitRot=0;
emitRotSpread=10;
directional=0;
alwaysvisible=1;
}
air=1;
water=1;
ground=1;
count=10;
}
}
Then you have to go to the unitdef of the unit you want to use this FX. There are lots of examples from other games/mods, but in general it uses the [sfxtype] section:
Code: Select all
[sfxtypes]
{
explosionGenerator1=custom:MEDIUMLARGE_MUZZLEFLASH;
}
#define MEDIUMLARGE_Muzzleflash 1024+1
this allows the script to "detect" the FX; by using the "1024+[the FX included in the sfxtypes section of the unitdef] it will then use that effect when told to, for instance "emit-sfx MEDIUMLARGE_Muzzleflash from flare;"
In S44 we also use emit-sfx to reproduce tracer fire for machineguns, since there's no native way to do that with the engine (and with machineguns, only 1/3 or so bullets fired are actually tracers with the rest being "invisible"). So we made a weapon that effectively does 0 damage which fires little tracer-like lasers, and use the script to force-fire this weapon when the actual machinegun fires.
This is done similarly to above. Make the weapon you want to fire, and include it as a weapon in the unit's unitdef. It doesn't need any parameters, just weapon#=sfxweapon; or whatever.
In your script you'll want a line like this:
#define SMALL_TRACER 2048+4
The '2048' tells the script that "SMALL_TRACER" is a weapon the unit has (in its unitdef file), with the +# telling it which weapon. To figure out this number, take the weapon# (ie in this instance weapon5) and subtract 1 (I have no fucking clue why) -- in this instance in the line above, 2048+4 would define the unit's weapon5. Then you just emit-sfx as normal when you want:
emit-sfx SMALL_TRACER from coaxflare;
Note that the weapon will fire according to the global orientation of the emit piece, so weapons with high tolerances (that appear to shoot slightly sideways out of their barrels) will look kinda silly as the script-emit'd weapon will only fire directly straight. This is most apparent in S44 from sandbag machineguns, when placed on elevated terrain, their emit-sfx tracers will fire straight out above targets that are actually on lower terrain below.
Hope this helps you (and anyone else).
Re: Effects
Note that Spiked's examples are in fbi/tdf and bos formats.
- SanadaUjiosan
- Conflict Terra Developer
- Posts: 907
- Joined: 21 Jan 2010, 06:21
Re: Effects
Wow, that does sound complicated
Thanks a ton for all of the information. I'll probably get around to it in a day or so. I think I'm understanding it now. The 1024+1 and all that was what really threw me for a loop.

Thanks a ton for all of the information. I'll probably get around to it in a day or so. I think I'm understanding it now. The 1024+1 and all that was what really threw me for a loop.
-
- MC: Legacy & Spring 1944 Developer
- Posts: 1948
- Joined: 21 Sep 2004, 08:25
Re: Effects
Note that you are a bitch.FLOZi wrote:Note that Spiked's examples are in fbi/tdf and bos formats.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: Effects
no need to use the +1 crap, just use 1024 1025 1026 1027 etcSanadaUjiosan wrote:Wow, that does sound complicated![]()
Thanks a ton for all of the information. I'll probably get around to it in a day or so. I think I'm understanding it now. The 1024+1 and all that was what really threw me for a loop.
Re: Effects
The +1 stuff makes it a lot easier to maintain, IMO, because then you know exactly what CEG is pointing to what BOS command. In Lua-land, you can just emit the CEG through the appropriate callout, I'd think.
Re: Effects
Can't use that to emit from a model piece afaik?
Well, not trivially anyway.
Well, not trivially anyway.
Re: Effects
I must not be doing something right. I'm not getting any errors but nothing is happening either.
Script http://pastebin.com/gLvwfHkP
Unit http://pastebin.com/Ummy84tE
CEG defs http://pastebin.com/MZkjd3Qn and http://pastebin.com/g4gmJCuB
Sorry for the slow response, been hung up with a million other things.
EDIT
Got muzzle flash figured out thanks to flozi, so there's a bit in the unitdef, a bit in the animation, the targas, lua files for the targas, and aresource.lua to tie it all together..Some one should really make a chart or something to better explain this mess.
Script http://pastebin.com/gLvwfHkP
Unit http://pastebin.com/Ummy84tE
CEG defs http://pastebin.com/MZkjd3Qn and http://pastebin.com/g4gmJCuB
Sorry for the slow response, been hung up with a million other things.
EDIT
Got muzzle flash figured out thanks to flozi, so there's a bit in the unitdef, a bit in the animation, the targas, lua files for the targas, and aresource.lua to tie it all together..Some one should really make a chart or something to better explain this mess.