And as I promised here is the beta version of particle effects library.
Warning! Wall of text and code.
What it dose is basically reduce Lua coding of various particle streams, effects and traces to something like this (this is the actual listing of all lua code of D9 Arc Gun):
Code:
function Create(self)
self.origin = IsAnyActorAtPosition(self.Pos);
if self.origin ~= nil and MovableMan:ValidMO(self.origin) then
local AimVector = ConvertAngleToNormalizedVector(self.origin:GetAimAngle(true));
self.Pos = self.Pos + AimVector*15;
CastD9Lightning(self.Pos, AimVector, 350, self.origin.ID);
end
self.ToDelete=true;
end
Step by step what this code dose:
- 1.Gets the actor, who shot the projectile. Projectile must form inside the gun for this to work. It is best to set MuzzleOffset in ini file to (0,0) we'll add offset later in this script.
- 2.Checks if actor is OK
- 3.Gets actor's aim angle
- 4.Moves the projectile to a new position where muzzle should be
- 5.The most interesting part: Uses function from the library to create particle stream with predefined settings. tarting at self.Pos, aiming along AimVector with length of 350, ignoring actor who created it.
- 6. Destroys the projectile
So creating similar effects becomes more like ini moding.
The actual CastParticleStream function with all parameters (lots of them
):
Code:
function CastParticleStream(StartPosition,DirectionVector,ArcLength,MinimumDeviationFromTheAxis,
MaximumDeviationFromTheAxis,MinimumNumberOfArcFractures,MaximumNumberOfArcFractures,
MOPixelToDrawWith,DrawJitter,MinimumDrawLengthMultiplier,MaximumDrawLengthMultiplier,DrawingQuality,
MOIToIgnore,FunctionToCallOnHitMO,p1,FunctionToCallOnHitTerrain,p2,FunctionToCallOnHitNothing,
p3,PassAllParameters)
Most parameter's names are self-explanatory so for now I'll focus only on some of them but if there would ever be proper release I'll write a detailed manual.
Minimum/MaximumDrawLengthMultiplier - Length Multiplier range for individual lines in resulting effect. This is responsible for these neat little branches of lightning. Set to 0+. If Min = Max the length would always be the same. If Min,Max=1 Lines would strictly fit into stream path.
DrawingQuality - How smooth the effect will be .Reasonable values 0 .. 1. 1 - draw 1 particle for each pixel. 2 - Skip every second particle and so on. One of the main ways of reducing lag is to tinker with this value and adjust particles lifetimes. It IS possible to create effects with almost no lag - just tinker with different settings.
MOPixelToDrawWith - Particle to draw with, yes, for now only MOPixels are allowed.
The things i like most:
FunctionToCallOnHitMO, p1
FunctionToCallOnHitTerrain, p2
FunctionToCallOnHitNothing, p3
PassAllParameters
You can define your own function or use one from the library for CastParticleStream to call on each of this occasions. For example Arc gun is set to ExplosionOnRootMO,nil,DoNothing,nil,DoNothing,nil this means that if it hits MO it calls ExplosionOnRootMO function which creates explosion right on RootMO of whatever it hit, otherwise it do nothing. To each of these functions CastParticleStream passes some variables + optionally p# + optionally all initial parameters of CastParticleStream
.
For now apart from base functions library contains
Stream presets and effects:
CastD9Lightning
CastTerrainDamagingLightning
CastDecorativeLightning
CastBeam
CastElectroBeam
LastPositionExplosion
ExplosionOnRootMO
Some exapmples.
If you are interested - download and see for yourself.
I want to tell so much more, describe all the ideas I have, but I think it will be enough for now. Lua to the masses!
P.S. I added the exclamation mark in the mod name to ensure that it loads before any mod that may use it so you don't have to integrate it.