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.classname == "target_objective")
37 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
39 ent = find(ent, targetname, spot.target);
43 if (spot.team == teamcheck && spotactive > 0)
50 if (vlen(player.origin - spot.origin) < mindist)
52 player = player.chain;
58 previousspot.chain = spot;
65 spawn_allgood = FALSE;
69 // if we couldn't find ANY good points, return the original list
71 newfirstspot = firstspot;
75 entity Spawn_RandomPoint(entity firstspot)
79 // count number of spots
84 numspots = numspots + 1;
88 numspots = numspots * random();
90 while (spot.chain && numspots >= 1)
92 numspots = numspots - 1;
98 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
100 local entity best, spot, player;
101 local float bestrating, rating;
103 bestrating = -1000000;
112 rating = min(rating, vlen(player.origin - spot.origin));
113 player = player.chain;
115 rating = rating + random() * 16;
116 if (bestrating < rating)
130 Finds a point to respawn
133 entity SelectSpawnPoint (float anypoint)
135 local float teamcheck;
136 local entity spot, firstspot, playerlist;
138 spot = find (world, classname, "testplayerstart");
144 if(!anypoint && (g_ctf || g_assault))
145 teamcheck = self.team;
147 // get the list of players
148 playerlist = findchain(classname, "player");
149 // get the entire list of spots
150 firstspot = findchain(classname, "info_player_deathmatch");
151 // filter out the bad ones
152 // (note this returns the original list if none survived)
153 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
155 // there is 50/50 chance of choosing a random spot or the furthest spot
156 // (this means that roughly every other spawn will be furthest, so you
157 // usually won't get fragged at spawn twice in a row)
158 if (arena_roundbased)
160 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
161 spot = Spawn_RandomPoint(firstspot);
163 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
164 spot = Spawn_RandomPoint(firstspot);
166 spot = Spawn_FurthestPoint(firstspot, playerlist);
170 if(cvar("spawn_debug"))
173 error ("PutClientInServer: no start points on level");
183 Checks if the argument string can be a valid playermodel.
184 Returns a valid one in doubt.
187 string FallbackPlayerModel = "models/player/marine.zym";
188 string CheckPlayerModel(string plyermodel) {
189 if(strlen(plyermodel) < 4)
190 return FallbackPlayerModel;
191 if( substring(plyermodel,0,14) != "models/player/")
192 return FallbackPlayerModel;
193 else if(cvar("sv_servermodelsonly"))
195 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
196 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
197 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
198 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
199 return FallbackPlayerModel;
200 if(!fexists(plyermodel))
201 return FallbackPlayerModel;
208 Client_customizeentityforclient
213 float Client_customizeentityforclient()
215 #ifdef ALLOW_VARIABLE_LOD
217 // other: the player viewing me
221 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
224 if(other.cvar_cl_playerdetailreduction <= 0)
226 if(other.cvar_cl_playerdetailreduction <= -2)
227 self.modelindex = self.modelindex_lod2;
228 else if(other.cvar_cl_playerdetailreduction <= -1)
229 self.modelindex = self.modelindex_lod1;
231 self.modelindex = self.modelindex_lod0;
235 distance = vlen(self.origin - other.origin);
236 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
238 self.modelindex = self.modelindex_lod2;
240 self.modelindex = self.modelindex_lod1;
242 self.modelindex = self.modelindex_lod0;
249 void UpdateVoiceMessages();
250 void setmodel_lod(entity e, string modelname)
252 #ifdef ALLOW_VARIABLE_LOD
255 // FIXME: this only supports 3-letter extensions
256 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
260 setmodel(e, s); // players have high precision
261 self.modelindex_lod1 = self.modelindex;
264 self.modelindex_lod1 = -1;
266 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
270 setmodel(e, s); // players have high precision
271 self.modelindex_lod2 = self.modelindex;
274 self.modelindex_lod2 = -1;
276 precache_model(modelname);
277 setmodel(e, modelname); // players have high precision
278 self.modelindex_lod0 = self.modelindex;
280 if(self.modelindex_lod1 < 0)
281 self.modelindex_lod1 = self.modelindex;
283 if(self.modelindex_lod2 < 0)
284 self.modelindex_lod2 = self.modelindex;
286 precache_model(modelname);
287 setmodel(e, modelname); // players have high precision
289 player_setupanimsformodel();
290 UpdateVoiceMessages();
297 putting a client as observer in the server
300 void PutObserverInServer (void)
303 spot = SelectSpawnPoint (TRUE);
304 RemoveGrapplingHook(self); // Wazat's Grappling Hook
306 if(clienttype(self) == CLIENTTYPE_REAL)
309 WriteByte(MSG_ONE, SVC_SETVIEW);
310 WriteEntity(MSG_ONE, self);
314 kh_Key_DropAll(self, TRUE);
317 DropFlag(self.flagcarried);
319 WaypointSprite_PlayerDead();
321 DistributeFragsAmongTeam(self, self.team, 1);
323 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
324 bprint ("^4", self.netname, "^4 has no more lives left\n");
325 else if(self.killcount != -666)
326 bprint ("^4", self.netname, "^4 is spectating now\n");
328 self.classname = "observer";
330 self.takedamage = DAMAGE_NO;
331 self.solid = SOLID_NOT;
332 self.movetype = MOVETYPE_NOCLIP;
333 self.flags = FL_CLIENT | FL_NOTARGET;
334 self.armorvalue = 666;
336 self.armorvalue = cvar("g_balance_armor_start");
337 self.pauserotarmor_finished = 0;
338 self.pauserothealth_finished = 0;
339 self.pauseregen_finished = 0;
340 self.damageforcescale = 0;
348 self.pain_finished = 0;
349 self.strength_finished = 0;
350 self.invincible_finished = 0;
352 self.think = SUB_Null;
356 self.deadflag = DEAD_NO;
357 self.angles = spot.angles;
359 self.fixangle = TRUE;
362 self.view_ofs = PL_VIEW_OFS;
363 setorigin (self, spot.origin);
364 setsize (self, '0 0 0', '0 0 0');
365 self.oldorigin = self.origin;
370 self.weaponmodel = "";
371 self.weaponentity = world;
372 self.killcount = -666;
373 self.velocity = '0 0 0';
374 self.avelocity = '0 0 0';
375 self.punchangle = '0 0 0';
376 self.punchvector = '0 0 0';
377 self.oldvelocity = self.velocity;
378 self.customizeentityforclient = Client_customizeentityforclient;
384 Spawnqueue_Insert(self);
388 Spawnqueue_Unmark(self);
389 Spawnqueue_Remove(self);
401 Called when a client spawns in the server
404 void PutClientInServer (void)
406 if(clienttype(self) == CLIENTTYPE_BOT)
408 self.classname = "player";
410 else if(clienttype(self) == CLIENTTYPE_REAL)
413 WriteByte(MSG_ONE, SVC_SETVIEW);
414 WriteEntity(MSG_ONE, self);
417 // player is dead and becomes observer
418 if(g_lms && self.frags < 1)
419 self.classname = "observer";
423 self.classname = "observer";
425 if(self.classname == "player") {
428 spot = SelectSpawnPoint (FALSE);
430 RemoveGrapplingHook(self); // Wazat's Grappling Hook
432 self.classname = "player";
433 self.iscreature = TRUE;
434 self.movetype = MOVETYPE_WALK;
435 self.solid = SOLID_SLIDEBOX;
436 self.flags = FL_CLIENT;
437 self.takedamage = DAMAGE_AIM;
439 self.air_finished = time + 12;
442 self.ammo_shells = start_ammo_shells;
443 self.ammo_nails = start_ammo_nails;
444 self.ammo_rockets = start_ammo_rockets;
445 self.ammo_cells = start_ammo_cells;
446 self.health = start_health;
447 self.armorvalue = start_armorvalue;
448 self.items = start_items;
449 self.switchweapon = start_switchweapon;
451 self.jump_interval = time;
453 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
454 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
455 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
456 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
457 self.damageforcescale = 2;
464 self.pain_finished = 0;
465 self.strength_finished = 0;
466 self.invincible_finished = 0;
468 //self.speed_finished = 0;
469 //self.slowmo_finished = 0;
470 // players have no think function
471 self.think = SUB_Null;
477 self.deadflag = DEAD_NO;
479 self.angles = spot.angles;
481 self.angles_z = 0; // never spawn tilted even if the spot says to
482 self.fixangle = TRUE; // turn this way immediately
483 self.velocity = '0 0 0';
484 self.avelocity = '0 0 0';
485 self.punchangle = '0 0 0';
486 self.punchvector = '0 0 0';
487 self.oldvelocity = self.velocity;
492 self.customizeentityforclient = Client_customizeentityforclient;
494 if(cvar("sv_defaultcharacter") == 1) {
495 local string defaultmodel;
496 defaultmodel = cvar_string("sv_defaultplayermodel");
497 setmodel_lod (self, defaultmodel);
498 self.skin = stof(cvar_string("sv_defaultplayerskin"));
500 self.playermodel = CheckPlayerModel(self.playermodel);
501 setmodel_lod (self, self.playermodel);
505 s = stof(self.playerskin);
514 self.skin = stof(self.playerskin);
517 if(strlen(cvar_string("sv_defaultplayercolors")))
518 setcolor(self, cvar("sv_defaultplayercolors"));
521 self.view_ofs = PL_VIEW_OFS;
522 setsize (self, PL_MIN, PL_MAX);
523 self.spawnorigin = spot.origin;
524 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
525 // don't reset back to last position, even if new position is stuck in solid
526 self.oldorigin = self.origin;
530 Spawnqueue_Remove(self);
531 Spawnqueue_Mark(self);
534 self.event_damage = PlayerDamage;
536 self.bot_attack = TRUE;
538 self.statdraintime = time + 5;
539 self.button0 = self.button1 = self.button2 = self.button3 = 0;
541 if(self.killcount == -666) {
548 self.cnt = WEP_LASER;
549 self.nixnex_lastchange_id = -1;
551 CL_SpawnWeaponentity();
552 self.alpha = default_player_alpha;
553 self.colormod = '1 1 1' * cvar("g_player_brightness");
554 self.exteriorweaponentity.alpha = default_weapon_alpha;
556 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
557 self.lms_traveled_distance = 0;
559 if(cvar("spawn_debug"))
561 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
562 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
565 //stuffcmd(self, "chase_active 0");
566 //stuffcmd(self, "set viewsize $tmpviewsize \n");
568 if (cvar("g_spawnsound"))
569 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
572 if(self.team == assault_attacker_team)
573 centerprint(self, "You are attacking!\n");
575 centerprint(self, "You are defending!\n");
578 } else if(self.classname == "observer") {
579 PutObserverInServer ();
588 void SetNewParms (void)
598 void SetChangeParms (void)
607 Called when a client types 'kill' in the console
610 void ClientKill (void)
612 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
615 void FixClientCvars(entity e)
618 // send prediction settings to the client
619 stuffcmd(e, "\nin_bindmap 0 0\n");
620 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
621 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
622 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
623 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
624 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
625 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
626 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
627 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
628 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
629 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
630 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
631 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
632 stuffcmd(e, "cl_movement_edgefriction 1\n");
634 // notify about available teams
637 CheckAllowedTeams(e);
638 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
639 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
642 stuffcmd(e, "set _teams_available 0\n");
649 Called when a client connects to the server
652 string ColoredTeamName(float t);
653 //void dom_player_join_team(entity pl);
654 void ClientConnect (void)
659 if(Ban_IsClientBanned(self))
661 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
667 self.classname = "player_joining";
668 self.flags = self.flags | FL_CLIENT;
669 self.version_nagtime = time + 10 + random() * 10;
673 dprint("BUG player count is lower than zero, this cannot happen!\n");
680 // dom_player_join_team(self);
682 //JoinBestTeam(self, FALSE);
684 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
685 self.classname = "observer";
687 self.classname = "player";
688 campaign_bots_may_start = 1;
691 self.playerid = (playerid_last = playerid_last + 1);
692 if(cvar("sv_eventlog"))
694 if(clienttype(self) == CLIENTTYPE_REAL)
698 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
699 s = strcat(":team:", ftos(self.playerid), ":");
700 s = strcat(s, ftos(self.team));
701 GameLogEcho(s, FALSE);
704 //stuffcmd(self, "set tmpviewsize $viewsize \n");
706 bprint ("^4",self.netname);
707 bprint ("^4 connected");
709 if(g_domination || g_ctf)
711 bprint(" and joined the ");
712 bprint(ColoredTeamName(self.team));
717 self.welcomemessage_time = 0;
719 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
720 // TODO: is this being used for anything else than cd tracks?
721 // Remember: SVC_CDTRACK exists. Maybe it should be used.
723 FixClientCvars(self);
726 WaypointSprite_InitClient(self);
728 // Wazat's grappling hook
729 SetGrappleHookBindings();
731 // get autoswitch state from player when he toggles it
732 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
734 // get version info from player
735 stuffcmd(self, "cmd clientversion $gameversion\n");
737 // send all weapon info strings
738 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
740 while (wep <= WEP_LAST)
742 weapon_action(wep, WR_REGISTER);
746 // get other cvars from player
749 // set cvar for team scoreboard
753 t = cvar("teamplay");
754 // 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
755 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
758 stuffcmd(self, "set teamplay 0\n");
762 self.frags = LMS_NewPlayerLives();
768 self.classname = "observer";
769 Spawnqueue_Insert(self);
772 bot_relinkplayerlist();
774 self.jointime = time;
781 Called when a client disconnects from the server
784 void(entity e) DropFlag;
785 .entity chatbubbleentity;
786 .entity teambubbleentity;
787 void ClientDisconnect (void)
790 if(cvar("sv_eventlog"))
791 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
792 bprint ("^4",self.netname);
793 bprint ("^4 disconnected\n");
795 if (self.chatbubbleentity)
797 remove (self.chatbubbleentity);
798 self.chatbubbleentity = world;
801 if (self.teambubbleentity)
803 remove (self.teambubbleentity);
804 self.teambubbleentity = world;
807 WaypointSprite_PlayerGone();
810 kh_Key_DropAll(self, TRUE);
813 DropFlag(self.flagcarried);
815 DistributeFragsAmongTeam(self, self.team, 1);
818 self.flags = self.flags - (self.flags & FL_CLIENT);
819 bot_relinkplayerlist();
823 if(self.weaponentity)
824 if(self.weaponentity.lasertarget)
825 remove(self.weaponentity.lasertarget);
829 Spawnqueue_Unmark(self);
830 Spawnqueue_Remove(self);
838 void() ChatBubbleThink =
840 self.nextthink = time;
841 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
843 self.owner.chatbubbleentity = world;
847 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
848 if (self.owner.buttonchat && !self.owner.deadflag)
849 self.model = self.mdl;
854 void() UpdateChatBubble =
856 if (!self.modelindex)
858 // spawn a chatbubble entity if needed
859 if (!self.chatbubbleentity)
861 self.chatbubbleentity = spawn();
862 self.chatbubbleentity.owner = self;
863 self.chatbubbleentity.exteriormodeltoclient = self;
864 self.chatbubbleentity.think = ChatBubbleThink;
865 self.chatbubbleentity.nextthink = time;
866 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
867 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
868 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
869 self.chatbubbleentity.model = "";
870 self.chatbubbleentity.effects = EF_LOWPRECISION;
875 void() TeamBubbleThink =
877 self.nextthink = time;
878 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
880 self.owner.teambubbleentity = world;
884 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
885 if (self.owner.buttonchat || self.owner.deadflag)
888 self.model = self.mdl;
892 float() TeamBubble_customizeentityforclient
894 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
897 void() UpdateTeamBubble =
899 if (!self.modelindex || !cvar("teamplay"))
901 // spawn a teambubble entity if needed
902 if (!self.teambubbleentity && cvar("teamplay"))
904 self.teambubbleentity = spawn();
905 self.teambubbleentity.owner = self;
906 self.teambubbleentity.exteriormodeltoclient = self;
907 self.teambubbleentity.think = TeamBubbleThink;
908 self.teambubbleentity.nextthink = time;
909 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
910 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
911 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
912 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
913 self.teambubbleentity.mdl = self.teambubbleentity.model;
914 self.teambubbleentity.model = self.teambubbleentity.mdl;
915 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
916 self.teambubbleentity.effects = EF_LOWPRECISION;
920 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
921 // added to the model skins
922 /*void() UpdateColorModHack =
925 c = self.clientcolors & 15;
926 // LordHavoc: only bothering to support white, green, red, yellow, blue
927 if (teamplay == 0) self.colormod = '0 0 0';
928 else if (c == 0) self.colormod = '1.00 1.00 1.00';
929 else if (c == 3) self.colormod = '0.10 1.73 0.10';
930 else if (c == 4) self.colormod = '1.73 0.10 0.10';
931 else if (c == 12) self.colormod = '1.22 1.22 0.10';
932 else if (c == 13) self.colormod = '0.10 0.10 1.73';
933 else self.colormod = '1 1 1';
942 void player_powerups (void)
946 self.effects = EF_FULLBRIGHT;
947 if (self.items & IT_STRENGTH)
949 if (time > self.strength_finished)
951 self.alpha = default_player_alpha;
952 self.exteriorweaponentity.alpha = default_weapon_alpha;
953 self.items = self.items - (self.items & IT_STRENGTH);
954 sprint(self, "^3Invisibility has worn off\n");
959 if (time < self.strength_finished)
961 self.alpha = cvar("g_minstagib_invis_alpha");
962 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
963 self.items = self.items | IT_STRENGTH;
964 sprint(self, "^3You are invisible\n");
968 if (self.items & IT_INVINCIBLE)
970 if (time > self.invincible_finished)
972 self.items = self.items - (self.items & IT_INVINCIBLE);
973 sprint(self, "^3Speed has worn off\n");
978 if (time < self.invincible_finished)
980 self.items = self.items | IT_INVINCIBLE;
981 sprint(self, "^3You are on speed\n");
987 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
988 if (self.items & IT_STRENGTH)
990 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
991 if (time > self.strength_finished)
993 self.items = self.items - (self.items & IT_STRENGTH);
994 sprint(self, "^3Strength has worn off\n");
999 if (time < self.strength_finished)
1001 self.items = self.items | IT_STRENGTH;
1002 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1005 if (self.items & IT_INVINCIBLE)
1007 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1008 if (time > self.invincible_finished)
1010 self.items = self.items - (self.items & IT_INVINCIBLE);
1011 sprint(self, "^3Shield has worn off\n");
1016 if (time < self.invincible_finished)
1018 self.items = self.items | IT_INVINCIBLE;
1019 sprint(self, "^3Shield surrounds you\n");
1023 if (cvar("g_fullbrightplayers"))
1024 self.effects = self.effects | EF_FULLBRIGHT;
1026 // midair gamemode: damage only while in the air
1027 // if in midair mode, being on ground grants temporary invulnerability
1028 // (this is so that multishot weapon don't clear the ground flag on the
1029 // first damage in the frame, leaving the player vulnerable to the
1030 // remaining hits in the same frame)
1031 if (self.flags & FL_ONGROUND)
1033 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1035 if (time < self.spawnshieldtime)
1036 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1039 float CalcRegen(float current, float stable, float regenfactor)
1041 if(current > stable)
1043 else if(current > stable - 0.25) // when close enough, "snap"
1046 return min(stable, current + (stable - current) * regenfactor * frametime);
1049 void player_regen (void)
1051 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1052 maxh = cvar("g_balance_health_stable");
1053 maxa = cvar("g_balance_armor_stable");
1054 limith = cvar("g_balance_health_limit");
1055 limita = cvar("g_balance_armor_limit");
1057 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1060 max_mod = regen_mod = rot_mod = limit_mod = 1;
1062 if (self.runes & RUNE_REGEN)
1064 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1066 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1067 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1068 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1072 regen_mod = cvar("g_balance_rune_regen_regenrate");
1073 max_mod = cvar("g_balance_rune_regen_hpmod");
1074 limit_mod = cvar("g_balance_rune_regen_limitmod");
1077 else if (self.runes & CURSE_VENOM)
1079 max_mod = cvar("g_balance_curse_venom_hpmod");
1080 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1081 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1083 rot_mod = cvar("g_balance_curse_venom_rotrate");
1084 limit_mod = cvar("g_balance_curse_venom_limitmod");
1085 //if (!self.runes & RUNE_REGEN)
1086 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1088 maxh = maxh * max_mod;
1089 //maxa = maxa * max_mod;
1090 limith = limith * limit_mod;
1091 limita = limita * limit_mod;
1093 if (self.armorvalue > maxa)
1095 if (time > self.pauserotarmor_finished)
1097 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1098 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1101 else if (self.armorvalue < maxa)
1103 if (time > self.pauseregen_finished)
1105 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1106 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1109 if (self.health > maxh)
1111 if (time > self.pauserothealth_finished)
1113 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1114 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1117 else if (self.health < maxh)
1119 if (time > self.pauseregen_finished)
1121 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1122 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1126 if (self.health > limith)
1127 self.health = limith;
1128 if (self.armorvalue > limita)
1129 self.armorvalue = limita;
1131 // if player rotted to death... die!
1133 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1137 ======================
1138 spectate mode routines
1139 ======================
1141 void SpectateCopy(entity spectatee) {
1142 self.armortype = spectatee.armortype;
1143 self.armorvalue = spectatee.armorvalue;
1144 self.currentammo = spectatee.currentammo;
1145 self.effects = spectatee.effects;
1146 self.health = spectatee.health;
1148 self.items = spectatee.items;
1149 self.punchangle = spectatee.punchangle;
1150 self.view_ofs = spectatee.view_ofs;
1151 self.v_angle = spectatee.v_angle;
1152 self.viewzoom = spectatee.viewzoom;
1153 setorigin(self, spectatee.origin);
1154 setsize(self, spectatee.mins, spectatee.maxs);
1157 void SpectateUpdate() {
1159 PutObserverInServer();
1161 if (self != self.enemy) {
1162 if(self.enemy.flags & FL_NOTARGET)
1163 PutObserverInServer();
1164 SpectateCopy(self.enemy);
1165 self.dmg_take = self.enemy.dmg_take;
1166 self.dmg_save = self.enemy.dmg_save;
1167 self.dmg_inflictor = self.enemy.dmg_inflictor;
1168 self.fixangle = TRUE;
1169 self.angles = self.enemy.v_angle;
1170 //msg_entity = self;
1171 //WriteByte(MSG_ONE, SVC_SETANGLE);
1172 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1173 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1174 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1178 float SpectateNext() {
1179 other = find(self.enemy, classname, "player");
1181 other = find(other, classname, "player");
1186 if(self.enemy.classname == "player") {
1188 WriteByte(MSG_ONE, SVC_SETVIEW);
1189 WriteEntity(MSG_ONE, self.enemy);
1190 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1200 ShowRespawnCountdown()
1202 Update a respawn countdown display.
1205 void ShowRespawnCountdown()
1208 if(self.deadflag == DEAD_NO) // just respawned?
1212 number = ceil(self.death_time - time);
1215 if(number <= self.respawn_countdown)
1217 self.respawn_countdown = number - 1;
1218 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
1219 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1224 void LeaveSpectatorMode()
1226 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1227 self.classname = "player";
1228 if(cvar("g_campaign") || cvar("g_balance_teams"))
1229 JoinBestTeam(self, 0);
1230 if(cvar("g_campaign"))
1231 campaign_bots_may_start = 1;
1232 PutClientInServer();
1233 if(!(self.flags & FL_NOTARGET))
1234 bprint ("^4", self.netname, "^4 is playing now\n");
1235 centerprint(self,"");
1238 stuffcmd(self,"menu_showteamselect\n");
1247 Called every frame for each client before the physics are run
1250 void() ctf_setstatus;
1251 .float vote_nagtime;
1252 void PlayerPreThink (void)
1255 if(self.version_nagtime)
1256 if(self.cvar_g_nexuizversion)
1257 if(time > self.version_nagtime)
1259 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1260 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1262 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");
1263 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1265 self.version_nagtime = 0;
1269 if(self.cvar_scr_centertime)
1270 if(time > self.vote_nagtime)
1273 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1277 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1279 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1280 self.max_armorvalue = 0;
1283 if(self.classname == "player") {
1284 local vector m1, m2;
1286 // if(self.netname == "Wazat")
1287 // bprint(self.classname, "\n");
1289 CheckRules_Player();
1292 PrintWelcomeMessage(self);
1294 if(g_lms || !cvar("sv_spectate"))
1295 if((time - self.jointime) <= cvar("welcome_message_time"))
1296 PrintWelcomeMessage(self);
1298 if (intermission_running)
1300 IntermissionThink (); // otherwise a button could be missed between
1301 return; // the think tics
1304 if(time > self.teleport_time)
1306 self.effects = self.effects - (self.effects & EF_NODRAW);
1307 if(self.weaponentity)
1308 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1311 Nixnex_GiveCurrentWeapon();
1313 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1314 UpdateSelectedPlayer();
1316 if (self.deadflag != DEAD_NO)
1318 float button_pressed, force_respawn;
1320 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1321 force_respawn = (g_lms || cvar("g_forced_respawn"));
1322 if (self.deadflag == DEAD_DYING)
1325 self.deadflag = DEAD_RESPAWNING;
1326 else if(!button_pressed)
1327 self.deadflag = DEAD_DEAD;
1329 else if (self.deadflag == DEAD_DEAD)
1332 self.deadflag = DEAD_RESPAWNABLE;
1334 else if (self.deadflag == DEAD_RESPAWNABLE)
1337 self.deadflag = DEAD_RESPAWNING;
1339 else if (self.deadflag == DEAD_RESPAWNING)
1341 if(time > self.death_time)
1344 ShowRespawnCountdown();
1348 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1352 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1353 dist = self.oldorigin - self.origin;
1355 self.lms_traveled_distance += fabs(vlen(dist));
1357 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1359 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1360 self.lms_traveled_distance = 0;
1363 if(time > self.lms_nextcheck)
1365 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1366 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1368 centerprint(self, cvar_string("g_lms_campcheck_message"));
1369 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1370 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1371 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');
1373 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1374 self.lms_traveled_distance = 0;
1378 if (self.button5 && !self.hook.state)
1383 self.view_ofs = PL_CROUCH_VIEW_OFS;
1384 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1385 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1392 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1393 if (!trace_startsolid)
1395 self.crouch = FALSE;
1396 self.view_ofs = PL_VIEW_OFS;
1397 setsize (self, PL_MIN, PL_MAX);
1402 if(cvar("sv_defaultcharacter") == 1) {
1403 local string defaultmodel;
1404 defaultmodel = cvar_string("sv_defaultplayermodel");
1406 if (defaultmodel != self.model)
1410 setmodel_lod (self, defaultmodel);
1411 setsize (self, m1, m2);
1414 if (self.skin != cvar("sv_defaultplayerskin"))
1415 self.skin = cvar("sv_defaultplayerskin");
1417 if (self.playermodel != self.model)
1419 self.playermodel = CheckPlayerModel(self.playermodel);
1422 setmodel_lod (self, self.playermodel);
1423 setsize (self, m1, m2);
1428 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1429 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1433 if (self.skin != stof(self.playerskin))
1434 self.skin = stof(self.playerskin);
1438 if(strlen(cvar_string("sv_defaultplayercolors")))
1439 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1440 setcolor(self, cvar("sv_defaultplayercolors"));
1442 GrapplingHookFrame();
1447 float zoomfactor, zoomspeed, zoomdir;
1448 zoomfactor = self.cvar_cl_zoomfactor;
1449 if(zoomfactor < 1 || zoomfactor > 16)
1451 zoomspeed = self.cvar_cl_zoomspeed;
1452 if(zoomspeed >= 0) // < 0 is instant zoom
1453 if(zoomspeed < 0.5 || zoomspeed > 16)
1456 zoomdir = self.button4;
1458 if(self.weapon == WEP_NEX)
1463 self.has_zoomed = 1;
1467 if(zoomspeed <= 0) // instant zoom
1470 self.viewzoom = 1 / zoomfactor;
1476 // geometric zoom would be:
1477 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1478 // however, testing showed that arithmetic/harmonic zoom works better
1480 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1481 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1482 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1484 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1485 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1486 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1490 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1498 minstagib_ammocheck();
1503 //self.angles_y=self.v_angle_y + 90; // temp
1505 //if (TetrisPreFrame()) return;
1506 } else if(gameover) {
1507 if (intermission_running)
1508 IntermissionThink (); // otherwise a button could be missed between
1510 } else if(self.classname == "observer") {
1512 if (self.flags & FL_JUMPRELEASED) {
1513 if (self.button2 && self.version == cvar("gameversion")) {
1514 self.welcomemessage_time = 0;
1515 self.flags = self.flags - FL_JUMPRELEASED;
1516 LeaveSpectatorMode();
1518 } else if(self.button0 && self.version == cvar("gameversion")) {
1519 self.welcomemessage_time = 0;
1520 self.flags = self.flags - FL_JUMPRELEASED;
1521 if(SpectateNext() == 1) {
1522 self.classname = "spectator";
1526 if (!(self.button0 || self.button2)) {
1527 self.flags = self.flags | FL_JUMPRELEASED;
1530 PrintWelcomeMessage(self);
1531 } else if(self.classname == "spectator") {
1532 if (self.flags & FL_JUMPRELEASED) {
1533 if (self.button2 && self.version == cvar("gameversion")) {
1534 self.welcomemessage_time = 0;
1535 self.flags = self.flags - FL_JUMPRELEASED;
1536 LeaveSpectatorMode();
1538 } else if(self.button0) {
1539 self.welcomemessage_time = 0;
1540 self.flags = self.flags - FL_JUMPRELEASED;
1541 if(SpectateNext() == 1) {
1542 self.classname = "spectator";
1544 self.classname = "observer";
1545 PutClientInServer();
1547 } else if (self.button3) {
1548 self.welcomemessage_time = 0;
1549 self.flags = self.flags - FL_JUMPRELEASED;
1550 self.classname = "observer";
1551 PutClientInServer();
1556 if (!(self.button0 || self.button3)) {
1557 self.flags = self.flags | FL_JUMPRELEASED;
1560 PrintWelcomeMessage(self);
1561 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1570 Called every frame for each client after the physics are run
1573 void PlayerPostThink (void)
1575 // Savage: Check for nameless players
1576 if (strlen(self.netname) < 1) {
1577 self.netname = "Player";
1578 stuffcmd(self, "seta _cl_name Player\n");
1581 if(self.classname == "player") {
1582 CheckRules_Player();
1587 if (intermission_running)
1588 return; // intermission or finale
1590 //PrintWelcomeMessage(self);
1591 //if (TetrisPostFrame()) return;
1593 // restart countdown
1594 if(time < restart_countdown)
1599 sec = ceil(restart_countdown-time);
1600 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1601 centerprint(self, s);
1602 self.movetype = MOVETYPE_NONE;
1603 self.velocity = '0 0 0';
1604 self.avelocity = '0 0 0';
1605 self.movement = '0 0 0';
1607 else if(self.movetype == MOVETYPE_NONE)
1609 self.movetype = MOVETYPE_WALK;
1610 centerprint(self, "\n");
1612 } else if (self.classname == "observer") {
1614 } else if (self.classname == "spectator") {