1 // let's abuse an existing field
2 #define SPAWNPOINT_SCORE frags
4 .float wantswelcomemessage;
5 .string netname_previous;
7 void spawnfunc_info_player_survivor (void)
9 spawnfunc_info_player_deathmatch();
12 void spawnfunc_info_player_start (void)
14 spawnfunc_info_player_deathmatch();
17 void spawnfunc_info_player_deathmatch (void)
19 self.classname = "info_player_deathmatch";
20 relocate_spawnpoint();
28 self.team = activator.team;
29 some_spawn_has_been_used = 1;
34 // -1 if a spawn can't be used
35 // otherwise, a weight of the spawnpoint
36 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
38 float shortest, thisdist;
41 // filter out spots for the wrong team
43 if(spot.team != teamcheck)
46 // filter out spots for assault
47 if(spot.target != "") {
49 ent = find(world, targetname, spot.target);
53 if(ent.classname == "target_objective")
54 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
56 else if(ent.classname == "trigger_race_checkpoint")
57 if(max(0, self.race_checkpoint) != ent.cnt)
58 // checkpoint -1 players (freshly spawned) spawn close to finish!
60 ent = find(ent, targetname, spot.target);
65 shortest = vlen(world.maxs - world.mins);
66 for(player = playerlist; player; player = player.chain)
69 thisdist = vlen(player.origin - spot.origin);
70 if (thisdist < shortest)
78 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
80 local entity spot, spotlist, spotlistend;
87 for(spot = firstspot; spot; spot = spot.chain)
89 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
91 if(cvar("spawn_debugview"))
93 setmodel(spot, "models/runematch/rune.mdl");
94 if(spot.SPAWNPOINT_SCORE < mindist)
96 spot.colormod = '1 0 0';
101 spot.colormod = '0 1 0';
102 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
106 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
108 if(spot.SPAWNPOINT_SCORE < mindist)
110 // too short distance
111 spawn_allgood = FALSE;
116 spawn_allbad = FALSE;
119 spotlistend.chain = spot;
126 if(spot.team != teamcheck)
127 error("invalid spawn added");
129 print("added ", etos(spot), "\n");
135 spotlistend.chain = world;
140 for(e = spotlist; e; e = e.chain)
142 print("seen ", etos(e), "\n");
143 if(e.team != teamcheck)
144 error("invalid spawn found");
151 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
153 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
154 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
157 RandomSelection_Init();
158 for(spot = firstspot; spot; spot = spot.chain)
159 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
161 return RandomSelection_chosen_ent;
168 Finds a point to respawn
171 entity SelectSpawnPoint (float anypoint)
173 local float teamcheck;
174 local entity firstspot_new;
175 local entity spot, firstspot, playerlist;
177 spot = find (world, classname, "testplayerstart");
183 if(!anypoint && have_team_spawns)
184 teamcheck = self.team;
186 // get the list of players
187 playerlist = findchain(classname, "player");
188 // get the entire list of spots
189 firstspot = findchain(classname, "info_player_deathmatch");
190 // filter out the bad ones
191 // (note this returns the original list if none survived)
192 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
194 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
195 firstspot = firstspot_new;
197 // there is 50/50 chance of choosing a random spot or the furthest spot
198 // (this means that roughly every other spawn will be furthest, so you
199 // usually won't get fragged at spawn twice in a row)
200 if (arena_roundbased)
202 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
204 firstspot = firstspot_new;
205 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
207 else if (random() > cvar("g_spawn_furthest"))
208 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
210 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
212 if(cvar("spawn_debugview"))
214 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
218 for(e = firstspot; e; e = e.chain)
219 if(e.team != teamcheck)
220 error("invalid spawn found");
225 if(cvar("spawn_debug"))
229 if(some_spawn_has_been_used)
230 return world; // team can't spawn any more, because of actions of other team
232 error("Cannot find a spawn point - please fix the map!");
243 Checks if the argument string can be a valid playermodel.
244 Returns a valid one in doubt.
247 string FallbackPlayerModel = "models/player/marine.zym";
248 string CheckPlayerModel(string plyermodel) {
249 if(strlen(plyermodel) < 4)
250 return FallbackPlayerModel;
251 if( substring(plyermodel,0,14) != "models/player/")
252 return FallbackPlayerModel;
253 else if(cvar("sv_servermodelsonly"))
255 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
256 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
257 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
258 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
259 return FallbackPlayerModel;
260 if(!fexists(plyermodel))
261 return FallbackPlayerModel;
268 Client_customizeentityforclient
273 float Client_customizeentityforclient()
275 #ifdef ALLOW_VARIABLE_LOD
277 // other: the player viewing me
281 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
284 if(other.cvar_cl_playerdetailreduction <= 0)
286 if(other.cvar_cl_playerdetailreduction <= -2)
287 self.modelindex = self.modelindex_lod2;
288 else if(other.cvar_cl_playerdetailreduction <= -1)
289 self.modelindex = self.modelindex_lod1;
291 self.modelindex = self.modelindex_lod0;
295 distance = vlen(self.origin - other.origin);
296 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
298 self.modelindex = self.modelindex_lod2;
300 self.modelindex = self.modelindex_lod1;
302 self.modelindex = self.modelindex_lod0;
309 void UpdatePlayerSounds();
310 void setmodel_lod(entity e, string modelname)
312 #ifdef ALLOW_VARIABLE_LOD
315 // FIXME: this only supports 3-letter extensions
316 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
320 setmodel(e, s); // players have high precision
321 self.modelindex_lod1 = self.modelindex;
324 self.modelindex_lod1 = -1;
326 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
330 setmodel(e, s); // players have high precision
331 self.modelindex_lod2 = self.modelindex;
334 self.modelindex_lod2 = -1;
336 precache_model(modelname);
337 setmodel(e, modelname); // players have high precision
338 self.modelindex_lod0 = self.modelindex;
340 if(self.modelindex_lod1 < 0)
341 self.modelindex_lod1 = self.modelindex;
343 if(self.modelindex_lod2 < 0)
344 self.modelindex_lod2 = self.modelindex;
346 precache_model(modelname);
347 setmodel(e, modelname); // players have high precision
349 player_setupanimsformodel();
350 UpdatePlayerSounds();
357 putting a client as observer in the server
360 void PutObserverInServer (void)
363 spot = SelectSpawnPoint (TRUE);
365 error("No spawnpoints for observers?!?\n");
366 RemoveGrapplingHook(self); // Wazat's Grappling Hook
368 if(clienttype(self) == CLIENTTYPE_REAL)
371 WriteByte(MSG_ONE, SVC_SETVIEW);
372 WriteEntity(MSG_ONE, self);
376 kh_Key_DropAll(self, TRUE);
379 DropFlag(self.flagcarried);
381 WaypointSprite_PlayerDead();
383 if(self.killcount != -666)
387 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
388 bprint ("^4", self.netname, "^4 has no more lives left\n");
390 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
393 bprint ("^4", self.netname, "^4 is spectating now\n");
396 PlayerScore_Clear(self); // clear scores when needed
398 self.spectatortime = time;
400 self.classname = "observer";
402 self.takedamage = DAMAGE_NO;
403 self.solid = SOLID_NOT;
404 self.movetype = MOVETYPE_NOCLIP;
405 self.flags = FL_CLIENT | FL_NOTARGET;
406 self.armorvalue = 666;
408 self.armorvalue = cvar("g_balance_armor_start");
409 self.pauserotarmor_finished = 0;
410 self.pauserothealth_finished = 0;
411 self.pauseregen_finished = 0;
412 self.damageforcescale = 0;
419 self.pain_finished = 0;
420 self.strength_finished = 0;
421 self.invincible_finished = 0;
423 self.think = SUB_Null;
427 self.deadflag = DEAD_NO;
428 self.angles = spot.angles;
430 self.fixangle = TRUE;
433 self.view_ofs = PL_VIEW_OFS;
434 setorigin (self, spot.origin);
435 setsize (self, '0 0 0', '0 0 0');
436 self.oldorigin = self.origin;
441 self.weaponmodel = "";
442 self.weaponentity = world;
443 self.killcount = -666;
444 self.velocity = '0 0 0';
445 self.avelocity = '0 0 0';
446 self.punchangle = '0 0 0';
447 self.punchvector = '0 0 0';
448 self.oldvelocity = self.velocity;
449 self.customizeentityforclient = Client_customizeentityforclient;
451 self.wantswelcomemessage = 1;
454 race_PreparePlayer();
458 if(self.version_mismatch)
460 Spawnqueue_Unmark(self);
461 Spawnqueue_Remove(self);
465 Spawnqueue_Insert(self);
470 // Only if the player cannot play at all
471 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
480 float RestrictSkin(float s)
489 void FixPlayermodel()
491 local string defaultmodel;
492 local float defaultskin;
497 if(cvar("sv_defaultcharacter") == 1) {
502 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
503 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
506 if(defaultmodel == "")
508 defaultmodel = cvar_string("sv_defaultplayermodel");
509 defaultskin = cvar("sv_defaultplayerskin");
513 if(defaultmodel != "")
515 if (defaultmodel != self.model)
519 setmodel_lod (self, defaultmodel);
520 setsize (self, m1, m2);
523 self.skin = defaultskin;
525 if (self.playermodel != self.model)
527 self.playermodel = CheckPlayerModel(self.playermodel);
530 setmodel_lod (self, self.playermodel);
531 setsize (self, m1, m2);
534 self.skin = RestrictSkin(stof(self.playerskin));
538 if(strlen(cvar_string("sv_defaultplayercolors")))
539 if(self.clientcolors != cvar("sv_defaultplayercolors"))
540 setcolor(self, cvar("sv_defaultplayercolors"));
547 Called when a client spawns in the server
550 //void() ctf_playerchanged;
551 void PutClientInServer (void)
553 if(clienttype(self) == CLIENTTYPE_BOT)
555 self.classname = "player";
557 else if(clienttype(self) == CLIENTTYPE_REAL)
560 WriteByte(MSG_ONE, SVC_SETVIEW);
561 WriteEntity(MSG_ONE, self);
564 // player is dead and becomes observer
565 // FIXME fix LMS scoring for new system
568 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
569 self.classname = "observer";
574 self.classname = "observer";
576 if(self.classname == "player") {
580 if(self.killcount == -666)
581 race_PreparePlayer();
583 spot = SelectSpawnPoint (FALSE);
586 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
587 return; // spawn failed
590 RemoveGrapplingHook(self); // Wazat's Grappling Hook
592 self.classname = "player";
593 self.iscreature = TRUE;
594 self.movetype = MOVETYPE_WALK;
595 self.solid = SOLID_SLIDEBOX;
596 self.flags = FL_CLIENT;
597 self.takedamage = DAMAGE_AIM;
599 self.effects = EF_FULLBRIGHT;
602 self.air_finished = time + 12;
605 self.ammo_shells = start_ammo_shells;
606 self.ammo_nails = start_ammo_nails;
607 self.ammo_rockets = start_ammo_rockets;
608 self.ammo_cells = start_ammo_cells;
609 self.health = start_health;
610 self.armorvalue = start_armorvalue;
611 self.items = start_items;
612 self.switchweapon = start_switchweapon;
613 self.cnt = start_switchweapon;
615 self.jump_interval = time;
617 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
618 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
619 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
620 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
621 //extend the pause of rotting if client was reset at the beginning of the countdown
622 if(!cvar("sv_ready_restart_after_countdown") && time < restart_countdown) {
623 self.spawnshieldtime += RESTART_COUNTDOWN;
624 self.pauserotarmor_finished += RESTART_COUNTDOWN;
625 self.pauserothealth_finished += RESTART_COUNTDOWN;
626 self.pauseregen_finished += RESTART_COUNTDOWN;
628 self.damageforcescale = 2;
635 self.pain_finished = 0;
636 self.strength_finished = 0;
637 self.invincible_finished = 0;
639 //self.speed_finished = 0;
640 //self.slowmo_finished = 0;
641 // players have no think function
642 self.think = SUB_Null;
648 self.deadflag = DEAD_NO;
650 self.angles = spot.angles;
652 self.angles_z = 0; // never spawn tilted even if the spot says to
653 self.fixangle = TRUE; // turn this way immediately
654 self.velocity = '0 0 0';
655 self.avelocity = '0 0 0';
656 self.punchangle = '0 0 0';
657 self.punchvector = '0 0 0';
658 self.oldvelocity = self.velocity;
663 self.customizeentityforclient = Client_customizeentityforclient;
669 self.view_ofs = PL_VIEW_OFS;
670 setsize (self, PL_MIN, PL_MAX);
671 self.spawnorigin = spot.origin;
672 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
673 // don't reset back to last position, even if new position is stuck in solid
674 self.oldorigin = self.origin;
678 Spawnqueue_Remove(self);
679 Spawnqueue_Mark(self);
682 self.event_damage = PlayerDamage;
684 self.bot_attack = TRUE;
686 self.statdraintime = time + 5;
687 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
690 if(self.killcount != -666)
691 if(spot.target == "")
692 // let the player run without timing, if he did not spawn at a targetting spawnpoint
693 race_PreparePlayer();
695 if(self.killcount == -666) {
696 PlayerScore_Clear(self);
701 self.cnt = WEP_LASER;
702 self.nixnex_lastchange_id = -1;
704 CL_SpawnWeaponentity();
705 self.alpha = default_player_alpha;
706 self.colormod = '1 1 1' * cvar("g_player_brightness");
707 self.exteriorweaponentity.alpha = default_weapon_alpha;
709 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
710 self.lms_traveled_distance = 0;
711 self.speedrunning = FALSE;
713 if(cvar("spawn_debug"))
715 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
716 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
719 //stuffcmd(self, "chase_active 0");
720 //stuffcmd(self, "set viewsize $tmpviewsize \n");
722 if (cvar("g_spawnsound"))
723 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
726 if(self.team == assault_attacker_team)
727 centerprint(self, "You are attacking!\n");
729 centerprint(self, "You are defending!\n");
732 } else if(self.classname == "observer") {
733 PutObserverInServer ();
737 // ctf_playerchanged();
744 Send whatever CSQC needs NOW and cannot wait for SendServerInfo to happen...
747 void SendCSQCInfo(void)
749 if(clienttype(self) != CLIENTTYPE_REAL)
752 WriteByte(MSG_ONE, SVC_TEMPENTITY);
753 WriteByte(MSG_ONE, TE_CSQC_INIT);
754 WriteShort(MSG_ONE, CSQC_REVISION);
755 WriteByte(MSG_ONE, maxclients);
763 void SetNewParms (void)
765 // initialize parms for a new player
766 parm1 = -(86400 * 366);
774 void SetChangeParms (void)
776 // save parms for level change
777 parm1 = self.parm_idlesince - time;
785 void DecodeLevelParms (void)
788 self.parm_idlesince = parm1;
789 if(self.parm_idlesince == -(86400 * 366))
790 self.parm_idlesince = time;
797 Called when a client types 'kill' in the console
801 void ClientKill_Now_TeamChange()
803 if(self.killindicator_teamchange == -1)
806 JoinBestTeam( self, FALSE, FALSE );
810 SV_ChangeTeam(self.killindicator_teamchange - 1);
814 void ClientKill_Now()
816 if(self.killindicator_teamchange)
817 ClientKill_Now_TeamChange();
820 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
822 if(self.killindicator)
824 dprint("Cleaned up after a leaked kill indicator.\n");
825 remove(self.killindicator);
826 self.killindicator = world;
829 void KillIndicator_Think()
831 if (!self.owner.modelindex)
833 self.owner.killindicator = world;
841 ClientKill_Now(); // no oldself needed
847 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
848 if(clienttype(self.owner) == CLIENTTYPE_REAL)
851 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
852 if(self.owner.killindicator_teamchange)
854 if(self.owner.killindicator_teamchange == -1)
855 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
857 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
860 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
862 self.nextthink = time + 1;
867 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
871 killtime = cvar("g_balance_kill_delay");
873 self.killindicator_teamchange = targetteam;
875 if(!self.killindicator)
877 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
883 self.killindicator = spawn();
884 self.killindicator.owner = self;
885 self.killindicator.scale = 0.5;
886 setattachment(self.killindicator, self, "");
887 setorigin(self.killindicator, '0 0 52');
888 self.killindicator.think = KillIndicator_Think;
889 self.killindicator.nextthink = time + (self.lip) * 0.05;
890 self.killindicator.cnt = ceil(killtime);
891 self.killindicator.count = bound(0, ceil(killtime), 10);
892 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
894 for(e = world; (e = find(e, classname, "body")) != world; )
898 e.killindicator = spawn();
899 e.killindicator.owner = e;
900 e.killindicator.scale = 0.5;
901 setattachment(e.killindicator, e, "");
902 setorigin(e.killindicator, '0 0 52');
903 e.killindicator.think = KillIndicator_Think;
904 e.killindicator.nextthink = time + (e.lip) * 0.05;
905 e.killindicator.cnt = ceil(killtime);
910 if(self.killindicator)
913 self.killindicator.colormod = TeamColor(targetteam);
915 self.killindicator.colormod = '0 0 0';
919 void ClientKill (void)
921 ClientKill_TeamChange(0);
924 void DoTeamChange(float destteam)
927 if(!cvar("teamplay"))
930 SetPlayerColors(self, destteam);
933 if(self.classname == "player")
936 CheckAllowedTeams(self);
937 t = FindSmallestTeam(self, TRUE);
940 case COLOR_TEAM1: c0 = c1; break;
941 case COLOR_TEAM2: c0 = c2; break;
942 case COLOR_TEAM3: c0 = c3; break;
943 case COLOR_TEAM4: c0 = c4; break;
950 destteam = COLOR_TEAM1;
954 destteam = COLOR_TEAM2;
958 destteam = COLOR_TEAM3;
962 destteam = COLOR_TEAM4;
968 if(destteam == self.team && !self.killindicator)
970 ClientKill_TeamChange(destteam);
973 void FixClientCvars(entity e)
975 // send prediction settings to the client
976 stuffcmd(e, "\nin_bindmap 0 0\n");
978 * we no longer need to stuff this. Remove this comment block if you feel
979 * 2.3 and higher (or was it 2.2.3?) don't need these any more
980 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
981 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
982 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
983 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
984 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
985 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
986 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
987 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
988 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
989 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
990 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
991 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
992 stuffcmd(e, "cl_movement_edgefriction 1\n");
1000 Called when a client connects to the server
1003 //void ctf_clientconnect();
1004 string ColoredTeamName(float t);
1005 void DecodeLevelParms (void);
1006 //void dom_player_join_team(entity pl);
1007 void ClientConnect (void)
1012 if(self.flags & FL_CLIENT)
1014 print("Warning: ClientConnect, but already connected!\n");
1018 if(Ban_IsClientBanned(self))
1020 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
1028 self.classname = "player_joining";
1030 self.flags = self.flags | FL_CLIENT;
1031 self.version_nagtime = time + 10 + random() * 10;
1035 dprint("BUG player count is lower than zero, this cannot happen!\n");
1039 PlayerScore_Attach(self);
1041 bot_clientconnect();
1044 // dom_player_join_team(self);
1046 //JoinBestTeam(self, FALSE, FALSE);
1048 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1049 self.classname = "observer";
1051 self.classname = "player";
1052 campaign_bots_may_start = 1;
1055 self.playerid = (playerid_last = playerid_last + 1);
1056 if(cvar("sv_eventlog"))
1058 if(clienttype(self) == CLIENTTYPE_REAL)
1062 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
1063 s = strcat(":team:", ftos(self.playerid), ":");
1064 s = strcat(s, ftos(self.team));
1065 GameLogEcho(s, FALSE);
1067 self.netname_previous = strzone(self.netname);
1069 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1071 bprint ("^4",self.netname);
1072 bprint ("^4 connected");
1074 if(g_domination || g_ctf)
1076 bprint(" and joined the ");
1077 bprint(ColoredTeamName(self.team));
1082 self.welcomemessage_time = 0;
1084 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1085 // TODO: is this being used for anything else than cd tracks?
1086 // Remember: SVC_CDTRACK exists. Maybe it should be used.
1088 stuffcmd(self, "cl_particles_reloadeffects\n");
1090 FixClientCvars(self);
1092 // spawnfunc_waypoint sprites
1093 WaypointSprite_InitClient(self);
1095 // Wazat's grappling hook
1096 SetGrappleHookBindings();
1098 // get autoswitch state from player when he toggles it
1099 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1101 // get version info from player
1102 stuffcmd(self, "cmd clientversion $gameversion\n");
1104 // send all weapon info strings
1105 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
1107 while (wep <= WEP_LAST)
1109 weapon_action(wep, WR_REGISTER);
1113 // get other cvars from player
1116 // set cvar for team scoreboard
1120 t = cvar("teamplay");
1121 // 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
1122 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1125 stuffcmd(self, "set teamplay 0\n");
1127 // notify about available teams
1130 CheckAllowedTeams(self);
1131 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1132 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1135 stuffcmd(self, "set _teams_available 0\n");
1137 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1141 self.classname = "observer";
1142 Spawnqueue_Insert(self);
1146 ctf_clientconnect();
1152 bot_relinkplayerlist();
1154 self.spectatortime = time;
1157 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"));
1160 self.jointime = time;
1161 self.allowedTimeouts = cvar("sv_timeout_number");
1163 if(clienttype(self) == CLIENTTYPE_REAL)
1165 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1168 if(mapvote_initialized && !cvar("g_maplist_textonly"))
1170 MapVote_SendData(MSG_ONE);
1171 MapVote_UpdateData(MSG_ONE);
1173 ScoreInfo_Write(MSG_ONE);
1178 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1180 PlayerScore_Add(self, SP_LMS_RANK, 666);
1181 self.frags = -666; // FIXME do we still need this?
1190 Called when a client disconnects from the server
1193 void(entity e) DropFlag;
1194 .entity chatbubbleentity;
1195 .entity teambubbleentity;
1196 //void() ctf_clientdisconnect;
1197 void ClientDisconnect (void)
1201 if not(self.flags & FL_CLIENT)
1203 print("Warning: ClientDisconnect without ClientConnect\n");
1207 bot_clientdisconnect();
1212 if(cvar("sv_eventlog"))
1213 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
1214 bprint ("^4",self.netname);
1215 bprint ("^4 disconnected\n");
1217 if (self.chatbubbleentity)
1219 remove (self.chatbubbleentity);
1220 self.chatbubbleentity = world;
1223 if (self.teambubbleentity)
1225 remove (self.teambubbleentity);
1226 self.teambubbleentity = world;
1229 if (self.killindicator)
1231 remove (self.killindicator);
1232 self.killindicator = world;
1235 WaypointSprite_PlayerGone();
1238 kh_Key_DropAll(self, TRUE);
1240 if(self.flagcarried)
1241 DropFlag(self.flagcarried);
1244 self.flags = self.flags - (self.flags & FL_CLIENT);
1245 bot_relinkplayerlist();
1249 if(self.weaponentity)
1250 if(self.weaponentity.lasertarget)
1251 remove(self.weaponentity.lasertarget);
1255 Spawnqueue_Unmark(self);
1256 Spawnqueue_Remove(self);
1260 ctf_clientdisconnect();
1264 PlayerScore_Detach(self);
1266 if(self.netname_previous)
1267 strunzone(self.netname_previous);
1269 ClearPlayerSounds();
1277 void ChatBubbleThink()
1279 self.nextthink = time;
1280 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1282 self.owner.chatbubbleentity = world;
1286 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1287 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1288 self.model = self.mdl;
1293 void UpdateChatBubble()
1295 if (!self.modelindex)
1297 // spawn a chatbubble entity if needed
1298 if (!self.chatbubbleentity)
1300 self.chatbubbleentity = spawn();
1301 self.chatbubbleentity.owner = self;
1302 self.chatbubbleentity.exteriormodeltoclient = self;
1303 self.chatbubbleentity.think = ChatBubbleThink;
1304 self.chatbubbleentity.nextthink = time;
1305 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1306 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1307 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1308 self.chatbubbleentity.model = "";
1309 self.chatbubbleentity.effects = EF_LOWPRECISION;
1314 void TeamBubbleThink()
1316 self.nextthink = time;
1317 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1319 self.owner.teambubbleentity = world;
1323 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1324 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1327 self.model = self.mdl;
1331 float TeamBubble_customizeentityforclient()
1333 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1336 void UpdateTeamBubble()
1338 if (!self.modelindex || !cvar("teamplay"))
1340 // spawn a teambubble entity if needed
1341 if (!self.teambubbleentity && cvar("teamplay"))
1343 self.teambubbleentity = spawn();
1344 self.teambubbleentity.owner = self;
1345 self.teambubbleentity.exteriormodeltoclient = self;
1346 self.teambubbleentity.think = TeamBubbleThink;
1347 self.teambubbleentity.nextthink = time;
1348 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1349 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1350 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1351 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1352 self.teambubbleentity.mdl = self.teambubbleentity.model;
1353 self.teambubbleentity.model = self.teambubbleentity.mdl;
1354 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1355 self.teambubbleentity.effects = EF_LOWPRECISION;
1359 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1360 // added to the model skins
1361 /*void UpdateColorModHack()
1364 c = self.clientcolors & 15;
1365 // LordHavoc: only bothering to support white, green, red, yellow, blue
1366 if (teamplay == 0) self.colormod = '0 0 0';
1367 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1368 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1369 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1370 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1371 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1372 else self.colormod = '1 1 1';
1378 self.effects |= EF_NODRAW; // prevent another CopyBody
1379 PutClientInServer();
1383 * When sv_timeout is used this function returs strings like
1384 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1385 * Called by centerprint functions
1386 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1388 string getTimeoutText(float addOneSecond) {
1389 if (!cvar("sv_timeout") || !timeoutStatus)
1392 local string retStr;
1393 if (timeoutStatus == 1) {
1394 if (addOneSecond == 1) {
1395 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1398 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1402 else if (timeoutStatus == 2) {
1404 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1405 //don't show messages like "Timeout ends in 0 seconds"...
1406 if ((remainingTimeoutTime + 1) > 0)
1412 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1413 //don't show messages like "Timeout ends in 0 seconds"...
1414 if (remainingTimeoutTime > 0)
1423 void player_powerups (void)
1427 if (self.items & IT_STRENGTH)
1429 if (time > self.strength_finished)
1431 if (g_minstagib_invis_alpha > 0)
1433 self.alpha = default_player_alpha;
1434 self.exteriorweaponentity.alpha = default_weapon_alpha;
1435 self.effects = self.effects | EF_FULLBRIGHT;
1439 self.effects -= self.effects & EF_NODRAW;
1441 self.items = self.items - (self.items & IT_STRENGTH);
1442 sprint(self, "^3Invisibility has worn off\n");
1447 if (time < self.strength_finished)
1449 if (g_minstagib_invis_alpha > 0)
1451 self.alpha = g_minstagib_invis_alpha;
1452 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1453 self.effects -= self.effects & EF_FULLBRIGHT;
1457 self.effects = self.effects | EF_NODRAW;
1459 self.items = self.items | IT_STRENGTH;
1460 sprint(self, "^3You are invisible\n");
1464 if (self.items & IT_INVINCIBLE)
1466 if (time > self.invincible_finished)
1468 self.items = self.items - (self.items & IT_INVINCIBLE);
1469 sprint(self, "^3Speed has worn off\n");
1474 if (time < self.invincible_finished)
1476 self.items = self.items | IT_INVINCIBLE;
1477 sprint(self, "^3You are on speed\n");
1483 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1484 if (self.items & IT_STRENGTH)
1486 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1487 if (time > self.strength_finished)
1489 self.items = self.items - (self.items & IT_STRENGTH);
1490 sprint(self, "^3Strength has worn off\n");
1495 if (time < self.strength_finished)
1497 self.items = self.items | IT_STRENGTH;
1498 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1501 if (self.items & IT_INVINCIBLE)
1503 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1504 if (time > self.invincible_finished)
1506 self.items = self.items - (self.items & IT_INVINCIBLE);
1507 sprint(self, "^3Shield has worn off\n");
1512 if (time < self.invincible_finished)
1514 self.items = self.items | IT_INVINCIBLE;
1515 sprint(self, "^3Shield surrounds you\n");
1519 if (cvar("g_fullbrightplayers"))
1520 self.effects = self.effects | EF_FULLBRIGHT;
1522 // midair gamemode: damage only while in the air
1523 // if in midair mode, being on ground grants temporary invulnerability
1524 // (this is so that multishot weapon don't clear the ground flag on the
1525 // first damage in the frame, leaving the player vulnerable to the
1526 // remaining hits in the same frame)
1527 if (self.flags & FL_ONGROUND)
1529 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1531 if (time < self.spawnshieldtime)
1532 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1535 float CalcRegen(float current, float stable, float regenfactor)
1537 if(current > stable)
1539 else if(current > stable - 0.25) // when close enough, "snap"
1542 return min(stable, current + (stable - current) * regenfactor * frametime);
1545 void player_regen (void)
1547 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1548 maxh = cvar("g_balance_health_stable");
1549 maxa = cvar("g_balance_armor_stable");
1550 limith = cvar("g_balance_health_limit");
1551 limita = cvar("g_balance_armor_limit");
1553 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1556 max_mod = regen_mod = rot_mod = limit_mod = 1;
1558 if (self.runes & RUNE_REGEN)
1560 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1562 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1563 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1564 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1568 regen_mod = cvar("g_balance_rune_regen_regenrate");
1569 max_mod = cvar("g_balance_rune_regen_hpmod");
1570 limit_mod = cvar("g_balance_rune_regen_limitmod");
1573 else if (self.runes & CURSE_VENOM)
1575 max_mod = cvar("g_balance_curse_venom_hpmod");
1576 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1577 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1579 rot_mod = cvar("g_balance_curse_venom_rotrate");
1580 limit_mod = cvar("g_balance_curse_venom_limitmod");
1581 //if (!self.runes & RUNE_REGEN)
1582 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1584 maxh = maxh * max_mod;
1585 //maxa = maxa * max_mod;
1586 limith = limith * limit_mod;
1587 limita = limita * limit_mod;
1589 if (self.armorvalue > maxa)
1591 if (time > self.pauserotarmor_finished)
1593 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1594 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1597 else if (self.armorvalue < maxa)
1599 if (time > self.pauseregen_finished)
1601 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1602 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1605 if (self.health > maxh)
1607 if (time > self.pauserothealth_finished)
1609 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1610 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1613 else if (self.health < maxh)
1615 if (time > self.pauseregen_finished)
1617 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1618 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1622 if (self.health > limith)
1623 self.health = limith;
1624 if (self.armorvalue > limita)
1625 self.armorvalue = limita;
1627 // if player rotted to death... die!
1629 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1633 ======================
1634 spectate mode routines
1635 ======================
1637 void SpectateCopy(entity spectatee) {
1638 self.armortype = spectatee.armortype;
1639 self.armorvalue = spectatee.armorvalue;
1640 self.currentammo = spectatee.currentammo;
1641 self.effects = spectatee.effects;
1642 self.health = spectatee.health;
1644 self.items = spectatee.items;
1645 self.punchangle = spectatee.punchangle;
1646 self.view_ofs = spectatee.view_ofs;
1647 self.v_angle = spectatee.v_angle;
1648 self.viewzoom = spectatee.viewzoom;
1649 self.velocity = spectatee.velocity;
1650 self.dmg_take = spectatee.dmg_take;
1651 self.dmg_save = spectatee.dmg_save;
1652 self.dmg_inflictor = spectatee.dmg_inflictor;
1653 self.angles = spectatee.v_angle;
1654 self.fixangle = TRUE;
1655 setorigin(self, spectatee.origin);
1656 setsize(self, spectatee.mins, spectatee.maxs);
1659 float SpectateUpdate() {
1663 if (self == self.enemy)
1666 if(self.enemy.flags & FL_NOTARGET)
1669 SpectateCopy(self.enemy);
1674 float SpectateNext() {
1675 other = find(self.enemy, classname, "player");
1677 other = find(other, classname, "player");
1682 if(self.enemy.classname == "player") {
1684 WriteByte(MSG_ONE, SVC_SETVIEW);
1685 WriteEntity(MSG_ONE, self.enemy);
1686 self.wantswelcomemessage = 1;
1687 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1688 if(!SpectateUpdate())
1689 PutObserverInServer();
1698 ShowRespawnCountdown()
1700 Update a respawn countdown display.
1703 void ShowRespawnCountdown()
1706 if(self.deadflag == DEAD_NO) // just respawned?
1710 number = ceil(self.death_time - time);
1713 if(number <= self.respawn_countdown)
1715 self.respawn_countdown = number - 1;
1716 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
1717 announce(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1722 void LeaveSpectatorMode()
1724 if(isJoinAllowed()) {
1725 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1726 self.classname = "player";
1727 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1728 JoinBestTeam(self, FALSE, TRUE);
1729 if(cvar("g_campaign"))
1730 campaign_bots_may_start = 1;
1731 PutClientInServer();
1732 if(!(self.flags & FL_NOTARGET))
1733 bprint ("^4", self.netname, "^4 is playing now\n");
1734 centerprint(self,"");
1737 stuffcmd(self,"menu_showteamselect\n");
1742 //player may not join because of g_maxplayers is set
1743 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1748 * Determines whether the player is allowed to join. This depends on cvar
1749 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1750 * it checks whether the number of currently playing players exceeds g_maxplayers.
1751 * @return bool TRUE if the player is allowed to join, false otherwise
1753 float isJoinAllowed() {
1754 if (!cvar("g_maxplayers"))
1758 local float currentlyPlaying;
1759 FOR_EACH_REALPLAYER(e) {
1760 if(e.classname == "player")
1761 currentlyPlaying += 1;
1763 if(currentlyPlaying < cvar("g_maxplayers"))
1770 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1771 * g_maxplayers_spectator_blocktime seconds
1773 void checkSpectatorBlock() {
1774 if(self.classname == "spectator" || self.classname == "observer") {
1775 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1776 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1782 float vercmp_recursive(string v1, string v2)
1788 dot1 = strstrofs(v1, ".", 0);
1789 dot2 = strstrofs(v2, ".", 0);
1793 s1 = substring(v1, 0, dot1);
1797 s2 = substring(v2, 0, dot2);
1799 r = stof(s1) - stof(s2);
1803 r = strcasecmp(s1, s2);
1816 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1819 float vercmp(string v1, string v2)
1821 if(strcasecmp(v1, v2) == 0) // early out check
1823 return vercmp_recursive(v1, v2);
1826 void ObserverThink()
1828 if (self.flags & FL_JUMPRELEASED) {
1829 if (self.BUTTON_JUMP && !self.version_mismatch) {
1830 self.welcomemessage_time = 0;
1831 self.flags = self.flags - FL_JUMPRELEASED;
1832 LeaveSpectatorMode();
1834 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1835 self.welcomemessage_time = 0;
1836 self.flags = self.flags - FL_JUMPRELEASED;
1837 if(SpectateNext() == 1) {
1838 self.classname = "spectator";
1842 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1843 self.flags = self.flags | FL_JUMPRELEASED;
1846 if(self.BUTTON_ZOOM)
1847 self.wantswelcomemessage = 0;
1848 if(self.wantswelcomemessage)
1849 PrintWelcomeMessage(self);
1852 void SpectatorThink()
1854 if (self.flags & FL_JUMPRELEASED) {
1855 if (self.BUTTON_JUMP && !self.version_mismatch) {
1856 self.welcomemessage_time = 0;
1857 self.flags = self.flags - FL_JUMPRELEASED;
1858 LeaveSpectatorMode();
1860 } else if(self.BUTTON_ATCK) {
1861 self.welcomemessage_time = 0;
1862 self.flags = self.flags - FL_JUMPRELEASED;
1863 if(SpectateNext() == 1) {
1864 self.classname = "spectator";
1866 self.classname = "observer";
1867 PutClientInServer();
1869 } else if (self.BUTTON_ATCK2) {
1870 self.welcomemessage_time = 0;
1871 self.flags = self.flags - FL_JUMPRELEASED;
1872 self.classname = "observer";
1873 PutClientInServer();
1875 if(!SpectateUpdate())
1876 PutObserverInServer();
1879 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
1880 self.flags = self.flags | FL_JUMPRELEASED;
1883 if(self.BUTTON_ZOOM)
1884 self.wantswelcomemessage = 0;
1885 if(self.wantswelcomemessage)
1886 PrintWelcomeMessage(self);
1887 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1894 Called every frame for each client before the physics are run
1897 void() ctf_setstatus;
1898 .float vote_nagtime;
1899 void PlayerPreThink (void)
1902 checkSpectatorBlock();
1904 if(self.netname_previous != self.netname)
1906 if(cvar("sv_eventlog"))
1907 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname), TRUE);
1908 if(self.netname_previous)
1909 strunzone(self.netname_previous);
1910 self.netname_previous = strzone(self.netname);
1914 if(self.version_nagtime)
1915 if(self.cvar_g_nexuizversion)
1916 if(time > self.version_nagtime)
1918 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1920 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
1922 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");
1923 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"));
1928 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
1931 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");
1932 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"));
1936 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");
1937 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
1941 self.version_nagtime = 0;
1945 if(self.cvar_scr_centertime)
1946 if(time > self.vote_nagtime)
1949 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1953 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1955 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1956 self.max_armorvalue = 0;
1960 antilag_record(self);
1962 if(self.classname == "player") {
1963 // if(self.netname == "Wazat")
1964 // bprint(self.classname, "\n");
1966 CheckRules_Player();
1968 if(self.BUTTON_INFO)
1969 PrintWelcomeMessage(self);
1971 if(g_lms || !cvar("sv_spectate"))
1972 if((time - self.jointime) <= cvar("welcome_message_time"))
1973 PrintWelcomeMessage(self);
1975 if (intermission_running)
1977 IntermissionThink (); // otherwise a button could be missed between
1978 return; // the think tics
1981 if(self.teleport_time)
1982 if(time > self.teleport_time)
1984 self.teleport_time = 0;
1985 self.effects = self.effects - (self.effects & EF_NODRAW);
1986 if(self.weaponentity)
1987 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1990 Nixnex_GiveCurrentWeapon();
1992 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1993 UpdateSelectedPlayer();
1995 //don't allow the player to turn around while game is paused!
1996 if(timeoutStatus == 2) {
1997 self.v_angle = self.lastV_angle;
1998 self.angles = self.lastV_angle;
1999 self.fixangle = TRUE;
2002 if (self.deadflag != DEAD_NO)
2004 float button_pressed, force_respawn;
2006 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2007 force_respawn = (g_lms || cvar("g_forced_respawn"));
2008 if (self.deadflag == DEAD_DYING)
2011 self.deadflag = DEAD_RESPAWNING;
2012 else if(!button_pressed)
2013 self.deadflag = DEAD_DEAD;
2015 else if (self.deadflag == DEAD_DEAD)
2018 self.deadflag = DEAD_RESPAWNABLE;
2020 else if (self.deadflag == DEAD_RESPAWNABLE)
2023 self.deadflag = DEAD_RESPAWNING;
2025 else if (self.deadflag == DEAD_RESPAWNING)
2027 if(time > self.death_time)
2029 self.death_time = time + 1; // only retry once a second
2033 ShowRespawnCountdown();
2037 if((g_race || g_lms) && !self.deadflag && cvar("g_lms_campcheck_interval"))
2041 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2042 dist = self.oldorigin - self.origin;
2044 self.lms_traveled_distance += fabs(vlen(dist));
2046 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
2048 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2049 self.lms_traveled_distance = 0;
2052 if(time > self.lms_nextcheck)
2054 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2055 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2057 centerprint(self, cvar_string("g_lms_campcheck_message"));
2058 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2059 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2060 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');
2062 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2063 self.lms_traveled_distance = 0;
2067 if (self.BUTTON_CROUCH && !self.hook.state)
2072 self.view_ofs = PL_CROUCH_VIEW_OFS;
2073 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2074 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2081 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2082 if (!trace_startsolid)
2084 self.crouch = FALSE;
2085 self.view_ofs = PL_VIEW_OFS;
2086 setsize (self, PL_MIN, PL_MAX);
2093 GrapplingHookFrame();
2098 float zoomfactor, zoomspeed, zoomdir;
2099 zoomfactor = self.cvar_cl_zoomfactor;
2100 if(zoomfactor < 1 || zoomfactor > 16)
2102 zoomspeed = self.cvar_cl_zoomspeed;
2103 if(zoomspeed >= 0) // < 0 is instant zoom
2104 if(zoomspeed < 0.5 || zoomspeed > 16)
2107 zoomdir = self.BUTTON_ZOOM;
2108 if(self.BUTTON_ATCK2)
2109 if(self.weapon == WEP_NEX)
2114 self.has_zoomed = 1;
2118 if(zoomspeed <= 0) // instant zoom
2121 self.viewzoom = 1 / zoomfactor;
2127 // geometric zoom would be:
2128 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
2129 // however, testing showed that arithmetic/harmonic zoom works better
2131 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
2132 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
2133 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
2135 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
2136 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
2137 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
2141 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
2149 minstagib_ammocheck();
2154 //self.angles_y=self.v_angle_y + 90; // temp
2156 //if (TetrisPreFrame()) return;
2157 } else if(gameover) {
2158 if (intermission_running)
2159 IntermissionThink (); // otherwise a button could be missed between
2161 } else if(self.classname == "observer") {
2163 } else if(self.classname == "spectator") {
2173 Called every frame for each client after the physics are run
2176 .float idlekick_lasttimeleft;
2177 void PlayerPostThink (void)
2179 // Savage: Check for nameless players
2180 if (strlen(self.netname) < 1) {
2181 self.netname = "Player";
2182 stuffcmd(self, "seta _cl_name Player\n");
2188 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2191 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2192 announce(self, "announcer/robotic/terminated.ogg");
2196 else if(timeleft <= 10)
2198 if(timeleft != self.idlekick_lasttimeleft)
2200 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2201 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".ogg"));
2206 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2208 self.idlekick_lasttimeleft = timeleft;
2211 if(self.classname == "player") {
2212 CheckRules_Player();
2217 if (intermission_running)
2218 return; // intermission or finale
2220 //PrintWelcomeMessage(self);
2221 //if (TetrisPostFrame()) return;
2223 // restart countdown
2224 if (restart_countdown) {
2225 if(time < restart_countdown) {
2226 if (!cvar("sv_ready_restart_after_countdown"))
2228 self.movetype = MOVETYPE_NONE;
2229 self.velocity = '0 0 0';
2230 self.avelocity = '0 0 0';
2231 self.movement = '0 0 0';
2236 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2237 if (!cvar("sv_ready_restart_after_countdown"))
2239 if(self.movetype == MOVETYPE_NONE)
2241 self.movetype = MOVETYPE_WALK;
2247 } else if (self.classname == "observer") {
2249 } else if (self.classname == "spectator") {
2255 for(i = 0; i < 1000; ++i)
2258 end = self.origin + '0 0 1024' + 512 * randomvec();
2259 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2260 if(trace_fraction < 1)
2261 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2263 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");