1 void ka_SpawnBall(void);
2 void ka_TouchEvent(void);
3 void ka_RespawnBall(void);
4 void ka_DropEvent(entity);
6 void ka_Initialize() // run at the start of a match, initiates game mode
11 precache_sound("keepaway/pickedup.wav");
12 precache_sound("keepaway/dropped.wav");
13 precache_sound("keepaway/respawn.wav");
14 precache_sound("keepaway/touch.wav");
16 ScoreRules_keepaway();
20 void ka_Reset() // used to clear the ballcarrier whenever the match switches from warmup to normal
23 if(self.owner.classname == "player")
24 ka_DropEvent(self.owner);
29 void ka_SpawnBall() // loads various values for the ball
31 if(!g_keepaway) { return; }
35 e.model = "models/orbs/orbblue.md3";
37 precache_model(e.model);
39 setsize(e, '-20 -20 -20', '20 20 20');
40 e.classname = "keepawayball";
41 e.damageforcescale = cvar("g_keepawayball_damageforcescale");
42 e.takedamage = DAMAGE_YES;
43 e.glow_color = cvar("g_keepawayball_trail_color");
45 e.movetype = MOVETYPE_BOUNCE;
46 e.touch = ka_TouchEvent;
51 InitializeEntity(e, ka_RespawnBall, INITPRIO_SETLOCATION); // is this the right priority? Neh, I have no idea.. Well-- it works! So.
54 void ka_RespawnBall() // runs whenever the ball needs to be relocated
56 vector oldballorigin = self.origin;
58 if(MoveToRandomMapLocation(self, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY, 10, 1024, 256))
60 makevectors(self.angles);
61 self.movetype = MOVETYPE_BOUNCE;
62 self.velocity = '0 0 200';
63 self.angles = '0 0 0';
64 self.solid = SOLID_TRIGGER;
65 self.think = ka_RespawnBall;
66 self.nextthink = time + cvar("g_keepawayball_respawntime");
68 pointparticles(particleeffectnum("electro_combo"), oldballorigin, '0 0 0', 1);
69 pointparticles(particleeffectnum("electro_combo"), self.origin, '0 0 0', 1);
71 WaypointSprite_Spawn("ka-ball", 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attachedforcarrier, FALSE);
72 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '0 1 1');
73 WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
75 sound(self, CHAN_AUTO, "keepaway/respawn.wav", VOL_BASE, ATTN_NONE); // no attenuation as this is a global sound
79 ka_RespawnBall(); // finding a location failed, retry
83 void ka_TouchEvent() // runs any time that the ball comes in contact with something
86 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
87 { // The ball fell off the map, respawn it since players can't get to it
91 if(other.deadflag != DEAD_NO) { return; }
92 if(other.classname != "player")
93 { // The ball just touched an object, most likely the world
94 pointparticles(particleeffectnum("kaball_sparks"), self.origin, '0 0 0', 1);
95 sound(self, CHAN_AUTO, "keepaway/touch.wav", VOL_BASE, ATTN_NORM);
98 if(self.wait > time) { return; }
100 // attach the ball to the player
102 other.ballcarried = self;
103 setattachment(self, other, "");
104 setorigin(self, '3 0 20');
106 // make the ball invisible/unable to do anything
107 self.velocity = '0 0 0';
108 self.movetype = MOVETYPE_NONE;
109 self.touch = SUB_Null;
110 self.effects |= EF_NODRAW;
111 self.think = SUB_Null;
113 self.takedamage = DAMAGE_NO;
115 // apply effects to player
116 other.glow_color = cvar("g_keepawayball_trail_color");
117 other.glow_trail = TRUE;
121 // messages and sounds
122 Send_KillNotification(other.netname, "", "", KA_PICKUPBALL, MSG_KA);
123 WriteByte(MSG_BROADCAST, SVC_CENTERPRINT);
124 WriteString(MSG_BROADCAST, strcat("\n\n", other.netname, "^7 has picked up the ball!\n"));
125 sound(self.owner, CHAN_AUTO, "keepaway/pickedup.wav", VOL_BASE, ATTN_NONE);
128 PlayerScore_Add(other, SP_KEEPAWAY_PICKUPS, 1);
131 WaypointSprite_AttachCarrier("ka-ballcarrier", other);
132 WaypointSprite_UpdateRule(other.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
133 WaypointSprite_UpdateTeamRadar(other.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '1 0 0');
134 WaypointSprite_Ping(other.waypointsprite_attachedforcarrier);
135 WaypointSprite_Kill(self.waypointsprite_attachedforcarrier);
138 void ka_DropEvent(entity plyr) // runs any time that a player is supposed to lose the ball
141 ball = plyr.ballcarried;
143 if(!ball) { return; }
146 setattachment(ball, world, "");
147 ball.movetype = MOVETYPE_BOUNCE;
148 ball.solid = SOLID_TRIGGER;
149 ball.wait = time + 1;
150 ball.think = ka_RespawnBall;
151 ball.nextthink = time + cvar("g_keepawayball_respawntime");
152 ball.touch = ka_TouchEvent;
153 ball.takedamage = DAMAGE_YES;
154 ball.effects &~= EF_NODRAW;
155 setorigin(ball, plyr.origin + '0 0 10');
156 ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
157 ball.owner.ballcarried = world;
160 // reset the player effects
163 plyr.glow_trail = FALSE;
165 // messages and sounds
166 Send_KillNotification(plyr.netname, "", "", KA_DROPBALL, MSG_KA);
167 WriteByte(MSG_BROADCAST, SVC_CENTERPRINT);
168 WriteString(MSG_BROADCAST, strcat("\n\n", plyr.netname, "^7 has dropped the ball!\n"));
169 sound(other, CHAN_AUTO, "keepaway/dropped.wav", VOL_BASE, ATTN_NONE);
172 PlayerScore_Add(plyr, SP_KEEPAWAY_DROPS, 1);
175 WaypointSprite_Spawn("ka-ball", 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, FALSE);
176 WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
177 WaypointSprite_UpdateTeamRadar(ball.waypointsprite_attachedforcarrier, RADARICON_FLAGCARRIER, '0 1 1');
178 WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
179 WaypointSprite_Kill(plyr.waypointsprite_attachedforcarrier);
182 MUTATOR_HOOKFUNCTION(ka_RemovePlayer)
184 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has left the match, drop it
188 MUTATOR_HOOKFUNCTION(ka_Scoring)
190 if((frag_attacker != frag_target) && (frag_attacker.classname == "player"))
192 if(frag_target.ballcarried) { // add to amount of times killing carrier
193 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_CARRIERKILLS, 1);
194 if(cvar("g_keepaway_bckillscore")) // add bckills to the score
195 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_SCORE, 1);
197 else if(!frag_attacker.ballcarried)
198 if(cvar("g_keepaway_noncarrier_warn"))
199 centerprint_atprio(frag_attacker, (CENTERPRIO_SPAM + 5), "Killing people while you don't have the ball gives no points!");
201 if(frag_attacker.ballcarried) // add to amount of kills while ballcarrier
202 PlayerScore_Add(frag_attacker, SP_KEEPAWAY_SCORE, 1);
205 if(self.ballcarried) { ka_DropEvent(self); } // a player with the ball has died, drop it
209 MUTATOR_HOOKFUNCTION(ka_GiveFragsForKill)
211 frag_score = 0; // no frags counted in keepaway
215 MUTATOR_HOOKFUNCTION(ka_PlayerPreThink)
217 self.items &~= IT_KEY1;
220 self.items |= IT_KEY1;
222 if(self.BUTTON_USE) // drop the ball if the player presses the use button
223 if(self.ballcarried) { ka_DropEvent(self); }
228 MUTATOR_HOOKFUNCTION(ka_PlayerDamage) // for changing damage and force values that are applied to players in g_damage.qc
230 if(frag_attacker.items & IT_KEY1) // if the attacker is a ballcarrier
232 if(frag_target == frag_attacker) // damage done to yourself
234 frag_damage *= cvar("g_keepaway_ballcarrier_selfdamage");
235 frag_force *= cvar("g_keepaway_ballcarrier_selfforce");
237 else // damage done to noncarriers
239 frag_damage *= cvar("g_keepaway_ballcarrier_damage");
240 frag_force *= cvar("g_keepaway_ballcarrier_force");
243 else if not(frag_target.items & IT_KEY1) // if the target is a noncarrier
245 if(frag_target == frag_attacker) // damage done to yourself
247 frag_damage *= cvar("g_keepaway_noncarrier_selfdamage");
248 frag_force *= cvar("g_keepaway_noncarrier_selfforce");
250 else // damage done to other noncarriers
252 frag_damage *= cvar("g_keepaway_noncarrier_damage");
253 frag_force *= cvar("g_keepaway_noncarrier_force");
259 MUTATOR_DEFINITION(gamemode_keepaway)
261 MUTATOR_HOOK(MakePlayerObserver, ka_RemovePlayer, CBC_ORDER_ANY);
262 MUTATOR_HOOK(ClientDisconnect, ka_RemovePlayer, CBC_ORDER_ANY);
263 MUTATOR_HOOK(PlayerDies, ka_Scoring, CBC_ORDER_ANY);
264 MUTATOR_HOOK(GiveFragsForKill, ka_GiveFragsForKill, CBC_ORDER_ANY);
265 MUTATOR_HOOK(PlayerPreThink, ka_PlayerPreThink, CBC_ORDER_FIRST);
266 MUTATOR_HOOK(PlayerDamage_Calculate, ka_PlayerDamage, CBC_ORDER_ANY);
270 if(time > 1) // game loads at time 1
271 error("This is a game type and it cannot be added at runtime.");
279 error("This is a game type and it cannot be removed at runtime.");