Author Topic: Dynamically making 63 different colored projectiles or trails  (Read 888 times)

Code: [Select]
//explosion
datablock AudioProfile(combo1)
{
filename = "./sounds/combo1.wav";
description = AudioClosest3d;
preload = true;
};
datablock AudioProfile(combo2:combo1) { filename = "./sounds/combo2.wav"; };
datablock AudioProfile(combo3:combo1) { filename = "./sounds/combo3.wav"; };
datablock AudioProfile(combo4:combo1) { filename = "./sounds/combo4.wav"; };
datablock AudioProfile(combo5:combo1) { filename = "./sounds/combo5.wav"; };
datablock AudioProfile(takeProjExplode:combo1) { filename = "./sounds/explode.wav"; };
datablock AudioProfile(takeProjHit:combo1) { filename = "./sounds/hit.wav"; };
datablock AudioProfile(takeProjFire:combo1) { filename = "./sounds/fire.wav"; };

datablock ParticleData(takeGameProjExplosionParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = -0.0;
inheritedVelFactor   = 0.0;
constantAcceleration = 0.0;
lifetimeMS           = 700;
lifetimeVarianceMS   = 300;
textureName          = "base/data/particles/dot";
spinSpeed      = 0;
spinRandomMin     = 0;
spinRandomMax     = 0;
colors[0]     = "1 1 1 0.1";
colors[1]     = "1 1 1 0.5";
colors[2]     = "1 1 1 1";
sizes[0]      = 2;
sizes[1]      = 2;
sizes[2]      = 2;

times[0] = 0;
times[1] = 0.1;
times[2] = 0.2;

useInvAlpha = false;
};

datablock ParticleEmitterData(takeGameProjExplosionEmitter)
{
lifeTimeMS = 500;

ejectionPeriodMS = 1;
periodVarianceMS = 0;
ejectionVelocity = 15;
velocityVariance = 8.0;
ejectionOffset   = 1.25;
thetaMin         = 0;
thetaMax         = 180;
phiReferenceVel  = 0;
phiVariance      = 360;
overrideAdvance = false;
particles = "takeGameProjExplosionParticle";

uiName = "takeGameProj Explosion";
};
datablock ExplosionData(takeGameProjExplosion)
{
//explosionShape = "";
lifeTimeMS = 500;

emitter[0] = takeGameProjExplosionEmitter;

soundProfile = takeProjExplode;

faceViewer     = true;
explosionScale = "1 1 1";

shakeCamera = true;
camShakeFreq = "2.0 2.0 2.0";
camShakeAmp = "1.0 1.0 1.0";
camShakeDuration = 0.5;
camShakeRadius = 10.0;

// Dynamic light
lightStartRadius = 3;
lightEndRadius = 1;
lightStartColor = "00.0 0.6 0.9";
lightEndColor = "0 0 0";
};

//bullet trail effects
datablock ParticleData(takeGameProjTrailParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = -0.0;
inheritedVelFactor   = 0.0;
constantAcceleration = 0.0;
lifetimeMS           = 15000;
lifetimeVarianceMS   = 0;
textureName          = "base/data/particles/dot";
spinSpeed      = 0;
spinRandomMin     = 0;
spinRandomMax     = 0;
colors[0]     = "1 1 1 1";
colors[1]     = "1 1 1 1";
colors[2]     = "1 1 1 1";
sizes[0]      = 4;
sizes[1]      = 4;
sizes[2]      = 4;

times[0] = 0;
times[1] = 0;
times[2] = 0;

useInvAlpha = false;
};
datablock ParticleEmitterData(takeGameProjTrailEmitter)
{
ejectionPeriodMS = 2;
periodVarianceMS = 0;
ejectionVelocity = 0.0;
velocityVariance = 0.0;
ejectionOffset   = 0.0;
thetaMin         = 0;
thetaMax         = 90;
phiReferenceVel  = 0;
phiVariance      = 360;
overrideAdvance = false;
particles = "takeGameProjTrailParticle";

uiName = "takeGameProj Trail";
};


datablock ProjectileData(takeGameProjProjectile)
{
projectileShapeName = "base/data/shapes/empty.dts";
directDamage        = 0;
directDamageType    = $DamageType::Default;
radiusDamageType    = $DamageType::Default;
classname = "takeGameProjProjectileClass";


impactImpulse       = 0;
verticalImpulse     = 0;
explosion           = takeGameProjExplosion;
bloodExplosion        = takeGameProjExplosion;
particleEmitter       = takeGameProjTrailEmitter;
explodeOnPlayerImpact = false;
explodeOnDeath        = true;

   brickExplosionRadius = 0;
   brickExplosionImpact = 0;             //destroy a brick if we hit it directly?
   brickExplosionForce  = 0;            
   brickExplosionMaxVolume = 0;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 0;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

   sound = "";

   muzzleVelocity      = 65;
   velInheritFactor    = 1.0;

   armingDelay         = 15000;
   lifetime            = 15000;
   fadeDelay           = 14500;
   bounceElasticity    = 0.99;
   bounceFriction      = 0.00;
   isBallistic         = true;
   gravityMod          = 0.0;

hasLight    = false;
lightRadius = 3.0;
lightColor  = "0 0 0.5";

uiName = "takeGameProj";
};

function createDynamicTGProjectiles() {
for(%i=1;%i<64;%i++) {
%string[0] = "datablock ParticleData(takeGameProjTrailParticle" @ %i @ " : takeGameProjTrailParticle) { colors[0] = colors[1] = colors[2] = \"" @ getColorIDTable(%i) @ "\"; };";
%string[1] = "datablock ParticleEmitterData(takeGameProjTrailEmitter" @ %i @ " : takeGameProjTrailEmitter) { particles = \"takeGameProjTrailParticle" @ %i @ "\"; };";
%string[2] = "datablock ProjectileData(takeGameProjProjectile" @ %i @ " : takeGameProjProjectile) { particleEmitter = \"takeGameProjTrailEmitter" @ %i @ "\"; };";
for(%j=0;%j<3;%j++) {
echo(%string[%j]);
}
//eval()
}
//datablock ParticleData("takeGameProjTrailParticle" @ %i : takeGameProjTrailParticle) {
// colors[0] = colors[1] = colors[2] = getColorIDTable(%i);
//};
//datablock ParticleEmitterData("takeGameProjTrailEmitter" @ %i : takeGameProjTrailEmitter) {
// particles = "takeGameProjTrailParticle" @ %i;
//};
//datablock ProjectileData("takeGameProjProjectile" @ %i : takeGameProjProjectile) {
// particleEmitter = "takeGameProjTrailEmitter" @ %i;
//};
}
createDynamicTGProjectiles();

package takeGameProjPackage {
function Projectile::onAdd(%this,%obj) {
%obj.client.projectile = %obj;
return parent::onAdd(%this,%obj);
}
};
activatePackage(takeGameProjPackage);

function takeGameProjProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
if(%col.getType() & $TypeMasks::FXBrickObjectType) {
if(!isObject(%obj.client)) {
return;
}
if(!isObject(%obj.client.minigame)) {
return;
}
%client = %obj.client;

if(%col.takenBy != %client) {
%obj.combo++;
if(%obj.combo >= 5) {
$DefaultMinigame.messageAll('',"\c4" @ %client.name SPC "\c6obtained a\c3 x" @ %obj.combo SPC "combo!");
%sound = "combo" @ %obj.combo-4;
if(!isObject(%sound)) {
%sound = "combo5";
}
$DefaultMinigame.playSound(%sound);
}
%client.play2D(takeProjHit);
%col.playSound(takeProjHit);
}

%col.takenBy = %client;
%col.setColor(%client.color);
}
}

function takeGameProjProjectile::onExplode(%this,%obj) {
%obj.client.play2D(takeProjExplode);
}

I'm trying to create different colored projectiles that will use a defined color in the colorset from a client variable (e.g. %client.color = 12, so it would fire a projectile with that color and only that color).

I'm looking at the paint can projectiles as a base, and noticed they all use the same class name. So I figured I could do the same, but I can't? I get this when creating the initial datablock the dynamic ones are using as a base.
Error: Cannot change namespace parent linkage for takeGameProjProjectile from ProjectileData to takeGameProjProjectileClass
I searched the error here and only came up with results saying "try using a different name, you're using the same name somewhere else," but this isn't used anywhere else.

I assumed I could also just set the state of an emitter and just define 63 colors[##] variables, but it looks like I can't do that either.

pls help

edit: clarified to mention trails are ok too, namely takeGameProjTrailParticle
« Last Edit: April 04, 2015, 05:34:03 PM by TheBlackParrot »

Like this:
Code: [Select]
for(%i = 0; %i < %maxFlagColors; %i ++)
{
%color = getColorIDTable(%i);
datablock ItemData(flagItem)
{
className = slyrCTF_FlagItem;

shapeFile = $Slayer::Server::CTF::flagShapeFile[$Slayer::Server::CTF::flagModel];
uiName = "";

doColorShift = true;
colorShiftColor = %color;
colorID = %i;
};
flagItem.setName("slyrCTF_Flag" @ %i @ "Item");
}

I don't need an item though, unless I need one to change the color
I'm looking specifically at takeGameProjTrailParticle

It's an example. That will work for any type of datablock. The className field is the generic class for all of your datablocks.

Also, notice how I changed the name of the datablock to allow for dynamic creation.
« Last Edit: April 04, 2015, 05:51:24 PM by Greek2me »

Still getting namespace parent errors
Error: cannot change namespace parent linkage for TempTGDatablock from ParticleEmitterData to takeGameProjProjectileClass.
edit: it's using the wrong thing from the looks of the error actually, what the hell

Code: [Select]
function createDynamicTGProjectiles() {
for(%i=1;%i<64;%i++) {
datablock ParticleData(TempTGDatablock) {
dragCoefficient      = 3;
gravityCoefficient   = -0.0;
inheritedVelFactor   = 0.0;
constantAcceleration = 0.0;
lifetimeMS           = 15000;
lifetimeVarianceMS   = 0;
textureName          = "base/data/particles/dot";
spinSpeed      = 0;
spinRandomMin     = 0;
spinRandomMax     = 0;
sizes[0]      = 4;
sizes[1]      = 4;
sizes[2]      = 4;

times[0] = 0;
times[1] = 0;
times[2] = 0;

useInvAlpha = false;

colors[0] = getColorIDTable(%i);
colors[1] = getColorIDTable(%i);
colors[2] = getColorIDTable(%i);
};
TempTGDatablock.setName("takeGameProjTrailParticle" @ %i);

datablock ParticleEmitterData(TempTGDatablock) {
ejectionPeriodMS = 2;
periodVarianceMS = 0;
ejectionVelocity = 0.0;
velocityVariance = 0.0;
ejectionOffset   = 0.0;
thetaMin         = 0;
thetaMax         = 90;
phiReferenceVel  = 0;
phiVariance      = 360;
overrideAdvance = false;
particles = "takeGameProjTrailParticle" @ %i;

uiName = "takeGameProj Trail";
};
TempTGDatablock.setName("takeGameProjTrailEmitter" @ %i);

datablock ProjectileData(TempTGDatablock) {
projectileShapeName = "base/data/shapes/empty.dts";
directDamage        = 0;
directDamageType    = $DamageType::Default;
radiusDamageType    = $DamageType::Default;
className = "takeGameProjProjectileClass";


impactImpulse       = 0;
verticalImpulse     = 0;
explosion           = takeGameProjExplosion;
bloodExplosion        = takeGameProjExplosion;
particleEmitter = "takeGameProjTrailEmitter" @ %i;
explodeOnPlayerImpact = false;
explodeOnDeath        = true;

brickExplosionRadius = 0;
brickExplosionImpact = 0;             //destroy a brick if we hit it directly?
brickExplosionForce  = 0;            
brickExplosionMaxVolume = 0;          //max volume of bricks that we can destroy
brickExplosionMaxVolumeFloating = 0;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

sound = "";

muzzleVelocity      = 65;
velInheritFactor    = 1.0;

armingDelay         = 15000;
lifetime            = 15000;
fadeDelay           = 14500;
bounceElasticity    = 0.99;
bounceFriction      = 0.00;
isBallistic         = true;
gravityMod          = 0.0;

hasLight    = false;
lightRadius = 3.0;
lightColor  = "0 0 0.5";

uiName = "takeGameProj";
};
TempTGDatablock.setName("takeGameProjProjectile" @ %i);
}
}
createDynamicTGProjectiles();

Changing TempTGDatablock to TempTGDatablock1/ and etc. fixed it, thanks Greek.