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)
50 // filter out spots for assault
51 if(spot.target != "") {
54 ent = find(world, targetname, spot.target);
56 if(ent.classname == "target_objective")
58 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
62 else if(ent.classname == "trigger_race_checkpoint")
64 if(self.classname == "player") // spectators may spawn everywhere
69 if(ent.race_checkpoint != 0)
71 if(spot.race_place != race_lowest_place_spawn)
76 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
80 if(pl > race_highest_place_spawn)
82 if(spot.race_place != pl)
91 ent = find(ent, targetname, spot.target);
99 shortest = vlen(world.maxs - world.mins);
100 for(player = playerlist; player; player = player.chain)
103 thisdist = vlen(player.origin - spot.origin);
104 if (thisdist < shortest)
112 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
114 local entity spot, spotlist, spotlistend;
115 spawn_allgood = TRUE;
121 for(spot = firstspot; spot; spot = spot.chain)
123 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
125 if(cvar("spawn_debugview"))
127 setmodel(spot, "models/runematch/rune.mdl");
128 if(spot.SPAWNPOINT_SCORE < mindist)
130 spot.colormod = '1 0 0';
135 spot.colormod = '0 1 0';
136 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
140 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
142 if(spot.SPAWNPOINT_SCORE < mindist)
144 // too short distance
145 spawn_allgood = FALSE;
150 spawn_allbad = FALSE;
153 spotlistend.chain = spot;
160 if(spot.team != teamcheck)
161 error("invalid spawn added");
163 print("added ", etos(spot), "\n");
169 spotlistend.chain = world;
174 for(e = spotlist; e; e = e.chain)
176 print("seen ", etos(e), "\n");
177 if(e.team != teamcheck)
178 error("invalid spawn found");
185 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
187 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
188 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
191 RandomSelection_Init();
192 for(spot = firstspot; spot; spot = spot.chain)
193 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
195 return RandomSelection_chosen_ent;
202 Finds a point to respawn
205 entity SelectSpawnPoint (float anypoint)
207 local float teamcheck;
208 local entity firstspot_new;
209 local entity spot, firstspot, playerlist;
211 spot = find (world, classname, "testplayerstart");
217 if(!anypoint && have_team_spawns)
218 teamcheck = self.team;
220 // get the list of players
221 playerlist = findchain(classname, "player");
222 // get the entire list of spots
223 firstspot = findchain(classname, "info_player_deathmatch");
224 // filter out the bad ones
225 // (note this returns the original list if none survived)
226 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
228 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
229 firstspot = firstspot_new;
231 // there is 50/50 chance of choosing a random spot or the furthest spot
232 // (this means that roughly every other spawn will be furthest, so you
233 // usually won't get fragged at spawn twice in a row)
234 if (arena_roundbased)
236 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
238 firstspot = firstspot_new;
239 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
241 else if (random() > cvar("g_spawn_furthest"))
242 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
244 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
246 if(cvar("spawn_debugview"))
248 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
252 for(e = firstspot; e; e = e.chain)
253 if(e.team != teamcheck)
254 error("invalid spawn found");
259 if(cvar("spawn_debug"))
263 if(some_spawn_has_been_used)
264 return world; // team can't spawn any more, because of actions of other team
266 error("Cannot find a spawn point - please fix the map!");
277 Checks if the argument string can be a valid playermodel.
278 Returns a valid one in doubt.
281 string FallbackPlayerModel = "models/player/marine.zym";
282 string CheckPlayerModel(string plyermodel) {
283 if(strlen(plyermodel) < 4)
284 return FallbackPlayerModel;
285 if( substring(plyermodel,0,14) != "models/player/")
286 return FallbackPlayerModel;
287 else if(cvar("sv_servermodelsonly"))
289 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
290 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
291 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
292 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
293 return FallbackPlayerModel;
294 if(plyermodel != strtolower(plyermodel))
295 return FallbackPlayerModel;
296 if(!fexists(plyermodel))
297 return FallbackPlayerModel;
304 Client_customizeentityforclient
309 float Client_customizeentityforclient()
311 #ifdef ALLOW_VARIABLE_LOD
313 // other: the player viewing me
317 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
320 if(other.cvar_cl_playerdetailreduction <= 0)
322 if(other.cvar_cl_playerdetailreduction <= -2)
323 self.modelindex = self.modelindex_lod2;
324 else if(other.cvar_cl_playerdetailreduction <= -1)
325 self.modelindex = self.modelindex_lod1;
327 self.modelindex = self.modelindex_lod0;
331 distance = vlen(self.origin - other.origin);
332 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
334 self.modelindex = self.modelindex_lod2;
336 self.modelindex = self.modelindex_lod1;
338 self.modelindex = self.modelindex_lod0;
345 void UpdatePlayerSounds();
346 void setmodel_lod(entity e, string modelname)
348 #ifdef ALLOW_VARIABLE_LOD
351 // FIXME: this only supports 3-letter extensions
352 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
356 setmodel(e, s); // players have high precision
357 self.modelindex_lod1 = self.modelindex;
360 self.modelindex_lod1 = -1;
362 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
366 setmodel(e, s); // players have high precision
367 self.modelindex_lod2 = self.modelindex;
370 self.modelindex_lod2 = -1;
372 precache_model(modelname);
373 setmodel(e, modelname); // players have high precision
374 self.modelindex_lod0 = self.modelindex;
376 if(self.modelindex_lod1 < 0)
377 self.modelindex_lod1 = self.modelindex;
379 if(self.modelindex_lod2 < 0)
380 self.modelindex_lod2 = self.modelindex;
382 precache_model(modelname);
383 setmodel(e, modelname); // players have high precision
385 player_setupanimsformodel();
386 UpdatePlayerSounds();
393 putting a client as observer in the server
396 void PutObserverInServer (void)
400 race_PreSpawnObserver();
402 spot = SelectSpawnPoint (TRUE);
404 error("No spawnpoints for observers?!?\n");
405 RemoveGrapplingHook(self); // Wazat's Grappling Hook
407 if(clienttype(self) == CLIENTTYPE_REAL)
410 WriteByte(MSG_ONE, SVC_SETVIEW);
411 WriteEntity(MSG_ONE, self);
415 kh_Key_DropAll(self, TRUE);
417 Portal_ClearAll(self);
420 DropFlag(self.flagcarried, 0);
422 WaypointSprite_PlayerDead();
424 if(self.killcount != -666)
428 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
429 bprint ("^4", self.netname, "^4 has no more lives left\n");
431 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
434 bprint ("^4", self.netname, "^4 is spectating now\n");
437 PlayerScore_Clear(self); // clear scores when needed
439 self.spectatortime = time;
441 self.classname = "observer";
443 self.takedamage = DAMAGE_NO;
444 self.solid = SOLID_NOT;
445 self.movetype = MOVETYPE_NOCLIP;
446 self.flags = FL_CLIENT | FL_NOTARGET;
447 self.armorvalue = 666;
449 self.armorvalue = cvar("g_balance_armor_start");
450 self.pauserotarmor_finished = 0;
451 self.pauserothealth_finished = 0;
452 self.pauseregen_finished = 0;
453 self.damageforcescale = 0;
460 self.pain_finished = 0;
461 self.strength_finished = 0;
462 self.invincible_finished = 0;
464 self.think = SUB_Null;
468 self.deadflag = DEAD_NO;
469 self.angles = spot.angles;
471 self.fixangle = TRUE;
474 self.view_ofs = PL_VIEW_OFS;
475 setorigin (self, spot.origin);
476 setsize (self, '0 0 0', '0 0 0');
477 self.oldorigin = self.origin;
483 self.weaponmodel = "";
484 self.weaponentity = world;
485 self.killcount = -666;
486 self.velocity = '0 0 0';
487 self.avelocity = '0 0 0';
488 self.punchangle = '0 0 0';
489 self.punchvector = '0 0 0';
490 self.oldvelocity = self.velocity;
491 self.customizeentityforclient = Client_customizeentityforclient;
492 self.wantswelcomemessage = 1;
496 if(self.version_mismatch)
498 Spawnqueue_Unmark(self);
499 Spawnqueue_Remove(self);
503 Spawnqueue_Insert(self);
508 // Only if the player cannot play at all
509 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
518 float RestrictSkin(float s)
527 void FixPlayermodel()
529 local string defaultmodel;
530 local float defaultskin;
535 if(cvar("sv_defaultcharacter") == 1) {
540 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
541 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
544 if(defaultmodel == "")
546 defaultmodel = cvar_string("sv_defaultplayermodel");
547 defaultskin = cvar("sv_defaultplayerskin");
551 if(defaultmodel != "")
553 if (defaultmodel != self.model)
557 setmodel_lod (self, defaultmodel);
558 setsize (self, m1, m2);
561 self.skin = defaultskin;
563 if (self.playermodel != self.model)
565 self.playermodel = CheckPlayerModel(self.playermodel);
568 setmodel_lod (self, self.playermodel);
569 setsize (self, m1, m2);
572 self.skin = RestrictSkin(stof(self.playerskin));
576 if(strlen(cvar_string("sv_defaultplayercolors")))
577 if(self.clientcolors != cvar("sv_defaultplayercolors"))
578 setcolor(self, cvar("sv_defaultplayercolors"));
585 Called when a client spawns in the server
588 //void() ctf_playerchanged;
589 void PutClientInServer (void)
591 if(clienttype(self) == CLIENTTYPE_BOT)
593 self.classname = "player";
595 else if(clienttype(self) == CLIENTTYPE_REAL)
598 WriteByte(MSG_ONE, SVC_SETVIEW);
599 WriteEntity(MSG_ONE, self);
602 // player is dead and becomes observer
603 // FIXME fix LMS scoring for new system
606 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
607 self.classname = "observer";
612 self.classname = "observer";
614 if(self.classname == "player") {
619 spot = SelectSpawnPoint (FALSE);
622 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
623 return; // spawn failed
626 RemoveGrapplingHook(self); // Wazat's Grappling Hook
628 self.classname = "player";
629 self.iscreature = TRUE;
630 self.movetype = MOVETYPE_WALK;
631 self.solid = SOLID_SLIDEBOX;
632 if(independent_players)
633 MAKE_INDEPENDENT_PLAYER(self);
634 self.flags = FL_CLIENT;
635 self.takedamage = DAMAGE_AIM;
637 self.effects = EF_FULLBRIGHT;
640 self.air_finished = time + 12;
645 self.ammo_shells = warmup_start_ammo_shells;
646 self.ammo_nails = warmup_start_ammo_nails;
647 self.ammo_rockets = warmup_start_ammo_rockets;
648 self.ammo_cells = warmup_start_ammo_cells;
649 self.health = warmup_start_health;
650 self.armorvalue = warmup_start_armorvalue;
651 self.weapons = warmup_start_weapons;
655 self.ammo_shells = start_ammo_shells;
656 self.ammo_nails = start_ammo_nails;
657 self.ammo_rockets = start_ammo_rockets;
658 self.ammo_cells = start_ammo_cells;
659 self.health = start_health;
660 self.armorvalue = start_armorvalue;
661 self.weapons = start_weapons;
663 self.items = start_items;
664 self.switchweapon = w_getbestweapon(self);
665 self.cnt = self.switchweapon;
667 self.jump_interval = time;
669 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
670 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
671 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
672 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
673 //extend the pause of rotting if client was reset at the beginning of the countdown
674 if(!cvar("sv_ready_restart_after_countdown") && time < restart_countdown) {
675 self.spawnshieldtime += RESTART_COUNTDOWN;
676 self.pauserotarmor_finished += RESTART_COUNTDOWN;
677 self.pauserothealth_finished += RESTART_COUNTDOWN;
678 self.pauseregen_finished += RESTART_COUNTDOWN;
680 self.damageforcescale = 2;
687 self.pain_finished = 0;
688 self.strength_finished = 0;
689 self.invincible_finished = 0;
691 //self.speed_finished = 0;
692 //self.slowmo_finished = 0;
693 // players have no think function
694 self.think = SUB_Null;
700 self.deadflag = DEAD_NO;
702 self.angles = spot.angles;
704 self.angles_z = 0; // never spawn tilted even if the spot says to
705 self.fixangle = TRUE; // turn this way immediately
706 self.velocity = '0 0 0';
707 self.avelocity = '0 0 0';
708 self.punchangle = '0 0 0';
709 self.punchvector = '0 0 0';
710 self.oldvelocity = self.velocity;
713 WRITESPECTATABLE_MSG_ONE({
714 WriteByte(MSG_ONE, SVC_TEMPENTITY);
715 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
718 self.customizeentityforclient = Client_customizeentityforclient;
724 self.view_ofs = PL_VIEW_OFS;
725 setsize (self, PL_MIN, PL_MAX);
726 self.spawnorigin = spot.origin;
727 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
728 // don't reset back to last position, even if new position is stuck in solid
729 self.oldorigin = self.origin;
733 Spawnqueue_Remove(self);
734 Spawnqueue_Mark(self);
737 self.event_damage = PlayerDamage;
739 self.bot_attack = TRUE;
741 self.statdraintime = time + 5;
742 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
744 if(self.killcount == -666) {
745 PlayerScore_Clear(self);
750 self.cnt = WEP_LASER;
751 self.nixnex_lastchange_id = -1;
753 CL_SpawnWeaponentity();
754 self.alpha = default_player_alpha;
755 self.colormod = '1 1 1' * cvar("g_player_brightness");
756 self.exteriorweaponentity.alpha = default_weapon_alpha;
758 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
759 self.lms_traveled_distance = 0;
760 self.speedrunning = FALSE;
762 race_PostSpawn(spot);
764 if(cvar("spawn_debug"))
766 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
767 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
770 //stuffcmd(self, "chase_active 0");
771 //stuffcmd(self, "set viewsize $tmpviewsize \n");
773 if (cvar("g_spawnsound"))
774 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
777 if(self.team == assault_attacker_team)
778 centerprint(self, "You are attacking!\n");
780 centerprint(self, "You are defending!\n");
783 } else if(self.classname == "observer") {
784 PutObserverInServer ();
788 // ctf_playerchanged();
795 Send whatever CSQC needs NOW and cannot wait for SendServerInfo to happen...
798 void SendCSQCInfo(void)
801 if(clienttype(self) != CLIENTTYPE_REAL)
804 WriteByte(MSG_ONE, SVC_TEMPENTITY);
805 WriteByte(MSG_ONE, TE_CSQC_INIT);
806 WriteShort(MSG_ONE, CSQC_REVISION);
807 WriteByte(MSG_ONE, maxclients);
808 for(i = 1; i <= 24; ++i)
809 WriteByte(MSG_ONE, (get_weaponinfo(i)).impulse + 1);
817 void SetNewParms (void)
819 // initialize parms for a new player
820 parm1 = -(86400 * 366);
828 void SetChangeParms (void)
830 // save parms for level change
831 parm1 = self.parm_idlesince - time;
839 void DecodeLevelParms (void)
842 self.parm_idlesince = parm1;
843 if(self.parm_idlesince == -(86400 * 366))
844 self.parm_idlesince = time;
851 Called when a client types 'kill' in the console
855 void ClientKill_Now_TeamChange()
857 if(self.killindicator_teamchange == -1)
860 JoinBestTeam( self, FALSE, FALSE );
864 SV_ChangeTeam(self.killindicator_teamchange - 1);
868 void ClientKill_Now()
870 if(self.killindicator_teamchange)
871 ClientKill_Now_TeamChange();
874 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
876 if(self.killindicator)
878 dprint("Cleaned up after a leaked kill indicator.\n");
879 remove(self.killindicator);
880 self.killindicator = world;
883 void KillIndicator_Think()
885 if (!self.owner.modelindex)
887 self.owner.killindicator = world;
895 ClientKill_Now(); // no oldself needed
901 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
902 if(clienttype(self.owner) == CLIENTTYPE_REAL)
905 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
906 if(self.owner.killindicator_teamchange)
908 if(self.owner.killindicator_teamchange == -1)
909 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
911 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
914 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
916 self.nextthink = time + 1;
921 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
925 killtime = cvar("g_balance_kill_delay");
927 self.killindicator_teamchange = targetteam;
929 if(!self.killindicator)
931 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
937 self.killindicator = spawn();
938 self.killindicator.owner = self;
939 self.killindicator.scale = 0.5;
940 setattachment(self.killindicator, self, "");
941 setorigin(self.killindicator, '0 0 52');
942 self.killindicator.think = KillIndicator_Think;
943 self.killindicator.nextthink = time + (self.lip) * 0.05;
944 self.killindicator.cnt = ceil(killtime);
945 self.killindicator.count = bound(0, ceil(killtime), 10);
946 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
948 for(e = world; (e = find(e, classname, "body")) != world; )
952 e.killindicator = spawn();
953 e.killindicator.owner = e;
954 e.killindicator.scale = 0.5;
955 setattachment(e.killindicator, e, "");
956 setorigin(e.killindicator, '0 0 52');
957 e.killindicator.think = KillIndicator_Think;
958 e.killindicator.nextthink = time + (e.lip) * 0.05;
959 e.killindicator.cnt = ceil(killtime);
964 if(self.killindicator)
967 self.killindicator.colormod = TeamColor(targetteam);
969 self.killindicator.colormod = '0 0 0';
973 void ClientKill (void)
975 ClientKill_TeamChange(0);
978 void DoTeamChange(float destteam)
981 if(!cvar("teamplay"))
984 SetPlayerColors(self, destteam);
987 if(self.classname == "player")
990 CheckAllowedTeams(self);
991 t = FindSmallestTeam(self, TRUE);
994 case COLOR_TEAM1: c0 = c1; break;
995 case COLOR_TEAM2: c0 = c2; break;
996 case COLOR_TEAM3: c0 = c3; break;
997 case COLOR_TEAM4: c0 = c4; break;
1004 destteam = COLOR_TEAM1;
1008 destteam = COLOR_TEAM2;
1012 destteam = COLOR_TEAM3;
1016 destteam = COLOR_TEAM4;
1022 if(destteam == self.team && !self.killindicator)
1024 ClientKill_TeamChange(destteam);
1027 void FixClientCvars(entity e)
1029 // send prediction settings to the client
1030 stuffcmd(e, "\nin_bindmap 0 0\n");
1032 * we no longer need to stuff this. Remove this comment block if you feel
1033 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1034 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1035 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1036 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1037 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1038 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1039 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1040 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1041 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1042 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1043 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1044 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1045 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1046 stuffcmd(e, "cl_movement_edgefriction 1\n");
1053 if(world.fog) // NOT string_null!
1060 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1061 WriteByte(MSG_ONE, TE_CSQC_FOG);
1062 WriteString(MSG_ONE, world.fog);
1066 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1076 Called when a client connects to the server
1079 //void ctf_clientconnect();
1080 string ColoredTeamName(float t);
1081 void DecodeLevelParms (void);
1082 //void dom_player_join_team(entity pl);
1083 void ClientConnect (void)
1087 if(self.flags & FL_CLIENT)
1089 print("Warning: ClientConnect, but already connected!\n");
1093 if(Ban_MaybeEnforceBan(self))
1098 self.classname = "player_joining";
1100 self.flags = self.flags | FL_CLIENT;
1101 self.version_nagtime = time + 10 + random() * 10;
1105 dprint("BUG player count is lower than zero, this cannot happen!\n");
1109 PlayerScore_Attach(self);
1111 bot_clientconnect();
1113 race_PreSpawnObserver();
1116 // dom_player_join_team(self);
1118 //JoinBestTeam(self, FALSE, FALSE);
1120 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1121 self.classname = "observer";
1123 self.classname = "player";
1124 campaign_bots_may_start = 1;
1127 self.playerid = (playerid_last = playerid_last + 1);
1128 if(cvar("sv_eventlog"))
1130 if(clienttype(self) == CLIENTTYPE_REAL)
1131 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1133 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1134 s = strcat(":team:", ftos(self.playerid), ":");
1135 s = strcat(s, ftos(self.team));
1138 self.netname_previous = strzone(self.netname);
1140 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1142 bprint ("^4",self.netname);
1143 bprint ("^4 connected");
1145 if(g_domination || g_ctf)
1147 bprint(" and joined the ");
1148 bprint(ColoredTeamName(self.team));
1153 self.welcomemessage_time = 0;
1155 stuffcmd(self, strcat(clientstuff, "\n"));
1156 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1157 stuffcmd(self, "cl_particles_reloadeffects\n");
1159 FixClientCvars(self);
1161 // spawnfunc_waypoint sprites
1162 WaypointSprite_InitClient(self);
1164 // Wazat's grappling hook
1165 SetGrappleHookBindings();
1167 // get autoswitch state from player when he toggles it
1168 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1170 // get version info from player
1171 stuffcmd(self, "cmd clientversion $gameversion\n");
1173 // get other cvars from player
1176 // set cvar for team scoreboard
1180 t = cvar("teamplay");
1181 // 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
1182 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1185 stuffcmd(self, "set teamplay 0\n");
1187 // notify about available teams
1190 CheckAllowedTeams(self);
1191 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1192 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1195 stuffcmd(self, "set _teams_available 0\n");
1197 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1201 self.classname = "observer";
1202 Spawnqueue_Insert(self);
1206 ctf_clientconnect();
1212 bot_relinkplayerlist();
1214 self.spectatortime = time;
1217 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"));
1220 self.jointime = time;
1221 self.allowedTimeouts = cvar("sv_timeout_number");
1223 if(clienttype(self) == CLIENTTYPE_REAL)
1225 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1228 if(mapvote_initialized && !cvar("g_maplist_textonly"))
1230 MapVote_SendData(MSG_ONE);
1231 MapVote_UpdateData(MSG_ONE);
1233 ScoreInfo_Write(MSG_ONE);
1239 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1240 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
1241 WriteByte(MSG_ONE, 1);
1246 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1248 PlayerScore_Add(self, SP_LMS_RANK, 666);
1249 self.frags = -666; // FIXME do we still need this?
1260 Called when a client disconnects from the server
1263 .entity chatbubbleentity;
1264 .entity teambubbleentity;
1266 //void() ctf_clientdisconnect;
1267 void ClientDisconnect (void)
1271 if not(self.flags & FL_CLIENT)
1273 print("Warning: ClientDisconnect without ClientConnect\n");
1277 bot_clientdisconnect();
1282 if(cvar("sv_eventlog"))
1283 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1284 bprint ("^4",self.netname);
1285 bprint ("^4 disconnected\n");
1287 if (self.chatbubbleentity)
1289 remove (self.chatbubbleentity);
1290 self.chatbubbleentity = world;
1293 if (self.teambubbleentity)
1295 remove (self.teambubbleentity);
1296 self.teambubbleentity = world;
1299 if (self.killindicator)
1301 remove (self.killindicator);
1302 self.killindicator = world;
1305 WaypointSprite_PlayerGone();
1308 kh_Key_DropAll(self, TRUE);
1310 Portal_ClearAll(self);
1312 if(self.flagcarried)
1313 DropFlag(self.flagcarried, 0);
1316 self.flags = self.flags - (self.flags & FL_CLIENT);
1317 bot_relinkplayerlist();
1321 if(self.weaponentity)
1322 if(self.weaponentity.lasertarget)
1323 remove(self.weaponentity.lasertarget);
1327 Spawnqueue_Unmark(self);
1328 Spawnqueue_Remove(self);
1332 ctf_clientdisconnect();
1336 PlayerScore_Detach(self);
1338 if(self.netname_previous)
1339 strunzone(self.netname_previous);
1341 ClearPlayerSounds();
1351 void ChatBubbleThink()
1353 self.nextthink = time;
1354 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1356 self.owner.chatbubbleentity = world;
1360 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1361 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1362 self.model = self.mdl;
1367 void UpdateChatBubble()
1369 if (!self.modelindex)
1371 // spawn a chatbubble entity if needed
1372 if (!self.chatbubbleentity)
1374 self.chatbubbleentity = spawn();
1375 self.chatbubbleentity.owner = self;
1376 self.chatbubbleentity.exteriormodeltoclient = self;
1377 self.chatbubbleentity.think = ChatBubbleThink;
1378 self.chatbubbleentity.nextthink = time;
1379 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1380 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1381 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1382 self.chatbubbleentity.model = "";
1383 self.chatbubbleentity.effects = EF_LOWPRECISION;
1388 void TeamBubbleThink()
1390 self.nextthink = time;
1391 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1393 self.owner.teambubbleentity = world;
1397 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1398 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1401 self.model = self.mdl;
1405 float TeamBubble_customizeentityforclient()
1407 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1410 void UpdateTeamBubble()
1412 if (!self.modelindex || !cvar("teamplay"))
1414 // spawn a teambubble entity if needed
1415 if (!self.teambubbleentity && cvar("teamplay"))
1417 self.teambubbleentity = spawn();
1418 self.teambubbleentity.owner = self;
1419 self.teambubbleentity.exteriormodeltoclient = self;
1420 self.teambubbleentity.think = TeamBubbleThink;
1421 self.teambubbleentity.nextthink = time;
1422 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1423 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1424 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1425 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1426 self.teambubbleentity.mdl = self.teambubbleentity.model;
1427 self.teambubbleentity.model = self.teambubbleentity.mdl;
1428 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1429 self.teambubbleentity.effects = EF_LOWPRECISION;
1433 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1434 // added to the model skins
1435 /*void UpdateColorModHack()
1438 c = self.clientcolors & 15;
1439 // LordHavoc: only bothering to support white, green, red, yellow, blue
1440 if (teamplay == 0) self.colormod = '0 0 0';
1441 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1442 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1443 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1444 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1445 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1446 else self.colormod = '1 1 1';
1452 self.effects |= EF_NODRAW; // prevent another CopyBody
1453 PutClientInServer();
1457 * When sv_timeout is used this function returs strings like
1458 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1459 * Called by centerprint functions
1460 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1462 string getTimeoutText(float addOneSecond) {
1463 if (!cvar("sv_timeout") || !timeoutStatus)
1466 local string retStr;
1467 if (timeoutStatus == 1) {
1468 if (addOneSecond == 1) {
1469 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1472 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1476 else if (timeoutStatus == 2) {
1478 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1479 //don't show messages like "Timeout ends in 0 seconds"...
1480 if ((remainingTimeoutTime + 1) > 0)
1486 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1487 //don't show messages like "Timeout ends in 0 seconds"...
1488 if (remainingTimeoutTime > 0)
1497 void player_powerups (void)
1501 if (self.items & IT_STRENGTH)
1503 if (time > self.strength_finished)
1505 if (g_minstagib_invis_alpha > 0)
1507 self.alpha = default_player_alpha;
1508 self.exteriorweaponentity.alpha = default_weapon_alpha;
1509 self.effects = self.effects | EF_FULLBRIGHT;
1513 self.effects -= self.effects & EF_NODRAW;
1515 self.items = self.items - (self.items & IT_STRENGTH);
1516 sprint(self, "^3Invisibility has worn off\n");
1521 if (time < self.strength_finished)
1523 if (g_minstagib_invis_alpha > 0)
1525 self.alpha = g_minstagib_invis_alpha;
1526 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1527 self.effects -= self.effects & EF_FULLBRIGHT;
1531 self.effects = self.effects | EF_NODRAW;
1533 self.items = self.items | IT_STRENGTH;
1534 sprint(self, "^3You are invisible\n");
1538 if (self.items & IT_INVINCIBLE)
1540 if (time > self.invincible_finished)
1542 self.items = self.items - (self.items & IT_INVINCIBLE);
1543 sprint(self, "^3Speed has worn off\n");
1548 if (time < self.invincible_finished)
1550 self.items = self.items | IT_INVINCIBLE;
1551 sprint(self, "^3You are on speed\n");
1557 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1558 if (self.items & IT_STRENGTH)
1560 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1561 if (time > self.strength_finished)
1563 self.items = self.items - (self.items & IT_STRENGTH);
1564 sprint(self, "^3Strength has worn off\n");
1569 if (time < self.strength_finished)
1571 self.items = self.items | IT_STRENGTH;
1572 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1575 if (self.items & IT_INVINCIBLE)
1577 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1578 if (time > self.invincible_finished)
1580 self.items = self.items - (self.items & IT_INVINCIBLE);
1581 sprint(self, "^3Shield has worn off\n");
1586 if (time < self.invincible_finished)
1588 self.items = self.items | IT_INVINCIBLE;
1589 sprint(self, "^3Shield surrounds you\n");
1593 if (cvar("g_fullbrightplayers"))
1594 self.effects = self.effects | EF_FULLBRIGHT;
1596 // midair gamemode: damage only while in the air
1597 // if in midair mode, being on ground grants temporary invulnerability
1598 // (this is so that multishot weapon don't clear the ground flag on the
1599 // first damage in the frame, leaving the player vulnerable to the
1600 // remaining hits in the same frame)
1601 if (self.flags & FL_ONGROUND)
1603 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1605 if (time > restart_countdown)
1606 if (time < self.spawnshieldtime)
1607 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1610 float CalcRegen(float current, float stable, float regenfactor)
1612 if(current > stable)
1614 else if(current > stable - 0.25) // when close enough, "snap"
1617 return min(stable, current + (stable - current) * regenfactor * frametime);
1620 void player_regen (void)
1622 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1623 maxh = cvar("g_balance_health_stable");
1624 maxa = cvar("g_balance_armor_stable");
1625 limith = cvar("g_balance_health_limit");
1626 limita = cvar("g_balance_armor_limit");
1628 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1631 max_mod = regen_mod = rot_mod = limit_mod = 1;
1633 if (self.runes & RUNE_REGEN)
1635 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1637 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1638 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1639 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1643 regen_mod = cvar("g_balance_rune_regen_regenrate");
1644 max_mod = cvar("g_balance_rune_regen_hpmod");
1645 limit_mod = cvar("g_balance_rune_regen_limitmod");
1648 else if (self.runes & CURSE_VENOM)
1650 max_mod = cvar("g_balance_curse_venom_hpmod");
1651 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1652 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1654 rot_mod = cvar("g_balance_curse_venom_rotrate");
1655 limit_mod = cvar("g_balance_curse_venom_limitmod");
1656 //if (!self.runes & RUNE_REGEN)
1657 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1659 maxh = maxh * max_mod;
1660 //maxa = maxa * max_mod;
1661 limith = limith * limit_mod;
1662 limita = limita * limit_mod;
1664 if (self.armorvalue > maxa)
1666 if (time > self.pauserotarmor_finished)
1668 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1669 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1672 else if (self.armorvalue < maxa)
1674 if (time > self.pauseregen_finished)
1676 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1677 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1680 if (self.health > maxh)
1682 if (time > self.pauserothealth_finished)
1684 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1685 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1688 else if (self.health < maxh)
1690 if (time > self.pauseregen_finished)
1692 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1693 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1697 if (self.health > limith)
1698 self.health = limith;
1699 if (self.armorvalue > limita)
1700 self.armorvalue = limita;
1702 // if player rotted to death... die!
1704 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1708 float zoomstate_set;
1709 void SetZoomState(float z)
1711 if(z != self.zoomstate)
1714 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1715 WriteByte(MSG_ONE, TE_CSQC_ZOOMNOTIFY);
1716 WriteByte(MSG_ONE, z);
1723 ======================
1724 spectate mode routines
1725 ======================
1727 void SpectateCopy(entity spectatee) {
1728 self.armortype = spectatee.armortype;
1729 self.armorvalue = spectatee.armorvalue;
1730 self.currentammo = spectatee.currentammo;
1731 self.effects = spectatee.effects;
1732 self.health = spectatee.health;
1734 self.items = spectatee.items;
1735 self.weapons = spectatee.weapons;
1736 self.punchangle = spectatee.punchangle;
1737 self.view_ofs = spectatee.view_ofs;
1738 self.v_angle = spectatee.v_angle;
1739 self.velocity = spectatee.velocity;
1740 self.dmg_take = spectatee.dmg_take;
1741 self.dmg_save = spectatee.dmg_save;
1742 self.dmg_inflictor = spectatee.dmg_inflictor;
1743 self.angles = spectatee.v_angle;
1744 self.fixangle = TRUE;
1745 setorigin(self, spectatee.origin);
1746 setsize(self, spectatee.mins, spectatee.maxs);
1747 SetZoomState(spectatee.zoomstate);
1750 float SpectateUpdate() {
1754 if (self == self.enemy)
1757 if(self.enemy.flags & FL_NOTARGET)
1760 SpectateCopy(self.enemy);
1765 float SpectateNext() {
1766 other = find(self.enemy, classname, "player");
1768 other = find(other, classname, "player");
1773 if(self.enemy.classname == "player") {
1775 WriteByte(MSG_ONE, SVC_SETVIEW);
1776 WriteEntity(MSG_ONE, self.enemy);
1777 self.wantswelcomemessage = 1;
1778 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1779 if(!SpectateUpdate())
1780 PutObserverInServer();
1789 ShowRespawnCountdown()
1791 Update a respawn countdown display.
1794 void ShowRespawnCountdown()
1797 if(self.deadflag == DEAD_NO) // just respawned?
1801 number = ceil(self.death_time - time);
1804 if(number <= self.respawn_countdown)
1806 self.respawn_countdown = number - 1;
1807 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
1808 announce(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1813 void LeaveSpectatorMode()
1815 if(isJoinAllowed()) {
1816 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1817 self.classname = "player";
1818 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1819 JoinBestTeam(self, FALSE, TRUE);
1820 if(cvar("g_campaign"))
1821 campaign_bots_may_start = 1;
1822 PutClientInServer();
1823 if(!(self.flags & FL_NOTARGET))
1824 bprint ("^4", self.netname, "^4 is playing now\n");
1825 centerprint(self,"");
1828 stuffcmd(self,"menu_showteamselect\n");
1833 //player may not join because of g_maxplayers is set
1834 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1839 * Determines whether the player is allowed to join. This depends on cvar
1840 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1841 * it checks whether the number of currently playing players exceeds g_maxplayers.
1842 * @return bool TRUE if the player is allowed to join, false otherwise
1844 float isJoinAllowed() {
1845 if (!cvar("g_maxplayers"))
1849 local float currentlyPlaying;
1850 FOR_EACH_REALPLAYER(e) {
1851 if(e.classname == "player")
1852 currentlyPlaying += 1;
1854 if(currentlyPlaying < cvar("g_maxplayers"))
1861 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1862 * g_maxplayers_spectator_blocktime seconds
1864 void checkSpectatorBlock() {
1865 if(self.classname == "spectator" || self.classname == "observer") {
1866 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1867 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1873 float vercmp_recursive(string v1, string v2)
1879 dot1 = strstrofs(v1, ".", 0);
1880 dot2 = strstrofs(v2, ".", 0);
1884 s1 = substring(v1, 0, dot1);
1888 s2 = substring(v2, 0, dot2);
1890 r = stof(s1) - stof(s2);
1894 r = strcasecmp(s1, s2);
1907 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1910 float vercmp(string v1, string v2)
1912 if(strcasecmp(v1, v2) == 0) // early out check
1914 return vercmp_recursive(v1, v2);
1917 void ObserverThink()
1919 if (self.flags & FL_JUMPRELEASED) {
1920 if (self.BUTTON_JUMP && !self.version_mismatch) {
1921 self.welcomemessage_time = 0;
1922 self.flags = self.flags - FL_JUMPRELEASED;
1923 LeaveSpectatorMode();
1925 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1926 self.welcomemessage_time = 0;
1927 self.flags = self.flags - FL_JUMPRELEASED;
1928 if(SpectateNext() == 1) {
1929 self.classname = "spectator";
1933 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1934 self.flags = self.flags | FL_JUMPRELEASED;
1937 if(self.BUTTON_ZOOM)
1938 self.wantswelcomemessage = 0;
1939 if(self.wantswelcomemessage)
1940 PrintWelcomeMessage(self);
1943 void SpectatorThink()
1945 if (self.flags & FL_JUMPRELEASED) {
1946 if (self.BUTTON_JUMP && !self.version_mismatch) {
1947 self.welcomemessage_time = 0;
1948 self.flags = self.flags - FL_JUMPRELEASED;
1949 LeaveSpectatorMode();
1951 } else if(self.BUTTON_ATCK) {
1952 self.welcomemessage_time = 0;
1953 self.flags = self.flags - FL_JUMPRELEASED;
1954 if(SpectateNext() == 1) {
1955 self.classname = "spectator";
1957 self.classname = "observer";
1958 PutClientInServer();
1960 } else if (self.BUTTON_ATCK2) {
1961 self.welcomemessage_time = 0;
1962 self.flags = self.flags - FL_JUMPRELEASED;
1963 self.classname = "observer";
1964 PutClientInServer();
1966 if(!SpectateUpdate())
1967 PutObserverInServer();
1970 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
1971 self.flags = self.flags | FL_JUMPRELEASED;
1974 if(self.BUTTON_ZOOM)
1975 self.wantswelcomemessage = 0;
1976 if(self.wantswelcomemessage)
1977 PrintWelcomeMessage(self);
1978 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1985 Called every frame for each client before the physics are run
1988 void() ctf_setstatus;
1989 .float vote_nagtime;
1990 .float spectatee_status;
1991 void PlayerPreThink (void)
1993 self.stat_sys_ticrate = cvar("sys_ticrate");
1995 checkSpectatorBlock();
1999 if(self.netname_previous != self.netname)
2001 if(cvar("sv_eventlog"))
2002 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2003 if(self.netname_previous)
2004 strunzone(self.netname_previous);
2005 self.netname_previous = strzone(self.netname);
2009 if(self.version_nagtime)
2010 if(self.cvar_g_nexuizversion)
2011 if(time > self.version_nagtime)
2013 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2015 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2017 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");
2018 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"));
2023 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2026 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");
2027 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"));
2031 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");
2032 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2036 self.version_nagtime = 0;
2040 if(self.cvar_scr_centertime)
2041 if(time > self.vote_nagtime)
2044 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
2048 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2050 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2051 self.max_armorvalue = 0;
2056 antilag_record(self);
2061 if(self.classname == "player") {
2062 // if(self.netname == "Wazat")
2063 // bprint(self.classname, "\n");
2065 CheckRules_Player();
2067 if(self.BUTTON_INFO)
2068 PrintWelcomeMessage(self);
2070 if(g_lms || !cvar("sv_spectate"))
2071 if((time - self.jointime) <= cvar("welcome_message_time"))
2072 PrintWelcomeMessage(self);
2074 if (intermission_running)
2076 IntermissionThink (); // otherwise a button could be missed between
2077 return; // the think tics
2080 if(self.teleport_time)
2081 if(time > self.teleport_time)
2083 self.teleport_time = 0;
2084 self.effects = self.effects - (self.effects & EF_NODRAW);
2085 if(self.weaponentity)
2086 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
2089 Nixnex_GiveCurrentWeapon();
2091 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2092 UpdateSelectedPlayer();
2094 //don't allow the player to turn around while game is paused!
2095 if(timeoutStatus == 2) {
2096 self.v_angle = self.lastV_angle;
2097 self.angles = self.lastV_angle;
2098 self.fixangle = TRUE;
2101 if (self.deadflag != DEAD_NO)
2103 float button_pressed, force_respawn;
2105 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2106 force_respawn = (g_lms || cvar("g_forced_respawn"));
2107 if (self.deadflag == DEAD_DYING)
2110 self.deadflag = DEAD_RESPAWNING;
2111 else if(!button_pressed)
2112 self.deadflag = DEAD_DEAD;
2114 else if (self.deadflag == DEAD_DEAD)
2117 self.deadflag = DEAD_RESPAWNABLE;
2119 else if (self.deadflag == DEAD_RESPAWNABLE)
2122 self.deadflag = DEAD_RESPAWNING;
2124 else if (self.deadflag == DEAD_RESPAWNING)
2126 if(time > self.death_time)
2128 self.death_time = time + 1; // only retry once a second
2132 ShowRespawnCountdown();
2136 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2140 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2141 dist = self.oldorigin - self.origin;
2143 self.lms_traveled_distance += fabs(vlen(dist));
2145 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
2147 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2148 self.lms_traveled_distance = 0;
2151 if(time > self.lms_nextcheck)
2153 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2154 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2156 centerprint(self, cvar_string("g_lms_campcheck_message"));
2157 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2158 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2159 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');
2161 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2162 self.lms_traveled_distance = 0;
2166 if (self.BUTTON_CROUCH && !self.hook.state)
2171 self.view_ofs = PL_CROUCH_VIEW_OFS;
2172 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2173 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2180 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2181 if (!trace_startsolid)
2183 self.crouch = FALSE;
2184 self.view_ofs = PL_VIEW_OFS;
2185 setsize (self, PL_MIN, PL_MAX);
2192 GrapplingHookFrame();
2201 minstagib_ammocheck();
2206 //self.angles_y=self.v_angle_y + 90; // temp
2208 //if (TetrisPreFrame()) return;
2209 } else if(gameover) {
2210 if (intermission_running)
2211 IntermissionThink (); // otherwise a button could be missed between
2213 } else if(self.classname == "observer") {
2215 } else if(self.classname == "spectator") {
2220 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2222 float oldspectatee_status;
2223 oldspectatee_status = self.spectatee_status;
2224 if(self.classname == "spectator")
2225 self.spectatee_status = num_for_edict(self.enemy);
2226 else if(self.classname == "observer")
2227 self.spectatee_status = num_for_edict(self);
2229 self.spectatee_status = 0;
2230 if(self.spectatee_status != oldspectatee_status)
2233 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2234 WriteByte(MSG_ONE, TE_CSQC_SPECTATING);
2235 WriteByte(MSG_ONE, self.spectatee_status);
2237 race_InitSpectator();
2246 Called every frame for each client after the physics are run
2249 .float idlekick_lasttimeleft;
2250 .float race_penalty;
2251 .float race_penalty_nagged;
2252 void PlayerPostThink (void)
2254 // Savage: Check for nameless players
2255 if (strlen(self.netname) < 1) {
2256 self.netname = "Player";
2257 stuffcmd(self, "seta _cl_name Player\n");
2263 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2266 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2267 announce(self, "announcer/robotic/terminated.ogg");
2271 else if(timeleft <= 10)
2273 if(timeleft != self.idlekick_lasttimeleft)
2275 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2276 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".ogg"));
2281 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2283 self.idlekick_lasttimeleft = timeleft;
2286 if(self.classname == "player") {
2287 CheckRules_Player();
2292 if (intermission_running)
2293 return; // intermission or finale
2295 //PrintWelcomeMessage(self);
2296 //if (TetrisPostFrame()) return;
2298 // restart countdown
2299 if (restart_countdown) {
2300 if(time < restart_countdown) {
2301 if (!cvar("sv_ready_restart_after_countdown"))
2303 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2305 if(time < restart_countdown - 2)
2307 if(!self.race_penalty_nagged)
2309 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2310 self.race_penalty_nagged = 1;
2313 else if(!self.race_penalty)
2315 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2316 self.race_penalty = time + 5;
2319 self.movetype = MOVETYPE_NONE;
2320 self.velocity = '0 0 0';
2321 self.avelocity = '0 0 0';
2322 self.movement = '0 0 0';
2325 else if (time < self.race_penalty)
2327 self.movetype = MOVETYPE_NONE;
2328 self.velocity = '0 0 0';
2329 self.avelocity = '0 0 0';
2330 self.movement = '0 0 0';
2334 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2335 if (!cvar("sv_ready_restart_after_countdown"))
2337 if(self.movetype == MOVETYPE_NONE)
2339 self.movetype = MOVETYPE_WALK;
2341 self.race_penalty = 0;
2342 self.race_penalty_nagged = 0;
2347 } else if (self.classname == "observer") {
2349 } else if (self.classname == "spectator") {
2355 for(i = 0; i < 1000; ++i)
2358 end = self.origin + '0 0 1024' + 512 * randomvec();
2359 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2360 if(trace_fraction < 1)
2361 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2363 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");