Add cl_righthand to your mod

A Tutorial for Half-Life

Yo, buddy. We are one of the oldest mod sites on the Interwebs. Sign up and maximize your browsing experience.

  • Subscribe: Get notified of new submissions like this.
  • Say Thanks: Show your appreciation by sending MegaKnight points.
  • Post: Give MegaKnight your thoughts on this Tutorial.
  • Vote: Help MegaKnight win the Monthly Awards.
  • Rate: Give this Tutorial a rating out of 10.
  • Flag: Alert moderators and warn members of a problem with this Tutorial.
  • Watch: Get notified when this Tutorial is updated.
Mascot

Stop Lurking!

Sign up

Already a Bananite? Login

This is for Half-Life 1 and the GoldSrc engine, if you're looking for how to do this in Half-Life 2 and the Source engine go to this Valve Dev Wiki article.

This tutorial will give little to no hand holding or any major details, nor will there be any image instructions. What you see here is what you get, and I give no guarantee that this will work for you or your version of Half-Life. All of this code is entirely client side. Sorry in advance if this is all formatted horribly, but the text editor on this site is very different from every other I used and I'm having a hard time using it and had many cases where I had chunks of code turning into huge mangled wads of word spaghetti.

Anyway, lets get started.

Part 1: The Command

Here we will create the command itself.

Add this:
cvar_t *cl_righthand;

Right below this in hud.h in the CHud class definition:

cvar_t	*m_pCvarDraw;
Next, add:

cl_righthand = CVAR_CREATE( "cl_righthand", "1", FCVAR_ARCHIVE );
Below this in hud.cpp in the CHud::Init function:
CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE );
Alright, now that we have the ConVar created we can actually do things with it now.

Part 2: Actually flipping the models

Next we will actually implement the flipping code.

In StudioModelRenderer.cpp search for this:
for (i = 0; i < m_pStudioHeader->numbones; i++)

You should find 3 or 4 cases of it depending on the version of Half-Life you are using.
If you see this right below it you have the correct one:
QuaternionMatrix( q[i], bonematrix );
Then find this just a bit below it:

ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_pbonetransform)[i]);
Then add this just above that:

if (bIsViewModel && ((gHUD.cl_righthand->value != 0.0f) ^ (g_bWeaponIsRightHanded))){bonematrix[1][0] = -bonematrix[1][0];bonematrix[1][1] = -bonematrix[1][1];bonematrix[1][2] = -bonematrix[1][2];bonematrix[1][3] = -bonematrix[1][3];IEngineStudio.StudioSetCullState(1); // set backface culling}else{IEngineStudio.StudioSetCullState(0);}

Now the command itself should work, but how do you check if a weapon is left or right handed already? We'll cover that next.

Part 3: Setting the handedness for the weapons

Now this part is pretty quick and simple.

Go to the top of StudioModelRenderer.cpp and add this to the includes:
#include "com_weapons.h"

Then go into com_weapons.h and add this near the end of the file before the closing #endif:
extern bool g_bWeaponIsRightHanded;

Then go into hl_weapons.cpp and add this above the HLDM Weapon placerholder crap near the top of the file:
bool g_bWeaponIsRightHanded = true;
Now, you're only going to want it looking like that in the event all of your weapons are right handed. If all of your weapon models are left handed, change that true to a false.

If you are going to use a mixture of left and right handed weapons, add this to the Deploy function of each of your weapons before the return:

#ifdef CLIENT_DLLextern bool g_bWeaponIsRightHanded;g_bWeaponIsRightHanded = true;#endif 
If the weapon is left handed, change that true to a false. 

Now this can be where you finish, but continue reading on if you want to adjust shell ejection depending on the handedness.

Part 4: Shell ejection changes

Go to ev_hldm.cpp and for every single instance of  EV_GetDefaultShellInfo, put this above it:

if( !gHUD.cl_righthand->value ){//Edited value}else{//Default value}
Then cut and paste the existing EV_GetDefaultShellInfo call directly below the default value comment, then paste it again below the edited value comment and edit that one so that both right values are negative. Here is an example of that with the glock:
if( !gHUD.cl_righthand->value ){//Edited valueEV_GetDefaultShellInfo( args, origin, velocity, ShellVelocity, ShellOrigin, forward, -right, up, 20, -12, -4 );}else{//Default valueEV_GetDefaultShellInfo( args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, 20, -12, 4 );}
Just do this for every single call and then it will be good, though some tweaking may be required in some cases.

Thank you for reading this, I hope it helps.
It's late as hell as I'm writing this, so if there is any issues I will get to them in the morning.

Posts

  • 5mo
    James Luke avatar
    James Luke Offline
    Member Joined 2y
    721 points Ranked 6260th
    It isn't.

    Programming it in is easier than having to change all your guns out.

    8/10

    Goldsource Programmer
  • 5mo
    N4HW3ll avatar
    N4HW3ll avatar Offline
    Member Joined 1y
    1,504 points Ranked 3105th
    9 medals 1 rare
    • Returned 1000 times Medal icon
    • One month a member Medal icon
    • 6 months a member Medal icon
    • Returned 100 times Medal icon
    • Submission featured Medal icon
    • Submitted 10 Skins Medal icon
    if this is about flipping horizontaly the mdl you can just use gflip, heres the link http://gamebanana.com/tools/4907
    The Doomed Grunt avatar
    Mantra
    The Doomed Grunt
  • 5mo
    James Luke avatar
    James Luke Offline
    Member Joined 2y
    721 points Ranked 6260th
    At first glance I thought this was a copy-pasting of the HLFX.ru tutorial.

    But you have a interesting way to do it.

    I'd usually register my CVAR in the main StudioModelRednerer class and call it externally elsewhere...but that's my business. Also, why have an extra BOOL for right-hand anyways? You can just register the CVAR and your set. Just going through too many steps to get the same effect.

    You also have a interesting way to flip the viewmodel.

    Also, instead of replacing the call TO the function over and over again, here's a better way to do it. Inside of the actual EV_GetDefaultShellInfo and add your CVAR call there to negate your final value.

    EDIT: And just to note. SetCullFace is redundant. A global never used within the engine. See here.

    8/10

    Goldsource Programmer
  • 5mo
    MegaKnight avatar
    MegaKnight Offline
    Member Joined 5mo
    Posted by Matias-TM

    Amazing, I will try. But the HL2 tutorial link is wrong.
    It wasn't when I put it in.
    As I said, this thing got mangled hard and I just don't know how to fix it.
  • 5mo
    Matias-TM avatar
    Matias-TM Offline
    Member Joined 3y
    472 points Ranked 9192nd
    19 medals 3 rare
    • Returned 1000 times Medal icon
    • 10 submissions featured Medal icon
    • Submitted 20 Maps Medal icon
    • One month a member Medal icon
    • 6 months a member Medal icon
    • 1 year a member Medal icon
    Amazing, I will try. But the HL2 tutorial link is wrong.
    Like modding

Share

Shareable Image:
Share banner
HTML embed code:
BB embed code:
Markdown embed code:

More embeddable images

Bookmark and Share

Credits

Key Authors
MegaKnight
MegaKnight Offline
Member Joined 5mo
Wrote it.

Submitter

MegaKnight avatar
MegaKnight Offline
Member Joined 5mo

MegaKnight
Creator
Send a Private Message to the submitter

Category

Details

Difficulty Level
Advanced Difficulty

Attributes

Stats

Posts
5
Views
839
Date Added
5mo
Date Modified
5mo

Scores

70 bScore
8 Rating

1 voter

bcp.crwdcntrl.net tracking pixel