]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/nexball.qc
forgot a few changes to support >2 teams
[divverent/nexuiz.git] / data / qcsrc / server / nexball.qc
1 //EF_BRIGHTFIELD|EF_BRIGHTLIGHT|EF_DIMLIGHT|EF_BLUE|EF_RED|EF_FLAME
2 #define BALL_EFFECTMASK 1229
3 #define BALL_MINS '-16 -16 -16'  // The model is 24*24*24
4 #define BALL_MAXS '16 16 16'
5 #define BALL_ATTACHORG '3 0 16'
6 #define BALL_FOOT   1
7 #define BALL_BASKET 2
8 //spawnflags
9 #define GOAL_TOUCHPLAYER 1
10 //goal types
11 #define GOAL_FAULT -1
12 #define GOAL_OUT -2
13
14 #define CVTOV(s) s = cvar( #s )
15
16 float g_nexball_football_boost_forward;
17 float g_nexball_football_boost_up;
18 float g_nexball_football_physics;
19 float g_nexball_delay_idle;
20 float g_nexball_basketball_delay_hold;
21 float g_nexball_basketball_delay_hold_forteam;
22 float g_nexball_basketball_effects_default;
23 float g_nexball_basketball_teamsteal;
24 float balls;
25 float ball_scale;
26
27 .float teamtime;
28
29 void nb_delayedinit();
30 void nb_init() // Called early (worldspawn stage)
31 {
32         CVTOV(g_nexball_meter_period); //sent with the client init entity
33         if (g_nexball_meter_period <= 0)
34                 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
35         g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
36         addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
37
38         // General settings
39         CVTOV(g_nexball_football_boost_forward);   //100
40         CVTOV(g_nexball_football_boost_up);        //200
41         CVTOV(g_nexball_delay_idle);               //10
42         CVTOV(g_nexball_football_physics);         //0
43
44         InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
45 }
46
47 void ResetBall();
48
49 void LogNB(string mode, entity actor)
50 {
51         string s;
52         if(!cvar("sv_eventlog"))
53                 return;
54         s = strcat(":nexball:", mode);
55         if(actor != world)
56                 s = strcat(s, ":", ftos(actor.playerid));
57         GameLogEcho(s);
58 }
59
60 void ball_restart (void)
61 {
62         if(self.owner)
63                 DropBall(self, self.owner.origin, '0 0 0');
64         ResetBall();
65 }
66
67 void nexball_setstatus (void)
68 {
69         local entity oldself;
70         if (!g_nexball)
71                 return;
72         if (self.ballcarried)
73         {
74                 if (self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
75                 {
76                         bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
77                         oldself = self;
78                         self = self.ballcarried;
79                         DropBall(self, self.owner.origin, '0 0 0');
80                         ResetBall();
81                         self = oldself;
82                 } else
83                         self.items |= IT_KEY1;
84         }
85 }
86
87 void relocate_nexball (void)
88 {
89         tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, TRUE, self);
90         if (trace_startsolid)
91         {
92                 vector o;
93                 o = self.origin;
94                 if(!move_out_of_solid(self))
95                         objerror("could not get out of solid at all!");
96                 print("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
97                 print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
98                 print(" ", ftos(self.origin_y - o_y));
99                 print(" ", ftos(self.origin_z - o_z), "'\n");
100                 self.origin = o;
101         }
102 }
103
104 void basketball_touch();
105 void football_touch();
106
107 void DropOwner (void)
108 {
109         local entity ownr;
110         ownr = self.owner;
111         DropBall(self, ownr.origin, ownr.velocity);
112         makevectors(ownr.v_angle_y * '0 1 0');
113         ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
114         ownr.flags &~= FL_ONGROUND;
115 }
116
117 void DropBall (entity ball, vector org, vector vel)
118 {
119         ball.effects |= g_nexball_basketball_effects_default;
120         ball.effects &~= EF_NOSHADOW;
121         ball.owner.effects &~= g_nexball_basketball_effects_default; // this may be problematic.
122
123         setattachment(ball, world, "");
124         setorigin (ball, org);
125         ball.movetype = MOVETYPE_BOUNCE;
126         ball.flags &~= FL_ONGROUND;
127         ball.scale = ball_scale;
128         ball.velocity = vel;
129         ball.ctf_droptime = time;
130         ball.touch = basketball_touch;
131         ball.think = ResetBall;
132         ball.nextthink = min(time + g_nexball_delay_idle, ball.teamtime);
133
134         if (ball.owner.metertime)
135         {
136                 ball.owner.metertime = 0;
137                 ball.owner.weaponentity.state = WS_READY;
138         }
139
140         ball.owner.ballcarried = world;
141         ball.owner = world;
142 }
143
144 void InitBall (void)
145 {
146         if (gameover) return;
147         self.flags &~= FL_ONGROUND;
148         self.movetype = MOVETYPE_BOUNCE;
149         if (self.classname == "nexball_basketball")
150                 self.touch = basketball_touch;
151         else if (self.classname == "nexball_football")
152                 self.touch = football_touch;
153         self.cnt = 0;
154         self.think = ResetBall;
155         self.nextthink = time + g_nexball_delay_idle + 3;
156         self.teamtime = 0;
157         self.pusher = world;
158         self.team = FALSE;
159         sound (self, CHAN_PROJECTILE, self.noise1, VOL_BASE, ATTN_NORM);
160         LogNB("init", world);
161 }
162
163 void ResetBall (void)
164 {
165         if (self.cnt < 2) { // step 1
166                 if (time == self.teamtime)
167                         bprint("The ", ColoredTeamName(self.team), " held the ball for too long.\n");
168                 self.touch = SUB_Null;
169                 self.movetype = MOVETYPE_NOCLIP;
170                 self.velocity = '0 0 0'; // just in case?
171                 if(!self.cnt)
172                         LogNB("resetidle", world);
173                 self.cnt = 2;
174                 self.nextthink = time;
175         } else if (self.cnt < 4) { // step 2 and 3
176 //              dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
177                 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
178                 self.nextthink = time + 0.5;
179                 self.cnt += 1;
180         } else { // step 4
181 //              dprint("Step 4: time: ", ftos(time), "\n");
182                 if (vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
183                         dprint("The ball moved too far away from its spawn origin.\nOffset: ",
184                                vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
185                 self.velocity = '0 0 0';
186                 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
187                 self.movetype = MOVETYPE_NONE;
188                 self.think = InitBall;
189                 self.nextthink = max(time, game_starttime) + cvar("g_nexball_delay_start");
190         }
191 }
192
193 void football_touch (void)
194 {
195         if (other.solid == SOLID_BSP) {
196                 if (time > self.lastground + 0.1)
197                 {
198                         sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
199                         self.lastground = time;
200                 }
201                 if (vlen(self.velocity) && !self.cnt)
202                         self.nextthink = time + g_nexball_delay_idle;
203                 return;
204         }
205         if (other.classname != "player")
206                 return;
207         if (other.health < 1)
208                 return;
209         if (!self.cnt)
210                 self.nextthink = time + g_nexball_delay_idle;
211
212         self.pusher = other;
213         self.team = other.team;
214
215         if (g_nexball_football_physics == -1) { // MrBougo try 1, before decompiling Rev's original
216                 if (vlen(other.velocity))
217                         self.velocity = other.velocity * 1.5 + '0 0 1' * g_nexball_football_boost_up;
218         } else if (g_nexball_football_physics == 1) { // MrBougo's modded Rev style: partially independant of the height of the aiming point
219                 makevectors(other.v_angle);
220                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + '0 0 1' * g_nexball_football_boost_up;
221         } else if (g_nexball_football_physics == 2) { // 2nd mod try: totally independant. Really playable!
222                 makevectors(other.v_angle_y * '0 1 0');
223                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
224         } else { // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
225                 makevectors(other.v_angle);
226                 self.velocity = other.velocity + v_forward * g_nexball_football_boost_forward + v_up * g_nexball_football_boost_up;
227         }
228         self.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
229 }
230
231 void basketball_touch (void)
232 {
233         if (other.ballcarried)
234         {
235                 football_touch();
236                 return;
237         }
238         if (!self.cnt && other.classname == "player" && (other.playerid != self.dropperid || time > self.ctf_droptime + cvar("g_nexball_delay_collect"))) {
239                 if (other.health <= 0)
240                         return;
241                 LogNB("caught", other);
242
243                 if (self.team != other.team)
244                         self.teamtime = time + g_nexball_basketball_delay_hold_forteam;
245
246                 self.owner = self.pusher = other; //"owner" is set to the player carrying, "pusher" to the last player who touched it
247                 self.team = other.team;
248                 other.ballcarried = self;
249                 other.effects = other.effects | g_nexball_basketball_effects_default;
250                 self.effects &~= g_nexball_basketball_effects_default;
251                 self.effects |= EF_NOSHADOW;
252                 self.scale = 1; // scale down.
253                 self.dropperid = other.playerid;
254                 setattachment(self, other, "");
255                 setorigin(self, BALL_ATTACHORG);
256                 self.velocity = '0 0 0';
257                 self.movetype = MOVETYPE_NONE;
258                 self.touch = SUB_Null;
259                 if (g_nexball_basketball_delay_hold)
260                 {
261                         self.think = DropOwner;
262                         self.nextthink = time + g_nexball_basketball_delay_hold;
263                 }
264         } else if (other.solid == SOLID_BSP) {
265                 sound (self, CHAN_PROJECTILE, self.noise, VOL_BASE, ATTN_NORM);
266                 if (vlen(self.velocity) && !self.cnt)
267                         self.nextthink = min(time + g_nexball_delay_idle, self.teamtime);
268         }
269 }
270
271 void GoalTouch (void)
272 {
273         entity ball;
274         float isclient, pscore;
275         string pname;
276
277         if (gameover) return;
278         if ((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
279                 ball = other.ballcarried;
280         else
281                 ball = other;
282         if (ball.classname != "nexball_basketball")
283         if (ball.classname != "nexball_football")
284                 return;
285         if ((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
286                 return;
287         EXACTTRIGGER_TOUCH;
288
289
290         if((isclient = ball.pusher.flags & FL_CLIENT))
291                 pname = ball.pusher.netname;
292         else
293                 pname = "Someone (?)";
294
295         if        (ball.team == self.team) //owngoal (regular goals)
296         {
297                 LogNB("owngoal", ball.pusher);
298                 bprint("Boo! ", pname, "^7 scored a goal against his own team!\n");
299                 pscore = -1;
300         } else if (self.team == GOAL_FAULT) {
301                 LogNB("fault", ball.pusher);
302                 bprint(ColoredTeamName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
303                 pscore = -1;
304         } else if (self.team == GOAL_OUT) {
305                 LogNB("out", ball.pusher);
306                 if ((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
307                         bprint(pname, "^7 went out of bounds.\n");
308                 else
309                         bprint("The ball was returned.\n");
310                 pscore = 0;
311         } else {                           //score
312                 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
313                 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", ColoredTeamName(ball.team), ".\n");
314                 pscore = 1;
315         }
316
317         sound (ball, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NONE);
318
319         if(ball.team && pscore)
320                 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
321         if (isclient && pscore > 0)
322                 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
323         else if (isclient && pscore < 0)
324                 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, pscore);
325
326         if (ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
327                 DropBall(ball, ball.owner.origin, ball.owner.velocity);
328         ball.cnt = 1;
329         ball.think = ResetBall;
330         if (ball.classname == "nexball_basketball")
331                 ball.touch = football_touch; // better than SUB_Null: football control until the ball gets reset
332         ball.nextthink = time + cvar("g_nexball_delay_goal") * (self.team != GOAL_OUT);
333 }
334
335 //=======================//
336 //       team ents       //
337 //=======================//
338 void spawnfunc_nexball_team (void)
339 {
340         if(!g_nexball) { remove(self); return; }
341         self.team = self.cnt + 1;
342 }
343
344 void nb_spawnteam (string teamname, float teamcolor)
345 {
346         dprint("^2spawned team ", teamname, "\n");
347         local entity e;
348         e = spawn();
349         e.classname = "nexball_team";
350         e.netname = teamname;
351         e.cnt = teamcolor;
352         e.team = e.cnt + 1;
353 };
354
355 void nb_spawnteams (void)
356 {
357         float t_r, t_b, t_y, t_p;
358         entity e;
359         for(e = world; (e = find(e, classname, "nexball_goal")); )
360         {
361                 switch(e.team)
362                 {
363                         case COLOR_TEAM1: if(!t_r) { nb_spawnteam ("Red", e.team-1)   ; t_r = 1; } break;
364                         case COLOR_TEAM2: if(!t_b) { nb_spawnteam ("Blue", e.team-1)  ; t_b = 1; } break; 
365                         case COLOR_TEAM3: if(!t_y) { nb_spawnteam ("Yellow", e.team-1); t_y = 1; } break;
366                         case COLOR_TEAM4: if(!t_p) { nb_spawnteam ("Pink", e.team-1)  ; t_p = 1; } break;
367                 }
368         }
369 }
370
371 void nb_delayedinit (void)
372 {
373         if (find(world, classname, "nexball_team") == world)
374                 nb_spawnteams();
375         ScoreRules_nexball();
376 }
377
378
379 //=======================//
380 //      spawnfuncs       //
381 //=======================//
382
383 void SpawnBall (void)
384 {
385         if(!g_nexball) { remove(self); return; }
386
387         if (!self.model) {
388                 self.model = "models/nexball/ball.md3";
389                 self.scale = 1.3;
390         }
391
392         precache_model (self.model);
393         setmodel (self, self.model);
394         setsize (self, BALL_MINS, BALL_MAXS);
395         ball_scale = self.scale;
396
397         relocate_nexball();
398         self.spawnorigin = self.origin;
399
400         self.effects = self.effects | EF_LOWPRECISION;
401
402         if (cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
403         {
404                 self.glow_color = cvar("g_nexball_trail_color");
405                 self.glow_trail = TRUE;
406         }
407
408         self.movetype = MOVETYPE_FLY;
409
410         if (!cvar("g_nexball_sound_bounce"))
411                 self.noise = "";
412         else if (!self.noise)
413                 self.noise = "sound/nexball/bounce.ogg";
414                 //bounce sound placeholder (FIXME)
415         if (!self.noise1)
416                 self.noise1 = "sound/nexball/drop.ogg";
417                 //ball drop sound placeholder (FIXME)
418         if (!self.noise2)
419                 self.noise2 = "sound/nexball/steal.ogg";
420                 //stealing sound placeholder (FIXME)
421         if (self.noise) precache_sound (self.noise);
422         precache_sound (self.noise1);
423         precache_sound (self.noise2);
424
425         self.reset = ball_restart;
426         self.think = InitBall;
427         self.nextthink = game_starttime + cvar("g_nexball_delay_start");
428 }
429
430 void spawnfunc_nexball_basketball (void)
431 {
432         self.classname = "nexball_basketball";
433         if(!balls & BALL_BASKET)
434         {
435                 CVTOV(g_nexball_basketball_effects_default);
436                 CVTOV(g_nexball_basketball_delay_hold);
437                 CVTOV(g_nexball_basketball_delay_hold_forteam);
438                 CVTOV(g_nexball_basketball_teamsteal);
439                 g_nexball_basketball_effects_default = g_nexball_basketball_effects_default & BALL_EFFECTMASK;
440         }
441         if (!self.effects)
442                 self.effects = g_nexball_basketball_effects_default;
443         self.solid = SOLID_TRIGGER;
444         balls |= BALL_BASKET;
445         SpawnBall();
446 }
447
448 void spawnfunc_nexball_football (void)
449 {
450         self.classname = "nexball_football";
451         self.solid = SOLID_TRIGGER;
452         balls |= BALL_FOOT;
453         SpawnBall();
454 }
455
456 void SpawnGoal (void)
457 {
458         if(!g_nexball) { remove(self); return; }
459         EXACTTRIGGER_INIT;
460         self.classname = "nexball_goal";
461         if (!self.noise)
462                 self.noise = "ctf/respawn.wav";
463         precache_sound(self.noise);
464         self.touch = GoalTouch;
465 }
466
467 void spawnfunc_nexball_redgoal (void)
468 {
469         self.team = COLOR_TEAM1;
470         SpawnGoal();
471 }
472 void spawnfunc_nexball_bluegoal (void)
473 {
474         self.team = COLOR_TEAM2;
475         SpawnGoal();
476 }
477 void spawnfunc_nexball_yellowgoal (void)
478 {
479         self.team = COLOR_TEAM3;
480         SpawnGoal();
481 }
482 void spawnfunc_nexball_pinkgoal (void)
483 {
484         self.team = COLOR_TEAM4;
485         SpawnGoal();
486 }
487
488 void spawnfunc_nexball_fault (void)
489 {
490         self.team = GOAL_FAULT;
491         if (!self.noise)
492                 self.noise = "misc/typehit.wav";
493         SpawnGoal();
494 }
495
496 void spawnfunc_nexball_out (void)
497 {
498         self.team = GOAL_OUT;
499         if (!self.noise)
500                 self.noise = "misc/typehit.wav";
501         SpawnGoal();
502 }
503
504 //
505 //Spawnfuncs preserved for compatibility
506 //
507
508 void spawnfunc_ball            (void) { spawnfunc_nexball_football(); }
509 void spawnfunc_ball_football   (void) { spawnfunc_nexball_football(); }
510 void spawnfunc_ball_basketball (void) { spawnfunc_nexball_basketball(); }
511 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
512 void spawnfunc_ball_redgoal    (void) { spawnfunc_nexball_bluegoal(); } // I blame Revenant
513 void spawnfunc_ball_bluegoal   (void) { spawnfunc_nexball_redgoal(); }  // but he didn't mean to cause trouble :p
514 void spawnfunc_ball_fault      (void) { spawnfunc_nexball_fault(); }
515 void spawnfunc_ball_bound      (void) { spawnfunc_nexball_out(); }
516
517 //=======================//
518 //      Weapon code      //
519 //=======================//
520
521 void W_Nexball_Touch (void)
522 {
523         local entity ball, attacker;
524         attacker = self.owner;
525
526         PROJECTILE_TOUCH;
527         if(attacker.team != other.team || g_nexball_basketball_teamsteal)
528         if((ball = other.ballcarried))
529         {
530                 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * cvar("g_balance_nexball_secondary_force");
531                 other.flags &~= FL_ONGROUND;
532                 if(!attacker.ballcarried)
533                 {
534                         other.effects &~= g_nexball_basketball_effects_default;
535                         other.ballcarried = world;
536
537                         if (g_nexball_basketball_delay_hold)
538                         {
539                                 ball.think = DropOwner;
540                                 ball.nextthink = time + g_nexball_basketball_delay_hold;
541                         }
542
543                         attacker.effects = attacker.effects | g_nexball_basketball_effects_default;
544                         attacker.ballcarried = ball;
545                         if (other.metertime)
546                         {
547                                 other.metertime = 0;
548                                 other.weaponentity.state = WS_READY;
549                         }
550
551                         setattachment(ball, attacker, "");
552                         ball.owner = ball.pusher = attacker;
553                         ball.team = attacker.team;
554                         ball.dropperid = attacker.playerid;
555
556                         if (other.team != attacker.team)
557                                 ball.teamtime = time + g_nexball_basketball_delay_hold_forteam;
558
559                         LogNB("stole", attacker);
560                         sound (other, CHAN_AUTO, ball.noise2, VOL_BASE, ATTN_NORM);
561                 }
562         }
563         remove(self);
564 }
565
566 void W_Nexball_Attack (float t)
567 {
568         local entity ball;
569         local float mul, mi, ma;
570         if (!(ball = self.ballcarried))
571                 return;
572
573         W_SetupShot (self, FALSE, 4, "weapons/grenade_fire.wav");
574         tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
575         if(trace_startsolid)
576         {
577                 if(self.metertime)
578                         self.metertime = 0; // Shot failed, hide the power meter
579                 return;
580         }
581
582         //Calculate multiplier
583         if (t < 0)
584                 mul = 1;
585         else
586         {
587                 mi = cvar("g_nexball_basketball_meter_minpower");
588                 ma = max(mi, cvar("g_nexball_basketball_meter_maxpower")); // avoid confusion
589                 //One triangle wave period with 1 as max
590                 mul = 2 * mod(t, g_nexball_meter_period) / g_nexball_meter_period;
591                 if (mul > 1)
592                         mul = 2 - mul;
593                 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
594         }
595         DropBall (ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * cvar("g_balance_nexball_primary_speed") * mul));
596         //TODO: use the speed_up cvar too ??
597 }
598
599 void W_Nexball_Attack2 (void)
600 {
601         local entity missile;
602         if (!(balls & BALL_BASKET))
603                 return;
604         W_SetupShot (self, FALSE, 2, "weapons/grenade_fire.wav");
605         pointparticles(particleeffectnum("grenadelauncher_muzzleflash"), w_shotorg, w_shotdir * 1000, 1);
606         missile = spawn ();
607
608         missile.owner = self;
609         missile.classname = "ballstealer";
610
611         missile.movetype = MOVETYPE_FLY;
612         missile.solid = SOLID_BBOX;
613
614         setmodel (missile, "models/elaser.mdl"); // precision set below
615         setsize (missile, '0 0 0', '0 0 0');
616         setorigin (missile, w_shotorg);
617
618         missile.velocity = w_shotdir * cvar("g_balance_nexball_secondary_speed");
619         W_SetupProjectileVelocity(missile);
620         missile.angles = vectoangles (missile.velocity);
621         missile.touch = W_Nexball_Touch;
622         missile.think = SUB_Remove;
623         missile.nextthink = time + cvar("g_balance_nexball_secondary_lifetime"); //FIXME: use a distance instead?
624
625         missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
626         missile.flags = FL_PROJECTILE;
627 }
628
629 float w_nexball_weapon(float req)
630 {
631         if (req == WR_THINK)
632         {
633                 if (self.BUTTON_ATCK)
634                 if (weapon_prepareattack(0, cvar("g_balance_nexball_primary_refire")))
635                 if (cvar("g_nexball_basketball_meter"))
636                 {
637                         if (self.ballcarried && !self.metertime)
638                                 self.metertime = time;
639                         else
640                                 weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
641                 }
642                 else
643                 {
644                         W_Nexball_Attack(-1);
645                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
646                 }
647                 if (self.BUTTON_ATCK2)
648                 if (weapon_prepareattack(1, cvar("g_balance_nexball_secondary_refire")))
649                 {
650                         W_Nexball_Attack2();
651                         weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_nexball_secondary_animtime"), w_ready);
652                 }
653                 
654                 if (!self.BUTTON_ATCK && self.metertime && self.ballcarried)
655                 {
656                         W_Nexball_Attack(time - self.metertime);
657                         // DropBall or stealing will set metertime back to 0
658                         weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_nexball_primary_animtime"), w_ready);
659                 }
660         }
661         else if (req == WR_PRECACHE)
662         {
663                 precache_model ("models/weapons/g_gl.md3");
664                 precache_model ("models/weapons/v_gl.md3");
665                 precache_model ("models/weapons/h_gl.dpm");
666                 precache_model ("models/elaser.mdl");
667                 precache_sound ("weapons/grenade_fire.wav");
668         }
669         else if (req == WR_SETUP)
670                 weapon_setup(WEP_GRENADE_LAUNCHER);
671         else if (req == WR_SUICIDEMESSAGE)
672         {
673                 w_deathtypestring = "is a weirdo";
674         }
675         else if (req == WR_KILLMESSAGE)
676         {
677                 w_deathtypestring = "got killed by #'s black magic";
678         }
679         // No need to check WR_CHECKAMMO* or WR_AIM, it should always return TRUE
680         return TRUE;
681 }