2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", _("Machine Gun"))
8 void W_UZI_SetAmmoCounter()
10 // set clip_load to the weapon we have switched to, if the gun uses reloading
11 if(!autocvar_g_balance_uzi_reload_ammo)
12 self.clip_load = 0; // also keeps crosshair ammo from displaying
15 self.clip_load = self.uzi_load;
16 self.clip_size = autocvar_g_balance_uzi_reload_ammo; // for the crosshair ammo display
20 void W_UZI_ReloadedAndReady()
24 // now do the ammo transfer
25 self.clip_load = self.old_clip_load; // restore the ammo counter, in case we still had ammo in the weapon before reloading
26 while(self.clip_load < autocvar_g_balance_uzi_reload_ammo && self.ammo_nails) // make sure we don't add more ammo than we have
31 self.uzi_load = self.clip_load;
33 t = ATTACK_FINISHED(self) - autocvar_g_balance_uzi_reload_time - 1;
34 ATTACK_FINISHED(self) = t;
40 // return if reloading is disabled for this weapon
41 if(!autocvar_g_balance_uzi_reload_ammo)
44 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)))
49 sound (self, CHAN_WEAPON2, "weapons/reload.wav", VOL_BASE, ATTN_NORM);
51 t = max(time, ATTACK_FINISHED(self)) + autocvar_g_balance_uzi_reload_time + 1;
52 ATTACK_FINISHED(self) = t;
54 weapon_thinkf(WFRAME_RELOAD, autocvar_g_balance_uzi_reload_time, W_UZI_ReloadedAndReady);
56 self.old_clip_load = self.clip_load;
60 // leilei's fancy muzzleflash stuff
63 self.frame = self.frame + 2;
64 self.scale = self.scale * 0.5;
65 self.alpha = self.alpha - 0.25;
66 self.nextthink = time + 0.05;
70 self.think = SUB_Remove;
71 self.nextthink = time;
72 self.owner.muzzle_flash = world;
80 if (self.muzzle_flash == world)
81 self.muzzle_flash = spawn();
83 // muzzle flash for 1st person view
84 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
86 self.muzzle_flash.scale = 0.75;
87 self.muzzle_flash.think = UZI_Flash_Go;
88 self.muzzle_flash.nextthink = time + 0.02;
89 self.muzzle_flash.frame = 2;
90 self.muzzle_flash.alpha = 0.75;
91 self.muzzle_flash.angles_z = random() * 180;
92 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
93 self.muzzle_flash.owner = self;
96 void W_UZI_Attack (float deathtype)
98 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));
101 self.punchangle_x = random () - 0.5;
102 self.punchangle_y = random () - 0.5;
105 // this attack_finished just enforces a cooldown at the end of a burst
106 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
108 if (self.misc_bulletcounter == 1)
109 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);
111 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);
112 endFireBallisticBullet();
114 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
117 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
120 if (autocvar_g_casings >= 2)
121 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);
127 if(self.weapon != self.switchweapon) // abort immediately if switching
132 if (self.BUTTON_ATCK)
134 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
136 W_SwitchWeapon_Force(self, w_getbestweapon(self));
140 self.misc_bulletcounter = self.misc_bulletcounter + 1;
141 W_UZI_Attack(WEP_UZI);
142 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
145 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
149 void uzi_mode1_fire_auto()
153 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
154 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
156 if(autocvar_g_balance_uzi_reload_ammo)
158 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
159 self.uzi_load = self.clip_load;
162 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
165 if (self.BUTTON_ATCK)
166 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
169 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
170 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
174 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
176 W_SwitchWeapon_Force(self, w_getbestweapon(self));
181 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);
184 self.punchangle_x = random () - 0.5;
185 self.punchangle_y = random () - 0.5;
188 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);
189 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);
190 endFireBallisticBullet();
192 self.misc_bulletcounter = self.misc_bulletcounter + 1;
194 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
197 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
199 if (autocvar_g_casings >= 2) // casing code
200 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);
203 void uzi_mode1_fire_burst()
205 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);
208 self.punchangle_x = random () - 0.5;
209 self.punchangle_y = random () - 0.5;
212 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);
213 endFireBallisticBullet();
216 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
219 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
221 if (autocvar_g_casings >= 2) // casing code
222 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 self.misc_bulletcounter = self.misc_bulletcounter + 1;
225 if (self.misc_bulletcounter == 0)
227 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
228 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
232 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
237 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
239 float w_uzi(float req)
242 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
243 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
246 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
248 else if (req == WR_THINK)
250 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
252 else if(autocvar_g_balance_uzi_mode == 1)
254 if (self.BUTTON_ATCK)
255 if (weapon_prepareattack(0, 0))
257 self.misc_bulletcounter = 0;
258 uzi_mode1_fire_auto();
261 if(self.BUTTON_ATCK2)
262 if(weapon_prepareattack(1, 0))
264 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
266 W_SwitchWeapon_Force(self, w_getbestweapon(self));
271 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
272 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
274 if(autocvar_g_balance_uzi_reload_ammo)
276 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
277 self.uzi_load = self.clip_load;
280 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
283 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
284 uzi_mode1_fire_burst();
290 if (self.BUTTON_ATCK)
291 if (weapon_prepareattack(0, 0))
293 self.misc_bulletcounter = 1;
294 W_UZI_Attack(WEP_UZI); // sets attack_finished
295 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
298 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
299 if (weapon_prepareattack(1, 0))
301 self.misc_bulletcounter = 1;
302 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
303 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
308 if(self.switchweapon == self.weapon)
310 if(self.weaponentity.state == WS_READY)
312 self.wish_reload = 0;
318 else if (req == WR_PRECACHE)
320 precache_model ("models/uziflash.md3");
321 precache_model ("models/weapons/g_uzi.md3");
322 precache_model ("models/weapons/v_uzi.md3");
323 precache_model ("models/weapons/h_uzi.iqm");
324 precache_sound ("weapons/uzi_fire.wav");
325 precache_sound ("weapons/reload.wav");
327 else if (req == WR_SETUP)
329 weapon_setup(WEP_UZI);
330 W_UZI_SetAmmoCounter();
332 else if (req == WR_CHECKAMMO1)
334 if(autocvar_g_balance_uzi_mode == 1)
335 return self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
337 return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
339 else if (req == WR_CHECKAMMO2)
341 if(autocvar_g_balance_uzi_mode == 1)
342 return self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
344 return self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
346 else if (req == WR_RELOAD)
354 float w_uzi(float req)
356 if(req == WR_IMPACTEFFECT)
359 org2 = w_org + w_backoff * 2;
360 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
363 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
364 else if(w_random < 0.1)
365 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
366 else if(w_random < 0.2)
367 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
369 else if(req == WR_PRECACHE)
371 precache_sound("weapons/ric1.wav");
372 precache_sound("weapons/ric2.wav");
373 precache_sound("weapons/ric3.wav");
375 else if (req == WR_SUICIDEMESSAGE)
376 w_deathtypestring = "%s did the impossible";
377 else if (req == WR_KILLMESSAGE)
379 if(w_deathtype & HITTYPE_SECONDARY)
380 w_deathtypestring = "%s was sniped by %s";
382 w_deathtypestring = "%s was riddled full of holes by %s";