1 #include "sv_nexball.qh"
3 #include <server/command/vote.qh>
4 #include <server/gamelog.qh>
5 #include <common/ent_cs.qh>
9 int autocvar_g_nexball_goalleadlimit;
10 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
12 bool autocvar_g_nexball_basketball_jumppad = true;
13 float autocvar_g_nexball_basketball_bouncefactor;
14 float autocvar_g_nexball_basketball_bouncestop;
15 float autocvar_g_nexball_basketball_carrier_highspeed;
16 bool autocvar_g_nexball_basketball_meter;
17 float autocvar_g_nexball_basketball_meter_maxpower;
18 float autocvar_g_nexball_basketball_meter_minpower;
19 float autocvar_g_nexball_delay_collect;
20 float autocvar_g_nexball_delay_goal;
21 float autocvar_g_nexball_delay_start;
22 bool autocvar_g_nexball_football_jumppad = true;
23 float autocvar_g_nexball_football_bouncefactor;
24 float autocvar_g_nexball_football_bouncestop;
25 bool autocvar_g_nexball_radar_showallplayers;
26 bool autocvar_g_nexball_sound_bounce;
27 int autocvar_g_nexball_trail_color;
28 bool autocvar_g_nexball_playerclip_collisions = true;
30 float autocvar_g_nexball_safepass_turnrate;
31 float autocvar_g_nexball_safepass_maxdist;
32 float autocvar_g_nexball_safepass_holdtime;
33 float autocvar_g_nexball_viewmodel_scale;
34 float autocvar_g_nexball_tackling;
35 vector autocvar_g_nexball_viewmodel_offset;
37 float autocvar_g_balance_nexball_primary_animtime;
38 float autocvar_g_balance_nexball_primary_refire;
39 float autocvar_g_balance_nexball_primary_speed;
40 float autocvar_g_balance_nexball_secondary_animtime;
41 float autocvar_g_balance_nexball_secondary_force;
42 float autocvar_g_balance_nexball_secondary_lifetime;
43 float autocvar_g_balance_nexball_secondary_refire;
44 float autocvar_g_balance_nexball_secondary_speed;
46 void basketball_touch(entity this, entity toucher);
47 void football_touch(entity this, entity toucher);
48 void ResetBall(entity this);
49 const int NBM_NONE = 0;
50 const int NBM_FOOTBALL = 2;
51 const int NBM_BASKETBALL = 4;
54 float OtherTeam(float t) //works only if there are two teams on the map!
57 e = find(NULL, classname, "nexball_team");
59 e = find(e, classname, "nexball_team");
63 const int ST_NEXBALL_GOALS = 1;
64 void nb_ScoreRules(int teams)
66 GameRules_scoring(teams, 0, 0, {
67 field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
68 field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
69 field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
73 void LogNB(string mode, entity actor)
76 if(!autocvar_sv_eventlog)
78 s = strcat(":nexball:", mode);
80 s = strcat(s, ":", ftos(actor.playerid));
84 void ball_restart(entity this)
87 DropBall(this, this.owner.origin, '0 0 0');
91 void nexball_setstatus(entity this)
93 this.items &= ~IT_KEY1;
96 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
98 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
99 entity e = this.ballcarried;
100 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
104 this.items |= IT_KEY1;
108 void relocate_nexball(entity this)
110 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
113 vector o = this.origin;
114 if (!move_out_of_solid(this)) {
115 objerror(this, "could not get out of solid at all!");
118 "^1NOTE: this map needs FIXING. %s at %s needs to be moved out of solid, e.g. by %s",
121 vtos(this.origin - o)
127 void DropOwner(entity this)
131 DropBall(this, ownr.origin, ownr.velocity);
132 makevectors(ownr.v_angle.y * '0 1 0');
133 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
134 UNSET_ONGROUND(ownr);
137 void GiveBall(entity plyr, entity ball)
139 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
140 entity ownr = ball.owner;
143 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
144 ownr.ballcarried = NULL;
145 GameRules_scoring_vip(ownr, false);
146 if(STAT(NB_METERSTART, ownr))
148 STAT(NB_METERSTART, ownr) = 0;
149 ownr.(weaponentity).state = WS_READY;
151 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
155 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
158 //setattachment(ball, plyr, "");
159 setorigin(ball, plyr.origin + plyr.view_ofs);
161 if(ball.team != plyr.team)
162 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
164 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
165 ball.weaponentity_fld = weaponentity;
166 ball.team = plyr.team;
167 plyr.ballcarried = ball;
168 GameRules_scoring_vip(plyr, true);
169 ball.nb_dropper = plyr;
171 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
172 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
174 ball.velocity = '0 0 0';
175 set_movetype(ball, MOVETYPE_NONE);
176 settouch(ball, func_null);
177 ball.effects |= EF_NOSHADOW;
178 ball.scale = 1; // scale down.
180 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
181 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
183 if(autocvar_g_nexball_basketball_delay_hold)
185 setthink(ball, DropOwner);
186 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
189 STAT(WEAPONS, plyr.(weaponentity)) = STAT(WEAPONS, plyr);
190 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
191 STAT(WEAPONS, plyr) = WEPSET(NEXBALL);
192 Weapon w = WEP_NEXBALL;
193 w.wr_resetplayer(w, plyr);
194 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
195 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
198 void DropBall(entity ball, vector org, vector vel)
200 ball.effects |= autocvar_g_nexball_basketball_effects_default;
201 ball.effects &= ~EF_NOSHADOW;
202 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
204 setattachment(ball, NULL, "");
205 setorigin(ball, org);
206 set_movetype(ball, MOVETYPE_BOUNCE);
207 UNSET_ONGROUND(ball);
208 ball.scale = ball_scale;
210 ball.nb_droptime = time;
211 settouch(ball, basketball_touch);
212 setthink(ball, ResetBall);
213 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
215 if(STAT(NB_METERSTART, ball.owner))
217 STAT(NB_METERSTART, ball.owner) = 0;
218 .entity weaponentity = ball.weaponentity_fld;
219 ball.owner.(weaponentity).state = WS_READY;
222 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
223 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
224 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
226 entity e = ball.owner; ball.owner = NULL;
227 e.ballcarried = NULL;
228 GameRules_scoring_vip(e, false);
231 void InitBall(entity this)
233 if(game_stopped) return;
234 UNSET_ONGROUND(this);
235 set_movetype(this, MOVETYPE_BOUNCE);
236 if(this.classname == "nexball_basketball")
237 settouch(this, basketball_touch);
238 else if(this.classname == "nexball_football")
239 settouch(this, football_touch);
241 setthink(this, ResetBall);
242 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
246 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
247 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
251 void ResetBall(entity this)
253 if(this.cnt < 2) // step 1
255 if(time == this.teamtime)
256 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
258 settouch(this, func_null);
259 set_movetype(this, MOVETYPE_NOCLIP);
260 this.velocity = '0 0 0'; // just in case?
262 LogNB("resetidle", NULL);
264 this.nextthink = time;
266 else if(this.cnt < 4) // step 2 and 3
268 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
269 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
270 this.nextthink = time + 0.5;
275 // dprint("Step 4: time: ", ftos(time), "\n");
276 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
277 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
278 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
279 this.velocity = '0 0 0';
280 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
281 set_movetype(this, MOVETYPE_NONE);
282 setthink(this, InitBall);
283 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
287 void football_touch(entity this, entity toucher)
289 if(toucher.solid == SOLID_BSP)
291 if(time > this.lastground + 0.1)
293 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
294 this.lastground = time;
296 if(this.velocity && !this.cnt)
297 this.nextthink = time + autocvar_g_nexball_delay_idle;
300 if (!IS_PLAYER(toucher) && !IS_VEHICLE(toucher))
302 if(GetResource(toucher, RES_HEALTH) < 1)
305 this.nextthink = time + autocvar_g_nexball_delay_idle;
307 this.pusher = toucher;
308 this.team = toucher.team;
310 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
313 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
315 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
317 makevectors(toucher.v_angle);
318 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
320 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
322 makevectors(toucher.v_angle.y * '0 1 0');
323 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
325 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
327 makevectors(toucher.v_angle);
328 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
330 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
333 void basketball_touch(entity this, entity toucher)
335 if(toucher.ballcarried)
337 football_touch(this, toucher);
340 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))
342 if(GetResource(toucher, RES_HEALTH) < 1)
344 LogNB("caught", toucher);
345 GiveBall(toucher, this);
347 else if(toucher.solid == SOLID_BSP)
349 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
350 if(this.velocity && !this.cnt)
351 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
355 void GoalTouch(entity this, entity toucher)
358 float isclient, pscore, otherteam;
361 if(game_stopped) return;
362 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
363 ball = toucher.ballcarried;
366 if(ball.classname != "nexball_basketball")
367 if(ball.classname != "nexball_football")
369 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
371 EXACTTRIGGER_TOUCH(this, toucher);
374 if(NumTeams(nb_teams) == 2)
375 otherteam = OtherTeam(ball.team);
379 if((isclient = IS_CLIENT(ball.pusher)))
380 pname = ball.pusher.netname;
382 pname = "Someone (?)";
384 if(ball.team == this.team) //owngoal (regular goals)
386 LogNB("owngoal", ball.pusher);
387 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
390 else if(this.team == GOAL_FAULT)
392 LogNB("fault", ball.pusher);
393 if(NumTeams(nb_teams) == 2)
394 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
396 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
399 else if(this.team == GOAL_OUT)
401 LogNB("out", ball.pusher);
402 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
403 bprint(pname, "^7 went out of bounds.\n");
405 bprint("The ball was returned.\n");
410 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
411 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
415 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
417 if(ball.team && pscore)
419 if(NumTeams(nb_teams) == 2 && pscore < 0)
420 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
422 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
427 GameRules_scoring_add(ball.pusher, NEXBALL_GOALS, pscore);
429 GameRules_scoring_add(ball.pusher, NEXBALL_FAULTS, -pscore);
432 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
433 DropBall(ball, ball.owner.origin, ball.owner.velocity);
435 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
438 setthink(ball, ResetBall);
439 if(ball.classname == "nexball_basketball")
440 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
441 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
444 //=======================//
446 //=======================//
447 spawnfunc(nexball_team)
454 this.team = this.cnt + 1;
457 void nb_spawnteam(string teamname, float teamcolor)
459 LOG_TRACE("^2spawned team ", teamname);
460 entity e = new(nexball_team);
461 e.netname = teamname;
469 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
471 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
478 nb_spawnteam("Red", e.team-1) ;
486 nb_spawnteam("Blue", e.team-1) ;
494 nb_spawnteam("Yellow", e.team-1);
502 nb_spawnteam("Pink", e.team-1) ;
511 void nb_delayedinit(entity this)
513 if(find(NULL, classname, "nexball_team") == NULL)
515 nb_ScoreRules(nb_teams);
519 //=======================//
521 //=======================//
523 void SpawnBall(entity this)
525 if(!g_nexball) { delete(this); return; }
527 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
531 this.model = "models/nexball/ball.md3";
535 precache_model(this.model);
536 _setmodel(this, this.model);
537 setsize(this, BALL_MINS, BALL_MAXS);
538 ball_scale = this.scale;
540 relocate_nexball(this);
541 this.spawnorigin = this.origin;
543 this.effects = this.effects | EF_LOWPRECISION;
545 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
547 this.glow_color = autocvar_g_nexball_trail_color;
548 this.glow_trail = true;
551 set_movetype(this, MOVETYPE_FLY);
553 if(autocvar_g_nexball_playerclip_collisions)
554 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
556 if(!autocvar_g_nexball_sound_bounce)
558 else if(this.noise == "")
559 this.noise = strzone(SND(NB_BOUNCE));
560 //bounce sound placeholder (FIXME)
561 if(this.noise1 == "")
562 this.noise1 = strzone(SND(NB_DROP));
563 //ball drop sound placeholder (FIXME)
564 if(this.noise2 == "")
565 this.noise2 = strzone(SND(NB_STEAL));
566 //stealing sound placeholder (FIXME)
567 if(this.noise) precache_sound(this.noise);
568 precache_sound(this.noise1);
569 precache_sound(this.noise2);
571 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
573 this.reset = ball_restart;
574 setthink(this, InitBall);
575 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
578 spawnfunc(nexball_basketball)
580 nexball_mode |= NBM_BASKETBALL;
581 this.classname = "nexball_basketball";
582 if (!(balls & BALL_BASKET))
585 CVTOV(g_nexball_basketball_effects_default);
586 CVTOV(g_nexball_basketball_delay_hold);
587 CVTOV(g_nexball_basketball_delay_hold_forteam);
588 CVTOV(g_nexball_basketball_teamsteal);
590 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
593 this.effects = autocvar_g_nexball_basketball_effects_default;
594 this.solid = SOLID_TRIGGER;
595 this.pushable = autocvar_g_nexball_basketball_jumppad;
596 balls |= BALL_BASKET;
597 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
598 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
602 spawnfunc(nexball_football)
604 nexball_mode |= NBM_FOOTBALL;
605 this.classname = "nexball_football";
606 this.solid = SOLID_TRIGGER;
608 this.pushable = autocvar_g_nexball_football_jumppad;
609 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
610 this.bouncestop = autocvar_g_nexball_football_bouncestop;
614 bool nb_Goal_Customize(entity this, entity client)
616 entity e = WaypointSprite_getviewentity(client);
617 entity wp_owner = this.owner;
618 if(SAME_TEAM(e, wp_owner)) { return false; }
623 void SpawnGoal(entity this)
625 if(!g_nexball) { delete(this); return; }
629 if(this.team != GOAL_OUT && Team_IsValidTeam(this.team))
631 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
632 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
633 setcefc(this.sprite, nb_Goal_Customize);
636 this.classname = "nexball_goal";
638 this.noise = "ctf/respawn.wav";
639 precache_sound(this.noise);
640 settouch(this, GoalTouch);
643 spawnfunc(nexball_redgoal)
645 this.team = NUM_TEAM_1;
648 spawnfunc(nexball_bluegoal)
650 this.team = NUM_TEAM_2;
653 spawnfunc(nexball_yellowgoal)
655 this.team = NUM_TEAM_3;
658 spawnfunc(nexball_pinkgoal)
660 this.team = NUM_TEAM_4;
664 spawnfunc(nexball_fault)
666 this.team = GOAL_FAULT;
668 this.noise = strzone(SND(TYPEHIT));
672 spawnfunc(nexball_out)
674 this.team = GOAL_OUT;
676 this.noise = strzone(SND(TYPEHIT));
681 //Spawnfuncs preserved for compatibility
686 spawnfunc_nexball_football(this);
688 spawnfunc(ball_football)
690 spawnfunc_nexball_football(this);
692 spawnfunc(ball_basketball)
694 spawnfunc_nexball_basketball(this);
696 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
697 spawnfunc(ball_redgoal)
699 spawnfunc_nexball_bluegoal(this); // I blame Revenant
701 spawnfunc(ball_bluegoal)
703 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
705 spawnfunc(ball_fault)
707 spawnfunc_nexball_fault(this);
709 spawnfunc(ball_bound)
711 spawnfunc_nexball_out(this);
714 bool ball_customize(entity this, entity client)
718 this.effects &= ~EF_FLAME;
720 setcefc(this, func_null);
724 if(client == this.owner)
726 this.scale = autocvar_g_nexball_viewmodel_scale;
728 this.effects |= EF_FLAME;
730 this.effects &= ~EF_FLAME;
734 this.effects &= ~EF_FLAME;
741 void nb_DropBall(entity player)
743 if(player.ballcarried && g_nexball)
744 DropBall(player.ballcarried, player.origin, player.velocity);
747 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
749 entity player = M_ARGV(0, entity);
754 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
756 entity frag_target = M_ARGV(2, entity);
758 nb_DropBall(frag_target);
761 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
763 entity player = M_ARGV(0, entity);
769 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
771 entity player = M_ARGV(0, entity);
773 makevectors(player.v_angle);
774 if(nexball_mode & NBM_BASKETBALL)
776 if(player.ballcarried)
779 player.ballcarried.velocity = player.velocity;
780 setcefc(player.ballcarried, ball_customize);
782 vector org = player.origin + player.view_ofs +
783 v_forward * autocvar_g_nexball_viewmodel_offset.x +
784 v_right * autocvar_g_nexball_viewmodel_offset.y +
785 v_up * autocvar_g_nexball_viewmodel_offset.z;
786 setorigin(player.ballcarried, org);
789 if(autocvar_g_nexball_safepass_maxdist)
791 if(player.ballcarried.wait < time && player.ballcarried.enemy)
793 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
794 player.ballcarried.enemy = NULL;
798 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
799 crosshair_trace(player);
801 IS_CLIENT(trace_ent) &&
802 !IS_DEAD(trace_ent) &&
803 trace_ent.team == player.team &&
804 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
807 //if(player.ballcarried.enemy != trace_ent)
808 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
809 player.ballcarried.enemy = trace_ent;
810 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
818 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
820 .entity weaponentity = weaponentities[slot];
822 if(STAT(WEAPONS, player.(weaponentity)))
824 STAT(WEAPONS, player) = STAT(WEAPONS, player.(weaponentity));
825 Weapon w = WEP_NEXBALL;
826 w.wr_resetplayer(w, player);
827 player.(weaponentity).m_switchweapon = player.m_switchweapon;
828 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
830 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
837 nexball_setstatus(player);
840 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
842 entity spectatee = M_ARGV(0, entity);
843 entity client = M_ARGV(1, entity);
845 STAT(NB_METERSTART, client) = STAT(NB_METERSTART, spectatee);
848 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
850 entity player = M_ARGV(0, entity);
852 STAT(NB_METERSTART, player) = 0;
853 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
855 .entity weaponentity = weaponentities[slot];
856 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
859 if (nexball_mode & NBM_BASKETBALL)
860 STAT(WEAPONS, player) |= WEPSET(NEXBALL);
862 STAT(WEAPONS, player) = '0 0 0';
867 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics_UpdateStats)
869 entity player = M_ARGV(0, entity);
870 // these automatically reset, no need to worry
872 if(player.ballcarried)
873 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nexball_basketball_carrier_highspeed;
876 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
878 //entity player = M_ARGV(0, entity);
879 entity wepent = M_ARGV(1, entity);
881 return wepent.m_weapon == WEP_NEXBALL;
884 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
886 //entity player = M_ARGV(0, entity);
887 int wep = M_ARGV(1, int);
889 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
892 MUTATOR_HOOKFUNCTION(nb, FilterItem)
894 entity item = M_ARGV(0, entity);
896 if(Item_IsLoot(item))
897 if(item.weapon == WEP_NEXBALL.m_id)
903 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
905 entity item = M_ARGV(0, entity);
906 entity toucher = M_ARGV(1, entity);
908 if(item.weapon && toucher.ballcarried)
909 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
911 return MUT_ITEMTOUCH_CONTINUE;
914 MUTATOR_HOOKFUNCTION(nb, TeamBalance_CheckAllowedTeams)
916 M_ARGV(1, string) = "nexball_team";
920 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
922 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
926 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
928 entity frag_target = M_ARGV(0, entity);
930 if(frag_target.ballcarried)
931 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
936 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
938 M_ARGV(2, int) &= ~0x80;
941 REGISTER_MUTATOR(nb, false)
946 g_nexball_meter_period = autocvar_g_nexball_meter_period;
947 if(g_nexball_meter_period <= 0)
948 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
949 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
953 CVTOV(g_nexball_football_boost_forward); //100
954 CVTOV(g_nexball_football_boost_up); //200
955 CVTOV(g_nexball_delay_idle); //10
956 CVTOV(g_nexball_football_physics); //0
958 radar_showenemies = autocvar_g_nexball_radar_showallplayers;
960 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
961 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
963 GameRules_teams(true);
964 GameRules_limit_score(autocvar_g_nexball_goallimit);
965 GameRules_limit_lead(autocvar_g_nexball_goalleadlimit);
968 MUTATOR_ONROLLBACK_OR_REMOVE
970 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;