Mounted Gun (Orange Box)

Tutorial collection, comprehensive listings on main site.

Mounted Gun (Orange Box)

Postby Tutorial on Sun Aug 31, 2008 12:08 pm

category
General Half-Life 2/Effects

description
A mounted gun that comes with an attached light.

keywords
mounted, gun, mounted gun, orange, box, shoot, combine, rifle, machine, machine gun.

Setting up the stand.

Step 1. Create a prop_static with the model of:
models/props_combine/combine_barricade_short01a.mdl

Place this where you want the gun to be mounted. This could be substituted with a pile of rubble or otherwise. Here it is used to give me an idea of how high the gun should be mounted. (45-50 units if you wish to do it with a brush.)

Setting up the gun model.

Step 1. Create a prop_dynamic with the model of:

models/props_combine/bunker_gun01.mdl

Place this on top of your barricade, with the feet resting on the edges.

Image

Name the prop_dynamic:

  • Barricade_Gun_Model, or something to that effect.
  • Disable Shadows: Yes
  • Start Fade Dist: 1000
  • End Fade Dist: 2000
  • Collisions: Not Solid
  • Default Animation: idle_inactive

Image

Setting up the func_tank.

Step 1. Create a 16x16x16 cube centered over the models feet, textured with tools/toolsblockbullets.

Image

Tie this block to func_tank. (Ctrl + T) Now, copy the following settings. Most settings should be left default, unless otherwise noted.

  • Name: Barricade_Gun_Tank
  • Parent: Barricade_Gun_Model //Obviously the model that is being used for the turret.
  • Control Volume: Barricade_Gun_ControlVolume
  • Yaw Rate: 200 //How fast does it yaw? (Turn left to right)
  • Yaw Range: 60 //How far can it turn?
  • Pitch Rate: 120 //How far does it pitch? (Turn up to down)
  • Pitch Range: 60 //How far can it turn?
  • Barrel Length: 31 //Length from orgin of func_tank to the end of the muzzleflash sprite.

Used for sprite placement.

  • Barrel Vertical: 8
  • Rate of Fire: 15 //How fast does it fire?
  • Damage per Bullet: 9 //How much do the bullets do?
  • Damage Per Bullet Vs Player: 5 //How much do the bullets do to PLAYERS?
  • Firing Persistence: 4 //AI: How long to keep firing at last known position, after loosing sight of target.
  • Firing Persistence2: 2 //AI: How long to occasionaly shoot after last position.
  • Bullet Accuracy: Small Cone //How accurate is the gun?
  • Maximum Target Range: 2500 //AI: How far away can you aquire the target from?

//DO NOT CHANGE ANY VALUES BELOW, UNLESS YOU KNOW WHAT YOU ARE DOING.
  • Gun Base Attachment: aimrotation
  • Gun Barrel Attachment: muzzle
  • Gun Yaw Pose Param: aim_yaw
  • Gun Pitch Pose Param: aim_pitch
  • Gun Pitch Pose Center: 7.5
//DO NOT CHANGE ANY VALUES ABOVE, UNLESS YOU KNOW WHAT YOU ARE DOING. (Is related to the bunkergun model, and code.)

  • Ammountion Count: -1 //How much ammo does this gun have?
  • NPC Man Point: Barricade_Gun_Manpoint
  • Player Lock Time: 0.1 //AI: How long to be tracking the player before shooting?
  • Effect Handling: AR2 //Effects sounds
  • Ammo Type: AR2 //What ammo does it use, how much damage, etc. MODDERS: Uses ammotypes defined in hl2_gamerules.cpp

Image

Step 1.5: Go to the func_tank's flags, and check:

  • Active
  • Controllable
  • NPC Controlable
  • Non-Solid

Step 2: Create a 80x35x128+-ish brush, texture it with tools/toolstrigger, and tie it to a trigger_multiple. These numbers do not need to be exact, and can be changed for your liking. This defines in what area the player can "Use" the func_tank. If he is pushed out of it, he will stop using it.

THIS MUST BE TALLER THEN THE PLAYER HEIGHT.

Name the trigger_multiple: Barricade_Gun_ControlVolume
And under Flags check:
Clients

Image

Step 3: Create an info_target and inch or so off the ground, with the name:
Barricade_Gun_Manpoint

Place it exactly 32 units behind the centre of the func_tank volume. This is used for AI's controlling the gun, and tells them where to stand, so animations work.

Image

Setting up the outputs

This one's a bit of a doozy. You have to set several animations, with delays, so I'll do it like this.

Output | Targetname | Input | Parameter | Delay.

  • OnFire | Barricade_Gun_Model | SetAnimation | Fire
  • OnGotControler | Barricade_Gun_Model | SetAnimation | Activate
  • OnGotControler | Barricade_Gun_Model | SetDefaultAnimation | Idle | 0.1
  • OnGotPlayerControler | Barricade_Gun_Model | SetAnimation | Activate
  • OnGotPlayerControler | Barricade_Gun_Model | SetDefaultAnimation | Idle | 0.1
  • OnLostControler | Barricade_Gun_Model | SetAnimation | Retract
  • OnLostControler | Barricade_Gun_Model | SetDefaultAnimation | Idle | 0.1
  • OnLostPlayerControler | Barricade_Gun_Model | SetAnimation | Retract
  • OnLostPlayerControler | Barricade_Gun_Model | SetDefaultAnimation | idle_inactive | 0.1

And since that's confusing:

Image

If you compile that, (after putting in the rest of the map, and a spawn...) and go into game, it should work.

Adding some cool effects.

Because frankly, effects are awesome. Were going to create a light that turns on when the gun is in use, and turns off when it's not (And moves with it).

Create a env_sprite, with the following settings:

  • Name: Barricade_Gun_Model_Sprite_Glow
  • Parent: Barricade_Gun_Model
  • Render Mode: Worldspace Glow
  • Scale: .3
  • HDR Color Scale: .5
  • FX Amount: 215
  • FX Color: 225 255 255
  • Render Mode: Additive

Place this at the tip of the barrel, near the small flashlight. Create a point_spotlight, so that there's an actual effect:

  • Name: Barricade_Gun_Model_Sprite_Spotlight
  • Parent: Barricade_Gun_Model
  • Spotlight Width: 18
  • Spotlight Length: 128
  • HDR Color Scale: .7
  • Color: 225 255 255

Image

Now, to make it move with the gun, create a logic auto with the following outputs:

  • OnMapSpawn | Barricade_Gun_Model_Spite_Glow | SetParentAttachment | muzzle
  • OnMapSpawn | Barricade_Gun_Model_Sprite_Spotlight | SetParentAttachment | muzzle

Image

Now, we've got a light that tracks around. Pretty cool, but you know, it could be cooler.
Add two more Outputs:

  • OnMapSpawn | Barricade_Gun_Model_Sprite_Glow | HideSprite
  • OnMapSpawn | Barricade_Gun_Model_Sprite_Spotlight | LightOff

This could also be accomplished by checking the flags inside of the Spotlight, and the Sprite, but that would require you going back to those entites.

Go to the func_tank, and add these Outputs:

  • OnGotController | Barricade_Gun_Model_Sprite_Spotlight | LightOn | 0.15
  • OnGotController | Barricade_Gun_Model_Sprite_Glow | ShowSprite | 0.2
  • OnLostController | Barricade_Gun_Model_Sprite_Spotlight | LightOff | 0.05
  • OnLostController | Barricade_Gun_Model_Sprite_Glow | HideSprite | 0.1

Duplicate your efforts for OnGotPlayerController, and OnLostPlayerController.

Image

InGame Screenies:

Image
Image
Image

- Lord Ned
- Don't send PM's to this user -
Tutorial
Not A Real User
 
Joined: Sun Mar 06, 2005 11:00 pm

Re: Mounted Gun (Orange Box)

Postby marnamai on Sun Aug 31, 2008 12:28 pm

Good tutorial, but it has one minor flaw. The hands of the NPC (holding/aiming anims) controlling the turret don't always match up with the gun and it looks really weird.

Here are some screenshots showing the problem.

EDIT: FIXED the problem, the distance between the func_tank's orgin and the info_target's orgin was too short. PLEASE update the tutorial, the perfect distance is 40 units, not 32. ;)
Attachments
bunkergun0001.jpg
(239.44 KiB) Downloaded 81 times
bunkergun0000.jpg
(314.13 KiB) Downloaded 63 times
User avatar
marnamai
Veteran
Veteran
 
Joined: Thu Nov 10, 2005 12:17 pm
Location: Belgium

Re: Mounted Gun (Orange Box)

Postby Lord Ned on Tue Sep 02, 2008 6:51 pm

When I wrote it, I had the same problem when a citizen grabbed it, but as soon as he panned back and forth, the hands got to the place.
User avatar
Lord Ned
Sir Post-a-lot
Sir Post-a-lot
 
Joined: Thu Jul 17, 2008 8:42 pm

Re: Mounted Gun (Orange Box)

Postby Jangalomph on Wed Sep 10, 2008 12:07 am

Very nice. This will help me with other weapons etc. Thanks man :D
User avatar
Jangalomph
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Wed Jun 25, 2008 3:19 pm
Location: Sumter, SC

Re: Mounted Gun (Orange Box)

Postby andy4729 on Wed Oct 22, 2008 1:33 pm

Hey, nice tutorial.

Only problem i have though is that i spawn an npc next to it. Not touching it or anything but it prefers to shoot me with its gun rather than the turret. Any ideas to force it onto the turret?

I've tried giving the func_tank an input to look for NPCs and the NPC specifically by name. I've also tried taking away the NPC's weapon, still nothing. I've also made sure the info_target in40 units away as someone said.
User avatar
andy4729
Regular
Regular
 
Joined: Sat Sep 09, 2006 7:26 pm
Location: Canterbury, United Kingdom

Re: Mounted Gun (Orange Box)

Postby KimboRambo on Fri Nov 28, 2008 12:44 pm

andy4729 wrote:Hey, nice tutorial.

Only problem i have though is that i spawn an npc next to it. Not touching it or anything but it prefers to shoot me with its gun rather than the turret. Any ideas to force it onto the turret?

I've tried giving the func_tank an input to look for NPCs and the NPC specifically by name. I've also tried taking away the NPC's weapon, still nothing. I've also made sure the info_target in40 units away as someone said.


I have the same problem, anyone?

Is fine now, nevermind.
KimboRambo
Just Joined
Just Joined
 
Joined: Thu Nov 27, 2008 12:08 pm

Re: Mounted Gun (Orange Box)

Postby Mephasto on Sun Dec 28, 2008 11:42 pm

Well it works fine otherwise.. but its not showing bullet animation or hurting player when npc is using it. Do you need special entity of some kind for that?

Also what animation smoke/flash sprites does AR2 use
User avatar
Mephasto
May Contain Skills
May Contain Skills
 
Joined: Sun Aug 19, 2007 7:03 pm
Location: Finland, Tampere

Re: Mounted Gun (Orange Box)

Postby kkirspel on Sat Jan 03, 2009 6:14 am

andy4729 wrote:Hey, nice tutorial.

Only problem i have though is that i spawn an npc next to it. Not touching it or anything but it prefers to shoot me with its gun rather than the turret. Any ideas to force it onto the turret?

I've tried giving the func_tank an input to look for NPCs and the NPC specifically by name. I've also tried taking away the NPC's weapon, still nothing. I've also made sure the info_target in40 units away as someone said.


Make sure the info_target's name is correctly entered into the func_tank's NPC Man Point in its Class Info. I actually had the same problem and realized the solution today...

I do have another problem I don't understand: my point_spotlight works fine when a npc is using the gun, but when I'm using it (or directly behind the npc gunner) the spotlight fades out. How do you get it to work like in the final picture in the tut?
The inspiration as to why I'm here: Adam Foster; Minerva. Great job man.
User avatar
kkirspel
Pheropod
Pheropod
 
Joined: Wed Dec 03, 2008 6:34 pm
Location: Columbus, GA, USA

Re: Mounted Gun (Orange Box)

Postby Mas-pro on Sun Feb 21, 2010 4:37 pm

kkirspel wrote:
andy4729 wrote:Hey, nice tutorial.

Only problem i have though is that i spawn an npc next to it. Not touching it or anything but it prefers to shoot me with its gun rather than the turret. Any ideas to force it onto the turret?

I've tried giving the func_tank an input to look for NPCs and the NPC specifically by name. I've also tried taking away the NPC's weapon, still nothing. I've also made sure the info_target in40 units away as someone said.


Make sure the info_target's name is correctly entered into the func_tank's NPC Man Point in its Class Info. I actually had the same problem and realized the solution today...

I do have another problem I don't understand: my point_spotlight works fine when a npc is using the gun, but when I'm using it (or directly behind the npc gunner) the spotlight fades out. How do you get it to work like in the final picture in the tut?



Yeah you might have found what the problem was but like can you tell us cos just saying uv found the problem dose not help us one bit btw.
Zilly
Mas-pro
Member
Member
 
Joined: Fri Oct 20, 2006 9:29 pm

Re: Mounted Gun (Orange Box)

Postby tophat_anon on Fri Sep 10, 2010 1:41 pm

Thanks for the tut. I have a problem with my gun. Everything works fine, including all the firing animations and sounds etc, but the gun just fires blanks. It doesn't do any damage to NPCs or explosive barrels and makes no bullet holes in the wall. I've made sure that I set Ammo Type to AR2 and Bullet Damage to 9 but they don't seem to matter.

If it's any help, I followed a different tutorial ( http://forum.interlopers.net/viewtopic.php?t=1782 ) before and had the same problem, so I'm not sure if it's a problem with my SDK settings or something. Although, on the other tut, alot of people also had the same problem.
tophat_anon
Just Joined
Just Joined
 
Joined: Fri Sep 10, 2010 1:31 pm

Re: Mounted Gun (Orange Box)

Postby kkirspel on Wed Oct 13, 2010 5:10 am

Mas-pro wrote:Yeah you might have found what the problem was but like can you tell us cos just saying uv found the problem dose not help us one bit btw.


kkirspel wrote:Make sure the info_target's name is correctly entered into the func_tank's NPC Man Point in its Class Info.
The inspiration as to why I'm here: Adam Foster; Minerva. Great job man.
User avatar
kkirspel
Pheropod
Pheropod
 
Joined: Wed Dec 03, 2008 6:34 pm
Location: Columbus, GA, USA

Re: Mounted Gun (Orange Box)

Postby Kareena on Thu Dec 02, 2010 10:15 am

Its informative update
Kareena
Dumpling
Dumpling
 
Joined: Thu Dec 02, 2010 10:12 am

Re: Mounted Gun (Orange Box)

Postby kkirspel on Thu Dec 02, 2010 7:49 pm

Kareena wrote:Its informative update

huh, what?
The inspiration as to why I'm here: Adam Foster; Minerva. Great job man.
User avatar
kkirspel
Pheropod
Pheropod
 
Joined: Wed Dec 03, 2008 6:34 pm
Location: Columbus, GA, USA

Re: Mounted Gun (Orange Box)

Postby joe_rogers_11155 on Thu Jan 10, 2013 6:47 am

...those bots are getting smarter every day
"Day breaks, but decay soon follows." - Ava Winona
Currently developing in radio silence... 99 Bolts
Here's another project of mine... Assault on Overwatch
Are you new to Source SDK? VDC
joe_rogers_11155
Veteran
Veteran
 
Joined: Wed Oct 08, 2008 11:11 pm
Location: United States

Return to Tutorials

Who is online

Users browsing this forum: No registered users