Welcome, Guest! Login | Register

3rd person View in Multiplayer [Print this Article]
Posted by: cct
Date posted: Nov 13 2006
User Rating: 5 out of 5.0
Number of views: 4612
Number of comments: 0
Description: How to enable it in HL2DM
Hello guys. This is my very first tutorial so it might be not the best but the code works.

In HL2DM when you start with a clean sdk and you compile as release, you can´t use thirdperson view with a bit of code. I tried a HL1 tutorial and with a little modification it works.

Let´s start:

Open up your client and go to in_camera.cpp.

If you want to hardcode your distance,yaw and pitch you need to add a few defines. I hard coded mine but it also could be done with the convars.

Here are the defines:

 CODE (C++) 
#define THIRDYAW    0
#define THIRDPITCH  0
#define THIRDDIST   70


Then go to line 459 to function

 CODE (C++) 
void CInput::CAM_ToThirdPerson(void)


and remove this

 CODE (C++) 
#if !defined( CSTRIKE_DLL )
#if !defined( _DEBUG )

// Do allow third person in TF for now
#if defined ( TF_CLIENT_DLL )
        // This is empty intentionally!
#else
    if ( gpGlobals->maxClients > 1 )
    {
        // no thirdperson in multiplayer.
        //return;
    }
#endif

#endif
#endif


Its easy to explain: If one of those statements become true, it will execute the code which will prevent your 3rd person cam from working.

Next Step is in line 230 inside Cam_Think(). Just remove this one:



 CODE (C++) 
    // If cheats have been disabled, pull us back out of third-person view.
    /*if ( sv_cheats && !sv_cheats->GetBool() )
    {
        CAM_ToFirstPerson();
        return;
    }*/


This is just for kicking us out from 3rd person cam when we disable sv_cheats. So while we talk about sv_cheats we need to change a little thing that we dont need sv_cheats enabled to use 3rd person cam. Here we go.

Change:

 CODE (C++) 
static ConCommand thirdperson( \"thirdperson\", ::CAM_ToThirdPerson, \"Switch to thirdperson camera.\",FCVAR_CHEAT);


to

 CODE (C++) 
static ConCommand thirdperson( \"thirdperson\", ::CAM_ToThirdPerson, \"Switch to thirdperson camera.\");


Its just a few more things left. Now you should have a working 3rd Person Cam. But some things are a bit annoying yet.

I.e. the distance,yaw and pitch. Thats an easy fix. In line 237 you need to change this

 CODE (C++) 
    camAngles[ PITCH ] = cam_idealpitch.GetFloat();
    camAngles[ YAW ] = cam_idealyaw.GetFloat();
    dist = cam_idealdist.GetFloat();


to this

 CODE (C++) 
    camAngles[ PITCH ] = THIRDYAW;
    camAngles[ YAW ] = THIRDPITCH;
    dist = THIRDDIST;


Now the last Step and we are done. If you only want to press one key for switching between first and 3rd person you need to change following. In line 60 inside

 CODE (C++) 
void CAM_ToThirdPerson(void)


Change it from

 CODE (C++) 
void CAM_ToThirdPerson(void)
{
    input->CAM_ToThirdPerson();
}


to

 CODE (C++) 
void CAM_ToThirdPerson(void)
{
    if( ::input->CAM_IsThirdPerson())
    {
        input->CAM_ToFirstPerson();
    }
    else
    input->CAM_ToThirdPerson();
}


A little sidenote to the defines. This is just if you wanna hardcode your values. You might prefer to change the convars instead which i wont cover in this Tutorial but its easy to figure out on your own.

So we are finished now. As i said in the beginning, this is my very first tutorial. It might not be as informable as others but the code works.

This code is made with a clean,fresh and virgin hl2dm sdk. You do this on your own Risk.

Regards
cct

Rate This Article
This article is currently rated: 5 out of 5.0 (1 Votes)

You have to register to rate this article.
User Comments

No User Comments

You must register to post a comment. If you have already registered, you must login.

Latest Articles
3rd person View in Multiplayer
Half-Life 2 | Coding | Client Side Tutorials
How to enable it in HL2DM

By: cct | Nov 13 2006

Making a Camera
Half-Life 2 | Level Design
This camera is good for when you join a map, it gives you a view of the map before you join a team

By: slackiller | Mar 04 2006

Making a camera , Part 2
Half-Life 2 | Level Design
these cameras are working monitors that turn on when a button is pushed.

By: slackiller | Mar 04 2006

Storing weapons on ladder
Half-Life 2 | Coding | Snippets
like Raven Sheild or BF2

By: British_Bomber | Dec 24 2005

Implementation of a string lookup table
Half-Life 2 | Coding | Snippets
A string lookup table is a set of functions that is used to convert strings to pre-defined values

By: deathz0rz | Nov 13 2005


Latest Comments
Where do we go from here
General | News
By: MIFUNE | Jun 09 2008
 
The Input/Output system
Half-Life 2 | Level Design
By: nazitaco | Dec 23 2007
 
Where do we go from here
General | News
By: Rob_F | Nov 22 2007
 
Rescaling Half-Life
Half-Life | Coding | Shared Tutorials
By: christoph | Nov 12 2007
 
GameUI
Half-Life 2 | Coding | Client Side Tutorials
By: Evil_j | Oct 29 2007
 
3 State Zoom For Any Weapon
Half-Life 2 | Coding | Server Side Tutorials
By: Ennuified | Oct 18 2007
 
Storing weapons on ladder
Half-Life 2 | Coding | Snippets
By: cct | Sep 07 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: DarkNight | Aug 28 2007
 
CTF Gameplay Part 1
Half-Life | Coding | Shared Tutorials
By: deedok | Aug 20 2007
 
Debugging your half-life 2 mod
Half-Life 2 | Coding | Articles
By: blackshark | Aug 17 2007
 

Site Info
296 Approved Articless
5 Pending Articles
3940 Registered Members
0 People Online (21 guests)
About - Credits - Contact Us

Wavelength version: 3.0.0.9
Valid XHTML 1.0! Valid CSS!