2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", _("Machine Gun"))
6 // weapon load persistence, for weapons that support reloading
9 void W_UZI_SetAmmoCounter()
11 // set clip_load to the weapon we have switched to, if the gun uses reloading
12 if(!autocvar_g_balance_uzi_reload_ammo)
13 self.clip_load = 0; // also keeps crosshair ammo from displaying
16 self.clip_load = self.uzi_load;
17 self.clip_size = autocvar_g_balance_uzi_reload_ammo; // for the crosshair ammo display
23 self.reload_ammo_player = ammo_fuel;
24 self.reload_ammo_min = min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo);
25 self.reload_ammo_amount = autocvar_g_balance_uzi_reload_ammo;
26 self.reload_time = autocvar_g_balance_uzi_reload_time;
27 self.reload_sound = "weapons/reload.wav";
32 // leilei's fancy muzzleflash stuff
35 self.frame = self.frame + 2;
36 self.scale = self.scale * 0.5;
37 self.alpha = self.alpha - 0.25;
38 self.nextthink = time + 0.05;
42 self.think = SUB_Remove;
43 self.nextthink = time;
44 self.owner.muzzle_flash = world;
52 if (self.muzzle_flash == world)
53 self.muzzle_flash = spawn();
55 // muzzle flash for 1st person view
56 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
58 self.muzzle_flash.scale = 0.75;
59 self.muzzle_flash.think = UZI_Flash_Go;
60 self.muzzle_flash.nextthink = time + 0.02;
61 self.muzzle_flash.frame = 2;
62 self.muzzle_flash.alpha = 0.75;
63 self.muzzle_flash.angles_z = random() * 180;
64 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
65 self.muzzle_flash.owner = self;
68 void W_UZI_Attack (float deathtype)
70 W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, ((self.misc_bulletcounter == 1) ? autocvar_g_balance_uzi_first_damage : autocvar_g_balance_uzi_sustained_damage));
73 self.punchangle_x = random () - 0.5;
74 self.punchangle_y = random () - 0.5;
77 // this attack_finished just enforces a cooldown at the end of a burst
78 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
80 if (self.misc_bulletcounter == 1)
81 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_first_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_first_damage, 0, autocvar_g_balance_uzi_first_force, deathtype, 0, 1, autocvar_g_balance_uzi_bulletconstant);
83 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_sustained_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, deathtype, 0, 1, autocvar_g_balance_uzi_bulletconstant);
84 endFireBallisticBullet();
86 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
89 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
92 if (autocvar_g_casings >= 2)
93 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
95 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
96 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
98 if(autocvar_g_balance_uzi_reload_ammo)
100 if (self.misc_bulletcounter == 1)
101 self.clip_load -= autocvar_g_balance_uzi_first_ammo;
103 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
104 self.uzi_load = self.clip_load;
108 if (self.misc_bulletcounter == 1)
109 self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
111 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
119 if(self.weapon != self.switchweapon) // abort immediately if switching
124 if (self.BUTTON_ATCK)
126 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
128 W_SwitchWeapon_Force(self, w_getbestweapon(self));
132 self.misc_bulletcounter = self.misc_bulletcounter + 1;
133 W_UZI_Attack(WEP_UZI);
134 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
137 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
141 void uzi_mode1_fire_auto()
145 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
146 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
148 if(autocvar_g_balance_uzi_reload_ammo)
150 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
151 self.uzi_load = self.clip_load;
154 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
157 if (self.BUTTON_ATCK)
158 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
161 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
162 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
166 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
168 W_SwitchWeapon_Force(self, w_getbestweapon(self));
173 W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, autocvar_g_balance_uzi_sustained_damage);
176 self.punchangle_x = random () - 0.5;
177 self.punchangle_y = random () - 0.5;
180 uzi_spread = bound(autocvar_g_balance_uzi_spread_min, autocvar_g_balance_uzi_spread_min + (autocvar_g_balance_uzi_spread_add * self.misc_bulletcounter), autocvar_g_balance_uzi_spread_max);
181 fireBallisticBullet(w_shotorg, w_shotdir, uzi_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, 1, autocvar_g_balance_uzi_bulletconstant);
182 endFireBallisticBullet();
184 self.misc_bulletcounter = self.misc_bulletcounter + 1;
186 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
189 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
191 if (autocvar_g_casings >= 2) // casing code
192 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
195 void uzi_mode1_fire_burst()
197 W_SetupShot (self, autocvar_g_antilag_bullets && autocvar_g_balance_uzi_speed >= autocvar_g_antilag_bullets, 0, "weapons/uzi_fire.wav", CHAN_WEAPON, autocvar_g_balance_uzi_sustained_damage);
200 self.punchangle_x = random () - 0.5;
201 self.punchangle_y = random () - 0.5;
204 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_burst_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, 0, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, 1, autocvar_g_balance_uzi_bulletconstant);
205 endFireBallisticBullet();
208 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
211 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
213 if (autocvar_g_casings >= 2) // casing code
214 SpawnCasing (((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3, self);
216 self.misc_bulletcounter = self.misc_bulletcounter + 1;
217 if (self.misc_bulletcounter == 0)
219 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
220 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
224 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
229 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
231 float w_uzi(float req)
235 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
236 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
239 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
241 else if (req == WR_THINK)
243 if(autocvar_g_balance_uzi_reload_ammo && self.clip_load < min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo)) // forced reload
245 else if(autocvar_g_balance_uzi_mode == 1)
247 if (self.BUTTON_ATCK)
248 if (weapon_prepareattack(0, 0))
250 self.misc_bulletcounter = 0;
251 uzi_mode1_fire_auto();
254 if(self.BUTTON_ATCK2)
255 if(weapon_prepareattack(1, 0))
257 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
259 W_SwitchWeapon_Force(self, w_getbestweapon(self));
264 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
265 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
267 if(autocvar_g_balance_uzi_reload_ammo)
269 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
270 self.uzi_load = self.clip_load;
273 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
276 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
277 uzi_mode1_fire_burst();
283 if (self.BUTTON_ATCK)
284 if (weapon_prepareattack(0, 0))
286 self.misc_bulletcounter = 1;
287 W_UZI_Attack(WEP_UZI); // sets attack_finished
288 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
291 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
292 if (weapon_prepareattack(1, 0))
294 self.misc_bulletcounter = 1;
295 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
296 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
300 else if (req == WR_PRECACHE)
302 precache_model ("models/uziflash.md3");
303 precache_model ("models/weapons/g_uzi.md3");
304 precache_model ("models/weapons/v_uzi.md3");
305 precache_model ("models/weapons/h_uzi.iqm");
306 precache_sound ("weapons/uzi_fire.wav");
307 precache_sound ("weapons/reload.wav");
309 else if (req == WR_SETUP)
311 weapon_setup(WEP_UZI);
312 W_UZI_SetAmmoCounter();
314 else if (req == WR_CHECKAMMO1)
316 if(autocvar_g_balance_uzi_mode == 1)
317 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
319 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
321 if(autocvar_g_balance_uzi_reload_ammo)
323 if(autocvar_g_balance_uzi_mode == 1)
324 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_sustained_ammo;
326 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
330 else if (req == WR_CHECKAMMO2)
332 if(autocvar_g_balance_uzi_mode == 1)
333 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
335 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
337 if(autocvar_g_balance_uzi_reload_ammo)
339 if(autocvar_g_balance_uzi_mode == 1)
340 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_burst_ammo;
342 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
346 else if (req == WR_RESETPLAYER)
348 // all weapons must be fully loaded when we spawn
349 self.uzi_load = autocvar_g_balance_uzi_reload_ammo;
351 else if (req == WR_RELOAD)
359 float w_uzi(float req)
361 if(req == WR_IMPACTEFFECT)
364 org2 = w_org + w_backoff * 2;
365 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
368 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
369 else if(w_random < 0.1)
370 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
371 else if(w_random < 0.2)
372 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
374 else if(req == WR_PRECACHE)
376 precache_sound("weapons/ric1.wav");
377 precache_sound("weapons/ric2.wav");
378 precache_sound("weapons/ric3.wav");
380 else if (req == WR_SUICIDEMESSAGE)
381 w_deathtypestring = _("%s did the impossible");
382 else if (req == WR_KILLMESSAGE)
384 if(w_deathtype & HITTYPE_SECONDARY)
385 w_deathtypestring = _("%s was sniped by %s");
387 w_deathtypestring = _("%s was riddled full of holes by %s");