1 .float wantswelcomemessage;
2 .string netname_previous;
4 void spawnfunc_info_player_survivor (void)
6 spawnfunc_info_player_deathmatch();
9 void spawnfunc_info_player_start (void)
11 spawnfunc_info_player_deathmatch();
14 void spawnfunc_info_player_deathmatch (void)
16 self.classname = "info_player_deathmatch";
17 relocate_spawnpoint();
20 void() spawnpoint_use =
25 self.team = activator.team;
26 some_spawn_has_been_used = 1;
31 // -1 if a spawn can't be used
32 // otherwise, a weight of the spawnpoint
33 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
35 float shortest, thisdist;
38 // filter out spots for the wrong team
40 if(spot.team != teamcheck)
43 // filter out spots for assault
44 if(spot.target != "") {
46 ent = find(world, targetname, spot.target);
48 if(ent.classname == "target_objective")
49 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
51 ent = find(ent, targetname, spot.target);
56 shortest = vlen(world.maxs - world.mins);
57 for(player = playerlist; player; player = player.chain)
60 thisdist = vlen(player.origin - spot.origin);
61 if (thisdist < shortest)
69 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
71 local entity spot, spotlist, spotlistend;
78 for(spot = firstspot; spot; spot = spot.chain)
80 spot.frags = Spawn_Score(spot, playerlist, teamcheck);
82 if(cvar("spawn_debugview"))
84 setmodel(spot, "models/runematch/rune.mdl");
85 if(spot.frags < mindist)
87 spot.colormod = '1 0 0';
92 spot.colormod = '0 1 0';
93 spot.scale = spot.frags / mindist;
97 if(spot.frags >= 0) // spawning allowed here
99 if(spot.frags < mindist)
101 // too short distance
102 spawn_allgood = FALSE;
107 spawn_allbad = FALSE;
110 spotlistend.chain = spot;
121 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
123 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
124 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
127 RandomSelection_Init();
128 for(spot = firstspot; spot; spot = spot.chain)
129 RandomSelection_Add(spot, 0, pow(bound(lower, spot.frags, upper), exponent) * spot.cnt);
131 return RandomSelection_chosen_ent;
138 Finds a point to respawn
141 entity SelectSpawnPoint (float anypoint)
143 local float teamcheck;
144 local entity firstspot_new;
145 local entity spot, firstspot, playerlist;
147 spot = find (world, classname, "testplayerstart");
153 if(!anypoint && have_team_spawns)
154 teamcheck = self.team;
156 // get the list of players
157 playerlist = findchain(classname, "player");
158 // get the entire list of spots
159 firstspot = findchain(classname, "info_player_deathmatch");
160 // filter out the bad ones
161 // (note this returns the original list if none survived)
162 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
164 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
165 firstspot = firstspot_new;
167 // there is 50/50 chance of choosing a random spot or the furthest spot
168 // (this means that roughly every other spawn will be furthest, so you
169 // usually won't get fragged at spawn twice in a row)
170 if (arena_roundbased)
172 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
174 firstspot = firstspot_new;
175 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
177 else if (random() > cvar("g_spawn_furthest"))
178 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
180 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
182 if(cvar("spawn_debugview"))
184 print("spot mindistance: ", ftos(spot.frags), "\n");
189 if(cvar("spawn_debug"))
193 if(some_spawn_has_been_used)
194 return world; // team can't spawn any more, because of actions of other team
196 error("Cannot find a spawn point - please fix the map!");
207 Checks if the argument string can be a valid playermodel.
208 Returns a valid one in doubt.
211 string FallbackPlayerModel = "models/player/marine.zym";
212 string CheckPlayerModel(string plyermodel) {
213 if(strlen(plyermodel) < 4)
214 return FallbackPlayerModel;
215 if( substring(plyermodel,0,14) != "models/player/")
216 return FallbackPlayerModel;
217 else if(cvar("sv_servermodelsonly"))
219 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
220 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
221 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
222 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
223 return FallbackPlayerModel;
224 if(!fexists(plyermodel))
225 return FallbackPlayerModel;
232 Client_customizeentityforclient
237 float Client_customizeentityforclient()
239 #ifdef ALLOW_VARIABLE_LOD
241 // other: the player viewing me
245 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
248 if(other.cvar_cl_playerdetailreduction <= 0)
250 if(other.cvar_cl_playerdetailreduction <= -2)
251 self.modelindex = self.modelindex_lod2;
252 else if(other.cvar_cl_playerdetailreduction <= -1)
253 self.modelindex = self.modelindex_lod1;
255 self.modelindex = self.modelindex_lod0;
259 distance = vlen(self.origin - other.origin);
260 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
262 self.modelindex = self.modelindex_lod2;
264 self.modelindex = self.modelindex_lod1;
266 self.modelindex = self.modelindex_lod0;
273 void UpdatePlayerSounds();
274 void setmodel_lod(entity e, string modelname)
276 #ifdef ALLOW_VARIABLE_LOD
279 // FIXME: this only supports 3-letter extensions
280 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
284 setmodel(e, s); // players have high precision
285 self.modelindex_lod1 = self.modelindex;
288 self.modelindex_lod1 = -1;
290 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
294 setmodel(e, s); // players have high precision
295 self.modelindex_lod2 = self.modelindex;
298 self.modelindex_lod2 = -1;
300 precache_model(modelname);
301 setmodel(e, modelname); // players have high precision
302 self.modelindex_lod0 = self.modelindex;
304 if(self.modelindex_lod1 < 0)
305 self.modelindex_lod1 = self.modelindex;
307 if(self.modelindex_lod2 < 0)
308 self.modelindex_lod2 = self.modelindex;
310 precache_model(modelname);
311 setmodel(e, modelname); // players have high precision
313 player_setupanimsformodel();
314 UpdatePlayerSounds();
321 putting a client as observer in the server
324 void PutObserverInServer (void)
327 spot = SelectSpawnPoint (TRUE);
329 error("No spawnpoints for observers?!?\n");
330 RemoveGrapplingHook(self); // Wazat's Grappling Hook
332 if(clienttype(self) == CLIENTTYPE_REAL)
335 WriteByte(MSG_ONE, SVC_SETVIEW);
336 WriteEntity(MSG_ONE, self);
340 kh_Key_DropAll(self, TRUE);
343 DropFlag(self.flagcarried);
345 WaypointSprite_PlayerDead();
347 DistributeFragsAmongTeam(self, self.team, 1);
349 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
350 bprint ("^4", self.netname, "^4 has no more lives left\n");
351 else if(self.killcount != -666)
352 bprint ("^4", self.netname, "^4 is spectating now\n");
354 self.spectatortime = time;
356 self.classname = "observer";
358 self.takedamage = DAMAGE_NO;
359 self.solid = SOLID_NOT;
360 self.movetype = MOVETYPE_NOCLIP;
361 self.flags = FL_CLIENT | FL_NOTARGET;
362 self.armorvalue = 666;
364 self.armorvalue = cvar("g_balance_armor_start");
365 self.pauserotarmor_finished = 0;
366 self.pauserothealth_finished = 0;
367 self.pauseregen_finished = 0;
368 self.damageforcescale = 0;
376 self.pain_finished = 0;
377 self.strength_finished = 0;
378 self.invincible_finished = 0;
380 self.think = SUB_Null;
384 self.deadflag = DEAD_NO;
385 self.angles = spot.angles;
387 self.fixangle = TRUE;
390 self.view_ofs = PL_VIEW_OFS;
391 setorigin (self, spot.origin);
392 setsize (self, '0 0 0', '0 0 0');
393 self.oldorigin = self.origin;
398 self.weaponmodel = "";
399 self.weaponentity = world;
400 self.killcount = -666;
401 self.velocity = '0 0 0';
402 self.avelocity = '0 0 0';
403 self.punchangle = '0 0 0';
404 self.punchvector = '0 0 0';
405 self.oldvelocity = self.velocity;
406 self.customizeentityforclient = Client_customizeentityforclient;
408 self.wantswelcomemessage = 1;
414 Spawnqueue_Insert(self);
418 Spawnqueue_Unmark(self);
419 Spawnqueue_Remove(self);
426 float RestrictSkin(float s)
435 void FixPlayermodel()
437 local string defaultmodel;
438 local float defaultskin;
443 if(cvar("sv_defaultcharacter") == 1) {
448 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
449 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
452 if(defaultmodel == "")
454 defaultmodel = cvar_string("sv_defaultplayermodel");
455 defaultskin = cvar("sv_defaultplayerskin");
459 if(defaultmodel != "")
461 if (defaultmodel != self.model)
465 setmodel_lod (self, defaultmodel);
466 setsize (self, m1, m2);
469 self.skin = defaultskin;
471 if (self.playermodel != self.model)
473 self.playermodel = CheckPlayerModel(self.playermodel);
476 setmodel_lod (self, self.playermodel);
477 setsize (self, m1, m2);
480 self.skin = RestrictSkin(stof(self.playerskin));
484 if(strlen(cvar_string("sv_defaultplayercolors")))
485 if(self.clientcolors != cvar("sv_defaultplayercolors"))
486 setcolor(self, cvar("sv_defaultplayercolors"));
493 Called when a client spawns in the server
496 void PutClientInServer (void)
498 if(clienttype(self) == CLIENTTYPE_BOT)
500 self.classname = "player";
502 else if(clienttype(self) == CLIENTTYPE_REAL)
505 WriteByte(MSG_ONE, SVC_SETVIEW);
506 WriteEntity(MSG_ONE, self);
509 // player is dead and becomes observer
510 if(g_lms && self.frags < 1)
511 self.classname = "observer";
515 self.classname = "observer";
517 if(self.classname == "player") {
520 spot = SelectSpawnPoint (FALSE);
523 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
524 return; // spawn failed
527 RemoveGrapplingHook(self); // Wazat's Grappling Hook
529 self.classname = "player";
530 self.iscreature = TRUE;
531 self.movetype = MOVETYPE_WALK;
532 self.solid = SOLID_SLIDEBOX;
533 self.flags = FL_CLIENT;
534 self.takedamage = DAMAGE_AIM;
536 self.effects = EF_FULLBRIGHT;
539 self.air_finished = time + 12;
542 self.ammo_shells = start_ammo_shells;
543 self.ammo_nails = start_ammo_nails;
544 self.ammo_rockets = start_ammo_rockets;
545 self.ammo_cells = start_ammo_cells;
546 self.health = start_health;
547 self.armorvalue = start_armorvalue;
548 self.items = start_items;
549 self.switchweapon = start_switchweapon;
550 self.cnt = start_switchweapon;
552 self.jump_interval = time;
554 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
555 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
556 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
557 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
558 //extend the pause of rotting if client was reset at the beginning of the countdown
559 if(!cvar("sv_ready_restart_after_countdown") && time < restart_countdown) {
560 self.spawnshieldtime += RESTART_COUNTDOWN;
561 self.pauserotarmor_finished += RESTART_COUNTDOWN;
562 self.pauserothealth_finished += RESTART_COUNTDOWN;
563 self.pauseregen_finished += RESTART_COUNTDOWN;
565 self.damageforcescale = 2;
572 self.pain_finished = 0;
573 self.strength_finished = 0;
574 self.invincible_finished = 0;
576 //self.speed_finished = 0;
577 //self.slowmo_finished = 0;
578 // players have no think function
579 self.think = SUB_Null;
585 self.deadflag = DEAD_NO;
587 self.angles = spot.angles;
589 self.angles_z = 0; // never spawn tilted even if the spot says to
590 self.fixangle = TRUE; // turn this way immediately
591 self.velocity = '0 0 0';
592 self.avelocity = '0 0 0';
593 self.punchangle = '0 0 0';
594 self.punchvector = '0 0 0';
595 self.oldvelocity = self.velocity;
600 self.customizeentityforclient = Client_customizeentityforclient;
606 self.view_ofs = PL_VIEW_OFS;
607 setsize (self, PL_MIN, PL_MAX);
608 self.spawnorigin = spot.origin;
609 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
610 // don't reset back to last position, even if new position is stuck in solid
611 self.oldorigin = self.origin;
615 Spawnqueue_Remove(self);
616 Spawnqueue_Mark(self);
619 self.event_damage = PlayerDamage;
621 self.bot_attack = TRUE;
623 self.statdraintime = time + 5;
624 self.button0 = self.button1 = self.button2 = self.button3 = 0;
626 if(self.killcount == -666) {
633 self.cnt = WEP_LASER;
634 self.nixnex_lastchange_id = -1;
636 CL_SpawnWeaponentity();
637 self.alpha = default_player_alpha;
638 self.colormod = '1 1 1' * cvar("g_player_brightness");
639 self.exteriorweaponentity.alpha = default_weapon_alpha;
641 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
642 self.lms_traveled_distance = 0;
643 self.speedrunning = FALSE;
645 if(cvar("spawn_debug"))
647 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
648 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
651 //stuffcmd(self, "chase_active 0");
652 //stuffcmd(self, "set viewsize $tmpviewsize \n");
654 if (cvar("g_spawnsound"))
655 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
658 if(self.team == assault_attacker_team)
659 centerprint(self, "You are attacking!\n");
661 centerprint(self, "You are defending!\n");
664 } else if(self.classname == "observer") {
665 PutObserverInServer ();
674 void SetNewParms (void)
684 void SetChangeParms (void)
693 Called when a client types 'kill' in the console
697 void ClientKill_Now_TeamChange()
699 if(self.killindicator_teamchange == -1)
702 JoinBestTeam( self, FALSE, FALSE );
706 SV_ChangeTeam(self.killindicator_teamchange - 1);
710 void ClientKill_Now()
712 if(self.killindicator_teamchange)
713 ClientKill_Now_TeamChange();
716 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
718 void KillIndicator_Think()
720 if (!self.owner.modelindex)
722 self.owner.killindicator = world;
730 ClientKill_Now(); // no oldself needed
736 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
737 if(clienttype(self.owner) == CLIENTTYPE_REAL)
740 play2(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
741 if(self.owner.killindicator_teamchange)
743 if(self.owner.killindicator_teamchange == -1)
744 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
746 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
749 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
751 self.nextthink = time + 1;
756 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
760 killtime = cvar("g_balance_kill_delay");
762 self.killindicator_teamchange = targetteam;
764 if(!self.killindicator)
766 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
772 self.killindicator = spawn();
773 self.killindicator.owner = self;
774 self.killindicator.scale = 0.5;
775 setattachment(self.killindicator, self, "");
776 setorigin(self.killindicator, '0 0 52');
777 self.killindicator.think = KillIndicator_Think;
778 self.killindicator.nextthink = time + (self.lip) * 0.05;
779 self.killindicator.cnt = ceil(killtime);
780 self.killindicator.count = bound(0, ceil(killtime), 10);
781 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
783 for(e = world; (e = find(e, classname, "body")) != world; )
787 e.killindicator = spawn();
788 e.killindicator.owner = e;
789 e.killindicator.scale = 0.5;
790 setattachment(e.killindicator, e, "");
791 setorigin(e.killindicator, '0 0 52');
792 e.killindicator.think = KillIndicator_Think;
793 e.killindicator.nextthink = time + (e.lip) * 0.05;
794 e.killindicator.cnt = ceil(killtime);
799 if(self.killindicator)
802 self.killindicator.colormod = TeamColor(targetteam);
804 self.killindicator.colormod = '0 0 0';
808 void ClientKill (void)
810 ClientKill_TeamChange(0);
813 void DoTeamChange(float destteam)
816 if(!cvar("teamplay"))
819 SetPlayerColors(self, destteam);
822 if(self.classname == "player")
825 CheckAllowedTeams(self);
826 t = FindSmallestTeam(self, TRUE);
829 case COLOR_TEAM1: c0 = c1; break;
830 case COLOR_TEAM2: c0 = c2; break;
831 case COLOR_TEAM3: c0 = c3; break;
832 case COLOR_TEAM4: c0 = c4; break;
839 destteam = COLOR_TEAM1;
843 destteam = COLOR_TEAM2;
847 destteam = COLOR_TEAM3;
851 destteam = COLOR_TEAM4;
857 if(destteam == self.team && !self.killindicator)
859 ClientKill_TeamChange(destteam);
862 void FixClientCvars(entity e)
864 // send prediction settings to the client
865 stuffcmd(e, "\nin_bindmap 0 0\n");
867 * we no longer need to stuff this. Remove this comment block if you feel
868 * 2.3 and higher (or was it 2.2.3?) don't need these any more
869 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
870 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
871 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
872 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
873 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
874 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
875 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
876 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
877 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
878 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
879 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
880 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
881 stuffcmd(e, "cl_movement_edgefriction 1\n");
889 Called when a client connects to the server
892 string ColoredTeamName(float t);
893 //void dom_player_join_team(entity pl);
894 void ClientConnect (void)
899 if(Ban_IsClientBanned(self))
901 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
907 self.classname = "player_joining";
908 self.flags = self.flags | FL_CLIENT;
909 self.version_nagtime = time + 10 + random() * 10;
913 dprint("BUG player count is lower than zero, this cannot happen!\n");
920 // dom_player_join_team(self);
922 //JoinBestTeam(self, FALSE, FALSE);
924 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
925 self.classname = "observer";
927 self.classname = "player";
928 campaign_bots_may_start = 1;
931 self.playerid = (playerid_last = playerid_last + 1);
932 if(cvar("sv_eventlog"))
934 if(clienttype(self) == CLIENTTYPE_REAL)
938 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
939 s = strcat(":team:", ftos(self.playerid), ":");
940 s = strcat(s, ftos(self.team));
941 GameLogEcho(s, FALSE);
943 self.netname_previous = strzone(self.netname);
945 //stuffcmd(self, "set tmpviewsize $viewsize \n");
947 bprint ("^4",self.netname);
948 bprint ("^4 connected");
950 if(g_domination || g_ctf)
952 bprint(" and joined the ");
953 bprint(ColoredTeamName(self.team));
958 self.welcomemessage_time = 0;
960 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
961 // TODO: is this being used for anything else than cd tracks?
962 // Remember: SVC_CDTRACK exists. Maybe it should be used.
964 stuffcmd(self, "cl_particles_reloadeffects\n");
966 FixClientCvars(self);
968 // spawnfunc_waypoint sprites
969 WaypointSprite_InitClient(self);
971 // Wazat's grappling hook
972 SetGrappleHookBindings();
974 // get autoswitch state from player when he toggles it
975 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
977 // get version info from player
978 stuffcmd(self, "cmd clientversion $gameversion\n");
980 // send all weapon info strings
981 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
983 while (wep <= WEP_LAST)
985 weapon_action(wep, WR_REGISTER);
989 // get other cvars from player
992 // set cvar for team scoreboard
996 t = cvar("teamplay");
997 // 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
998 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1001 stuffcmd(self, "set teamplay 0\n");
1003 // notify about available teams
1006 CheckAllowedTeams(self);
1007 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1008 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1011 stuffcmd(self, "set _teams_available 0\n");
1013 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1017 self.frags = LMS_NewPlayerLives();
1023 self.classname = "observer";
1024 Spawnqueue_Insert(self);
1027 bot_relinkplayerlist();
1029 self.spectatortime = time;
1032 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1035 self.jointime = time;
1036 self.allowedTimeouts = cvar("sv_timeout_number");
1043 Called when a client disconnects from the server
1046 void(entity e) DropFlag;
1047 .entity chatbubbleentity;
1048 .entity teambubbleentity;
1049 void ClientDisconnect (void)
1052 if(cvar("sv_eventlog"))
1053 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
1054 bprint ("^4",self.netname);
1055 bprint ("^4 disconnected\n");
1057 if (self.chatbubbleentity)
1059 remove (self.chatbubbleentity);
1060 self.chatbubbleentity = world;
1063 if (self.teambubbleentity)
1065 remove (self.teambubbleentity);
1066 self.teambubbleentity = world;
1069 if (self.killindicator)
1071 remove (self.killindicator);
1072 self.killindicator = world;
1075 WaypointSprite_PlayerGone();
1078 kh_Key_DropAll(self, TRUE);
1080 if(self.flagcarried)
1081 DropFlag(self.flagcarried);
1083 DistributeFragsAmongTeam(self, self.team, 1);
1086 self.flags = self.flags - (self.flags & FL_CLIENT);
1087 bot_relinkplayerlist();
1091 if(self.weaponentity)
1092 if(self.weaponentity.lasertarget)
1093 remove(self.weaponentity.lasertarget);
1097 Spawnqueue_Unmark(self);
1098 Spawnqueue_Remove(self);
1101 if(self.netname_previous)
1102 strunzone(self.netname_previous);
1109 void() ChatBubbleThink =
1111 self.nextthink = time;
1112 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1114 self.owner.chatbubbleentity = world;
1118 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1119 if (self.owner.buttonchat && !self.owner.deadflag)
1120 self.model = self.mdl;
1125 void() UpdateChatBubble =
1127 if (!self.modelindex)
1129 // spawn a chatbubble entity if needed
1130 if (!self.chatbubbleentity)
1132 self.chatbubbleentity = spawn();
1133 self.chatbubbleentity.owner = self;
1134 self.chatbubbleentity.exteriormodeltoclient = self;
1135 self.chatbubbleentity.think = ChatBubbleThink;
1136 self.chatbubbleentity.nextthink = time;
1137 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1138 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1139 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1140 self.chatbubbleentity.model = "";
1141 self.chatbubbleentity.effects = EF_LOWPRECISION;
1146 void() TeamBubbleThink =
1148 self.nextthink = time;
1149 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1151 self.owner.teambubbleentity = world;
1155 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1156 if (self.owner.buttonchat || self.owner.deadflag || self.owner.killindicator)
1159 self.model = self.mdl;
1163 float() TeamBubble_customizeentityforclient
1165 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1168 void() UpdateTeamBubble =
1170 if (!self.modelindex || !cvar("teamplay"))
1172 // spawn a teambubble entity if needed
1173 if (!self.teambubbleentity && cvar("teamplay"))
1175 self.teambubbleentity = spawn();
1176 self.teambubbleentity.owner = self;
1177 self.teambubbleentity.exteriormodeltoclient = self;
1178 self.teambubbleentity.think = TeamBubbleThink;
1179 self.teambubbleentity.nextthink = time;
1180 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1181 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1182 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1183 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1184 self.teambubbleentity.mdl = self.teambubbleentity.model;
1185 self.teambubbleentity.model = self.teambubbleentity.mdl;
1186 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1187 self.teambubbleentity.effects = EF_LOWPRECISION;
1191 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1192 // added to the model skins
1193 /*void() UpdateColorModHack =
1196 c = self.clientcolors & 15;
1197 // LordHavoc: only bothering to support white, green, red, yellow, blue
1198 if (teamplay == 0) self.colormod = '0 0 0';
1199 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1200 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1201 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1202 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1203 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1204 else self.colormod = '1 1 1';
1210 self.effects |= EF_NODRAW; // prevent another CopyBody
1211 PutClientInServer();
1215 * When sv_timeout is used this function returs strings like
1216 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1217 * Called by centerprint functions
1218 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1220 string getTimeoutText(float addOneSecond) {
1221 if (!cvar("sv_timeout") || !timeoutStatus)
1224 local string retStr;
1225 if (timeoutStatus == 1) {
1226 if (addOneSecond == 1) {
1227 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1230 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1234 else if (timeoutStatus == 2) {
1236 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1237 //don't show messages like "Timeout ends in 0 seconds"...
1238 if ((remainingTimeoutTime + 1) > 0)
1244 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1245 //don't show messages like "Timeout ends in 0 seconds"...
1246 if (remainingTimeoutTime > 0)
1255 void player_powerups (void)
1259 if (self.items & IT_STRENGTH)
1261 if (time > self.strength_finished)
1263 if (g_minstagib_invis_alpha > 0)
1265 self.alpha = default_player_alpha;
1266 self.exteriorweaponentity.alpha = default_weapon_alpha;
1267 self.effects = self.effects | EF_FULLBRIGHT;
1271 self.effects -= self.effects & EF_NODRAW;
1273 self.items = self.items - (self.items & IT_STRENGTH);
1274 sprint(self, "^3Invisibility has worn off\n");
1279 if (time < self.strength_finished)
1281 if (g_minstagib_invis_alpha > 0)
1283 self.alpha = g_minstagib_invis_alpha;
1284 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1285 self.effects -= self.effects & EF_FULLBRIGHT;
1289 self.effects = self.effects | EF_NODRAW;
1291 self.items = self.items | IT_STRENGTH;
1292 sprint(self, "^3You are invisible\n");
1296 if (self.items & IT_INVINCIBLE)
1298 if (time > self.invincible_finished)
1300 self.items = self.items - (self.items & IT_INVINCIBLE);
1301 sprint(self, "^3Speed has worn off\n");
1306 if (time < self.invincible_finished)
1308 self.items = self.items | IT_INVINCIBLE;
1309 sprint(self, "^3You are on speed\n");
1315 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1316 if (self.items & IT_STRENGTH)
1318 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1319 if (time > self.strength_finished)
1321 self.items = self.items - (self.items & IT_STRENGTH);
1322 sprint(self, "^3Strength has worn off\n");
1327 if (time < self.strength_finished)
1329 self.items = self.items | IT_STRENGTH;
1330 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1333 if (self.items & IT_INVINCIBLE)
1335 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1336 if (time > self.invincible_finished)
1338 self.items = self.items - (self.items & IT_INVINCIBLE);
1339 sprint(self, "^3Shield has worn off\n");
1344 if (time < self.invincible_finished)
1346 self.items = self.items | IT_INVINCIBLE;
1347 sprint(self, "^3Shield surrounds you\n");
1351 if (cvar("g_fullbrightplayers"))
1352 self.effects = self.effects | EF_FULLBRIGHT;
1354 // midair gamemode: damage only while in the air
1355 // if in midair mode, being on ground grants temporary invulnerability
1356 // (this is so that multishot weapon don't clear the ground flag on the
1357 // first damage in the frame, leaving the player vulnerable to the
1358 // remaining hits in the same frame)
1359 if (self.flags & FL_ONGROUND)
1361 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1363 if (time < self.spawnshieldtime)
1364 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1367 float CalcRegen(float current, float stable, float regenfactor)
1369 if(current > stable)
1371 else if(current > stable - 0.25) // when close enough, "snap"
1374 return min(stable, current + (stable - current) * regenfactor * frametime);
1377 void player_regen (void)
1379 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1380 maxh = cvar("g_balance_health_stable");
1381 maxa = cvar("g_balance_armor_stable");
1382 limith = cvar("g_balance_health_limit");
1383 limita = cvar("g_balance_armor_limit");
1385 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1388 max_mod = regen_mod = rot_mod = limit_mod = 1;
1390 if (self.runes & RUNE_REGEN)
1392 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1394 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1395 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1396 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1400 regen_mod = cvar("g_balance_rune_regen_regenrate");
1401 max_mod = cvar("g_balance_rune_regen_hpmod");
1402 limit_mod = cvar("g_balance_rune_regen_limitmod");
1405 else if (self.runes & CURSE_VENOM)
1407 max_mod = cvar("g_balance_curse_venom_hpmod");
1408 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1409 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1411 rot_mod = cvar("g_balance_curse_venom_rotrate");
1412 limit_mod = cvar("g_balance_curse_venom_limitmod");
1413 //if (!self.runes & RUNE_REGEN)
1414 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1416 maxh = maxh * max_mod;
1417 //maxa = maxa * max_mod;
1418 limith = limith * limit_mod;
1419 limita = limita * limit_mod;
1421 if (self.armorvalue > maxa)
1423 if (time > self.pauserotarmor_finished)
1425 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1426 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1429 else if (self.armorvalue < maxa)
1431 if (time > self.pauseregen_finished)
1433 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1434 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1437 if (self.health > maxh)
1439 if (time > self.pauserothealth_finished)
1441 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1442 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1445 else if (self.health < maxh)
1447 if (time > self.pauseregen_finished)
1449 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1450 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1454 if (self.health > limith)
1455 self.health = limith;
1456 if (self.armorvalue > limita)
1457 self.armorvalue = limita;
1459 // if player rotted to death... die!
1461 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1465 ======================
1466 spectate mode routines
1467 ======================
1469 void SpectateCopy(entity spectatee) {
1470 self.armortype = spectatee.armortype;
1471 self.armorvalue = spectatee.armorvalue;
1472 self.currentammo = spectatee.currentammo;
1473 self.effects = spectatee.effects;
1474 self.health = spectatee.health;
1476 self.items = spectatee.items;
1477 self.punchangle = spectatee.punchangle;
1478 self.view_ofs = spectatee.view_ofs;
1479 self.v_angle = spectatee.v_angle;
1480 self.viewzoom = spectatee.viewzoom;
1481 self.velocity = spectatee.velocity;
1482 self.dmg_take = spectatee.dmg_take;
1483 self.dmg_save = spectatee.dmg_save;
1484 self.dmg_inflictor = spectatee.dmg_inflictor;
1485 self.angles = spectatee.v_angle;
1486 self.fixangle = TRUE;
1487 setorigin(self, spectatee.origin);
1488 setsize(self, spectatee.mins, spectatee.maxs);
1491 float SpectateUpdate() {
1495 if (self == self.enemy)
1498 if(self.enemy.flags & FL_NOTARGET)
1501 SpectateCopy(self.enemy);
1506 float SpectateNext() {
1507 other = find(self.enemy, classname, "player");
1509 other = find(other, classname, "player");
1514 if(self.enemy.classname == "player") {
1516 WriteByte(MSG_ONE, SVC_SETVIEW);
1517 WriteEntity(MSG_ONE, self.enemy);
1518 self.wantswelcomemessage = 1;
1519 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1520 if(!SpectateUpdate())
1521 PutObserverInServer();
1530 ShowRespawnCountdown()
1532 Update a respawn countdown display.
1535 void ShowRespawnCountdown()
1538 if(self.deadflag == DEAD_NO) // just respawned?
1542 number = ceil(self.death_time - time);
1545 if(number <= self.respawn_countdown)
1547 self.respawn_countdown = number - 1;
1548 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
1549 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1554 void LeaveSpectatorMode()
1556 if(isJoinAllowed()) {
1557 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1558 self.classname = "player";
1559 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1560 JoinBestTeam(self, FALSE, TRUE);
1561 if(cvar("g_campaign"))
1562 campaign_bots_may_start = 1;
1563 PutClientInServer();
1564 if(!(self.flags & FL_NOTARGET))
1565 bprint ("^4", self.netname, "^4 is playing now\n");
1566 centerprint(self,"");
1569 stuffcmd(self,"menu_showteamselect\n");
1574 //player may not join because of g_maxplayers is set
1575 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1580 * Determines whether the player is allowed to join. This depends on cvar
1581 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1582 * it checks whether the number of currently playing players exceeds g_maxplayers.
1583 * @return bool TRUE if the player is allowed to join, false otherwise
1585 float isJoinAllowed() {
1586 if (!cvar("g_maxplayers"))
1590 local float currentlyPlaying;
1591 FOR_EACH_REALPLAYER(e) {
1592 if(e.classname == "player")
1593 currentlyPlaying += 1;
1595 if(currentlyPlaying < cvar("g_maxplayers"))
1602 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1603 * g_maxplayers_spectator_blocktime seconds
1605 void checkSpectatorBlock() {
1606 if(self.classname == "spectator" || self.classname == "observer") {
1607 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1608 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1614 float vercmp_recursive(string v1, string v2)
1620 dot1 = strstrofs(v1, ".", 0);
1621 dot2 = strstrofs(v2, ".", 0);
1625 s1 = substring(v1, 0, dot1);
1629 s2 = substring(v2, 0, dot2);
1631 r = stof(s1) - stof(s2);
1635 r = strcasecmp(s1, s2);
1648 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1651 float vercmp(string v1, string v2)
1653 if(strcasecmp(v1, v2) == 0) // early out check
1655 return vercmp_recursive(v1, v2);
1658 void ObserverThink()
1660 if (self.flags & FL_JUMPRELEASED) {
1661 if (self.button2 && self.version == cvar("gameversion")) {
1662 self.welcomemessage_time = 0;
1663 self.flags = self.flags - FL_JUMPRELEASED;
1664 LeaveSpectatorMode();
1666 } else if(self.button0 && self.version == cvar("gameversion")) {
1667 self.welcomemessage_time = 0;
1668 self.flags = self.flags - FL_JUMPRELEASED;
1669 if(SpectateNext() == 1) {
1670 self.classname = "spectator";
1674 if (!(self.button0 || self.button2)) {
1675 self.flags = self.flags | FL_JUMPRELEASED;
1679 self.wantswelcomemessage = 0;
1680 if(self.wantswelcomemessage)
1681 PrintWelcomeMessage(self);
1684 void SpectatorThink()
1686 if (self.flags & FL_JUMPRELEASED) {
1687 if (self.button2 && self.version == cvar("gameversion")) {
1688 self.welcomemessage_time = 0;
1689 self.flags = self.flags - FL_JUMPRELEASED;
1690 LeaveSpectatorMode();
1692 } else if(self.button0) {
1693 self.welcomemessage_time = 0;
1694 self.flags = self.flags - FL_JUMPRELEASED;
1695 if(SpectateNext() == 1) {
1696 self.classname = "spectator";
1698 self.classname = "observer";
1699 PutClientInServer();
1701 } else if (self.button3) {
1702 self.welcomemessage_time = 0;
1703 self.flags = self.flags - FL_JUMPRELEASED;
1704 self.classname = "observer";
1705 PutClientInServer();
1707 if(!SpectateUpdate())
1708 PutObserverInServer();
1711 if (!(self.button0 || self.button3)) {
1712 self.flags = self.flags | FL_JUMPRELEASED;
1716 self.wantswelcomemessage = 0;
1717 if(self.wantswelcomemessage)
1718 PrintWelcomeMessage(self);
1719 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1726 Called every frame for each client before the physics are run
1729 void() ctf_setstatus;
1730 .float vote_nagtime;
1731 void PlayerPreThink (void)
1734 checkSpectatorBlock();
1736 if(self.netname_previous != self.netname)
1738 if(cvar("sv_eventlog"))
1739 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname), TRUE);
1740 if(self.netname_previous)
1741 strunzone(self.netname_previous);
1742 self.netname_previous = strzone(self.netname);
1746 if(self.version_nagtime)
1747 if(self.cvar_g_nexuizversion)
1748 if(time > self.version_nagtime)
1750 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1752 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
1754 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
1755 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
1760 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
1763 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n");
1764 sprint(self, strcat("\{1}^1NOTE: ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n"));
1768 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
1769 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
1773 self.version_nagtime = 0;
1777 if(self.cvar_scr_centertime)
1778 if(time > self.vote_nagtime)
1781 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1785 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1787 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1788 self.max_armorvalue = 0;
1792 antilag_record(self);
1794 if(self.classname == "player") {
1795 // if(self.netname == "Wazat")
1796 // bprint(self.classname, "\n");
1798 CheckRules_Player();
1801 PrintWelcomeMessage(self);
1803 if(g_lms || !cvar("sv_spectate"))
1804 if((time - self.jointime) <= cvar("welcome_message_time"))
1805 PrintWelcomeMessage(self);
1807 if (intermission_running)
1809 IntermissionThink (); // otherwise a button could be missed between
1810 return; // the think tics
1813 if(self.teleport_time)
1814 if(time > self.teleport_time)
1816 self.teleport_time = 0;
1817 self.effects = self.effects - (self.effects & EF_NODRAW);
1818 if(self.weaponentity)
1819 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1822 Nixnex_GiveCurrentWeapon();
1824 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1825 UpdateSelectedPlayer();
1827 //don't allow the player to turn around while game is paused!
1828 if(timeoutStatus == 2) {
1829 self.v_angle = self.lastV_angle;
1830 self.angles = self.lastV_angle;
1831 self.fixangle = TRUE;
1834 if (self.deadflag != DEAD_NO)
1836 float button_pressed, force_respawn;
1838 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1839 force_respawn = (g_lms || cvar("g_forced_respawn"));
1840 if (self.deadflag == DEAD_DYING)
1843 self.deadflag = DEAD_RESPAWNING;
1844 else if(!button_pressed)
1845 self.deadflag = DEAD_DEAD;
1847 else if (self.deadflag == DEAD_DEAD)
1850 self.deadflag = DEAD_RESPAWNABLE;
1852 else if (self.deadflag == DEAD_RESPAWNABLE)
1855 self.deadflag = DEAD_RESPAWNING;
1857 else if (self.deadflag == DEAD_RESPAWNING)
1859 if(time > self.death_time)
1861 self.death_time = time + 1; // only retry once a second
1865 ShowRespawnCountdown();
1869 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1873 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1874 dist = self.oldorigin - self.origin;
1876 self.lms_traveled_distance += fabs(vlen(dist));
1878 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1880 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1881 self.lms_traveled_distance = 0;
1884 if(time > self.lms_nextcheck)
1886 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1887 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1889 centerprint(self, cvar_string("g_lms_campcheck_message"));
1890 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1891 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1892 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');
1894 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1895 self.lms_traveled_distance = 0;
1899 if (self.button5 && !self.hook.state)
1904 self.view_ofs = PL_CROUCH_VIEW_OFS;
1905 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1906 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1913 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1914 if (!trace_startsolid)
1916 self.crouch = FALSE;
1917 self.view_ofs = PL_VIEW_OFS;
1918 setsize (self, PL_MIN, PL_MAX);
1925 GrapplingHookFrame();
1930 float zoomfactor, zoomspeed, zoomdir;
1931 zoomfactor = self.cvar_cl_zoomfactor;
1932 if(zoomfactor < 1 || zoomfactor > 16)
1934 zoomspeed = self.cvar_cl_zoomspeed;
1935 if(zoomspeed >= 0) // < 0 is instant zoom
1936 if(zoomspeed < 0.5 || zoomspeed > 16)
1939 zoomdir = self.button4;
1941 if(self.weapon == WEP_NEX)
1946 self.has_zoomed = 1;
1950 if(zoomspeed <= 0) // instant zoom
1953 self.viewzoom = 1 / zoomfactor;
1959 // geometric zoom would be:
1960 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1961 // however, testing showed that arithmetic/harmonic zoom works better
1963 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1964 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1965 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1967 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1968 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1969 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1973 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1981 minstagib_ammocheck();
1986 //self.angles_y=self.v_angle_y + 90; // temp
1988 //if (TetrisPreFrame()) return;
1989 } else if(gameover) {
1990 if (intermission_running)
1991 IntermissionThink (); // otherwise a button could be missed between
1993 } else if(self.classname == "observer") {
1995 } else if(self.classname == "spectator") {
2005 Called every frame for each client after the physics are run
2008 void PlayerPostThink (void)
2010 // Savage: Check for nameless players
2011 if (strlen(self.netname) < 1) {
2012 self.netname = "Player";
2013 stuffcmd(self, "seta _cl_name Player\n");
2016 if(self.classname == "player") {
2017 CheckRules_Player();
2022 if (intermission_running)
2023 return; // intermission or finale
2025 //PrintWelcomeMessage(self);
2026 //if (TetrisPostFrame()) return;
2028 // restart countdown
2029 if (restart_countdown) {
2030 if(time < restart_countdown) {
2031 if (!cvar("sv_ready_restart_after_countdown"))
2033 self.movetype = MOVETYPE_NONE;
2034 self.velocity = '0 0 0';
2035 self.avelocity = '0 0 0';
2036 self.movement = '0 0 0';
2041 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2042 if (!cvar("sv_ready_restart_after_countdown"))
2044 if(self.movetype == MOVETYPE_NONE)
2046 self.movetype = MOVETYPE_WALK;
2052 } else if (self.classname == "observer") {
2054 } else if (self.classname == "spectator") {