Author Topic: C4 Explosion  (Read 1102 times)

When i try to shoot a C4 it only damages the players around it, but not the player that shoot it.
Heres part of the code:
Code: [Select]
function GameConnection::C4Detonate(%client,%killer)
{
if(!isObject(%client.c4))
return;
if(!%killer)
%killer = %client;
cancel(%client.c4tick);
%pos = %client.c4.getTransform();
%p = new Projectile()
{
dataBlock = C4ExplosionP;
initialPosition  = %pos;
initialVelocity = "0 0 0";
client = %killer;
};
MissionCleanup.Add(%p);
%p.explode();
%client.c4Timer = 1;
if(%client.c4.getClassName() $= "StaticShape")
%client.c4.delete();
else
%client.c4 = "";
}
function ProjectileData::onCollision(%this,%obj,%col,%fade,%pos,%norm)
{
Parent::onCollision(%this,%obj,%col,%fade,%pos,%norm);
if(%col.getClassName() !$= "StaticShape")
return;
if(%obj.client.minigame != %col.client.minigame)
return;
if(%col.getDatablock() $= nametoid("C4Shape"))
{
if(%obj.client.player.getMountedImage(0).melee != 1)
{
%col.client.C4Detonate(%obj.client);
commandtoclient(%col.client,'clearbottomprint');
}
else
{
if(isEventPending(%col.client.c4tick))
{
%col.diffused = 1;
commandtoclient(%col.client,'clearbottomprint');
commandtoclient(%obj.client,'bottomprint',"\c4C4 bomb diffused.");
cancel(%col.client.c4tick);
%col.schedule(2000,delete);
}
}
return;
}
}



Well, mine damages the player that shoots it as well, if they are within the blast radius.  Or do you mean some type of recoil?

the problem is, it damages players within the radius except the player that shot it.

the problem is, it damages players within the radius except the player that shot it.
Well the link I posted leads to one that does damage the player who shot it (if in the radius), and anyone else within the blast radius.

   %p = new Projectile()
   {
      dataBlock = C4ExplosionP;
      initialPosition  = %pos;
      initialVelocity = "0 0 0";
      //client = %killer;
   };

Now it doesn't affect anyone.

I would remove the .explode() usage and instead give the projectile a very short lifetime (in the datablock) and set explodeOnDeath to true (also in the datablock) to best replicate the effect of a standard projectile. Setting the client of the projectile is also necessary to work out who is doing the damage, otherwise no damage is done to anything.

You should also be setting the sourceObject of the projectile - which is the player who spawned it (the physical player object ID).
« Last Edit: April 07, 2010, 02:35:11 PM by Ephialtes »


Works i heart you guys.