1 #include "gamemode_nexball.qh"
6 float autocvar_g_nexball_safepass_turnrate;
7 float autocvar_g_nexball_safepass_maxdist;
8 float autocvar_g_nexball_safepass_holdtime;
9 float autocvar_g_nexball_viewmodel_scale;
10 float autocvar_g_nexball_tackling;
11 vector autocvar_g_nexball_viewmodel_offset;
13 void basketball_touch();
14 void football_touch();
16 const float NBM_NONE = 0;
17 const float NBM_FOOTBALL = 2;
18 const float NBM_BASKETBALL = 4;
21 float OtherTeam(float t) //works only if there are two teams on the map!
24 e = find(world, classname, "nexball_team");
26 e = find(e, classname, "nexball_team");
30 const float ST_NEXBALL_GOALS = 1;
31 const float SP_NEXBALL_GOALS = 4;
32 const float SP_NEXBALL_FAULTS = 5;
33 void nb_ScoreRules(float teams)
35 ScoreRules_basics(teams, 0, 0, true);
36 ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
37 ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
38 ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
39 ScoreRules_basics_end();
42 void LogNB(string mode, entity actor)
45 if(!autocvar_sv_eventlog)
47 s = strcat(":nexball:", mode);
49 s = strcat(s, ":", ftos(actor.playerid));
53 void ball_restart(void)
56 DropBall(self, self.owner.origin, '0 0 0');
60 void nexball_setstatus(void)
63 self.items &= ~IT_KEY1;
66 if(self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
68 bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
70 self = self.ballcarried;
71 DropBall(self, self.owner.origin, '0 0 0');
76 self.items |= IT_KEY1;
80 void relocate_nexball(void)
82 tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, true, self);
87 if(!move_out_of_solid(self))
88 objerror("could not get out of solid at all!");
89 LOG_INFO("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
90 LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
91 LOG_INFO(" ", ftos(self.origin.y - o.y));
92 LOG_INFO(" ", ftos(self.origin.z - o.z), "'\n");
101 DropBall(self, ownr.origin, ownr.velocity);
102 makevectors(ownr.v_angle.y * '0 1 0');
103 ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
104 ownr.flags &= ~FL_ONGROUND;
107 void GiveBall(entity plyr, entity ball)
111 if((ownr = ball.owner))
113 ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
114 ownr.ballcarried = world;
118 ownr.weaponentity.state = WS_READY;
120 WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
124 WaypointSprite_Kill(ball.waypointsprite_attachedforcarrier);
127 //setattachment(ball, plyr, "");
128 setorigin(ball, plyr.origin + plyr.view_ofs);
130 if(ball.team != plyr.team)
131 ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
133 ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
134 ball.team = plyr.team;
135 plyr.ballcarried = ball;
136 ball.nb_dropper = plyr;
138 plyr.effects |= autocvar_g_nexball_basketball_effects_default;
139 ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
141 ball.velocity = '0 0 0';
142 ball.movetype = MOVETYPE_NONE;
143 ball.touch = func_null;
144 ball.effects |= EF_NOSHADOW;
145 ball.scale = 1; // scale down.
147 WaypointSprite_AttachCarrier(WP_NbBall, plyr, RADARICON_FLAGCARRIER);
148 WaypointSprite_UpdateRule(plyr.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
150 if(autocvar_g_nexball_basketball_delay_hold)
152 ball.think = DropOwner;
153 ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
158 self.weaponentity.weapons = self.weapons;
159 self.weaponentity.switchweapon = self.weapon;
160 self.weapons = WEPSET_PORTO;
161 WEP_ACTION(WEP_PORTO.m_id, WR_RESETPLAYER);
162 self.switchweapon = WEP_PORTO.m_id;
163 W_SwitchWeapon(WEP_PORTO.m_id);
167 void DropBall(entity ball, vector org, vector vel)
169 ball.effects |= autocvar_g_nexball_basketball_effects_default;
170 ball.effects &= ~EF_NOSHADOW;
171 ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
173 setattachment(ball, world, "");
174 setorigin(ball, org);
175 ball.movetype = MOVETYPE_BOUNCE;
176 ball.flags &= ~FL_ONGROUND;
177 ball.scale = ball_scale;
179 ball.nb_droptime = time;
180 ball.touch = basketball_touch;
181 ball.think = ResetBall;
182 ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
184 if(ball.owner.metertime)
186 ball.owner.metertime = 0;
187 ball.owner.weaponentity.state = WS_READY;
190 WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
191 WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
192 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
194 ball.owner.ballcarried = world;
201 self.flags &= ~FL_ONGROUND;
202 self.movetype = MOVETYPE_BOUNCE;
203 if(self.classname == "nexball_basketball")
204 self.touch = basketball_touch;
205 else if(self.classname == "nexball_football")
206 self.touch = football_touch;
208 self.think = ResetBall;
209 self.nextthink = time + autocvar_g_nexball_delay_idle + 3;
213 sound(self, CH_TRIGGER, self.noise1, VOL_BASE, ATTEN_NORM);
214 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
215 LogNB("init", world);
220 if(self.cnt < 2) // step 1
222 if(time == self.teamtime)
223 bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
225 self.touch = func_null;
226 self.movetype = MOVETYPE_NOCLIP;
227 self.velocity = '0 0 0'; // just in case?
229 LogNB("resetidle", world);
231 self.nextthink = time;
233 else if(self.cnt < 4) // step 2 and 3
235 // dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
236 self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
237 self.nextthink = time + 0.5;
242 // dprint("Step 4: time: ", ftos(time), "\n");
243 if(vlen(self.origin - self.spawnorigin) > 10) // should not happen anymore
244 LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
245 vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
246 self.velocity = '0 0 0';
247 setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
248 self.movetype = MOVETYPE_NONE;
249 self.think = InitBall;
250 self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
254 void football_touch(void)
256 if(other.solid == SOLID_BSP)
258 if(time > self.lastground + 0.1)
260 sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
261 self.lastground = time;
263 if(vlen(self.velocity) && !self.cnt)
264 self.nextthink = time + autocvar_g_nexball_delay_idle;
267 if (!IS_PLAYER(other))
272 self.nextthink = time + autocvar_g_nexball_delay_idle;
275 self.team = other.team;
277 if(autocvar_g_nexball_football_physics == -1) // MrBougo try 1, before decompiling Rev's original
279 if(vlen(other.velocity))
280 self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
282 else if(autocvar_g_nexball_football_physics == 1) // MrBougo's modded Rev style: partially independant of the height of the aiming point
284 makevectors(other.v_angle);
285 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
287 else if(autocvar_g_nexball_football_physics == 2) // 2nd mod try: totally independant. Really playable!
289 makevectors(other.v_angle.y * '0 1 0');
290 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
292 else // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
294 makevectors(other.v_angle);
295 self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
297 self.avelocity = -250 * v_forward; // maybe there is a way to make it look better?
300 void basketball_touch(void)
302 if(other.ballcarried)
307 if(!self.cnt && IS_PLAYER(other) && !other.frozen && !other.deadflag && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
309 if(other.health <= 0)
311 LogNB("caught", other);
312 GiveBall(other, self);
314 else if(other.solid == SOLID_BSP)
316 sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
317 if(vlen(self.velocity) && !self.cnt)
318 self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
325 float isclient, pscore, otherteam;
329 if((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
330 ball = other.ballcarried;
333 if(ball.classname != "nexball_basketball")
334 if(ball.classname != "nexball_football")
336 if((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
342 otherteam = OtherTeam(ball.team);
346 if((isclient = IS_CLIENT(ball.pusher)))
347 pname = ball.pusher.netname;
349 pname = "Someone (?)";
351 if(ball.team == self.team) //owngoal (regular goals)
353 LogNB("owngoal", ball.pusher);
354 bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
357 else if(self.team == GOAL_FAULT)
359 LogNB("fault", ball.pusher);
361 bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
363 bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
366 else if(self.team == GOAL_OUT)
368 LogNB("out", ball.pusher);
369 if((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
370 bprint(pname, "^7 went out of bounds.\n");
372 bprint("The ball was returned.\n");
377 LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
378 bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
382 sound(ball, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NONE);
384 if(ball.team && pscore)
386 if(nb_teams == 2 && pscore < 0)
387 TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
389 TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
394 PlayerScore_Add(ball.pusher, SP_NEXBALL_GOALS, pscore);
396 PlayerScore_Add(ball.pusher, SP_NEXBALL_FAULTS, -pscore);
399 if(ball.owner) // Happens on spawnflag GOAL_TOUCHPLAYER
400 DropBall(ball, ball.owner.origin, ball.owner.velocity);
402 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
405 ball.think = ResetBall;
406 if(ball.classname == "nexball_basketball")
407 ball.touch = football_touch; // better than func_null: football control until the ball gets reset
408 ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
411 //=======================//
413 //=======================//
414 void spawnfunc_nexball_team(void)
421 self.team = self.cnt + 1;
424 void nb_spawnteam(string teamname, float teamcolor)
426 LOG_TRACE("^2spawned team ", teamname, "\n");
429 e.classname = "nexball_team";
430 e.netname = teamname;
436 void nb_spawnteams(void)
438 bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
440 for(e = world; (e = find(e, classname, "nexball_goal"));)
447 nb_spawnteam("Red", e.team-1) ;
454 nb_spawnteam("Blue", e.team-1) ;
461 nb_spawnteam("Yellow", e.team-1);
468 nb_spawnteam("Pink", e.team-1) ;
476 void nb_delayedinit(void)
478 if(find(world, classname, "nexball_team") == world)
480 nb_ScoreRules(nb_teams);
484 //=======================//
486 //=======================//
490 if(!g_nexball) { remove(self); return; }
492 // balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
496 self.model = "models/nexball/ball.md3";
500 precache_model(self.model);
501 setmodel(self, self.model);
502 setsize(self, BALL_MINS, BALL_MAXS);
503 ball_scale = self.scale;
506 self.spawnorigin = self.origin;
508 self.effects = self.effects | EF_LOWPRECISION;
510 if(cvar(strcat("g_", self.classname, "_trail"))) //nexball_basketball :p
512 self.glow_color = autocvar_g_nexball_trail_color;
513 self.glow_trail = true;
516 self.movetype = MOVETYPE_FLY;
518 if(!autocvar_g_nexball_sound_bounce)
520 else if(self.noise == "")
521 self.noise = "sound/nexball/bounce.wav";
522 //bounce sound placeholder (FIXME)
523 if(self.noise1 == "")
524 self.noise1 = "sound/nexball/drop.wav";
525 //ball drop sound placeholder (FIXME)
526 if(self.noise2 == "")
527 self.noise2 = "sound/nexball/steal.wav";
528 //stealing sound placeholder (FIXME)
529 if(self.noise) precache_sound(self.noise);
530 precache_sound(self.noise1);
531 precache_sound(self.noise2);
533 WaypointSprite_AttachCarrier(WP_NbBall, self, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
535 self.reset = ball_restart;
536 self.think = InitBall;
537 self.nextthink = game_starttime + autocvar_g_nexball_delay_start;
540 void spawnfunc_nexball_basketball(void)
542 nexball_mode |= NBM_BASKETBALL;
543 self.classname = "nexball_basketball";
544 if (!(balls & BALL_BASKET))
547 CVTOV(g_nexball_basketball_effects_default);
548 CVTOV(g_nexball_basketball_delay_hold);
549 CVTOV(g_nexball_basketball_delay_hold_forteam);
550 CVTOV(g_nexball_basketball_teamsteal);
552 autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
555 self.effects = autocvar_g_nexball_basketball_effects_default;
556 self.solid = SOLID_TRIGGER;
557 balls |= BALL_BASKET;
558 self.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
559 self.bouncestop = autocvar_g_nexball_basketball_bouncestop;
563 void spawnfunc_nexball_football(void)
565 nexball_mode |= NBM_FOOTBALL;
566 self.classname = "nexball_football";
567 self.solid = SOLID_TRIGGER;
569 self.bouncefactor = autocvar_g_nexball_football_bouncefactor;
570 self.bouncestop = autocvar_g_nexball_football_bouncestop;
574 float nb_Goal_Customize()
577 e = WaypointSprite_getviewentity(other);
578 wp_owner = self.owner;
579 if(SAME_TEAM(e, wp_owner)) { return false; }
586 if(!g_nexball) { remove(self); return; }
590 if(self.team != GOAL_OUT && Team_TeamToNumber(self.team) != -1)
592 entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (self.absmin + self.absmax) * 0.5, self, sprite, RADARICON_NONE);
593 wp.colormod = ((self.team) ? Team_ColorRGB(self.team) : '1 0.5 0');
594 self.sprite.customizeentityforclient = nb_Goal_Customize;
597 self.classname = "nexball_goal";
599 self.noise = "ctf/respawn.wav";
600 precache_sound(self.noise);
601 self.touch = GoalTouch;
604 void spawnfunc_nexball_redgoal(void)
606 self.team = NUM_TEAM_1;
609 void spawnfunc_nexball_bluegoal(void)
611 self.team = NUM_TEAM_2;
614 void spawnfunc_nexball_yellowgoal(void)
616 self.team = NUM_TEAM_3;
619 void spawnfunc_nexball_pinkgoal(void)
621 self.team = NUM_TEAM_4;
625 void spawnfunc_nexball_fault(void)
627 self.team = GOAL_FAULT;
629 self.noise = "misc/typehit.wav";
633 void spawnfunc_nexball_out(void)
635 self.team = GOAL_OUT;
637 self.noise = "misc/typehit.wav";
642 //Spawnfuncs preserved for compatibility
645 void spawnfunc_ball(void)
647 spawnfunc_nexball_football();
649 void spawnfunc_ball_football(void)
651 spawnfunc_nexball_football();
653 void spawnfunc_ball_basketball(void)
655 spawnfunc_nexball_basketball();
657 // The "red goal" is defended by blue team. A ball in there counts as a point for red.
658 void spawnfunc_ball_redgoal(void)
660 spawnfunc_nexball_bluegoal(); // I blame Revenant
662 void spawnfunc_ball_bluegoal(void)
664 spawnfunc_nexball_redgoal(); // but he didn't mean to cause trouble :p
666 void spawnfunc_ball_fault(void)
668 spawnfunc_nexball_fault();
670 void spawnfunc_ball_bound(void)
672 spawnfunc_nexball_out();
675 //=======================//
677 //=======================//
680 void W_Nexball_Think()
682 //dprint("W_Nexball_Think\n");
683 //vector new_dir = steerlib_arrive(self.enemy.origin, 2500);
684 vector new_dir = normalize(self.enemy.origin + '0 0 50' - self.origin);
685 vector old_dir = normalize(self.velocity);
686 float _speed = vlen(self.velocity);
687 vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
688 //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
690 self.velocity = new_vel;
692 self.nextthink = time;
695 void W_Nexball_Touch(void)
697 entity ball, attacker;
698 attacker = self.owner;
699 //self.think = func_null;
700 //self.enemy = world;
703 if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
704 if((ball = other.ballcarried) && !other.frozen && !other.deadflag && (IS_PLAYER(attacker)))
706 other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
707 other.flags &= ~FL_ONGROUND;
708 if(!attacker.ballcarried)
710 LogNB("stole", attacker);
711 sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
713 if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
715 attacker.teamkill_complain = time + 5;
716 attacker.teamkill_soundtime = time + 0.4;
717 attacker.teamkill_soundsource = other;
720 GiveBall(attacker, other.ballcarried);
726 void W_Nexball_Attack(float t)
730 if(!(ball = self.ballcarried))
733 W_SetupShot(self, false, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
734 tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
738 self.metertime = 0; // Shot failed, hide the power meter
742 //Calculate multiplier
747 mi = autocvar_g_nexball_basketball_meter_minpower;
748 ma = max(mi, autocvar_g_nexball_basketball_meter_maxpower); // avoid confusion
749 //One triangle wave period with 1 as max
750 mul = 2 * (t % g_nexball_meter_period) / g_nexball_meter_period;
753 mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
756 DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(self.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
759 //TODO: use the speed_up cvar too ??
762 void W_Nexball_Attack2(void)
764 if(self.ballcarried.enemy)
766 entity _ball = self.ballcarried;
767 W_SetupShot(self, false, 4, "nexball/shoot1.wav", CH_WEAPON_A, 0);
768 DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
769 _ball.think = W_Nexball_Think;
770 _ball.nextthink = time;
774 if(!autocvar_g_nexball_tackling)
778 if(!(balls & BALL_BASKET))
780 W_SetupShot(self, false, 2, "nexball/shoot2.wav", CH_WEAPON_A, 0);
783 missile.owner = self;
784 missile.classname = "ballstealer";
786 missile.movetype = MOVETYPE_FLY;
787 PROJECTILE_MAKETRIGGER(missile);
789 //setmodel(missile, "models/elaser.mdl"); // precision set below
790 setsize(missile, '0 0 0', '0 0 0');
791 setorigin(missile, w_shotorg);
793 W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
794 missile.angles = vectoangles(missile.velocity);
795 missile.touch = W_Nexball_Touch;
796 missile.think = SUB_Remove;
797 missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
799 missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
800 missile.flags = FL_PROJECTILE;
802 CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
805 float ball_customize()
809 self.effects &= ~EF_FLAME;
811 self.customizeentityforclient = func_null;
815 if(other == self.owner)
817 self.scale = autocvar_g_nexball_viewmodel_scale;
819 self.effects |= EF_FLAME;
821 self.effects &= ~EF_FLAME;
825 self.effects &= ~EF_FLAME;
832 float w_nexball_weapon(float req)
837 if(weapon_prepareattack(0, autocvar_g_balance_nexball_primary_refire))
838 if(autocvar_g_nexball_basketball_meter)
840 if(self.ballcarried && !self.metertime)
841 self.metertime = time;
843 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
847 W_Nexball_Attack(-1);
848 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
850 if(self.BUTTON_ATCK2)
851 if(weapon_prepareattack(1, autocvar_g_balance_nexball_secondary_refire))
854 weapon_thinkf(WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
857 if(!self.BUTTON_ATCK && self.metertime && self.ballcarried)
859 W_Nexball_Attack(time - self.metertime);
860 // DropBall or stealing will set metertime back to 0
861 weapon_thinkf(WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
864 else if(req == WR_INIT)
866 precache_model(W_Model("g_porto.md3"));
867 precache_model(W_Model("v_porto.md3"));
868 precache_model(W_Model("h_porto.iqm"));
869 precache_model("models/elaser.mdl");
870 precache_sound("nexball/shoot1.wav");
871 precache_sound("nexball/shoot2.wav");
872 precache_sound("misc/typehit.wav");
874 else if(req == WR_SETUP)
876 //weapon_setup(WEP_PORTO.m_id);
878 // No need to check WR_CHECKAMMO* or WR_AIM, it should always return true
882 MUTATOR_HOOKFUNCTION(nexball_BallDrop)
884 if(self.ballcarried && g_nexball)
885 DropBall(self.ballcarried, self.origin, self.velocity);
890 MUTATOR_HOOKFUNCTION(nexball_PlayerPreThink)
892 makevectors(self.v_angle);
893 if(nexball_mode & NBM_BASKETBALL)
898 self.ballcarried.velocity = self.velocity;
899 self.ballcarried.customizeentityforclient = ball_customize;
901 setorigin(self.ballcarried, self.origin + self.view_ofs +
902 v_forward * autocvar_g_nexball_viewmodel_offset.x +
903 v_right * autocvar_g_nexball_viewmodel_offset.y +
904 v_up * autocvar_g_nexball_viewmodel_offset.z);
907 if(autocvar_g_nexball_safepass_maxdist)
909 if(self.ballcarried.wait < time && self.ballcarried.enemy)
911 //centerprint(self, sprintf("Lost lock on %s", self.ballcarried.enemy.netname));
912 self.ballcarried.enemy = world;
916 //tracebox(self.origin + self.view_ofs, '-2 -2 -2', '2 2 2', self.origin + self.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
917 crosshair_trace(self);
919 IS_CLIENT(trace_ent) &&
920 trace_ent.deadflag == DEAD_NO &&
921 trace_ent.team == self.team &&
922 vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
925 //if(self.ballcarried.enemy != trace_ent)
926 // centerprint(self, sprintf("Locked to %s", trace_ent.netname));
927 self.ballcarried.enemy = trace_ent;
928 self.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
936 if(self.weaponentity.weapons)
938 self.weapons = self.weaponentity.weapons;
939 WEP_ACTION(WEP_PORTO.m_id, WR_RESETPLAYER);
940 self.switchweapon = self.weaponentity.switchweapon;
941 W_SwitchWeapon(self.switchweapon);
943 self.weaponentity.weapons = '0 0 0';
954 MUTATOR_HOOKFUNCTION(nexball_PlayerSpawn)
956 self.weaponentity.weapons = '0 0 0';
958 if(nexball_mode & NBM_BASKETBALL)
959 self.weapons |= WEPSET_PORTO;
961 self.weapons = '0 0 0';
966 MUTATOR_HOOKFUNCTION(nexball_PlayerPhysics)
970 self.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
971 self.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
976 MUTATOR_HOOKFUNCTION(nexball_SetStartItems)
978 start_items |= IT_UNLIMITED_SUPERWEAPONS; // FIXME BAD BAD BAD BAD HACK, NEXBALL SHOULDN'T ABUSE PORTO'S WEAPON SLOT
983 MUTATOR_HOOKFUNCTION(nexball_ForbidThrowing)
985 if(self.weapon == WEP_MORTAR.m_id)
991 MUTATOR_HOOKFUNCTION(nexball_FilterItem)
993 if(self.classname == "droppedweapon")
994 if(self.weapon == WEP_MORTAR.m_id)
1000 MUTATOR_DEFINITION(gamemode_nexball)
1002 MUTATOR_HOOK(PlayerDies, nexball_BallDrop, CBC_ORDER_ANY);
1003 MUTATOR_HOOK(MakePlayerObserver, nexball_BallDrop, CBC_ORDER_ANY);
1004 MUTATOR_HOOK(ClientDisconnect, nexball_BallDrop, CBC_ORDER_ANY);
1005 MUTATOR_HOOK(PlayerSpawn, nexball_PlayerSpawn, CBC_ORDER_ANY);
1006 MUTATOR_HOOK(PlayerPreThink, nexball_PlayerPreThink, CBC_ORDER_ANY);
1007 MUTATOR_HOOK(PlayerPhysics, nexball_PlayerPhysics, CBC_ORDER_ANY);
1008 MUTATOR_HOOK(SetStartItems, nexball_SetStartItems, CBC_ORDER_ANY);
1009 MUTATOR_HOOK(ForbidThrowCurrentWeapon, nexball_ForbidThrowing, CBC_ORDER_ANY);
1010 MUTATOR_HOOK(FilterItem, nexball_FilterItem, CBC_ORDER_ANY);
1014 g_nexball_meter_period = autocvar_g_nexball_meter_period;
1015 if(g_nexball_meter_period <= 0)
1016 g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
1017 g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
1018 addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
1022 CVTOV(g_nexball_football_boost_forward); //100
1023 CVTOV(g_nexball_football_boost_up); //200
1024 CVTOV(g_nexball_delay_idle); //10
1025 CVTOV(g_nexball_football_physics); //0
1027 radar_showennemies = autocvar_g_nexball_radar_showallplayers;
1029 InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
1032 MUTATOR_ONROLLBACK_OR_REMOVE
1034 // we actually cannot roll back nb_delayedinit here
1035 // BUT: we don't need to! If this gets called, adding always
1041 LOG_INFO("This is a game type and it cannot be removed at runtime.");