- Joined
- Apr 9, 2013
- Messages
- 101
- Reaction score
- 83
Hey guys i've implemented toggleable flashlights and i show you how you can do it too
.
It don't switches off for other ppl. so its not synched over network!
Any help with the netcode is very much appreciated
#Update 1: I forgot to check if the flashlight is on and only switch it on/off when its on or off. make sure to update your code inside the Weapon.cpp : Line 675. Or it spamms with turning the flashlight on or off.
Project: Eclipse Studio
Weapon.h : Line 164
Weapon.h : Line 202
Weapon.cpp : Line 240
Weapon.cpp : Line 642
Weapon.cpp : Line 675
AI_Player.CPP : Line 2016
WeaponConfig.h : Line 123
r3dInput.h : Line 295
r3dInput.cpp : Line 1002
r3dInput.cpp : Line 1049
That should be it. Now Recompile and you should be able to Toggle the Flashlight ingame with the F key.
It don't switches off for other ppl. so its not synched over network!
Any help with the netcode is very much appreciated
#Update 1: I forgot to check if the flashlight is on and only switch it on/off when its on or off. make sure to update your code inside the Weapon.cpp : Line 675. Or it spamms with turning the flashlight on or off.
Project: Eclipse Studio
Weapon.h : Line 164
Find:
Add below:
Code:
int m_triggerPressed; // for how many shots trigger is pressed
Code:
// ultraporing - flashlight toggle bool
bool m_flashlightToggle;
Weapon.h : Line 202
Find:
Add below:
Code:
void reloadMuzzleParticle();
Code:
void toggleFlashlight(); // ultraporting - toggle the flashlight
Weapon.cpp : Line 240
Find:
Add below:
Code:
,m_triggerPressed(0)
Code:
,m_flashlightToggle(true)
Weapon.cpp : Line 642
Find this function:
Add this function below:
Code:
void Weapon::switchFiremode()
Code:
void Weapon::toggleFlashlight()
{
m_flashlightToggle = !m_flashlightToggle;
}
Weapon.cpp : Line 675
Find this:
Add this if statement below:
So it looks like this:
Code:
void Weapon::Update(const D3DXMATRIX& weaponBone)
{
R3DPROFILE_FUNCTION("Weapon::Update");
obj_Player* player = (obj_Player*)m_Owner;
if(!m_isMeshLoaded)
{
m_isMeshLoaded = isLoaded();
if(m_isMeshLoaded)
{
m_pConfig->updateMuzzleOffset(g_camera_mode->GetInt()==2 && player->NetworkLocal);
if(g_camera_mode->GetInt()==2 && player->NetworkLocal)
checkForSkeleton();
}
}
Code:
if (m_flashlightToggle && !m_Flashlight.IsOn())
{
if( m_FlashlightParticle )
{
m_FlashlightParticle->ObjFlags &= ~OBJFLAG_SkipDraw;
m_Flashlight.TurnOn();
}
}
else if (!m_flashlightToggle && m_Flashlight.IsOn())
{
if( m_FlashlightParticle )
{
m_FlashlightParticle->ObjFlags |= OBJFLAG_SkipDraw;
m_Flashlight.TurnOff();
}
}
Code:
void Weapon::Update(const D3DXMATRIX& weaponBone)
{
R3DPROFILE_FUNCTION("Weapon::Update");
obj_Player* player = (obj_Player*)m_Owner;
if(!m_isMeshLoaded)
{
m_isMeshLoaded = isLoaded();
if(m_isMeshLoaded)
{
m_pConfig->updateMuzzleOffset(g_camera_mode->GetInt()==2 && player->NetworkLocal);
if(g_camera_mode->GetInt()==2 && player->NetworkLocal)
checkForSkeleton();
}
}
if (m_flashlightToggle && !m_Flashlight.IsOn()) {
if( m_FlashlightParticle )
{
m_FlashlightParticle->ObjFlags &= ~OBJFLAG_SkipDraw;
m_Flashlight.TurnOn();
}
}
else if (!m_flashlightToggle && m_Flashlight.IsOn())
{
if( m_FlashlightParticle )
{
m_FlashlightParticle->ObjFlags |= OBJFLAG_SkipDraw;
m_Flashlight.TurnOff();
}
}
r3dPoint3D muzzlerPoint = getMuzzlePos(weaponBone);
AI_Player.CPP : Line 2016
Find this:
Add this below:
Code:
if(needExit)
{
if(!wpnIsNoLongerAvailable)
wpn->isReadyToFire(false, false); // very important to call ready to fire with false to reset internal counter of how long trigger was pressed
return;
}
Code:
if(wpn->getItemID() == WeaponConfig::ITEMID_Flashlight)
{
if (InputMappingMngr->wasReleased(r3dInputMappingMngr::KS_TOGGLE_FLASHLIGHT))
{
wpn->toggleFlashlight();
}
}
WeaponConfig.h : Line 123
Find:
Add below:
Code:
ITEMID_PieceOfPaper = 101305, // used to create world notes
Code:
ITEMID_Flashlight = 101306, // ultraporing - flashlight
r3dInput.h : Line 295
Find:
Add below:
Code:
KS_SHOW_PLAYERS,
Code:
KS_TOGGLE_FLASHLIGHT, // ultraporing - flashlight key
r3dInput.cpp : Line 1002
Find:
Add below:
Code:
m_Mapping[KS_SHOW_PLAYERS] = KeyboardMapping(INPUTMAP_KEYBOARD, kbsTab, "$HUD_Cntrl_ShowPlayers");
Code:
m_Mapping[KS_TOGGLE_FLASHLIGHT] = KeyboardMapping(INPUTMAP_KEYBOARD, kbsF, "$HUD_Cntrl_Toggle_Flashlight");
r3dInput.cpp : Line 1049
Find:
Change the number to one higher, if you have = 4 then change it to 5:
Code:
static const int INPUT_MAPPING_FILE_VERSION = 4;
Code:
static const int INPUT_MAPPING_FILE_VERSION = 5;
That should be it. Now Recompile and you should be able to Toggle the Flashlight ingame with the F key.
Last edited:

