Hide HUD Flashlight Power Bar/Icon until Flashlight Pickup

Grab your favourite IDE and tinker with the innards of game engines

Hide HUD Flashlight Power Bar/Icon until Flashlight Pickup

Postby SJPiglet on Sun Oct 23, 2011 9:10 pm

Hello,

Firstly, my programming skills in C++ are very basic! Though I am keen to learn, so im not demanding someone solves the solution for me (unless you want to or know how to :D ), but a nudge in the right direction or a confirmation of my method would be greatly appreciated.

Basically I have followed the tutorial on Interlopers to make the Flashlight require batteries. I basically want to take this a bit further and make the flashlight disabled until a Flashlight model is found and picked up in the level.

At the bottom of the tutorial it said about using point_servercommands, which work as the player cannot use the flashlight, however it is still visible in the HUD, I wish to make this hidden until Flashlight model is picked up.

I have managed to code the "item_flashlight" based on the "item_flashbattery" however I become stumped when I need the new function to display the Flashlight in the HUD.

To begin with I have added a boolean to "hud_flashlight.cpp" which is defined just under the includes, which makes it global?

Code: Select all
extern bool flash_pickup = false;


This boolen "flash_pickup" starts as false, and an IF statement is added to all functions regarding Hud display for the flashlight mainly the Paint function. So basically when I run my mod the Flashlight doesn't appear in the HUD as the boolean is set to false and the point_servercommand disables the Flashlight sound and the flashlighteffect.

I am having trouble in setting my function to switch the variable to True and then executing the function to draw the Flashlight on the HUD.

My flashlight function is contained in hl2_player.cpp in the Server files and my boolean and Paint function is located in hud_flashlight.cpp as part of the Client files.

Is there a way to call a function from a different project in the same solution?

I have tried google search, but with my limited experience some help that is based around the source engine and files would be beneficial.

Apologies for the long post. Any help greatly appreciated.

SJPiglet
User avatar
SJPiglet
Dumpling
Dumpling
 
Joined: Thu Sep 29, 2011 3:26 pm
Location: South West England

Re: Hide HUD Flashlight Power Bar/Icon until Flashlight Pick

Postby zombie@computer on Sun Oct 23, 2011 10:26 pm

Your thinking too much, its really simple. Dont have the code around but it's something like

UTIL_GetLocalPlayer()->SetHiddenBits( HIDEHUD_FLASHLIGHT );

This also saves the 'hideyness' of the hud elements so a save->reload will not cripple your system.
If the above line is not working, it should at least give you an idea how to implement it correctly.

Mind UTIL_GetLocalPlayer() is only kinda valid in singleplayer.
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Hide HUD Flashlight Power Bar/Icon until Flashlight Pick

Postby SJPiglet on Mon Oct 24, 2011 10:11 am

zombie@computer, thanks for the reply!

I had a feeling that there would probably be an easier way to do this.

I will try your method when I get home.

Thanks again.

SJPiglet
User avatar
SJPiglet
Dumpling
Dumpling
 
Joined: Thu Sep 29, 2011 3:26 pm
Location: South West England

Return to Programming

Who is online

Users browsing this forum: No registered users