Author Topic: getting what type of weapon damaged a player  (Read 1415 times)

I tried searching but nothing came up. Here is the code

Code: [Select]
package ninjad
{
function Armor::onDamage(%client,%killer,%type)
{
if(something pertaining to the weapon damage type is this = nSwordProjectile)
{
                //do other stuff
}
}
};

activatePackage(ninjad);

How do

Probably use this instead.

package YourPackage
{
   function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      Parent::damage(%this,%obj,%col,%fade,%pos,%normal); //Always include the parent if it already exists
      if(%this == nameToID(swordProjectile)) //Make sure the projectile data is the same as the one being checked, using ID's
      {
         //Stuff here
      }
   }
};
activatePackage(YourPackage);

Probably use this instead.

package YourPackage
{
   function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      Parent::damage(%this,%obj,%col,%fade,%pos,%normal); //Always include the parent if it already exists
      if(%this == nameToID(swordProjectile)) //Make sure the projectile data is the same as the one being checked, using ID's
      {
         //Stuff here
      }
   }
};
activatePackage(YourPackage);
I was trying to play a sound to everyone and message them when someone is killed by a certain weapon. Will this work for that purpose?

I was trying to play a sound to everyone and message them when someone is killed by a certain weapon. Will this work for that purpose?
Yes.
package YourPackage
{
   function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      Parent::damage(%this,%obj,%col,%fade,%pos,%normal); //Always include the parent if it already exists
      if(%this == nameToID(swordProjectile)) //Make sure the projectile data is the same as the one being checked, using ID's
      {
         %obj.customSound = SoundDatablock;
         %obj.lastWeapon = %this.uiName;
      }
   }
};
activatePackage(YourPackage);

Then using something like this:

function gameConnection::onDeath(%client,%obj,%killer,%type,%location)
   {
      serverPlay2D(%obj.customSound);
      messageAll(%client @ "was killed by " @ %obj.lastWeapon);
      parent::onDeath(%client,%obj,%killer,%type,%location);
   }


Make sure this is in a package too.

so the completed one looks like this?

Code: [Select]
package ninjad
{
   function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      Parent::damage(%this,%obj,%col,%fade,%pos,%normal); //Always include the parent if it already exists
      if(%this == nameToID(nSwordProjectile)) //Make sure the projectile data is the same as the one being checked, using ID's
      {
         %obj.customSound = nDeathSound;
         %obj.lastWeapon = %this.uiName;
      }
   }

function gameConnection::onDeath(%client,%obj,%killer,%type,%location)
   {
      serverPlay2D(%obj.customSound);
      messageAll(%client @ "was killed by " @ %obj.lastWeapon);
      parent::onDeath(%client,%obj,%killer,%type,%location);
   }
   
};
activatePackage(ninjad);

so the completed one looks like this?

Code: [Select]
package ninjad
{
   function ProjectileData::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      Parent::damage(%this,%obj,%col,%fade,%pos,%normal); //Always include the parent if it already exists
      if(%this == nameToID(nSwordProjectile)) //Make sure the projectile data is the same as the one being checked, using ID's
      {
         %obj.customSound = nDeathSound;
         %obj.lastWeapon = %this.uiName;
      }
   }

function gameConnection::onDeath(%client,%obj,%killer,%type,%location)
   {
      serverPlay2D(%obj.customSound);
      messageAll(%client @ "was killed by " @ %obj.lastWeapon);
      parent::onDeath(%client,%obj,%killer,%type,%location);
   }
   
};
activatePackage(ninjad);
Correct. I have found a few issues, but the mod will work fine, just will have a little of console errors, because what if the lastWeapon or customSound doesn't exist? I will fix this tomorrow. I have to go to bed.

Okay, back.

Here should be a better code.

package YourPackage
{
   function YourProjectileDatablock::damage(%this,%obj,%col,%fade,%pos,%normal)
   {
      %obj.customSound = SoundDatablock;
      %obj.lastWeapon = %this.uiName;
   }

   function gameConnection::onDeath(%client,%obj,%killer,%type,%location)
   {
      if(isObject(%obj.customSound)) //Does it exist?
         serverPlay2D(%obj.customSound);
      if(%obj.lastWeapon !$= "") //Is it not blank?
         messageAll(%client @ "was killed by " @ %obj.lastWeapon);
      Parent::onDeath(%client,%obj,%killer,%type,%location);
   }
};
activatePackage(YourPackage);
« Last Edit: December 12, 2013, 07:58:57 PM by Advanced Bot »

If your weapon uses a particular projectileData, then you can just swap out the projectileData:: part with the name of your projectile Datablock. This way it doesn't even need to be in a package.

function yourProjectileDatablock::damage(%this,%obj,%col,%fade,%pos,%normal)

Basically works the same way, but it's only called when that particular projectile deals damage, which removes the need for an if statement checking the type of projectile.

If your weapon uses a particular projectileData, then you can just swap out the projectileData:: part with the name of your projectile Datablock. This way it doesn't even need to be in a package.

function yourProjectileDatablock::damage(%this,%obj,%col,%fade,%pos,%normal)

Basically works the same way, but it's only called when that particular projectile deals damage, which removes the need for an if statement checking the type of projectile.
I was thinking of this way too, just wasn't sure if the args are the same, but I guess they are.

I will just edit my code. Thanks Pecon.