4 int autocvar_cl_eventchase_nexball = 1;
6 REGISTER_MUTATOR(cl_nb, true);
8 MUTATOR_HOOKFUNCTION(cl_nb, WantEventchase)
10 if(autocvar_cl_eventchase_nexball && gametype == MAPINFO_TYPE_NEXBALL && !(WepSet_GetFromStat() & WEPSET(NEXBALL)))
16 .float metertime = _STAT(NB_METERSTART);
20 int autocvar_g_nexball_goalleadlimit;
21 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
23 bool autocvar_g_nexball_basketball_jumppad = true;
24 float autocvar_g_nexball_basketball_bouncefactor;
25 float autocvar_g_nexball_basketball_bouncestop;
26 float autocvar_g_nexball_basketball_carrier_highspeed;
27 bool autocvar_g_nexball_basketball_meter;
28 float autocvar_g_nexball_basketball_meter_maxpower;
29 float autocvar_g_nexball_basketball_meter_minpower;
30 float autocvar_g_nexball_delay_collect;
31 float autocvar_g_nexball_delay_goal;
32 float autocvar_g_nexball_delay_start;
33 bool autocvar_g_nexball_football_jumppad = true;
34 float autocvar_g_nexball_football_bouncefactor;
35 float autocvar_g_nexball_football_bouncestop;
36 bool autocvar_g_nexball_radar_showallplayers;
37 bool autocvar_g_nexball_sound_bounce;
38 int autocvar_g_nexball_trail_color;
39 bool autocvar_g_nexball_playerclip_collisions = true;
41 float autocvar_g_nexball_safepass_turnrate;
42 float autocvar_g_nexball_safepass_maxdist;
43 float autocvar_g_nexball_safepass_holdtime;
44 float autocvar_g_nexball_viewmodel_scale;
45 float autocvar_g_nexball_tackling;
46 vector autocvar_g_nexball_viewmodel_offset;
48 float autocvar_g_balance_nexball_primary_animtime;
49 float autocvar_g_balance_nexball_primary_refire;
50 float autocvar_g_balance_nexball_primary_speed;
51 float autocvar_g_balance_nexball_secondary_animtime;
52 float autocvar_g_balance_nexball_secondary_force;
53 float autocvar_g_balance_nexball_secondary_lifetime;
54 float autocvar_g_balance_nexball_secondary_refire;
55 float autocvar_g_balance_nexball_secondary_speed;
57 void basketball_touch(entity this, entity toucher);
58 void football_touch(entity this, entity toucher);
59 void ResetBall(entity this);
60 const int NBM_NONE = 0;
61 const int NBM_FOOTBALL = 2;
62 const int NBM_BASKETBALL = 4;
65 float OtherTeam(float t) //works only if there are two teams on the map!
68 e = find(NULL, classname, "nexball_team");
70 e = find(e, classname, "nexball_team");
74 const int ST_NEXBALL_GOALS = 1;
75 void nb_ScoreRules(int teams)
77 GameRules_scoring(teams, 0, 0, {
78 field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
79 field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
80 field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
84 void LogNB(string mode, entity actor)
87 if(!autocvar_sv_eventlog)
89 s = strcat(":nexball:", mode);
91 s = strcat(s, ":", ftos(actor.playerid));
95 void ball_restart(entity this)
98 DropBall(this, this.owner.origin, '0 0 0');
102 void nexball_setstatus(entity this)
104 this.items &= ~IT_KEY1;
107 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
109 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
110 entity e = this.ballcarried;
111 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
115 this.items |= IT_KEY1;
119 void relocate_nexball(entity this)
121 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
124 vector o = this.origin;
125 if (!move_out_of_solid(this)) {
126 objerror(this, "could not get out of solid at all!");
129 "^1NOTE: this map needs FIXING. %s at %s needs to be moved out of solid, e.g. by %s",
132 vtos(this.origin - o)
138 void DropOwner(entity this)
142 DropBall(this, ownr.origin, ownr.velocity);
143 makevectors(ownr.v_angle.y * '0 1 0');
144 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
145 UNSET_ONGROUND(ownr);
148 void GiveBall(entity plyr, entity ball)
150 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
151 entity ownr = ball.owner;
154 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
155 ownr.ballcarried = NULL;
156 GameRules_scoring_vip(ownr, false);
160 ownr.(weaponentity).state = WS_READY;
162 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
166 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
169 //setattachment(ball, plyr, "");
170 setorigin(ball, plyr.origin + plyr.view_ofs);
172 if(ball.team != plyr.team)
173 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
175 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
176 ball.weaponentity_fld = weaponentity;
177 ball.team = plyr.team;
178 plyr.ballcarried = ball;
179 GameRules_scoring_vip(plyr, true);
180 ball.nb_dropper = plyr;
182 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
183 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
185 ball.velocity = '0 0 0';
186 set_movetype(ball, MOVETYPE_NONE);
187 settouch(ball, func_null);
188 ball.effects |= EF_NOSHADOW;
189 ball.scale = 1; // scale down.
191 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
192 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
194 if(autocvar_g_nexball_basketball_delay_hold)
196 setthink(ball, DropOwner);
197 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
200 plyr.(weaponentity).weapons = plyr.weapons;
201 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
202 plyr.weapons = WEPSET(NEXBALL);
203 Weapon w = WEP_NEXBALL;
204 w.wr_resetplayer(w, plyr);
205 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
206 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
209 void DropBall(entity ball, vector org, vector vel)
211 ball.effects |= autocvar_g_nexball_basketball_effects_default;
212 ball.effects &= ~EF_NOSHADOW;
213 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
215 setattachment(ball, NULL, "");
216 setorigin(ball, org);
217 set_movetype(ball, MOVETYPE_BOUNCE);
218 UNSET_ONGROUND(ball);
219 ball.scale = ball_scale;
221 ball.nb_droptime = time;
222 settouch(ball, basketball_touch);
223 setthink(ball, ResetBall);
224 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
226 if(ball.owner.metertime)
228 ball.owner.metertime = 0;
229 .entity weaponentity = ball.weaponentity_fld;
230 ball.owner.(weaponentity).state = WS_READY;
233 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
234 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
235 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
237 entity e = ball.owner; ball.owner = NULL;
238 e.ballcarried = NULL;
239 GameRules_scoring_vip(e, false);
242 void InitBall(entity this)
244 if(game_stopped) return;
245 UNSET_ONGROUND(this);
246 set_movetype(this, MOVETYPE_BOUNCE);
247 if(this.classname == "nexball_basketball")
248 settouch(this, basketball_touch);
249 else if(this.classname == "nexball_football")
250 settouch(this, football_touch);
252 setthink(this, ResetBall);
253 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
257 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
258 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
262 void ResetBall(entity this)
264 if(this.cnt < 2) // step 1
266 if(time == this.teamtime)
267 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
269 settouch(this, func_null);
270 set_movetype(this, MOVETYPE_NOCLIP);
271 this.velocity = '0 0 0'; // just in case?
273 LogNB("resetidle", NULL);
275 this.nextthink = time;
277 else if(this.cnt < 4) // step 2 and 3
279 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
280 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
281 this.nextthink = time + 0.5;
286 // dprint("Step 4: time: ", ftos(time), "\n");
287 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
288 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
289 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
290 this.velocity = '0 0 0';
291 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
292 set_movetype(this, MOVETYPE_NONE);
293 setthink(this, InitBall);
294 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
298 void football_touch(entity this, entity toucher)
300 if(toucher.solid == SOLID_BSP)
302 if(time > this.lastground + 0.1)
304 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
305 this.lastground = time;
307 if(this.velocity && !this.cnt)
308 this.nextthink = time + autocvar_g_nexball_delay_idle;
311 if (!IS_PLAYER(toucher))
313 if(toucher.health < 1)
316 this.nextthink = time + autocvar_g_nexball_delay_idle;
318 this.pusher = toucher;
319 this.team = toucher.team;
321 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
324 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
326 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
328 makevectors(toucher.v_angle);
329 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
331 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
333 makevectors(toucher.v_angle.y * '0 1 0');
334 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
336 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
338 makevectors(toucher.v_angle);
339 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
341 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
344 void basketball_touch(entity this, entity toucher)
346 if(toucher.ballcarried)
348 football_touch(this, toucher);
351 if(!this.cnt && IS_PLAYER(toucher) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (toucher != this.nb_dropper || time > this.nb_droptime + autocvar_g_nexball_delay_collect))
353 if(toucher.health <= 0)
355 LogNB("caught", toucher);
356 GiveBall(toucher, this);
358 else if(toucher.solid == SOLID_BSP)
360 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
361 if(this.velocity && !this.cnt)
362 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
366 void GoalTouch(entity this, entity toucher)
369 float isclient, pscore, otherteam;
372 if(game_stopped) return;
373 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
374 ball = toucher.ballcarried;
377 if(ball.classname != "nexball_basketball")
378 if(ball.classname != "nexball_football")
380 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
382 EXACTTRIGGER_TOUCH(this, toucher);
385 if(NumTeams(nb_teams) == 2)
386 otherteam = OtherTeam(ball.team);
390 if((isclient = IS_CLIENT(ball.pusher)))
391 pname = ball.pusher.netname;
393 pname = "Someone (?)";
395 if(ball.team == this.team) //owngoal (regular goals)
397 LogNB("owngoal", ball.pusher);
398 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
401 else if(this.team == GOAL_FAULT)
403 LogNB("fault", ball.pusher);
404 if(NumTeams(nb_teams) == 2)
405 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
407 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
410 else if(this.team == GOAL_OUT)
412 LogNB("out", ball.pusher);
413 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
414 bprint(pname, "^7 went out of bounds.\n");
416 bprint("The ball was returned.\n");
421 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
422 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
426 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
428 if(ball.team && pscore)
430 if(NumTeams(nb_teams) == 2 && pscore < 0)
431 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
433 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
438 GameRules_scoring_add(ball.pusher, NEXBALL_GOALS, pscore);
440 GameRules_scoring_add(ball.pusher, NEXBALL_FAULTS, -pscore);
443 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
444 DropBall(ball, ball.owner.origin, ball.owner.velocity);
446 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
449 setthink(ball, ResetBall);
450 if(ball.classname == "nexball_basketball")
451 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
452 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
455 //=======================//
457 //=======================//
458 spawnfunc(nexball_team)
465 this.team = this.cnt + 1;
468 void nb_spawnteam(string teamname, float teamcolor)
470 LOG_TRACE("^2spawned team ", teamname);
471 entity e = new(nexball_team);
472 e.netname = teamname;
480 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
482 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
489 nb_spawnteam("Red", e.team-1) ;
497 nb_spawnteam("Blue", e.team-1) ;
505 nb_spawnteam("Yellow", e.team-1);
513 nb_spawnteam("Pink", e.team-1) ;
522 void nb_delayedinit(entity this)
524 if(find(NULL, classname, "nexball_team") == NULL)
526 nb_ScoreRules(nb_teams);
530 //=======================//
532 //=======================//
534 void SpawnBall(entity this)
536 if(!g_nexball) { delete(this); return; }
538 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
542 this.model = "models/nexball/ball.md3";
546 precache_model(this.model);
547 _setmodel(this, this.model);
548 setsize(this, BALL_MINS, BALL_MAXS);
549 ball_scale = this.scale;
551 relocate_nexball(this);
552 this.spawnorigin = this.origin;
554 this.effects = this.effects | EF_LOWPRECISION;
556 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
558 this.glow_color = autocvar_g_nexball_trail_color;
559 this.glow_trail = true;
562 set_movetype(this, MOVETYPE_FLY);
564 if(autocvar_g_nexball_playerclip_collisions)
565 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
567 if(!autocvar_g_nexball_sound_bounce)
569 else if(this.noise == "")
570 this.noise = strzone(SND(NB_BOUNCE));
571 //bounce sound placeholder (FIXME)
572 if(this.noise1 == "")
573 this.noise1 = strzone(SND(NB_DROP));
574 //ball drop sound placeholder (FIXME)
575 if(this.noise2 == "")
576 this.noise2 = strzone(SND(NB_STEAL));
577 //stealing sound placeholder (FIXME)
578 if(this.noise) precache_sound(this.noise);
579 precache_sound(this.noise1);
580 precache_sound(this.noise2);
582 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
584 this.reset = ball_restart;
585 setthink(this, InitBall);
586 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
589 spawnfunc(nexball_basketball)
591 nexball_mode |= NBM_BASKETBALL;
592 this.classname = "nexball_basketball";
593 if (!(balls & BALL_BASKET))
596 CVTOV(g_nexball_basketball_effects_default);
597 CVTOV(g_nexball_basketball_delay_hold);
598 CVTOV(g_nexball_basketball_delay_hold_forteam);
599 CVTOV(g_nexball_basketball_teamsteal);
601 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
604 this.effects = autocvar_g_nexball_basketball_effects_default;
605 this.solid = SOLID_TRIGGER;
606 this.pushable = autocvar_g_nexball_basketball_jumppad;
607 balls |= BALL_BASKET;
608 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
609 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
613 spawnfunc(nexball_football)
615 nexball_mode |= NBM_FOOTBALL;
616 this.classname = "nexball_football";
617 this.solid = SOLID_TRIGGER;
619 this.pushable = autocvar_g_nexball_football_jumppad;
620 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
621 this.bouncestop = autocvar_g_nexball_football_bouncestop;
625 bool nb_Goal_Customize(entity this, entity client)
627 entity e = WaypointSprite_getviewentity(client);
628 entity wp_owner = this.owner;
629 if(SAME_TEAM(e, wp_owner)) { return false; }
634 void SpawnGoal(entity this)
636 if(!g_nexball) { delete(this); return; }
640 if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
642 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
643 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
644 setcefc(this.sprite, nb_Goal_Customize);
647 this.classname = "nexball_goal";
649 this.noise = "ctf/respawn.wav";
650 precache_sound(this.noise);
651 settouch(this, GoalTouch);
654 spawnfunc(nexball_redgoal)
656 this.team = NUM_TEAM_1;
659 spawnfunc(nexball_bluegoal)
661 this.team = NUM_TEAM_2;
664 spawnfunc(nexball_yellowgoal)
666 this.team = NUM_TEAM_3;
669 spawnfunc(nexball_pinkgoal)
671 this.team = NUM_TEAM_4;
675 spawnfunc(nexball_fault)
677 this.team = GOAL_FAULT;
679 this.noise = strzone(SND(TYPEHIT));
683 spawnfunc(nexball_out)
685 this.team = GOAL_OUT;
687 this.noise = strzone(SND(TYPEHIT));
692 //Spawnfuncs preserved for compatibility
697 spawnfunc_nexball_football(this);
699 spawnfunc(ball_football)
701 spawnfunc_nexball_football(this);
703 spawnfunc(ball_basketball)
705 spawnfunc_nexball_basketball(this);
707 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
708 spawnfunc(ball_redgoal)
710 spawnfunc_nexball_bluegoal(this); // I blame Revenant
712 spawnfunc(ball_bluegoal)
714 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
716 spawnfunc(ball_fault)
718 spawnfunc_nexball_fault(this);
720 spawnfunc(ball_bound)
722 spawnfunc_nexball_out(this);
725 bool ball_customize(entity this, entity client)
729 this.effects &= ~EF_FLAME;
731 setcefc(this, func_null);
735 if(client == this.owner)
737 this.scale = autocvar_g_nexball_viewmodel_scale;
739 this.effects |= EF_FLAME;
741 this.effects &= ~EF_FLAME;
745 this.effects &= ~EF_FLAME;
752 void nb_DropBall(entity player)
754 if(player.ballcarried && g_nexball)
755 DropBall(player.ballcarried, player.origin, player.velocity);
758 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
760 entity player = M_ARGV(0, entity);
765 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
767 entity frag_target = M_ARGV(2, entity);
769 nb_DropBall(frag_target);
772 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
774 entity player = M_ARGV(0, entity);
780 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
782 entity player = M_ARGV(0, entity);
784 makevectors(player.v_angle);
785 if(nexball_mode & NBM_BASKETBALL)
787 if(player.ballcarried)
790 player.ballcarried.velocity = player.velocity;
791 setcefc(player.ballcarried, ball_customize);
793 vector org = player.origin + player.view_ofs +
794 v_forward * autocvar_g_nexball_viewmodel_offset.x +
795 v_right * autocvar_g_nexball_viewmodel_offset.y +
796 v_up * autocvar_g_nexball_viewmodel_offset.z;
797 setorigin(player.ballcarried, org);
800 if(autocvar_g_nexball_safepass_maxdist)
802 if(player.ballcarried.wait < time && player.ballcarried.enemy)
804 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
805 player.ballcarried.enemy = NULL;
809 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
810 crosshair_trace(player);
812 IS_CLIENT(trace_ent) &&
813 !IS_DEAD(trace_ent) &&
814 trace_ent.team == player.team &&
815 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
818 //if(player.ballcarried.enemy != trace_ent)
819 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
820 player.ballcarried.enemy = trace_ent;
821 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
829 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
831 .entity weaponentity = weaponentities[slot];
833 if(player.(weaponentity).weapons)
835 player.weapons = player.(weaponentity).weapons;
836 Weapon w = WEP_NEXBALL;
837 w.wr_resetplayer(w, player);
838 player.(weaponentity).m_switchweapon = player.m_switchweapon;
839 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
841 player.(weaponentity).weapons = '0 0 0';
848 nexball_setstatus(player);
851 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
853 entity spectatee = M_ARGV(0, entity);
854 entity client = M_ARGV(1, entity);
856 client.metertime = spectatee.metertime;
859 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
861 entity player = M_ARGV(0, entity);
863 player.metertime = 0;
864 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
866 .entity weaponentity = weaponentities[slot];
867 player.(weaponentity).weapons = '0 0 0';
870 if (nexball_mode & NBM_BASKETBALL)
871 player.weapons |= WEPSET(NEXBALL);
873 player.weapons = '0 0 0';
878 .float stat_sv_airspeedlimit_nonqw;
879 .float stat_sv_maxspeed;
881 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
883 entity player = M_ARGV(0, entity);
885 if(player.ballcarried)
887 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
888 player.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
892 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
894 //entity player = M_ARGV(0, entity);
895 entity wepent = M_ARGV(1, entity);
897 return wepent.m_weapon == WEP_NEXBALL;
900 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
902 //entity player = M_ARGV(0, entity);
903 int wep = M_ARGV(1, int);
905 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
908 MUTATOR_HOOKFUNCTION(nb, FilterItem)
910 entity item = M_ARGV(0, entity);
912 if(Item_IsLoot(item))
913 if(item.weapon == WEP_NEXBALL.m_id)
919 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
921 entity item = M_ARGV(0, entity);
922 entity toucher = M_ARGV(1, entity);
924 if(item.weapon && toucher.ballcarried)
925 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
927 return MUT_ITEMTOUCH_CONTINUE;
930 MUTATOR_HOOKFUNCTION(nb, CheckAllowedTeams)
932 M_ARGV(1, string) = "nexball_team";
936 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
938 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
942 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
944 entity frag_target = M_ARGV(0, entity);
946 if(frag_target.ballcarried)
947 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
952 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
954 M_ARGV(2, int) &= ~0x80;
957 REGISTER_MUTATOR(nb, g_nexball)
962 g_nexball_meter_period = autocvar_g_nexball_meter_period;
963 if(g_nexball_meter_period <= 0)
964 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
965 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
969 CVTOV(g_nexball_football_boost_forward); //100
970 CVTOV(g_nexball_football_boost_up); //200
971 CVTOV(g_nexball_delay_idle); //10
972 CVTOV(g_nexball_football_physics); //0
974 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
976 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
977 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
979 GameRules_teams(true);
980 GameRules_limit_score(autocvar_g_nexball_goallimit);
981 GameRules_limit_lead(autocvar_g_nexball_goalleadlimit);
984 MUTATOR_ONROLLBACK_OR_REMOVE
986 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;