Mounted guns

From Source Entities
Jump to navigation Jump to search

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 Tf2.png, 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 OutputTarget EntityTarget InputParameterDelayOnly Once
OnPressed!selfLock0.00No
OnPressed!activatorAddOutputtargetname gun1_user0.00No
OnPressedgun1_movementSetMeasureTargetgun1_user0.01No
OnPressedgun1_uiActivate0.00No

Now go to the game_ui and add these outputs:

My OutputTarget EntityTarget InputParameterDelayOnly Once
PlayerOff!activatorAddOutputtargetname notusinggun0.00No
PlayerOffgun1_buttonUnlock0.00No
PlayerOffgun1_movementSetMeasureTargetgun1_base0.00No
PressedAttack2!selfDeactivate0.00No

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 Csgo-small.png. 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 OutputTarget EntityTarget InputParameterDelayOnly Once
PressedAttackgun1_bulletsEnable0.00No
PressedAttackgun1_hurtEnable0.00No
UnpressedAttackgun1_bulletsDisable0.00No
UnpressedAttackgun1_hurtDisable0.00No

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 OutputTarget EntityTarget InputParameterDelayOnly Once
OnTimergun1_soundPlaySound0.00No

Finally, add two more outputs to the game_ui:

My OutputTarget EntityTarget InputParameterDelayOnly Once
PressedAttackgun1_soundtimerEnable0.00No
UnpressedAttackgun1_soundtimerDisable0.00No

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]