Skip to content

Commit 4f5f7bd

Browse files
committed
client: implemented bullet tracer effect for weapon firing events
1 parent 58901a3 commit 4f5f7bd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

client/events/game_event_utils.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ GNU General Public License for more details.
1919
#include "r_efx.h"
2020
#include "event_api.h"
2121
#include "event_args.h"
22+
#include "pm_defs.h"
2223

2324
void GameEventUtils::EjectBrass(const Vector &origin, const Vector &angles, const Vector &velocity, int modelIndex, int soundType)
2425
{
@@ -29,6 +30,32 @@ void GameEventUtils::EjectBrass(const Vector &origin, const Vector &angles, cons
2930
2.5, modelIndex, soundType);
3031
}
3132

33+
void GameEventUtils::FireBullet(int entIndex, const matrix3x3 &camera, const Vector &origin, const Vector &direction, int tracerFreq)
34+
{
35+
pmtrace_t tr;
36+
Vector endPos = origin + direction * 8196.f;
37+
38+
gEngfuncs.pEventAPI->EV_SetUpPlayerPrediction(false, true);
39+
gEngfuncs.pEventAPI->EV_PushPMStates();
40+
gEngfuncs.pEventAPI->EV_SetSolidPlayers(entIndex - 1);
41+
gEngfuncs.pEventAPI->EV_SetTraceHull(2); // 2 is a point hull
42+
gEngfuncs.pEventAPI->EV_PlayerTrace(const_cast<float*>(&origin.x), endPos, PM_NORMAL, -1, &tr);
43+
CreateTracer(camera, origin, tr.endpos, tracerFreq);
44+
gEngfuncs.pEventAPI->EV_PopPMStates();
45+
}
46+
47+
void GameEventUtils::CreateTracer(const matrix3x3 &camera, const Vector &origin, const Vector &end, int frequency)
48+
{
49+
static int32_t count = 0;
50+
if (count % frequency == 0)
51+
{
52+
const Vector offset = Vector(0.f, 0.f, -4.f);
53+
Vector startPos = origin + offset + camera.GetRight() * -6.f + camera.GetForward() * 10.f;
54+
gEngfuncs.pEfxAPI->R_TracerEffect(startPos, const_cast<float*>(&end.x));
55+
}
56+
count++;
57+
}
58+
3259
void GameEventUtils::SpawnMuzzleflash()
3360
{
3461
cl_entity_t *ent = gEngfuncs.GetViewModel();

client/events/game_event_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ GNU General Public License for more details.
1515

1616
#pragma once
1717
#include "vector.h"
18+
#include "matrix.h"
1819

1920
namespace GameEventUtils
2021
{
2122
void EjectBrass(const Vector &origin, const Vector &angles, const Vector &velocity, int modelIndex, int soundType);
23+
void FireBullet(int entIndex, const matrix3x3 &camera, const Vector &origin, const Vector &direction, int tracerFreq);
24+
void CreateTracer(const matrix3x3 &camera, const Vector &origin, const Vector &end, int frequency);
2225
void SpawnMuzzleflash();
2326
}

client/events/glock_fire_event.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void CGlockFireEvent::Execute()
5757
Vector shellOrigin = GetOrigin() + up * -12.0f + forward * 20.0f + right * 4.0f;
5858

5959
GameEventUtils::EjectBrass(shellOrigin, GetAngles(), shellVelocity, brassModelIndex, TE_BOUNCE_SHELL);
60+
GameEventUtils::FireBullet(m_arguments->entindex, cameraMatrix, GetOrigin(), forward, 1);
6061
gEngfuncs.pEventAPI->EV_PlaySound( GetEntityIndex(), GetOrigin(), CHAN_WEAPON, "weapons/pl_gun3.wav", gEngfuncs.pfnRandomFloat(0.92, 1.0), ATTN_NORM, 0, 98 + gEngfuncs.pfnRandomLong(0, 3));
6162
}
6263

0 commit comments

Comments
 (0)