]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/w_uzi.c
- fixed bug that players didn't die when health rots to 0
[divverent/nexuiz.git] / data / qcsrc / server / gamec / w_uzi.c
1 void() uzi_ready_01;
2 void() uzi_fire1_01;
3 void() uzi_deselect_01;
4 void() uzi_select_01;
5
6 float() uzi_check =
7 {
8         if (self.ammo_nails >= cvar("g_balance_uzi_first_ammo"))
9                 return TRUE;
10         return FALSE;
11 };
12
13 float() uzi_check2 =
14 {
15         if (self.ammo_nails >= cvar("g_balance_uzi_sustained_ammo"))
16                 return TRUE;
17         return FALSE;
18 };
19
20 void(float req) w_uzi =
21 {
22         if (req == WR_IDLE)
23                 uzi_ready_01();
24         else if (req == WR_AIM)
25                 self.button0 = bot_aim(1000000, 0, 0.001, FALSE);
26         else if (req == WR_FIRE1 || req == WR_FIRE2)
27                 weapon_prepareattack(uzi_check, uzi_check, uzi_fire1_01, cvar("g_balance_uzi_refire"));
28         else if (req == WR_RAISE)
29                 uzi_select_01();
30         else if (req == WR_UPDATECOUNTS)
31                 self.currentammo = self.ammo_nails;
32         else if (req == WR_DROP)
33                 uzi_deselect_01();
34         else if (req == WR_SETUP)
35                 weapon_setup(WEP_UZI, "w_uzi.zym", IT_NAILS);
36         else if (req == WR_CHECKAMMO)
37                 weapon_hasammo = uzi_check();
38 };
39
40 .float uzi_bulletcounter;
41 void W_Uzi_Attack (void)
42 {
43         local vector org;
44
45         local vector trueaim;
46         trueaim = W_TrueAim();
47
48         entity flash;
49         sound (self, CHAN_WEAPON, "weapons/uzi_fire.ogg", 1, ATTN_NORM);
50         if (self.items & IT_STRENGTH)
51                 sound (self, CHAN_AUTO, "weapons/strength_fire.ogg", 1, ATTN_NORM);
52
53         if (cvar("g_use_ammunition"))
54         {
55                 if (self.uzi_bulletcounter == 1)
56                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_first_ammo");
57                 else
58                         self.ammo_nails = self.ammo_nails - cvar("g_balance_uzi_sustained_ammo");
59         }
60         self.punchangle_x = random () - 0.5;
61         self.punchangle_y = random () - 0.5;
62         org = W_MuzzleOrigin (self, '32 6 -8');
63
64         // this attack_finished just enforces a cooldown at the end of a burst
65         self.attack_finished = time + cvar("g_balance_uzi_first_refire");
66
67         if (self.uzi_bulletcounter == 1)
68                 fireBullet (org, normalize(trueaim - org), cvar("g_balance_uzi_first_spread"), cvar("g_balance_uzi_first_damage"), IT_UZI, (self.uzi_bulletcounter & 3) == 0);
69         else
70                 fireBullet (org, normalize(trueaim - org), cvar("g_balance_uzi_sustained_spread"), cvar("g_balance_uzi_sustained_damage"), IT_UZI, (self.uzi_bulletcounter & 3) == 0);
71
72         flash = spawn ();
73 //      org = self.origin + self.view_ofs + (v_right * 6) - (v_up * 10) + (v_forward * 40);
74         setorigin (flash, org);
75         setmodel (flash, "models/uziflash.md3");
76         flash.velocity = v_forward * 20;
77         flash.angles = vectoangles (flash.velocity);
78         flash.angles_z=flash.v_angle_z + random () * 180;
79         flash.scale = 0.75;
80         flash.alpha = 0.5;
81         SUB_SetFade (flash, time, 0.2);
82         flash.effects = flash.effects | EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
83
84         // casing code
85         if (cvar("g_casings") >= 2)
86         {
87                 org = W_MuzzleOrigin (self, '15 6 -8');
88                 SpawnCasing (org, ((random () * 50 + 50) * v_right) - ((random () * 25 + 25) * v_forward) - ((random () * 5 - 70) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 3);
89         }
90 }
91 // weapon frames
92
93 void()  uzi_ready_01 =  {weapon_thinkf(WFRAME_IDLE, 0.1, uzi_ready_01); self.weaponentity.state = WS_READY;};
94 void()  uzi_select_01 = {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_ready); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');};
95 void()  uzi_deselect_01 =       {weapon_thinkf(-1, cvar("g_balance_weaponswitchdelay"), w_clear); weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, PLAYER_WEAPONSELECTION_RANGE);};
96 void()  uzi_fire1_02 =
97 {
98         if (self.button0 && self.weapon == self.switchweapon)
99         {
100                 self.uzi_bulletcounter = self.uzi_bulletcounter + 1;
101                 weapon_doattack(uzi_check2, uzi_check2, W_Uzi_Attack);
102                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
103         }
104         else
105                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_ready_01);
106 };
107 void()  uzi_fire1_01 =
108 {
109         self.uzi_bulletcounter = 1;
110         weapon_doattack(uzi_check, uzi_check, W_Uzi_Attack);
111         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_uzi_sustained_refire"), uzi_fire1_02);
112 };
113