1 void info_player_start (void)
3 info_player_deathmatch();
6 void info_player_deathmatch (void)
8 self.classname = "info_player_deathmatch";
14 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
16 local entity spot, player, nextspot, previousspot, newfirstspot;
25 nextspot = spot.chain;
26 // count team mismatches as bad spots
28 local float spotactive;
31 // filter out spots for assault
32 if(spot.target != "") {
34 ent = find(world, targetname, spot.target);
36 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
38 ent = find(ent, targetname, spot.target);
42 if (spot.team == teamcheck && spotactive > 0)
49 if (vlen(player.origin - spot.origin) < mindist)
51 player = player.chain;
57 previousspot.chain = spot;
64 spawn_allgood = FALSE;
68 // if we couldn't find ANY good points, return the original list
70 newfirstspot = firstspot;
74 entity Spawn_RandomPoint(entity firstspot)
78 // count number of spots
83 numspots = numspots + 1;
87 numspots = numspots * random();
89 while (spot.chain && numspots >= 1)
91 numspots = numspots - 1;
97 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
99 local entity best, spot, player;
100 local float bestrating, rating;
102 bestrating = -1000000;
111 rating = min(rating, vlen(player.origin - spot.origin));
112 player = player.chain;
114 rating = rating + random() * 16;
115 if (bestrating < rating)
129 Finds a point to respawn
132 entity SelectSpawnPoint (float anypoint)
134 local float teamcheck;
135 local entity spot, firstspot, playerlist;
137 spot = find (world, classname, "testplayerstart");
143 if(!anypoint && cvar("g_ctf") )
144 teamcheck = self.team;
146 // get the list of players
147 playerlist = findchain(classname, "player");
148 // get the entire list of spots
149 firstspot = findchain(classname, "info_player_deathmatch");
150 // filter out the bad ones
151 // (note this returns the original list if none survived)
152 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
154 // there is 50/50 chance of choosing a random spot or the furthest spot
155 // (this means that roughly every other spawn will be furthest, so you
156 // usually won't get fragged at spawn twice in a row)
157 if (arena_roundbased)
159 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
160 spot = Spawn_RandomPoint(firstspot);
162 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
163 spot = Spawn_RandomPoint(firstspot);
165 spot = Spawn_FurthestPoint(firstspot, playerlist);
169 if(cvar("spawn_debug"))
172 error ("PutClientInServer: no start points on level");
182 Checks if the argument string can be a valid playermodel.
183 Returns a valid one in doubt.
186 string FallbackPlayerModel = "models/player/marine.zym";
187 string CheckPlayerModel(string plyermodel) {
188 if(strlen(plyermodel) < 4)
189 return FallbackPlayerModel;
190 if( substring(plyermodel,0,14) != "models/player/")
191 return FallbackPlayerModel;
192 else if(cvar("sv_servermodelsonly"))
194 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
195 return FallbackPlayerModel;
196 if(!fexists(plyermodel))
197 return FallbackPlayerModel;
204 Client_customizeentityforclient
209 float Client_customizeentityforclient()
211 #ifdef ALLOW_VARIABLE_LOD
213 // other: the player viewing me
217 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
220 if(other.cvar_cl_playerdetailreduction <= 0)
222 if(other.cvar_cl_playerdetailreduction <= -2)
223 self.modelindex = self.modelindex_lod2;
224 else if(other.cvar_cl_playerdetailreduction <= -1)
225 self.modelindex = self.modelindex_lod1;
227 self.modelindex = self.modelindex_lod0;
231 distance = vlen(self.origin - other.origin);
232 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
234 self.modelindex = self.modelindex_lod2;
236 self.modelindex = self.modelindex_lod1;
238 self.modelindex = self.modelindex_lod0;
245 void setmodel_lod(entity e, string modelname)
247 #ifdef ALLOW_VARIABLE_LOD
250 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1.zym");
254 setmodel(e, s); // players have high precision
255 self.modelindex_lod1 = self.modelindex;
258 self.modelindex_lod1 = -1;
260 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2.zym");
264 setmodel(e, s); // players have high precision
265 self.modelindex_lod2 = self.modelindex;
268 self.modelindex_lod2 = -1;
270 precache_model(modelname);
271 setmodel(e, modelname); // players have high precision
272 self.modelindex_lod0 = self.modelindex;
274 if(self.modelindex_lod1 < 0)
275 self.modelindex_lod1 = self.modelindex;
277 if(self.modelindex_lod2 < 0)
278 self.modelindex_lod2 = self.modelindex;
280 precache_model(modelname);
281 setmodel(e, modelname); // players have high precision
289 putting a client as observer in the server
292 void PutObserverInServer (void)
295 spot = SelectSpawnPoint (FALSE);
296 RemoveGrapplingHook(self); // Wazat's Grappling Hook
298 if(clienttype(self) == CLIENTTYPE_REAL)
301 WriteByte(MSG_ONE, SVC_SETVIEW);
302 WriteEntity(MSG_ONE, self);
306 kh_Key_DropAll(self, TRUE);
309 DropFlag(self.flagcarried);
311 WaypointSprite_PlayerDead();
313 DistributeFragsAmongTeam(self, self.team, 1);
315 if(self.frags <= 0 && self.frags > -666 && cvar("g_lms") && self.killcount != -666)
316 bprint ("^4", self.netname, "^4 has no more lives left\n");
317 else if(self.killcount != -666)
318 bprint ("^4", self.netname, "^4 is spectating now\n");
320 self.classname = "observer";
322 self.takedamage = DAMAGE_NO;
323 self.solid = SOLID_NOT;
324 self.movetype = MOVETYPE_NOCLIP;
325 self.flags = FL_CLIENT | FL_NOTARGET;
326 self.armorvalue = 666;
328 self.armorvalue = cvar("g_balance_armor_start");
329 self.pauserotarmor_finished = 0;
330 self.pauserothealth_finished = 0;
331 self.pauseregen_finished = 0;
332 self.damageforcescale = 0;
342 self.pain_finished = 0;
343 self.strength_finished = 0;
344 self.invincible_finished = 0;
346 self.think = SUB_Null;
350 self.deadflag = DEAD_NO;
351 self.angles = spot.angles;
353 self.fixangle = TRUE;
356 self.view_ofs = PL_VIEW_OFS;
357 setorigin (self, spot.origin);
358 setsize (self, '0 0 0', '0 0 0');
359 self.oldorigin = self.origin;
364 self.weaponmodel = "";
365 self.weaponentity = world;
366 self.killcount = -666;
367 self.velocity = '0 0 0';
368 self.avelocity = '0 0 0';
369 self.punchangle = '0 0 0';
370 self.punchvector = '0 0 0';
371 self.oldvelocity = self.velocity;
372 self.customizeentityforclient = Client_customizeentityforclient;
378 Spawnqueue_Insert(self);
382 Spawnqueue_Unmark(self);
383 Spawnqueue_Remove(self);
386 else if(!cvar("g_lms"))
395 Called when a client spawns in the server
398 void PutClientInServer (void)
400 if(clienttype(self) == CLIENTTYPE_BOT)
402 self.classname = "player";
404 else if(clienttype(self) == CLIENTTYPE_REAL)
407 WriteByte(MSG_ONE, SVC_SETVIEW);
408 WriteEntity(MSG_ONE, self);
411 // player is dead and becomes observer
412 if(cvar("g_lms") && self.frags < 1)
413 self.classname = "observer";
417 self.classname = "observer";
419 if(self.classname == "player") {
422 spot = SelectSpawnPoint (FALSE);
424 RemoveGrapplingHook(self); // Wazat's Grappling Hook
426 self.classname = "player";
427 self.iscreature = TRUE;
428 self.movetype = MOVETYPE_WALK;
429 self.solid = SOLID_SLIDEBOX;
430 self.flags = FL_CLIENT;
431 self.takedamage = DAMAGE_AIM;
433 self.air_finished = time + 12;
436 self.ammo_shells = start_ammo_shells;
437 self.ammo_nails = start_ammo_nails;
438 self.ammo_rockets = start_ammo_rockets;
439 self.ammo_cells = start_ammo_cells;
440 self.health = start_health;
441 self.armorvalue = start_armorvalue;
442 self.items = start_items;
443 self.switchweapon = start_switchweapon;
445 self.jump_interval = time;
447 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
448 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
449 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
450 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
451 self.damageforcescale = 2;
460 self.pain_finished = 0;
461 self.strength_finished = 0;
462 self.invincible_finished = 0;
464 //self.speed_finished = 0;
465 //self.slowmo_finished = 0;
466 // players have no think function
467 self.think = SUB_Null;
473 self.deadflag = DEAD_NO;
475 self.angles = spot.angles;
477 self.angles_z = 0; // never spawn tilted even if the spot says to
478 self.fixangle = TRUE; // turn this way immediately
479 self.velocity = '0 0 0';
480 self.avelocity = '0 0 0';
481 self.punchangle = '0 0 0';
482 self.punchvector = '0 0 0';
483 self.oldvelocity = self.velocity;
488 self.customizeentityforclient = Client_customizeentityforclient;
490 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
491 local string defaultmodel;
492 defaultmodel = cvar_string("sv_defaultplayermodel");
493 setmodel_lod (self, defaultmodel);
494 self.skin = stof(cvar_string("sv_defaultplayerskin"));
496 self.playermodel = CheckPlayerModel(self.playermodel);
497 setmodel_lod (self, self.playermodel);
499 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
501 self.skin = stof(self.playerskin);
505 self.view_ofs = PL_VIEW_OFS;
506 setsize (self, PL_MIN, PL_MAX);
507 self.spawnorigin = spot.origin;
508 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
509 // don't reset back to last position, even if new position is stuck in solid
510 self.oldorigin = self.origin;
514 Spawnqueue_Remove(self);
515 Spawnqueue_Mark(self);
518 self.event_damage = PlayerDamage;
520 self.bot_attack = TRUE;
522 self.statdraintime = time + 5;
523 self.button0 = self.button1 = self.button2 = self.button3 = 0;
525 if(self.killcount == -666) {
532 self.cnt = WEP_LASER;
533 self.nixnex_lastchange_id = -1;
535 CL_SpawnWeaponentity();
536 self.alpha = default_player_alpha;
537 self.exteriorweaponentity.alpha = default_weapon_alpha;
539 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
540 self.lms_traveled_distance = 0;
542 if(cvar("spawn_debug"))
544 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
545 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
548 //stuffcmd(self, "chase_active 0");
549 //stuffcmd(self, "set viewsize $tmpviewsize \n");
551 if (cvar("g_spawnsound"))
552 sound (self, CHAN_AUTO, "misc/teleport.wav", 1, ATTN_NORM);
554 } else if(self.classname == "observer") {
555 PutObserverInServer ();
564 void SetNewParms (void)
574 void SetChangeParms (void)
583 Called when a client types 'kill' in the console
586 void ClientKill (void)
588 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
591 void FixClientCvars(entity e)
593 // send prediction settings to the client
594 stuffcmd(e, "\nin_bindmap 0 0\n");
595 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
596 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
597 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
598 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
599 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
600 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
601 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
602 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
603 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
604 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
605 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
606 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
607 stuffcmd(e, "cl_movement_edgefriction 1\n");
614 Called when a client connects to the server
617 string ColoredTeamName(float t);
618 //void dom_player_join_team(entity pl);
619 void ClientConnect (void)
623 self.classname = "player_joining";
624 self.flags = self.flags | FL_CLIENT;
625 self.version_nagtime = time + 10 + random() * 10;
629 dprint("BUG player count is lower than zero, this cannot happen!\n");
635 //if(cvar("g_domination"))
636 // dom_player_join_team(self);
638 //JoinBestTeam(self, FALSE);
640 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
641 self.classname = "observer";
643 self.classname = "player";
644 campaign_bots_may_start = 1;
647 self.playerid = (playerid_last = playerid_last + 1);
648 if(cvar("sv_eventlog"))
650 if(clienttype(self) == CLIENTTYPE_REAL)
654 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
655 s = strcat(":team:", ftos(self.playerid), ":");
656 s = strcat(s, ftos(self.team));
657 GameLogEcho(s, FALSE);
660 //stuffcmd(self, "set tmpviewsize $viewsize \n");
662 bprint ("^4",self.netname);
663 bprint ("^4 connected");
665 if(cvar("g_domination") || cvar("g_ctf"))
667 bprint(" and joined the ");
668 bprint(ColoredTeamName(self.team));
673 self.welcomemessage_time = 0;
675 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
676 // TODO: is this being used for anything else than cd tracks?
677 // Remember: SVC_CDTRACK exists. Maybe it should be used.
679 FixClientCvars(self);
682 WaypointSprite_InitClient(self);
684 // Wazat's grappling hook
685 SetGrappleHookBindings();
687 // get autoswitch state from player when he toggles it
688 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
690 // get version info from player
691 stuffcmd(self, "cmd clientversion $gameversion\n");
693 // get other cvars from player
696 // set cvar for team scoreboard
700 t = cvar("teamplay");
701 // we have to stuff the correct teamplay value because if this is a listen server, this changes the teamplay mode of the server itself, which is bad
702 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
705 stuffcmd(self, "set teamplay 0\n");
709 self.frags = cvar("fraglimit");
710 // no fraglimit was set, so player gets 999 lives
714 self.frags = LMS_NewPlayerLives();
720 else if(cvar("g_arena"))
722 self.classname = "observer";
723 Spawnqueue_Insert(self);
726 bot_relinkplayerlist();
728 self.jointime = time;
735 Called when a client disconnects from the server
738 void(entity e) DropFlag;
739 .entity chatbubbleentity;
740 .entity teambubbleentity;
741 void ClientDisconnect (void)
744 if(cvar("sv_eventlog"))
745 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
746 bprint ("^4",self.netname);
747 bprint ("^4 disconnected\n");
749 if (self.chatbubbleentity)
751 remove (self.chatbubbleentity);
752 self.chatbubbleentity = world;
755 if (self.teambubbleentity)
757 remove (self.teambubbleentity);
758 self.teambubbleentity = world;
761 WaypointSprite_PlayerGone();
764 kh_Key_DropAll(self, TRUE);
767 DropFlag(self.flagcarried);
769 DistributeFragsAmongTeam(self, self.team, 1);
772 self.flags = self.flags - (self.flags & FL_CLIENT);
773 bot_relinkplayerlist();
777 if(self.weaponentity)
778 if(self.weaponentity.lasertarget)
779 remove(self.weaponentity.lasertarget);
783 Spawnqueue_Unmark(self);
784 Spawnqueue_Remove(self);
792 void() ChatBubbleThink =
794 self.nextthink = time;
795 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
797 self.owner.chatbubbleentity = world;
801 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
802 if (self.owner.buttonchat && !self.owner.deadflag)
803 self.model = self.mdl;
808 void() UpdateChatBubble =
810 if (!self.modelindex)
812 // spawn a chatbubble entity if needed
813 if (!self.chatbubbleentity)
815 self.chatbubbleentity = spawn();
816 self.chatbubbleentity.owner = self;
817 self.chatbubbleentity.exteriormodeltoclient = self;
818 self.chatbubbleentity.think = ChatBubbleThink;
819 self.chatbubbleentity.nextthink = time;
820 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
821 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
822 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
823 self.chatbubbleentity.model = "";
824 self.chatbubbleentity.effects = EF_LOWPRECISION;
829 void() TeamBubbleThink =
831 self.nextthink = time;
832 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
834 self.owner.teambubbleentity = world;
838 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
839 if (self.owner.buttonchat || self.owner.deadflag)
842 self.model = self.mdl;
846 float() TeamBubble_customizeentityforclient
848 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
851 void() UpdateTeamBubble =
853 if (!self.modelindex || !cvar("teamplay"))
855 // spawn a teambubble entity if needed
856 if (!self.teambubbleentity && cvar("teamplay"))
858 self.teambubbleentity = spawn();
859 self.teambubbleentity.owner = self;
860 self.teambubbleentity.exteriormodeltoclient = self;
861 self.teambubbleentity.think = TeamBubbleThink;
862 self.teambubbleentity.nextthink = time;
863 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
864 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
865 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
866 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
867 self.teambubbleentity.mdl = self.teambubbleentity.model;
868 self.teambubbleentity.model = self.teambubbleentity.mdl;
869 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
870 self.teambubbleentity.effects = EF_LOWPRECISION;
874 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
875 // added to the model skins
876 /*void() UpdateColorModHack =
879 c = self.clientcolors & 15;
880 // LordHavoc: only bothering to support white, green, red, yellow, blue
881 if (teamplay == 0) self.colormod = '0 0 0';
882 else if (c == 0) self.colormod = '1.00 1.00 1.00';
883 else if (c == 3) self.colormod = '0.10 1.73 0.10';
884 else if (c == 4) self.colormod = '1.73 0.10 0.10';
885 else if (c == 12) self.colormod = '1.22 1.22 0.10';
886 else if (c == 13) self.colormod = '0.10 0.10 1.73';
887 else self.colormod = '1 1 1';
896 void player_powerups (void)
898 if (cvar("g_minstagib"))
900 self.effects = EF_FULLBRIGHT;
901 if (self.items & IT_STRENGTH)
903 if (time > self.strength_finished)
905 self.alpha = default_player_alpha;
906 self.exteriorweaponentity.alpha = default_weapon_alpha;
907 self.items = self.items - (self.items & IT_STRENGTH);
908 sprint(self, "^3Invisibility has worn off\n");
913 if (time < self.strength_finished)
915 self.alpha = cvar("g_minstagib_invis_alpha");
916 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
917 self.items = self.items | IT_STRENGTH;
918 sprint(self, "^3You are invisible\n");
922 if (self.items & IT_INVINCIBLE)
924 if (time > self.invincible_finished)
926 self.items = self.items - (self.items & IT_INVINCIBLE);
927 sprint(self, "^3Speed has worn off\n");
932 if (time < self.invincible_finished)
934 self.items = self.items | IT_INVINCIBLE;
935 sprint(self, "^3You are on speed\n");
941 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
942 if (self.items & IT_STRENGTH)
944 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
945 if (time > self.strength_finished)
947 self.items = self.items - (self.items & IT_STRENGTH);
948 sprint(self, "^3Strength has worn off\n");
953 if (time < self.strength_finished)
955 self.items = self.items | IT_STRENGTH;
956 sprint(self, "^3Strength infuses your weapons with devastating power\n");
959 if (self.items & IT_INVINCIBLE)
961 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
962 if (time > self.invincible_finished)
964 self.items = self.items - (self.items & IT_INVINCIBLE);
965 sprint(self, "^3Shield has worn off\n");
970 if (time < self.invincible_finished)
972 self.items = self.items | IT_INVINCIBLE;
973 sprint(self, "^3Shield surrounds you\n");
977 if (cvar("g_fullbrightplayers"))
978 self.effects = self.effects | EF_FULLBRIGHT;
980 // midair gamemode: damage only while in the air
981 // if in midair mode, being on ground grants temporary invulnerability
982 // (this is so that multishot weapon don't clear the ground flag on the
983 // first damage in the frame, leaving the player vulnerable to the
984 // remaining hits in the same frame)
985 if (self.flags & FL_ONGROUND)
986 if (cvar("g_midair"))
987 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
989 if (time < self.spawnshieldtime)
990 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
993 float CalcRegen(float current, float stable, float regenfactor)
997 else if(current > stable - 0.25) // when close enough, "snap"
1000 return min(stable, current + (stable - current) * regenfactor * frametime);
1003 void player_regen (void)
1005 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1006 maxh = cvar("g_balance_health_stable");
1007 maxa = cvar("g_balance_armor_stable");
1008 limith = cvar("g_balance_health_limit");
1009 limita = cvar("g_balance_armor_limit");
1011 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1014 max_mod = regen_mod = rot_mod = limit_mod = 1;
1016 if (self.runes & RUNE_REGEN)
1018 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1020 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1021 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1022 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1026 regen_mod = cvar("g_balance_rune_regen_regenrate");
1027 max_mod = cvar("g_balance_rune_regen_hpmod");
1028 limit_mod = cvar("g_balance_rune_regen_limitmod");
1031 else if (self.runes & CURSE_VENOM)
1033 max_mod = cvar("g_balance_curse_venom_hpmod");
1034 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1035 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1037 rot_mod = cvar("g_balance_curse_venom_rotrate");
1038 limit_mod = cvar("g_balance_curse_venom_limitmod");
1039 //if (!self.runes & RUNE_REGEN)
1040 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1042 maxh = maxh * max_mod;
1043 //maxa = maxa * max_mod;
1044 limith = limith * limit_mod;
1045 limita = limita * limit_mod;
1047 if (self.armorvalue > maxa)
1049 if (time > self.pauserotarmor_finished)
1051 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1052 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1055 else if (self.armorvalue < maxa)
1057 if (time > self.pauseregen_finished)
1059 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1060 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1063 if (self.health > maxh)
1065 if (time > self.pauserothealth_finished)
1067 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1068 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1071 else if (self.health < maxh)
1073 if (time > self.pauseregen_finished)
1075 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1076 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1080 if (self.health > limith)
1081 self.health = limith;
1082 if (self.armorvalue > limita)
1083 self.armorvalue = limita;
1085 // if player rotted to death... die!
1087 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1091 ======================
1092 spectate mode routines
1093 ======================
1095 void SpectateCopy(entity spectatee) {
1096 self.armortype = spectatee.armortype;
1097 self.armorvalue = spectatee.armorvalue;
1098 self.currentammo = spectatee.currentammo;
1099 self.effects = spectatee.effects;
1100 self.health = spectatee.health;
1102 self.items = spectatee.items;
1103 self.punchangle = spectatee.punchangle;
1104 self.view_ofs = spectatee.view_ofs;
1105 self.v_angle = spectatee.v_angle;
1106 self.viewzoom = spectatee.viewzoom;
1107 setorigin(self, spectatee.origin);
1108 setsize(self, spectatee.mins, spectatee.maxs);
1111 void SpectateUpdate() {
1113 PutObserverInServer();
1115 if (self != self.enemy) {
1116 if(self.enemy.flags & FL_NOTARGET)
1117 PutObserverInServer();
1118 SpectateCopy(self.enemy);
1119 self.dmg_take = self.enemy.dmg_take;
1120 self.dmg_save = self.enemy.dmg_save;
1121 self.dmg_inflictor = self.enemy.dmg_inflictor;
1122 self.fixangle = TRUE;
1123 self.angles = self.enemy.v_angle;
1124 //msg_entity = self;
1125 //WriteByte(MSG_ONE, SVC_SETANGLE);
1126 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1127 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1128 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1132 float SpectateNext() {
1133 other = find(self.enemy, classname, "player");
1135 other = find(other, classname, "player");
1140 if(self.enemy.classname == "player") {
1142 WriteByte(MSG_ONE, SVC_SETVIEW);
1143 WriteEntity(MSG_ONE, self.enemy);
1144 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1154 ShowRespawnCountdown()
1156 Update a respawn countdown display.
1159 void ShowRespawnCountdown()
1162 if(self.deadflag == DEAD_NO) // just respawned?
1166 number = ceil(self.death_time - time);
1169 if(number <= self.respawn_countdown)
1171 self.respawn_countdown = number - 1;
1172 if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1173 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1178 void LeaveSpectatorMode()
1180 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1181 self.classname = "player";
1182 if(cvar("g_campaign") || cvar("g_balance_teams"))
1183 JoinBestTeam(self, 0);
1184 if(cvar("g_campaign"))
1185 campaign_bots_may_start = 1;
1186 PutClientInServer();
1187 if(!(self.flags & FL_NOTARGET))
1188 bprint ("^4", self.netname, "^4 is playing now\n");
1189 centerprint(self,"");
1192 stuffcmd(self,"menu_showteamselect\n");
1201 Called every frame for each client before the physics are run
1204 void() ctf_setstatus;
1205 .float vote_nagtime;
1206 void PlayerPreThink (void)
1209 if(self.version_nagtime)
1210 if(self.cvar_g_nexuizversion)
1211 if(time > self.version_nagtime)
1213 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1214 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1216 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n");
1217 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1219 self.version_nagtime = 0;
1223 if(self.cvar_scr_centertime)
1224 if(time > self.vote_nagtime)
1227 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1231 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1233 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1234 self.max_armorvalue = 0;
1237 if(self.classname == "player") {
1238 local vector m1, m2;
1240 // if(self.netname == "Wazat")
1241 // bprint(self.classname, "\n");
1243 CheckRules_Player();
1246 PrintWelcomeMessage(self);
1248 if(cvar("g_lms") || !cvar("sv_spectate"))
1249 if((time - self.jointime) <= cvar("welcome_message_time"))
1250 PrintWelcomeMessage(self);
1252 if (intermission_running)
1254 IntermissionThink (); // otherwise a button could be missed between
1255 return; // the think tics
1258 if(time > self.teleport_time)
1260 self.effects = self.effects - (self.effects & EF_NODRAW);
1261 if(self.weaponentity)
1262 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1265 Nixnex_GiveCurrentWeapon();
1266 UpdateSelectedPlayer();
1268 if (self.deadflag != DEAD_NO)
1270 float button_pressed, force_respawn;
1272 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1273 force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1274 if (self.deadflag == DEAD_DYING)
1277 self.deadflag = DEAD_RESPAWNING;
1278 else if(!button_pressed)
1279 self.deadflag = DEAD_DEAD;
1281 else if (self.deadflag == DEAD_DEAD)
1284 self.deadflag = DEAD_RESPAWNABLE;
1286 else if (self.deadflag == DEAD_RESPAWNABLE)
1289 self.deadflag = DEAD_RESPAWNING;
1291 else if (self.deadflag == DEAD_RESPAWNING)
1293 if(time > self.death_time)
1296 ShowRespawnCountdown();
1300 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1304 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1305 dist = self.oldorigin - self.origin;
1307 self.lms_traveled_distance += fabs(vlen(dist));
1309 if(cvar("g_campaign"))
1310 if(!campaign_bots_may_start)
1312 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1313 self.lms_traveled_distance = 0;
1316 if(time > self.lms_nextcheck)
1318 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1319 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1321 centerprint(self, cvar_string("g_lms_campcheck_message"));
1322 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1323 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1324 Damage(self, self, self, bound(0, cvar("g_lms_campcheck_damage"), self.health + self.armorvalue * cvar("g_balance_armor_blockpercent") + 5), DEATH_CAMP, self.origin, '0 0 0');
1326 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1327 self.lms_traveled_distance = 0;
1331 if (self.button5 && !self.hook.state)
1336 self.view_ofs = PL_CROUCH_VIEW_OFS;
1337 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1344 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1345 if (!trace_startsolid)
1347 self.crouch = FALSE;
1348 self.view_ofs = PL_VIEW_OFS;
1349 setsize (self, PL_MIN, PL_MAX);
1354 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1355 local string defaultmodel;
1356 defaultmodel = cvar_string("sv_defaultplayermodel");
1358 if (defaultmodel != self.model)
1362 setmodel_lod (self, defaultmodel);
1363 setsize (self, m1, m2);
1366 if (self.skin != cvar("sv_defaultplayerskin"))
1367 self.skin = cvar("sv_defaultplayerskin");
1369 if (self.playermodel != self.model)
1371 self.playermodel = CheckPlayerModel(self.playermodel);
1374 setmodel_lod (self, self.playermodel);
1375 setsize (self, m1, m2);
1380 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1381 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1385 if (self.skin != stof(self.playerskin))
1386 self.skin = stof(self.playerskin);
1390 GrapplingHookFrame();
1395 float zoomfactor, zoomspeed, zoomdir;
1396 zoomfactor = self.cvar_cl_zoomfactor;
1397 if(zoomfactor < 1 || zoomfactor > 16)
1399 zoomspeed = self.cvar_cl_zoomspeed;
1400 if(zoomspeed >= 0) // < 0 is instant zoom
1401 if(zoomspeed < 0.5 || zoomspeed > 16)
1404 zoomdir = self.button4;
1406 if(self.weapon == WEP_NEX)
1407 if(!cvar("g_minstagib"))
1411 self.has_zoomed = 1;
1415 if(zoomspeed <= 0) // instant zoom
1418 self.viewzoom = 1 / zoomfactor;
1424 // geometric zoom would be:
1425 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1426 // however, testing showed that arithmetic/harmonic zoom works better
1428 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1429 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1430 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1432 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1433 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1434 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1438 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1445 if (cvar("g_minstagib"))
1446 minstagib_ammocheck();
1451 //self.angles_y=self.v_angle_y + 90; // temp
1453 //if (TetrisPreFrame()) return;
1454 } else if(gameover) {
1455 if (intermission_running)
1456 IntermissionThink (); // otherwise a button could be missed between
1458 } else if(self.classname == "observer") {
1460 if (self.flags & FL_JUMPRELEASED) {
1461 if (self.button2 && self.version == cvar("gameversion")) {
1462 self.welcomemessage_time = 0;
1463 self.flags = self.flags - FL_JUMPRELEASED;
1464 LeaveSpectatorMode();
1466 } else if(self.button0 && self.version == cvar("gameversion")) {
1467 self.welcomemessage_time = 0;
1468 self.flags = self.flags - FL_JUMPRELEASED;
1469 if(SpectateNext() == 1) {
1470 self.classname = "spectator";
1474 if (!(self.button0 || self.button2)) {
1475 self.flags = self.flags | FL_JUMPRELEASED;
1478 PrintWelcomeMessage(self);
1479 } else if(self.classname == "spectator") {
1480 if (self.flags & FL_JUMPRELEASED) {
1481 if (self.button2 && self.version == cvar("gameversion")) {
1482 self.welcomemessage_time = 0;
1483 self.flags = self.flags - FL_JUMPRELEASED;
1484 LeaveSpectatorMode();
1486 } else if(self.button0) {
1487 self.welcomemessage_time = 0;
1488 self.flags = self.flags - FL_JUMPRELEASED;
1489 if(SpectateNext() == 1) {
1490 self.classname = "spectator";
1492 self.classname = "observer";
1493 PutClientInServer();
1495 } else if (self.button3) {
1496 self.welcomemessage_time = 0;
1497 self.flags = self.flags - FL_JUMPRELEASED;
1498 self.classname = "observer";
1499 PutClientInServer();
1504 if (!(self.button0 || self.button3)) {
1505 self.flags = self.flags | FL_JUMPRELEASED;
1508 PrintWelcomeMessage(self);
1509 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1518 Called every frame for each client after the physics are run
1521 void PlayerPostThink (void)
1523 // Savage: Check for nameless players
1524 if (strlen(self.netname) < 1) {
1525 self.netname = "Player";
1526 stuffcmd(self, "seta _cl_name Player\n");
1529 if(self.classname == "player") {
1530 CheckRules_Player();
1535 if (intermission_running)
1536 return; // intermission or finale
1538 //PrintWelcomeMessage(self);
1539 //if (TetrisPostFrame()) return;
1540 } else if (self.classname == "observer") {
1542 } else if (self.classname == "spectator") {