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 (float anypoint)
83 local entity spot, firstspot, playerlist;
86 spot = find (world, classname, "testplayerstart");
90 spotname = "info_player_deathmatch";
92 if(!anypoint && cvar("g_ctf") )
94 if(self.team == 5)//4)
95 spotname = "info_player_team1";
96 if(self.team == 14)//13)
97 spotname = "info_player_team2";
98 if(self.team == 4)//3)
99 spotname = "info_player_team3";
100 if(self.team == 13)//12)
101 spotname = "info_player_team4";
104 playerlist = findchain(classname, "player");
105 firstspot = find(world, classname, spotname);
106 Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, 1000000);
107 // first check if there are ANY good spots
108 if (spawn_goodspots > 0)
110 // good spots exist, there is 50/50 chance of choosing a random good
111 // spot or the furthest spot
112 // (this means that roughly every other spawn will be furthest, so you
113 // usually won't get fragged at spawn twice in a row)
115 spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, min(floor(random() * spawn_goodspots), spawn_goodspots - 1), 1000000);
117 spot = Spawn_FurthestPoint(firstspot, playerlist);
121 // no good spots exist, pick a random bad spot
122 spot = Spawn_ClassifyPoints(firstspot, playerlist, 100, 1000000, min(floor(random() * spawn_badspots), spawn_badspots - 1));
128 error ("PutClientInServer: no start points on level");
129 else // try again with deathmatch spots
130 spot = SelectSpawnPoint(TRUE);
140 Checks if the argument string can be a valid playermodel.
141 Returns a valid one in doubt.
144 string CheckPlayerModel(string plyermodel) {
145 if( substring(plyermodel,0,14) != "models/player/") plyermodel = "models/player/marine.zym";
147 /* Possible Fixme: Check if server can open the model?
148 This would kill custom models, however. */
158 Called when a client spawns in the server
161 void PutClientInServer (void)
165 spot = SelectSpawnPoint (FALSE);
167 RemoveGrapplingHook(self); // Wazat's Grappling Hook
169 self.classname = "player";
170 self.iscreature = TRUE;
171 self.movetype = MOVETYPE_WALK;
172 self.solid = SOLID_SLIDEBOX;
173 self.flags = FL_CLIENT;
174 self.takedamage = DAMAGE_AIM;
176 self.health = cvar("g_balance_health_start");
177 self.armorvalue = cvar("g_balance_armor_start");
178 self.pauserotarmor_finished = time + 10;
179 self.pauserothealth_finished = time + 10;
180 self.pauseregen_finished = 0;
181 self.damageforcescale = 2;
190 self.pain_finished = 0;
191 self.strength_finished = 0;
192 self.invincible_finished = 0;
194 //self.speed_finished = 0;
195 //self.slowmo_finished = 0;
196 self.vote_finished = 0;
197 // players have no think function
198 self.think = SUB_Null;
205 self.deadflag = DEAD_NO;
207 self.angles = spot.angles;
209 self.angles_z = 0; // never spawn tilted even if the spot says to
210 self.fixangle = TRUE; // turn this way immediately
211 self.velocity = '0 0 0';
212 self.avelocity = '0 0 0';
213 self.punchangle = '0 0 0';
214 self.punchvector = '0 0 0';
215 self.oldvelocity = self.velocity;
220 self.playermodel = CheckPlayerModel(self.playermodel);
222 precache_model (self.playermodel);
223 setmodel (self, self.playermodel);
224 self.skin = stof(self.playerskin);
226 self.view_ofs = PL_VIEW_OFS;
227 setsize (self, PL_MIN, PL_MAX);
228 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
229 // don't reset back to last position, even if new position is stuck in solid
230 self.oldorigin = self.origin;
232 if (cvar("g_use_ammunition")) {
233 self.ammo_shells = cvar("g_start_ammo_shells");
234 self.ammo_nails = cvar("g_start_ammo_nails");
235 self.ammo_rockets = cvar("g_start_ammo_rockets");
236 self.ammo_cells = cvar("g_start_ammo_cells");
238 self.ammo_shells = 999;
239 self.ammo_nails = 999;
240 self.ammo_rockets = 999;
241 self.ammo_cells = 999;
245 if (cvar("g_start_weapon_laser"))
247 self.items = self.items | IT_LASER;
248 self.switchweapon = WEP_LASER;
250 if (cvar("g_start_weapon_shotgun"))
252 self.items = self.items | IT_SHOTGUN;
253 self.switchweapon = WEP_SHOTGUN;
255 if (cvar("g_start_weapon_uzi"))
257 self.items = self.items | IT_UZI;
258 self.switchweapon = WEP_UZI;
260 if (cvar("g_start_weapon_grenadelauncher"))
262 self.items = self.items | IT_GRENADE_LAUNCHER;
263 self.switchweapon = WEP_GRENADE_LAUNCHER;
265 if (cvar("g_start_weapon_electro"))
267 self.items = self.items | IT_ELECTRO;
268 self.switchweapon = WEP_ELECTRO;
270 if (cvar("g_start_weapon_crylink"))
272 self.items = self.items | IT_CRYLINK;
273 self.switchweapon = WEP_CRYLINK;
275 if (cvar("g_start_weapon_nex"))
277 self.items = self.items | IT_NEX;
278 self.switchweapon = WEP_NEX;
280 if (cvar("g_start_weapon_hagar"))
282 self.items = self.items | IT_HAGAR;
283 self.switchweapon = WEP_HAGAR;
285 if (cvar("g_start_weapon_rocketlauncher"))
287 self.items = self.items | IT_ROCKET_LAUNCHER;
288 self.switchweapon = WEP_ROCKET_LAUNCHER;
291 self.event_damage = PlayerDamage;
293 self.statdraintime = time + 5;
294 self.button0 = self.button1 = self.button2 = self.button3 = 0;
300 CL_SpawnWeaponentity();
302 //stuffcmd(self, "chase_active 0");
310 void SetNewParms (void)
320 void SetChangeParms (void)
329 Called when a client types 'kill' in the console
332 void ClientKill (void)
334 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
341 Called when a client connects to the server
344 string ColoredTeamName(float t);
345 //void dom_player_join_team(entity pl);
346 void ClientConnect (void)
348 self.classname = "player_joining";
350 //if(cvar("g_domination"))
351 // dom_player_join_team(self);
353 JoinBestTeam(self, FALSE);
355 self.classname = "player";
359 bprint ("^4",self.netname);
360 bprint (" connected");
362 if(cvar("g_domination") || cvar("g_ctf"))
364 bprint(" and joined the ");
365 bprint(ColoredTeamName(self.team));
370 self.welcomemessage_time = time + cvar("welcome_message_time");
371 self.welcomemessage_time2 = 0;
374 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
375 // send prediction settings to the client
376 stuffcmd(self, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
377 stuffcmd(self, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
378 stuffcmd(self, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
379 stuffcmd(self, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
380 stuffcmd(self, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
381 stuffcmd(self, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
382 stuffcmd(self, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
383 stuffcmd(self, strcat("cl_movement_edgefriction 0\n"));
385 // Wazat's grappling hook
386 SetGrappleHookBindings();
393 Called when a client disconnects from the server
396 .entity chatbubbleentity;
397 void ClientDisconnect (void)
399 bprint ("^4",self.netname);
400 bprint (" disconnected\n");
402 if (self.chatbubbleentity)
404 remove (self.chatbubbleentity);
405 self.chatbubbleentity = world;
411 void() ChatBubbleThink =
413 self.nextthink = time;
414 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
419 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
420 if (self.owner.buttonchat && !self.owner.deadflag)
421 self.model = self.mdl;
426 void() UpdateChatBubble =
428 if (!self.modelindex)
430 // spawn a chatbubble entity if needed
431 if (!self.chatbubbleentity)
433 self.chatbubbleentity = spawn();
434 self.chatbubbleentity.owner = self;
435 self.chatbubbleentity.exteriormodeltoclient = self;
436 self.chatbubbleentity.think = ChatBubbleThink;
437 self.chatbubbleentity.nextthink = time;
438 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
439 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
440 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
441 self.chatbubbleentity.model = "";
445 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
446 // added to the model skins
447 void() UpdateColorModHack =
450 c = self.clientcolors & 15;
451 // LordHavoc: only bothering to support white, green, red, yellow, blue
452 if (teamplay == 0) self.colormod = '0 0 0';
453 else if (c == 0) self.colormod = '1.00 1.00 1.00';
454 else if (c == 3) self.colormod = '0.10 1.73 0.10';
455 else if (c == 4) self.colormod = '1.73 0.10 0.10';
456 else if (c == 12) self.colormod = '1.22 1.22 0.10';
457 else if (c == 13) self.colormod = '0.10 0.10 1.73';
458 else self.colormod = '1 1 1';
465 When you press the jump key
468 void PlayerJump (void)
472 mjumpheight = cvar("g_balance_jumpheight");
473 if (self.waterlevel >= 2)
475 if (self.watertype == CONTENT_WATER)
476 self.velocity_z = 200;
477 else if (self.watertype == CONTENT_SLIME)
478 self.velocity_z = 80;
480 self.velocity_z = 50;
486 if (!(self.flags & FL_ONGROUND))
489 if (!(self.flags & FL_JUMPRELEASED))
492 if(cvar("g_runematch"))
494 if(self.runes & RUNE_SPEED)
496 if(self.runes & CURSE_SLOW)
497 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
499 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
501 else if(self.runes & CURSE_SLOW)
503 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
507 self.velocity_z = self.velocity_z + mjumpheight;
508 self.oldvelocity_z = self.velocity_z;
510 self.flags = self.flags - FL_ONGROUND;
511 self.flags = self.flags - FL_JUMPRELEASED;
514 void() CheckWaterJump =
516 local vector start, end;
518 // check for a jump-out-of-water
519 makevectors (self.angles);
521 start_z = start_z + 8;
523 normalize(v_forward);
524 end = start + v_forward*24;
525 traceline (start, end, TRUE, self);
526 if (trace_fraction < 1)
528 start_z = start_z + self.maxs_z - 8;
529 end = start + v_forward*24;
530 self.movedir = trace_plane_normal * -50;
531 traceline (start, end, TRUE, self);
532 if (trace_fraction == 1)
533 { // open at eye level
534 self.flags = self.flags | FL_WATERJUMP;
535 self.velocity_z = 225;
536 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
537 self.teleport_time = time + 2; // safety net
550 void player_powerups (void)
552 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
553 if (self.items & IT_STRENGTH)
555 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
556 if (time > self.strength_finished)
558 self.items = self.items - (self.items & IT_STRENGTH);
559 sprint(self, "^3Strength has worn off\n");
564 if (time < self.strength_finished)
566 self.items = self.items | IT_STRENGTH;
567 sprint(self, "^3Strength infuses your weapons with devestating power\n");
570 if (self.items & IT_INVINCIBLE)
572 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
573 if (time > self.invincible_finished)
575 self.items = self.items - (self.items & IT_INVINCIBLE);
576 sprint(self, "^3Shield has worn off\n");
581 if (time < self.invincible_finished)
583 self.items = self.items | IT_INVINCIBLE;
584 sprint(self, "^3Shield surrounds you\n");
588 if (cvar("g_fullbrightplayers"))
589 self.effects = EF_FULLBRIGHT;
593 void player_regen (void)
595 float maxh, maxa, max_mod, regen_mod, rot_mod;
596 maxh = cvar("g_balance_health_stable");
597 maxa = cvar("g_balance_armor_stable");
599 if(cvar("g_runematch"))
601 max_mod = regen_mod = rot_mod = 1;
602 if (self.runes & RUNE_REGEN)
604 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
606 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
607 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
611 regen_mod = cvar("g_balance_rune_regen_regenrate");
612 max_mod = cvar("g_balance_rune_regen_hpmod");
615 else if (self.runes & CURSE_VENOM)
617 max_mod = cvar("g_balance_curse_venom_hpmod");
618 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
619 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
621 rot_mod = cvar("g_balance_curse_venom_rotrate");
622 //if (!self.runes & RUNE_REGEN)
623 // rot_mod = cvar("g_balance_curse_venom_rotrate");
625 maxh = maxh * max_mod;
626 //maxa = maxa * max_mod;
628 if (time > self.pauserotarmor_finished)
630 if (self.armorvalue > maxa)
631 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
633 if (time > self.pauserothealth_finished)
635 if (self.health > maxh)
636 self.health = bound(0, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime, 1000);
638 if (time > self.pauseregen_finished)
640 if (self.health < maxh)
641 self.health = bound(0, self.health + (maxh- self.health) * regen_mod*cvar("g_balance_health_regen") * frametime, 1000);
642 if (self.armorvalue < maxa)
643 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_regen") * frametime, 1000);
648 if (time > self.pauserothealth_finished)
649 if (self.health > maxh)
650 self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
651 if (time > self.pauserotarmor_finished)
652 if (self.armorvalue > maxa)
653 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
654 if (time > self.pauseregen_finished)
656 if (self.health < maxh)
657 self.health = bound(0, self.health + (maxh- self.health) * cvar("g_balance_health_regen") * frametime, 1000);
658 if (self.armorvalue < maxa)
659 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_regen") * frametime, 1000);
668 Called every frame for each client before the physics are run
671 void PlayerPreThink (void)
677 // if(self.netname == "Wazat")
678 // bprint(strcat(self.classname, "\n"));
682 if (intermission_running)
684 IntermissionThink (); // otherwise a button could be missed between
685 return; // the think tics
688 if (self.deadflag != DEAD_NO)
692 if (self.deadflag == DEAD_DYING)
694 if (time > self.dead_time)
695 self.deadflag = DEAD_DEAD;
697 else if (self.deadflag == DEAD_DEAD)
699 if (!self.button0 && !self.button2 && !self.button3)
700 self.deadflag = DEAD_RESPAWNABLE;
702 else if (self.deadflag == DEAD_RESPAWNABLE)
704 if (self.button0 || self.button2 || self.button3 || self.button4)
715 self.view_ofs = PL_CROUCH_VIEW_OFS;
716 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
723 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
724 if (!trace_startsolid)
727 self.view_ofs = PL_VIEW_OFS;
728 setsize (self, PL_MIN, PL_MAX);
733 if (self.playermodel != self.model)
735 self.playermodel = CheckPlayerModel(self.playermodel);
738 precache_model (self.playermodel);
739 setmodel (self, self.playermodel);
740 setsize (self, m1, m2);
743 // Savage: Check for nameless players
744 if (strlen(self.netname) < 1) {
745 self.netname = "Player";
746 stuffcmd(self, "name Player\n");
749 if (self.skin != stof(self.playerskin))
750 self.skin = stof(self.playerskin);
752 GrapplingHookFrame();
756 if (self.button4 || (self.weapon == WEP_NEX && self.button3))
758 if (self.viewzoom > 0.4)
759 self.viewzoom = max (0.4, self.viewzoom - frametime * 2);
761 else if (self.viewzoom < 1.0)
762 self.viewzoom = min (1.0, self.viewzoom + frametime);
768 self.flags = self.flags | FL_JUMPRELEASED;
770 if (self.vote_finished > 0 // this player has called a vote
771 && time > self.vote_finished) // time is up
780 //self.angles_y=self.v_angle_y + 90; // temp
782 if (self.waterlevel == 2)
785 //if (TetrisPreFrame()) return;
792 Called every frame for each client after the physics are run
795 void PlayerPostThink (void)
799 UpdateColorModHack();
800 if (self.deadflag == DEAD_NO)
803 if (intermission_running)
804 return; // intermission or finale
806 PrintWelcomeMessage(self);
807 //if (TetrisPostFrame()) return;