1 void ka_SpawnBall(void);
2 void ka_TouchEvent(void);
3 void ka_RespawnBall(void);
4 void ka_DropEvent(entity);
7 void ka_Initialize() // run at the start of a match, initiates game mode
12 precache_sound("keepaway/pickedup.wav");
13 precache_sound("keepaway/dropped.wav");
14 precache_sound("keepaway/respawn.wav");
15 precache_sound("keepaway/touch.wav");
17 ScoreRules_keepaway();
19 //entity e; // Is this needed here? I think not
21 //e.think = ka_SpawnBall;
24 //InitializeEntity(e, ka_SpawnBall, INITPRIO_SETLOCATION); // Is initializeentity needed here? I think not
28 void ka_Reset() // used to clear the ballcarrier whenever the match switches from warmup to normal
31 if(self.owner.classname == "player")
32 ka_DropEvent(self.owner);
37 void ka_SpawnBall() // loads various values for the ball
39 if(!g_keepaway) { return; }
43 if (!e.model) { // is this needed? OF COURSE the model doesn't exist, the ball isn't on the map yet!
44 e.model = "models/orbs/orbblue.md3";
46 precache_model(e.model);
48 setsize(e, BALL_MINS, BALL_MAXS);
50 e.classname = "keepawayball";
51 e.damageforcescale = cvar("g_keepawayball_damageforcescale");
52 e.takedamage = DAMAGE_YES;
53 //self.effects |= "sparks";
54 e.glow_color = cvar("g_keepawayball_trail_color");
56 e.movetype = MOVETYPE_BOUNCE;
57 e.touch = ka_TouchEvent;
58 e.think = ka_RespawnBall;
65 void ka_RespawnBall() // runs whenever the ball needs to be relocated
67 vector oldballorigin = self.origin;
69 if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
71 makevectors(self.angles);
72 self.movetype = MOVETYPE_BOUNCE;
73 self.velocity = '0 0 200';
74 self.angles = '0 0 0';
75 self.solid = SOLID_TRIGGER;
76 //self.touch = ka_TouchEvent;
77 self.think = ka_RespawnBall;
78 self.nextthink = time + cvar("g_keepawayball_respawntime");
79 pointparticles(particleeffectnum("electro_combo"), oldballorigin, '0 0 0', 1);
80 pointparticles(particleeffectnum("electro_combo"), self.origin, '0 0 0', 1);
82 WaypointSprite_Spawn("ka-ball", 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attachedforcarrier, FALSE);
83 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '0 1 1');
85 sound(self, CHAN_AUTO, "keepaway/respawn.wav", VOL_BASE, ATTN_NONE);
89 // sorry, can't spawn, better luck next frame
90 //self.think = ka_RespawnBall;
91 //self.nextthink = time;
96 void ka_TouchEvent() // runs any time that the ball comes in contact with something
99 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
101 self.think = ka_RespawnBall;
102 self.nextthink = time;
105 if(other.deadflag != DEAD_NO) { return; }
106 if(other.classname != "player")
107 { // The ball just touched an object, most likely the world
108 pointparticles(particleeffectnum("kaball_sparks"), self.origin, '0 0 0', 1);
109 sound(self, CHAN_AUTO, "keepaway/touch.wav", VOL_BASE, ATTN_NORM);
112 if(self.wait > time) { return; }
115 other.ballcarried = self;
116 setattachment(self, other, "");
117 setorigin(self, BALL_ATTACHORG);
119 self.velocity = '0 0 0';
120 self.movetype = MOVETYPE_NONE;
121 self.touch = SUB_Null;
122 self.effects |= EF_NODRAW;
123 self.think = SUB_Null;
125 self.takedamage = DAMAGE_NO;
127 other.glow_color = cvar("g_keepawayball_trail_color");
128 other.glow_trail = TRUE;
132 bprint(other.netname, "^7 has picked up the ball!\n");
133 WriteByte(MSG_BROADCAST, SVC_CENTERPRINT);
134 WriteString(MSG_BROADCAST, strcat("\n\n", other.netname, "^7 has picked up the ball!\n"));
135 sound(self.owner, CHAN_AUTO, "keepaway/pickedup.wav", VOL_BASE, ATTN_NONE);
137 PlayerScore_Add(other, SP_KEEPAWAY_PICKUPS, 1);
139 WaypointSprite_AttachCarrier("ka-ballcarrier", other);
140 WaypointSprite_UpdateRule(other.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
141 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 0 0');
142 WaypointSprite_Ping(other.waypointsprite_attachedforcarrier);
143 WaypointSprite_Kill(self.waypointsprite_attachedforcarrier);
146 void ka_DropEvent(entity plyr) // runs any time that a player is supposed to lose the ball
149 ball = plyr.ballcarried;
151 if(!ball) { return; }
153 setattachment(ball, world, "");
154 ball.movetype = MOVETYPE_BOUNCE;
155 ball.solid = SOLID_TRIGGER;
156 ball.wait = time + 1;
157 ball.think = ka_RespawnBall;
158 ball.nextthink = time + cvar("g_keepawayball_respawntime");
159 ball.touch = ka_TouchEvent;
160 ball.takedamage = DAMAGE_YES;
161 ball.effects &~= EF_NODRAW; //ball.alpha = 1.0;
162 setorigin(ball, plyr.origin + '0 0 10');
163 ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
164 ball.owner.ballcarried = world;
169 plyr.glow_trail = FALSE;
171 bprint(plyr.netname, "^7 has dropped the ball!\n");
172 WriteByte(MSG_BROADCAST, SVC_CENTERPRINT);
173 WriteString(MSG_BROADCAST, strcat("\n\n", plyr.netname, "^7 has dropped the ball!\n"));
174 sound(other, CHAN_AUTO, "keepaway/dropped.wav", VOL_BASE, ATTN_NONE);
176 PlayerScore_Add(plyr, SP_KEEPAWAY_DROPS, 1);
178 WaypointSprite_Spawn("ka-ball", 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, FALSE);
179 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
180 WaypointSprite_UpdateTeamRadar(ball.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '0 1 1');
181 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
182 WaypointSprite_Kill(plyr.waypointsprite_attachedforcarrier);
185 MUTATOR_HOOKFUNCTION(ka_RemovePlayer)
187 if(self.ballcarried) { ka_DropEvent(self); }
191 MUTATOR_HOOKFUNCTION(ka_Scoring)
193 if((frag_attacker != frag_target) && (frag_attacker.classname == "player"))
195 if(frag_target.ballcarried) { // get amount of times killing carrier
196 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_CARRIERKILLS, 1);
197 if(cvar("g_keepaway_bckillscore"))
198 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_SCORE, 1);
200 else if(!frag_attacker.ballcarried)
201 if(cvar("g_keepaway_noncarrier_warn"))
202 centerprint_atprio(frag_attacker, (CENTERPRIO_SPAM + 5), "Killing people while you don't have the ball gives no points!");
204 if(frag_attacker.ballcarried) // get kills as carrier
205 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_SCORE, 1);
208 if(self.ballcarried) { ka_DropEvent(self); }
212 MUTATOR_HOOKFUNCTION(ka_GiveFragsForKill)
214 frag_score = 0; // no frags counted in keepaway
218 MUTATOR_HOOKFUNCTION(ka_PlayerPreThink)
220 self.items &~= IT_KEY1;
223 self.items |= IT_KEY1;
226 if(self.ballcarried) { ka_DropEvent(self); }
231 MUTATOR_DEFINITION(gamemode_keepaway)
233 MUTATOR_HOOK(MakePlayerObserver, ka_RemovePlayer, CBC_ORDER_ANY);
234 MUTATOR_HOOK(ClientDisconnect, ka_RemovePlayer, CBC_ORDER_ANY);
235 MUTATOR_HOOK(PlayerDies, ka_Scoring, CBC_ORDER_ANY);
236 MUTATOR_HOOK(GiveFragsForKill, ka_GiveFragsForKill, CBC_ORDER_FIRST);
237 MUTATOR_HOOK(PlayerPreThink, ka_PlayerPreThink, CBC_ORDER_FIRST);
241 if(time > 1) // game loads at time 1
242 error("This is a game type and it cannot be added at runtime.");
250 error("This is a game type and it cannot be removed at runtime.");