2 REGISTER_WEAPON(UZI, w_uzi, IT_NAILS, 3, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN, BOT_PICKUP_RATING_MID, "uzi", "uzi", _("Machine Gun"))
8 W_Reload(ammo_nails, min(max(autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_first_ammo), autocvar_g_balance_uzi_burst_ammo), autocvar_g_balance_uzi_reload_ammo, autocvar_g_balance_uzi_reload_time, "weapons/reload.wav");
11 // leilei's fancy muzzleflash stuff
14 self.frame = self.frame + 2;
15 self.scale = self.scale * 0.5;
16 self.alpha = self.alpha - 0.25;
17 self.nextthink = time + 0.05;
21 self.think = SUB_Remove;
22 self.nextthink = time;
23 self.owner.muzzle_flash = world;
31 if (self.muzzle_flash == world)
32 self.muzzle_flash = spawn();
34 // muzzle flash for 1st person view
35 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
37 self.muzzle_flash.scale = 0.75;
38 self.muzzle_flash.think = UZI_Flash_Go;
39 self.muzzle_flash.nextthink = time + 0.02;
40 self.muzzle_flash.frame = 2;
41 self.muzzle_flash.alpha = 0.75;
42 self.muzzle_flash.angles_z = random() * 180;
43 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
44 self.muzzle_flash.owner = self;
47 void W_UZI_Attack (float deathtype)
49 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));
52 self.punchangle_x = random () - 0.5;
53 self.punchangle_y = random () - 0.5;
56 // this attack_finished just enforces a cooldown at the end of a burst
57 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
59 if (self.misc_bulletcounter == 1)
60 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);
62 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);
63 endFireBallisticBullet();
65 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
68 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
71 if (autocvar_g_casings >= 2)
72 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);
74 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
75 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
77 if(autocvar_g_balance_uzi_reload_ammo)
79 if (self.misc_bulletcounter == 1)
80 self.clip_load -= autocvar_g_balance_uzi_first_ammo;
82 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
83 self.weapon_load[WEP_UZI] = self.clip_load;
87 if (self.misc_bulletcounter == 1)
88 self.ammo_nails -= autocvar_g_balance_uzi_first_ammo;
90 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
98 if(self.weapon != self.switchweapon) // abort immediately if switching
103 if (self.BUTTON_ATCK)
105 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
107 W_SwitchWeapon_Force(self, w_getbestweapon(self));
111 self.misc_bulletcounter = self.misc_bulletcounter + 1;
112 W_UZI_Attack(WEP_UZI);
113 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
116 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
120 void uzi_mode1_fire_auto()
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 self.clip_load -= autocvar_g_balance_uzi_sustained_ammo;
130 self.weapon_load[WEP_UZI] = self.clip_load;
133 self.ammo_nails -= autocvar_g_balance_uzi_sustained_ammo;
136 if (self.BUTTON_ATCK)
137 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
140 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
141 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
145 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
147 W_SwitchWeapon_Force(self, w_getbestweapon(self));
152 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);
155 self.punchangle_x = random () - 0.5;
156 self.punchangle_y = random () - 0.5;
159 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);
160 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);
161 endFireBallisticBullet();
163 self.misc_bulletcounter = self.misc_bulletcounter + 1;
165 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
168 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
170 if (autocvar_g_casings >= 2) // casing code
171 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);
174 void uzi_mode1_fire_burst()
176 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);
179 self.punchangle_x = random () - 0.5;
180 self.punchangle_y = random () - 0.5;
183 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);
184 endFireBallisticBullet();
187 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
190 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
192 if (autocvar_g_casings >= 2) // casing code
193 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 self.misc_bulletcounter = self.misc_bulletcounter + 1;
196 if (self.misc_bulletcounter == 0)
198 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
199 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
203 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
208 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
210 float w_uzi(float req)
214 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
215 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
218 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
220 else if (req == WR_THINK)
222 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
224 else if(autocvar_g_balance_uzi_mode == 1)
226 if (self.BUTTON_ATCK)
227 if (weapon_prepareattack(0, 0))
229 self.misc_bulletcounter = 0;
230 uzi_mode1_fire_auto();
233 if(self.BUTTON_ATCK2)
234 if(weapon_prepareattack(1, 0))
236 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
238 W_SwitchWeapon_Force(self, w_getbestweapon(self));
243 // if this weapon is reloadable, decrease its load. Else decrease the player's ammo
244 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
246 if(autocvar_g_balance_uzi_reload_ammo)
248 self.clip_load -= autocvar_g_balance_uzi_burst_ammo;
249 self.weapon_load[WEP_UZI] = self.clip_load;
252 self.ammo_nails -= autocvar_g_balance_uzi_burst_ammo;
255 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
256 uzi_mode1_fire_burst();
262 if (self.BUTTON_ATCK)
263 if (weapon_prepareattack(0, 0))
265 self.misc_bulletcounter = 1;
266 W_UZI_Attack(WEP_UZI); // sets attack_finished
267 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
270 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
271 if (weapon_prepareattack(1, 0))
273 self.misc_bulletcounter = 1;
274 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
275 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
279 else if (req == WR_PRECACHE)
281 precache_model ("models/uziflash.md3");
282 precache_model ("models/weapons/g_uzi.md3");
283 precache_model ("models/weapons/v_uzi.md3");
284 precache_model ("models/weapons/h_uzi.iqm");
285 precache_sound ("weapons/uzi_fire.wav");
286 precache_sound ("weapons/reload.wav");
288 else if (req == WR_SETUP)
290 weapon_setup(WEP_UZI);
292 else if (req == WR_CHECKAMMO1)
294 if(autocvar_g_balance_uzi_mode == 1)
295 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
297 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
299 if(autocvar_g_balance_uzi_reload_ammo)
301 if(autocvar_g_balance_uzi_mode == 1)
302 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_sustained_ammo;
304 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
308 else if (req == WR_CHECKAMMO2)
310 if(autocvar_g_balance_uzi_mode == 1)
311 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
313 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
315 if(autocvar_g_balance_uzi_reload_ammo)
317 if(autocvar_g_balance_uzi_mode == 1)
318 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_burst_ammo;
320 ammo_amount += self.weapon_load[WEP_UZI] >= autocvar_g_balance_uzi_first_ammo;
324 else if (req == WR_RELOAD)
332 float w_uzi(float req)
334 if(req == WR_IMPACTEFFECT)
337 org2 = w_org + w_backoff * 2;
338 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
341 sound(self, CHAN_PROJECTILE, "weapons/ric1.wav", VOL_BASE, ATTN_NORM);
342 else if(w_random < 0.1)
343 sound(self, CHAN_PROJECTILE, "weapons/ric2.wav", VOL_BASE, ATTN_NORM);
344 else if(w_random < 0.2)
345 sound(self, CHAN_PROJECTILE, "weapons/ric3.wav", VOL_BASE, ATTN_NORM);
347 else if(req == WR_PRECACHE)
349 precache_sound("weapons/ric1.wav");
350 precache_sound("weapons/ric2.wav");
351 precache_sound("weapons/ric3.wav");
353 else if (req == WR_SUICIDEMESSAGE)
354 w_deathtypestring = _("%s did the impossible");
355 else if (req == WR_KILLMESSAGE)
357 if(w_deathtype & HITTYPE_SECONDARY)
358 w_deathtypestring = _("%s was sniped by %s");
360 w_deathtypestring = _("%s was riddled full of holes by %s");