Half-Life 2

Half-Life 2

Not enough ratings
Adding Working Scopes to Weapons
By V92
How to add working scopes to weapons in HL2 through weapon script editing.
   
Award
Favorite
Favorited
Unfavorite
Getting Started
To add a working scope to any weapon in HL2 is relatively simple.

You'll need a scope texture to use. The internet has a bunch laying around, so you should be able to find one if you look hard enough.

Open up the weapon of choice, such as weapon_crossbow, and scroll to the texturedata block. In this table, you'll find several entries such as weapon, weapon_s, etc. You can find detailed descriptions of what each of these mean on the Valve Developer Community page. The parts we're looking to change or add are called zoom and zoom_autoaim.
Breaking it Down
zoom is called when the +zoom or toggle_zoom commands are used. zoom_autoaim is a slight variation used when the crosshair is over a target. This could be used to make a different overlay appear when a target is marked.
The Code
The following is an example of how to add a proper scope overlay to the weapon.
zoom { // Texture path; relative to root/materials/ file sprites/scope_2 // X & Y-position on the screen x 0 y 0 // The width & height of the texture; preferably match the VTF size width 4096 height 2048 } zoom_autoaim { file sprites/scope_2 x 0 y 0 width 4096 height 2048 }

The file line can be used to choose the texture to display. The x & y are used to set the translation, width & height the size.
Conclusion
This can be added to any of the native weapons in HL2, as they all share the same form fields as far as texturedata is concerned for the scope of this tutorial. If you want a working example to shamelessly edit & break apart for experimentation, you might try my release of the scoped Crossbows using this very method[github.com].

6 Comments
yajathb 8 Aug, 2024 @ 5:18pm 
I GUESS I WAS FORMATTING MY TEXTURES WRONG CUZ I WAS GOING ON GOOGLE FOR THEM THANKS SO MUCH
yajathb 8 Aug, 2024 @ 5:18pm 
MY GOD IT WORKS
yajathb 8 Aug, 2024 @ 5:18pm 
oh ok thanks
V92  [author] 8 Aug, 2024 @ 5:16pm 
@thatnoobgamer

You need the textures. Download my example file linked at the bottom, it includes them.
yajathb 8 Aug, 2024 @ 5:05pm 
i copy pastes all the code
yajathb 8 Aug, 2024 @ 5:05pm 
when i use it the texture comes as a purple and black overlay in game