To make a weapon use raycasting, you put the script file Support_RaycastingWeapons.cs in with your Add-On (can be found in various places e.g. TF2 Basic Guns, Tier+Tactical), exec() it then add several of these attributes to the ShapeBaseImageData weapon you want to use it:
raycastWeaponRange - Required. The distance it fires for e.g. flashlight doesn't work at long distances.
raycastWeaponTargets - What it collides with. Use this to make it go through players and only shine on walls:
raycastWeaponTargets =
$TypeMasks::StaticObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::VehicleObjectType |
$TypeMasks::FXBrickObjectType;
raycastExplosionProjectile - A Projectile datablock. You cannot directly spawn "Explosion" objects for particles/lighting effects so if needed use a 10-20ms lifetime projectile.
raycastDirectDamage - Unimportant for a flashlight.
raycastDirectDamageType - Same.
raycastSpreadAmt - This causes the ray to have a random spread.
raycastSpreadCount - Number of rays to fire per shot.
raycastTracerProjectile - Optionally fires a different projectile datablock down the path of each shot.
This affects WeaponImage::onFire so if your gun uses a modified firing method (e.g. the Gun's "move hand up" animation) then you must call Parent::onFire(%this,%obj,%slot) or it won't work.
You can also adjust your weapon's ::onHitObject or ::onRaycastDamage functions (arguments %this,%obj,%slot,%col,%pos,%normal,%shotVec) similarly to Badspot's Projectile::onCollision/onDamage functions to have different effects on hit.
One thing is that the last flashlight made in this way (with a short-lived explosion with a light radius wherever you aimed it) kept flickering if there was any lag at all.