[TuT] Toggleable Flashlight - DNC Community Release

Status
Not open for further replies.
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
Find:
Code:
int m_triggerPressed; // for how many shots trigger is pressed
Add below:
Code:
// ultraporing - flashlight toggle bool
bool m_flashlightToggle;

Weapon.h : Line 202
Find:
Code:
void reloadMuzzleParticle();
Add below:
Code:
void toggleFlashlight(); // ultraporting - toggle the flashlight

Weapon.cpp : Line 240
Find:
Code:
,m_triggerPressed(0)
Add below:
Code:
,m_flashlightToggle(true)

Weapon.cpp : Line 642
Find this function:
Code:
void Weapon::switchFiremode()
Add this function below:
Code:
void Weapon::toggleFlashlight()
{
    m_flashlightToggle = !m_flashlightToggle;
}

Weapon.cpp : Line 675
Find 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();
        }
    }
Add this if statement below:
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();
		}
	}
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();
        }
    }


     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:
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;
    }
Add this below:
Code:
if(wpn->getItemID() == WeaponConfig::ITEMID_Flashlight)
    {
        if (InputMappingMngr->wasReleased(r3dInputMappingMngr::KS_TOGGLE_FLASHLIGHT))
        {
            wpn->toggleFlashlight();
        }
    }

WeaponConfig.h : Line 123
Find:
Code:
ITEMID_PieceOfPaper = 101305,    // used to create world notes
Add below:
Code:
ITEMID_Flashlight = 101306, // ultraporing - flashlight

r3dInput.h : Line 295
Find:
Code:
KS_SHOW_PLAYERS,
Add below:
Code:
KS_TOGGLE_FLASHLIGHT, // ultraporing - flashlight key

r3dInput.cpp : Line 1002
Find:
Code:
m_Mapping[KS_SHOW_PLAYERS] =        KeyboardMapping(INPUTMAP_KEYBOARD, kbsTab, "$HUD_Cntrl_ShowPlayers");
Add below:
Code:
m_Mapping[KS_TOGGLE_FLASHLIGHT] = KeyboardMapping(INPUTMAP_KEYBOARD, kbsF, "$HUD_Cntrl_Toggle_Flashlight");

r3dInput.cpp : Line 1049
Find:
Code:
static const int INPUT_MAPPING_FILE_VERSION = 4;
Change the number to one higher, if you have = 4 then change it to 5:
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:
Ultraporing

can u post your Weapon.cpp for me ?
i think i make it error . for me compiled sucess but dont work in game *-*
i think error is in Weapon.cpp

can u post it thx for u post
 
Last edited:
Error 1 error C2447: '{' : missing function header (old-style formal list?) c:\WarZ\src\EclipseStudio\Sources\ObjectsCode\WEAPONS\Weapon.cpp 648 Eclipse Studio


?
 
Ultraporing
now with u mega file compiled sucess but dont work with F o.o

can u post all this files ? PLS *-*
 
Last edited:
Ultraporing
now with u mega file compiled sucess but dont work with F o.o

can u post all this files ? PLS *-*

This could have a couple of reasons.
You could messed up while implementing the actual Key in the:
r3dInput.h : Line 295
r3dInput.cpp : Line 1002
r3dInput.cpp : Line 1049

Or your flashlight ID is a other one, make sure you enter here the right id:
WeaponConfig.h : Line 123
Also you have to do a clean build or the key mapping xml dont get created also you have to do this step correctly:
r3dInput.cpp : Line 1049

Or you dont use the right Release
and many more possible reasons.

you can use r3dOutToLog("some debug string");
to display messages in the r3dlog.txt.
Make use of it and track the issue.

for example make the code look like this in this step AI_Player.CPP : Line 2016:

Code:
if(wpn->getItemID() == WeaponConfig::ITEMID_Flashlight)
    {
        if (InputMappingMngr->wasReleased(r3dInputMappingMngr::KS_TOGGLE_FLASHLIGHT))
        {
[I]r3dOutToLog("F Key Pressed");[/I]
            wpn->toggleFlashlight();
        }
    }

then it will show you a message if the F key is pressed. then you know that your input code is fine and toggleFlashlight(); is called.
 
Hmm we inplemented this, clients dont see ok..
Begin developing why not able to see..
Lets look where is the update or something for the flashlight, because clients can see the flashlight, when you holding it.

And what i found?! Nothing :D f**kin nothing..

Dont broadcasting the light?
Only broadcasting the wep. Id, and the lights come out, like a magic :)

And why?
The game check the items in our hands and broadcasting to all peer..

What can we do?

Maybe im wrong, but when you turn off the light, we need to broadcast a fake weaponswitch packet, or we need broadcast that we hold nothing :)

Any suggestion, idea or something?
Or somebody found something why and how can see everybody the light of anyone else flashlights? :)
 
Last edited:
Status
Not open for further replies.
Back