1 #include "sv_nexball.qh"
3 #include <server/gamelog.qh>
7 int autocvar_g_nexball_goalleadlimit;
8 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
10 bool autocvar_g_nexball_basketball_jumppad = true;
11 float autocvar_g_nexball_basketball_bouncefactor;
12 float autocvar_g_nexball_basketball_bouncestop;
13 float autocvar_g_nexball_basketball_carrier_highspeed;
14 bool autocvar_g_nexball_basketball_meter;
15 float autocvar_g_nexball_basketball_meter_maxpower;
16 float autocvar_g_nexball_basketball_meter_minpower;
17 float autocvar_g_nexball_delay_collect;
18 float autocvar_g_nexball_delay_goal;
19 float autocvar_g_nexball_delay_start;
20 bool autocvar_g_nexball_football_jumppad = true;
21 float autocvar_g_nexball_football_bouncefactor;
22 float autocvar_g_nexball_football_bouncestop;
23 bool autocvar_g_nexball_radar_showallplayers;
24 bool autocvar_g_nexball_sound_bounce;
25 int autocvar_g_nexball_trail_color;
26 bool autocvar_g_nexball_playerclip_collisions = true;
28 float autocvar_g_nexball_safepass_turnrate;
29 float autocvar_g_nexball_safepass_maxdist;
30 float autocvar_g_nexball_safepass_holdtime;
31 float autocvar_g_nexball_viewmodel_scale;
32 float autocvar_g_nexball_tackling;
33 vector autocvar_g_nexball_viewmodel_offset;
35 float autocvar_g_balance_nexball_primary_animtime;
36 float autocvar_g_balance_nexball_primary_refire;
37 float autocvar_g_balance_nexball_primary_speed;
38 float autocvar_g_balance_nexball_secondary_animtime;
39 float autocvar_g_balance_nexball_secondary_force;
40 float autocvar_g_balance_nexball_secondary_lifetime;
41 float autocvar_g_balance_nexball_secondary_refire;
42 float autocvar_g_balance_nexball_secondary_speed;
44 void basketball_touch(entity this, entity toucher);
45 void football_touch(entity this, entity toucher);
46 void ResetBall(entity this);
47 const int NBM_NONE = 0;
48 const int NBM_FOOTBALL = 2;
49 const int NBM_BASKETBALL = 4;
52 float OtherTeam(float t) //works only if there are two teams on the map!
55 e = find(NULL, classname, "nexball_team");
57 e = find(e, classname, "nexball_team");
61 const int ST_NEXBALL_GOALS = 1;
62 void nb_ScoreRules(int teams)
64 GameRules_scoring(teams, 0, 0, {
65 field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
66 field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
67 field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
71 void LogNB(string mode, entity actor)
74 if(!autocvar_sv_eventlog)
76 s = strcat(":nexball:", mode);
78 s = strcat(s, ":", ftos(actor.playerid));
82 void ball_restart(entity this)
85 DropBall(this, this.owner.origin, '0 0 0');
89 void nexball_setstatus(entity this)
91 this.items &= ~IT_KEY1;
94 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
96 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
97 entity e = this.ballcarried;
98 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
102 this.items |= IT_KEY1;
106 void relocate_nexball(entity this)
108 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
111 vector o = this.origin;
112 if (!move_out_of_solid(this)) {
113 objerror(this, "could not get out of solid at all!");
116 "^1NOTE: this map needs FIXING. %s at %s needs to be moved out of solid, e.g. by %s",
119 vtos(this.origin - o)
125 void DropOwner(entity this)
129 DropBall(this, ownr.origin, ownr.velocity);
130 makevectors(ownr.v_angle.y * '0 1 0');
131 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
132 UNSET_ONGROUND(ownr);
135 void GiveBall(entity plyr, entity ball)
137 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
138 entity ownr = ball.owner;
141 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
142 ownr.ballcarried = NULL;
143 GameRules_scoring_vip(ownr, false);
144 if(STAT(NB_METERSTART, ownr))
146 STAT(NB_METERSTART, ownr) = 0;
147 ownr.(weaponentity).state = WS_READY;
149 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
153 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
156 //setattachment(ball, plyr, "");
157 setorigin(ball, plyr.origin + plyr.view_ofs);
159 if(ball.team != plyr.team)
160 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
162 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
163 ball.weaponentity_fld = weaponentity;
164 ball.team = plyr.team;
165 plyr.ballcarried = ball;
166 GameRules_scoring_vip(plyr, true);
167 ball.nb_dropper = plyr;
169 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
170 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
172 ball.velocity = '0 0 0';
173 set_movetype(ball, MOVETYPE_NONE);
174 settouch(ball, func_null);
175 ball.effects |= EF_NOSHADOW;
176 ball.scale = 1; // scale down.
178 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
179 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
181 if(autocvar_g_nexball_basketball_delay_hold)
183 setthink(ball, DropOwner);
184 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
187 STAT(WEAPONS, plyr.(weaponentity)) = STAT(WEAPONS, plyr);
188 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
189 STAT(WEAPONS, plyr) = WEPSET(NEXBALL);
190 Weapon w = WEP_NEXBALL;
191 w.wr_resetplayer(w, plyr);
192 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
193 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
196 void DropBall(entity ball, vector org, vector vel)
198 ball.effects |= autocvar_g_nexball_basketball_effects_default;
199 ball.effects &= ~EF_NOSHADOW;
200 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
202 setattachment(ball, NULL, "");
203 setorigin(ball, org);
204 set_movetype(ball, MOVETYPE_BOUNCE);
205 UNSET_ONGROUND(ball);
206 ball.scale = ball_scale;
208 ball.nb_droptime = time;
209 settouch(ball, basketball_touch);
210 setthink(ball, ResetBall);
211 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
213 if(STAT(NB_METERSTART, ball.owner))
215 STAT(NB_METERSTART, ball.owner) = 0;
216 .entity weaponentity = ball.weaponentity_fld;
217 ball.owner.(weaponentity).state = WS_READY;
220 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
221 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
222 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
224 entity e = ball.owner; ball.owner = NULL;
225 e.ballcarried = NULL;
226 GameRules_scoring_vip(e, false);
229 void InitBall(entity this)
231 if(game_stopped) return;
232 UNSET_ONGROUND(this);
233 set_movetype(this, MOVETYPE_BOUNCE);
234 if(this.classname == "nexball_basketball")
235 settouch(this, basketball_touch);
236 else if(this.classname == "nexball_football")
237 settouch(this, football_touch);
239 setthink(this, ResetBall);
240 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
244 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
245 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
249 void ResetBall(entity this)
251 if(this.cnt < 2) // step 1
253 if(time == this.teamtime)
254 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
256 settouch(this, func_null);
257 set_movetype(this, MOVETYPE_NOCLIP);
258 this.velocity = '0 0 0'; // just in case?
260 LogNB("resetidle", NULL);
262 this.nextthink = time;
264 else if(this.cnt < 4) // step 2 and 3
266 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
267 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
268 this.nextthink = time + 0.5;
273 // dprint("Step 4: time: ", ftos(time), "\n");
274 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
275 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
276 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
277 this.velocity = '0 0 0';
278 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
279 set_movetype(this, MOVETYPE_NONE);
280 setthink(this, InitBall);
281 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
285 void football_touch(entity this, entity toucher)
287 if(toucher.solid == SOLID_BSP)
289 if(time > this.lastground + 0.1)
291 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
292 this.lastground = time;
294 if(this.velocity && !this.cnt)
295 this.nextthink = time + autocvar_g_nexball_delay_idle;
298 if (!IS_PLAYER(toucher) && !IS_VEHICLE(toucher))
300 if(GetResource(toucher, RES_HEALTH) < 1)
303 this.nextthink = time + autocvar_g_nexball_delay_idle;
305 this.pusher = toucher;
306 this.team = toucher.team;
308 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
311 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
313 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
315 makevectors(toucher.v_angle);
316 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
318 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
320 makevectors(toucher.v_angle.y * '0 1 0');
321 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
323 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
325 makevectors(toucher.v_angle);
326 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
328 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
331 void basketball_touch(entity this, entity toucher)
333 if(toucher.ballcarried)
335 football_touch(this, toucher);
338 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))
340 if(GetResource(toucher, RES_HEALTH) < 1)
342 LogNB("caught", toucher);
343 GiveBall(toucher, this);
345 else if(toucher.solid == SOLID_BSP)
347 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
348 if(this.velocity && !this.cnt)
349 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
353 void GoalTouch(entity this, entity toucher)
356 float isclient, pscore, otherteam;
359 if(game_stopped) return;
360 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
361 ball = toucher.ballcarried;
364 if(ball.classname != "nexball_basketball")
365 if(ball.classname != "nexball_football")
367 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
369 EXACTTRIGGER_TOUCH(this, toucher);
372 if(NumTeams(nb_teams) == 2)
373 otherteam = OtherTeam(ball.team);
377 if((isclient = IS_CLIENT(ball.pusher)))
378 pname = ball.pusher.netname;
380 pname = "Someone (?)";
382 if(ball.team == this.team) //owngoal (regular goals)
384 LogNB("owngoal", ball.pusher);
385 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
388 else if(this.team == GOAL_FAULT)
390 LogNB("fault", ball.pusher);
391 if(NumTeams(nb_teams) == 2)
392 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
394 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
397 else if(this.team == GOAL_OUT)
399 LogNB("out", ball.pusher);
400 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
401 bprint(pname, "^7 went out of bounds.\n");
403 bprint("The ball was returned.\n");
408 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
409 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
413 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
415 if(ball.team && pscore)
417 if(NumTeams(nb_teams) == 2 && pscore < 0)
418 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
420 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
425 GameRules_scoring_add(ball.pusher, NEXBALL_GOALS, pscore);
427 GameRules_scoring_add(ball.pusher, NEXBALL_FAULTS, -pscore);
430 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
431 DropBall(ball, ball.owner.origin, ball.owner.velocity);
433 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
436 setthink(ball, ResetBall);
437 if(ball.classname == "nexball_basketball")
438 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
439 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
442 //=======================//
444 //=======================//
445 spawnfunc(nexball_team)
452 this.team = this.cnt + 1;
455 void nb_spawnteam(string teamname, float teamcolor)
457 LOG_TRACE("^2spawned team ", teamname);
458 entity e = new(nexball_team);
459 e.netname = teamname;
467 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
469 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
476 nb_spawnteam("Red", e.team-1) ;
484 nb_spawnteam("Blue", e.team-1) ;
492 nb_spawnteam("Yellow", e.team-1);
500 nb_spawnteam("Pink", e.team-1) ;
509 void nb_delayedinit(entity this)
511 if(find(NULL, classname, "nexball_team") == NULL)
513 nb_ScoreRules(nb_teams);
517 //=======================//
519 //=======================//
521 void SpawnBall(entity this)
523 if(!g_nexball) { delete(this); return; }
525 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
529 this.model = "models/nexball/ball.md3";
533 precache_model(this.model);
534 _setmodel(this, this.model);
535 setsize(this, BALL_MINS, BALL_MAXS);
536 ball_scale = this.scale;
538 relocate_nexball(this);
539 this.spawnorigin = this.origin;
541 this.effects = this.effects | EF_LOWPRECISION;
543 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
545 this.glow_color = autocvar_g_nexball_trail_color;
546 this.glow_trail = true;
549 set_movetype(this, MOVETYPE_FLY);
551 if(autocvar_g_nexball_playerclip_collisions)
552 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
554 if(!autocvar_g_nexball_sound_bounce)
556 else if(this.noise == "")
557 this.noise = strzone(SND(NB_BOUNCE));
558 //bounce sound placeholder (FIXME)
559 if(this.noise1 == "")
560 this.noise1 = strzone(SND(NB_DROP));
561 //ball drop sound placeholder (FIXME)
562 if(this.noise2 == "")
563 this.noise2 = strzone(SND(NB_STEAL));
564 //stealing sound placeholder (FIXME)
565 if(this.noise) precache_sound(this.noise);
566 precache_sound(this.noise1);
567 precache_sound(this.noise2);
569 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
571 this.reset = ball_restart;
572 setthink(this, InitBall);
573 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
576 spawnfunc(nexball_basketball)
578 nexball_mode |= NBM_BASKETBALL;
579 this.classname = "nexball_basketball";
580 if (!(balls & BALL_BASKET))
583 CVTOV(g_nexball_basketball_effects_default);
584 CVTOV(g_nexball_basketball_delay_hold);
585 CVTOV(g_nexball_basketball_delay_hold_forteam);
586 CVTOV(g_nexball_basketball_teamsteal);
588 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
591 this.effects = autocvar_g_nexball_basketball_effects_default;
592 this.solid = SOLID_TRIGGER;
593 this.pushable = autocvar_g_nexball_basketball_jumppad;
594 balls |= BALL_BASKET;
595 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
596 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
600 spawnfunc(nexball_football)
602 nexball_mode |= NBM_FOOTBALL;
603 this.classname = "nexball_football";
604 this.solid = SOLID_TRIGGER;
606 this.pushable = autocvar_g_nexball_football_jumppad;
607 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
608 this.bouncestop = autocvar_g_nexball_football_bouncestop;
612 bool nb_Goal_Customize(entity this, entity client)
614 entity e = WaypointSprite_getviewentity(client);
615 entity wp_owner = this.owner;
616 if(SAME_TEAM(e, wp_owner)) { return false; }
621 void SpawnGoal(entity this)
623 if(!g_nexball) { delete(this); return; }
627 if(this.team != GOAL_OUT && Team_IsValidTeam(this.team))
629 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
630 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
631 setcefc(this.sprite, nb_Goal_Customize);
634 this.classname = "nexball_goal";
636 this.noise = "ctf/respawn.wav";
637 precache_sound(this.noise);
638 settouch(this, GoalTouch);
641 spawnfunc(nexball_redgoal)
643 this.team = NUM_TEAM_1;
646 spawnfunc(nexball_bluegoal)
648 this.team = NUM_TEAM_2;
651 spawnfunc(nexball_yellowgoal)
653 this.team = NUM_TEAM_3;
656 spawnfunc(nexball_pinkgoal)
658 this.team = NUM_TEAM_4;
662 spawnfunc(nexball_fault)
664 this.team = GOAL_FAULT;
666 this.noise = strzone(SND(TYPEHIT));
670 spawnfunc(nexball_out)
672 this.team = GOAL_OUT;
674 this.noise = strzone(SND(TYPEHIT));
679 //Spawnfuncs preserved for compatibility
684 spawnfunc_nexball_football(this);
686 spawnfunc(ball_football)
688 spawnfunc_nexball_football(this);
690 spawnfunc(ball_basketball)
692 spawnfunc_nexball_basketball(this);
694 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
695 spawnfunc(ball_redgoal)
697 spawnfunc_nexball_bluegoal(this); // I blame Revenant
699 spawnfunc(ball_bluegoal)
701 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
703 spawnfunc(ball_fault)
705 spawnfunc_nexball_fault(this);
707 spawnfunc(ball_bound)
709 spawnfunc_nexball_out(this);
712 bool ball_customize(entity this, entity client)
716 this.effects &= ~EF_FLAME;
718 setcefc(this, func_null);
722 if(client == this.owner)
724 this.scale = autocvar_g_nexball_viewmodel_scale;
726 this.effects |= EF_FLAME;
728 this.effects &= ~EF_FLAME;
732 this.effects &= ~EF_FLAME;
739 void nb_DropBall(entity player)
741 if(player.ballcarried && g_nexball)
742 DropBall(player.ballcarried, player.origin, player.velocity);
745 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
747 entity player = M_ARGV(0, entity);
752 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
754 entity frag_target = M_ARGV(2, entity);
756 nb_DropBall(frag_target);
759 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
761 entity player = M_ARGV(0, entity);
767 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
769 entity player = M_ARGV(0, entity);
771 makevectors(player.v_angle);
772 if(nexball_mode & NBM_BASKETBALL)
774 if(player.ballcarried)
777 player.ballcarried.velocity = player.velocity;
778 setcefc(player.ballcarried, ball_customize);
780 vector org = player.origin + player.view_ofs +
781 v_forward * autocvar_g_nexball_viewmodel_offset.x +
782 v_right * autocvar_g_nexball_viewmodel_offset.y +
783 v_up * autocvar_g_nexball_viewmodel_offset.z;
784 setorigin(player.ballcarried, org);
787 if(autocvar_g_nexball_safepass_maxdist)
789 if(player.ballcarried.wait < time && player.ballcarried.enemy)
791 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
792 player.ballcarried.enemy = NULL;
796 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
797 crosshair_trace(player);
799 IS_CLIENT(trace_ent) &&
800 !IS_DEAD(trace_ent) &&
801 trace_ent.team == player.team &&
802 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
805 //if(player.ballcarried.enemy != trace_ent)
806 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
807 player.ballcarried.enemy = trace_ent;
808 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
816 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
818 .entity weaponentity = weaponentities[slot];
820 if(STAT(WEAPONS, player.(weaponentity)))
822 STAT(WEAPONS, player) = STAT(WEAPONS, player.(weaponentity));
823 Weapon w = WEP_NEXBALL;
824 w.wr_resetplayer(w, player);
825 player.(weaponentity).m_switchweapon = player.m_switchweapon;
826 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
828 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
835 nexball_setstatus(player);
838 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
840 entity spectatee = M_ARGV(0, entity);
841 entity client = M_ARGV(1, entity);
843 STAT(NB_METERSTART, client) = STAT(NB_METERSTART, spectatee);
846 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
848 entity player = M_ARGV(0, entity);
850 STAT(NB_METERSTART, player) = 0;
851 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
853 .entity weaponentity = weaponentities[slot];
854 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
857 if (nexball_mode & NBM_BASKETBALL)
858 STAT(WEAPONS, player) |= WEPSET(NEXBALL);
860 STAT(WEAPONS, player) = '0 0 0';
865 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics_UpdateStats)
867 entity player = M_ARGV(0, entity);
868 // these automatically reset, no need to worry
870 if(player.ballcarried)
871 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nexball_basketball_carrier_highspeed;
874 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
876 //entity player = M_ARGV(0, entity);
877 entity wepent = M_ARGV(1, entity);
879 return wepent.m_weapon == WEP_NEXBALL;
882 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
884 //entity player = M_ARGV(0, entity);
885 int wep = M_ARGV(1, int);
887 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
890 MUTATOR_HOOKFUNCTION(nb, FilterItem)
892 entity item = M_ARGV(0, entity);
894 if(Item_IsLoot(item))
895 if(item.weapon == WEP_NEXBALL.m_id)
901 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
903 entity item = M_ARGV(0, entity);
904 entity toucher = M_ARGV(1, entity);
906 if(item.weapon && toucher.ballcarried)
907 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
909 return MUT_ITEMTOUCH_CONTINUE;
912 MUTATOR_HOOKFUNCTION(nb, TeamBalance_CheckAllowedTeams)
914 M_ARGV(1, string) = "nexball_team";
918 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
920 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
924 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
926 entity frag_target = M_ARGV(0, entity);
928 if(frag_target.ballcarried)
929 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
934 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
936 M_ARGV(2, int) &= ~0x80;
939 REGISTER_MUTATOR(nb, false)
944 g_nexball_meter_period = autocvar_g_nexball_meter_period;
945 if(g_nexball_meter_period <= 0)
946 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
947 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
951 CVTOV(g_nexball_football_boost_forward); //100
952 CVTOV(g_nexball_football_boost_up); //200
953 CVTOV(g_nexball_delay_idle); //10
954 CVTOV(g_nexball_football_physics); //0
956 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
958 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
959 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
961 GameRules_teams(true);
962 GameRules_limit_score(autocvar_g_nexball_goallimit);
963 GameRules_limit_lead(autocvar_g_nexball_goalleadlimit);
966 MUTATOR_ONROLLBACK_OR_REMOVE
968 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;