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