1 .float spectatee_status;
3 .float bloodloss_timer;
6 float ClientData_Send(entity to, float sf)
17 if(to.classname == "spectator")
23 sf |= 1; // forced scoreboard
24 if(to.spectatee_status)
25 sf |= 2; // spectator ent number follows
28 if(e.porto_v_angle_held)
29 sf |= 8; // angles held
31 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
32 WriteByte(MSG_ENTITY, sf);
35 WriteByte(MSG_ENTITY, to.spectatee_status);
39 WriteAngle(MSG_ENTITY, e.v_angle_x);
40 WriteAngle(MSG_ENTITY, e.v_angle_y);
46 void ClientData_Attach()
48 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
49 self.clientdata.drawonlytoclient = self;
50 self.clientdata.owner = self;
53 void ClientData_Detach()
55 remove(self.clientdata);
56 self.clientdata = world;
59 void ClientData_Touch(entity e)
61 e.clientdata.SendFlags = 1;
63 // make it spectatable
65 FOR_EACH_REALCLIENT(e2)
68 if(e2.classname == "spectator")
70 e2.clientdata.SendFlags = 1;
75 #define SPAWNPOINT_SCORE frags
77 .float wantswelcomemessage;
78 .string netname_previous;
80 void spawnfunc_info_player_survivor (void)
82 spawnfunc_info_player_deathmatch();
85 void spawnfunc_info_player_start (void)
87 spawnfunc_info_player_deathmatch();
90 void spawnfunc_info_player_deathmatch (void)
92 self.classname = "info_player_deathmatch";
93 relocate_spawnpoint();
101 self.team = activator.team;
102 some_spawn_has_been_used = 1;
107 // -1 if a spawn can't be used
108 // otherwise, a weight of the spawnpoint
109 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
111 float shortest, thisdist;
114 // filter out spots for the wrong team
116 if(spot.team != teamcheck)
120 if(spot.target == "")
123 // filter out spots for assault
124 if(spot.target != "") {
127 ent = find(world, targetname, spot.target);
130 if(ent.classname == "target_objective")
132 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
136 else if(ent.classname == "trigger_race_checkpoint")
138 if(self.classname == "player") // spectators may spawn everywhere
140 if(g_race_qualifying)
143 if(ent.race_checkpoint != 0)
145 if(spot.race_place != race_lowest_place_spawn)
150 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
153 pl = self.race_place;
154 if(pl > race_highest_place_spawn)
156 if(spot.race_place != pl)
165 ent = find(ent, targetname, spot.target);
173 shortest = vlen(world.maxs - world.mins);
174 for(player = playerlist; player; player = player.chain)
177 thisdist = vlen(player.origin - spot.origin);
178 if (thisdist < shortest)
186 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
188 local entity spot, spotlist, spotlistend;
189 spawn_allgood = TRUE;
195 for(spot = firstspot; spot; spot = spot.chain)
197 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
199 if(cvar("spawn_debugview"))
201 setmodel(spot, "models/runematch/rune.mdl");
202 if(spot.SPAWNPOINT_SCORE < mindist)
204 spot.colormod = '1 0 0';
209 spot.colormod = '0 1 0';
210 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
214 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
216 if(spot.SPAWNPOINT_SCORE < mindist)
218 // too short distance
219 spawn_allgood = FALSE;
224 spawn_allbad = FALSE;
227 spotlistend.chain = spot;
234 if(spot.team != teamcheck)
235 error("invalid spawn added");
237 print("added ", etos(spot), "\n");
243 spotlistend.chain = world;
248 for(e = spotlist; e; e = e.chain)
250 print("seen ", etos(e), "\n");
251 if(e.team != teamcheck)
252 error("invalid spawn found");
259 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
261 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
262 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
265 RandomSelection_Init();
266 for(spot = firstspot; spot; spot = spot.chain)
267 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
269 return RandomSelection_chosen_ent;
276 Finds a point to respawn
279 entity SelectSpawnPoint (float anypoint)
281 local float teamcheck;
282 local entity firstspot_new;
283 local entity spot, firstspot, playerlist;
285 spot = find (world, classname, "testplayerstart");
291 if(!anypoint && have_team_spawns)
292 teamcheck = self.team;
294 // get the list of players
295 playerlist = findchain(classname, "player");
296 // get the entire list of spots
297 firstspot = findchain(classname, "info_player_deathmatch");
298 // filter out the bad ones
299 // (note this returns the original list if none survived)
300 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
302 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
303 firstspot = firstspot_new;
305 // there is 50/50 chance of choosing a random spot or the furthest spot
306 // (this means that roughly every other spawn will be furthest, so you
307 // usually won't get fragged at spawn twice in a row)
308 if (arena_roundbased)
310 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
312 firstspot = firstspot_new;
313 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
315 else if (random() > cvar("g_spawn_furthest"))
316 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
318 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
320 if(cvar("spawn_debugview"))
322 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
326 for(e = firstspot; e; e = e.chain)
327 if(e.team != teamcheck)
328 error("invalid spawn found");
333 if(cvar("spawn_debug"))
337 if(some_spawn_has_been_used)
338 return world; // team can't spawn any more, because of actions of other team
340 error("Cannot find a spawn point - please fix the map!");
351 Checks if the argument string can be a valid playermodel.
352 Returns a valid one in doubt.
355 string FallbackPlayerModel = "models/player/marine.zym";
356 string CheckPlayerModel(string plyermodel) {
357 if(strlen(plyermodel) < 4)
358 return FallbackPlayerModel;
359 if( substring(plyermodel,0,14) != "models/player/")
360 return FallbackPlayerModel;
361 else if(cvar("sv_servermodelsonly"))
363 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
364 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
365 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
366 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
367 return FallbackPlayerModel;
368 if(plyermodel != strtolower(plyermodel))
369 return FallbackPlayerModel;
370 if(!fexists(plyermodel))
371 return FallbackPlayerModel;
378 Client_customizeentityforclient
383 float Client_customizeentityforclient()
385 #ifdef ALLOW_VARIABLE_LOD
387 // other: the player viewing me
391 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
394 if(other.cvar_cl_playerdetailreduction <= 0)
396 if(other.cvar_cl_playerdetailreduction <= -2)
397 self.modelindex = self.modelindex_lod2;
398 else if(other.cvar_cl_playerdetailreduction <= -1)
399 self.modelindex = self.modelindex_lod1;
401 self.modelindex = self.modelindex_lod0;
405 distance = vlen(self.origin - other.origin);
406 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
408 self.modelindex = self.modelindex_lod2;
410 self.modelindex = self.modelindex_lod1;
412 self.modelindex = self.modelindex_lod0;
419 void UpdatePlayerSounds();
420 void setmodel_lod(entity e, string modelname)
422 #ifdef ALLOW_VARIABLE_LOD
425 // FIXME: this only supports 3-letter extensions
426 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
430 setmodel(e, s); // players have high precision
431 self.modelindex_lod1 = self.modelindex;
434 self.modelindex_lod1 = -1;
436 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
440 setmodel(e, s); // players have high precision
441 self.modelindex_lod2 = self.modelindex;
444 self.modelindex_lod2 = -1;
446 precache_model(modelname);
447 setmodel(e, modelname); // players have high precision
448 self.modelindex_lod0 = self.modelindex;
450 if(self.modelindex_lod1 < 0)
451 self.modelindex_lod1 = self.modelindex;
453 if(self.modelindex_lod2 < 0)
454 self.modelindex_lod2 = self.modelindex;
456 precache_model(modelname);
457 setmodel(e, modelname); // players have high precision
459 player_setupanimsformodel();
460 UpdatePlayerSounds();
467 putting a client as observer in the server
470 void PutObserverInServer (void)
474 race_PreSpawnObserver();
476 spot = SelectSpawnPoint (TRUE);
478 error("No spawnpoints for observers?!?\n");
479 RemoveGrapplingHook(self); // Wazat's Grappling Hook
481 if(clienttype(self) == CLIENTTYPE_REAL)
484 WriteByte(MSG_ONE, SVC_SETVIEW);
485 WriteEntity(MSG_ONE, self);
489 kh_Key_DropAll(self, TRUE);
491 Portal_ClearAll(self);
494 DropFlag(self.flagcarried, world, world);
496 WaypointSprite_PlayerDead();
498 if(self.killcount != -666)
502 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
503 bprint ("^4", self.netname, "^4 has no more lives left\n");
505 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
508 bprint ("^4", self.netname, "^4 is spectating now\n");
511 PlayerScore_Clear(self); // clear scores when needed
513 self.spectatortime = time;
515 self.classname = "observer";
516 self.iscreature = FALSE;
518 self.takedamage = DAMAGE_NO;
519 self.solid = SOLID_NOT;
520 self.movetype = MOVETYPE_NOCLIP;
521 self.flags = FL_CLIENT | FL_NOTARGET;
522 self.armorvalue = 666;
524 self.armorvalue = cvar("g_balance_armor_start");
525 self.pauserotarmor_finished = 0;
526 self.pauserothealth_finished = 0;
527 self.pauseregen_finished = 0;
528 self.damageforcescale = 0;
535 self.pain_finished = 0;
536 self.strength_finished = 0;
537 self.invincible_finished = 0;
539 self.think = SUB_Null;
543 self.deadflag = DEAD_NO;
544 self.angles = spot.angles;
546 self.fixangle = TRUE;
549 self.view_ofs = PL_VIEW_OFS;
550 setorigin (self, spot.origin);
551 setsize (self, '0 0 0', '0 0 0');
552 self.oldorigin = self.origin;
558 self.weaponmodel = "";
559 self.weaponentity = world;
560 self.killcount = -666;
561 self.velocity = '0 0 0';
562 self.avelocity = '0 0 0';
563 self.punchangle = '0 0 0';
564 self.punchvector = '0 0 0';
565 self.oldvelocity = self.velocity;
566 self.customizeentityforclient = Client_customizeentityforclient;
567 self.wantswelcomemessage = 1;
571 if(self.version_mismatch)
573 Spawnqueue_Unmark(self);
574 Spawnqueue_Remove(self);
578 Spawnqueue_Insert(self);
583 // Only if the player cannot play at all
584 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
585 self.frags = FRAGS_SPECTATOR;
587 self.frags = FRAGS_SPECTATOR; // this was -667 before, is this okay?
590 self.frags = FRAGS_SPECTATOR;
593 float RestrictSkin(float s)
602 void FixPlayermodel()
604 local string defaultmodel;
605 local float defaultskin;
610 if(cvar("sv_defaultcharacter") == 1) {
615 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
616 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
619 if(defaultmodel == "")
621 defaultmodel = cvar_string("sv_defaultplayermodel");
622 defaultskin = cvar("sv_defaultplayerskin");
626 if(self.modelindex == 0)
629 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
630 self.model = ""; // force the != checks to return true
633 if(defaultmodel != "")
635 if (defaultmodel != self.model)
639 setmodel_lod (self, defaultmodel);
640 setsize (self, m1, m2);
643 self.skin = defaultskin;
645 if (self.playermodel != self.model)
647 self.playermodel = CheckPlayerModel(self.playermodel);
650 setmodel_lod (self, self.playermodel);
651 setsize (self, m1, m2);
654 self.skin = RestrictSkin(stof(self.playerskin));
658 if(strlen(cvar_string("sv_defaultplayercolors")))
659 if(self.clientcolors != cvar("sv_defaultplayercolors"))
660 setcolor(self, cvar("sv_defaultplayercolors"));
663 void PlayerTouchExplode(entity p1, entity p2)
666 org = (p1.origin + p2.origin) * 0.5;
667 org_z += (p1.mins_z + p2.mins_z) * 0.5;
674 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
682 Called when a client spawns in the server
685 //void() ctf_playerchanged;
686 void PutClientInServer (void)
688 if(clienttype(self) == CLIENTTYPE_BOT)
690 self.classname = "player";
692 else if(clienttype(self) == CLIENTTYPE_REAL)
695 WriteByte(MSG_ONE, SVC_SETVIEW);
696 WriteEntity(MSG_ONE, self);
699 // player is dead and becomes observer
700 // FIXME fix LMS scoring for new system
703 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
704 self.classname = "observer";
709 self.classname = "observer";
711 if(self.classname == "player") {
712 entity spot, oldself;
716 spot = SelectSpawnPoint (FALSE);
719 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
720 return; // spawn failed
723 RemoveGrapplingHook(self); // Wazat's Grappling Hook
724 self.campingrifle_bulletcounter = 0;
726 self.classname = "player";
727 self.iscreature = TRUE;
728 self.movetype = MOVETYPE_WALK;
729 self.solid = SOLID_SLIDEBOX;
730 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
731 self.frags = FRAGS_PLAYER;
732 if(independent_players)
733 MAKE_INDEPENDENT_PLAYER(self);
734 self.flags = FL_CLIENT;
735 self.takedamage = DAMAGE_AIM;
737 self.effects = EF_FULLBRIGHT;
740 self.air_finished = time + 12;
745 self.ammo_shells = warmup_start_ammo_shells;
746 self.ammo_nails = warmup_start_ammo_nails;
747 self.ammo_rockets = warmup_start_ammo_rockets;
748 self.ammo_cells = warmup_start_ammo_cells;
749 self.health = warmup_start_health;
750 self.armorvalue = warmup_start_armorvalue;
751 self.weapons = warmup_start_weapons;
755 self.ammo_shells = start_ammo_shells;
756 self.ammo_nails = start_ammo_nails;
757 self.ammo_rockets = start_ammo_rockets;
758 self.ammo_cells = start_ammo_cells;
759 self.health = start_health;
760 self.armorvalue = start_armorvalue;
761 self.weapons = start_weapons;
763 self.items = start_items;
764 self.switchweapon = w_getbestweapon(self);
765 self.cnt = self.switchweapon;
767 self.jump_interval = time;
769 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
770 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
771 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
772 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
773 //extend the pause of rotting if client was reset at the beginning of the countdown
774 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
775 self.spawnshieldtime += game_starttime - time;
776 self.pauserotarmor_finished += game_starttime - time;
777 self.pauserothealth_finished += game_starttime - time;
778 self.pauseregen_finished += game_starttime - time;
780 self.damageforcescale = 2;
787 self.pain_finished = 0;
788 self.strength_finished = 0;
789 self.invincible_finished = 0;
791 //self.speed_finished = 0;
792 //self.slowmo_finished = 0;
793 // players have no think function
794 self.think = SUB_Null;
801 self.deadflag = DEAD_NO;
803 self.angles = spot.angles;
805 self.angles_z = 0; // never spawn tilted even if the spot says to
806 self.fixangle = TRUE; // turn this way immediately
807 self.velocity = '0 0 0';
808 self.avelocity = '0 0 0';
809 self.punchangle = '0 0 0';
810 self.punchvector = '0 0 0';
811 self.oldvelocity = self.velocity;
814 WRITESPECTATABLE_MSG_ONE({
815 WriteByte(MSG_ONE, SVC_TEMPENTITY);
816 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
819 self.customizeentityforclient = Client_customizeentityforclient;
825 self.view_ofs = PL_VIEW_OFS;
826 setsize (self, PL_MIN, PL_MAX);
827 self.spawnorigin = spot.origin;
828 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
829 // don't reset back to last position, even if new position is stuck in solid
830 self.oldorigin = self.origin;
834 Spawnqueue_Remove(self);
835 Spawnqueue_Mark(self);
838 self.event_damage = PlayerDamage;
840 self.bot_attack = TRUE;
842 self.statdraintime = time + 5;
843 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
845 if(self.killcount == -666) {
846 PlayerScore_Clear(self);
850 self.cnt = WEP_LASER;
851 self.nixnex_lastchange_id = -1;
853 CL_SpawnWeaponentity();
854 self.alpha = default_player_alpha;
855 self.colormod = '1 1 1' * cvar("g_player_brightness");
856 self.exteriorweaponentity.alpha = default_weapon_alpha;
858 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
859 self.lms_traveled_distance = 0;
860 self.speedrunning = FALSE;
862 race_PostSpawn(spot);
864 if(cvar("spawn_debug"))
866 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
867 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
870 //stuffcmd(self, "chase_active 0");
871 //stuffcmd(self, "set viewsize $tmpviewsize \n");
873 if (cvar("g_spawnsound"))
874 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
877 if(self.team == assault_attacker_team)
878 centerprint(self, "You are attacking!");
880 centerprint(self, "You are defending!");
883 target_voicescript_clear(self);
892 } else if(self.classname == "observer") {
893 PutObserverInServer ();
897 // ctf_playerchanged();
900 float ClientInit_SendEntity(entity to, float sf)
903 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
904 WriteShort(MSG_ENTITY, CSQC_REVISION);
905 for(i = 1; i <= 24; ++i)
906 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
907 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
908 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
909 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
911 if(sv_foginterval && world.fog != "")
912 WriteString(MSG_ENTITY, world.fog);
914 WriteString(MSG_ENTITY, "");
919 void ClientInit_Spawn()
921 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
929 void SetNewParms (void)
931 // initialize parms for a new player
932 parm1 = -(86400 * 366);
940 void SetChangeParms (void)
942 // save parms for level change
943 parm1 = self.parm_idlesince - time;
951 void DecodeLevelParms (void)
954 self.parm_idlesince = parm1;
955 if(self.parm_idlesince == -(86400 * 366))
956 self.parm_idlesince = time;
958 // whatever happens, allow 60 seconds of idling directly after connect for map loading
959 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
966 Called when a client types 'kill' in the console
970 void ClientKill_Now_TeamChange()
972 if(self.killindicator_teamchange == -1)
975 JoinBestTeam( self, FALSE, FALSE );
979 SV_ChangeTeam(self.killindicator_teamchange - 1);
983 void ClientKill_Now()
985 if(self.killindicator_teamchange)
986 ClientKill_Now_TeamChange();
989 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
991 if(self.killindicator)
993 dprint("Cleaned up after a leaked kill indicator.\n");
994 remove(self.killindicator);
995 self.killindicator = world;
998 void KillIndicator_Think()
1000 if (!self.owner.modelindex)
1002 self.owner.killindicator = world;
1010 ClientKill_Now(); // no oldself needed
1016 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1017 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1020 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1021 if(self.owner.killindicator_teamchange)
1023 if(self.owner.killindicator_teamchange == -1)
1024 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1026 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1029 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1031 self.nextthink = time + 1;
1036 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1040 killtime = cvar("g_balance_kill_delay");
1042 self.killindicator_teamchange = targetteam;
1044 if(!self.killindicator)
1046 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1052 self.killindicator = spawn();
1053 self.killindicator.owner = self;
1054 self.killindicator.scale = 0.5;
1055 setattachment(self.killindicator, self, "");
1056 setorigin(self.killindicator, '0 0 52');
1057 self.killindicator.think = KillIndicator_Think;
1058 self.killindicator.nextthink = time + (self.lip) * 0.05;
1059 self.killindicator.cnt = ceil(killtime);
1060 self.killindicator.count = bound(0, ceil(killtime), 10);
1061 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1063 for(e = world; (e = find(e, classname, "body")) != world; )
1067 e.killindicator = spawn();
1068 e.killindicator.owner = e;
1069 e.killindicator.scale = 0.5;
1070 setattachment(e.killindicator, e, "");
1071 setorigin(e.killindicator, '0 0 52');
1072 e.killindicator.think = KillIndicator_Think;
1073 e.killindicator.nextthink = time + (e.lip) * 0.05;
1074 e.killindicator.cnt = ceil(killtime);
1079 if(self.killindicator)
1082 self.killindicator.colormod = TeamColor(targetteam);
1084 self.killindicator.colormod = '0 0 0';
1088 void ClientKill (void)
1090 ClientKill_TeamChange(0);
1093 void DoTeamChange(float destteam)
1096 if(!cvar("teamplay"))
1099 SetPlayerColors(self, destteam);
1102 if(self.classname == "player")
1105 CheckAllowedTeams(self);
1106 t = FindSmallestTeam(self, TRUE);
1109 case COLOR_TEAM1: c0 = c1; break;
1110 case COLOR_TEAM2: c0 = c2; break;
1111 case COLOR_TEAM3: c0 = c3; break;
1112 case COLOR_TEAM4: c0 = c4; break;
1119 destteam = COLOR_TEAM1;
1123 destteam = COLOR_TEAM2;
1127 destteam = COLOR_TEAM3;
1131 destteam = COLOR_TEAM4;
1137 if(destteam == self.team && !self.killindicator)
1139 ClientKill_TeamChange(destteam);
1142 void FixClientCvars(entity e)
1144 // send prediction settings to the client
1145 stuffcmd(e, "\nin_bindmap 0 0\n");
1147 * we no longer need to stuff this. Remove this comment block if you feel
1148 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1149 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1150 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1151 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1152 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1153 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1154 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1155 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1156 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1157 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1158 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1159 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1160 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1161 stuffcmd(e, "cl_movement_edgefriction 1\n");
1169 Called when a client connects to the server
1172 //void ctf_clientconnect();
1173 string ColoredTeamName(float t);
1174 void DecodeLevelParms (void);
1175 //void dom_player_join_team(entity pl);
1176 void ClientConnect (void)
1180 if(self.flags & FL_CLIENT)
1182 print("Warning: ClientConnect, but already connected!\n");
1186 if(Ban_MaybeEnforceBan(self))
1191 self.classname = "player_joining";
1193 self.flags = FL_CLIENT;
1194 self.version_nagtime = time + 10 + random() * 10;
1198 dprint("BUG player count is lower than zero, this cannot happen!\n");
1202 PlayerScore_Attach(self);
1203 ClientData_Attach();
1205 bot_clientconnect();
1207 race_PreSpawnObserver();
1210 // dom_player_join_team(self);
1212 //JoinBestTeam(self, FALSE, FALSE);
1214 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1215 self.classname = "observer";
1217 self.classname = "player";
1218 campaign_bots_may_start = 1;
1221 self.playerid = (playerid_last = playerid_last + 1);
1222 if(cvar("sv_eventlog"))
1224 if(clienttype(self) == CLIENTTYPE_REAL)
1225 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1227 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1228 s = strcat(":team:", ftos(self.playerid), ":");
1229 s = strcat(s, ftos(self.team));
1232 self.netname_previous = strzone(self.netname);
1234 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1236 bprint ("^4",self.netname);
1237 bprint ("^4 connected");
1239 if(g_domination || g_ctf)
1241 bprint(" and joined the ");
1242 bprint(ColoredTeamName(self.team));
1247 self.welcomemessage_time = 0;
1249 stuffcmd(self, strcat(clientstuff, "\n"));
1250 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1251 stuffcmd(self, "cl_particles_reloadeffects\n");
1253 FixClientCvars(self);
1255 // spawnfunc_waypoint sprites
1256 WaypointSprite_InitClient(self);
1258 // Wazat's grappling hook
1259 SetGrappleHookBindings();
1261 // get autoswitch state from player when he toggles it
1262 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1264 // get version info from player
1265 stuffcmd(self, "cmd clientversion $gameversion\n");
1267 // get other cvars from player
1270 // set cvar for team scoreboard
1274 t = cvar("teamplay");
1275 // 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
1276 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1279 stuffcmd(self, "set teamplay 0\n");
1281 // notify about available teams
1284 CheckAllowedTeams(self);
1285 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1286 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1289 stuffcmd(self, "set _teams_available 0\n");
1291 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1295 self.classname = "observer";
1296 Spawnqueue_Insert(self);
1300 ctf_clientconnect();
1306 bot_relinkplayerlist();
1308 self.spectatortime = time;
1311 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"));
1314 self.jointime = time;
1315 self.allowedTimeouts = cvar("sv_timeout_number");
1317 if(clienttype(self) == CLIENTTYPE_REAL)
1319 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1321 if(cvar("g_bugrigs"))
1322 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1327 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1329 PlayerScore_Add(self, SP_LMS_RANK, 666);
1330 self.frags = FRAGS_SPECTATOR; // FIXME do we still need this?
1334 if(!sv_foginterval && world.fog != "")
1335 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1342 Called when a client disconnects from the server
1345 .entity chatbubbleentity;
1346 .entity teambubbleentity;
1348 void ClientDisconnect (void)
1350 if not(self.flags & FL_CLIENT)
1352 print("Warning: ClientDisconnect without ClientConnect\n");
1356 bot_clientdisconnect();
1361 if(cvar("sv_eventlog"))
1362 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1363 bprint ("^4",self.netname);
1364 bprint ("^4 disconnected\n");
1367 kh_Key_DropAll(self, TRUE);
1369 Portal_ClearAll(self);
1371 if(self.flagcarried)
1372 DropFlag(self.flagcarried, world, world);
1374 // Here, everything has been done that requires this player to be a client.
1376 self.flags &~= FL_CLIENT;
1378 if (self.chatbubbleentity)
1379 remove (self.chatbubbleentity);
1381 if (self.teambubbleentity)
1382 remove (self.teambubbleentity);
1384 if (self.killindicator)
1385 remove (self.killindicator);
1387 WaypointSprite_PlayerGone();
1389 bot_relinkplayerlist();
1392 if(self.weaponentity)
1393 if(self.weaponentity.lasertarget)
1394 remove(self.weaponentity.lasertarget);
1398 Spawnqueue_Unmark(self);
1399 Spawnqueue_Remove(self);
1402 ClientData_Detach();
1403 PlayerScore_Detach(self);
1405 if(self.netname_previous)
1406 strunzone(self.netname_previous);
1408 ClearPlayerSounds();
1418 void ChatBubbleThink()
1420 self.nextthink = time;
1421 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1423 if(self.owner) // but why can that ever be world?
1424 self.owner.chatbubbleentity = world;
1428 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1429 self.model = self.mdl;
1434 void UpdateChatBubble()
1436 if (!self.modelindex)
1438 // spawn a chatbubble entity if needed
1439 if (!self.chatbubbleentity)
1441 self.chatbubbleentity = spawn();
1442 self.chatbubbleentity.owner = self;
1443 self.chatbubbleentity.exteriormodeltoclient = self;
1444 self.chatbubbleentity.think = ChatBubbleThink;
1445 self.chatbubbleentity.nextthink = time;
1446 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1447 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1448 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1449 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1450 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1451 self.chatbubbleentity.model = "";
1452 self.chatbubbleentity.effects = EF_LOWPRECISION;
1457 void TeamBubbleThink()
1459 self.nextthink = time;
1460 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1462 if(self.owner) // but why can that ever be world?
1463 self.owner.teambubbleentity = world;
1467 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1468 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1471 self.model = self.mdl;
1475 float TeamBubble_customizeentityforclient()
1477 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1480 void UpdateTeamBubble()
1482 if (!self.modelindex || !cvar("teamplay"))
1484 // spawn a teambubble entity if needed
1485 if (!self.teambubbleentity && cvar("teamplay"))
1487 self.teambubbleentity = spawn();
1488 self.teambubbleentity.owner = self;
1489 self.teambubbleentity.exteriormodeltoclient = self;
1490 self.teambubbleentity.think = TeamBubbleThink;
1491 self.teambubbleentity.nextthink = time;
1492 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1493 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1494 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1495 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1496 self.teambubbleentity.mdl = self.teambubbleentity.model;
1497 self.teambubbleentity.model = self.teambubbleentity.mdl;
1498 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1499 self.teambubbleentity.effects = EF_LOWPRECISION;
1503 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1504 // added to the model skins
1505 /*void UpdateColorModHack()
1508 c = self.clientcolors & 15;
1509 // LordHavoc: only bothering to support white, green, red, yellow, blue
1510 if (teamplay == 0) self.colormod = '0 0 0';
1511 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1512 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1513 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1514 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1515 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1516 else self.colormod = '1 1 1';
1522 self.effects |= EF_NODRAW; // prevent another CopyBody
1523 PutClientInServer();
1527 * When sv_timeout is used this function returs strings like
1528 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1529 * Called by centerprint functions
1530 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1532 string getTimeoutText(float addOneSecond) {
1533 if (!cvar("sv_timeout") || !timeoutStatus)
1536 local string retStr;
1537 if (timeoutStatus == 1) {
1538 if (addOneSecond == 1) {
1539 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1542 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1546 else if (timeoutStatus == 2) {
1548 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1549 //don't show messages like "Timeout ends in 0 seconds"...
1550 if ((remainingTimeoutTime + 1) > 0)
1556 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1557 //don't show messages like "Timeout ends in 0 seconds"...
1558 if (remainingTimeoutTime > 0)
1567 void player_powerups (void)
1571 if (self.items & IT_STRENGTH)
1573 if (time > self.strength_finished)
1575 self.alpha = default_player_alpha;
1576 self.exteriorweaponentity.alpha = default_weapon_alpha;
1577 self.items &~= IT_STRENGTH;
1578 sprint(self, "^3Invisibility has worn off\n");
1583 if (time < self.strength_finished)
1585 self.alpha = g_minstagib_invis_alpha;
1586 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1587 self.items |= IT_STRENGTH;
1588 sprint(self, "^3You are invisible\n");
1592 if (self.items & IT_INVINCIBLE)
1594 if (time > self.invincible_finished)
1596 self.items = self.items - (self.items & IT_INVINCIBLE);
1597 sprint(self, "^3Speed has worn off\n");
1602 if (time < self.invincible_finished)
1604 self.items = self.items | IT_INVINCIBLE;
1605 sprint(self, "^3You are on speed\n");
1611 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1612 if (self.items & IT_STRENGTH)
1614 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1615 if (time > self.strength_finished)
1617 self.items = self.items - (self.items & IT_STRENGTH);
1618 sprint(self, "^3Strength has worn off\n");
1623 if (time < self.strength_finished)
1625 self.items = self.items | IT_STRENGTH;
1626 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1629 if (self.items & IT_INVINCIBLE)
1631 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1632 if (time > self.invincible_finished)
1634 self.items = self.items - (self.items & IT_INVINCIBLE);
1635 sprint(self, "^3Shield has worn off\n");
1640 if (time < self.invincible_finished)
1642 self.items = self.items | IT_INVINCIBLE;
1643 sprint(self, "^3Shield surrounds you\n");
1647 if (cvar("g_fullbrightplayers"))
1648 self.effects = self.effects | EF_FULLBRIGHT;
1650 // midair gamemode: damage only while in the air
1651 // if in midair mode, being on ground grants temporary invulnerability
1652 // (this is so that multishot weapon don't clear the ground flag on the
1653 // first damage in the frame, leaving the player vulnerable to the
1654 // remaining hits in the same frame)
1655 if (self.flags & FL_ONGROUND)
1657 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1659 if (time >= game_starttime)
1660 if (time < self.spawnshieldtime)
1661 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1664 float CalcRegen(float current, float stable, float regenfactor)
1666 if(current > stable)
1668 else if(current > stable - 0.25) // when close enough, "snap"
1671 return min(stable, current + (stable - current) * regenfactor * frametime);
1674 void player_regen (void)
1676 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1677 maxh = cvar("g_balance_health_stable");
1678 maxa = cvar("g_balance_armor_stable");
1679 limith = cvar("g_balance_health_limit");
1680 limita = cvar("g_balance_armor_limit");
1682 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1685 max_mod = regen_mod = rot_mod = limit_mod = 1;
1687 if (self.runes & RUNE_REGEN)
1689 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1691 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1692 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1693 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1697 regen_mod = cvar("g_balance_rune_regen_regenrate");
1698 max_mod = cvar("g_balance_rune_regen_hpmod");
1699 limit_mod = cvar("g_balance_rune_regen_limitmod");
1702 else if (self.runes & CURSE_VENOM)
1704 max_mod = cvar("g_balance_curse_venom_hpmod");
1705 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1706 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1708 rot_mod = cvar("g_balance_curse_venom_rotrate");
1709 limit_mod = cvar("g_balance_curse_venom_limitmod");
1710 //if (!self.runes & RUNE_REGEN)
1711 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1713 maxh = maxh * max_mod;
1714 //maxa = maxa * max_mod;
1715 limith = limith * limit_mod;
1716 limita = limita * limit_mod;
1718 if (self.armorvalue > maxa)
1720 if (time > self.pauserotarmor_finished)
1722 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1723 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1726 else if (self.armorvalue < maxa)
1728 if (time > self.pauseregen_finished)
1730 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1731 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1734 if (self.health > maxh)
1736 if (time > self.pauserothealth_finished)
1738 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1739 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1742 else if (self.health < maxh)
1744 if (time > self.pauseregen_finished)
1746 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1747 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1751 if (self.health > limith)
1752 self.health = limith;
1753 if (self.armorvalue > limita)
1754 self.armorvalue = limita;
1756 // if player rotted to death... die!
1758 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1761 float zoomstate_set;
1762 void SetZoomState(float z)
1764 if(z != self.zoomstate)
1765 ClientData_Touch(self);
1770 ======================
1771 spectate mode routines
1772 ======================
1774 void SpectateCopy(entity spectatee) {
1775 self.armortype = spectatee.armortype;
1776 self.armorvalue = spectatee.armorvalue;
1777 self.currentammo = spectatee.currentammo;
1778 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1779 self.health = spectatee.health;
1781 self.items = spectatee.items;
1782 self.strength_finished = spectatee.strength_finished;
1783 self.invincible_finished = spectatee.invincible_finished;
1784 self.weapons = spectatee.weapons;
1785 self.switchweapon = spectatee.switchweapon;
1786 self.weapon = spectatee.weapon;
1787 self.punchangle = spectatee.punchangle;
1788 self.view_ofs = spectatee.view_ofs;
1789 self.v_angle = spectatee.v_angle;
1790 self.velocity = spectatee.velocity;
1791 self.dmg_take = spectatee.dmg_take;
1792 self.dmg_save = spectatee.dmg_save;
1793 self.dmg_inflictor = spectatee.dmg_inflictor;
1794 self.angles = spectatee.v_angle;
1795 self.fixangle = TRUE;
1796 setorigin(self, spectatee.origin);
1797 setsize(self, spectatee.mins, spectatee.maxs);
1798 SetZoomState(spectatee.zoomstate);
1801 float SpectateUpdate() {
1805 if (self == self.enemy)
1808 if(self.enemy.flags & FL_NOTARGET)
1811 SpectateCopy(self.enemy);
1816 float SpectateNext() {
1817 other = find(self.enemy, classname, "player");
1819 other = find(other, classname, "player");
1824 if(self.enemy.classname == "player") {
1826 WriteByte(MSG_ONE, SVC_SETVIEW);
1827 WriteEntity(MSG_ONE, self.enemy);
1828 self.wantswelcomemessage = 1;
1829 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1830 if(!SpectateUpdate())
1831 PutObserverInServer();
1840 ShowRespawnCountdown()
1842 Update a respawn countdown display.
1845 void ShowRespawnCountdown()
1848 if(self.deadflag == DEAD_NO) // just respawned?
1852 number = ceil(self.death_time - time);
1855 if(number <= self.respawn_countdown)
1857 self.respawn_countdown = number - 1;
1858 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
1859 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
1864 void LeaveSpectatorMode()
1866 if(isJoinAllowed()) {
1867 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1868 self.classname = "player";
1869 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1870 JoinBestTeam(self, FALSE, TRUE);
1871 if(cvar("g_campaign"))
1872 campaign_bots_may_start = 1;
1873 PutClientInServer();
1874 if(!(self.flags & FL_NOTARGET))
1875 bprint ("^4", self.netname, "^4 is playing now\n");
1876 centerprint(self,"");
1879 stuffcmd(self,"menu_showteamselect\n");
1884 //player may not join because of g_maxplayers is set
1885 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1890 * Determines whether the player is allowed to join. This depends on cvar
1891 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1892 * it checks whether the number of currently playing players exceeds g_maxplayers.
1893 * @return bool TRUE if the player is allowed to join, false otherwise
1895 float isJoinAllowed() {
1896 if (!cvar("g_maxplayers"))
1900 local float currentlyPlaying;
1901 FOR_EACH_REALPLAYER(e) {
1902 if(e.classname == "player")
1903 currentlyPlaying += 1;
1905 if(currentlyPlaying < cvar("g_maxplayers"))
1912 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1913 * g_maxplayers_spectator_blocktime seconds
1915 void checkSpectatorBlock() {
1916 if(self.classname == "spectator" || self.classname == "observer") {
1917 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1918 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1924 float vercmp_recursive(string v1, string v2)
1930 dot1 = strstrofs(v1, ".", 0);
1931 dot2 = strstrofs(v2, ".", 0);
1935 s1 = substring(v1, 0, dot1);
1939 s2 = substring(v2, 0, dot2);
1941 r = stof(s1) - stof(s2);
1945 r = strcasecmp(s1, s2);
1958 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1961 float vercmp(string v1, string v2)
1963 if(strcasecmp(v1, v2) == 0) // early out check
1965 return vercmp_recursive(v1, v2);
1968 void ObserverThink()
1970 if (self.flags & FL_JUMPRELEASED) {
1971 if (self.BUTTON_JUMP && !self.version_mismatch) {
1972 self.welcomemessage_time = 0;
1973 self.flags &~= FL_JUMPRELEASED;
1974 LeaveSpectatorMode();
1976 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1977 self.welcomemessage_time = 0;
1978 self.flags &~= FL_JUMPRELEASED;
1979 if(SpectateNext() == 1) {
1980 self.classname = "spectator";
1984 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1985 self.flags |= FL_JUMPRELEASED;
1988 if(self.BUTTON_ZOOM)
1989 self.wantswelcomemessage = 0;
1990 if(self.wantswelcomemessage)
1991 PrintWelcomeMessage(self);
1994 void SpectatorThink()
1996 if (self.flags & FL_JUMPRELEASED) {
1997 if (self.BUTTON_JUMP && !self.version_mismatch) {
1998 self.welcomemessage_time = 0;
1999 self.flags &~= FL_JUMPRELEASED;
2000 LeaveSpectatorMode();
2002 } else if(self.BUTTON_ATCK) {
2003 self.welcomemessage_time = 0;
2004 self.flags &~= FL_JUMPRELEASED;
2005 if(SpectateNext() == 1) {
2006 self.classname = "spectator";
2008 self.classname = "observer";
2009 PutClientInServer();
2011 } else if (self.BUTTON_ATCK2) {
2012 self.welcomemessage_time = 0;
2013 self.flags &~= FL_JUMPRELEASED;
2014 self.classname = "observer";
2015 PutClientInServer();
2017 if(!SpectateUpdate())
2018 PutObserverInServer();
2021 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2022 self.flags |= FL_JUMPRELEASED;
2025 if(self.BUTTON_ZOOM)
2026 self.wantswelcomemessage = 0;
2027 if(self.wantswelcomemessage)
2028 PrintWelcomeMessage(self);
2029 self.flags |= FL_CLIENT | FL_NOTARGET;
2032 .float touchexplode_time;
2038 Called every frame for each client before the physics are run
2041 void() ctf_setstatus;
2042 void PlayerPreThink (void)
2044 self.stat_sys_ticrate = cvar("sys_ticrate");
2045 self.stat_game_starttime = game_starttime;
2047 if(blockSpectators && frametime)
2048 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2049 checkSpectatorBlock();
2053 if(self.netname_previous != self.netname)
2055 if(cvar("sv_eventlog"))
2056 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2057 if(self.netname_previous)
2058 strunzone(self.netname_previous);
2059 self.netname_previous = strzone(self.netname);
2063 if(self.version_nagtime)
2064 if(self.cvar_g_nexuizversion)
2065 if(time > self.version_nagtime)
2067 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2069 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2071 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");
2072 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"));
2077 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2080 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");
2081 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"));
2085 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");
2086 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2090 self.version_nagtime = 0;
2094 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2096 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2097 self.max_armorvalue = 0;
2101 antilag_record(self);
2103 if(self.classname == "player") {
2104 // if(self.netname == "Wazat")
2105 // bprint(self.classname, "\n");
2107 CheckRules_Player();
2109 if(self.BUTTON_INFO)
2110 PrintWelcomeMessage(self);
2112 if(g_lms || !cvar("sv_spectate"))
2113 if((time - self.jointime) <= cvar("welcome_message_time"))
2114 PrintWelcomeMessage(self);
2116 if (intermission_running)
2118 IntermissionThink (); // otherwise a button could be missed between
2119 return; // the think tics
2122 if(self.teleport_time)
2123 if(time > self.teleport_time)
2125 self.teleport_time = 0;
2126 self.effects = self.effects - (self.effects & EF_NODRAW);
2129 Nixnex_GiveCurrentWeapon();
2131 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2132 UpdateSelectedPlayer();
2134 //don't allow the player to turn around while game is paused!
2135 if(timeoutStatus == 2) {
2136 self.v_angle = self.lastV_angle;
2137 self.angles = self.lastV_angle;
2138 self.fixangle = TRUE;
2141 if (self.deadflag != DEAD_NO)
2143 float button_pressed, force_respawn;
2145 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2146 force_respawn = (g_lms || cvar("g_forced_respawn"));
2147 if (self.deadflag == DEAD_DYING)
2150 self.deadflag = DEAD_RESPAWNING;
2151 else if(!button_pressed)
2152 self.deadflag = DEAD_DEAD;
2154 else if (self.deadflag == DEAD_DEAD)
2157 self.deadflag = DEAD_RESPAWNABLE;
2159 else if (self.deadflag == DEAD_RESPAWNABLE)
2162 self.deadflag = DEAD_RESPAWNING;
2164 else if (self.deadflag == DEAD_RESPAWNING)
2166 if(time > self.death_time)
2168 self.death_time = time + 1; // only retry once a second
2172 ShowRespawnCountdown();
2177 if(time > self.touchexplode_time)
2178 if(self.classname == "player")
2179 if(self.deadflag == DEAD_NO)
2180 if not(IS_INDEPENDENT_PLAYER(self))
2181 FOR_EACH_PLAYER(other) if(self != other)
2183 if(time > other.touchexplode_time)
2184 if(other.classname == "player")
2185 if(other.deadflag == DEAD_NO)
2186 if not(IS_INDEPENDENT_PLAYER(other))
2187 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2189 PlayerTouchExplode(self, other);
2190 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2194 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2198 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2199 dist = self.oldorigin - self.origin;
2201 self.lms_traveled_distance += fabs(vlen(dist));
2203 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2205 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2206 self.lms_traveled_distance = 0;
2209 if(time > self.lms_nextcheck)
2211 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2212 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2214 centerprint(self, cvar_string("g_lms_campcheck_message"));
2215 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2216 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2217 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');
2219 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2220 self.lms_traveled_distance = 0;
2224 self.oldorigin = self.origin;
2226 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2231 self.view_ofs = PL_CROUCH_VIEW_OFS;
2232 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2233 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2240 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2241 if (!trace_startsolid)
2243 self.crouch = FALSE;
2244 self.view_ofs = PL_VIEW_OFS;
2245 setsize (self, PL_MIN, PL_MAX);
2250 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2252 if(self.bloodloss_timer < time)
2254 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2255 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2261 GrapplingHookFrame();
2270 minstagib_ammocheck();
2275 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2277 //self.angles_y=self.v_angle_y + 90; // temp
2279 //if (TetrisPreFrame()) return;
2280 } else if(gameover) {
2281 if (intermission_running)
2282 IntermissionThink (); // otherwise a button could be missed between
2284 } else if(self.classname == "observer") {
2286 } else if(self.classname == "spectator") {
2291 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2293 float oldspectatee_status;
2294 oldspectatee_status = self.spectatee_status;
2295 if(self.classname == "spectator")
2296 self.spectatee_status = num_for_edict(self.enemy);
2297 else if(self.classname == "observer")
2298 self.spectatee_status = num_for_edict(self);
2300 self.spectatee_status = 0;
2301 if(self.spectatee_status != oldspectatee_status)
2303 ClientData_Touch(self);
2305 race_InitSpectator();
2308 if(self.teamkill_soundtime)
2309 if(time > self.teamkill_soundtime)
2311 self.teamkill_soundtime = 0;
2313 entity oldpusher, oldself;
2315 oldself = self; self = self.teamkill_soundsource;
2316 oldpusher = self.pusher; self.pusher = oldself;
2318 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2320 self.pusher = oldpusher;
2324 if(self.taunt_soundtime)
2325 if(time > self.taunt_soundtime)
2327 self.taunt_soundtime = 0;
2328 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2331 target_voicescript_next(self);
2339 Called every frame for each client after the physics are run
2342 .float idlekick_lasttimeleft;
2343 .float race_penalty;
2344 .float race_penalty_nagged;
2345 .float race_penalty_nagtime;
2346 void PlayerPostThink (void)
2348 // Savage: Check for nameless players
2349 if (strlen(self.netname) < 1) {
2350 self.netname = "Player";
2351 stuffcmd(self, "seta _cl_name Player\n");
2354 if(sv_maxidle && frametime)
2356 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2358 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2361 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2362 announce(self, "announcer/robotic/terminated.wav");
2366 else if(timeleft <= 10)
2368 if(timeleft != self.idlekick_lasttimeleft)
2370 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2371 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2376 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2378 self.idlekick_lasttimeleft = timeleft;
2381 if(self.classname == "player") {
2382 CheckRules_Player();
2387 if (intermission_running)
2388 return; // intermission or finale
2390 //PrintWelcomeMessage(self);
2391 //if (TetrisPostFrame()) return;
2393 // restart countdown
2394 if(time < game_starttime) {
2395 if (!cvar("sv_ready_restart_after_countdown"))
2397 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2399 if(time < game_starttime - 2)
2401 if(!self.race_penalty_nagged)
2403 // TODO better notification for this!
2404 self.race_penalty_nagtime = 0;
2405 self.race_penalty_nagged = 1;
2408 else if(!self.race_penalty)
2410 self.race_penalty_nagtime = 0;
2411 self.race_penalty = time + 5;
2414 if(time > self.race_penalty_nagtime)
2416 if(self.race_penalty > time)
2418 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2420 else if(self.race_penalty_nagged && time < game_starttime - 2)
2422 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2424 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2426 self.movetype = MOVETYPE_NONE;
2427 self.velocity = '0 0 0';
2428 self.avelocity = '0 0 0';
2429 self.movement = '0 0 0';
2432 else if (time < self.race_penalty)
2434 self.movetype = MOVETYPE_NONE;
2435 self.velocity = '0 0 0';
2436 self.avelocity = '0 0 0';
2437 self.movement = '0 0 0';
2441 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2442 if (!cvar("sv_ready_restart_after_countdown"))
2444 if(self.movetype == MOVETYPE_NONE)
2446 self.movetype = MOVETYPE_WALK;
2448 self.race_penalty = 0;
2449 self.race_penalty_nagged = 0;
2453 } else if (self.classname == "observer") {
2455 } else if (self.classname == "spectator") {
2461 for(i = 0; i < 1000; ++i)
2464 end = self.origin + '0 0 1024' + 512 * randomvec();
2465 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2466 if(trace_fraction < 1)
2467 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2469 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2477 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);