77 lines
3.5 KiB
Plaintext
77 lines
3.5 KiB
Plaintext
//Applies a row of visual effects from initial position to final
|
|
//position recursively, at a changeable frame rate and travel time
|
|
//use small visual effects for best results
|
|
//This function can be used with 3d vectors, and can generate an effect
|
|
//similar to the moving colored puffs in the Elemental ruins area in
|
|
//SoU chapter one.
|
|
void VFXTrace(vector vInitial, vector vFinal, float fTime, object oSource, int nVFX, float fRate= 2.0);
|
|
//DON'T USE THIS! It is an internal recursive function
|
|
void RecursiveVFX(vector vCurrent, vector vDiff, int nTimesLeft, int nVFX, float fDelay);
|
|
//This will generate a visual effect similar to a laser cutting
|
|
//beam tracing from the initial position to the final position
|
|
//The emitting object stays stationary, and may be a placeable or
|
|
//a creature. Adjust the travel time and frame rate to suit the
|
|
//distance travelled, or the beam will appear to jump. Frame rates
|
|
//higher than 2.0 do not work, as the created invisible object target
|
|
//needs time to appear
|
|
void BeamTrace(vector vInitial, vector vFinal, float fTime, object oSource, int nColor, float fRate= 2.0, int nNode=BODY_NODE_CHEST);
|
|
//DON'T USE THIS! It is an internal recursive function
|
|
void RecursiveBeam(vector vCurrent, vector vDiff, int nTimesLeft, object oSource, int nColor, float fDelay, int nNode);
|
|
|
|
//*****************************************************************************
|
|
//Now for the functions themselves...
|
|
|
|
void VFXTrace(vector vInitial, vector vFinal, float fTime, object oSource, int nVFX, float fRate= 2.0)
|
|
{
|
|
vector vdiff= vFinal-vInitial; //finding the relative position
|
|
int times= FloatToInt(fTime*fRate); //finding the number of times to recurse
|
|
float delay= 1.0/fRate; //finding the delay time
|
|
vector vdiff2;
|
|
vdiff2.x= vdiff.x/times; //finding the distance to move in the delay time
|
|
vdiff2.y= vdiff.y/times;
|
|
vdiff2.z= vdiff.z/times;
|
|
//Start the recursion!
|
|
AssignCommand(oSource, RecursiveVFX( vInitial, vdiff2, times, nVFX, delay));
|
|
}
|
|
|
|
void RecursiveVFX(vector vCurrent, vector vDiff, int nTimesLeft, int nVFX, float fDelay)
|
|
{
|
|
vCurrent+=vDiff; //update the current position by the difference
|
|
location lCurrent= Location(GetArea(OBJECT_SELF), vCurrent, GetFacing(OBJECT_SELF));
|
|
effect eVFX= EffectVisualEffect(nVFX);
|
|
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVFX, lCurrent, fDelay);
|
|
|
|
//now for the recursion...
|
|
nTimesLeft--;
|
|
if(nTimesLeft!=0)
|
|
DelayCommand(fDelay, RecursiveVFX( vCurrent, vDiff, nTimesLeft, nVFX, fDelay));
|
|
}
|
|
|
|
void BeamTrace(vector vInitial, vector vFinal, float fTime, object oSource, int nColor, float fRate= 2.0, int nNode= BODY_NODE_CHEST)
|
|
{
|
|
vector vdiff= vFinal-vInitial; //same idea as above function
|
|
int times= FloatToInt(fTime*fRate);
|
|
float delay= 1.0/fRate;
|
|
vector vdiff2;
|
|
vdiff2.x= vdiff.x/times;
|
|
vdiff2.y= vdiff.y/times;
|
|
vdiff2.z= vdiff.z/times;
|
|
|
|
RecursiveBeam( vInitial, vdiff2, times, oSource, nColor, delay, nNode);
|
|
}
|
|
|
|
void RecursiveBeam(vector vCurrent, vector vDiff, int nTimesLeft, object oSource, int nColor, float fDelay, int nNode)
|
|
{
|
|
vCurrent+=vDiff; //same idea as above function
|
|
location lCurrent= Location(GetArea(OBJECT_SELF), vCurrent, GetFacing(OBJECT_SELF));
|
|
effect eBeam= EffectBeam(nColor, oSource, nNode);
|
|
object oCreated= CreateObject(OBJECT_TYPE_PLACEABLE, "plc_invisobj", lCurrent); //error in name of item created
|
|
DestroyObject(oCreated, fDelay);
|
|
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oCreated, fDelay);
|
|
|
|
//now for the recursion...
|
|
nTimesLeft--;
|
|
if(nTimesLeft!=0)
|
|
DelayCommand(fDelay, RecursiveBeam( vCurrent, vDiff, nTimesLeft, oSource, nColor, fDelay, nNode));
|
|
}
|