Author Topic: Decreased damage which lifetime.  (Read 595 times)

Hello, I got a shotgun beening worked on and I what to get the damage to be lowered the longer it is alive.

This is how the theory goes.

When the project is created it gets simtime.

Code: [Select]
Spawn Time = 0

The max it can live too is 2 seconds.

Code: [Select]
DeathTime = 0 - 2000

Lets assume it gets hit half way through its life.

Code: [Select]
Damage = 10 - ((1000 - 0)/1000)*3

Which equals.

Code: [Select]
Damage = 7

If the lifetime 0

Code: [Select]
Damage = 10

If lifetime = 2000

Code: [Select]
Damage = 4

however. This is what I have and it doesn't work. I get console errors about missing function 'Onadd'

Code: [Select]
function Projectile::onadd(%obj,%a,%b)
{
Parent::onadd(%obj,%a,%b);
if(%obj.dataBlock $= "blunderbussprojectile")
{
%obj.spawntime = getsimtime();
}
}

function BlunderbussProjectile::Damage(%this,%obj,%col,%fade,%pos,%norm)
{
%obj.deathtime = getsimtime();
%obj.life = ((%obdeathtime - %obj.spawntime) / 1000) * 3;
echo(%obj.life);
%damage = %this.directdamage - %obj.life;
%col.damage(%obj,%pos,%damage,%this.directDamageType);
}


Since it's a shotgun that fires several pellets, you should be able to put it in the onFire code. (%p = new Projectile(){spawnTime = getSimTime();};)

Since it's a shotgun that fires several pellets, you should be able to put it in the onFire code. (%p = new Projectile(){spawnTime = getSimTime();};)

Awesome. Let me try that.

Works, however, when the projectile spawns from a brick it has no onfire script therefore gives huge -1000 damage.
« Last Edit: January 29, 2010, 03:52:45 PM by Choneis »

Check if(%projectile.spawnTime $= "") and make the damage a set value if it is.

Alternately, use the Projectile::onAdd method in the first post but package it.

Now the problem is in both, normal shooting and spawning. I was thinking of going back a few steps. And making it if the damage is < 0 it defaults to 7.

Code: [Select]
function BlunderBussImage::onFire(%this,%obj,%slot)
{
   
%projectile = %this.projectile;
%spread = 0.010;
%shellcount = getrandom(5,15);

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;
}

package Bluderbusspackage
{
function projectile::onAdd(%obj,%a,%b)
{
parent::onAdd(%obj,%a,%b);
if(%obj.dataBlock $= "BlunderBussProjectile")
{
%obj.spawntime = getsimtime();
}
}
};
activatePackage(BlunderBussPackage);

function BlunderbussProjectile::Damage(%this,%obj,%col,%fade,%pos,%norm)
{
%obj.deathtime = getsimtime();
%damage = 10 - ((%obj.deathtime - %obj.spawntime) / 1000 * 4);
echo("Damage :" SPC %damage);
if(%Damage < 0)
{
%damage = 1;
}
%col.damage(%obj,%pos,%damage,%this.directDamageType);

}