//Glowsticks - server.cs
//Anybody
//Projectile
datablock ProjectileData(GlowstickProjectile)
{
projectileShapeName = "./GlowstickProjectile.dts";
directDamage = 0;
muzzleVelocity = 10;
velInheritFactor = 0.2;
armingDelay = 1000;
lifetime = 1000;
fadeDelay = 10;
bounceElasticity = 0.2;
isBallistic = true;
gravityMod = 0.5;
explodeOnDeath = false;
hasLight = true;
lightRadius = 4;
lightColor = "0 1 0";
hasWaterLight = true;
waterLightColor = "0 1 0.5";
};
//Item on brick
datablock ItemData(GlowsticksItem)
{
category = "Weapon";
className = "Weapon";
shapeFile = "./Glowsticks.dts";
rotate = false;
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;
uiName = "Glowsticks";
iconName = "./GlowstickIcon.png";
doColorShift = false;
image = GlowsticksImage;
canDrop = true;
};
//Item in hand
datablock ShapeBaseImageData(GlowsticksImage)
{
shapeFile = "./Glowsticks.dts";
emap = true;
mountPoint = 0;
offset = "0 0 0";
eyeOffset = "0 0 0";
item = GlowsticksItem;
ammo = " ";
projectile = GlowstickProjectile;
projectileType = Projectile;
className = "WeaponImage";
armReady = true;
doColorShift = false;
//States
stateName[0] = "Active";
stateTimeoutValue[0] = 0.10;
stateTransitionOnTimeout[0] = "Ready";
stateName[1] = "Ready";
stateTransitionOnTrigerDown[1] = "Fire";
stateAllowImageChange[1] = true;
stateTimeoutValue[1] = 0.01;
stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "Done";
stateTimeoutValue[2] = 0.14;
stateFire[2] = true;
stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateWaitForTimeout[2] = true;
stateName[3] = "Done";
stateScript[3] = "onDone";
};
//This piece of code is directly from Ephialtes' shotgun
function GlowsticksImage::onFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
%obj.setVelocity(VectorAdd(%obj.getVelocity(),VectorScale(%obj.client.player.getEyeVector(),"-3")));
%obj.playThread(2, shiftAway);
%projectile = %this.projectile;
%spread = 0.0015;
%shellcount = 3;
for(%shell=0; %shell<%shellcount; %shell++)
{
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%y = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%z = (getRandom() - 0.5) * 10 * 3.1415926 * %spread;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);
%velocity = MatrixMulVector(%mat, %velocity);
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
}
return %p;
}
//This one is from Ephialtes', The Geek's and Pload's High-Explosive Grenade
function GlowsticksImage::onDone(%this,%obj,%slot)
{
%obj.unMountImage(%slot);
}
//All credit where credit is due!
I think it's because of my crappy states but then again I can't find anything wrong with them.