1 void info_player_start (void)
3 self.classname = "info_player_deathmatch";
6 void info_player_deathmatch (void)
10 float spawn_goodspots, spawn_badspots;
11 entity Spawn_ClassifyPoints(entity firstspot, entity playerlist, float mindist, float goodspotnum, float badspotnum)
13 local entity spot, player;
25 if (vlen(player.origin - spot.origin) < 100)
27 player = player.chain;
31 if (spawn_goodspots >= badspotnum)
33 spawn_badspots = spawn_badspots + 1;
37 if (spawn_goodspots >= goodspotnum)
39 spawn_goodspots = spawn_goodspots + 1;
41 spot = find(spot, classname, "info_player_deathmatch");
46 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
48 local entity best, spot, player;
49 local float bestrating, rating;
51 bestrating = -1000000;
60 rating = min(rating, vlen(player.origin - spot.origin));
61 player = player.chain;
63 rating = rating + random() * 16;
64 if (bestrating < rating)
69 spot = find(spot, classname, "info_player_deathmatch");
78 Finds a point to respawn
81 entity SelectSpawnPoint (void)
83 local entity spot, firstspot, playerlist;
85 spot = find (world, classname, "testplayerstart");
89 playerlist = findchain(classname, "player");
90 firstspot = find(world, classname, "info_player_deathmatch");
91 Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, 1000000);
92 // first check if there are ANY good spots
93 if (spawn_goodspots > 0)
95 // good spots exist, there is 50/50 chance of choosing a random good
96 // spot or the furthest spot
97 // (this means that roughly every other spawn will be furthest, so you
98 // usually won't get fragged at spawn twice in a row)
100 spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, min(floor(random() * spawn_goodspots), spawn_goodspots - 1), 1000000);
102 spot = Spawn_FurthestPoint(firstspot, playerlist);
106 // no good spots exist, pick a random bad spot
107 spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, min(floor(random() * spawn_badspots), spawn_badspots - 1));
111 error ("PutClientInServer: no info_player_start on level");
120 Checks if the argument string can be a valid playermodel.
121 Returns a valid one in doubt.
124 string CheckPlayerModel(string plyermodel) {
125 if( substring(plyermodel,0,14) != "models/player/") plyermodel = "models/player/marine.zym";
127 /* Possible Fixme: Check if server can open the model?
128 This would kill custom models, however. */
138 Called when a client spawns in the server
141 void PutClientInServer (void)
145 spot = SelectSpawnPoint ();
147 self.classname = "player";
148 self.iscreature = TRUE;
149 self.movetype = MOVETYPE_WALK;
150 self.solid = SOLID_SLIDEBOX;
151 self.flags = FL_CLIENT;
152 self.takedamage = DAMAGE_AIM;
154 self.health = cvar("g_balance_health_start");
155 self.armorvalue = cvar("g_balance_armor_start");
156 self.pauserotarmor_finished = time + 10;
157 self.pauserothealth_finished = time + 10;
158 self.pauseregen_finished = 0;
159 self.damageforcescale = 2;
168 self.pain_finished = 0;
169 self.strength_finished = 0;
170 self.invincible_finished = 0;
171 //self.speed_finished = 0;
172 //self.slowmo_finished = 0;
173 // players have no think function
174 self.think = SUB_Null;
177 self.deadflag = DEAD_NO;
179 self.angles = spot.angles;
180 self.fixangle = TRUE; // turn this way immediately
181 self.velocity = '0 0 0';
182 self.avelocity = '0 0 0';
183 self.punchangle = '0 0 0';
184 self.punchvector = '0 0 0';
185 self.oldvelocity = self.velocity;
190 self.playermodel = CheckPlayerModel(self.playermodel);
192 precache_model (self.playermodel);
193 setmodel (self, self.playermodel);
194 self.skin = stof(self.playerskin);
196 self.view_ofs = PL_VIEW_OFS;
197 setsize (self, PL_MIN, PL_MAX);
198 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
199 // don't reset back to last position, even if new position is stuck in solid
200 self.oldorigin = self.origin;
202 // self.items = IT_LASER | IT_UZI| IT_SHOTGUN | IT_GRENADE_LAUNCHER | IT_ELECTRO | IT_CRYLINK | IT_NEX | IT_HAGAR | IT_ROCKET_LAUNCHER;
203 // self.weapon = IT_UZI;
205 if (cvar("g_instagib") == 1)
208 self.switchweapon = WEP_NEX;
209 self.ammo_shells = 0;
211 self.ammo_rockets = 0;
212 self.ammo_cells = 999;
214 else if (cvar("g_rocketarena") == 1)
216 self.items = IT_ROCKET_LAUNCHER;
217 self.switchweapon = WEP_ROCKET_LAUNCHER;
218 self.ammo_shells = 0;
220 self.ammo_rockets = 999;
225 self.items = IT_LASER | IT_SHOTGUN;
226 self.switchweapon = WEP_SHOTGUN;
227 self.ammo_shells = 50;
229 self.ammo_rockets = 0;
233 if (cvar("g_fullbrightplayers") == 1)
234 self.effects = EF_FULLBRIGHT;
236 self.event_damage = PlayerDamage;
238 self.statdraintime = time + 5;
239 self.button0 = self.button1 = self.button2 = self.button3 = 0;
245 CL_SpawnWeaponentity();
247 //stuffcmd(self, "chase_active 0");
255 void SetNewParms (void)
265 void SetChangeParms (void)
274 Called when a client types 'kill' in the console
277 void ClientKill (void)
279 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
286 Called when a client connects to the server
289 void ClientConnect (void)
291 bprint ("^4",self.netname);
292 bprint (" connected\n");
293 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
294 // send prediction settings to the client
295 stuffcmd(self, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
296 stuffcmd(self, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
297 stuffcmd(self, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
298 stuffcmd(self, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
299 stuffcmd(self, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
300 stuffcmd(self, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
301 stuffcmd(self, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
302 stuffcmd(self, strcat("cl_movement_edgefriction 0\n"));
309 Called when a client disconnects from the server
312 .entity chatbubbleentity;
313 void ClientDisconnect (void)
315 bprint ("^4",self.netname);
316 bprint (" disconnected\n");
318 if (self.chatbubbleentity)
320 remove (self.chatbubbleentity);
321 self.chatbubbleentity = world;
326 void() ChatBubbleThink =
328 self.nextthink = time;
329 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
334 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
335 if (self.owner.buttonchat && !self.owner.deadflag)
336 self.model = self.mdl;
341 void() UpdateChatBubble =
343 if (!self.modelindex)
345 // spawn a chatbubble entity if needed
346 if (!self.chatbubbleentity)
348 self.chatbubbleentity = spawn();
349 self.chatbubbleentity.owner = self;
350 self.chatbubbleentity.exteriormodeltoclient = self;
351 self.chatbubbleentity.think = ChatBubbleThink;
352 self.chatbubbleentity.nextthink = time;
353 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
354 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
355 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
356 self.chatbubbleentity.model = "";
360 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
361 // added to the model skins
362 void() UpdateColorModHack =
365 c = self.clientcolors & 15;
366 // LordHavoc: only bothering to support white, green, red, yellow, blue
367 if (teamplay == 0) self.colormod = '0 0 0';
368 else if (c == 0) self.colormod = '1.00 1.00 1.00';
369 else if (c == 3) self.colormod = '0.10 1.73 0.10';
370 else if (c == 4) self.colormod = '1.73 0.10 0.10';
371 else if (c == 12) self.colormod = '1.22 1.22 0.10';
372 else if (c == 13) self.colormod = '0.10 0.10 1.73';
373 else self.colormod = '1 1 1';
380 When you press the jump key
383 void PlayerJump (void)
385 if (self.waterlevel >= 2)
387 if (self.watertype == CONTENT_WATER)
388 self.velocity_z = 200;
389 else if (self.watertype == CONTENT_SLIME)
390 self.velocity_z = 80;
392 self.velocity_z = 50;
398 if (!(self.flags & FL_ONGROUND))
401 if (!(self.flags & FL_JUMPRELEASED))
404 self.velocity_z = self.velocity_z + cvar("g_balance_jumpheight");
405 self.oldvelocity_z = self.velocity_z;
407 self.flags = self.flags - FL_ONGROUND;
408 self.flags = self.flags - FL_JUMPRELEASED;
411 void() CheckWaterJump =
413 local vector start, end;
415 // check for a jump-out-of-water
416 makevectors (self.angles);
418 start_z = start_z + 8;
420 normalize(v_forward);
421 end = start + v_forward*24;
422 traceline (start, end, TRUE, self);
423 if (trace_fraction < 1)
425 start_z = start_z + self.maxs_z - 8;
426 end = start + v_forward*24;
427 self.movedir = trace_plane_normal * -50;
428 traceline (start, end, TRUE, self);
429 if (trace_fraction == 1)
430 { // open at eye level
431 self.flags = self.flags | FL_WATERJUMP;
432 self.velocity_z = 225;
433 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
434 self.teleport_time = time + 2; // safety net
447 void player_powerups (void)
449 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
450 if (self.items & IT_STRENGTH)
452 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
453 if (time > self.strength_finished)
455 self.items = self.items - (self.items & IT_STRENGTH);
456 sprint(self, "^3Strength has worn off\n");
461 if (time < self.strength_finished)
463 self.items = self.items | IT_STRENGTH;
464 sprint(self, "^3Strength infuses your weapons with devestating power\n");
467 if (self.items & IT_INVINCIBLE)
469 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
470 if (time > self.invincible_finished)
472 self.items = self.items - (self.items & IT_INVINCIBLE);
473 sprint(self, "^3Shield has worn off\n");
478 if (time < self.invincible_finished)
480 self.items = self.items | IT_INVINCIBLE;
481 sprint(self, "^3Shield surrounds you\n");
486 void player_regen (void)
490 maxh = cvar("g_balance_health_stable");
491 maxa = cvar("g_balance_armor_stable");
492 if (time > self.pauserothealth_finished)
493 if (self.health > maxh)
494 self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
495 if (time > self.pauserotarmor_finished)
496 if (self.armorvalue > maxa)
497 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
498 if (time > self.pauseregen_finished)
500 if (self.health < maxh)
501 self.health = bound(0, self.health + (maxh- self.health) * cvar("g_balance_health_regen") * frametime, 1000);
502 if (self.armorvalue < maxa)
503 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_regen") * frametime, 1000);
511 Called every frame for each client before the physics are run
514 void PlayerPreThink (void)
522 if (intermission_running)
524 IntermissionThink (); // otherwise a button could be missed between
525 return; // the think tics
528 if (self.deadflag != DEAD_NO)
532 if (self.deadflag == DEAD_DYING)
534 if (time > self.dead_time)
535 self.deadflag = DEAD_DEAD;
537 else if (self.deadflag == DEAD_DEAD)
539 if (!self.button0 && !self.button2 && !self.button3)
540 self.deadflag = DEAD_RESPAWNABLE;
542 else if (self.deadflag == DEAD_RESPAWNABLE)
544 if (self.button0 || self.button2 || self.button3 || self.button4)
555 self.view_ofs = PL_CROUCH_VIEW_OFS;
556 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
563 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
564 if (!trace_startsolid)
567 self.view_ofs = PL_VIEW_OFS;
568 setsize (self, PL_MIN, PL_MAX);
573 if (self.playermodel != self.model)
575 self.playermodel = CheckPlayerModel(self.playermodel);
578 precache_model (self.playermodel);
579 setmodel (self, self.playermodel);
580 setsize (self, m1, m2);
583 // Savage: Check for nameless players
584 if (strlen(self.netname) < 1) {
585 self.netname = "Player";
586 stuffcmd(self, "name Player\n");
589 if (self.skin != stof(self.playerskin))
590 self.skin = stof(self.playerskin);
594 if (self.button4 || (self.weapon == WEP_NEX && self.button3))
596 if (self.viewzoom > 0.4)
597 self.viewzoom = max (0.4, self.viewzoom - frametime * 2);
599 else if (self.viewzoom < 1.0)
600 self.viewzoom = min (1.0, self.viewzoom + frametime);
606 self.flags = self.flags | FL_JUMPRELEASED;
613 //self.angles_y=self.v_angle_y + 90; // temp
615 if (self.waterlevel == 2)
618 //if (TetrisPreFrame()) return;
625 Called every frame for each client after the physics are run
628 void PlayerPostThink (void)
632 UpdateColorModHack();
633 if (self.deadflag == DEAD_NO)
636 if (intermission_running)
637 return; // intermission or finale
639 //if (TetrisPostFrame()) return;