I tried changing my lego spear to throwing it on charged fire. I wanted it to unmount from your and on the charged fire so I simply added the unmount object script, but it gives me an error. I dont know enough about scripting yet to understand my mistake.
Heres the code:
function lkspImage::onChargedFire(%this,%obj,%slot)
{
if((%obj.lastFireTime+%this.minShotTime) > getSimTime())
return;
%obj.lastFireTime = getSimTime();
%obj.playThread(2, spearThrow);
%projectile = lkspchargeProjectile;
%spread = 0.0;
%shellcount = 1;
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 = lkspchargeProjectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
{
%obj.unMountImage(%slot);
};
MissionCleanup.add(%p);
}
return %p;
}
}
Heres the error:
Loading Add-On: Weapon_Legoknights (CRC:-876017223)
Add-Ons/Weapon_Legoknights/Weapon_lksp.cs Line: 254 - Syntax error.
>>> Some error context, with ## on sides of error halt:
^^%velocity = MatrixMulVector(%mat, %velocity);
^^%p = new (%this.projectileType)()
^^{
^^^dataBlock = lkspchargeProjectile;
^^^initialVelocity = %velocity;
^^^initialPosition = %obj.getMuzzlePoint(%slot);
^^^sourceObject = %obj;
^^^sourceSlot = %slot;
^^^client = %obj.client;
^^^{##
##
^^^^%obj.unMountImage(%slot);
^^^};
^^^MissionCleanup.add(%p);
^^}
^^return %p;
^}
}
>>> Error report complete.