Mounted guns
Not every Source game can partake in the awesomeness of func_tank
or prop_minigun
, but using other entities you can still make a mounted gun, and get more customization.
This tutorial is based off one by TopHATTwaffle: [1], so original credit goes to him.
Following the mouse[edit | edit source]
First, make your gun and its base. These can use whatever entities you want. For the gun, this tutorial uses a prop_dynamic_override
called gun1_model
.
Make an info_target
on the spot you want the gun to pivot around. We'll call it gun1_base
.
Next we need a func_button
so we can tell when the player is trying to use the gun (by grabbing it). The button should ideally be non-solid, but still "push-able", so texture it with tools/toolsnpcclip
(if you don't have it, you'll have to settle for tools/toolsnodraw
which is solid to players). We'll call this gun1_button
. Parent this button to the gun and set the Don't move flag. For , you have to make some changes: (See here)
Next make a game_ui
, which will track the player's crosshair. Name it gun1_ui
, and we'll come back to it later.
Next make a logic_measure_movement
and name it gun1_movement
. This will make the gun follow the player's vision. Set the settings to these:
- Entity to Measure:
gun1_base
- Measure Reference:
gun1_base
- Movement Reference:
gun1_base
- Entity to Move:
gun1_model
- Movement scale: 100
- Measurement Type: Eye position
You might be confused how this part works right now - don't worry, we'll get there.
Go back to your func_button
and add these outputs:
My Output | Target Entity | Target Input | Parameter | Delay | Only Once |
---|---|---|---|---|---|
OnPressed | !self | Lock | 0.00 | No | |
OnPressed | !activator | AddOutput | targetname gun1_user | 0.00 | No |
OnPressed | gun1_movement | SetMeasureTarget | gun1_user | 0.01 | No |
OnPressed | gun1_ui | Activate | 0.00 | No |
Now go to the game_ui
and add these outputs:
My Output | Target Entity | Target Input | Parameter | Delay | Only Once |
---|---|---|---|---|---|
PlayerOff | !activator | AddOutput | targetname notusinggun | 0.00 | No |
PlayerOff | gun1_button | Unlock | 0.00 | No | |
PlayerOff | gun1_movement | SetMeasureTarget | gun1_base | 0.00 | No |
PressedAttack2 | !self | Deactivate | 0.00 | No |
Shooting[edit | edit source]
Make an env_gunfire
, parent it to the gun and put it on the front. Name it gun1_bullets
, set Start Disabled to Yes, parent it to gun1_model
, and set everything else however you like. Note: The env_gunfire
doesn't actually do damage, except in . You have to make the trigger below in order for the gun to do damage, unless the map is for CSGO, in which case you can substitute it for an info_target
placed ahead of the gun.
Since the bullets don't actually do damage, we have to emulate it with the next best thing: a trigger_hurt
. Shape this trigger so that extends out from the gun as much as your map requires it to. Drag the trigger's origin (little white/blue circle) to the far end of the trigger.
- Name:
gun1_hurt
- Parent:
gun1_model
- Start Disabled: Yes
- Damage Type: BULLET
Go back to your env_gunfire
and set Target to gun1_hurt
.
Now add these inputs to the game_ui
:
My Output | Target Entity | Target Input | Parameter | Delay | Only Once |
---|---|---|---|---|---|
PressedAttack | gun1_bullets | Enable | 0.00 | No | |
PressedAttack | gun1_hurt | Enable | 0.00 | No | |
UnpressedAttack | gun1_bullets | Disable | 0.00 | No | |
UnpressedAttack | gun1_hurt | Disable | 0.00 | No |
Depending on the game, you might be missing a firing sound. If so, make an ambient_generic
, name it gun1_sound
, set the Is NOT Looped flag and give it a gunfire sound.
Make a logic_timer
with these settings:
- Name:
gun1_soundtimer
- Start Disabled: Yes
- Refire Interval: .08 (adjust as needed)
My Output | Target Entity | Target Input | Parameter | Delay | Only Once |
---|---|---|---|---|---|
OnTimer | gun1_sound | PlaySound | 0.00 | No |
Finally, add two more outputs to the game_ui
:
My Output | Target Entity | Target Input | Parameter | Delay | Only Once |
---|---|---|---|---|---|
PressedAttack | gun1_soundtimer | Enable | 0.00 | No | |
UnpressedAttack | gun1_soundtimer | Disable | 0.00 | No |
Issues[edit | edit source]
TF2: alternative button[edit | edit source]
Since TF2 doesn't let players use things with E, we'll let them grab it in the next best way: hitting it. Make a filter_tf_damaged_by_weapon_in_slot
, name it melee_only
and set Weapon Slot to Melee. In your func_button
, check the Damage Activates flag and set Damage Filter to melee_only
. You'll also have to change the button's texture to tools/toolsnodraw
and live with it being solid. Don't change any outputs!
Env_gunfire doesn't appear in Hammer[edit | edit source]
This entity is missing from most FGDs, but it is usable. Some Source games will have a halflife2.fgd which does have the entity. To add that fgd, go to Tools, Options, Add, and select bin/halflife2.fgd
. If your game didn't come with one, copy the env_gunfire
code from here and paste it into an FGD Hammer is using.
Bullets don't fire[edit | edit source]
This happens in most games because they're missing some things from Half-Life 2. On the env_gunfire
, set Tracer to Default.
Players have a hard time grabbing the gun[edit | edit source]
It's probably because the gun is getting in the way of the button. Make the func_button
bigger.
See Also[edit | edit source]
- Don't want to shoot bullets, or want to emulate a certain weapon? Read Shooting anything in abstract form.