Skip to content

Commit e92db96

Browse files
authored
Change flashlight parenting (#359)
* Change flashlight parenting Use the created viewmodel for better stability and range of motion. * Add a cvar
1 parent 58dc72f commit e92db96

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cfg/cs2fixes/cs2fixes.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cs2f_flashlight_transmit_others 0 // Whether to transmit other players' flashli
4040
cs2f_flashlight_brightness 1.0 // How bright should flashlights be
4141
cs2f_flashlight_distance 54 // How far flashlights should be from the player's head (the default is such that an equipped awp doesn't block the light if shadows are enabled)
4242
cs2f_flashlight_color "255 255 255 0" // What color to use for flashlights
43+
cs2f_flashlight_use_attachment 0 // Whether to parent flashlights to an attachment or a viewmodel (1=use attachment, 0=use viewmodel)
4344
cs2f_flashlight_attachment axis_of_intent // Which attachment to parent a flashlight to. If the player model is not properly setup, you might have to use clip_limit here instead
4445

4546
// Damage block settings

src/playermanager.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ CConVar<bool> g_cvarFlashLightTransmitOthers("cs2f_flashlight_transmit_others",
169169
CConVar<float> g_cvarFlashLightBrightness("cs2f_flashlight_brightness", FCVAR_NONE, "How bright should flashlights be", 1.0f);
170170
CConVar<float> g_cvarFlashLightDistance("cs2f_flashlight_distance", FCVAR_NONE, "How far flashlights should be from the player's head", 54.0f); // The minimum distance such that an awp wouldn't block the light
171171
CConVar<Color> g_cvarFlashLightColor("cs2f_flashlight_color", FCVAR_NONE, "What color to use for flashlights", Color(255, 255, 255));
172+
CConVar<bool> g_cvarFlashLightUseAttachment("cs2f_flashlight_use_attachment", FCVAR_NONE, "Whether to parent flashlights to an attachment or a viewmodel (1=use attachment, 0=use viewmodel)", false);
172173
CConVar<CUtlString> g_cvarFlashLightAttachment("cs2f_flashlight_attachment", FCVAR_NONE, "Which attachment to parent a flashlight to. If the player model is not properly setup, you might have to use clip_limit here instead", "axis_of_intent");
173174

174175
void ZEPlayer::SpawnFlashLight()
@@ -178,6 +179,13 @@ void ZEPlayer::SpawnFlashLight()
178179

179180
CCSPlayerPawn* pPawn = (CCSPlayerPawn*)CCSPlayerController::FromSlot(GetPlayerSlot())->GetPawn();
180181

182+
// Ensure custom viewmodel exists if needed
183+
if (!g_cvarFlashLightUseAttachment.Get())
184+
{
185+
if (!pPawn->m_pViewModelServices() || !GetOrCreateCustomViewModel(pPawn))
186+
return;
187+
}
188+
181189
Vector origin = pPawn->GetAbsOrigin();
182190
Vector forward;
183191
AngleVectors(pPawn->m_angEyeAngles(), &forward);
@@ -206,8 +214,19 @@ void ZEPlayer::SpawnFlashLight()
206214

207215
pLight->DispatchSpawn(pKeyValues);
208216

209-
pLight->SetParent(pPawn);
210-
pLight->AcceptInput("SetParentAttachmentMaintainOffset", g_cvarFlashLightAttachment.Get().String());
217+
if (g_cvarFlashLightUseAttachment.Get())
218+
{
219+
pLight->SetParent(pPawn);
220+
pLight->AcceptInput("SetParentAttachmentMaintainOffset", g_cvarFlashLightAttachment.Get().String());
221+
}
222+
else
223+
{
224+
CBaseViewModel* pViewModel = GetOrCreateCustomViewModel(pPawn);
225+
if (!pViewModel)
226+
return;
227+
228+
pLight->SetParent(pViewModel);
229+
}
211230

212231
SetFlashLight(pLight);
213232
}

0 commit comments

Comments
 (0)