Here is an example of a controller setup configuration.

First, it is necessary to create keymap entries for the new buttons. In your data/keymap.cfg, add the following:

keymap -300 JBUTTONLT ""
keymap -301 JBUTTONRT "attack"
keymap -200 JDPADUP ""
keymap -201 JDPADDOWN ""
keymap -202 JDPADLEFT ""
keymap -203 JDPADRIGHT ""
keymap -100 JBUTTONA "jump"
keymap -101 JBUTTONB "weapon"
keymap -102 JBUTTONX "weapon"
keymap -103 JBUTTONY "weapon"
keymap -104 JBUTTONLB "weapon 2 3 1"
keymap -105 JBUTTONRB "weapon 4 1 2"
keymap -106 JBUTTON7 "showscores"
keymap -107 JBUTTON8 "menu"
keymap -108 JBUTTON9 ""
keymap -109 JBUTTON10 ""
keymap -110 JBUTTON11 ""
keymap -111 JBUTTON12 ""
keymap -112 JBUTTON13 ""
keymap -113 JBUTTON14 ""
keymap -114 JBUTTON15 ""
keymap -115 JBUTTON16 ""
keymap -50 MOUSEWHEELYUP ""
keymap -51 MOUSEWHEELYDOWN ""
keymap -52 MOUSEWHEELXUP ""
keymap -53 MOUSEWHEELXDOWN ""

It is then necessary to create the keybind entries. In your autoexec.cfg, add the following:

bind JDPADUP "weapon 2 3 1"
bind JDPADDOWN "weapon 3 2 1"
bind JDPADLEFT "weapon 4 1 2"
bind JDPADRIGHT "weapon 1 4 2"
bind JBUTTONLT ""
bind JBUTTONRT "attack"

bind "JBUTTONA" [jump]
bind "JBUTTONB" [weapon]
bind "JBUTTONX" [zoomnext]
bind "JBUTTONY" [weapon]
bind "JBUTTONLB" [ universaldelta  1 ]
bind "JBUTTONRB" [ universaldelta -1 ]
bind "JBUTTON7" [showscores]
bind "JBUTTON8" [showmenu main]

The zoom command can be emulated with cubescript. There is no need to emulate zoom with cubescript if zoomnext/zoomprev is built-in to the client. An example can be found in data/defaults.cfg.

The universaldelta function is implemented with cubescript. An implementation of the universaldelta function can be found in data/defaults.cfg. Here is an example universaldelta script that can be added to your autoexec.cfg:

bind "Z" [ domodifier 1 ]
bind "X" [ domodifier 5 ]

alias "s" [delta_game_0]
alias "modifier" [0]
alias "domodifier" [ alias modifier $arg1; onrelease [ alias modifier 0 ] ]
alias "universaldelta" [
  if $editing [ alias s "edit" ] [ alias s "game" ]
  concatword delta _ $s _ $modifier
  s
]
alias "delta_game_0" [ if (= $arg1 1) [ weapon 2 3 1 ] [ weapon 4 1 2 ] ]
alias "delta_game_1" [ if (= $arg1 1) [ zoomnext ] [ zoomprev ] ]
alias "delta_edit_0" [ editheight $flrceil $arg1 ]
alias "delta_edit_1" [ if $flrceil [ vdelta $arg1 ] [ vdelta (- 0 $arg1) ] ]
alias "delta_edit_2" [ edittex $flrceil $arg1 ]
alias "delta_edit_3" [ edittex (+ $flrceil 1) $arg1 ]
alias "delta_edit_4" [ equalize $flrceil ]
alias "delta_edit_5" [ entproperty 0 $arg1 ]

Finally, it is necessary to configure the joystick axes. You can add the following to your autoexec.cfg, or set them from the in-game console. If you put these settings in autoexec.cfg, they will overwrite any previous in-game configuration on startup, so you may wish to remove the settings after they are applied once.

joyaxismovementx 1
joyaxismovementy 0
joyaxislookx 3
joyaxislooky 4
joyaxistrigger 2
joyaxistrigger2 5
joyaxissticksensitivity 100
joyaxistriggerthreshold 80
joyaxisstickdeadzone 20