1 #include "sv_nexball.qh"
3 #include <server/client.qh>
4 #include <server/command/vote.qh>
5 #include <server/gamelog.qh>
6 #include <common/ent_cs.qh>
7 #include <common/mapobjects/triggers.qh>
11 int autocvar_g_nexball_goalleadlimit;
12 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
14 bool autocvar_g_nexball_basketball_jumppad = true;
15 float autocvar_g_nexball_basketball_bouncefactor;
16 float autocvar_g_nexball_basketball_bouncestop;
17 float autocvar_g_nexball_basketball_carrier_highspeed;
18 bool autocvar_g_nexball_basketball_meter;
19 float autocvar_g_nexball_basketball_meter_maxpower;
20 float autocvar_g_nexball_basketball_meter_minpower;
21 float autocvar_g_nexball_delay_collect;
22 float autocvar_g_nexball_delay_goal;
23 float autocvar_g_nexball_delay_start;
24 bool autocvar_g_nexball_football_jumppad = true;
25 float autocvar_g_nexball_football_bouncefactor;
26 float autocvar_g_nexball_football_bouncestop;
27 bool autocvar_g_nexball_radar_showallplayers;
28 bool autocvar_g_nexball_sound_bounce;
29 int autocvar_g_nexball_trail_color;
30 bool autocvar_g_nexball_playerclip_collisions = true;
32 float autocvar_g_nexball_safepass_turnrate;
33 float autocvar_g_nexball_safepass_maxdist;
34 float autocvar_g_nexball_safepass_holdtime;
35 float autocvar_g_nexball_viewmodel_scale;
36 float autocvar_g_nexball_tackling;
37 vector autocvar_g_nexball_viewmodel_offset;
39 float autocvar_g_balance_nexball_primary_animtime;
40 float autocvar_g_balance_nexball_primary_refire;
41 float autocvar_g_balance_nexball_primary_speed;
42 float autocvar_g_balance_nexball_secondary_animtime;
43 float autocvar_g_balance_nexball_secondary_force;
44 float autocvar_g_balance_nexball_secondary_lifetime;
45 float autocvar_g_balance_nexball_secondary_refire;
46 float autocvar_g_balance_nexball_secondary_speed;
48 void basketball_touch(entity this, entity toucher);
49 void football_touch(entity this, entity toucher);
50 void ResetBall(entity this);
51 const int NBM_NONE = 0;
52 const int NBM_FOOTBALL = 2;
53 const int NBM_BASKETBALL = 4;
56 float OtherTeam(float t) //works only if there are two teams on the map!
59 e = find(NULL, classname, "nexball_team");
61 e = find(e, classname, "nexball_team");
65 const int ST_NEXBALL_GOALS = 1;
66 void nb_ScoreRules(int teams)
68 GameRules_scoring(teams, 0, 0, {
69 field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
70 field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
71 field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
75 void LogNB(string mode, entity actor)
78 if(!autocvar_sv_eventlog)
80 s = strcat(":nexball:", mode);
82 s = strcat(s, ":", ftos(actor.playerid));
86 void ball_restart(entity this)
89 DropBall(this, this.owner.origin, '0 0 0');
93 void nexball_setstatus(entity this)
95 this.items &= ~IT_KEY1;
98 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
100 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
101 entity e = this.ballcarried;
102 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
106 this.items |= IT_KEY1;
110 void relocate_nexball(entity this)
112 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
115 vector o = this.origin;
116 if (!move_out_of_solid(this)) {
117 objerror(this, "could not get out of solid at all!");
120 "^1NOTE: this map needs FIXING. %s at %s needs to be moved out of solid, e.g. by %s",
123 vtos(this.origin - o)
129 void DropOwner(entity this)
133 DropBall(this, ownr.origin, ownr.velocity);
134 makevectors(ownr.v_angle.y * '0 1 0');
135 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
136 UNSET_ONGROUND(ownr);
139 void GiveBall(entity plyr, entity ball)
141 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
142 entity ownr = ball.owner;
145 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
146 ownr.ballcarried = NULL;
147 GameRules_scoring_vip(ownr, false);
148 if(STAT(NB_METERSTART, ownr))
150 STAT(NB_METERSTART, ownr) = 0;
151 ownr.(weaponentity).state = WS_READY;
153 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
157 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
160 //setattachment(ball, plyr, "");
161 setorigin(ball, plyr.origin + plyr.view_ofs);
163 if(ball.team != plyr.team)
164 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
166 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
167 ball.weaponentity_fld = weaponentity;
168 ball.team = plyr.team;
169 plyr.ballcarried = ball;
170 GameRules_scoring_vip(plyr, true);
171 ball.nb_dropper = plyr;
173 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
174 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
176 ball.velocity = '0 0 0';
177 set_movetype(ball, MOVETYPE_NONE);
178 settouch(ball, func_null);
179 ball.effects |= EF_NOSHADOW;
180 ball.scale = 1; // scale down.
182 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
183 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
185 if(autocvar_g_nexball_basketball_delay_hold)
187 setthink(ball, DropOwner);
188 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
191 STAT(WEAPONS, plyr.(weaponentity)) = STAT(WEAPONS, plyr);
192 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
193 STAT(WEAPONS, plyr) = WEPSET(NEXBALL);
194 Weapon w = WEP_NEXBALL;
195 w.wr_resetplayer(w, plyr);
196 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
197 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
200 void DropBall(entity ball, vector org, vector vel)
202 ball.effects |= autocvar_g_nexball_basketball_effects_default;
203 ball.effects &= ~EF_NOSHADOW;
204 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
206 setattachment(ball, NULL, "");
207 setorigin(ball, org);
208 set_movetype(ball, MOVETYPE_BOUNCE);
209 UNSET_ONGROUND(ball);
210 ball.scale = ball_scale;
212 ball.nb_droptime = time;
213 settouch(ball, basketball_touch);
214 setthink(ball, ResetBall);
215 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
217 if(STAT(NB_METERSTART, ball.owner))
219 STAT(NB_METERSTART, ball.owner) = 0;
220 .entity weaponentity = ball.weaponentity_fld;
221 ball.owner.(weaponentity).state = WS_READY;
224 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
225 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
226 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
228 entity e = ball.owner; ball.owner = NULL;
229 e.ballcarried = NULL;
230 GameRules_scoring_vip(e, false);
233 void InitBall(entity this)
235 if(game_stopped) return;
236 UNSET_ONGROUND(this);
237 set_movetype(this, MOVETYPE_BOUNCE);
238 if(this.classname == "nexball_basketball")
239 settouch(this, basketball_touch);
240 else if(this.classname == "nexball_football")
241 settouch(this, football_touch);
243 setthink(this, ResetBall);
244 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
248 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
249 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
253 void ResetBall(entity this)
255 if(this.cnt < 2) // step 1
257 if(time == this.teamtime)
258 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
260 settouch(this, func_null);
261 set_movetype(this, MOVETYPE_NOCLIP);
262 this.velocity = '0 0 0'; // just in case?
264 LogNB("resetidle", NULL);
266 this.nextthink = time;
268 else if(this.cnt < 4) // step 2 and 3
270 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
271 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
272 this.nextthink = time + 0.5;
277 // dprint("Step 4: time: ", ftos(time), "\n");
278 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
279 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
280 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
281 this.velocity = '0 0 0';
282 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
283 set_movetype(this, MOVETYPE_NONE);
284 setthink(this, InitBall);
285 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
289 void football_touch(entity this, entity toucher)
291 if(toucher.solid == SOLID_BSP)
293 if(time > this.lastground + 0.1)
295 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
296 this.lastground = time;
298 if(this.velocity && !this.cnt)
299 this.nextthink = time + autocvar_g_nexball_delay_idle;
302 if (!IS_PLAYER(toucher) && !IS_VEHICLE(toucher))
304 if(GetResource(toucher, RES_HEALTH) < 1)
307 this.nextthink = time + autocvar_g_nexball_delay_idle;
309 this.pusher = toucher;
310 this.team = toucher.team;
312 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
315 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
317 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
319 makevectors(toucher.v_angle);
320 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
322 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
324 makevectors(toucher.v_angle.y * '0 1 0');
325 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
327 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
329 makevectors(toucher.v_angle);
330 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
332 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
335 void basketball_touch(entity this, entity toucher)
337 if(toucher.ballcarried)
339 football_touch(this, toucher);
342 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))
344 if(GetResource(toucher, RES_HEALTH) < 1)
346 LogNB("caught", toucher);
347 GiveBall(toucher, this);
349 else if(toucher.solid == SOLID_BSP)
351 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
352 if(this.velocity && !this.cnt)
353 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
357 void GoalTouch(entity this, entity toucher)
360 float isclient, pscore, otherteam;
363 if(game_stopped) return;
364 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
365 ball = toucher.ballcarried;
368 if(ball.classname != "nexball_basketball")
369 if(ball.classname != "nexball_football")
371 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
373 EXACTTRIGGER_TOUCH(this, toucher);
376 if(NumTeams(nb_teams) == 2)
377 otherteam = OtherTeam(ball.team);
381 if((isclient = IS_CLIENT(ball.pusher)))
382 pname = ball.pusher.netname;
384 pname = "Someone (?)";
386 if(ball.team == this.team) //owngoal (regular goals)
388 LogNB("owngoal", ball.pusher);
389 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
392 else if(this.team == GOAL_FAULT)
394 LogNB("fault", ball.pusher);
395 if(NumTeams(nb_teams) == 2)
396 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
398 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
401 else if(this.team == GOAL_OUT)
403 LogNB("out", ball.pusher);
404 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
405 bprint(pname, "^7 went out of bounds.\n");
407 bprint("The ball was returned.\n");
412 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
413 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
417 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
419 if(ball.team && pscore)
421 if(NumTeams(nb_teams) == 2 && pscore < 0)
422 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
424 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
429 GameRules_scoring_add(ball.pusher, NEXBALL_GOALS, pscore);
431 GameRules_scoring_add(ball.pusher, NEXBALL_FAULTS, -pscore);
434 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
435 DropBall(ball, ball.owner.origin, ball.owner.velocity);
437 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
440 setthink(ball, ResetBall);
441 if(ball.classname == "nexball_basketball")
442 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
443 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
446 //=======================//
448 //=======================//
449 spawnfunc(nexball_team)
456 this.team = this.cnt + 1;
459 void nb_spawnteam(string teamname, float teamcolor)
461 LOG_TRACE("^2spawned team ", teamname);
462 entity e = new(nexball_team);
463 e.netname = teamname;
471 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
473 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
480 nb_spawnteam("Red", e.team-1) ;
488 nb_spawnteam("Blue", e.team-1) ;
496 nb_spawnteam("Yellow", e.team-1);
504 nb_spawnteam("Pink", e.team-1) ;
513 void nb_delayedinit(entity this)
515 if(find(NULL, classname, "nexball_team") == NULL)
517 nb_ScoreRules(nb_teams);
521 //=======================//
523 //=======================//
525 void SpawnBall(entity this)
527 if(!g_nexball) { delete(this); return; }
529 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
533 this.model = "models/nexball/ball.md3";
537 precache_model(this.model);
538 _setmodel(this, this.model);
539 setsize(this, BALL_MINS, BALL_MAXS);
540 ball_scale = this.scale;
542 relocate_nexball(this);
543 this.spawnorigin = this.origin;
545 this.effects = this.effects | EF_LOWPRECISION;
547 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
549 this.glow_color = autocvar_g_nexball_trail_color;
550 this.glow_trail = true;
553 set_movetype(this, MOVETYPE_FLY);
555 if(autocvar_g_nexball_playerclip_collisions)
556 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
558 if(!autocvar_g_nexball_sound_bounce)
560 else if(this.noise == "")
561 this.noise = strzone(SND(NB_BOUNCE));
562 //bounce sound placeholder (FIXME)
563 if(this.noise1 == "")
564 this.noise1 = strzone(SND(NB_DROP));
565 //ball drop sound placeholder (FIXME)
566 if(this.noise2 == "")
567 this.noise2 = strzone(SND(NB_STEAL));
568 //stealing sound placeholder (FIXME)
569 if(this.noise) precache_sound(this.noise);
570 precache_sound(this.noise1);
571 precache_sound(this.noise2);
573 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
575 this.reset = ball_restart;
576 setthink(this, InitBall);
577 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
580 spawnfunc(nexball_basketball)
582 nexball_mode |= NBM_BASKETBALL;
583 this.classname = "nexball_basketball";
584 if (!(balls & BALL_BASKET))
587 CVTOV(g_nexball_basketball_effects_default);
588 CVTOV(g_nexball_basketball_delay_hold);
589 CVTOV(g_nexball_basketball_delay_hold_forteam);
590 CVTOV(g_nexball_basketball_teamsteal);
592 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
595 this.effects = autocvar_g_nexball_basketball_effects_default;
596 this.solid = SOLID_TRIGGER;
597 this.pushable = autocvar_g_nexball_basketball_jumppad;
598 balls |= BALL_BASKET;
599 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
600 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
604 spawnfunc(nexball_football)
606 nexball_mode |= NBM_FOOTBALL;
607 this.classname = "nexball_football";
608 this.solid = SOLID_TRIGGER;
610 this.pushable = autocvar_g_nexball_football_jumppad;
611 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
612 this.bouncestop = autocvar_g_nexball_football_bouncestop;
616 bool nb_Goal_Customize(entity this, entity client)
618 entity e = WaypointSprite_getviewentity(client);
619 entity wp_owner = this.owner;
620 if(SAME_TEAM(e, wp_owner)) { return false; }
625 void SpawnGoal(entity this)
627 if(!g_nexball) { delete(this); return; }
631 if(this.team != GOAL_OUT && Team_IsValidTeam(this.team))
633 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
634 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
635 setcefc(this.sprite, nb_Goal_Customize);
638 this.classname = "nexball_goal";
640 this.noise = "ctf/respawn.wav";
641 precache_sound(this.noise);
642 settouch(this, GoalTouch);
645 spawnfunc(nexball_redgoal)
647 this.team = NUM_TEAM_1;
650 spawnfunc(nexball_bluegoal)
652 this.team = NUM_TEAM_2;
655 spawnfunc(nexball_yellowgoal)
657 this.team = NUM_TEAM_3;
660 spawnfunc(nexball_pinkgoal)
662 this.team = NUM_TEAM_4;
666 spawnfunc(nexball_fault)
668 this.team = GOAL_FAULT;
670 this.noise = strzone(SND(TYPEHIT));
674 spawnfunc(nexball_out)
676 this.team = GOAL_OUT;
678 this.noise = strzone(SND(TYPEHIT));
683 //Spawnfuncs preserved for compatibility
688 spawnfunc_nexball_football(this);
690 spawnfunc(ball_football)
692 spawnfunc_nexball_football(this);
694 spawnfunc(ball_basketball)
696 spawnfunc_nexball_basketball(this);
698 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
699 spawnfunc(ball_redgoal)
701 spawnfunc_nexball_bluegoal(this); // I blame Revenant
703 spawnfunc(ball_bluegoal)
705 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
707 spawnfunc(ball_fault)
709 spawnfunc_nexball_fault(this);
711 spawnfunc(ball_bound)
713 spawnfunc_nexball_out(this);
716 bool ball_customize(entity this, entity client)
720 this.effects &= ~EF_FLAME;
722 setcefc(this, func_null);
726 if(client == this.owner)
728 this.scale = autocvar_g_nexball_viewmodel_scale;
730 this.effects |= EF_FLAME;
732 this.effects &= ~EF_FLAME;
736 this.effects &= ~EF_FLAME;
743 void nb_DropBall(entity player)
745 if(player.ballcarried && g_nexball)
746 DropBall(player.ballcarried, player.origin, player.velocity);
749 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
751 entity player = M_ARGV(0, entity);
756 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
758 entity frag_target = M_ARGV(2, entity);
760 nb_DropBall(frag_target);
763 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
765 entity player = M_ARGV(0, entity);
771 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
773 entity player = M_ARGV(0, entity);
775 makevectors(player.v_angle);
776 if(nexball_mode & NBM_BASKETBALL)
778 if(player.ballcarried)
781 player.ballcarried.velocity = player.velocity;
782 setcefc(player.ballcarried, ball_customize);
784 vector org = player.origin + player.view_ofs +
785 v_forward * autocvar_g_nexball_viewmodel_offset.x +
786 v_right * autocvar_g_nexball_viewmodel_offset.y +
787 v_up * autocvar_g_nexball_viewmodel_offset.z;
788 setorigin(player.ballcarried, org);
791 if(autocvar_g_nexball_safepass_maxdist)
793 if(player.ballcarried.wait < time && player.ballcarried.enemy)
795 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
796 player.ballcarried.enemy = NULL;
800 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
801 crosshair_trace(player);
803 IS_CLIENT(trace_ent) &&
804 !IS_DEAD(trace_ent) &&
805 trace_ent.team == player.team &&
806 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
809 //if(player.ballcarried.enemy != trace_ent)
810 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
811 player.ballcarried.enemy = trace_ent;
812 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
820 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
822 .entity weaponentity = weaponentities[slot];
824 if(STAT(WEAPONS, player.(weaponentity)))
826 STAT(WEAPONS, player) = STAT(WEAPONS, player.(weaponentity));
827 Weapon w = WEP_NEXBALL;
828 w.wr_resetplayer(w, player);
829 player.(weaponentity).m_switchweapon = player.m_switchweapon;
830 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
832 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
839 nexball_setstatus(player);
842 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
844 entity spectatee = M_ARGV(0, entity);
845 entity client = M_ARGV(1, entity);
847 STAT(NB_METERSTART, client) = STAT(NB_METERSTART, spectatee);
850 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
852 entity player = M_ARGV(0, entity);
854 STAT(NB_METERSTART, player) = 0;
855 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
857 .entity weaponentity = weaponentities[slot];
858 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
861 if (nexball_mode & NBM_BASKETBALL)
862 STAT(WEAPONS, player) |= WEPSET(NEXBALL);
864 STAT(WEAPONS, player) = '0 0 0';
869 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics_UpdateStats)
871 entity player = M_ARGV(0, entity);
872 // these automatically reset, no need to worry
874 if(player.ballcarried)
875 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nexball_basketball_carrier_highspeed;
878 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
880 //entity player = M_ARGV(0, entity);
881 entity wepent = M_ARGV(1, entity);
883 return wepent.m_weapon == WEP_NEXBALL;
886 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
888 //entity player = M_ARGV(0, entity);
889 int wep = M_ARGV(1, int);
891 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
894 MUTATOR_HOOKFUNCTION(nb, FilterItem)
896 entity item = M_ARGV(0, entity);
898 if(Item_IsLoot(item))
899 if(item.weapon == WEP_NEXBALL.m_id)
905 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
907 entity item = M_ARGV(0, entity);
908 entity toucher = M_ARGV(1, entity);
910 if(item.weapon && toucher.ballcarried)
911 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
913 return MUT_ITEMTOUCH_CONTINUE;
916 MUTATOR_HOOKFUNCTION(nb, TeamBalance_CheckAllowedTeams)
918 M_ARGV(1, string) = "nexball_team";
922 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
924 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
928 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
930 entity frag_target = M_ARGV(0, entity);
932 if(frag_target.ballcarried)
933 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
938 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
940 M_ARGV(2, int) &= ~0x80;
943 REGISTER_MUTATOR(nb, false)
948 g_nexball_meter_period = autocvar_g_nexball_meter_period;
949 if(g_nexball_meter_period <= 0)
950 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
951 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
955 CVTOV(g_nexball_football_boost_forward); //100
956 CVTOV(g_nexball_football_boost_up); //200
957 CVTOV(g_nexball_delay_idle); //10
958 CVTOV(g_nexball_football_physics); //0
960 radar_showenemies = autocvar_g_nexball_radar_showallplayers;
962 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
963 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
965 GameRules_teams(true);
966 GameRules_limit_score(autocvar_g_nexball_goallimit);
967 GameRules_limit_lead(autocvar_g_nexball_goalleadlimit);
970 MUTATOR_ONROLLBACK_OR_REMOVE
972 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;