I'm pretty much just copypasting at this point. I have no clue what any of the things in the functions do.
function ImageData_NESL_Charge::onCharge(%this,%obj,%slot)
{
%obj.NESL_Charge_Time = getSimTime();
}
function ImageData_NESL_Charg::onFire(%this,%obj,%slot) //Why do I need an onFire in the first place?
{
%projectile = %this.projectile;
%spread = 0.0;
%shellcount = 1; //What is this?
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;
%x = 0.0;
%y = 0.0;
%z = 0.0;
%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;
}
function ProjectileData_NESL_Charge::damage(%this,%obj,%col,%fade,%pos,%normal)
{
%time = getSimTime() - %obj.NESL_Charge_Time;
if(%this.directDamage <= 0)
return;
%damageType = $DamageType::DmgType_NESL_Charge;;
if(%this.DirectDamageType)
%damageType = %this.DirectDamageType;
%scale = getWord(%obj.getScale(), 2);
%directDamage = mClampF(%this.directDamage, -100, 100) * %scale;
if(%col.getType() & $TypeMasks::PlayerObjectType)
{
%col.damage(%obj, %pos, %directDamage, %damageType);
}
else
{
%col.damage(%obj, %pos, %directDamage, %damageType);
}
if(%time < 5000) //Charged less than 5 seconds
{
%directDamage = %directDamage * %time / 1000; //If you charge less than 1s you do less dmg
%damageType = $DamageType::DmgType_NESL_Charge;
}
else
{
echo("This shouldn't be possible");
}
Parent::Damage(%this, %obj, %sourceObject, %position, %damage, %damageType);
}
function ImageData_NESL_Charge::onFireCharged(%this,%obj,%slot)
{
%projectile = ProjectileData_NESL_Charge_Charged;
}
You're making good progress, and at least you're trying to learn here. To answer your questions in the comments, you need an onFire so you can store the charge time on the projectile, so you can later check it when doing damage. The %shellCount is used in shotgun style weapons that fire multiple projectiles. You can see directly below it there's a loop, that contains all the actual projectile creation stuff, set to run %shellCount times. You can actually cut this stuff out, but it's not that big of a deal.
Now then, cut out your "%time = getSimTime() - %obj.NESL_Charge_Time;" from the damage function, and place it above those variables at the top of the onFire - at the very top of the method. Then what you do is add a new line to the projectile creation stuff (starting after "%p = new (%this.projectileType)()"), where we'll store %time on the projectile. Write this just like all the rest of the lines in that block, setting a new variable to %time. On to the damage function now.
First of all, you got an extra semicolon at the end of your %damageType line. Second - there's a line in the default damage function that actually forgets you over if you're trying to have a weapon do more than 100 damage: "%directDamage = mClampF(%this.directDamage, -100, 100) * %scale;" I have no idea why this was included, but replace it with "%directDamage = %this.directDamage * %scale;"
Now then, you'll want to retrieve your value for %time. In the context of the damage method, %obj is the projectile itself, so at the top of the method, set %time to %obj.something, where something is the name of the value you stored it to in the projectile creation above. You can now scale direct damage by %time. You have this written inside that if-else block, but as you noted, it shouldn't be possible to have one of the two conditions for it, for the block. Additionally, you already have %damageType set in place above, so you can scrap that line as well as if statement and else block. This leaves one line, the one where you actually scale the damage. Take it, and put it directly under the one we were working on a bit ago, where it gets scaled by the size of the projectile (%scale).
Finally, you'll want to remove the Parent::Damage line, otherwise you'll be calling the default damage function in addition to your own.
Last thing we need to handle is the charged projectile. There's actually a really easy way we can do that - and you sort of have the idea in place already in your onFireCharged. Look at the first onFire method, and note at the top, just after determining %time, it defines %projectile. You can use an if statement to define that conditionally. If time is less than 5000, define it just as it is now, but if it is greater than 5000, set it to your charged projectile. Then you can remove the onFireCharged method, and go back to your image datablock and set stateScript[5] to your single onFire method.
This will cause it to fire the charged projectile, but it looks like it's set to do 250 damage, which as we pointed out earlier, is forgeted over by the default damage implementation. You can fix this just by defining a damage method for your charged projectile, copying the same default damage script you put in the previous one, then doing that same line replacement of the mClampF I mentioned earlier.
Anyway, there's my step-by-step guide. Follow it as best you can and we'll see how it looks afterwards. If you have any more questions, ask.