Tutorial: Change hud_fastswitch to behave like Half-Life Source Last edited 1 year ago2023-01-14 20:19:18 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

Introduction

Hello. I am Surreal, and I run the GoldSrc modification Cold Ice Remastered. Today, we'll change the behavior of the hud_fastswitch command to match the behavior found in Half-Life Source.

Why

Swapping weapons (or quick swapping) is a nice feature. Swapping skips the need for an additional fire command to change the weapon through the menu. Pressing a slot command (slot1 thru slot5) will cycle through its respective weapons rapidly, making response time in combat fast(er)!

The motivation for this tutorial is from watching JarekTheGamingDragon video. While GoldSrc supports a partial version of this command, it does not cycle through the weapons, leading to convos of sharing additional binds. So, let's add it to our mod.

How

The code that follows is from Valve 2013 SDK. Other SDKs are compatible, such as Solo's halflife-updated.

Go to cl_dll/ammo.cpp in the SDK and find the line:
bool fastSwitch = CVAR_GET_FLOAT( "hud_fastswitch" ) != 0;
Insert the code block right after:
if (fastSwitch)
{
    // Switching between menus restarts count
    if (gpLastSel && iSlot != gpLastSel->iSlot)
        gpLastSel = NULL;

    // No selection, start at top
    if (!gpLastSel)
        p = GetFirstPos( iSlot );
    else
    {
        // Try next
        p = GetNextActivePos( iSlot, gpLastSel->iSlotPos );
        // End of list, start at top
        if (!p)
            p = GetFirstPos( iSlot );
    }

    // Found a weapon, store and switch
    if (p)
    {
        PlaySound("wpn_select.wav", 1);
        gpLastSel = p;
        ServerCmd( p->szName );
        g_weaponselect = p->iId;
    }

    return;
}
Following this added block, there is code that partially supports the swap. Remove these lines:
if ( p && fastSwitch ) // check for fast weapon switch mode
{
    // if fast weapon switch is on, then weapons can be selected in a single keypress
    // but only if there is only one item in the bucket
    WEAPON *p2 = GetNextActivePos( p->iSlot, p->iSlotPos );
    if ( !p2 )
    {    // only one active item in bucket, so change directly to weapon
        ServerCmd( p->szName );
        g_weaponselect = p->iId;
        return;
    }
}
Then, change this line:
if ( !fastSwitch )
    gpActiveSel = (WEAPON *)1;
else
    gpActiveSel = NULL;
to:
gpActiveSel = (WEAPON *)1;
In summary, here is the entire pull request within our mod for reference.

Test It

Once your code is compiled and libraries in place, start up the game and type in the console hud_fastswitch 1. Use sv_cheats 1 and impulse 101 for weapons, and then press binds for slot1 thru slot5(typically, key 1 through 5). You'll see that it will quickly cycle through each set of weapons. Nice!

Why Did Valve Do That?

I am sure Valve made the partial change for a good reason, but as far as I can tell, there should be no problems.

Questions

If you have any questions about this tutorial, don't hesitate to get in touch with me. Also, you can join Cold Ice Remastered Discord here.

Comments

You must log in to post a comment. You can login or register a new account.