Full Script from States down:
// Initial start up state
stateName[0] = "Activate";
stateTimeoutValue[0] = 0.95;
stateTransitionOnTimeout[0] = "Ready";
stateSound[0] = M6Galilestar fisheSound;
stateSequence[0] = "use";
stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Charge1";
stateAllowImageChange[1] = true;
stateScript[1] = "onTriggerUp";
stateName[2] = "Charge";
stateTransitionOnTimeout[2] = "Fire";
stateSequence[2] = "chargeLaser";
stateTimeoutValue[2] = 2.72;
stateEmitter[2] = M6GalileanChargeEmitter;
stateEmitterTime[2] = 2.72;
stateEmitterNode[2] = "muzzleNode";
//stateSound[2] = M6GalileanChargeSound;
stateAllowImageChange[2] = false;
stateWaitForTimeout[2] = true;
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Cool";
stateTimeoutValue[3] = 0.75;
stateFire[3] = true;
stateAllowImageChange[3] = false;
stateSequence[3] = "fire";
stateWaitForTimeout[3] = true;
stateEmitter[3] = M6GalileanFlashEmitter;
stateEmitterTime[3] = 0.4;
stateEmitterNode[3] = "muzzleNode";
//stateSound[3] = M6GalileanFireSound;
stateScript[3] = "onFire";
stateName[4] = "Cool";
stateEmitter[4] = M6GalileanSteamEmitter;
stateEmitterTime[4] = 2;
stateEmitterNode[4] = "steamPoint";
stateTimeoutValue[4] = 2;
stateTransitionOnTimeout[4] = "Ready";
stateSequence[4] = "cool";
stateName[5] = "Charge1";
stateTransitionOnTimeout[5] = "TriggerChargeCheck1";
stateTimeoutValue[5] = 0.68;
stateFire[5] = true;
stateAllowImageChange[5] = false;
stateSequence[5] = "charge1";
stateWaitForTimeout[5] = true;
stateEmitter[5] = M6GalileanCharge1Emitter;
stateEmitterTime[5] = 0.72;
stateEmitterNode[5] = "muzzleNode";
//stateSound[5] = M6GalileanCharge1Sound;
stateScript[5] = "onChargeStart";
stateName[6] = "Charge2";
stateTransitionOnTimeout[6] = "TriggerChargeCheck2";
stateTimeoutValue[6] = 0.68;
stateAllowImageChange[6] = false;
stateSequence[6] = "charge2";
stateWaitForTimeout[6] = true;
stateEmitter[6] = M6GalileanCharge2Emitter;
stateEmitterTime[6] = 0.72;
stateEmitterNode[6] = "muzzleNode";
//stateSound[6] = M6GalileanCharge2Sound;
stateScript[6] = "onCharge";
stateName[7] = "Charge3";
stateTransitionOnTimeout[7] = "TriggerChargeCheck3";
stateTimeoutValue[7] = 0.52;
stateAllowImageChange[7] = false;
stateSequence[7] = "charge3";
stateWaitForTimeout[7] = true;
stateEmitter[7] = M6GalileanCharge3Emitter;
stateEmitterTime[7] = 0.56;
stateEmitterNode[7] = "muzzleNode";
//stateSound[7] = M6GalileanCharge3Sound;
stateScript[7] = "onCharge";
stateName[8] = "Charge4";
stateTransitionOnTimeout[8] = "TriggerChargeCheck4";
stateTimeoutValue[8] = 0.68;
stateAllowImageChange[8] = false;
stateSequence[8] = "charge4";
stateWaitForTimeout[8] = true;
stateEmitter[8] = M6GalileanCharge4Emitter;
stateEmitterTime[8] = 0.72;
stateEmitterNode[8] = "muzzleNode";
//stateSound[8] = M6GalileanCharge4Sound;
stateScript[8] = "onCharge";
stateName[9] = "TriggerChargeCheck1";
stateTransitionOnTimeout[9] = "soundKill";
stateTransitionOnTriggerDown[9] = "Charge2";
stateWaitForTimeout[9] = false;
stateScript[8] = "onCharge";
stateName[10] = "TriggerChargeCheck2";
stateTransitionOnTimeout[10] = "soundKill";
stateTransitionOnTriggerDown[10] = "Charge3";
stateWaitForTimeout[10] = false;
stateName[11] = "TriggerChargeCheck3";
stateTransitionOnTimeout[11] = "soundKill";
stateTransitionOnTriggerDown[11] = "Charge4";
stateWaitForTimeout[11] = false;
stateName[12] = "TriggerChargeCheck4";
stateTransitionOnTimeout[12] = "soundKill";
stateTransitionOnTriggerDown[12] = "Fire";
stateWaitForTimeout[12] = false;
stateName[13] = "soundKill";
stateTransitionOnTimeout[13] = "Ready";
stateWaitForTimeout[13] = false;
stateScript[13] = "onChargeCancel";
};
function M6GalileanImage::onFire(%this,%obj,%slot)
{
%pos = %obj.getTransform();
%random = getRandom(1,4);
switch(%random)
{
case 1:
%obj.playAudio(1, M6GalileanFire1Sound);
case 2:
%obj.playAudio(1, M6GalileanFire2Sound);
case 3:
%obj.playAudio(1, M6GalileanFire3Sound);
case 4:
%obj.playAudio(1, M6GalileanFire4Sound);
default:
echo("Error on M6 Galilean");
}
if(%this.raycastWeaponRange > 0)
{
// Directional Math
%fvec = %obj.getForwardVector();
%fX = getWord(%fvec,0);
%fY = getWord(%fvec,1);
%evec = %obj.getEyeVector();
%eX = getWord(%evec,0);
%eY = getWord(%evec,1);
%eZ = getWord(%evec,2);
%eXY = mSqrt((%eX * %eX) + (%eY * %eY));
%aimVec = (%fX * %eXY) SPC (%fY * %eXY) SPC %eZ;
// Range
%range = %this.raycastWeaponRange * getWord(%obj.getScale(), 2);
if(%range >= 100)
{
%rangeRem = %range - 100;
%range = 100;
}
// Raycast Parameters
%start = %obj.getEyePoint();
%end[0] = vectorAdd(%start, vectorScale(%aimVec, %range)); // [0] required for loop
%targets = %this.raycastWeaponTargets;
// Raycasting
%ray = ContainerRayCast(%start, %end[0], %targets, %obj);
%col = getWord(%ray, 0);
if(isObject(%col))
{
%pos = posFromRaycast(%ray);
%normal = normalFromRaycast(%ray);
%end[0] = %pos;
%colclass = %col.getClassName();
%objstuff++;
%this.onHitObject(%obj, %slot, %col, %pos, %normal, %objstuff);
if(%colclass $= "Player" || %colclass $= "AIPlayer")
{
if(%col.getState() $= "Dead")
{
%objsKilled++;
}
}
}
if(%rangeRem > 0)
{
for(%a = 1; %a <= 10 && %rangeRem > 0; %a++)
{
%range = %rangeRem;
if(%range >= 100)
{
%rangeRem = %range - 100;
%range = 100;
}
%start[%a] = %end[%a - 1];
%end[%a] = vectorAdd(%start[%a], vectorScale(%aimVec, %range));
%ray = ContainerRayCast(%start[%a], %end[%a], %targets, %obj);
%col = getWord(%ray, 0);
if(isObject(%col))
{
%pos = posFromRaycast(%ray);
%normal = normalFromRaycast(%ray);
%end[%a] = %pos;
%colclass = %col.getClassName();
%objstuff++;
%this.onHitObject(%obj, %slot, %col, %pos, %normal, %objstuff);
if(%colclass $= "Player" || %colclass $= "AIPlayer")
{
if(%col.getState() $= "Dead")
{
%objsKilled++;
}
}
if(%objstuff >= 9)
{
break;
}
}
}
}
if(%objsKilled >= 2 && isObject(%client = %obj.client))
{
commandToClient(%client, 'bottomPrint', "<color:00ff00>Nice Shot! <color:ffffff>" @ %objsKilled @ " birds, one stone.", 5);
}
}
else
{
return Parent::onFire(%this, %obj, %slot);
}
%projectile = "M6GalileanFlashProjectile";
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
function M6GalileanImageScoped::onHitObject(%this, %obj, %slot, %col, %pos, %normal, %objstuff)
{
if(%this.raycastDirectDamage > 0 && %col.getType() & ($TypeMasks::PlayerObjectType | $TypeMasks::VehicleObjectType))
{
if(miniGameCanDamage(%obj, %col) == 1 && !%col.getDatablock().indestructable)
{
if(%this.raycastDirectDamageType)
{
%damageType = %this.raycastDirectDamageType;
}
else
{
%damageType = $DamageType::Direct;
}
%scale = %obj.getScale();
%scaleFactor = (getWord(%scale, 0) + getWord(%scale, 1) + getWord(%scale, 2)) / 3;
%damFloat = mClampF(%this.raycastDirectDamage, -100, 100);
%directDamage = (%damFloat * %scaleFactor) / %objstuff;
%col.damage(%obj, %pos, %directDamage, %damageType);
}
}
if(isObject(%this.raycastExplosionProjectile))
{
%scale = %obj.getScale();
%scaleFactor = ((getWord(%scale, 0) + getWord(%scale, 1) + getWord(%scale, 2)) / 3) / %objstuff;
%p = new Projectile()
{
dataBlock = %this.raycastExplosionProjectile;
initialPosition = %pos;
initialVelocity = %normal;
sourceObject = %obj;
client = %obj.client;
sourceSlot = 0;
originPoint = %pos;
};
MissionCleanup.add(%p);
%p.setScale(%scaleFactor SPC %scaleFactor SPC %scaleFactor);
%p.explode();
}
if(isObject(%this.raycastExplosionSound))
{
serverplay3d(%this.raycastExplosionSound, %pos);
}
}
function M6GalileanImage::onCharge(%this,%obj,%slot)
{
%projectile = "M6GalileanTargetPainter";
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
function M6GalileanImage::onChargeStart(%this,%obj,%slot)
{
%obj.playAudio(1, M6GalileanCharge1Sound);
%projectile = "M6GalileanTargetPainter";
%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
function M6GalileanImage::onChargeCancel(%this, %obj, %slot)
{
%obj.stopAudio(1);
}
//### Mount on player
datablock ShapeBaseImageData(M6GalileanBackImage)
{
shapeFile = "./M6Galilean_Back.dts";
emap = true;
mountPoint = $BackSlot;
offset = "-0.4 -0.35 0";
eyeOffset = "0 0 10";
rotation = eulerToMatrix("65 0 90");
armReady = false;
doColorShift = false;
};
function M6GalileanImage::onMount(%this,%obj,%slot)
{
parent::onMount(%this,%obj,%slot);
if(%obj.getMountedImage(1).getName() $= "M6GalileanBackImage") { %obj.unMountImage(1); }
%obj.hidenode("RHand");
%obj.hidenode("LHand");
}
function M6GalileanImage::onUnMount(%this,%obj,%slot)
{
parent::onUnMount(%this,%obj,%slot);
%obj.unMountImage(1);
%obj.mountImage(M6GalileanBackImage,1);
%obj.unhidenode("RHand");
%obj.unhidenode("LHand");
}
function M6GalileanItem::onPickup(%this,%obj,%col,%a)
{
for(%i=0;%i<%col.getdatablock().maxTools;%i++)
{
%item = %col.tool[%i];
if(%item $= 0 || %item $= "")
{
%freeSlot = 1;
break;
}
}
if(%obj.canpickup && !isobject(%col.getmountedimage(1)) && %freeSlot) { %col.mountimage(M6GalileanBackImage,1); }
parent::onPickup(%this,%obj,%col,%a);
}
package M6GalileanPackage
{
function servercmdDropTool(%this,%slot)
{
if(isobject(%this.player.tool[%slot]) && %this.player.tool[%slot].getname() $= "M6GalileanItem")
{
parent::servercmdDropTool(%this,%slot);
if(isobject(%this.player.getmountedimage(1)) && %this.player.getmountedimage(1).getname() $= "M6GalileanBackImage") { %this.player.schedule(5,unmountimage,1); }
return;
}
parent::servercmdDropTool(%this,%slot);
}
};
activatepackage(M6GalileanPackage);