]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_uzi.qc
sometimes weapon disappears completely. Maybe the WS_RAISE animation gets cancelled...
[divverent/nexuiz.git] / data / qcsrc / server / w_uzi.qc
1
2 .float uzi_bulletcounter;
3 void W_Uzi_Attack (void)
4 {
5         local entity flash;
6
7         if (cvar("g_use_ammunition"))
8         {
9                 if (self.uzi_bulletcounter == 1)
10                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_first_ammo");
11                 else
12                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_sustained_ammo");
13         }
14         W_SetupShot (self, '15 5.5 -8', TRUE, 0, "weapons/uzi_fire.ogg");
15         if (!cvar("g_norecoil"))
16         {
17                 self.punchangle_x = random () - 0.5;
18                 self.punchangle_y = random () - 0.5;
19         }
20
21         // this attack_finished just enforces a cooldown at the end of a burst
22         self.attack_finished = time + cvar("g_balance_uzi_first_refire");
23
24         if (self.uzi_bulletcounter == 1)
25                 fireBullet (w_shotorg, w_shotdir, cvar("g_balance_uzi_first_spread"), cvar("g_balance_uzi_first_damage"), IT_UZI, (self.uzi_bulletcounter & 3) == 0);
26         else
27                 fireBullet (w_shotorg, w_shotdir, cvar("g_balance_uzi_sustained_spread"), cvar("g_balance_uzi_sustained_damage"), IT_UZI, (self.uzi_bulletcounter & 3) == 0);
28
29         flash = spawn ();
30         setorigin (flash, w_shotorg + v_forward * 17);
31         setmodel (flash, "models/uziflash.md3");
32         flash.angles = vectoangles (w_shotdir);
33         flash.angles_z=flash.v_angle_z + random () * 180;
34         flash.scale = 0.75;
35         flash.alpha = 0.5;
36         SUB_SetFade (flash, time, 0.2);
37         flash.effects = flash.effects | EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
38
39         // casing code
40         if (cvar("g_casings") >= 2)
41                 SpawnCasing (w_shotorg + v_forward * 10, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3);
42 }
43
44 // weapon frames
45 void()  uzi_fire1_02 =
46 {
47         if(self.weapon != self.switchweapon) // abort immediately if switching
48         {
49                 w_ready();
50                 return;
51         }
52         if (self.button0)
53         {
54                 if (!weapon_action(self.weapon, WR_CHECKAMMO2))
55                 {
56                         self.switchweapon = w_getbestweapon(self);
57                         if (self.switchweapon != self.weapon)
58                                 self.cnt = self.weapon;
59                         w_ready();
60                         return;
61                 }
62                 self.attack_finished = time + cvar("g_balance_uzi_refire");
63                 self.uzi_bulletcounter = self.uzi_bulletcounter + 1;
64                 W_Uzi_Attack();
65                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
66         }
67         else
68                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), w_ready);
69 };
70
71 float(float req) w_uzi =
72 {
73         if (req == WR_AIM)
74                 self.button0 = bot_aim(1000000, 0, 0.001, FALSE);
75         else if (req == WR_THINK)
76         {
77                 if (self.button0)
78                 if (weapon_prepareattack(0, cvar("g_balance_uzi_refire")))
79                 {
80                         self.uzi_bulletcounter = 1;
81                         W_Uzi_Attack();
82                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
83                 }
84                 if (self.button3)
85                 if (weapon_prepareattack(1, cvar("g_balance_uzi_refire")))
86                 {
87                         self.uzi_bulletcounter = 1;
88                         W_Uzi_Attack();
89                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), w_ready);
90                 }
91         }
92         else if (req == WR_SETUP)
93                 weapon_setup(WEP_UZI, "uzi", IT_NAILS);
94         else if (req == WR_CHECKAMMO1)
95                 return self.ammo_nails >= cvar("g_balance_uzi_first_ammo");
96         else if (req == WR_CHECKAMMO2)
97                 return self.ammo_nails >= cvar("g_balance_uzi_sustained_ammo");
98         return TRUE;
99 };