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
21 void W_UZI_ReloadedAndReady()
25 // now do the ammo transfer
26 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
27 while(self.clip_load < autocvar_g_balance_uzi_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have
32 self.uzi_load = self.clip_load;
34 t = ATTACK_FINISHED(self) - autocvar_g_balance_uzi_reload_time - 1;
35 ATTACK_FINISHED(self) = t;
41 // return if reloading is disabled for this weapon
42 if(!autocvar_g_balance_uzi_reload_ammo)
45 if(!W_ReloadCheck(self.ammo_nails, min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo)))
50 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
52 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_uzi_reload_time + 1;
53 ATTACK_FINISHED(self) = t;
55 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_uzi_reload_time, W_UZI_ReloadedAndReady);
57 self.old_clip_load = self.clip_load;
61 // leilei's fancy muzzleflash stuff
64 self.frame = self.frame + 2;
65 self.scale = self.scale * 0.5;
66 self.alpha = self.alpha - 0.25;
67 self.nextthink = time + 0.05;
71 self.think = SUB_Remove;
72 self.nextthink = time;
73 self.owner.muzzle_flash = world;
81 if (self.muzzle_flash == world)
82 self.muzzle_flash = spawn();
84 // muzzle flash for 1st person view
85 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
87 self.muzzle_flash.scale = 0.75;
88 self.muzzle_flash.think = UZI_Flash_Go;
89 self.muzzle_flash.nextthink = time + 0.02;
90 self.muzzle_flash.frame = 2;
91 self.muzzle_flash.alpha = 0.75;
92 self.muzzle_flash.angles_z = random() * 180;
93 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
94 self.muzzle_flash.owner = self;
97 void W_UZI_Attack (float deathtype)
99 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));
102 self.punchangle_x = random () - 0.5;
103 self.punchangle_y = random () - 0.5;
106 // this attack_finished just enforces a cooldown at the end of a burst
107 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
109 if (self.misc_bulletcounter == 1)
110 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);
112 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);
113 endFireBallisticBullet();
115 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
118 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
121 if (autocvar_g_casings >= 2)
122 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);
124 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
125 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
127 if(autocvar_g_balance_uzi_reload_ammo)
129 if (self.misc_bulletcounter == 1)
130 self.clip_load -= autocvar_g_balance_uzi_first_ammo;
132 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
133 self.uzi_load = self.clip_load;
137 if (self.misc_bulletcounter == 1)
138 self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
140 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
148 if(self.weapon != self.switchweapon) // abort immediately if switching
153 if (self.BUTTON_ATCK)
155 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
157 W_SwitchWeapon_Force(self, w_getbestweapon(self));
161 self.misc_bulletcounter = self.misc_bulletcounter + 1;
162 W_UZI_Attack(WEP_UZI);
163 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
166 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
170 void uzi_mode1_fire_auto()
174 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
175 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
177 if(autocvar_g_balance_uzi_reload_ammo)
179 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
180 self.uzi_load = self.clip_load;
183 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
186 if (self.BUTTON_ATCK)
187 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
190 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
191 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
195 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
197 W_SwitchWeapon_Force(self, w_getbestweapon(self));
202 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);
205 self.punchangle_x = random () - 0.5;
206 self.punchangle_y = random () - 0.5;
209 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);
210 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);
211 endFireBallisticBullet();
213 self.misc_bulletcounter = self.misc_bulletcounter + 1;
215 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
218 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
220 if (autocvar_g_casings >= 2) // casing code
221 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);
224 void uzi_mode1_fire_burst()
226 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);
229 self.punchangle_x = random () - 0.5;
230 self.punchangle_y = random () - 0.5;
233 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);
234 endFireBallisticBullet();
237 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
240 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
242 if (autocvar_g_casings >= 2) // casing code
243 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);
245 self.misc_bulletcounter = self.misc_bulletcounter + 1;
246 if (self.misc_bulletcounter == 0)
248 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
249 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
253 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
258 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
260 float w_uzi(float req)
264 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
265 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
268 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
270 else if (req == WR_THINK)
272 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
274 else if(autocvar_g_balance_uzi_mode == 1)
276 if (self.BUTTON_ATCK)
277 if (weapon_prepareattack(0, 0))
279 self.misc_bulletcounter = 0;
280 uzi_mode1_fire_auto();
283 if(self.BUTTON_ATCK2)
284 if(weapon_prepareattack(1, 0))
286 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
288 W_SwitchWeapon_Force(self, w_getbestweapon(self));
293 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
294 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
296 if(autocvar_g_balance_uzi_reload_ammo)
298 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
299 self.uzi_load = self.clip_load;
302 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
305 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
306 uzi_mode1_fire_burst();
312 if (self.BUTTON_ATCK)
313 if (weapon_prepareattack(0, 0))
315 self.misc_bulletcounter = 1;
316 W_UZI_Attack(WEP_UZI); // sets attack_finished
317 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
320 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
321 if (weapon_prepareattack(1, 0))
323 self.misc_bulletcounter = 1;
324 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
325 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
329 else if (req == WR_PRECACHE)
331 precache_model ("models/uziflash.md3");
332 precache_model ("models/weapons/g_uzi.md3");
333 precache_model ("models/weapons/v_uzi.md3");
334 precache_model ("models/weapons/h_uzi.iqm");
335 precache_sound ("weapons/uzi_fire.wav");
336 precache_sound ("weapons/reload.wav");
338 else if (req == WR_SETUP)
340 weapon_setup(WEP_UZI);
341 W_UZI_SetAmmoCounter();
343 else if (req == WR_CHECKAMMO1)
345 if(autocvar_g_balance_uzi_mode == 1)
346 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
348 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
350 if(autocvar_g_balance_uzi_reload_ammo)
352 if(autocvar_g_balance_uzi_mode == 1)
353 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_sustained_ammo;
355 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
359 else if (req == WR_CHECKAMMO2)
361 if(autocvar_g_balance_uzi_mode == 1)
362 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
364 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
366 if(autocvar_g_balance_uzi_reload_ammo)
368 if(autocvar_g_balance_uzi_mode == 1)
369 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_burst_ammo;
371 ammo_amount += self.uzi_load >= autocvar_g_balance_uzi_first_ammo;
375 else if (req == WR_RESETPLAYER)
377 // all weapons must be fully loaded when we spawn
378 self.uzi_load = autocvar_g_balance_uzi_reload_ammo;
380 else if (req == WR_RELOAD)
388 float w_uzi(float req)
390 if(req == WR_IMPACTEFFECT)
393 org2 = w_org + w_backoff * 2;
394 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
397 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
398 else if(w_random < 0.1)
399 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
400 else if(w_random < 0.2)
401 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
403 else if(req == WR_PRECACHE)
405 precache_sound("weapons/ric1.wav");
406 precache_sound("weapons/ric2.wav");
407 precache_sound("weapons/ric3.wav");
409 else if (req == WR_SUICIDEMESSAGE)
410 w_deathtypestring = _("%s did the impossible");
411 else if (req == WR_KILLMESSAGE)
413 if(w_deathtype & HITTYPE_SECONDARY)
414 w_deathtypestring = _("%s was sniped by %s");
416 w_deathtypestring = _("%s was riddled full of holes by %s");