1 #include "sv_nexball.qh"
3 #include <server/client.qh>
4 #include <server/command/vote.qh>
5 #include <server/gamelog.qh>
6 #include <server/world.qh>
7 #include <common/ent_cs.qh>
8 #include <common/mapobjects/triggers.qh>
9 #include <common/mutators/base.qh>
13 int autocvar_g_nexball_goalleadlimit;
14 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
16 bool autocvar_g_nexball_basketball_jumppad = true;
17 float autocvar_g_nexball_basketball_bouncefactor;
18 float autocvar_g_nexball_basketball_bouncestop;
19 float autocvar_g_nexball_basketball_carrier_highspeed;
20 bool autocvar_g_nexball_basketball_meter;
21 float autocvar_g_nexball_basketball_meter_maxpower;
22 float autocvar_g_nexball_basketball_meter_minpower;
23 float autocvar_g_nexball_delay_collect;
24 float autocvar_g_nexball_delay_goal;
25 float autocvar_g_nexball_delay_start;
26 bool autocvar_g_nexball_football_jumppad = true;
27 float autocvar_g_nexball_football_bouncefactor;
28 float autocvar_g_nexball_football_bouncestop;
29 bool autocvar_g_nexball_radar_showallplayers;
30 bool autocvar_g_nexball_sound_bounce;
31 int autocvar_g_nexball_trail_color;
32 bool autocvar_g_nexball_playerclip_collisions = true;
34 float autocvar_g_nexball_safepass_turnrate;
35 float autocvar_g_nexball_safepass_maxdist;
36 float autocvar_g_nexball_safepass_holdtime;
37 float autocvar_g_nexball_viewmodel_scale;
38 float autocvar_g_nexball_tackling;
39 vector autocvar_g_nexball_viewmodel_offset;
41 float autocvar_g_balance_nexball_primary_animtime;
42 float autocvar_g_balance_nexball_primary_refire;
43 float autocvar_g_balance_nexball_primary_speed;
44 float autocvar_g_balance_nexball_secondary_animtime;
45 float autocvar_g_balance_nexball_secondary_force;
46 float autocvar_g_balance_nexball_secondary_lifetime;
47 float autocvar_g_balance_nexball_secondary_refire;
48 float autocvar_g_balance_nexball_secondary_speed;
50 void basketball_touch(entity this, entity toucher);
51 void football_touch(entity this, entity toucher);
52 void ResetBall(entity this);
53 const int NBM_NONE = 0;
54 const int NBM_FOOTBALL = 2;
55 const int NBM_BASKETBALL = 4;
58 float OtherTeam(float t) //works only if there are two teams on the map!
61 e = find(NULL, classname, "nexball_team");
63 e = find(e, classname, "nexball_team");
67 const int ST_NEXBALL_GOALS = 1;
68 void nb_ScoreRules(int teams)
70 GameRules_scoring(teams, 0, 0, {
71 field_team(ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
72 field(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
73 field(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
77 void LogNB(string mode, entity actor)
80 if(!autocvar_sv_eventlog)
82 s = strcat(":nexball:", mode);
84 s = strcat(s, ":", ftos(actor.playerid));
88 void ball_restart(entity this)
91 DropBall(this, this.owner.origin, '0 0 0');
95 void nexball_setstatus(entity this)
97 this.items &= ~IT_KEY1;
100 if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
102 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
103 entity e = this.ballcarried;
104 DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
108 this.items |= IT_KEY1;
112 void relocate_nexball(entity this)
114 tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
117 vector o = this.origin;
118 if (!move_out_of_solid(this)) {
119 objerror(this, "could not get out of solid at all!");
122 "^1NOTE: this map needs FIXING. %s at %s needs to be moved out of solid, e.g. by %s",
125 vtos(this.origin - o)
131 void DropOwner(entity this)
135 DropBall(this, ownr.origin, ownr.velocity);
136 makevectors(ownr.v_angle.y * '0 1 0');
137 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
138 UNSET_ONGROUND(ownr);
141 void GiveBall(entity plyr, entity ball)
143 .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
144 entity ownr = ball.owner;
147 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
148 ownr.ballcarried = NULL;
149 GameRules_scoring_vip(ownr, false);
150 if(STAT(NB_METERSTART, ownr))
152 STAT(NB_METERSTART, ownr) = 0;
153 ownr.(weaponentity).state = WS_READY;
155 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
159 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
162 //setattachment(ball, plyr, "");
163 setorigin(ball, plyr.origin + plyr.view_ofs);
165 if(ball.team != plyr.team)
166 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
168 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
169 ball.weaponentity_fld = weaponentity;
170 ball.team = plyr.team;
171 plyr.ballcarried = ball;
172 GameRules_scoring_vip(plyr, true);
173 ball.nb_dropper = plyr;
175 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
176 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
178 ball.velocity = '0 0 0';
179 set_movetype(ball, MOVETYPE_NONE);
180 settouch(ball, func_null);
181 ball.effects |= EF_NOSHADOW;
182 ball.scale = 1; // scale down.
184 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
185 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
187 if(autocvar_g_nexball_basketball_delay_hold)
189 setthink(ball, DropOwner);
190 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
193 STAT(WEAPONS, plyr.(weaponentity)) = STAT(WEAPONS, plyr);
194 plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
195 STAT(WEAPONS, plyr) = WEPSET(NEXBALL);
196 Weapon w = WEP_NEXBALL;
197 w.wr_resetplayer(w, plyr);
198 plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
199 W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
202 void DropBall(entity ball, vector org, vector vel)
204 ball.effects |= autocvar_g_nexball_basketball_effects_default;
205 ball.effects &= ~EF_NOSHADOW;
206 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
208 setattachment(ball, NULL, "");
209 setorigin(ball, org);
210 set_movetype(ball, MOVETYPE_BOUNCE);
211 UNSET_ONGROUND(ball);
212 ball.scale = ball_scale;
214 ball.nb_droptime = time;
215 settouch(ball, basketball_touch);
216 setthink(ball, ResetBall);
217 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
219 if(STAT(NB_METERSTART, ball.owner))
221 STAT(NB_METERSTART, ball.owner) = 0;
222 .entity weaponentity = ball.weaponentity_fld;
223 ball.owner.(weaponentity).state = WS_READY;
226 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
227 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
228 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
230 entity e = ball.owner; ball.owner = NULL;
231 e.ballcarried = NULL;
232 GameRules_scoring_vip(e, false);
235 void InitBall(entity this)
237 if(game_stopped) return;
238 UNSET_ONGROUND(this);
239 set_movetype(this, MOVETYPE_BOUNCE);
240 if(this.classname == "nexball_basketball")
241 settouch(this, basketball_touch);
242 else if(this.classname == "nexball_football")
243 settouch(this, football_touch);
245 setthink(this, ResetBall);
246 this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
250 _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
251 WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
255 void ResetBall(entity this)
257 if(this.cnt < 2) // step 1
259 if(time == this.teamtime)
260 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
262 settouch(this, func_null);
263 set_movetype(this, MOVETYPE_NOCLIP);
264 this.velocity = '0 0 0'; // just in case?
266 LogNB("resetidle", NULL);
268 this.nextthink = time;
270 else if(this.cnt < 4) // step 2 and 3
272 // dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
273 this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
274 this.nextthink = time + 0.5;
279 // dprint("Step 4: time: ", ftos(time), "\n");
280 if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
281 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
282 vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
283 this.velocity = '0 0 0';
284 setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
285 set_movetype(this, MOVETYPE_NONE);
286 setthink(this, InitBall);
287 this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
291 void football_touch(entity this, entity toucher)
293 if(toucher.solid == SOLID_BSP)
295 if(time > this.lastground + 0.1)
297 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
298 this.lastground = time;
300 if(this.velocity && !this.cnt)
301 this.nextthink = time + autocvar_g_nexball_delay_idle;
304 if (!IS_PLAYER(toucher) && !IS_VEHICLE(toucher))
306 if(GetResource(toucher, RES_HEALTH) < 1)
309 this.nextthink = time + autocvar_g_nexball_delay_idle;
311 this.pusher = toucher;
312 this.team = toucher.team;
314 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
317 this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
319 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
321 makevectors(toucher.v_angle);
322 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
324 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
326 makevectors(toucher.v_angle.y * '0 1 0');
327 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
329 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
331 makevectors(toucher.v_angle);
332 this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
334 this.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
337 void basketball_touch(entity this, entity toucher)
339 if(toucher.ballcarried)
341 football_touch(this, toucher);
344 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))
346 if(GetResource(toucher, RES_HEALTH) < 1)
348 LogNB("caught", toucher);
349 GiveBall(toucher, this);
351 else if(toucher.solid == SOLID_BSP)
353 _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
354 if(this.velocity && !this.cnt)
355 this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
359 void GoalTouch(entity this, entity toucher)
362 float isclient, pscore, otherteam;
365 if(game_stopped) return;
366 if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
367 ball = toucher.ballcarried;
370 if(ball.classname != "nexball_basketball")
371 if(ball.classname != "nexball_football")
373 if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
375 EXACTTRIGGER_TOUCH(this, toucher);
378 if(NumTeams(nb_teams) == 2)
379 otherteam = OtherTeam(ball.team);
383 if((isclient = IS_CLIENT(ball.pusher)))
384 pname = ball.pusher.netname;
386 pname = "Someone (?)";
388 if(ball.team == this.team) //owngoal (regular goals)
390 LogNB("owngoal", ball.pusher);
391 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
394 else if(this.team == GOAL_FAULT)
396 LogNB("fault", ball.pusher);
397 if(NumTeams(nb_teams) == 2)
398 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
400 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
403 else if(this.team == GOAL_OUT)
405 LogNB("out", ball.pusher);
406 if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
407 bprint(pname, "^7 went out of bounds.\n");
409 bprint("The ball was returned.\n");
414 LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
415 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
419 _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
421 if(ball.team && pscore)
423 if(NumTeams(nb_teams) == 2 && pscore < 0)
424 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
426 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
431 GameRules_scoring_add(ball.pusher, NEXBALL_GOALS, pscore);
433 GameRules_scoring_add(ball.pusher, NEXBALL_FAULTS, -pscore);
436 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
437 DropBall(ball, ball.owner.origin, ball.owner.velocity);
439 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
442 setthink(ball, ResetBall);
443 if(ball.classname == "nexball_basketball")
444 settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
445 ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
448 //=======================//
450 //=======================//
451 spawnfunc(nexball_team)
458 this.team = this.cnt + 1;
461 void nb_spawnteam(string teamname, float teamcolor)
463 LOG_TRACE("^2spawned team ", teamname);
464 entity e = new(nexball_team);
465 e.netname = teamname;
473 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
475 for(e = NULL; (e = find(e, classname, "nexball_goal"));)
482 nb_spawnteam("Red", e.team-1) ;
490 nb_spawnteam("Blue", e.team-1) ;
498 nb_spawnteam("Yellow", e.team-1);
506 nb_spawnteam("Pink", e.team-1) ;
515 void nb_delayedinit(entity this)
517 if(find(NULL, classname, "nexball_team") == NULL)
519 nb_ScoreRules(nb_teams);
523 //=======================//
525 //=======================//
527 void SpawnBall(entity this)
529 if(!g_nexball) { delete(this); return; }
531 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
535 this.model = "models/nexball/ball.md3";
539 precache_model(this.model);
540 _setmodel(this, this.model);
541 setsize(this, BALL_MINS, BALL_MAXS);
542 ball_scale = this.scale;
544 relocate_nexball(this);
545 this.spawnorigin = this.origin;
547 this.effects = this.effects | EF_LOWPRECISION;
549 if(cvar(strcat("g_", this.classname, "_trail"))) //nexball_basketball :p
551 this.glow_color = autocvar_g_nexball_trail_color;
552 this.glow_trail = true;
555 set_movetype(this, MOVETYPE_FLY);
557 if(autocvar_g_nexball_playerclip_collisions)
558 this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
560 if(!autocvar_g_nexball_sound_bounce)
562 else if(this.noise == "")
563 this.noise = strzone(SND(NB_BOUNCE));
564 //bounce sound placeholder (FIXME)
565 if(this.noise1 == "")
566 this.noise1 = strzone(SND(NB_DROP));
567 //ball drop sound placeholder (FIXME)
568 if(this.noise2 == "")
569 this.noise2 = strzone(SND(NB_STEAL));
570 //stealing sound placeholder (FIXME)
571 if(this.noise) precache_sound(this.noise);
572 precache_sound(this.noise1);
573 precache_sound(this.noise2);
575 WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
577 this.reset = ball_restart;
578 setthink(this, InitBall);
579 this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
582 spawnfunc(nexball_basketball)
584 nexball_mode |= NBM_BASKETBALL;
585 this.classname = "nexball_basketball";
586 if (!(balls & BALL_BASKET))
589 CVTOV(g_nexball_basketball_effects_default);
590 CVTOV(g_nexball_basketball_delay_hold);
591 CVTOV(g_nexball_basketball_delay_hold_forteam);
592 CVTOV(g_nexball_basketball_teamsteal);
594 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
597 this.effects = autocvar_g_nexball_basketball_effects_default;
598 this.solid = SOLID_TRIGGER;
599 this.pushable = autocvar_g_nexball_basketball_jumppad;
600 balls |= BALL_BASKET;
601 this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
602 this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
606 spawnfunc(nexball_football)
608 nexball_mode |= NBM_FOOTBALL;
609 this.classname = "nexball_football";
610 this.solid = SOLID_TRIGGER;
612 this.pushable = autocvar_g_nexball_football_jumppad;
613 this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
614 this.bouncestop = autocvar_g_nexball_football_bouncestop;
618 bool nb_Goal_Customize(entity this, entity client)
620 entity e = WaypointSprite_getviewentity(client);
621 entity wp_owner = this.owner;
622 if(SAME_TEAM(e, wp_owner)) { return false; }
627 void SpawnGoal(entity this)
629 if(!g_nexball) { delete(this); return; }
633 if(this.team != GOAL_OUT && Team_IsValidTeam(this.team))
635 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
636 wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
637 setcefc(this.sprite, nb_Goal_Customize);
640 this.classname = "nexball_goal";
642 this.noise = "ctf/respawn.wav";
643 precache_sound(this.noise);
644 settouch(this, GoalTouch);
647 spawnfunc(nexball_redgoal)
649 this.team = NUM_TEAM_1;
652 spawnfunc(nexball_bluegoal)
654 this.team = NUM_TEAM_2;
657 spawnfunc(nexball_yellowgoal)
659 this.team = NUM_TEAM_3;
662 spawnfunc(nexball_pinkgoal)
664 this.team = NUM_TEAM_4;
668 spawnfunc(nexball_fault)
670 this.team = GOAL_FAULT;
672 this.noise = strzone(SND(TYPEHIT));
676 spawnfunc(nexball_out)
678 this.team = GOAL_OUT;
680 this.noise = strzone(SND(TYPEHIT));
685 //Spawnfuncs preserved for compatibility
690 spawnfunc_nexball_football(this);
692 spawnfunc(ball_football)
694 spawnfunc_nexball_football(this);
696 spawnfunc(ball_basketball)
698 spawnfunc_nexball_basketball(this);
700 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
701 spawnfunc(ball_redgoal)
703 spawnfunc_nexball_bluegoal(this); // I blame Revenant
705 spawnfunc(ball_bluegoal)
707 spawnfunc_nexball_redgoal(this); // but he didn't mean to cause trouble :p
709 spawnfunc(ball_fault)
711 spawnfunc_nexball_fault(this);
713 spawnfunc(ball_bound)
715 spawnfunc_nexball_out(this);
718 bool ball_customize(entity this, entity client)
722 this.effects &= ~EF_FLAME;
724 setcefc(this, func_null);
728 if(client == this.owner)
730 this.scale = autocvar_g_nexball_viewmodel_scale;
732 this.effects |= EF_FLAME;
734 this.effects &= ~EF_FLAME;
738 this.effects &= ~EF_FLAME;
745 void nb_DropBall(entity player)
747 if(player.ballcarried && g_nexball)
748 DropBall(player.ballcarried, player.origin, player.velocity);
751 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
753 entity player = M_ARGV(0, entity);
758 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
760 entity frag_target = M_ARGV(2, entity);
762 nb_DropBall(frag_target);
765 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
767 entity player = M_ARGV(0, entity);
773 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
775 entity player = M_ARGV(0, entity);
777 makevectors(player.v_angle);
778 if(nexball_mode & NBM_BASKETBALL)
780 if(player.ballcarried)
783 player.ballcarried.velocity = player.velocity;
784 setcefc(player.ballcarried, ball_customize);
786 vector org = player.origin + player.view_ofs +
787 v_forward * autocvar_g_nexball_viewmodel_offset.x +
788 v_right * autocvar_g_nexball_viewmodel_offset.y +
789 v_up * autocvar_g_nexball_viewmodel_offset.z;
790 setorigin(player.ballcarried, org);
793 if(autocvar_g_nexball_safepass_maxdist)
795 if(player.ballcarried.wait < time && player.ballcarried.enemy)
797 //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
798 player.ballcarried.enemy = NULL;
802 //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
803 crosshair_trace(player);
805 IS_CLIENT(trace_ent) &&
806 !IS_DEAD(trace_ent) &&
807 trace_ent.team == player.team &&
808 vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
811 //if(player.ballcarried.enemy != trace_ent)
812 // centerprint(player, sprintf("Locked to %s", trace_ent.netname));
813 player.ballcarried.enemy = trace_ent;
814 player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
822 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
824 .entity weaponentity = weaponentities[slot];
826 if(STAT(WEAPONS, player.(weaponentity)))
828 STAT(WEAPONS, player) = STAT(WEAPONS, player.(weaponentity));
829 Weapon w = WEP_NEXBALL;
830 w.wr_resetplayer(w, player);
831 player.(weaponentity).m_switchweapon = player.m_switchweapon;
832 W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
834 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
841 nexball_setstatus(player);
844 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
846 entity spectatee = M_ARGV(0, entity);
847 entity client = M_ARGV(1, entity);
849 STAT(NB_METERSTART, client) = STAT(NB_METERSTART, spectatee);
852 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
854 entity player = M_ARGV(0, entity);
856 STAT(NB_METERSTART, player) = 0;
857 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
859 .entity weaponentity = weaponentities[slot];
860 STAT(WEAPONS, player.(weaponentity)) = '0 0 0';
863 if (nexball_mode & NBM_BASKETBALL)
864 STAT(WEAPONS, player) |= WEPSET(NEXBALL);
866 STAT(WEAPONS, player) = '0 0 0';
871 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics_UpdateStats)
873 entity player = M_ARGV(0, entity);
874 // these automatically reset, no need to worry
876 if(player.ballcarried)
877 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_nexball_basketball_carrier_highspeed;
880 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
882 //entity player = M_ARGV(0, entity);
883 entity wepent = M_ARGV(1, entity);
885 return wepent.m_weapon == WEP_NEXBALL;
888 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
890 //entity player = M_ARGV(0, entity);
891 int wep = M_ARGV(1, int);
893 return wep == WEP_MORTAR.m_id; // TODO: what is this for?
896 MUTATOR_HOOKFUNCTION(nb, FilterItem)
898 entity item = M_ARGV(0, entity);
900 if(Item_IsLoot(item))
901 if(item.weapon == WEP_NEXBALL.m_id)
907 MUTATOR_HOOKFUNCTION(nb, ItemTouch)
909 entity item = M_ARGV(0, entity);
910 entity toucher = M_ARGV(1, entity);
912 if(item.weapon && toucher.ballcarried)
913 return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
915 return MUT_ITEMTOUCH_CONTINUE;
918 MUTATOR_HOOKFUNCTION(nb, TeamBalance_CheckAllowedTeams)
920 M_ARGV(1, string) = "nexball_team";
924 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
926 M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
930 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
932 entity frag_target = M_ARGV(0, entity);
934 if(frag_target.ballcarried)
935 DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
940 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
942 M_ARGV(2, int) &= ~0x80;
945 REGISTER_MUTATOR(nb, false)
950 g_nexball_meter_period = autocvar_g_nexball_meter_period;
951 if(g_nexball_meter_period <= 0)
952 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
953 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
957 CVTOV(g_nexball_football_boost_forward); //100
958 CVTOV(g_nexball_football_boost_up); //200
959 CVTOV(g_nexball_delay_idle); //10
960 CVTOV(g_nexball_football_physics); //0
962 radar_showenemies = autocvar_g_nexball_radar_showallplayers;
964 InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
965 WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
967 GameRules_teams(true);
968 GameRules_limit_score(autocvar_g_nexball_goallimit);
969 GameRules_limit_lead(autocvar_g_nexball_goalleadlimit);
972 MUTATOR_ONROLLBACK_OR_REMOVE
974 WEP_NEXBALL.spawnflags |= WEP_FLAG_MUTATORBLOCKED;