]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_shotgun.qc
secondary shotgun mode now also has a muzzleflash
[divverent/nexuiz.git] / data / qcsrc / server / w_shotgun.qc
1
2 void W_Shotgun_Attack (void)
3 {
4         float   sc;
5         float   bullets;
6         float   d;
7         float   f;
8         float   spread;
9         local entity flash;
10
11         bullets = cvar("g_balance_shotgun_primary_bullets");
12         d = cvar("g_balance_shotgun_primary_damage");
13         f = cvar("g_balance_shotgun_primary_force");
14         spread = cvar("g_balance_shotgun_primary_spread");
15
16         W_SetupShot (self, '11 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
17         for (sc = 0;sc < bullets;sc = sc + 1)
18                 fireBullet (w_shotorg, w_shotdir, spread, d, f, IT_SHOTGUN, sc < 3);
19         if (cvar("g_use_ammunition"))
20                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_primary_ammo");
21
22         W_Smoke(w_shotorg + v_forward * 8, v_forward, 12);
23         //te_smallflash(w_shotorg);
24
25         // casing code
26         if (cvar("g_casings") >= 1)
27                 SpawnCasing (w_shotorg, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
28
29         // muzzle flash for 1st person view
30         flash = spawn();
31         setorigin(flash, '53 5 0');
32         setmodel(flash, "models/uziflash.md3"); // precision set below
33         setattachment(flash, self.weaponentity, "bone01");
34         flash.owner = self;
35         flash.viewmodelforclient = self;
36         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
37         flash.scale = 1.2;
38         flash.think = SUB_Remove;
39         flash.nextthink = time + 0.06;
40         flash.angles_z = flash.v_angle_z + random() * 180;
41         flash.alpha = 1;
42         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
43
44 }
45
46 void W_Shotgun_Attack2 (void)
47 {
48         float   sc;
49         float   bullets;
50         float   d;
51         float   f;
52         float   spread;
53         local entity flash;
54
55         bullets = cvar("g_balance_shotgun_secondary_bullets");
56         d = cvar("g_balance_shotgun_secondary_damage");
57         f = cvar("g_balance_shotgun_secondary_force");
58         spread = cvar("g_balance_shotgun_secondary_spread");
59
60         W_SetupShot (self, '11 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
61         for (sc = 0;sc < bullets;sc = sc + 1)
62                 fireBullet (w_shotorg, w_shotdir, spread, d, f, IT_SHOTGUN, sc < 3);
63         if (cvar("g_use_ammunition"))
64                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_secondary_ammo");
65
66         W_Smoke(w_shotorg + v_forward * 8, v_forward, 12);
67         //te_smallflash(w_shotorg);
68
69         // casing code
70         if (cvar("g_casings") >= 1)
71                 SpawnCasing (w_shotorg, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
72
73         flash = spawn();
74         setorigin(flash, '53 5 0');
75         setmodel(flash, "models/uziflash.md3"); // precision set below
76         setattachment(flash, self.weaponentity, "bone01");
77         flash.owner = self;
78         flash.viewmodelforclient = self;
79         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
80         flash.scale = 1.2;
81         flash.think = SUB_Remove;
82         flash.nextthink = time + 0.06;
83         flash.angles_z = flash.v_angle_z + random() * 180;
84         flash.alpha = 1;
85         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
86 }
87
88 // weapon frames
89 void()  shotgun_fire2_03 =
90 {
91         W_Shotgun_Attack2();
92         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), w_ready);
93 }
94 void()  shotgun_fire2_02 =
95 {
96         W_Shotgun_Attack2();
97         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_03);
98 }
99
100 float(float req) w_shotgun =
101 {
102         if (req == WR_AIM)
103                 if(vlen(self.origin-self.enemy.origin)>200)
104                         self.button0 = bot_aim(1000000, 0, 0.001, FALSE);
105                 else
106                         self.button3 = bot_aim(1000000, 0, 0.001, FALSE);
107         else if (req == WR_THINK)
108         {
109                 if (self.button0)
110                 if (weapon_prepareattack(0, cvar("g_balance_shotgun_primary_refire")))
111                 {
112                         W_Shotgun_Attack();
113                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_primary_animtime"), w_ready);
114                 }
115                 if (self.button3)
116                 if (weapon_prepareattack(1, cvar("g_balance_shotgun_secondary_refire")))
117                 {
118                         W_Shotgun_Attack2();
119                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_02);
120                 }
121         }
122         else if (req == WR_PRECACHE)
123         {
124                 precache_model ("models/uziflash.md3");
125                 precache_model ("models/tracer.mdl");
126                 precache_model ("models/weapons/g_shotgun.md3");
127                 precache_model ("models/weapons/v_shotgun.md3");
128                 precache_model ("models/weapons/w_shotgun.zym");
129                 precache_sound ("misc/itempickup.wav");
130                 precache_sound ("weapons/ric1.wav");
131                 precache_sound ("weapons/ric2.wav");
132                 precache_sound ("weapons/ric3.wav");
133                 precache_sound ("weapons/shotgun_fire.wav");
134                 precache_sound ("weapons/tink1.wav");
135                 if (cvar("g_casings") >= 1)
136                         precache_model ("models/casing_shell.mdl");
137         }
138         else if (req == WR_SETUP)
139                 weapon_setup(WEP_SHOTGUN, "shotgun", IT_SHELLS);
140         else if (req == WR_CHECKAMMO1)
141                 return self.ammo_shells >= cvar("g_balance_shotgun_primary_ammo");
142         else if (req == WR_CHECKAMMO2)
143                 return self.ammo_shells >= cvar("g_balance_shotgun_secondary_ammo") * 3;
144         else if (req == WR_REGISTER)
145                 weapon_register(WEP_SHOTGUN, min(cvar("g_balance_shotgun_primary_ammo"), cvar("g_balance_shotgun_secondary_ammo")));
146         return TRUE;
147 };