Author Topic: Changing Projectile onCollision  (Read 1398 times)

I was a bit tired of seeing the regular gun shot do the same, boring Splat effect when it hit a wall, a player, a vehicle, basically everything. So I shamelessly looked and copy-pasted a few lines from Ephi's well written Flak Cannon that used a bit of what I needed for it's effects and I came up with this script:

Code: [Select]
function SensorFusedLProjectile::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
if(%col.getClassName() $= "Player")
%obj.setDataBlock(PlaySensorFusedLProjectile);
Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}

function SensorFusedLProjectile::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
if(%col.getClassName() $= "WheeledVehicle")
%obj.setDataBlock(VehiSensorFusedLProjectile);
Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}

(where SensorFusedLProjectile is the weapon's main projectile, what it fires)

Basically if the projectile hits a Player, it switches to another Projectile with different damage, impulse, explosion, etc. for a completely different effect (like flying chunks of plastic and whatnot). If the projectile hits a Wheeled Vehicle, like jeeps and stunt planes, it also switches out to yet another different projectile producing a shower of sparks and fancy fire explosions.

I know the Vehicle bit works, but I'm not too sure about the Player bit. Testing with zombies didn't work but the flak cannon also doesn't behave normally on zombies.

All I want to know is, do you think this works? Might there be an issue with the code? Or is there a neater way of presenting it? Also thanks again Ephi
« Last Edit: August 08, 2008, 07:12:24 PM by Muffinmix »

It wouldn't work because the second code is overwriting the first.
Code: [Select]
function SensorFusedLProjectile::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
if(%col.getClassName() $= "Player")
%obj.setDataBlock(PlaySensorFusedLProjectile);
else if(%col.getClassName() $= "WheeledVehicle")
%obj.setDataBlock(VehiSensorFusedLProjectile);
else if(%col.getClassName() $= "AiPlayer")
//set datablock for AI players here.
Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
}

You can use "else" more then once in a row? No wonder.

Also will the initial projectile stay the same if it hits none of the above?

Yes it would.
You could add:
else
   do something.
to have no condition.

Ah ok, thanks for all the help