2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", _("Machine Gun"))
6 void W_UZI_SetAmmoCounter()
8 // set clip_load to the weapon we have switched to, if the gun uses reloading
9 if(!autocvar_g_balance_uzi_reload_ammo)
10 self.clip_load = 0; // also keeps crosshair ammo from displaying
13 self.clip_load = self.weapon_load[WEP_UZI];
14 self.clip_size = autocvar_g_balance_uzi_reload_ammo; // for the crosshair ammo display
20 self.reload_ammo_player = ammo_nails;
21 self.reload_ammo_min = min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo);
22 self.reload_ammo_amount = autocvar_g_balance_uzi_reload_ammo;
23 self.reload_time = autocvar_g_balance_uzi_reload_time;
24 self.reload_sound = "weapons/reload.wav";
29 // leilei's fancy muzzleflash stuff
32 self.frame = self.frame + 2;
33 self.scale = self.scale * 0.5;
34 self.alpha = self.alpha - 0.25;
35 self.nextthink = time + 0.05;
39 self.think = SUB_Remove;
40 self.nextthink = time;
41 self.owner.muzzle_flash = world;
49 if (self.muzzle_flash == world)
50 self.muzzle_flash = spawn();
52 // muzzle flash for 1st person view
53 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
55 self.muzzle_flash.scale = 0.75;
56 self.muzzle_flash.think = UZI_Flash_Go;
57 self.muzzle_flash.nextthink = time + 0.02;
58 self.muzzle_flash.frame = 2;
59 self.muzzle_flash.alpha = 0.75;
60 self.muzzle_flash.angles_z = random() * 180;
61 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
62 self.muzzle_flash.owner = self;
65 void W_UZI_Attack (float deathtype)
67 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));
70 self.punchangle_x = random () - 0.5;
71 self.punchangle_y = random () - 0.5;
74 // this attack_finished just enforces a cooldown at the end of a burst
75 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
77 if (self.misc_bulletcounter == 1)
78 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);
80 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);
81 endFireBallisticBullet();
83 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
86 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
89 if (autocvar_g_casings >= 2)
90 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);
92 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
93 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
95 if(autocvar_g_balance_uzi_reload_ammo)
97 if (self.misc_bulletcounter == 1)
98 self.clip_load -= autocvar_g_balance_uzi_first_ammo;
100 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
101 self.weapon_load[WEP_UZI] = self.clip_load;
105 if (self.misc_bulletcounter == 1)
106 self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
108 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
116 if(self.weapon != self.switchweapon) // abort immediately if switching
121 if (self.BUTTON_ATCK)
123 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
125 W_SwitchWeapon_Force(self, w_getbestweapon(self));
129 self.misc_bulletcounter = self.misc_bulletcounter + 1;
130 W_UZI_Attack(WEP_UZI);
131 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
134 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
138 void uzi_mode1_fire_auto()
142 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
143 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
145 if(autocvar_g_balance_uzi_reload_ammo)
147 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
148 self.weapon_load[WEP_UZI] = self.clip_load;
151 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
154 if (self.BUTTON_ATCK)
155 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
158 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
159 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
163 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
165 W_SwitchWeapon_Force(self, w_getbestweapon(self));
170 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);
173 self.punchangle_x = random () - 0.5;
174 self.punchangle_y = random () - 0.5;
177 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);
178 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);
179 endFireBallisticBullet();
181 self.misc_bulletcounter = self.misc_bulletcounter + 1;
183 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
186 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
188 if (autocvar_g_casings >= 2) // casing code
189 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);
192 void uzi_mode1_fire_burst()
194 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);
197 self.punchangle_x = random () - 0.5;
198 self.punchangle_y = random () - 0.5;
201 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);
202 endFireBallisticBullet();
205 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
208 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
210 if (autocvar_g_casings >= 2) // casing code
211 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);
213 self.misc_bulletcounter = self.misc_bulletcounter + 1;
214 if (self.misc_bulletcounter == 0)
216 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
217 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
221 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
226 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
228 float w_uzi(float req)
232 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
233 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
236 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
238 else if (req == WR_THINK)
240 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
242 else if(autocvar_g_balance_uzi_mode == 1)
244 if (self.BUTTON_ATCK)
245 if (weapon_prepareattack(0, 0))
247 self.misc_bulletcounter = 0;
248 uzi_mode1_fire_auto();
251 if(self.BUTTON_ATCK2)
252 if(weapon_prepareattack(1, 0))
254 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
256 W_SwitchWeapon_Force(self, w_getbestweapon(self));
261 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
262 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
264 if(autocvar_g_balance_uzi_reload_ammo)
266 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
267 self.weapon_load[WEP_UZI] = self.clip_load;
270 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
273 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
274 uzi_mode1_fire_burst();
280 if (self.BUTTON_ATCK)
281 if (weapon_prepareattack(0, 0))
283 self.misc_bulletcounter = 1;
284 W_UZI_Attack(WEP_UZI); // sets attack_finished
285 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
288 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
289 if (weapon_prepareattack(1, 0))
291 self.misc_bulletcounter = 1;
292 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
293 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
297 else if (req == WR_PRECACHE)
299 precache_model ("models/uziflash.md3");
300 precache_model ("models/weapons/g_uzi.md3");
301 precache_model ("models/weapons/v_uzi.md3");
302 precache_model ("models/weapons/h_uzi.iqm");
303 precache_sound ("weapons/uzi_fire.wav");
304 precache_sound ("weapons/reload.wav");
306 else if (req == WR_SETUP)
308 weapon_setup(WEP_UZI);
309 W_UZI_SetAmmoCounter();
311 else if (req == WR_CHECKAMMO1)
313 if(autocvar_g_balance_uzi_mode == 1)
314 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
316 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
318 if(autocvar_g_balance_uzi_reload_ammo)
320 if(autocvar_g_balance_uzi_mode == 1)
321 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_sustained_ammo;
323 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
327 else if (req == WR_CHECKAMMO2)
329 if(autocvar_g_balance_uzi_mode == 1)
330 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
332 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
334 if(autocvar_g_balance_uzi_reload_ammo)
336 if(autocvar_g_balance_uzi_mode == 1)
337 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_burst_ammo;
339 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
343 else if (req == WR_RESETPLAYER)
345 // all weapons must be fully loaded when we spawn
346 self.weapon_load[WEP_UZI] = autocvar_g_balance_uzi_reload_ammo;
348 else if (req == WR_RELOAD)
356 float w_uzi(float req)
358 if(req == WR_IMPACTEFFECT)
361 org2 = w_org + w_backoff * 2;
362 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
365 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
366 else if(w_random < 0.1)
367 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
368 else if(w_random < 0.2)
369 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
371 else if(req == WR_PRECACHE)
373 precache_sound("weapons/ric1.wav");
374 precache_sound("weapons/ric2.wav");
375 precache_sound("weapons/ric3.wav");
377 else if (req == WR_SUICIDEMESSAGE)
378 w_deathtypestring = _("%s did the impossible");
379 else if (req == WR_KILLMESSAGE)
381 if(w_deathtype & HITTYPE_SECONDARY)
382 w_deathtypestring = _("%s was sniped by %s");
384 w_deathtypestring = _("%s was riddled full of holes by %s");