PDA

View Full Version : Aux Power Drain


Carbonis
07-01-2007, 05:12 AM
Hi,

As I have limited C++ knoledge, I was wondering if anyone here could help me. I have a screenoverlay which will eventually be a nightvision feature in game. However, I do not know how to drain the aux power when the overlay is on and to turn it off when the power is drained.

Any suggestions? Thanks in advance

steveo3861
07-01-2007, 05:28 AM
This is checks if there is enough power.

if ( m_HL2Local.m_flSuitPower <= 0.0f )
{
if( IsSprinting() )
{
StopSprinting();
}
}

Carbonis
07-01-2007, 05:29 AM
Thanks. Now, if I knew the code to drain power...

longshanksAOC
07-01-2007, 09:43 AM
pOwner->SuitPower_Drain(20.0f);

Carbonis
07-01-2007, 11:14 AM
Thank you very much!

Carbonis
07-01-2007, 11:52 AM
Hmm, sorry to bother everyone again, but I still have problems with the code provided.

Current solution snippet involving the screenoverlay:

if( bDisplayed )
{
// turn it off
view->SetScreenOverlayMaterial( NULL );
cvar->FindVar("mat_fullbright")->SetValue(0);
}
else
{
// turn it on
view->SetScreenOverlayMaterial( pMaterial );
pHLPlayer->SuitPower_Drain(20.0f);
cvar->FindVar("mat_fullbright")->SetValue(1);
}

Any help please on where I am going wrong?

Thanks

razvan252
07-02-2007, 10:00 PM
you need a bool IsDisplayed then set it something like this
if( bDisplayed )
{
// turn it off
view->SetScreenOverlayMaterial( NULL );
cvar->FindVar("mat_fullbright")->SetValue(0);
IsDisplayed = false;
}
else
{
// turn it on
view->SetScreenOverlayMaterial( pMaterial );
cvar->FindVar("mat_fullbright")->SetValue(1);
IsDisplayed = true;
}

and below it

if ( IsDisplayed == true )
{
pHLPlayer->SuitPower_Drain(20.0f);
}

so now it drains if its enabled and not when its toggled on.

Carbonis
07-03-2007, 08:45 AM
I did have a bool, just not shown in quote, nevertheless I thank you for the help with the power drain implementation.

Carbonis
07-03-2007, 02:29 PM
One final request, I keep on getting two main errors when compiling (I got rid of 5!)

Could somebody help me correct the solution so the errors do not occur?

1>.\view_scene.cpp(4742) : error C2065: 'pHLPlayer' : undeclared identifier
1>.\view_scene.cpp(4742) : error C2227: left of '->SuitPower_Drain' must point to class/struct/union/generic type
1> type is ''unknown-type''

Current, and hopefully penultimate solution!
//NightVision
static void ScreenOver_f( void )
{
IMaterial *pMaterial = materials->FindMaterial( "HUDoverlays/nightvision", TEXTURE_GROUP_OTHER, true );

{
static bool bDisplayed;
bool IsDisplayed;


if( bDisplayed )
{
view->SetScreenOverlayMaterial( NULL );
cvar->FindVar("mat_fullbright")->SetValue(0);

IsDisplayed = false;
}
else
{
view->SetScreenOverlayMaterial( pMaterial );
cvar->FindVar("mat_fullbright")->SetValue(1);
IsDisplayed = true;
}

bDisplayed = !bDisplayed;

if( IsDisplayed = true )
{
pHLPlayer->SuitPower_Drain( 30 );
}

}
}
static ConCommand r_screenover( "r_screenover", ScreenOver_f );

Thanks to everyone for their help so far!

razvan252
07-03-2007, 09:38 PM
try this

CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );
pPlayer->SuitPower_Drain( 30 );

Carbonis
07-15-2007, 04:14 AM
One final request now, as I know what to do except one thing. At the beginning of the file all the headers to be included are shown, right? How would I include one from the client side, as the view_scene.cpp file is in the server side?

Thanks

Carbonis
07-16-2007, 11:42 AM
Please? Anyone?

Lolmen
07-16-2007, 09:31 PM
You can't use client side headers on server side.

razvan252
07-17-2007, 12:11 AM
what do you need to include?

Carbonis
07-17-2007, 01:10 AM
The nightvision instructions are in view_scene.cpp (client side, source files, HL2 DLL), the code which is for the suit's power interface is in the header HL2_Player.h (Server side, Source files, HL2 DLL).

Carbonis
07-31-2007, 02:02 AM
One final error which I would like assistance with:


1>.\view_scene.cpp(4751) : error C2065: 'player' : undeclared identifier

view_scene.cpp

Additional includes:

#if defined( CLIENT_DLL )
#define CHL2_Player C_BaseHLPlayer
#include "c_basehlplayer.h"
#else
#include "hl2_player.h"
#endif

Additional code (end of document):

static void ScreenOver_f( void )
{

IMaterial *pMaterial = materials->FindMaterial( "effects/combine_binocoverlay", TEXTURE_GROUP_OTHER, true );
// Final material "HUDoverlays/nightvision"

{
static bool bDisplayed;
bool IsDisplayed;

{


if( bDisplayed )
{
// turn it off
view->SetScreenOverlayMaterial( NULL );
// Deactivate the 'light'
cvar->FindVar("mat_fullbright")->SetValue(0);
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, 0, "Sole Survivor.NightVisOff" );
//play the off sound
IsDisplayed = false;
}
else
{
// turn it on
view->SetScreenOverlayMaterial( pMaterial );
// Activate the 'light'
cvar->FindVar("mat_fullbright")->SetValue(1);
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, 0, "Sole Survivor.NightVisOn" );
IsDisplayed = true;
}

bDisplayed = !bDisplayed;

if( IsDisplayed = true )

{
#if defined( CLIENT_DLL )
C_BaseHLPlayer *pHLPlayer = assert_cast<C_BaseHLPlayer*>( player );

if ( pHLPlayer->m_HL2Local.m_flSuitPower > 30 )
pHLPlayer->m_HL2Local.m_flSuitPower = max( pHLPlayer->m_HL2Local.m_flSuitPower - 25, 0 );
else
return false;
#endif
}

}
}
}

I would be grateful for any more assistance - and thanks to those who have helped already!

razvan252
07-31-2007, 02:05 AM
where youget the error declare the player like this:
CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );

Carbonis
07-31-2007, 06:46 AM
I presume that I will need to include another header - as GetOwner() is not a member of my current headers. Are you sure that your solution is correct? At the moment I just keep on getting even more errors

Lolmen
08-03-2007, 07:11 PM
Use a communication between server to client for manipulating an nightvision from server on the client.

Carbonis
08-04-2007, 02:05 AM
Use a communication between server to client for manipulating an nightvision from server on the client.

The question I have been asking on this thread for the last couple of times is how do I enable the server to communicate with the client?

Thanks

Carbonis
08-10-2007, 02:06 AM
How do you make a communication between server to client for manipulating an nightvision from server on the client?

Winston
08-10-2007, 03:06 AM
Is this is still the issue with the line C_BaseHLPlayer *pHLPlayer = assert_cast<C_BaseHLPlayer*>( player );?

If so, then replace player with C_BasePlayer::LocalPlayer() (or it might be C_BasePlayer::GetLocalPlayer(), I don't have the code right now) - otherwise, what exactly are you trying to send with this "communication?"

Carbonis
08-10-2007, 04:21 AM
What I am trying to send is the signal (from view_scene.cpp) to drain the aux power (sever side) when the Nightvision overlay is applied.

Carbonis
08-10-2007, 11:02 AM
Aha, I might actually have this solved - yet one problem not related to any other has occured.

1>Compiling...
1>view_scene.cpp
1>c:\program files\steam\mods\further education\src\cl_dll\view_scene.cpp(4757) : error C2562: 'ScreenOver_f' : 'void' function returning a value
1> c:\program files\steam\mods\further education\src\cl_dll\view_scene.cpp(4708) : see declaration of 'ScreenOver_f'

Any solutions?

Current code:


static void ScreenOver_f( void )

{

IMaterial *pMaterial = materials->FindMaterial( "effects/combine_binocoverlay", TEXTURE_GROUP_OTHER, true );

{
static bool bDisplayed;
bool IsDisplayed;

{


if( bDisplayed )
{
view->SetScreenOverlayMaterial( NULL );
cvar->FindVar("mat_fullbright")->SetValue(0);
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, 0, "Sole Survivor.NightVisOff" );
IsDisplayed = false;
}
else
{
view->SetScreenOverlayMaterial( pMaterial );
cvar->FindVar("mat_fullbright")->SetValue(1);
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, 0, "Sole Survivor.NightVisOn" );

IsDisplayed = true;
}

bDisplayed = !bDisplayed;

if( IsDisplayed = true )

{
#if defined( CLIENT_DLL )
C_BaseHLPlayer *pHLPlayer = (C_BaseHLPlayer *) C_BasePlayer::GetLocalPlayer();

if ( pHLPlayer->m_HL2Local.m_flSuitPower > 30 )
pHLPlayer->m_HL2Local.m_flSuitPower = max( pHLPlayer->m_HL2Local.m_flSuitPower - 25, 0 ); //drain stamina for the jump
else
return false;
#endif
}


//check if fullbright has been disabled, or enabled
//if (cvar->FindVar("mat_fullbright")->GetInt() == 1)//if on
// cvar->FindVar("mat_fullbright")->SetValue(0);//turn it off.
}
}
}
static ConCommand r_screenover( "r_screenover", ScreenOver_f );

Winston
08-10-2007, 03:28 PM
well, replace "return false" with just "return" and you won't be returning a value.
Also, you appear to have several braces ( { & } ) that dont really say or mean anything, so I suggest you get rid of them. From that snippet, remove the 2nd & 3rd ones, and the last two. You only need them for defining a "section" of code, eg if ( some condition )
{
Do this
Also do this
And this
}
else
do this only
do this, regardless of the last if
Indentation also makes this logic easier to see