5 /* ammotype */ IT_NAILS,
7 /* flags */ WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN,
8 /* rating */ BOT_PICKUP_RATING_MID,
10 /* shortname */ "uzi",
11 /* fullname */ _("Machine Gun")
16 // leilei's fancy muzzleflash stuff
19 self.frame = self.frame + 2;
20 self.scale = self.scale * 0.5;
21 self.alpha = self.alpha - 0.25;
22 self.nextthink = time + 0.05;
26 self.think = SUB_Remove;
27 self.nextthink = time;
28 self.realowner.muzzle_flash = world;
36 if (self.muzzle_flash == world)
37 self.muzzle_flash = spawn();
39 // muzzle flash for 1st person view
40 setmodel(self.muzzle_flash, "models/uziflash.md3"); // precision set below
42 self.muzzle_flash.scale = 0.75;
43 self.muzzle_flash.think = UZI_Flash_Go;
44 self.muzzle_flash.nextthink = time + 0.02;
45 self.muzzle_flash.frame = 2;
46 self.muzzle_flash.alpha = 0.75;
47 self.muzzle_flash.angles_z = random() * 180;
48 self.muzzle_flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
49 self.muzzle_flash.owner = self.muzzle_flash.realowner = self;
52 void W_UZI_Attack (float deathtype)
54 W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, ((self.misc_bulletcounter == 1) ? autocvar_g_balance_uzi_first_damage : autocvar_g_balance_uzi_sustained_damage));
55 if (!autocvar_g_norecoil)
57 self.punchangle_x = random () - 0.5;
58 self.punchangle_y = random () - 0.5;
61 // this attack_finished just enforces a cooldown at the end of a burst
62 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
64 if (self.misc_bulletcounter == 1)
65 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_first_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_first_damage, autocvar_g_balance_uzi_first_force, deathtype, 0, autocvar_g_balance_uzi_bulletconstant);
67 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_sustained_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, autocvar_g_balance_uzi_sustained_force, deathtype, 0, autocvar_g_balance_uzi_bulletconstant);
68 endFireBallisticBullet();
70 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
73 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
76 if (autocvar_g_casings >= 2)
77 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);
79 if (self.misc_bulletcounter == 1)
80 W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_first_ammo, autocvar_g_balance_uzi_reload_ammo);
82 W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_reload_ammo);
88 if(self.weapon != self.switchweapon) // abort immediately if switching
95 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
96 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
98 W_SwitchWeapon_Force(self, w_getbestweapon(self));
102 self.misc_bulletcounter = self.misc_bulletcounter + 1;
103 W_UZI_Attack(WEP_UZI);
104 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
107 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, w_ready);
111 void uzi_mode1_fire_auto()
115 if (!self.BUTTON_ATCK)
121 if (!weapon_action(self.weapon, WR_CHECKAMMO1))
122 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
124 W_SwitchWeapon_Force(self, w_getbestweapon(self));
129 W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_sustained_ammo, autocvar_g_balance_uzi_reload_ammo);
131 W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, autocvar_g_balance_uzi_sustained_damage);
132 if (!autocvar_g_norecoil)
134 self.punchangle_x = random () - 0.5;
135 self.punchangle_y = random () - 0.5;
138 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);
139 fireBallisticBullet(w_shotorg, w_shotdir, uzi_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, autocvar_g_balance_uzi_bulletconstant);
140 endFireBallisticBullet();
142 self.misc_bulletcounter = self.misc_bulletcounter + 1;
144 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
147 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
149 if (autocvar_g_casings >= 2) // casing code
150 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);
152 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_first_refire * W_WeaponRateFactor();
153 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_mode1_fire_auto);
156 void uzi_mode1_fire_burst()
158 W_SetupShot (self, TRUE, 0, "weapons/uzi_fire.wav", CH_WEAPON_A, autocvar_g_balance_uzi_sustained_damage);
159 if (!autocvar_g_norecoil)
161 self.punchangle_x = random () - 0.5;
162 self.punchangle_y = random () - 0.5;
165 fireBallisticBullet(w_shotorg, w_shotdir, autocvar_g_balance_uzi_burst_spread, autocvar_g_balance_uzi_speed, 5, autocvar_g_balance_uzi_sustained_damage, autocvar_g_balance_uzi_sustained_force, WEP_UZI, 0, autocvar_g_balance_uzi_bulletconstant);
166 endFireBallisticBullet();
169 pointparticles(particleeffectnum("uzi_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
172 W_AttachToShotorg(self.muzzle_flash, '5 0 0');
174 if (autocvar_g_casings >= 2) // casing code
175 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);
177 self.misc_bulletcounter = self.misc_bulletcounter + 1;
178 if (self.misc_bulletcounter == 0)
180 ATTACK_FINISHED(self) = time + autocvar_g_balance_uzi_burst_refire2 * W_WeaponRateFactor();
181 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_animtime, w_ready);
185 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_burst_refire, uzi_mode1_fire_burst);
190 void spawnfunc_weapon_machinegun(); // defined in t_items.qc
192 float w_uzi(float req)
196 if(vlen(self.origin-self.enemy.origin) < 3000 - bound(0, skill, 10) * 200)
197 self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
200 self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
202 else if (req == WR_THINK)
204 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
205 weapon_action(self.weapon, WR_RELOAD);
206 else if(autocvar_g_balance_uzi_mode == 1)
208 if (self.BUTTON_ATCK)
209 if (weapon_prepareattack(0, 0))
211 self.misc_bulletcounter = 0;
212 uzi_mode1_fire_auto();
215 if(self.BUTTON_ATCK2)
216 if(weapon_prepareattack(1, 0))
218 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
219 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
221 W_SwitchWeapon_Force(self, w_getbestweapon(self));
226 W_DecreaseAmmo(ammo_nails, autocvar_g_balance_uzi_burst_ammo, autocvar_g_balance_uzi_reload_ammo);
228 self.misc_bulletcounter = autocvar_g_balance_uzi_burst * -1;
229 uzi_mode1_fire_burst();
235 if (self.BUTTON_ATCK)
236 if (weapon_prepareattack(0, 0))
238 self.misc_bulletcounter = 1;
239 W_UZI_Attack(WEP_UZI); // sets attack_finished
240 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_uzi_sustained_refire, uzi_fire1_02);
243 if (self.BUTTON_ATCK2 && autocvar_g_balance_uzi_first)
244 if (weapon_prepareattack(1, 0))
246 self.misc_bulletcounter = 1;
247 W_UZI_Attack(WEP_UZI | HITTYPE_SECONDARY); // sets attack_finished
248 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_uzi_first_refire, w_ready);
252 else if (req == WR_PRECACHE)
254 precache_model ("models/uziflash.md3");
255 precache_model ("models/weapons/g_uzi.md3");
256 precache_model ("models/weapons/v_uzi.md3");
257 precache_model ("models/weapons/h_uzi.iqm");
258 precache_sound ("weapons/uzi_fire.wav");
259 //precache_sound ("weapons/reload.wav"); // until weapons have individual reload sounds, precache the reload sound somewhere else
261 else if (req == WR_SETUP)
263 weapon_setup(WEP_UZI);
264 self.current_ammo = ammo_nails;
266 else if (req == WR_CHECKAMMO1)
268 if(autocvar_g_balance_uzi_mode == 1)
269 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_sustained_ammo;
271 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
273 if(autocvar_g_balance_uzi_reload_ammo)
275 if(autocvar_g_balance_uzi_mode == 1)
276 ammo_amount += self.(weapon_load[WEP_UZI]) >= autocvar_g_balance_uzi_sustained_ammo;
278 ammo_amount += self.(weapon_load[WEP_UZI]) >= autocvar_g_balance_uzi_first_ammo;
282 else if (req == WR_CHECKAMMO2)
284 if(autocvar_g_balance_uzi_mode == 1)
285 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_burst_ammo;
287 ammo_amount = self.ammo_nails >= autocvar_g_balance_uzi_first_ammo;
289 if(autocvar_g_balance_uzi_reload_ammo)
291 if(autocvar_g_balance_uzi_mode == 1)
292 ammo_amount += self.(weapon_load[WEP_UZI]) >= autocvar_g_balance_uzi_burst_ammo;
294 ammo_amount += self.(weapon_load[WEP_UZI]) >= autocvar_g_balance_uzi_first_ammo;
298 else if (req == WR_RELOAD)
300 W_Reload(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");
302 else if (req == WR_SUICIDEMESSAGE)
304 return WEAPON_THINKING_WITH_PORTALS;
306 else if (req == WR_KILLMESSAGE)
308 if(w_deathtype & HITTYPE_SECONDARY)
309 return WEAPON_UZI_MURDER_SNIPE;
311 return WEAPON_UZI_MURDER_SPRAY;
317 float w_uzi(float req)
319 if(req == WR_IMPACTEFFECT)
322 org2 = w_org + w_backoff * 2;
323 pointparticles(particleeffectnum("machinegun_impact"), org2, w_backoff * 1000, 1);
326 sound(self, CH_SHOTS, "weapons/ric1.wav", VOL_BASE, ATTEN_NORM);
327 else if(w_random < 0.1)
328 sound(self, CH_SHOTS, "weapons/ric2.wav", VOL_BASE, ATTEN_NORM);
329 else if(w_random < 0.2)
330 sound(self, CH_SHOTS, "weapons/ric3.wav", VOL_BASE, ATTEN_NORM);
332 else if(req == WR_PRECACHE)
334 precache_sound("weapons/ric1.wav");
335 precache_sound("weapons/ric2.wav");
336 precache_sound("weapons/ric3.wav");