Author Topic: How do I get critical hits/headshots to work on T+T?  (Read 790 times)


Also, does anyone know where I can find an add-on that clears tools when a player tries to drop them (aka they do ctrl-w and the item is immediately wiped from all existence rather than being dropped for other players to pick it up)? I used to have something like this years ago but not anymore...

the latter addon appears to be easy to make

the title addon can be done with a bunch of copypasta. take a look at the sport rifle.cs, all the way at the bottom:

function SportRifleWeakProjectile::damage(%this,%obj,%col,%fade,%pos,%normal)
{
   if(%this.directDamage <= 0)
      return;

   %damageType = $DamageType::Direct;
   if(%this.DirectDamageType)
      %damageType = %this.DirectDamageType;

   %scale = getWord(%obj.getScale(), 2);
   %directDamage = 24;
   %damage = %directDamage;

   %sobj = %obj.sourceObject;
   if(%sobj.getType() & $TypeMasks::PlayerObjectType)
   {
      if(isObject(%sobj.client))
         %sobj.client.play2d(bulletHitSound);
   }
   
   if(%col.getType() & $TypeMasks::PlayerObjectType)
   {
      %colscale = getWord(%col.getScale(),2);
      if(getword(%pos, 2) > getword(%col.getWorldBoxCenter(), 2) - 3.3*%colscale)
      {
         %directDamage = %directDamage * 2;
         %damageType = $DamageType::SportRifleHeadshot;
         
         %col.spawnExplosion(critProjectile,%colscale);
         if(isObject(%col.client))
            %col.client.play2d(critRecieveSound);
         
         if(%sobj.getType() & $TypeMasks::PlayerObjectType)
         {
            serverplay3d(critFireSound,%sobj.getHackPosition());
            if(isObject(%sobj.client))
               %sobj.client.play2d(critHitSound);
         }
      }
     
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }
   else
   {
      %col.damage(%obj, %pos, %directDamage, %damageType);
   }
}

Just copy-paste that into any bullet weapon you want to have critical hits for, then replace "SportRifleWeakProjectile" with the projectile the gun is shooting (ex: GunProjectile). Adjust the critical hit bonus damage in the line %directdamage = %directdamage * 2; by changing 2 to some other value.
Make sure CritHitSound and CritReceiveSound and CritProjectile are existing datablocks - if you have any weapon with criticals enabled these datablocks should exist; otherwise, copy-paste the datablocks from them into your custom weapon (which you should do if you are releasing this so you don't have dependencies)

Also, does anyone know where I can find an add-on that clears tools when a player tries to drop them (aka they do ctrl-w and the item is immediately wiped from all existence rather than being dropped for other players to pick it up)? I used to have something like this years ago but not anymore...
I'm sure it exists. I just can't find it.

don't you need the emote_criticalhit addon for it to work in the first place?

Just copy-paste that into any bullet weapon you want to have critical hits for, then replace "SportRifleWeakProjectile" with the projectile the gun is shooting (ex: GunProjectile). Adjust the critical hit bonus damage in the line %directdamage = %directdamage * 2; by changing 2 to some other value.
Make sure CritHitSound and CritReceiveSound and CritProjectile are existing datablocks - if you have any weapon with criticals enabled these datablocks should exist; otherwise, copy-paste the datablocks from them into your custom weapon (which you should do if you are releasing this so you don't have dependencies)
revise this to
enable emote_criticalhit so it exists.

don't you need the emote_criticalhit addon for it to work in the first place?
yeah. but thats really only for the critical animations/sounds which can be replaced. you'd have to enable it alongside adding the code i pasted into the addon you want critical hits for.

never mind, i got critical hits working. all i needed was emote_criticalhit