Projectile based Weapons
I have had several simple mod ideas that require projectile weapons like the crossbow or RPG, instead of the standard guns that hit or miss instantly. I will try to explore some of the possibilties in this article, all based on the crossbow code.
For now, the relevant code can all be found in the server side part of the crossbow code. This is found under hl -> source files -> HL2 DLL -> weapon_crossbow.cpp
Adding spread
Spread can be added rather quickly. The GetAutoAimVector used in other weapons appears to do no good here, so another approach is needed. I basically use the aiming vector converted to angles to change these angles, and then convert it back to the aiming vector. The relevant code is found in the CWeaponCrossbow::FireBolt method, the lines that need to be changed are:
594 - 595
QAngle angAiming; VectorAngles( vecAiming, angAiming );
these can be exchanged with:
QAngle angAiming; VectorAngles( vecAiming, angAiming ); angAiming.x += ((rand() % 250) / 100.0) * (rand() % 2 == 1 ? -1 : 1); angAiming.y += ((rand() % 250) / 100.0) * (rand() % 2 == 1 ? -1 : 1); AngleVectors(angAiming, &vecAiming);
This changes the x and y angles with up to 2.5 degrees in either direction. This actually results in a square spread instead of a cone, but at least it works. If anybody knows of a better approach, I would be happy to hear about it.