1 void race_send_recordtime(float msg);
2 void race_SendRankings(float pos, float prevpos, float del, float msg);
4 void send_CSQC_teamnagger() {
5 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
6 WriteByte(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
9 void Announce(string snd) {
10 WriteByte(MSG_ALL, SVC_TEMPENTITY);
11 WriteByte(MSG_ALL, TE_CSQC_ANNOUNCE);
12 WriteString(MSG_ALL, snd);
15 void AnnounceTo(entity e, string snd) {
16 if (clienttype(e) == CLIENTTYPE_REAL)
19 WriteByte(MSG_ONE, SVC_TEMPENTITY);
20 WriteByte(MSG_ONE, TE_CSQC_ANNOUNCE);
21 WriteString(MSG_ONE, snd);
25 float ClientData_Send(entity to, float sf)
36 if(to.classname == "spectator")
42 sf |= 1; // forced scoreboard
43 if(to.spectatee_status)
44 sf |= 2; // spectator ent number follows
47 if(e.porto_v_angle_held)
48 sf |= 8; // angles held
50 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
51 WriteByte(MSG_ENTITY, sf);
54 WriteByte(MSG_ENTITY, to.spectatee_status);
58 WriteAngle(MSG_ENTITY, e.v_angle_x);
59 WriteAngle(MSG_ENTITY, e.v_angle_y);
65 void ClientData_Attach()
67 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
68 self.clientdata.drawonlytoclient = self;
69 self.clientdata.owner = self;
72 void ClientData_Detach()
74 remove(self.clientdata);
75 self.clientdata = world;
78 void ClientData_Touch(entity e)
80 e.clientdata.SendFlags = 1;
82 // make it spectatable
84 FOR_EACH_REALCLIENT(e2)
87 if(e2.classname == "spectator")
89 e2.clientdata.SendFlags = 1;
94 .vector spawnpoint_score;
95 .string netname_previous;
97 void spawnfunc_info_player_survivor (void)
99 spawnfunc_info_player_deathmatch();
102 void spawnfunc_info_player_start (void)
104 spawnfunc_info_player_deathmatch();
107 void spawnfunc_info_player_deathmatch (void)
109 self.classname = "info_player_deathmatch";
110 relocate_spawnpoint();
113 void spawnpoint_use()
116 if(have_team_spawns > 0)
118 self.team = activator.team;
119 some_spawn_has_been_used = 1;
124 // _x: prio (-1 if unusable)
126 vector Spawn_Score(entity spot, float mindist, float teamcheck)
128 float shortest, thisdist;
134 // filter out spots for the wrong team
136 if(spot.team != teamcheck)
140 if(spot.target == "")
143 if(clienttype(self) == CLIENTTYPE_REAL)
145 if(spot.restriction == 1)
150 if(spot.restriction == 2)
154 shortest = vlen(world.maxs - world.mins);
155 FOR_EACH_PLAYER(player) if (player != self)
157 thisdist = vlen(player.origin - spot.origin);
158 if (thisdist < shortest)
161 if(shortest > mindist)
162 prio += SPAWN_PRIO_GOOD_DISTANCE;
164 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
167 // filter out spots for assault
168 if(spot.target != "") {
173 for(ent = world; (ent = find(ent, targetname, spot.target)); )
176 if(ent.spawn_evalfunc)
178 entity oldself = self;
180 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
182 if(spawn_score_x < 0)
189 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
194 MUTATOR_CALLHOOK(Spawn_Score);
198 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
201 for(spot = firstspot; spot; spot = spot.chain)
202 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
205 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
207 entity spot, spotlist, spotlistend;
212 Spawn_ScoreAll(firstspot, mindist, teamcheck);
214 for(spot = firstspot; spot; spot = spot.chain)
216 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
219 spotlistend.chain = spot;
226 spotlistend.chain = world;
231 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
233 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
234 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
237 RandomSelection_Init();
238 for(spot = firstspot; spot; spot = spot.chain)
239 RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.spawnpoint_score_y, upper), exponent) * spot.cnt, (spot.spawnpoint_score_y >= lower) * 0.5 + spot.spawnpoint_score_x);
241 return RandomSelection_chosen_ent;
248 Finds a point to respawn
251 entity SelectSpawnPoint (float anypoint)
254 entity spot, firstspot;
256 spot = find (world, classname, "testplayerstart");
260 if(anypoint || autocvar_g_spawn_useallspawns)
262 else if(have_team_spawns > 0)
264 if(have_team_spawns_forteam[self.team] == 0)
266 // we request a spawn for a team, and we have team
267 // spawns, but that team has no spawns?
268 if(have_team_spawns_forteam[0])
272 // if not, any spawn has to do
276 teamcheck = self.team; // MUST be team
278 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
279 teamcheck = 0; // MUST be noteam
282 // if we get here, we either require team spawns but have none, or we require non-team spawns and have none; use any spawn then
285 // get the entire list of spots
286 firstspot = findchain(classname, "info_player_deathmatch");
287 // filter out the bad ones
288 // (note this returns the original list if none survived)
291 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
296 if (arena_roundbased && !g_ca)
300 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
302 // there is 50/50 chance of choosing a random spot or the furthest spot
303 // (this means that roughly every other spawn will be furthest, so you
304 // usually won't get fragged at spawn twice in a row)
305 if (random() > autocvar_g_spawn_furthest)
306 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
308 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
313 if(autocvar_spawn_debug)
317 if(some_spawn_has_been_used)
318 return world; // team can't spawn any more, because of actions of other team
320 error("Cannot find a spawn point - please fix the map!");
331 Checks if the argument string can be a valid playermodel.
332 Returns a valid one in doubt.
335 string FallbackPlayerModel;
336 string CheckPlayerModel(string plyermodel) {
337 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
339 // note: we cannot summon Don Strunzone here, some player may
340 // still have the model string set. In case anyone manages how
341 // to change a cvar default, we'll have a small leak here.
342 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
344 if(strlen(plyermodel) < 4)
345 return FallbackPlayerModel;
346 if( substring(plyermodel,0,14) != "models/player/")
347 return FallbackPlayerModel;
348 else if(autocvar_sv_servermodelsonly)
350 if(substring(plyermodel,-4,4) != ".zym")
351 if(substring(plyermodel,-4,4) != ".dpm")
352 if(substring(plyermodel,-4,4) != ".iqm")
353 if(substring(plyermodel,-4,4) != ".md3")
354 if(substring(plyermodel,-4,4) != ".psk")
355 return FallbackPlayerModel;
356 // forbid the LOD models
357 if(substring(plyermodel, -9,5) == "_lod1")
358 return FallbackPlayerModel;
359 if(substring(plyermodel, -9,5) == "_lod2")
360 return FallbackPlayerModel;
361 if(plyermodel != strtolower(plyermodel))
362 return FallbackPlayerModel;
363 if(!fexists(plyermodel))
364 return FallbackPlayerModel;
371 Client_customizeentityforclient
376 void Client_uncustomizeentityforclient()
378 if(self.modelindex == 0) // no need to uncustomize then
380 self.modelindex = self.modelindex_lod0;
381 self.skin = self.skinindex;
384 float Client_customizeentityforclient()
388 if(self.modelindex == 0)
395 t0 = gettime(GETTIME_HIRES); // reference
400 #ifdef ALLOW_FORCEMODELS
401 if(other.cvar_cl_forceplayermodelsfromxonotic)
402 if not(self.modelindex_lod0_from_xonotic)
404 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
408 self.skin = modelsource.skinindex;
411 if(modelsource == self)
412 self.skin = modelsource.skinindex;
414 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
418 // other: the player viewing me
422 if(other.cvar_cl_playerdetailreduction <= 0)
424 if(other.cvar_cl_playerdetailreduction <= -2)
425 self.modelindex = modelsource.modelindex_lod2;
426 else if(other.cvar_cl_playerdetailreduction <= -1)
427 self.modelindex = modelsource.modelindex_lod1;
429 self.modelindex = modelsource.modelindex_lod0;
433 distance = vlen(self.origin - other.origin);
434 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
435 if(f > sv_loddistance2)
436 self.modelindex = modelsource.modelindex_lod2;
437 else if(f > sv_loddistance1)
438 self.modelindex = modelsource.modelindex_lod1;
440 self.modelindex = modelsource.modelindex_lod0;
445 t1 = gettime(GETTIME_HIRES); // reference
446 client_cefc_accumulator += (t1 - t0);
452 void setmodel_lod(entity e, string modelname)
458 // FIXME: this only supports 3-letter extensions
459 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
462 setmodel(e, s); // players have high precision
463 self.modelindex_lod1 = self.modelindex;
466 self.modelindex_lod1 = -1;
468 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
471 setmodel(e, s); // players have high precision
472 self.modelindex_lod2 = self.modelindex;
475 self.modelindex_lod2 = -1;
477 precache_model(modelname);
478 setmodel(e, modelname); // players have high precision
479 self.modelindex_lod0 = self.modelindex;
481 if(self.modelindex_lod1 < 0)
482 self.modelindex_lod1 = self.modelindex;
484 if(self.modelindex_lod2 < 0)
485 self.modelindex_lod2 = self.modelindex;
489 precache_model(modelname);
490 setmodel(e, modelname); // players have high precision
491 self.modelindex_lod0 = self.modelindex;
492 // save it for possible player model forcing
495 s = whichpack(self.model);
496 self.modelindex_lod0_from_xonotic = ((s == "") || (substring(s, 0, 4) == "data"));
498 player_setupanimsformodel();
499 UpdatePlayerSounds();
506 putting a client as observer in the server
509 void FixPlayermodel();
510 void PutObserverInServer (void)
513 self.hud = HUD_NORMAL;
514 race_PreSpawnObserver();
516 spot = SelectSpawnPoint (TRUE);
518 error("No spawnpoints for observers?!?\n");
519 RemoveGrapplingHook(self); // Wazat's Grappling Hook
521 if(clienttype(self) == CLIENTTYPE_REAL)
524 WriteByte(MSG_ONE, SVC_SETVIEW);
525 WriteEntity(MSG_ONE, self);
529 MUTATOR_CALLHOOK(MakePlayerObserver);
531 minstagib_stop_countdown(self);
533 Portal_ClearAll(self);
537 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
542 vehicles_exit(VHEF_RELESE);
545 DropFlag(self.flagcarried, world, world);
547 if(self.ballcarried && g_nexball)
548 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
550 WaypointSprite_PlayerDead();
552 if not(g_ca) // don't reset teams when moving a ca player to the spectators
553 self.team = -1; // move this as it is needed to log the player spectating in eventlog
555 if(self.killcount != -666) {
557 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
558 bprint ("^4", self.netname, "^4 has no more lives left\n");
560 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
562 bprint ("^4", self.netname, "^4 is spectating now\n");
564 if(self.just_joined == FALSE) {
565 LogTeamchange(self.playerid, -1, 4);
567 self.just_joined = FALSE;
570 PlayerScore_Clear(self); // clear scores when needed
572 accuracy_resend(self);
574 self.spectatortime = time;
576 self.classname = "observer";
577 self.iscreature = FALSE;
578 self.damagedbycontents = FALSE;
580 self.takedamage = DAMAGE_NO;
581 self.solid = SOLID_NOT;
582 self.movetype = MOVETYPE_FLY_WORLDONLY; //(self.cvar_cl_clippedspectating ? MOVETYPE_NOCLIP : MOVETYPE_FLY); // it's too early for this anyway, lets just set it in playerprethink
583 self.flags = FL_CLIENT | FL_NOTARGET;
584 self.armorvalue = 666;
586 self.armorvalue = autocvar_g_balance_armor_start;
587 self.pauserotarmor_finished = 0;
588 self.pauserothealth_finished = 0;
589 self.pauseregen_finished = 0;
590 self.damageforcescale = 0;
597 self.pain_finished = 0;
598 self.strength_finished = 0;
599 self.invincible_finished = 0;
601 self.think = SUB_Null;
605 self.deadflag = DEAD_NO;
606 self.angles = spot.angles;
608 self.fixangle = TRUE;
611 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
612 setorigin (self, spot.origin);
613 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
614 self.prevorigin = self.origin;
622 self.weaponname = "";
623 self.switchingweapon = 0;
624 self.weaponmodel = "";
625 self.weaponentity = world;
626 self.exteriorweaponentity = world;
627 self.killcount = -666;
628 self.velocity = '0 0 0';
629 self.avelocity = '0 0 0';
630 self.punchangle = '0 0 0';
631 self.punchvector = '0 0 0';
632 self.oldvelocity = self.velocity;
633 self.fire_endtime = -1;
636 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
640 if(self.version_mismatch)
642 Spawnqueue_Unmark(self);
643 Spawnqueue_Remove(self);
647 Spawnqueue_Insert(self);
652 // Only if the player cannot play at all
653 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
654 self.frags = FRAGS_SPECTATOR;
656 self.frags = FRAGS_LMS_LOSER;
661 self.frags = FRAGS_LMS_LOSER;
663 self.frags = FRAGS_SPECTATOR;
666 self.frags = FRAGS_SPECTATOR;
669 .float model_randomizer;
670 void FixPlayermodel()
673 float defaultskin, chmdl, oldskin, n, i;
678 if(autocvar_sv_defaultcharacter == 1)
685 s = Team_ColorNameLowerCase(self.team);
688 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
689 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
693 if(defaultmodel == "")
695 defaultmodel = autocvar_sv_defaultplayermodel;
696 defaultskin = autocvar_sv_defaultplayerskin;
699 n = tokenize_console(defaultmodel);
701 defaultmodel = argv(floor(n * self.model_randomizer));
703 i = strstrofs(defaultmodel, ":", 0);
706 defaultskin = stof(substring(defaultmodel, i+1, -1));
707 defaultmodel = substring(defaultmodel, 0, i);
711 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
714 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
715 self.model = ""; // force the != checks to return true
718 if(defaultmodel != "")
720 if (defaultmodel != self.model)
724 setmodel_lod (self, defaultmodel);
725 setsize (self, m1, m2);
729 oldskin = self.skinindex;
730 self.skinindex = defaultskin;
732 if (self.playermodel != self.model || self.playermodel == "")
734 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
737 setmodel_lod (self, self.playermodel);
738 setsize (self, m1, m2);
742 oldskin = self.skinindex;
743 self.skinindex = stof(self.playerskin);
746 if(chmdl || oldskin != self.skinindex)
747 self.species = player_getspecies(); // model or skin has changed
750 if(strlen(autocvar_sv_defaultplayercolors))
751 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
752 setcolor(self, stof(autocvar_sv_defaultplayercolors));
755 void PlayerTouchExplode(entity p1, entity p2)
758 org = (p1.origin + p2.origin) * 0.5;
759 org_z += (p1.mins_z + p2.mins_z) * 0.5;
766 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
774 Called when a client spawns in the server
777 //void() ctf_playerchanged;
778 void PutClientInServer (void)
780 if(clienttype(self) == CLIENTTYPE_BOT)
782 self.classname = "player";
784 else if(clienttype(self) == CLIENTTYPE_REAL)
787 WriteByte(MSG_ONE, SVC_SETVIEW);
788 WriteEntity(MSG_ONE, self);
794 // player is dead and becomes observer
795 // FIXME fix LMS scoring for new system
798 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
799 self.classname = "observer";
802 if(g_arena || (g_ca && !allowed_to_spawn))
804 self.classname = "observer";
807 self.classname = "observer";
809 if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {
810 entity spot, oldself;
813 accuracy_resend(self);
816 JoinBestTeam(self, FALSE, TRUE);
820 spot = SelectSpawnPoint (FALSE);
823 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
824 return; // spawn failed
827 RemoveGrapplingHook(self); // Wazat's Grappling Hook
829 self.classname = "player";
830 self.wasplayer = TRUE;
831 self.iscreature = TRUE;
832 self.damagedbycontents = TRUE;
833 self.movetype = MOVETYPE_WALK;
834 self.solid = SOLID_SLIDEBOX;
835 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
836 if(autocvar_g_playerclip_collisions)
837 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
838 if(clienttype(self) == CLIENTTYPE_BOT && autocvar_g_botclip_collisions)
839 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
840 self.frags = FRAGS_PLAYER;
841 if(INDEPENDENT_PLAYERS)
842 MAKE_INDEPENDENT_PLAYER(self);
843 self.flags = FL_CLIENT;
844 if(autocvar__notarget)
845 self.flags |= FL_NOTARGET;
846 self.takedamage = DAMAGE_AIM;
848 self.effects = EF_FULLBRIGHT;
851 self.air_finished = time + 12;
853 if(autocvar_g_balance_nex_charge)
855 if(autocvar_g_balance_nex_secondary_chargepool)
856 self.nex_chargepool_ammo = 1;
857 self.nex_charge = autocvar_g_balance_nex_charge_start;
862 self.ammo_shells = warmup_start_ammo_shells;
863 self.ammo_nails = warmup_start_ammo_nails;
864 self.ammo_rockets = warmup_start_ammo_rockets;
865 self.ammo_cells = warmup_start_ammo_cells;
866 self.ammo_fuel = warmup_start_ammo_fuel;
867 self.health = warmup_start_health;
868 self.armorvalue = warmup_start_armorvalue;
869 self.weapons = warmup_start_weapons;
873 self.ammo_shells = start_ammo_shells;
874 self.ammo_nails = start_ammo_nails;
875 self.ammo_rockets = start_ammo_rockets;
876 self.ammo_cells = start_ammo_cells;
877 self.ammo_fuel = start_ammo_fuel;
878 self.health = start_health;
879 self.armorvalue = start_armorvalue;
880 self.weapons = start_weapons;
883 if(g_weaponarena_random)
885 if(g_weaponarena_random_with_laser)
886 self.weapons &~= WEPBIT_LASER;
887 self.weapons = randombits(self.weapons, g_weaponarena_random, FALSE);
888 if(g_weaponarena_random_with_laser)
889 self.weapons |= WEPBIT_LASER;
892 self.items = start_items;
893 self.jump_interval = time;
895 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
896 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
897 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
898 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
899 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
900 //extend the pause of rotting if client was reset at the beginning of the countdown
901 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
902 self.spawnshieldtime += game_starttime - time;
903 self.pauserotarmor_finished += game_starttime - time;
904 self.pauserothealth_finished += game_starttime - time;
905 self.pauseregen_finished += game_starttime - time;
907 self.damageforcescale = 2;
914 self.pain_finished = 0;
915 self.strength_finished = 0;
916 self.invincible_finished = 0;
918 // players have no think function
919 self.think = SUB_Null;
923 self.ballistics_density = autocvar_g_ballistics_density_player;
929 self.deadflag = DEAD_NO;
931 self.angles = spot.angles;
933 self.angles_z = 0; // never spawn tilted even if the spot says to
934 self.fixangle = TRUE; // turn this way immediately
935 self.velocity = '0 0 0';
936 self.avelocity = '0 0 0';
937 self.punchangle = '0 0 0';
938 self.punchvector = '0 0 0';
939 self.oldvelocity = self.velocity;
940 self.fire_endtime = -1;
943 WRITESPECTATABLE_MSG_ONE({
944 WriteByte(MSG_ONE, SVC_TEMPENTITY);
945 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
949 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
955 self.view_ofs = PL_VIEW_OFS;
956 setsize (self, PL_MIN, PL_MAX);
957 self.spawnorigin = spot.origin;
958 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
959 // don't reset back to last position, even if new position is stuck in solid
960 self.oldorigin = self.origin;
961 self.prevorigin = self.origin;
962 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
963 self.lastteleporttime = time; // prevent insane speeds due to changing origin
964 self.hud = HUD_NORMAL;
968 Spawnqueue_Remove(self);
969 Spawnqueue_Mark(self);
975 self.event_damage = PlayerDamage;
977 self.bot_attack = TRUE;
979 self.statdraintime = time + 5;
980 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
982 if(self.killcount == -666) {
983 PlayerScore_Clear(self);
987 CL_SpawnWeaponentity();
988 self.alpha = default_player_alpha;
989 self.colormod = '1 1 1' * autocvar_g_player_brightness;
990 self.exteriorweaponentity.alpha = default_weapon_alpha;
992 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
993 self.lms_traveled_distance = 0;
994 self.speedrunning = FALSE;
996 race_PostSpawn(spot);
998 //stuffcmd(self, "chase_active 0");
999 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1001 if (autocvar_g_spawnsound)
1002 sound (self, CH_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
1005 if(self.team == assault_attacker_team)
1006 centerprint(self, "You are attacking!");
1008 centerprint(self, "You are defending!");
1011 target_voicescript_clear(self);
1013 // reset fields the weapons may use
1014 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
1016 weapon_action(j, WR_RESETPLAYER);
1018 // all weapons must be fully loaded when we spawn
1020 e = get_weaponinfo(j);
1021 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
1022 self.(weapon_load[j]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
1027 activator = oldself;
1030 self.target = string_null;
1037 MUTATOR_CALLHOOK(PlayerSpawn);
1039 if(autocvar_spawn_debug)
1041 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
1042 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
1045 self.switchweapon = w_getbestweapon(self);
1046 self.cnt = -1; // W_LastWeapon will not complain
1048 self.weaponname = "";
1049 self.switchingweapon = 0;
1052 self.alivetime = time;
1054 antilag_clear(self);
1055 } else if(self.classname == "observer" || (g_ca && !allowed_to_spawn)) {
1056 PutObserverInServer ();
1060 // ctf_playerchanged();
1063 .float ebouncefactor, ebouncestop; // electro's values
1064 // TODO do we need all these fields, or should we stop autodetecting runtime
1065 // changes and just have a console command to update this?
1066 float ClientInit_SendEntity(entity to, float sf)
1068 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
1069 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
1070 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
1071 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
1072 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
1073 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
1074 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[0]));
1075 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[1]));
1076 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[2]));
1077 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[3]));
1078 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[0]));
1079 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[1]));
1080 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[2]));
1081 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[3]));
1082 if(sv_foginterval && world.fog != "")
1083 WriteString(MSG_ENTITY, world.fog);
1085 WriteString(MSG_ENTITY, "");
1086 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
1087 WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
1088 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_bouncefactor
1089 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_bouncestop
1090 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
1091 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
1092 WriteByte(MSG_ENTITY, autocvar_g_balance_nex_secondary); // client has to know if it should zoom or not
1093 WriteByte(MSG_ENTITY, autocvar_g_balance_rifle_secondary); // client has to know if it should zoom or not
1094 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
1095 WriteByte(MSG_ENTITY, autocvar_g_balance_minelayer_limit); // minelayer max mines
1096 WriteByte(MSG_ENTITY, autocvar_g_balance_hagar_secondary_load_max); // hagar max loadable rockets
1097 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
1101 void ClientInit_CheckUpdate()
1103 self.nextthink = time;
1104 if(self.count != autocvar_g_balance_armor_blockpercent)
1106 self.count = autocvar_g_balance_armor_blockpercent;
1107 self.SendFlags |= 1;
1109 if(self.cnt != autocvar_g_balance_weaponswitchdelay)
1111 self.cnt = autocvar_g_balance_weaponswitchdelay;
1112 self.SendFlags |= 1;
1114 if(self.bouncefactor != autocvar_g_balance_grenadelauncher_bouncefactor)
1116 self.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
1117 self.SendFlags |= 1;
1119 if(self.bouncestop != autocvar_g_balance_grenadelauncher_bouncestop)
1121 self.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
1122 self.SendFlags |= 1;
1124 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
1126 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
1127 self.SendFlags |= 1;
1129 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
1131 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
1132 self.SendFlags |= 1;
1136 void ClientInit_Spawn()
1141 e.classname = "clientinit";
1142 e.think = ClientInit_CheckUpdate;
1143 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
1147 ClientInit_CheckUpdate();
1156 void SetNewParms (void)
1158 // initialize parms for a new player
1159 parm1 = -(86400 * 366);
1167 void SetChangeParms (void)
1169 // save parms for level change
1170 parm1 = self.parm_idlesince - time;
1178 void DecodeLevelParms (void)
1181 self.parm_idlesince = parm1;
1182 if(self.parm_idlesince == -(86400 * 366))
1183 self.parm_idlesince = time;
1185 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1186 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1193 Called when a client types 'kill' in the console
1197 .float clientkill_nexttime;
1198 void ClientKill_Now_TeamChange()
1200 if(self.killindicator_teamchange == -1)
1203 JoinBestTeam( self, FALSE, FALSE );
1205 else if(self.killindicator_teamchange == -2)
1210 sprint(self, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1211 PutObserverInServer();
1214 SV_ChangeTeam(self.killindicator_teamchange - 1);
1217 void ClientKill_Now()
1221 vehicles_exit(VHEF_RELESE);
1222 if(!self.killindicator_teamchange)
1224 self.vehicle_health = -1;
1225 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
1229 if(self.killindicator && !wasfreed(self.killindicator))
1230 remove(self.killindicator);
1232 self.killindicator = world;
1234 if(self.killindicator_teamchange)
1235 ClientKill_Now_TeamChange();
1238 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1240 // now I am sure the player IS dead
1242 void KillIndicator_Think()
1246 self.owner.killindicator = world;
1251 if (!self.owner.modelindex)
1253 self.owner.killindicator = world;
1261 ClientKill_Now(); // no oldself needed
1264 else if(g_cts && self.health == 1) // health == 1 means that it's silent
1266 self.nextthink = time + 1;
1272 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1273 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1276 AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));
1278 self.nextthink = time + 1;
1283 float clientkilltime;
1284 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
1293 killtime = autocvar_g_balance_kill_delay;
1295 if(g_race_qualifying || g_cts)
1298 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
1300 remove(self.killindicator);
1301 self.killindicator = world;
1303 ClientKill_Now(); // allow instant kill in this case
1307 self.killindicator_teamchange = targetteam;
1309 if(!self.killindicator)
1311 if(self.modelindex && self.deadflag == DEAD_NO)
1313 killtime = max(killtime, self.clientkill_nexttime - time);
1314 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
1317 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1323 starttime = max(time, clientkilltime);
1325 self.killindicator = spawn();
1326 self.killindicator.owner = self;
1327 self.killindicator.scale = 0.5;
1328 setattachment(self.killindicator, self, "");
1329 setorigin(self.killindicator, '0 0 52');
1330 self.killindicator.think = KillIndicator_Think;
1331 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
1332 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
1333 self.killindicator.cnt = ceil(killtime);
1334 self.killindicator.count = bound(0, ceil(killtime), 10);
1335 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1337 for(e = world; (e = find(e, classname, "body")) != world; )
1341 e.killindicator = spawn();
1342 e.killindicator.owner = e;
1343 e.killindicator.scale = 0.5;
1344 setattachment(e.killindicator, e, "");
1345 setorigin(e.killindicator, '0 0 52');
1346 e.killindicator.think = KillIndicator_Think;
1347 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
1348 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
1349 e.killindicator.cnt = ceil(killtime);
1354 if(self.killindicator)
1356 if(targetteam == 0) // just die
1358 self.killindicator.colormod = '0 0 0';
1359 if(clienttype(self) == CLIENTTYPE_REAL)
1360 if(self.killindicator.cnt > 0)
1361 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "^1Suicide in %d seconds", 1, self.killindicator.cnt);
1363 else if(targetteam == -1) // auto
1365 self.killindicator.colormod = '0 1 0';
1366 if(clienttype(self) == CLIENTTYPE_REAL)
1367 if(self.killindicator.cnt > 0)
1368 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Changing team in %d seconds", 1, self.killindicator.cnt);
1370 else if(targetteam == -2) // spectate
1372 self.killindicator.colormod = '0.5 0.5 0.5';
1373 if(clienttype(self) == CLIENTTYPE_REAL)
1374 if(self.killindicator.cnt > 0)
1375 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Spectating in %d seconds", 1, self.killindicator.cnt);
1379 self.killindicator.colormod = TeamColor(targetteam);
1380 if(clienttype(self) == CLIENTTYPE_REAL)
1381 if(self.killindicator.cnt > 0)
1382 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, strcat("Changing to ", ColoredTeamName(targetteam), " in %d seconds"), 1, self.killindicator.cnt);
1388 void ClientKill (void)
1393 if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either
1397 else if(self.freezetag_frozen)
1402 ClientKill_TeamChange(0);
1405 void CTS_ClientKill (entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed
1407 e.killindicator = spawn();
1408 e.killindicator.owner = e;
1409 e.killindicator.think = KillIndicator_Think;
1410 e.killindicator.nextthink = time + (e.lip) * 0.05;
1411 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
1412 e.killindicator.health = 1; // this is used to indicate that it should be silent
1416 void FixClientCvars(entity e)
1418 // send prediction settings to the client
1419 stuffcmd(e, "\nin_bindmap 0 0\n");
1421 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1422 if(autocvar_g_antilag == 3) // client side hitscan
1423 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1425 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1427 * we no longer need to stuff this. Remove this comment block if you feel
1428 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1429 stuffcmd(e, strcat("cl_gravity ", ftos(autocvar_sv_gravity), "\n"));
1430 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(autocvar_sv_accelerate), "\n"));
1431 stuffcmd(e, strcat("cl_movement_friction ", ftos(autocvar_sv_friction), "\n"));
1432 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(autocvar_sv_maxspeed), "\n"));
1433 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(autocvar_sv_airaccelerate), "\n"));
1434 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(autocvar_sv_maxairspeed), "\n"));
1435 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(autocvar_sv_stopspeed), "\n"));
1436 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(autocvar_sv_jumpvelocity), "\n"));
1437 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(autocvar_sv_stepheight), "\n"));
1438 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(autocvar_sv_friction_on_land), "\n"));
1439 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(autocvar_sv_airaccel_qw), "\n"));
1440 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(autocvar_sv_airaccel_sideways_friction), "\n"));
1441 stuffcmd(e, "cl_movement_edgefriction 1\n");
1445 float PlayerInIDList(entity p, string idlist)
1450 // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
1451 if not(p.crypto_idfp)
1454 // this function allows abbreviated player IDs too!
1455 n = tokenize_console(idlist);
1456 for(i = 0; i < n; ++i)
1459 if(s == substring(p.crypto_idfp, 0, strlen(s)))
1470 Called when a client connects to the server
1473 //void ctf_clientconnect();
1474 string ColoredTeamName(float t);
1475 void DecodeLevelParms (void);
1476 //void dom_player_join_team(entity pl);
1477 void set_dom_state(entity e);
1478 void ClientConnect (void)
1482 if(self.flags & FL_CLIENT)
1484 print("Warning: ClientConnect, but already connected!\n");
1488 if(Ban_MaybeEnforceBan(self))
1494 sprint(self, strcat("^4SVQC Build information: ^1", WATERMARK(), "\n"));
1497 self.classname = "player_joining";
1499 self.flags = FL_CLIENT;
1500 self.version_nagtime = time + 10 + random() * 10;
1504 dprint("BUG player count is lower than zero, this cannot happen!\n");
1508 PlayerScore_Attach(self);
1509 ClientData_Attach();
1510 accuracy_init(self);
1512 bot_clientconnect();
1518 race_PreSpawnObserver();
1521 // dom_player_join_team(self);
1523 // identify the right forced team
1524 if(autocvar_g_campaign)
1526 if(clienttype(self) == CLIENTTYPE_REAL) // only players, not bots
1528 switch(autocvar_g_campaign_forceteam)
1530 case 1: self.team_forced = COLOR_TEAM1; break;
1531 case 2: self.team_forced = COLOR_TEAM2; break;
1532 case 3: self.team_forced = COLOR_TEAM3; break;
1533 case 4: self.team_forced = COLOR_TEAM4; break;
1534 default: self.team_forced = 0;
1538 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1539 self.team_forced = COLOR_TEAM1;
1540 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1541 self.team_forced = COLOR_TEAM2;
1542 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1543 self.team_forced = COLOR_TEAM3;
1544 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1545 self.team_forced = COLOR_TEAM4;
1546 else if(autocvar_g_forced_team_otherwise == "red")
1547 self.team_forced = COLOR_TEAM1;
1548 else if(autocvar_g_forced_team_otherwise == "blue")
1549 self.team_forced = COLOR_TEAM2;
1550 else if(autocvar_g_forced_team_otherwise == "yellow")
1551 self.team_forced = COLOR_TEAM3;
1552 else if(autocvar_g_forced_team_otherwise == "pink")
1553 self.team_forced = COLOR_TEAM4;
1554 else if(autocvar_g_forced_team_otherwise == "spectate")
1555 self.team_forced = -1;
1556 else if(autocvar_g_forced_team_otherwise == "spectator")
1557 self.team_forced = -1;
1559 self.team_forced = 0;
1562 if(self.team_forced > 0)
1563 self.team_forced = 0;
1565 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1567 if((autocvar_sv_spectate == 1 && !g_lms) || autocvar_g_campaign || self.team_forced < 0) {
1568 self.classname = "observer";
1572 if(autocvar_g_balance_teams || autocvar_g_balance_teams_force)
1574 self.classname = "player";
1575 campaign_bots_may_start = 1;
1579 self.classname = "observer"; // do it anyway
1584 self.classname = "player";
1585 campaign_bots_may_start = 1;
1589 self.playerid = (playerid_last = playerid_last + 1);
1591 PlayerStats_AddEvent(sprintf("kills-%d", self.playerid));
1593 if(clienttype(self) == CLIENTTYPE_BOT)
1594 PlayerStats_AddPlayer(self);
1596 if(autocvar_sv_eventlog)
1597 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
1599 LogTeamchange(self.playerid, self.team, 1);
1601 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1603 self.netname_previous = strzone(self.netname);
1605 bprint("^4", self.netname, "^4 connected");
1607 if(self.classname != "observer" && (g_domination || g_ctf))
1608 bprint(" and joined the ", ColoredTeamName(self.team));
1612 stuffcmd(self, strcat(clientstuff, "\n"));
1613 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1615 FixClientCvars(self);
1617 // spawnfunc_waypoint sprites
1618 WaypointSprite_InitClient(self);
1620 // Wazat's grappling hook
1621 SetGrappleHookBindings();
1623 // get version info from player
1624 stuffcmd(self, "cmd clientversion $gameversion\n");
1626 // get other cvars from player
1629 // notify about available teams
1632 CheckAllowedTeams(self);
1633 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1634 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1637 stuffcmd(self, "set _teams_available 0\n");
1639 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1643 self.classname = "observer";
1645 Spawnqueue_Insert(self);
1649 ctf_clientconnect();
1654 bot_relinkplayerlist();
1656 self.spectatortime = time;
1659 sprint(self, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1662 self.jointime = time;
1663 self.allowedTimeouts = autocvar_sv_timeout_number;
1665 if(clienttype(self) == CLIENTTYPE_REAL)
1667 if(autocvar_g_bugrigs || g_weaponarena == WEPBIT_TUBA)
1668 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1673 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1675 PlayerScore_Add(self, SP_LMS_RANK, 666);
1676 self.frags = FRAGS_SPECTATOR;
1680 if(!sv_foginterval && world.fog != "")
1681 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1683 SoundEntity_Attach(self);
1685 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", self.netaddress, " "), 0) >= 0)
1687 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1688 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1691 self.hitplotfh = -1;
1693 if(g_race || g_cts) {
1699 t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
1702 race_send_recordtime(MSG_ONE);
1703 race_send_speedaward(MSG_ONE);
1705 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
1706 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
1707 race_send_speedaward_alltimebest(MSG_ONE);
1710 for (i = 1; i <= RANKINGS_CNT; ++i) {
1711 race_SendRankings(i, 0, 0, MSG_ONE);
1714 else if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
1715 send_CSQC_teamnagger();
1718 set_dom_state(self);
1722 if(!autocvar_g_campaign)
1723 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), autocvar_welcome_message_time, 0);
1725 self.model_randomizer = random();
1732 Called when a client disconnects from the server
1735 .entity chatbubbleentity;
1737 void ClientDisconnect (void)
1740 vehicles_exit(VHEF_RELESE);
1742 if not(self.flags & FL_CLIENT)
1744 print("Warning: ClientDisconnect without ClientConnect\n");
1748 PlayerStats_AddGlobalInfo(self);
1750 CheatShutdownClient();
1752 if(self.hitplotfh >= 0)
1754 fclose(self.hitplotfh);
1755 self.hitplotfh = -1;
1759 anticheat_shutdown();
1761 playerdemo_shutdown();
1763 bot_clientdisconnect();
1768 if(autocvar_sv_eventlog)
1769 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1770 bprint ("^4",self.netname);
1771 bprint ("^4 disconnected\n");
1773 SoundEntity_Detach(self);
1776 MUTATOR_CALLHOOK(ClientDisconnect);
1778 Portal_ClearAll(self);
1780 RemoveGrapplingHook(self);
1781 if(self.flagcarried)
1782 DropFlag(self.flagcarried, world, world);
1783 if(self.ballcarried && g_nexball)
1784 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1786 // Here, everything has been done that requires this player to be a client.
1788 self.flags &~= FL_CLIENT;
1790 if (self.chatbubbleentity)
1791 remove (self.chatbubbleentity);
1793 if (self.killindicator)
1794 remove (self.killindicator);
1796 WaypointSprite_PlayerGone();
1798 bot_relinkplayerlist();
1802 Spawnqueue_Unmark(self);
1803 Spawnqueue_Remove(self);
1806 accuracy_free(self);
1807 ClientData_Detach();
1808 PlayerScore_Detach(self);
1810 if(self.netname_previous)
1811 strunzone(self.netname_previous);
1812 if(self.clientstatus)
1813 strunzone(self.clientstatus);
1814 if(self.weaponorder_byimpulse)
1815 strunzone(self.weaponorder_byimpulse);
1817 ClearPlayerSounds();
1820 remove(self.personal);
1830 void ChatBubbleThink()
1832 self.nextthink = time;
1833 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1835 if(self.owner) // but why can that ever be world?
1836 self.owner.chatbubbleentity = world;
1840 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1842 || self.owner.tetris_on
1845 self.model = self.mdl;
1850 void UpdateChatBubble()
1852 if (!self.modelindex)
1854 // spawn a chatbubble entity if needed
1855 if (!self.chatbubbleentity)
1857 self.chatbubbleentity = spawn();
1858 self.chatbubbleentity.owner = self;
1859 self.chatbubbleentity.exteriormodeltoclient = self;
1860 self.chatbubbleentity.think = ChatBubbleThink;
1861 self.chatbubbleentity.nextthink = time;
1862 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1863 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1864 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1865 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1866 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1867 self.chatbubbleentity.model = "";
1868 self.chatbubbleentity.effects = EF_LOWPRECISION;
1873 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1874 // added to the model skins
1875 /*void UpdateColorModHack()
1878 c = self.clientcolors & 15;
1879 // LordHavoc: only bothering to support white, green, red, yellow, blue
1880 if (!teamplay) self.colormod = '0 0 0';
1881 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1882 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1883 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1884 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1885 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1886 else self.colormod = '1 1 1';
1892 if(self.modelindex != 0 && autocvar_g_respawn_ghosts)
1894 self.solid = SOLID_NOT;
1895 self.takedamage = DAMAGE_NO;
1896 self.movetype = MOVETYPE_FLY;
1897 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1898 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1899 self.effects |= EF_ADDITIVE;
1900 self.oldcolormap = self.colormap;
1901 self.colormap = 0; // this originally was 512, but raises a warning in the engine, so get rid of it
1902 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1903 if(autocvar_g_respawn_ghosts_maxtime)
1904 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1908 self.effects |= EF_NODRAW; // prevent another CopyBody
1909 if(self.oldcolormap)
1911 self.colormap = self.oldcolormap;
1912 self.oldcolormap = 0;
1914 PutClientInServer();
1917 void play_countdown(float finished, string samp)
1919 if(clienttype(self) == CLIENTTYPE_REAL)
1920 if(floor(finished - time - frametime) != floor(finished - time))
1921 if(finished - time < 6)
1922 sound (self, CH_INFO, samp, VOL_BASE, ATTN_NORM);
1925 void player_powerups (void)
1927 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1928 olditems = self.items;
1930 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1932 SoundEntity_StartSound(self, CH_TRIGGER_SINGLE, "misc/jetpack_fly.wav", VOL_BASE, autocvar_g_jetpack_attenuation);
1933 self.modelflags |= MF_ROCKET;
1937 SoundEntity_StopSound(self, CH_TRIGGER_SINGLE);
1938 self.modelflags &~= MF_ROCKET;
1941 self.effects &~= (EF_DIMLIGHT | EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1943 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1946 Fire_ApplyDamage(self);
1947 Fire_ApplyEffect(self);
1951 self.effects |= EF_FULLBRIGHT;
1953 if (self.items & IT_STRENGTH)
1955 play_countdown(self.strength_finished, "misc/poweroff.wav");
1956 if (time > self.strength_finished)
1958 self.alpha = default_player_alpha;
1959 self.exteriorweaponentity.alpha = default_weapon_alpha;
1960 self.items &~= IT_STRENGTH;
1961 sprint(self, "^3Invisibility has worn off\n");
1966 if (time < self.strength_finished)
1968 self.alpha = g_minstagib_invis_alpha;
1969 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1970 self.items |= IT_STRENGTH;
1971 sprint(self, "^3You are invisible\n");
1975 if (self.items & IT_INVINCIBLE)
1977 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1978 if (time > self.invincible_finished && autocvar_g_balance_powerup_timer)
1980 self.items = self.items - (self.items & IT_INVINCIBLE);
1981 sprint(self, "^3Speed has worn off\n");
1986 if (time < self.invincible_finished)
1988 self.items = self.items | IT_INVINCIBLE;
1989 sprint(self, "^3You are on speed\n");
1993 else // if we're not in minstagib, continue. I added this else to replace the "return" which was here that broke the callhook for this function -- This code is nasty.
1995 if (self.items & IT_STRENGTH)
1997 play_countdown(self.strength_finished, "misc/poweroff.wav");
1998 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1999 if (time > self.strength_finished && autocvar_g_balance_powerup_timer)
2001 self.items = self.items - (self.items & IT_STRENGTH);
2002 sprint(self, "^3Strength has worn off\n");
2007 if (time < self.strength_finished)
2009 self.items = self.items | IT_STRENGTH;
2010 sprint(self, "^3Strength infuses your weapons with devastating power\n");
2013 if (self.items & IT_INVINCIBLE)
2015 play_countdown(self.invincible_finished, "misc/poweroff.wav");
2016 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
2017 if (time > self.invincible_finished && autocvar_g_balance_powerup_timer)
2019 self.items = self.items - (self.items & IT_INVINCIBLE);
2020 sprint(self, "^3Shield has worn off\n");
2025 if (time < self.invincible_finished)
2027 self.items = self.items | IT_INVINCIBLE;
2028 sprint(self, "^3Shield surrounds you\n");
2032 if(autocvar_g_nodepthtestplayers)
2033 self.effects = self.effects | EF_NODEPTHTEST;
2035 if(autocvar_g_fullbrightplayers)
2036 self.effects = self.effects | EF_FULLBRIGHT;
2038 // midair gamemode: damage only while in the air
2039 // if in midair mode, being on ground grants temporary invulnerability
2040 // (this is so that multishot weapon don't clear the ground flag on the
2041 // first damage in the frame, leaving the player vulnerable to the
2042 // remaining hits in the same frame)
2043 if (self.flags & FL_ONGROUND)
2045 self.spawnshieldtime = max(self.spawnshieldtime, time + autocvar_g_midair_shieldtime);
2047 if (time >= game_starttime)
2048 if (time < self.spawnshieldtime)
2049 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
2052 MUTATOR_CALLHOOK(PlayerPowerups);
2055 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
2057 if(current > stable)
2059 else if(current > stable - 0.25) // when close enough, "snap"
2062 return min(stable, current + (stable - current) * regenfactor * regenframetime);
2065 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
2067 if(current < stable)
2069 else if(current < stable + 0.25) // when close enough, "snap"
2072 return max(stable, current + (stable - current) * rotfactor * rotframetime);
2075 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
2077 if(current > rotstable)
2079 if(rotframetime > 0)
2081 current = CalcRot(current, rotstable, rotfactor, rotframetime);
2082 current = max(rotstable, current - rotlinear * rotframetime);
2085 else if(current < regenstable)
2087 if(regenframetime > 0)
2089 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
2090 current = min(regenstable, current + regenlinear * regenframetime);
2100 void player_regen (void)
2102 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
2103 maxh = autocvar_g_balance_health_rotstable;
2104 maxa = autocvar_g_balance_armor_rotstable;
2105 maxf = autocvar_g_balance_fuel_rotstable;
2106 minh = autocvar_g_balance_health_regenstable;
2107 mina = autocvar_g_balance_armor_regenstable;
2108 minf = autocvar_g_balance_fuel_regenstable;
2109 limith = autocvar_g_balance_health_limit;
2110 limita = autocvar_g_balance_armor_limit;
2111 limitf = autocvar_g_balance_fuel_limit;
2113 max_mod = regen_mod = rot_mod = limit_mod = 1;
2115 if (self.runes & RUNE_REGEN)
2117 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
2119 regen_mod = autocvar_g_balance_rune_regen_combo_regenrate;
2120 max_mod = autocvar_g_balance_rune_regen_combo_hpmod;
2121 limit_mod = autocvar_g_balance_rune_regen_combo_limitmod;
2125 regen_mod = autocvar_g_balance_rune_regen_regenrate;
2126 max_mod = autocvar_g_balance_rune_regen_hpmod;
2127 limit_mod = autocvar_g_balance_rune_regen_limitmod;
2130 else if (self.runes & CURSE_VENOM)
2132 max_mod = autocvar_g_balance_curse_venom_hpmod;
2133 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
2134 rot_mod = autocvar_g_balance_rune_regen_combo_rotrate;
2136 rot_mod = autocvar_g_balance_curse_venom_rotrate;
2137 limit_mod = autocvar_g_balance_curse_venom_limitmod;
2138 //if (!self.runes & RUNE_REGEN)
2139 // rot_mod = autocvar_g_balance_curse_venom_rotrate;
2141 maxh = maxh * max_mod;
2142 //maxa = maxa * max_mod;
2143 //maxf = maxf * max_mod;
2144 minh = minh * max_mod;
2145 //mina = mina * max_mod;
2146 //minf = minf * max_mod;
2147 limith = limith * limit_mod;
2148 limita = limita * limit_mod;
2149 //limitf = limitf * limit_mod;
2154 if (!g_minstagib && !g_ca && (!g_lms || autocvar_g_lms_regenerate))
2156 self.armorvalue = CalcRotRegen(self.armorvalue, mina, autocvar_g_balance_armor_regen, autocvar_g_balance_armor_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished), maxa, autocvar_g_balance_armor_rot, autocvar_g_balance_armor_rotlinear, rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
2157 self.health = CalcRotRegen(self.health, minh, autocvar_g_balance_health_regen, autocvar_g_balance_health_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished), maxh, autocvar_g_balance_health_rot, autocvar_g_balance_health_rotlinear, rot_mod * frametime * (time > self.pauserothealth_finished), limith);
2159 // if player rotted to death... die!
2161 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2164 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
2165 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, regen_mod * frametime * (time > self.pauseregen_finished) * (self.items & IT_FUEL_REGEN != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, rot_mod * frametime * (time > self.pauserotfuel_finished), limitf);
2168 float zoomstate_set;
2169 void SetZoomState(float z)
2171 if(z != self.zoomstate)
2174 ClientData_Touch(self);
2179 void GetPressedKeys(void) {
2180 MUTATOR_CALLHOOK(GetPressedKeys);
2181 if (self.movement_x > 0) // get if movement keys are pressed
2182 { // forward key pressed
2183 self.pressedkeys |= KEY_FORWARD;
2184 self.pressedkeys &~= KEY_BACKWARD;
2186 else if (self.movement_x < 0)
2187 { // backward key pressed
2188 self.pressedkeys |= KEY_BACKWARD;
2189 self.pressedkeys &~= KEY_FORWARD;
2193 self.pressedkeys &~= KEY_FORWARD;
2194 self.pressedkeys &~= KEY_BACKWARD;
2197 if (self.movement_y > 0)
2198 { // right key pressed
2199 self.pressedkeys |= KEY_RIGHT;
2200 self.pressedkeys &~= KEY_LEFT;
2202 else if (self.movement_y < 0)
2203 { // left key pressed
2204 self.pressedkeys |= KEY_LEFT;
2205 self.pressedkeys &~= KEY_RIGHT;
2209 self.pressedkeys &~= KEY_RIGHT;
2210 self.pressedkeys &~= KEY_LEFT;
2213 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
2214 self.pressedkeys |= KEY_JUMP;
2216 self.pressedkeys &~= KEY_JUMP;
2217 if (self.BUTTON_CROUCH)
2218 self.pressedkeys |= KEY_CROUCH;
2220 self.pressedkeys &~= KEY_CROUCH;
2224 ======================
2225 spectate mode routines
2226 ======================
2229 void SpectateCopy(entity spectatee) {
2231 MUTATOR_CALLHOOK(SpectateCopy);
2232 self.armortype = spectatee.armortype;
2233 self.armorvalue = spectatee.armorvalue;
2234 self.ammo_cells = spectatee.ammo_cells;
2235 self.ammo_shells = spectatee.ammo_shells;
2236 self.ammo_nails = spectatee.ammo_nails;
2237 self.ammo_rockets = spectatee.ammo_rockets;
2238 self.ammo_fuel = spectatee.ammo_fuel;
2239 self.clip_load = spectatee.clip_load;
2240 self.clip_size = spectatee.clip_size;
2241 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
2242 self.health = spectatee.health;
2244 self.items = spectatee.items;
2245 self.last_pickup = spectatee.last_pickup;
2246 self.hit_time = spectatee.hit_time;
2247 self.metertime = spectatee.metertime;
2248 self.strength_finished = spectatee.strength_finished;
2249 self.invincible_finished = spectatee.invincible_finished;
2250 self.pressedkeys = spectatee.pressedkeys;
2251 self.weapons = spectatee.weapons;
2252 self.switchweapon = spectatee.switchweapon;
2253 self.switchingweapon = spectatee.switchingweapon;
2254 self.weapon = spectatee.weapon;
2255 self.nex_charge = spectatee.nex_charge;
2256 self.nex_chargepool_ammo = spectatee.nex_chargepool_ammo;
2257 self.hagar_load = spectatee.hagar_load;
2258 self.minelayer_mines = spectatee.minelayer_mines;
2259 self.punchangle = spectatee.punchangle;
2260 self.view_ofs = spectatee.view_ofs;
2261 self.v_angle = spectatee.v_angle;
2262 self.velocity = spectatee.velocity;
2263 self.dmg_take = spectatee.dmg_take;
2264 self.dmg_save = spectatee.dmg_save;
2265 self.dmg_inflictor = spectatee.dmg_inflictor;
2266 self.angles = spectatee.v_angle;
2267 if(!self.BUTTON_USE)
2268 self.fixangle = TRUE;
2269 setorigin(self, spectatee.origin);
2270 setsize(self, spectatee.mins, spectatee.maxs);
2271 SetZoomState(spectatee.zoomstate);
2273 anticheat_spectatecopy(spectatee);
2275 //self.vehicle = spectatee.vehicle;
2277 self.hud = spectatee.hud;
2278 if(spectatee.vehicle)
2280 setorigin(self, spectatee.origin);
2281 self.velocity = spectatee.vehicle.velocity;
2282 self.v_angle += spectatee.vehicle.angles;
2283 //self.v_angle_x *= -1;
2284 self.vehicle_health = spectatee.vehicle_health;
2285 self.vehicle_shield = spectatee.vehicle_shield;
2286 self.vehicle_energy = spectatee.vehicle_energy;
2287 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
2288 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
2289 self.vehicle_reload1 = spectatee.vehicle_reload1;
2290 self.vehicle_reload2 = spectatee.vehicle_reload2;
2293 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
2294 WriteEntity(MSG_ONE, spectatee);
2295 //self.tur_head = spectatee.vehicle.vehicle_viewport;
2299 float SpectateUpdate() {
2303 if (self == self.enemy)
2306 if(self.enemy.classname != "player")
2309 SpectateCopy(self.enemy);
2315 // Returns next available player to spectate if g_ca_spectate_enemies == 0
2316 entity CA_SpectateNext(entity start) {
2317 if (start.team == self.team) {
2322 // continue from current player
2323 while(other && other.team != self.team) {
2324 other = find(other, classname, "player");
2328 // restart from begining
2329 other = find(other, classname, "player");
2330 while(other && other.team != self.team) {
2331 other = find(other, classname, "player");
2338 float SpectateNext() {
2339 other = find(self.enemy, classname, "player");
2340 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer) {
2341 // CA and ca players when spectating enemies is forbidden
2342 other = CA_SpectateNext(other);
2344 // other modes and ca spectators or spectating enemies is allowed
2346 other = find(other, classname, "player");
2352 if(self.enemy.classname == "player") {
2353 if(self.enemy.vehicle)
2356 WriteByte(MSG_ONE, SVC_SETVIEWPORT);
2357 WriteEntity(MSG_ONE, self.enemy);
2358 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2359 self.movetype = MOVETYPE_NONE;
2360 accuracy_resend(self);
2365 WriteByte(MSG_ONE, SVC_SETVIEW);
2366 WriteEntity(MSG_ONE, self.enemy);
2367 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2368 self.movetype = MOVETYPE_NONE;
2369 accuracy_resend(self);
2371 if(!SpectateUpdate())
2372 PutObserverInServer();
2382 ShowRespawnCountdown()
2384 Update a respawn countdown display.
2387 void ShowRespawnCountdown()
2390 if(self.deadflag == DEAD_NO) // just respawned?
2394 number = ceil(self.death_time - time);
2397 if(number <= self.respawn_countdown)
2399 self.respawn_countdown = number - 1;
2400 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
2401 AnnounceTo(self, strcat(ftos(number), ""));
2406 .float prevent_join_msgtime;
2407 void LeaveSpectatorMode()
2409 if(nJoinAllowed(1)) {
2410 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) {
2411 self.classname = "player";
2413 if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force)
2414 JoinBestTeam(self, FALSE, TRUE);
2416 if(autocvar_g_campaign)
2417 campaign_bots_may_start = 1;
2419 PutClientInServer();
2421 if(self.classname == "player")
2422 bprint ("^4", self.netname, "^4 is playing now\n");
2424 if(!autocvar_g_campaign)
2425 if (time < self.jointime + autocvar_welcome_message_time)
2426 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD); // clear MOTD
2428 if (self.prevent_join_msgtime)
2430 Send_CSQC_Centerprint_Generic_Expire(self, CPID_PREVENT_JOIN);
2431 self.prevent_join_msgtime = 0;
2436 if (g_ca && self.caplayer) {
2439 stuffcmd(self,"menu_showteamselect\n");
2444 //player may not join because of g_maxplayers is set
2445 if (time - self.prevent_join_msgtime > 2)
2447 Send_CSQC_Centerprint_Generic(self, CPID_PREVENT_JOIN, PREVENT_JOIN_TEXT, 0, 0);
2448 self.prevent_join_msgtime = time;
2454 * Determines whether the player is allowed to join. This depends on cvar
2455 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2456 * it checks whether the number of currently playing players exceeds g_maxplayers.
2457 * @return int number of free slots for players, 0 if none
2459 float nJoinAllowed(float includeMe) {
2460 if(self.team_forced < 0)
2461 return FALSE; // forced spectators can never join
2463 // TODO simplify this
2470 if (!autocvar_g_maxplayers)
2471 return maxclients - totalClients + includeMe;
2473 float currentlyPlaying;
2474 FOR_EACH_REALPLAYER(e)
2475 currentlyPlaying += 1;
2477 if(currentlyPlaying < autocvar_g_maxplayers)
2478 return min(maxclients - totalClients + includeMe, autocvar_g_maxplayers - currentlyPlaying);
2484 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2485 * g_maxplayers_spectator_blocktime seconds
2487 void checkSpectatorBlock() {
2488 if(self.classname == "spectator" || self.classname == "observer") {
2489 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2490 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2496 .float motd_actived_time; // used for both motd and campaign_message
2497 void PrintWelcomeMessage()
2499 if (self.motd_actived_time == 0) { // is there already a message showing?
2500 if (autocvar_g_campaign) {
2501 if ((self.classname == "player" && self.BUTTON_INFO) || (self.classname != "player")) {
2502 self.motd_actived_time = time;
2503 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, campaign_message, -1, 0);
2506 if ((time - self.jointime > autocvar_welcome_message_time) && self.BUTTON_INFO) {
2507 self.motd_actived_time = time;
2508 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), -1, 0);
2511 } else { // showing MOTD or campaign message
2512 if (autocvar_g_campaign) {
2513 if (self.BUTTON_INFO)
2514 self.motd_actived_time = time;
2515 else if ((time - self.motd_actived_time > 2) && self.classname == "player") { // hide it some seconds after BUTTON_INFO has been released
2516 self.motd_actived_time = 0;
2517 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2520 if ((time - self.jointime) > autocvar_welcome_message_time) {
2521 if (self.BUTTON_INFO)
2522 self.motd_actived_time = time;
2523 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2524 self.motd_actived_time = 0;
2525 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2532 void ObserverThink()
2534 float prefered_movetype;
2535 if (self.flags & FL_JUMPRELEASED) {
2536 if (self.BUTTON_JUMP && !self.version_mismatch) {
2537 self.flags &~= FL_JUMPRELEASED;
2538 self.flags |= FL_SPAWNING;
2539 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2540 self.flags &~= FL_JUMPRELEASED;
2541 if(SpectateNext() == 1) {
2542 self.classname = "spectator";
2545 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2546 if (self.movetype != prefered_movetype)
2547 self.movetype = prefered_movetype;
2550 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2551 self.flags |= FL_JUMPRELEASED;
2552 if(self.flags & FL_SPAWNING)
2554 self.flags &~= FL_SPAWNING;
2555 LeaveSpectatorMode();
2561 PrintWelcomeMessage();
2564 void SpectatorThink()
2566 if (self.flags & FL_JUMPRELEASED) {
2567 if (self.BUTTON_JUMP && !self.version_mismatch) {
2568 self.flags &~= FL_JUMPRELEASED;
2569 self.flags |= FL_SPAWNING;
2570 } else if(self.BUTTON_ATCK) {
2571 self.flags &~= FL_JUMPRELEASED;
2572 if(SpectateNext() == 1) {
2573 self.classname = "spectator";
2575 self.classname = "observer";
2576 PutClientInServer();
2578 } else if (self.BUTTON_ATCK2) {
2579 self.flags &~= FL_JUMPRELEASED;
2580 self.classname = "observer";
2581 PutClientInServer();
2583 if(!SpectateUpdate())
2584 PutObserverInServer();
2587 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2588 self.flags |= FL_JUMPRELEASED;
2589 if(self.flags & FL_SPAWNING)
2591 self.flags &~= FL_SPAWNING;
2592 LeaveSpectatorMode();
2596 if(!SpectateUpdate())
2597 PutObserverInServer();
2600 PrintWelcomeMessage();
2601 self.flags |= FL_CLIENT | FL_NOTARGET;
2607 if(self.classname != "player")
2612 vehicles_exit(VHEF_NORMAL);
2616 // a use key was pressed; call handlers
2620 MUTATOR_CALLHOOK(PlayerUseKey);
2623 .float touchexplode_time;
2629 Called every frame for each client before the physics are run
2632 .float usekeypressed;
2633 void() ctf_setstatus;
2634 void() nexball_setstatus;
2636 void PlayerPreThink (void)
2638 WarpZone_PlayerPhysics_FixVAngle();
2640 self.stat_game_starttime = game_starttime;
2641 self.stat_allow_oldnexbeam = autocvar_g_allow_oldnexbeam;
2642 self.stat_leadlimit = autocvar_leadlimit;
2646 // physics frames: update anticheat stuff
2647 anticheat_prethink();
2650 if(blockSpectators && frametime)
2651 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2652 checkSpectatorBlock();
2656 if(self.netname_previous != self.netname)
2658 if(autocvar_sv_eventlog)
2659 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2660 if(self.netname_previous)
2661 strunzone(self.netname_previous);
2662 self.netname_previous = strzone(self.netname);
2666 if(self.version_nagtime)
2667 if(self.cvar_g_xonoticversion)
2668 if(time > self.version_nagtime)
2670 // don't notify git users
2671 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2673 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2675 // notify release users if connecting to git
2676 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2677 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2682 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2685 // give users new version
2686 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Xonotic ", autocvar_g_xonoticversion, "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.org/^1!\n");
2687 sprint(self, strcat("\{1}^1NOTE: ^3Xonotic ", autocvar_g_xonoticversion, "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.org/^1!\n"));
2691 // notify users about old server version
2692 print("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2693 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2697 self.version_nagtime = 0;
2701 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2703 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2704 self.max_armorvalue = 0;
2708 if (TetrisPreFrame())
2712 MUTATOR_CALLHOOK(PlayerPreThink);
2714 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2716 if(self.BUTTON_USE && !self.usekeypressed)
2718 self.usekeypressed = self.BUTTON_USE;
2721 PrintWelcomeMessage();
2723 if(self.classname == "player") {
2724 // if(self.netname == "Wazat")
2725 // bprint(self.classname, "\n");
2727 CheckRules_Player();
2729 if (intermission_running)
2731 IntermissionThink (); // otherwise a button could be missed between
2732 return; // the think tics
2735 //don't allow the player to turn around while game is paused!
2736 if(timeoutStatus == 2) {
2737 // FIXME turn this into CSQC stuff
2738 self.v_angle = self.lastV_angle;
2739 self.angles = self.lastV_angle;
2740 self.fixangle = TRUE;
2745 if(self.health <= 0 && autocvar_g_deathglow)
2747 if(self.glowmod_x > 0)
2748 self.glowmod_x -= autocvar_g_deathglow * frametime;
2750 self.glowmod_x = -1;
2751 if(self.glowmod_y > 0)
2752 self.glowmod_y -= autocvar_g_deathglow * frametime;
2754 self.glowmod_y = -1;
2755 if(self.glowmod_z > 0)
2756 self.glowmod_z -= autocvar_g_deathglow * frametime;
2758 self.glowmod_z = -1;
2762 // set weapon and player glowmod
2763 self.glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2765 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge)
2767 self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_animlimit);
2768 self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_animlimit);
2769 self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.nex_charge / autocvar_g_balance_nex_charge_animlimit);
2771 if(self.nex_charge > autocvar_g_balance_nex_charge_animlimit)
2773 self.weaponentity_glowmod_x = self.weaponentity_glowmod_x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.nex_charge - autocvar_g_balance_nex_charge_animlimit) / (1 - autocvar_g_balance_nex_charge_animlimit);
2774 self.weaponentity_glowmod_y = self.weaponentity_glowmod_y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.nex_charge - autocvar_g_balance_nex_charge_animlimit) / (1 - autocvar_g_balance_nex_charge_animlimit);
2775 self.weaponentity_glowmod_z = self.weaponentity_glowmod_z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.nex_charge - autocvar_g_balance_nex_charge_animlimit) / (1 - autocvar_g_balance_nex_charge_animlimit);
2779 self.weaponentity_glowmod = self.glowmod;
2785 minstagib_ammocheck();
2787 if (self.deadflag != DEAD_NO)
2789 float button_pressed, force_respawn;
2790 if(self.personal && g_race_qualifying)
2792 if(time > self.death_time)
2794 self.death_time = time + 1; // only retry once a second
2803 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2804 force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
2805 if (self.deadflag == DEAD_DYING)
2808 self.deadflag = DEAD_RESPAWNING;
2809 else if(!button_pressed)
2810 self.deadflag = DEAD_DEAD;
2812 else if (self.deadflag == DEAD_DEAD)
2815 self.deadflag = DEAD_RESPAWNABLE;
2817 else if (self.deadflag == DEAD_RESPAWNABLE)
2820 self.deadflag = DEAD_RESPAWNING;
2822 else if (self.deadflag == DEAD_RESPAWNING)
2824 if(time > self.death_time)
2826 self.death_time = time + 1; // only retry once a second
2830 ShowRespawnCountdown();
2834 // FIXME from now on self.deadflag is always 0 (and self.health is never < 1)
2835 // so (self.deadflag == DEAD_NO) is always true in the code below
2838 if(time > self.touchexplode_time)
2839 if(self.classname == "player")
2840 if(self.deadflag == DEAD_NO)
2841 if not(IS_INDEPENDENT_PLAYER(self))
2842 FOR_EACH_PLAYER(other) if(self != other)
2844 if(time > other.touchexplode_time)
2845 if(other.deadflag == DEAD_NO)
2846 if not(IS_INDEPENDENT_PLAYER(other))
2847 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2849 PlayerTouchExplode(self, other);
2850 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2854 if(g_lms && !self.deadflag && autocvar_g_lms_campcheck_interval)
2858 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2859 dist = self.prevorigin - self.origin;
2861 self.lms_traveled_distance += fabs(vlen(dist));
2863 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime))
2865 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
2866 self.lms_traveled_distance = 0;
2869 if(time > self.lms_nextcheck)
2871 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2872 if(self.lms_traveled_distance < autocvar_g_lms_campcheck_distance)
2874 centerprint(self, autocvar_g_lms_campcheck_message);
2875 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2876 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2877 Damage(self, self, self, bound(0, autocvar_g_lms_campcheck_damage, self.health + self.armorvalue * autocvar_g_balance_armor_blockpercent + 5), DEATH_CAMP, self.origin, '0 0 0');
2879 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval;
2880 self.lms_traveled_distance = 0;
2884 self.prevorigin = self.origin;
2886 if (((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss) && self.animstate_startframe != self.anim_melee_x) // prevent crouching if using melee attack
2891 self.view_ofs = PL_CROUCH_VIEW_OFS;
2892 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2893 // setanim(self, self.anim_duck, FALSE, TRUE, TRUE); // this anim is BROKEN anyway
2900 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2901 if (!trace_startsolid)
2903 self.crouch = FALSE;
2904 self.view_ofs = PL_VIEW_OFS;
2905 setsize (self, PL_MIN, PL_MAX);
2910 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2912 if(self.bloodloss_timer < time)
2914 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2915 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2921 GrapplingHookFrame();
2923 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2926 self.items &~= self.items_added;
2930 self.items_added = 0;
2931 if(self.items & IT_JETPACK)
2932 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2933 self.items_added |= IT_FUEL;
2935 self.items |= self.items_added;
2940 // rot nex charge to the charge limit
2941 if(autocvar_g_balance_nex_charge_rot_rate && self.nex_charge > autocvar_g_balance_nex_charge_limit && self.nex_charge_rottime < time)
2942 self.nex_charge = bound(autocvar_g_balance_nex_charge_limit, self.nex_charge - autocvar_g_balance_nex_charge_rot_rate * frametime / W_TICSPERFRAME, 1);
2951 nexball_setstatus();
2954 secrets_setstatus();
2956 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2958 //self.angles_y=self.v_angle_y + 90; // temp
2959 } else if(gameover) {
2960 if (intermission_running)
2961 IntermissionThink (); // otherwise a button could be missed between
2963 } else if(self.classname == "observer") {
2965 } else if(self.classname == "spectator") {
2970 SetZoomState(self.BUTTON_ZOOM || self.BUTTON_ZOOMSCRIPT || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_RIFLE && autocvar_g_balance_rifle_secondary == 0));
2972 float oldspectatee_status;
2973 oldspectatee_status = self.spectatee_status;
2974 if(self.classname == "spectator")
2975 self.spectatee_status = num_for_edict(self.enemy);
2976 else if(self.classname == "observer")
2977 self.spectatee_status = num_for_edict(self);
2979 self.spectatee_status = 0;
2980 if(self.spectatee_status != oldspectatee_status)
2982 ClientData_Touch(self);
2984 race_InitSpectator();
2987 if(self.teamkill_soundtime)
2988 if(time > self.teamkill_soundtime)
2990 self.teamkill_soundtime = 0;
2992 entity oldpusher, oldself;
2994 oldself = self; self = self.teamkill_soundsource;
2995 oldpusher = self.pusher; self.pusher = oldself;
2997 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2999 self.pusher = oldpusher;
3003 if(self.taunt_soundtime)
3004 if(time > self.taunt_soundtime)
3006 self.taunt_soundtime = 0;
3007 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
3010 target_voicescript_next(self);
3012 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
3014 self.clip_load = self.clip_size = 0;
3017 float isInvisibleString(string s)
3020 s = strdecolorize(s);
3021 for((i = 0), (n = strlen(s)); i < n; ++i)
3029 case 192: // charmap space
3030 if (!autocvar_utf8_enable)
3033 case 160: // space in unicode fonts
3034 case 0xE000 + 192: // utf8 charmap space
3035 if (autocvar_utf8_enable)
3048 Called every frame for each client after the physics are run
3051 .float idlekick_lasttimeleft;
3052 .entity showheadshotbbox;
3053 void showheadshotbbox_think()
3055 if(self.owner.showheadshotbbox != self)
3060 self.nextthink = time;
3061 setorigin(self, self.owner.origin);
3062 setsize(self, GetHeadshotMins(self.owner), GetHeadshotMaxs(self.owner));
3064 void PlayerPostThink (void)
3066 // Savage: Check for nameless players
3067 if (isInvisibleString(self.netname)) {
3068 self.netname = "Player";
3069 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));
3072 if(sv_maxidle && frametime)
3074 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
3076 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
3078 if(self.idlekick_lasttimeleft)
3080 Send_CSQC_Centerprint_Generic_Expire(self, CPID_DISCONNECT_IDLING);
3081 self.idlekick_lasttimeleft = 0;
3085 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
3086 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
3088 if(!self.idlekick_lasttimeleft)
3089 Send_CSQC_Centerprint_Generic(self, CPID_DISCONNECT_IDLING, "^3Stop idling!\n^3Disconnecting in %d seconds...", 1, timeleft);
3093 bprint("^3", self.netname, "^3 was kicked for idling.\n");
3094 AnnounceTo(self, "terminated");
3098 else if(timeleft <= 10)
3100 if(timeleft != self.idlekick_lasttimeleft)
3101 AnnounceTo(self, ftos(timeleft));
3102 self.idlekick_lasttimeleft = timeleft;
3107 if(self.impulse == 100)
3109 if (TetrisPostFrame())
3115 //CheckPlayerJump();
3117 if(self.classname == "player") {
3118 CheckRules_Player();
3122 if (intermission_running)
3123 return; // intermission or finale
3125 } else if (self.classname == "observer") {
3127 } else if (self.classname == "spectator") {
3133 for(i = 0; i < 1000; ++i)
3136 end = self.origin + '0 0 1024' + 512 * randomvec();
3137 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
3138 if(trace_fraction < 1)
3139 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
3141 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
3149 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
3151 if(self.waypointsprite_attachedforcarrier)
3152 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent));
3154 if(self.classname == "player" && self.deadflag == DEAD_NO && autocvar_r_showbboxes)
3156 if(!self.showheadshotbbox)
3158 self.showheadshotbbox = spawn();
3159 self.showheadshotbbox.classname = "headshotbbox";
3160 self.showheadshotbbox.owner = self;
3161 self.showheadshotbbox.think = showheadshotbbox_think;
3162 self.showheadshotbbox.nextthink = time;
3163 self = self.showheadshotbbox;
3170 if(self.showheadshotbbox)
3171 if(self.showheadshotbbox && !wasfreed(self.showheadshotbbox))
3172 remove(self.showheadshotbbox);
3177 if((g_cts || g_race) && self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
3179 if(!self.stored_netname)
3180 self.stored_netname = strzone(uid2name(self.crypto_idfp));
3181 if(self.stored_netname != self.netname)
3183 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
3184 strunzone(self.stored_netname);
3185 self.stored_netname = strzone(self.netname);
3191 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));