]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_shotgun.qc
fixed muzzleflashes with sv_qcweaponanimation mode
[divverent/nexuiz.git] / data / qcsrc / server / w_shotgun.qc
1
2 void W_Shotgun_Attack (void)
3 {
4         float   sc;
5         float   bullets;
6         float   d;
7         float   f;
8         float   spread;
9         float   bulletspeed;
10         float   bulletconstant;
11         local entity flash;
12
13         bullets = cvar("g_balance_shotgun_primary_bullets");
14         d = cvar("g_balance_shotgun_primary_damage");
15         f = cvar("g_balance_shotgun_primary_force");
16         spread = cvar("g_balance_shotgun_primary_spread");
17         bulletspeed = cvar("g_balance_shotgun_primary_speed");
18         bulletconstant = cvar("g_balance_shotgun_primary_bulletconstant");
19
20         W_SetupShot (self, '28 8 -10', TRUE, 5, "weapons/shotgun_fire.wav");
21         for (sc = 0;sc < bullets;sc = sc + 1)
22                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN, 0, 1, bulletconstant);
23         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
24                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_primary_ammo");
25
26         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_primary_ammo"));
27
28         // casing code
29         if (cvar("g_casings") >= 1)
30                 SpawnCasing (w_shotorg - v_forward * 10, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
31
32         // muzzle flash for 1st person view
33         flash = spawn();
34         setorigin(flash, '5 0 0');
35         setmodel(flash, "models/uziflash.md3"); // precision set below
36         if (gettagindex(self.weaponentity, "shot"))
37                 setattachment(flash, self.weaponentity, "shot");
38         else if (gettagindex(self.weaponentity, "bone02"))
39                 setattachment(flash, self.weaponentity, "bone02");
40         else
41         {
42                 setorigin(flash, '48 0 5');
43                 setattachment(flash, self.weaponentity, "");
44         }
45         flash.owner = self;
46         flash.viewmodelforclient = self;
47         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
48         flash.think = SUB_Remove;
49         flash.nextthink = time + 0.06;
50         flash.angles_z = flash.v_angle_z + random() * 180;
51         flash.alpha = 1;
52         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
53
54 }
55
56 void W_Shotgun_Attack2 (void)
57 {
58         float   sc;
59         float   bullets;
60         float   d;
61         float   f;
62         float   spread;
63         float   bulletspeed;
64         float   bulletconstant;
65         local entity flash;
66
67         bullets = cvar("g_balance_shotgun_secondary_bullets");
68         d = cvar("g_balance_shotgun_secondary_damage");
69         f = cvar("g_balance_shotgun_secondary_force");
70         spread = cvar("g_balance_shotgun_secondary_spread");
71         bulletspeed = cvar("g_balance_shotgun_secondary_speed");
72         bulletconstant = cvar("g_balance_shotgun_secondary_bulletconstant");
73
74         W_SetupShot (self, '25 8 -8', TRUE, 5, "weapons/shotgun_fire.wav");
75         for (sc = 0;sc < bullets;sc = sc + 1)
76                 fireBallisticBullet(w_shotorg, w_shotdir, spread, bulletspeed, 5, d, 0, f, WEP_SHOTGUN | HITTYPE_SECONDARY, 0, 1, bulletconstant);
77         if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
78                 self.ammo_shells = self.ammo_shells - cvar("g_balance_shotgun_secondary_ammo");
79
80         pointparticles(particleeffectnum("shotgun_muzzleflash"), w_shotorg, w_shotdir * 1000, cvar("g_balance_shotgun_secondary_ammo"));
81
82         // casing code
83         if (cvar("g_casings") >= 1)
84                 SpawnCasing (w_shotorg - v_forward * 10, ((random () * 50 + 50) * v_right) - (v_forward * (random () * 25 + 25)) - ((random () * 5 - 30) * v_up), 2, vectoangles(v_forward),'0 250 0', 100, 1);
85
86         flash = spawn();
87         setorigin(flash, '53 5 0');
88         setmodel(flash, "models/uziflash.md3"); // precision set below
89         if (gettagindex(self.weaponentity, "shot"))
90                 setattachment(flash, self.weaponentity, "shot");
91         else if (gettagindex(self.weaponentity, "bone01"))
92                 setattachment(flash, self.weaponentity, "bone01");
93         else
94         {
95                 setorigin(flash, '48 0 5');
96                 setattachment(flash, self.weaponentity, "");
97         }
98         flash.owner = self;
99         flash.viewmodelforclient = self;
100         flash.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
101         flash.scale = 1.2;
102         flash.think = SUB_Remove;
103         flash.nextthink = time + 0.06;
104         flash.angles_z = flash.v_angle_z + random() * 180;
105         flash.alpha = 1;
106         flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
107 }
108
109 // weapon frames
110 void shotgun_fire2_03()
111 {
112         W_Shotgun_Attack2();
113         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), w_ready);
114 }
115 void shotgun_fire2_02()
116 {
117         W_Shotgun_Attack2();
118         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_03);
119 }
120
121 void spawnfunc_weapon_shotgun(); // defined in t_items.qc
122
123 float w_shotgun(float req)
124 {
125         if (req == WR_AIM)
126                 if(vlen(self.origin-self.enemy.origin)>200)
127                         self.BUTTON_ATCK = bot_aim(1000000, 0, 0.001, FALSE);
128                 else
129                         self.BUTTON_ATCK2 = bot_aim(1000000, 0, 0.001, FALSE);
130         else if (req == WR_THINK)
131         {
132                 if (self.BUTTON_ATCK)
133                 if (weapon_prepareattack(0, cvar("g_balance_shotgun_primary_refire")))
134                 {
135                         W_Shotgun_Attack();
136                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_shotgun_primary_animtime"), w_ready);
137                 }
138                 if (self.BUTTON_ATCK2)
139                 if (weapon_prepareattack(1, cvar("g_balance_shotgun_secondary_refire")))
140                 {
141                         W_Shotgun_Attack2();
142                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_shotgun_secondary_animtime"), shotgun_fire2_02);
143                 }
144         }
145         else if (req == WR_PRECACHE)
146         {
147                 precache_model ("models/uziflash.md3");
148                 precache_model ("models/weapons/g_shotgun.md3");
149                 precache_model ("models/weapons/v_shotgun.md3");
150                 precache_model ("models/weapons/w_shotgun.zym");
151                 precache_sound ("misc/itempickup.wav");
152                 precache_sound ("weapons/shotgun_fire.wav");
153         }
154         else if (req == WR_SETUP)
155                 weapon_setup(WEP_SHOTGUN);
156         else if (req == WR_CHECKAMMO1)
157                 return self.ammo_shells >= cvar("g_balance_shotgun_primary_ammo");
158         else if (req == WR_CHECKAMMO2)
159                 return self.ammo_shells >= cvar("g_balance_shotgun_secondary_ammo") * 3;
160         else if (req == WR_SUICIDEMESSAGE)
161                 w_deathtypestring = "did the impossible";
162         else if (req == WR_KILLMESSAGE)
163         {
164                 w_deathtypestring = "was gunned by"; // unchecked: SECONDARY
165         }
166         return TRUE;
167 };