Halflife 2 Script

I used to play multiplaye FPS (first person shooter) games in college, particularly Team Fortress. My interest later waned, but I still enjoyed the occasional match. The nature of the game, fortunately, is such that there is no need to consistently invest time in it.

Out of college, I developed somewhat of a carpal tunnel problem, particularly on the right side. This made mousing pretty much out of the question, so these sorts of games were right out.

Later on, we got a PS2, and while playing various games on it, I noticed that the PS2 controller is a lot easier on the wrists than mouse + keyboard. So recently, I got an adapter that converts a PS2 controller to USB, allowing it to be used on a computer.

In the intervening years, TF was suceeded by Team Fortress Classic running on the Half-Life engine, and more recently, some Half-Life 2 DM mods have been implementing something similar.

Getting an FPS game like HL2:DM to work welli with a PS2 controller, however, is not a trivial thing. Over time, I've worked out a config script to be able to do so, and so, for those who may need it or find it useful, here it is.

I've played through the single player with a slightly different setup, but here, I've focused the configuration on DeathMatch (playing against other people online). The goal is to be able to stand up to players using a mouse and keyboard (which provide superior targeting and a greater range of keystrokes, respectively). While I can't say I am nearly as good with this setup as with a mouse & keyboard, it at least levels the field a great deal.

The main areas of focus are:

  • Movement/looking with the two thumbsticks.
  • Multi-purpose buttons to offset the lack of a keyboard.
  • More advanced, general-purpose functionality.
  • Unused/discarded options.
The first two sections are pretty much a must for using the PS2 (or any similar) controller. The rest are optional, and can be used as a general reference for aliasing/scripting.

// Disclaimer: This has always been / is a work in progress, so if
// something doesn't work, you'll just have to muck with it to fix it.

// enable joystick

joystick "1"
joy_advanced 1
+jlook

// Minor note: to enable the joypad, you may need to also turn on Analog 
// mode with the analog button on the DualShock itself. This is best done
// before you load halflife, else it may not recognize the buttons.


// AXES

// Joystick axes are set up differently based on what joystick you have.
// The axes are joy_advaxisX where X is one of x,y,r,z,u,v. Try out
// each one to figure out what the axes of your joystick are.

// You set each to one of 5 values:
// 0 = no action
// 1 = move forward/back
// 2 = look up/down
// 3 = move left/right
// 4 = look left/right

// (if you are moving or looking in the opposite direction of which
// you expect, set sensitivity to be negative as described below)

// For the PS2 dualshock using the adapter I got at
// http://www.electricquarter.com/ps3in1.htm, the left stick is x/y
// and the right joystick is r/z, hence the values below.

joy_advaxisr 4
joy_advaxisz 2
joy_advaxisx 3
joy_advaxisy 1

// the following makes the axes setup take effect

joyadvancedupdate


// THRESHOLDS

// Joystick threshold sets the center deadzone of your joystick. A low
// value will allow you to move your aim more precisely, but may result
// in controller creep, where you're moving without touching the sticks.
// A high value will make it harder to aim precisely, but make the creep
// less likely.

// If you find yourself fighting the creep even at reasonable settings
// at the start of the game, move the sticks through their full range in
// every direction to let the game know where 'center' is. This usually
// helps, and with my settings & DualShock, I have to do this whenever
// I load the game.

// The forward and side thresholds aren't critical for deathmatch, since
// you aren't liable to need slow speeds.

joy_forwardthreshold "0.1"
joy_sidethreshold "0.1"

// Pitch and yaw refer to looking up/down and left/right, respectively
// I find .05 to be a bit on the edge, but not annoyingly so once
// I cycle through all the directions as suggested above.
// A threshold of .05 allows sensitivity .75 with reasonable accuracy
// even for long distance shots.

joy_pitchthreshold "0.05"
joy_yawthreshold "0.05"


// SENSITIVITY

// This is arguably the most complicated area (at least, look sensitivity
// is).

// Sensitivity sets how quickly you move in response to the stick. In
// addition, it sets which direction you move - if you find yourself
// moving in the opposite direction of which you expect, make the relevant
// value negative.

// Forward and side sensitivity is not critical in deathmatch, so I set
// it to 1 and -1 (for the above flipping reasons)

joy_forwardsensitivity "-1"

// When you deal with vehicles in the single player game, where for some 
// reason, getting into a vehicle flips the side-to-side movement of the
// joystick. I had to alias a key to switch between vehicle and walking 
// movement for that reason.)

alias sidewalk "joy_sidesensitivity 1; alias sidetoggle sidedrive"
alias sidedrive "joy_sidesensitivity -1; alias sidetoggle sidewalk"
sidewalk


// LOOK SENSITIVITY

// Pitch and yaw sensitivity is arguably the achilles heel of the 
// joystick setup. With a mouse, you can whip the pov around instantly, 
// and then slow down for precise aiming. Sadly, HL2 doesn't allow you 
// to adjust the sensitivity of the joystick to anything but linear,
// so a high value will let you turn around quickly to face an opponent,
// but will make it harder to aim, and a low value will let you aim, but
// won't allow you to turn around quickly enough to match a mouser.

// My solution is to add a 'shift' key to increase sensitivity when
// needed.

// To set sensitivity, you set the joy_pitchsensitivity and 
// joy_yawsensitivity variables. For slow, I set mine to .5, for fast,
// I set them to 1.

// Since I'm going to be updating these on the fly, I aliased them.

alias normsensitivity "joy_pitchsensitivity 1.2 ; joy_yawsensitivity -1.2"
alias slowsensitivity "joy_pitchsensitivity .3 ; joy_yawsensitivity -.3"
normsensitivity

// MISC ALIASES

// Duck & Jump

// Frankly, I'm not sure how useful this is, but a lot of people
// appear to be doing it, so I've added it as well. This alias
// lets you duck and jump at the same time easily. I *think* this
// makes you a smaller target when you jump, but who the hell knows?

alias +djump "+duck ; +jump"
alias -djump "-duck ; -jump"

// Zoom toggle

alias zoomtoggle zoomin
alias zoomin "fov 30 ; slowsensitivity ; alias zoomtoggle zoomout"
alias zoomout "fov 90 ; normsensitivity ; alias zoomtoggle zoomin"

// Stats display toggle

alias statstoggle showstats
alias showstats "cl_showfps 1 ; net_graph 1 ; alias statstoggle showstats2"
alias showstats2 "cl_showfps 2 ; net_graph 2 ; alias statstoggle hidestats"
alias hidestats "cl_showfps 0 ; net_graph 0 ; alias statstoggle showstats"

// Duck toggle

alias ducktoggle duckdown
alias duckdown "+duck ; alias ducktoggle duckup"
alias duckup "-duck ; alias ducktoggle duckdown"



// SHIFT

// Shift key shifts meaning (separated into weapons and action)
alias +myshift "+wshift ; +actshift; +openshift"
alias -myshift "-wshift ; -actshift; -openshift"

// action

// basic attack helper aliases
alias stopattack "-attack ; -attack2"
alias bothattack "+attack ; +attack2"

// special attack modes
alias normattack "alias +a1 +attack;  alias -a1 stopattack; 
                  alias +a2 +attack2; alias -a2 stopattack"
alias swapattack "alias +a1 +attack2; alias -a1 stopattack; 
                  alias +a2 +attack;  alias -a2 stopattack"
alias shotattack "alias +a1 shotstart2; alias -a1 shotstop; 
                  alias +a2 shotstart1; alias -a2 shotstop"
alias grenattack "alias +a1 gren1; alias +a2 gren2a"
alias zoomattack "alias +a1 +attack ; alias -a1 -attack ; 
                  alias +a2 zoomtoggle ; alias -a2"
alias dualattack "alias +a1 +attack ; alias -a1 stopattack ; 
                  alias +a2 bothattack ; alias -a2 stopattack"
normattack

// shotgun
alias shotstart1 "-reload ; +attack"
alias shotstart2 "-reload ; +attack2"
alias shotstop "-attack ; -attack2 ; +reload"

// grenade attack 1
alias gren1       "+attack ; alias -a1 -attack ; alias -a2 -attack"
// grenade attack 2: sequence - try to time-throw a grenade 
//                            (three button pushes)
                                    // push down: pull back arm
alias gren2a      "+attack2 ; alias -a1 gren2b; alias -a2 gren2b"
                                    // release: drop
alias gren2b      "-attack2 ; alias +a1 gren2c ; alias +a2 gren2c"
                                    // push down: swith to physcannon and grab
alias gren2c      "use weapon_physcannon ; +attack2 ; alias -a1 gren2d ; 
                  alias -a2 gren2d"
                                    // release: hold
alias gren2d      "-attack2 ; alias +a1 gren2e ; alias +a2 gren2e"
                                    // push down: fire grenade
alias gren2e      "+attack  ; alias -a1 gren2f ; alias -a2 gren2f"
                                    // release: switch back to grenade and reset
alias gren2f      " -attack ; use weapon_frag ; grenattack"

alias +actshift "alias +attacks +a2 ; alias +djumpreload +reload ; 
                  alias invnextprev invnext ; alias +zoomduck +zoom"
alias -actshift "alias +attacks +a1 ; alias +djumpreload +djump ; 
                  alias invnextprev invprev; alias +zoomduck +duck"

alias -attacks "-a1 ; -a2"
alias -djumpreload "-djump; -reload"
alias -zoomduck "-zoom ; -duck"

// weapons
alias +wshift "alias w1 w1b; alias w2 w2b; alias w3 w3b; 
                  alias w4 w4b; alias w5 w5b"
alias -wshift "alias w1 w1a; alias w2 w2a; alias w3 w3a; 
                  alias w4 w4a; alias w5 w5a"


alias w1a "zoomattack; use weapon_crossbow"
alias w1b "zoomattack; use weapon_357"
alias w2a "normattack; use weapon_rpg"
alias w2b "grenattack; use weapon_frag"
alias w3a "normattack; use weapon_physcannon"
alias w3b "normattack; use weapon_crowbar"
alias w4a "normattack; use weapon_ar2"
alias w4b "normattack; use weapon_smg1"
alias w5a "shotattack; use weapon_shotgun"
alias w5b "dualattack; use weapon_pistol"

// open (for mods, etc)
alias +openshift "alias open1 open1b ; alias open2 open2b"
alias -openshift "alias open1 open1a ; alias open2 open2a:

alias open1a zoomduck
alias open2a "load quick"
alias open2b "save quick'

// reset everything
-wshift


// BUTTONS

// Joystick buttons will vary. I think there's a way to figure
// out which is which easily under control panel, but I haven't tried. 
// I found out by going into the keyboard setup of the game, which 
// lets you press a button to indicate how it's going to be used - and 
// prints its 'name' - and used that to figure out the mapping.

// A joystick or joypad will have much fewer buttons available
// than a keyboard, so you have to be intelligent about using
// what you have.

// On the DualShock, there are 4 levels of button accessibility.

// 1: Triggers, which can be easily pressed without taking your
//    hands off the sticks. These are the most useful - set them
//    to things which you will need while moving. It helps to
//    not have ones you'll use together on the same side 
//    (+speed and +attack for R1 and R2 gets complicated unless
//    you use both index and middle fingers - which I don't)

// 2: R3 & L3: pushing down on the sticks. These are accessible
//    while moving, but more awkward than the triggers.
//    L3 is more awkward than R3 because you are always moving

// 3: Attack buttons (triangle, circle, etc) and Start. You have 
//    to take your thumb off the "look" stick to access these, so won't
//    be able to shoot anyone.

// 4: D-pad and Select. You have to take your thumb off the "move" 
//    stick to access these, which is instant death in DM


// Triggers
bind "AUX7" "+myshift"        // L1 (see above for what this is)
bind "AUX5" "+speed"          // L2
bind "AUX8" "+attacks"        // R1
bind "AUX6" "+djumpreload"    // R2

// Down on sticks
bind "AUX11" ""               // L3
bind "AUX12" "+zoomduck"      // R3

// Basic 4 buttons and Start (weapons)
bind "JOY1" "w4"              // triangle
bind "JOY2" "w3"              // circle
bind "JOY3" "w5"              // X
bind "JOY4" "w2"              // square
bind "AUX10" "w1"             // Start

// DPad
bind "AUX29" "zoomtoggle"     // forward
bind "AUX30" "+use"           // right
bind "AUX31" "ducktoggle"     // down
bind "AUX32" "impulse 100"    // left (flashlight)

bind "AUX9"  "invnextprev"    // Select

// KEYBOARD BINDS

// Some less-commonly used commands
// (I use a dvorak keyboard layout, so the key choice won't make sense
// for most people)

bind x "sidetoggle"
bind k "statstoggle"
bind y "say"
bind u "say_team"

// SET VARIABLES
hud_fastswitch 1     // fast-swap weapons
cl_autowepswitch 1   // switch weapons on pick up
con_enable 1         // enable console
cl_defaultweapon weapon_shotgun