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(0, SVC_TEMPENTITY);
6 WriteByte(0, TE_CSQC_TEAMNAGGER);
9 void send_CSQC_nexvelocity(entity e) {
11 WriteByte(MSG_ONE, SVC_TEMPENTITY);
12 WriteByte(MSG_ONE, TE_CSQC_NEX_VELOCITY);
13 WriteShort(MSG_ONE, cvar("g_balance_nex_velocitydependent_minspeed"));
14 WriteShort(MSG_ONE, cvar("g_balance_nex_velocitydependent_maxspeed"));
15 WriteShort(MSG_ONE, cvar("g_balance_nex_velocitydependent_falloff_factor") * 10000);
18 void send_CSQC_cr_maxbullets(entity e) {
20 WriteByte(MSG_ONE, SVC_TEMPENTITY);
21 WriteByte(MSG_ONE, TE_CSQC_CR_MAXBULLETS);
22 WriteByte(MSG_ONE, cvar("g_balance_campingrifle_magazinecapacity"));
25 void Announce(string snd) {
26 WriteByte(MSG_ALL, SVC_TEMPENTITY);
27 WriteByte(MSG_ALL, TE_CSQC_ANNOUNCE);
28 WriteString(MSG_ALL, snd);
31 void AnnounceTo(entity e, string snd) {
32 if (clienttype(e) == CLIENTTYPE_REAL)
35 WriteByte(MSG_ONE, SVC_TEMPENTITY);
36 WriteByte(MSG_ONE, TE_CSQC_ANNOUNCE);
37 WriteString(MSG_ONE, snd);
41 float ClientData_Send(entity to, float sf)
52 if(to.classname == "spectator")
58 sf |= 1; // forced scoreboard
59 if(to.spectatee_status)
60 sf |= 2; // spectator ent number follows
63 if(e.porto_v_angle_held)
64 sf |= 8; // angles held
66 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
67 WriteByte(MSG_ENTITY, sf);
70 WriteByte(MSG_ENTITY, to.spectatee_status);
74 WriteAngle(MSG_ENTITY, e.v_angle_x);
75 WriteAngle(MSG_ENTITY, e.v_angle_y);
81 void ClientData_Attach()
83 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
84 self.clientdata.drawonlytoclient = self;
85 self.clientdata.owner = self;
88 void ClientData_Detach()
90 remove(self.clientdata);
91 self.clientdata = world;
94 void ClientData_Touch(entity e)
96 e.clientdata.SendFlags = 1;
98 // make it spectatable
100 FOR_EACH_REALCLIENT(e2)
103 if(e2.classname == "spectator")
105 e2.clientdata.SendFlags = 1;
110 .vector spawnpoint_score;
111 .string netname_previous;
113 void spawnfunc_info_player_survivor (void)
115 spawnfunc_info_player_deathmatch();
118 void spawnfunc_info_player_start (void)
120 spawnfunc_info_player_deathmatch();
123 void spawnfunc_info_player_deathmatch (void)
125 self.classname = "info_player_deathmatch";
126 relocate_spawnpoint();
129 void spawnpoint_use()
132 if(have_team_spawns > 0)
134 self.team = activator.team;
135 some_spawn_has_been_used = 1;
140 // _x: prio (-1 if unusable)
142 vector Spawn_Score(entity spot, entity playerlist, float teamcheck, float anypoint)
144 float shortest, thisdist;
150 // filter out spots for the wrong team
152 if(spot.team != teamcheck)
156 if(spot.target == "")
159 if(clienttype(self) == CLIENTTYPE_REAL)
161 if(spot.restriction == 1)
166 if(spot.restriction == 2)
170 // filter out spots for assault
171 if(spot.target != "") {
174 ent = find(world, targetname, spot.target);
177 if(ent.classname == "target_objective")
180 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
184 else if(ent.classname == "trigger_race_checkpoint")
187 if(!anypoint) // spectators may spawn everywhere
190 if(g_race_qualifying)
193 if(ent.race_checkpoint != 0)
195 if(spot.race_place != race_lowest_place_spawn)
200 if(ent.race_checkpoint != self.race_respawn_checkpoint)
202 // try reusing the previous spawn
203 if(ent == self.race_respawn_spotref || spot == self.race_respawn_spotref)
205 if(ent.race_checkpoint == 0)
208 pl = self.race_place;
209 if(pl > race_highest_place_spawn)
211 if(pl == 0 && !self.race_started)
212 pl = race_highest_place_spawn; // use last place if he has not even touched finish yet
213 if(spot.race_place != pl)
220 ent = find(ent, targetname, spot.target);
228 shortest = vlen(world.maxs - world.mins);
229 for(player = playerlist; player; player = player.chain)
232 thisdist = vlen(player.origin - spot.origin);
233 if (thisdist < shortest)
236 return prio * '1 0 0' + shortest * '0 1 0';
241 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck, float anypoint)
243 local entity spot, spotlist, spotlistend;
244 spawn_allgood = TRUE;
250 for(spot = firstspot; spot; spot = spot.chain)
252 spot.spawnpoint_score = Spawn_Score(spot, playerlist, teamcheck, anypoint);
254 if(cvar("spawn_debugview"))
256 setmodel(spot, "models/runematch/rune.mdl");
257 if(spot.spawnpoint_score_y < mindist)
259 spot.colormod = '1 0 0';
264 spot.colormod = '0 1 0';
265 spot.scale = spot.spawnpoint_score_y / mindist;
269 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
271 if(spot.spawnpoint_score_y < mindist)
273 // too short distance
274 spawn_allgood = FALSE;
279 spawn_allbad = FALSE;
282 spotlistend.chain = spot;
289 if(spot.team != teamcheck)
290 error("invalid spawn added");
292 print("added ", etos(spot), "\n");
298 spotlistend.chain = world;
303 for(e = spotlist; e; e = e.chain)
305 print("seen ", etos(e), "\n");
306 if(e.team != teamcheck)
307 error("invalid spawn found");
314 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
316 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
317 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
320 RandomSelection_Init();
321 for(spot = firstspot; spot; spot = spot.chain)
322 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);
324 return RandomSelection_chosen_ent;
331 Finds a point to respawn
334 entity SelectSpawnPoint (float anypoint)
336 local float teamcheck;
337 local entity firstspot_new;
338 local entity spot, firstspot, playerlist;
340 spot = find (world, classname, "testplayerstart");
346 if(!anypoint && have_team_spawns > 0)
347 teamcheck = self.team;
349 // get the list of players
350 playerlist = findchain(classname, "player");
351 // get the entire list of spots
352 firstspot = findchain(classname, "info_player_deathmatch");
353 // filter out the bad ones
354 // (note this returns the original list if none survived)
357 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
361 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck, anypoint);
363 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck, anypoint);
364 firstspot = firstspot_new;
366 // there is 50/50 chance of choosing a random spot or the furthest spot
367 // (this means that roughly every other spawn will be furthest, so you
368 // usually won't get fragged at spawn twice in a row)
369 if (arena_roundbased && !g_ca)
371 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck, anypoint);
373 firstspot = firstspot_new;
374 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
376 else if (random() > cvar("g_spawn_furthest"))
377 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
379 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
382 if(cvar("spawn_debugview"))
384 print("spot mindistance: ", vtos(spot.spawnpoint_score), "\n");
388 for(e = firstspot; e; e = e.chain)
389 if(e.team != teamcheck)
390 error("invalid spawn found");
395 if(cvar("spawn_debug"))
399 if(some_spawn_has_been_used)
400 return world; // team can't spawn any more, because of actions of other team
402 error("Cannot find a spawn point - please fix the map!");
413 Checks if the argument string can be a valid playermodel.
414 Returns a valid one in doubt.
417 string FallbackPlayerModel;
418 string CheckPlayerModel(string plyermodel) {
419 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
421 // note: we cannot summon Don Strunzone here, some player may
422 // still have the model string set. In case anyone manages how
423 // to change a cvar default, we'll have a small leak here.
424 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
426 if(strlen(plyermodel) < 4)
427 return FallbackPlayerModel;
428 if( substring(plyermodel,0,14) != "models/player/")
429 return FallbackPlayerModel;
430 else if(cvar("sv_servermodelsonly"))
432 if(substring(plyermodel,-4,4) != ".zym")
433 if(substring(plyermodel,-4,4) != ".dpm")
434 if(substring(plyermodel,-4,4) != ".iqm")
435 if(substring(plyermodel,-4,4) != ".md3")
436 if(substring(plyermodel,-4,4) != ".psk")
437 return FallbackPlayerModel;
438 // forbid the LOD models
439 if(substring(plyermodel, -9,5) == "_lod1")
440 return FallbackPlayerModel;
441 if(substring(plyermodel, -9,5) == "_lod2")
442 return FallbackPlayerModel;
443 if(plyermodel != strtolower(plyermodel))
444 return FallbackPlayerModel;
445 if(!fexists(plyermodel))
446 return FallbackPlayerModel;
453 Client_customizeentityforclient
458 void Client_uncustomizeentityforclient()
460 if(self.modelindex == 0) // no need to uncustomize then
462 self.modelindex = self.modelindex_lod0;
463 self.skin = self.skinindex;
466 float Client_customizeentityforclient()
470 if(self.modelindex == 0)
477 t0 = gettime(GETTIME_HIRES); // reference
482 #ifdef ALLOW_FORCEMODELS
483 if(other.cvar_cl_forceplayermodelsfromxonotic)
484 if not(self.modelindex_lod0_from_xonotic)
486 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
490 self.skin = modelsource.skinindex;
493 if(modelsource == self)
494 self.skin = modelsource.skinindex;
496 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
500 // other: the player viewing me
504 if(other.cvar_cl_playerdetailreduction <= 0)
506 if(other.cvar_cl_playerdetailreduction <= -2)
507 self.modelindex = modelsource.modelindex_lod2;
508 else if(other.cvar_cl_playerdetailreduction <= -1)
509 self.modelindex = modelsource.modelindex_lod1;
511 self.modelindex = modelsource.modelindex_lod0;
515 distance = vlen(self.origin - other.origin);
516 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
517 if(f > sv_loddistance2)
518 self.modelindex = modelsource.modelindex_lod2;
519 else if(f > sv_loddistance1)
520 self.modelindex = modelsource.modelindex_lod1;
522 self.modelindex = modelsource.modelindex_lod0;
527 t1 = gettime(GETTIME_HIRES); // reference
528 client_cefc_accumulator += (t1 - t0);
534 void setmodel_lod(entity e, string modelname)
540 // FIXME: this only supports 3-letter extensions
541 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
544 setmodel(e, s); // players have high precision
545 self.modelindex_lod1 = self.modelindex;
548 self.modelindex_lod1 = -1;
550 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
553 setmodel(e, s); // players have high precision
554 self.modelindex_lod2 = self.modelindex;
557 self.modelindex_lod2 = -1;
559 precache_model(modelname);
560 setmodel(e, modelname); // players have high precision
561 self.modelindex_lod0 = self.modelindex;
563 if(self.modelindex_lod1 < 0)
564 self.modelindex_lod1 = self.modelindex;
566 if(self.modelindex_lod2 < 0)
567 self.modelindex_lod2 = self.modelindex;
571 precache_model(modelname);
572 setmodel(e, modelname); // players have high precision
573 self.modelindex_lod0 = self.modelindex;
574 // save it for possible player model forcing
577 s = whichpack(self.model);
578 self.modelindex_lod0_from_xonotic = ((s == "") || (substring(s, 0, 4) == "data"));
580 player_setupanimsformodel();
581 UpdatePlayerSounds();
588 putting a client as observer in the server
591 void FixPlayermodel();
592 void PutObserverInServer (void)
596 race_PreSpawnObserver();
598 spot = SelectSpawnPoint (TRUE);
600 error("No spawnpoints for observers?!?\n");
601 RemoveGrapplingHook(self); // Wazat's Grappling Hook
603 if(clienttype(self) == CLIENTTYPE_REAL)
606 WriteByte(MSG_ONE, SVC_SETVIEW);
607 WriteEntity(MSG_ONE, self);
612 Portal_ClearAll(self);
615 DropFlag(self.flagcarried, world, world);
618 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
620 WaypointSprite_PlayerDead();
622 if not(g_ca) // don't reset teams when moving a ca player to the spectators
623 self.team = -1; // move this as it is needed to log the player spectating in eventlog
625 if(self.killcount != -666) {
627 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
628 bprint ("^4", self.netname, "^4 has no more lives left\n");
630 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
632 bprint ("^4", self.netname, "^4 is spectating now\n");
634 if(self.just_joined == FALSE) {
635 LogTeamchange(self.playerid, -1, 4);
637 self.just_joined = FALSE;
640 PlayerScore_Clear(self); // clear scores when needed
642 self.spectatortime = time;
644 self.classname = "observer";
645 self.iscreature = FALSE;
647 self.takedamage = DAMAGE_NO;
648 self.solid = SOLID_NOT;
649 self.movetype = MOVETYPE_NOCLIP;
650 self.flags = FL_CLIENT | FL_NOTARGET;
651 self.armorvalue = 666;
653 self.armorvalue = cvar("g_balance_armor_start");
654 self.pauserotarmor_finished = 0;
655 self.pauserothealth_finished = 0;
656 self.pauseregen_finished = 0;
657 self.damageforcescale = 0;
664 self.pain_finished = 0;
665 self.strength_finished = 0;
666 self.invincible_finished = 0;
668 self.think = SUB_Null;
672 self.deadflag = DEAD_NO;
673 self.angles = spot.angles;
675 self.fixangle = TRUE;
678 self.view_ofs = PL_VIEW_OFS;
679 setorigin (self, spot.origin);
680 setsize (self, '0 0 0', '0 0 0');
681 self.prevorigin = self.origin;
689 self.weaponmodel = "";
690 self.weaponentity = world;
691 self.exteriorweaponentity = world;
692 self.killcount = -666;
693 self.velocity = '0 0 0';
694 self.avelocity = '0 0 0';
695 self.punchangle = '0 0 0';
696 self.punchvector = '0 0 0';
697 self.oldvelocity = self.velocity;
698 self.fire_endtime = -1;
701 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
705 if(self.version_mismatch)
707 Spawnqueue_Unmark(self);
708 Spawnqueue_Remove(self);
712 Spawnqueue_Insert(self);
717 // Only if the player cannot play at all
718 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
719 self.frags = FRAGS_SPECTATOR;
721 self.frags = FRAGS_LMS_LOSER;
724 self.frags = FRAGS_SPECTATOR;
726 MUTATOR_CALLHOOK(MakePlayerObserver);
729 float RestrictSkin(float s)
738 void FixPlayermodel()
740 local string defaultmodel;
741 local float defaultskin, chmdl, oldskin;
746 if(cvar("sv_defaultcharacter") == 1) {
752 s = Team_ColorNameLowerCase(self.team);
755 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
756 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
760 if(defaultmodel == "")
762 defaultmodel = cvar_string("sv_defaultplayermodel");
763 defaultskin = cvar("sv_defaultplayerskin");
767 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
770 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
771 self.model = ""; // force the != checks to return true
774 if(defaultmodel != "")
776 if (defaultmodel != self.model)
780 setmodel_lod (self, defaultmodel);
781 setsize (self, m1, m2);
785 oldskin = self.skinindex;
786 self.skinindex = defaultskin;
788 if (self.playermodel != self.model || self.playermodel == "")
790 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
793 setmodel_lod (self, self.playermodel);
794 setsize (self, m1, m2);
798 oldskin = self.skinindex;
799 self.skinindex = RestrictSkin(stof(self.playerskin));
802 if(chmdl || oldskin != self.skinindex)
803 self.species = player_getspecies(); // model or skin has changed
806 if(strlen(cvar_string("sv_defaultplayercolors")))
807 if(self.clientcolors != cvar("sv_defaultplayercolors"))
808 setcolor(self, cvar("sv_defaultplayercolors"));
811 void PlayerTouchExplode(entity p1, entity p2)
814 org = (p1.origin + p2.origin) * 0.5;
815 org_z += (p1.mins_z + p2.mins_z) * 0.5;
822 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
830 Called when a client spawns in the server
833 //void() ctf_playerchanged;
834 void PutClientInServer (void)
836 if(clienttype(self) == CLIENTTYPE_BOT)
838 self.classname = "player";
840 else if(clienttype(self) == CLIENTTYPE_REAL)
843 WriteByte(MSG_ONE, SVC_SETVIEW);
844 WriteEntity(MSG_ONE, self);
847 // player is dead and becomes observer
848 // FIXME fix LMS scoring for new system
851 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
852 self.classname = "observer";
855 if(g_arena || (g_ca && !allowed_to_spawn))
857 self.classname = "observer";
860 self.classname = "observer";
862 if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {
863 entity spot, oldself;
867 JoinBestTeam(self, FALSE, TRUE);
871 spot = SelectSpawnPoint (FALSE);
874 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
875 return; // spawn failed
878 RemoveGrapplingHook(self); // Wazat's Grappling Hook
880 self.classname = "player";
881 self.wasplayer = TRUE;
882 self.iscreature = TRUE;
883 self.movetype = MOVETYPE_WALK;
884 self.solid = SOLID_SLIDEBOX;
885 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
886 if(cvar("g_playerclip_collisions"))
887 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
888 if(clienttype(self) == CLIENTTYPE_BOT && cvar("g_botclip_collisions"))
889 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
890 self.frags = FRAGS_PLAYER;
891 if(independent_players)
892 MAKE_INDEPENDENT_PLAYER(self);
893 self.flags = FL_CLIENT;
894 self.takedamage = DAMAGE_AIM;
896 self.effects = EF_FULLBRIGHT;
899 self.air_finished = time + 12;
904 self.ammo_shells = warmup_start_ammo_shells;
905 self.ammo_nails = warmup_start_ammo_nails;
906 self.ammo_rockets = warmup_start_ammo_rockets;
907 self.ammo_cells = warmup_start_ammo_cells;
908 self.ammo_fuel = warmup_start_ammo_fuel;
909 self.health = warmup_start_health;
910 self.armorvalue = warmup_start_armorvalue;
911 self.weapons = warmup_start_weapons;
915 self.ammo_shells = start_ammo_shells;
916 self.ammo_nails = start_ammo_nails;
917 self.ammo_rockets = start_ammo_rockets;
918 self.ammo_cells = start_ammo_cells;
919 self.ammo_fuel = start_ammo_fuel;
920 self.health = start_health;
921 self.armorvalue = start_armorvalue;
922 self.weapons = start_weapons;
925 if(g_weaponarena_random)
926 self.weapons = randombits(self.weapons, g_weaponarena_random, FALSE);
928 self.items = start_items;
929 self.jump_interval = time;
931 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
932 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
933 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
934 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
935 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
936 //extend the pause of rotting if client was reset at the beginning of the countdown
937 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
938 self.spawnshieldtime += game_starttime - time;
939 self.pauserotarmor_finished += game_starttime - time;
940 self.pauserothealth_finished += game_starttime - time;
941 self.pauseregen_finished += game_starttime - time;
943 self.damageforcescale = 2;
950 self.pain_finished = 0;
951 self.strength_finished = 0;
952 self.invincible_finished = 0;
954 // players have no think function
955 self.think = SUB_Null;
959 self.ballistics_density = cvar("g_ballistics_density_player");
965 self.deadflag = DEAD_NO;
967 self.angles = spot.angles;
969 self.angles_z = 0; // never spawn tilted even if the spot says to
970 self.fixangle = TRUE; // turn this way immediately
971 self.velocity = '0 0 0';
972 self.avelocity = '0 0 0';
973 self.punchangle = '0 0 0';
974 self.punchvector = '0 0 0';
975 self.oldvelocity = self.velocity;
976 self.fire_endtime = -1;
979 WRITESPECTATABLE_MSG_ONE({
980 WriteByte(MSG_ONE, SVC_TEMPENTITY);
981 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
985 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
991 self.view_ofs = PL_VIEW_OFS;
992 setsize (self, PL_MIN, PL_MAX);
993 self.spawnorigin = spot.origin;
994 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
995 // don't reset back to last position, even if new position is stuck in solid
996 self.oldorigin = self.origin;
997 self.prevorigin = self.origin;
998 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
1002 Spawnqueue_Remove(self);
1003 Spawnqueue_Mark(self);
1009 self.event_damage = PlayerDamage;
1011 self.bot_attack = TRUE;
1013 self.statdraintime = time + 5;
1014 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
1016 if(self.killcount == -666) {
1017 PlayerScore_Clear(self);
1021 self.cnt = WEP_LASER;
1023 CL_SpawnWeaponentity();
1024 self.alpha = default_player_alpha;
1025 self.colormod = '1 1 1' * cvar("g_player_brightness");
1026 self.exteriorweaponentity.alpha = default_weapon_alpha;
1028 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1029 self.lms_traveled_distance = 0;
1030 self.speedrunning = FALSE;
1032 race_PostSpawn(spot);
1034 if(cvar("spawn_debug"))
1036 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
1037 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
1040 //stuffcmd(self, "chase_active 0");
1041 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1043 if (cvar("g_spawnsound"))
1044 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
1047 if(self.team == assault_attacker_team)
1048 centerprint(self, "You are attacking!");
1050 centerprint(self, "You are defending!");
1053 target_voicescript_clear(self);
1055 // reset fields the weapons may use
1056 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
1057 weapon_action(j, WR_RESETPLAYER);
1061 activator = oldself;
1066 MUTATOR_CALLHOOK(PlayerSpawn);
1068 self.switchweapon = w_getbestweapon(self);
1069 self.cnt = self.switchweapon;
1071 } else if(self.classname == "observer" || (g_ca && !allowed_to_spawn)) {
1072 PutObserverInServer ();
1076 // ctf_playerchanged();
1079 float ClientInit_SendEntity(entity to, float sf)
1081 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
1082 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
1083 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
1084 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
1085 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
1086 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
1087 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[0]));
1088 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[1]));
1089 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[2]));
1090 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[3]));
1091 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[0]));
1092 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[1]));
1093 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[2]));
1094 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[3]));
1095 if(sv_foginterval && world.fog != "")
1096 WriteString(MSG_ENTITY, world.fog);
1098 WriteString(MSG_ENTITY, "");
1099 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
1100 WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
1101 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_secondary_bouncefactor
1102 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_secondary_bouncestop
1103 WriteByte(MSG_ENTITY, cvar("g_balance_nex_secondary")); // client has to know if it should zoom or not
1104 WriteByte(MSG_ENTITY, cvar("g_balance_campingrifle_secondary")); // client has to know if it should zoom or not
1108 void ClientInit_CheckUpdate()
1110 self.nextthink = time;
1111 if(self.count != cvar("g_balance_armor_blockpercent"))
1113 self.count = cvar("g_balance_armor_blockpercent");
1114 self.SendFlags |= 1;
1116 if(self.cnt != cvar("g_balance_weaponswitchdelay"))
1118 self.cnt = cvar("g_balance_weaponswitchdelay");
1119 self.SendFlags |= 1;
1121 if(self.bouncefactor != cvar("g_balance_grenadelauncher_secondary_bouncefactor"))
1123 self.bouncefactor = cvar("g_balance_grenadelauncher_secondary_bouncefactor");
1124 self.SendFlags |= 1;
1126 if(self.bouncestop != cvar("g_balance_grenadelauncher_secondary_bouncestop"))
1128 self.bouncestop = cvar("g_balance_grenadelauncher_secondary_bouncestop");
1129 self.SendFlags |= 1;
1133 void ClientInit_Spawn()
1138 e.classname = "clientinit";
1139 e.think = ClientInit_CheckUpdate;
1140 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
1144 ClientInit_CheckUpdate();
1153 void SetNewParms (void)
1155 // initialize parms for a new player
1156 parm1 = -(86400 * 366);
1164 void SetChangeParms (void)
1166 // save parms for level change
1167 parm1 = self.parm_idlesince - time;
1175 void DecodeLevelParms (void)
1178 self.parm_idlesince = parm1;
1179 if(self.parm_idlesince == -(86400 * 366))
1180 self.parm_idlesince = time;
1182 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1183 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1190 Called when a client types 'kill' in the console
1194 void ClientKill_Now_TeamChange()
1196 if(self.killindicator_teamchange == -1)
1199 JoinBestTeam( self, FALSE, FALSE );
1202 SV_ChangeTeam(self.killindicator_teamchange - 1);
1205 void ClientKill_Now()
1207 if(self.killindicator_teamchange)
1208 ClientKill_Now_TeamChange();
1211 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1213 if(self.killindicator)
1215 dprint("Cleaned up after a leaked kill indicator.\n");
1216 remove(self.killindicator);
1217 self.killindicator = world;
1220 void KillIndicator_Think()
1222 if (!self.owner.modelindex)
1224 self.owner.killindicator = world;
1232 ClientKill_Now(); // no oldself needed
1238 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1239 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1242 AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));
1243 if(self.owner.killindicator_teamchange)
1245 if(self.owner.killindicator_teamchange == -1)
1246 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1248 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1251 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1253 self.nextthink = time + 1;
1258 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1262 killtime = cvar("g_balance_kill_delay");
1264 if(g_race_qualifying)
1267 self.killindicator_teamchange = targetteam;
1269 if(!self.killindicator)
1271 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1277 self.killindicator = spawn();
1278 self.killindicator.owner = self;
1279 self.killindicator.scale = 0.5;
1280 setattachment(self.killindicator, self, "");
1281 setorigin(self.killindicator, '0 0 52');
1282 self.killindicator.think = KillIndicator_Think;
1283 self.killindicator.nextthink = time + (self.lip) * 0.05;
1284 self.killindicator.cnt = ceil(killtime);
1285 self.killindicator.count = bound(0, ceil(killtime), 10);
1286 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1288 for(e = world; (e = find(e, classname, "body")) != world; )
1292 e.killindicator = spawn();
1293 e.killindicator.owner = e;
1294 e.killindicator.scale = 0.5;
1295 setattachment(e.killindicator, e, "");
1296 setorigin(e.killindicator, '0 0 52');
1297 e.killindicator.think = KillIndicator_Think;
1298 e.killindicator.nextthink = time + (e.lip) * 0.05;
1299 e.killindicator.cnt = ceil(killtime);
1304 if(self.killindicator)
1307 self.killindicator.colormod = TeamColor(targetteam);
1309 self.killindicator.colormod = '0 0 0';
1313 void ClientKill (void)
1315 ClientKill_TeamChange(0);
1318 void DoTeamChange(float destteam)
1324 SetPlayerColors(self, destteam);
1327 if(self.classname == "player")
1330 CheckAllowedTeams(self);
1331 t = FindSmallestTeam(self, TRUE);
1334 case COLOR_TEAM1: c0 = c1; break;
1335 case COLOR_TEAM2: c0 = c2; break;
1336 case COLOR_TEAM3: c0 = c3; break;
1337 case COLOR_TEAM4: c0 = c4; break;
1344 destteam = COLOR_TEAM1;
1348 destteam = COLOR_TEAM2;
1352 destteam = COLOR_TEAM3;
1356 destteam = COLOR_TEAM4;
1362 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1364 ClientKill_TeamChange(destteam);
1367 void FixClientCvars(entity e)
1369 // send prediction settings to the client
1370 stuffcmd(e, "\nin_bindmap 0 0\n");
1372 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1373 if(cvar("g_antilag") == 3) // client side hitscan
1374 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1376 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1378 * we no longer need to stuff this. Remove this comment block if you feel
1379 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1380 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1381 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1382 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1383 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1384 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1385 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1386 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1387 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1388 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1389 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1390 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1391 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1392 stuffcmd(e, "cl_movement_edgefriction 1\n");
1400 Called when a client connects to the server
1403 //void ctf_clientconnect();
1404 string ColoredTeamName(float t);
1405 void DecodeLevelParms (void);
1406 //void dom_player_join_team(entity pl);
1408 .float uid_kicktime;
1411 void ClientConnect (void)
1415 if(self.flags & FL_CLIENT)
1417 print("Warning: ClientConnect, but already connected!\n");
1421 if(Ban_MaybeEnforceBan(self))
1427 sprint(self, strcat("^4SVQC Build information: ", WATERMARK(), "\n"));
1430 self.classname = "player_joining";
1432 self.flags = FL_CLIENT;
1433 self.version_nagtime = time + 10 + random() * 10;
1437 dprint("BUG player count is lower than zero, this cannot happen!\n");
1441 PlayerScore_Attach(self);
1442 ClientData_Attach();
1444 bot_clientconnect();
1450 race_PreSpawnObserver();
1453 // dom_player_join_team(self);
1455 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1457 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1458 self.classname = "observer";
1462 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1464 self.classname = "player";
1465 campaign_bots_may_start = 1;
1469 self.classname = "observer"; // do it anyway
1474 self.classname = "player";
1475 campaign_bots_may_start = 1;
1479 self.playerid = (playerid_last = playerid_last + 1);
1481 if(cvar("sv_eventlog"))
1482 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
1484 LogTeamchange(self.playerid, self.team, 1);
1486 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1488 self.netname_previous = strzone(self.netname);
1490 bprint("^4", self.netname, "^4 connected");
1492 if(self.classname != "observer" && (g_domination || g_ctf))
1493 bprint(" and joined the ", ColoredTeamName(self.team));
1497 self.welcomemessage_time = 0;
1499 stuffcmd(self, strcat(clientstuff, "\n"));
1500 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1501 stuffcmd(self, "cl_particles_reloadeffects\n");
1503 FixClientCvars(self);
1505 // spawnfunc_waypoint sprites
1506 WaypointSprite_InitClient(self);
1508 // Wazat's grappling hook
1509 SetGrappleHookBindings();
1511 // get autoswitch state from player when he toggles it
1512 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1514 // get version info from player
1515 stuffcmd(self, "cmd clientversion $gameversion\n");
1517 // get other cvars from player
1520 // set cvar for team scoreboard
1521 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1523 // notify about available teams
1526 CheckAllowedTeams(self);
1527 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1528 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1531 stuffcmd(self, "set _teams_available 0\n");
1533 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1537 self.classname = "observer";
1539 Spawnqueue_Insert(self);
1543 ctf_clientconnect();
1546 if(teams_matter || radar_showennemies)
1549 bot_relinkplayerlist();
1551 self.spectatortime = time;
1554 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"));
1557 self.jointime = time;
1558 self.allowedTimeouts = cvar("sv_timeout_number");
1560 if(clienttype(self) == CLIENTTYPE_REAL)
1562 if(cvar("g_bugrigs") || g_weaponarena == WEPBIT_TUBA)
1563 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1568 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1570 PlayerScore_Add(self, SP_LMS_RANK, 666);
1571 self.frags = FRAGS_SPECTATOR;
1575 if(!sv_foginterval && world.fog != "")
1576 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1578 SoundEntity_Attach(self);
1580 if(cvar("g_hitplots") || strstrofs(strcat(" ", cvar_string("g_hitplots_individuals"), " "), strcat(" ", self.netaddress, " "), 0) >= 0)
1582 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1583 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1586 self.hitplotfh = -1;
1589 if(clienttype(self) == CLIENTTYPE_REAL)
1591 self.uid_kicktime = time + 60;
1594 if(g_race || g_cts) {
1600 t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
1602 race_send_recordtime(MSG_ONE);
1603 race_send_speedaward(MSG_ONE);
1605 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
1606 speedaward_alltimebest_holder = db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"));
1607 race_send_speedaward_alltimebest(MSG_ONE);
1610 for (i = 1; i <= RANKINGS_CNT; ++i) {
1611 race_SendRankings(i, 0, 0, MSG_ONE);
1614 else if(cvar("sv_teamnagger") && !(cvar("bot_vs_human") && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
1615 send_CSQC_teamnagger();
1617 send_CSQC_nexvelocity(self);
1618 send_CSQC_cr_maxbullets(self);
1627 Called when a client disconnects from the server
1630 .entity chatbubbleentity;
1631 .entity teambubbleentity;
1633 void ClientDisconnect (void)
1635 if not(self.flags & FL_CLIENT)
1637 print("Warning: ClientDisconnect without ClientConnect\n");
1641 CheatShutdownClient();
1643 if(self.hitplotfh >= 0)
1645 fclose(self.hitplotfh);
1646 self.hitplotfh = -1;
1650 anticheat_shutdown();
1652 playerdemo_shutdown();
1654 bot_clientdisconnect();
1659 if(cvar("sv_eventlog"))
1660 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1661 bprint ("^4",self.netname);
1662 bprint ("^4 disconnected\n");
1664 SoundEntity_Detach(self);
1667 MUTATOR_CALLHOOK(ClientDisconnect);
1669 Portal_ClearAll(self);
1671 if(self.flagcarried)
1672 DropFlag(self.flagcarried, world, world);
1673 if(self.ballcarried)
1674 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1676 // Here, everything has been done that requires this player to be a client.
1678 self.flags &~= FL_CLIENT;
1680 if (self.chatbubbleentity)
1681 remove (self.chatbubbleentity);
1683 if (self.teambubbleentity)
1684 remove (self.teambubbleentity);
1686 if (self.killindicator)
1687 remove (self.killindicator);
1689 WaypointSprite_PlayerGone();
1691 bot_relinkplayerlist();
1694 if(self.weaponentity)
1695 if(self.weaponentity.lasertarget)
1696 remove(self.weaponentity.lasertarget);
1700 Spawnqueue_Unmark(self);
1701 Spawnqueue_Remove(self);
1704 ClientData_Detach();
1705 PlayerScore_Detach(self);
1707 if(self.netname_previous)
1708 strunzone(self.netname_previous);
1709 if(self.clientstatus)
1710 strunzone(self.clientstatus);
1712 ClearPlayerSounds();
1715 remove(self.personal);
1725 void ChatBubbleThink()
1727 self.nextthink = time;
1728 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1730 if(self.owner) // but why can that ever be world?
1731 self.owner.chatbubbleentity = world;
1735 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1737 || self.owner.tetris_on
1740 self.model = self.mdl;
1745 void UpdateChatBubble()
1747 if (!self.modelindex)
1749 // spawn a chatbubble entity if needed
1750 if (!self.chatbubbleentity)
1752 self.chatbubbleentity = spawn();
1753 self.chatbubbleentity.owner = self;
1754 self.chatbubbleentity.exteriormodeltoclient = self;
1755 self.chatbubbleentity.think = ChatBubbleThink;
1756 self.chatbubbleentity.nextthink = time;
1757 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1758 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1759 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1760 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1761 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1762 self.chatbubbleentity.model = "";
1763 self.chatbubbleentity.effects = EF_LOWPRECISION;
1768 void TeamBubbleThink()
1770 self.nextthink = time;
1771 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1773 if(self.owner) // but why can that ever be world?
1774 self.owner.teambubbleentity = world;
1778 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1779 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1782 self.model = self.mdl;
1786 float TeamBubble_customizeentityforclient()
1788 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1791 void UpdateTeamBubble()
1793 if (!self.modelindex || !teams_matter)
1795 // spawn a teambubble entity if needed
1796 if (!self.teambubbleentity && teams_matter)
1798 self.teambubbleentity = spawn();
1799 self.teambubbleentity.owner = self;
1800 self.teambubbleentity.exteriormodeltoclient = self;
1801 self.teambubbleentity.think = TeamBubbleThink;
1802 self.teambubbleentity.nextthink = time;
1803 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1804 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1805 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1806 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1807 self.teambubbleentity.mdl = self.teambubbleentity.model;
1808 self.teambubbleentity.model = self.teambubbleentity.mdl;
1809 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1810 self.teambubbleentity.effects = EF_LOWPRECISION;
1814 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1815 // added to the model skins
1816 /*void UpdateColorModHack()
1819 c = self.clientcolors & 15;
1820 // LordHavoc: only bothering to support white, green, red, yellow, blue
1821 if (!teams_matter) self.colormod = '0 0 0';
1822 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1823 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1824 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1825 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1826 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1827 else self.colormod = '1 1 1';
1833 if(self.modelindex != 0 && cvar("g_respawn_ghosts"))
1835 self.solid = SOLID_NOT;
1836 self.takedamage = DAMAGE_NO;
1837 self.movetype = MOVETYPE_FLY;
1838 self.velocity = '0 0 1' * cvar("g_respawn_ghosts_speed");
1839 self.avelocity = randomvec() * cvar("g_respawn_ghosts_speed") * 3 - randomvec() * cvar("g_respawn_ghosts_speed") * 3;
1840 self.effects |= EF_ADDITIVE;
1841 self.oldcolormap = self.colormap;
1842 self.colormap = 512;
1843 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1844 if(cvar("g_respawn_ghosts_maxtime"))
1845 SUB_SetFade (self, time + cvar("g_respawn_ghosts_maxtime") / 2 + random () * (cvar("g_respawn_ghosts_maxtime") - cvar("g_respawn_ghosts_maxtime") / 2), 1.5);
1849 self.effects |= EF_NODRAW; // prevent another CopyBody
1850 if(self.oldcolormap)
1852 self.colormap = self.oldcolormap;
1853 self.oldcolormap = 0;
1855 PutClientInServer();
1858 void play_countdown(float finished, string samp)
1860 if(clienttype(self) == CLIENTTYPE_REAL)
1861 if(floor(finished - time - frametime) != floor(finished - time))
1862 if(finished - time < 6)
1863 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1867 * When sv_timeout is used this function returs strings like
1868 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1869 * Called by centerprint functions
1870 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1872 string getTimeoutText(float addOneSecond) {
1873 if (!cvar("sv_timeout") || !timeoutStatus)
1876 local string retStr;
1877 if (timeoutStatus == 1) {
1878 if (addOneSecond == 1) {
1879 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1882 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1886 else if (timeoutStatus == 2) {
1888 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1889 //don't show messages like "Timeout ends in 0 seconds"...
1890 if ((remainingTimeoutTime + 1) > 0)
1896 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1897 //don't show messages like "Timeout ends in 0 seconds"...
1898 if (remainingTimeoutTime > 0)
1907 void player_powerups (void)
1909 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1911 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));
1912 self.modelflags |= MF_ROCKET;
1916 SoundEntity_StopSound(self, CHAN_PLAYER);
1917 self.modelflags &~= MF_ROCKET;
1920 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1922 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1925 Fire_ApplyDamage(self);
1926 Fire_ApplyEffect(self);
1930 self.effects |= EF_FULLBRIGHT;
1932 if (self.items & IT_STRENGTH)
1934 play_countdown(self.strength_finished, "misc/poweroff.wav");
1935 if (time > self.strength_finished)
1937 self.alpha = default_player_alpha;
1938 self.exteriorweaponentity.alpha = default_weapon_alpha;
1939 self.items &~= IT_STRENGTH;
1940 sprint(self, "^3Invisibility has worn off\n");
1945 if (time < self.strength_finished)
1947 self.alpha = g_minstagib_invis_alpha;
1948 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1949 self.items |= IT_STRENGTH;
1950 sprint(self, "^3You are invisible\n");
1954 if (self.items & IT_INVINCIBLE)
1956 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1957 if (time > self.invincible_finished && cvar("g_balance_powerup_timer"))
1959 self.items = self.items - (self.items & IT_INVINCIBLE);
1960 sprint(self, "^3Speed has worn off\n");
1965 if (time < self.invincible_finished)
1967 self.items = self.items | IT_INVINCIBLE;
1968 sprint(self, "^3You are on speed\n");
1974 if (self.items & IT_STRENGTH)
1976 play_countdown(self.strength_finished, "misc/poweroff.wav");
1977 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1978 if (time > self.strength_finished && cvar("g_balance_powerup_timer"))
1980 self.items = self.items - (self.items & IT_STRENGTH);
1981 sprint(self, "^3Strength has worn off\n");
1986 if (time < self.strength_finished)
1988 self.items = self.items | IT_STRENGTH;
1989 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1992 if (self.items & IT_INVINCIBLE)
1994 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1995 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1996 if (time > self.invincible_finished && cvar("g_balance_powerup_timer"))
1998 self.items = self.items - (self.items & IT_INVINCIBLE);
1999 sprint(self, "^3Shield has worn off\n");
2004 if (time < self.invincible_finished)
2006 self.items = self.items | IT_INVINCIBLE;
2007 sprint(self, "^3Shield surrounds you\n");
2011 if(cvar("g_nodepthtestplayers"))
2012 self.effects = self.effects | EF_NODEPTHTEST;
2014 if(cvar("g_fullbrightplayers"))
2015 self.effects = self.effects | EF_FULLBRIGHT;
2017 // midair gamemode: damage only while in the air
2018 // if in midair mode, being on ground grants temporary invulnerability
2019 // (this is so that multishot weapon don't clear the ground flag on the
2020 // first damage in the frame, leaving the player vulnerable to the
2021 // remaining hits in the same frame)
2022 if (self.flags & FL_ONGROUND)
2024 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
2026 if (time >= game_starttime)
2027 if (time < self.spawnshieldtime)
2028 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
2031 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
2033 if(current > stable)
2035 else if(current > stable - 0.25) // when close enough, "snap"
2038 return min(stable, current + (stable - current) * regenfactor * regenframetime);
2041 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
2043 if(current < stable)
2045 else if(current < stable + 0.25) // when close enough, "snap"
2048 return max(stable, current + (stable - current) * rotfactor * rotframetime);
2051 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
2053 if(current > rotstable)
2055 if(rotframetime > 0)
2057 current = CalcRot(current, rotstable, rotfactor, rotframetime);
2058 current = max(rotstable, current - rotlinear * rotframetime);
2061 else if(current < regenstable)
2063 if(regenframetime > 0)
2065 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
2066 current = min(regenstable, current + regenlinear * regenframetime);
2076 void player_regen (void)
2078 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
2079 maxh = cvar("g_balance_health_rotstable");
2080 maxa = cvar("g_balance_armor_rotstable");
2081 maxf = cvar("g_balance_fuel_rotstable");
2082 minh = cvar("g_balance_health_regenstable");
2083 mina = cvar("g_balance_armor_regenstable");
2084 minf = cvar("g_balance_fuel_regenstable");
2085 limith = cvar("g_balance_health_limit");
2086 limita = cvar("g_balance_armor_limit");
2087 limitf = cvar("g_balance_fuel_limit");
2089 max_mod = regen_mod = rot_mod = limit_mod = 1;
2091 if (self.runes & RUNE_REGEN)
2093 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
2095 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
2096 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
2097 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
2101 regen_mod = cvar("g_balance_rune_regen_regenrate");
2102 max_mod = cvar("g_balance_rune_regen_hpmod");
2103 limit_mod = cvar("g_balance_rune_regen_limitmod");
2106 else if (self.runes & CURSE_VENOM)
2108 max_mod = cvar("g_balance_curse_venom_hpmod");
2109 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
2110 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
2112 rot_mod = cvar("g_balance_curse_venom_rotrate");
2113 limit_mod = cvar("g_balance_curse_venom_limitmod");
2114 //if (!self.runes & RUNE_REGEN)
2115 // rot_mod = cvar("g_balance_curse_venom_rotrate");
2117 maxh = maxh * max_mod;
2118 //maxa = maxa * max_mod;
2119 //maxf = maxf * max_mod;
2120 minh = minh * max_mod;
2121 //mina = mina * max_mod;
2122 //minf = minf * max_mod;
2123 limith = limith * limit_mod;
2124 limita = limita * limit_mod;
2125 //limitf = limitf * limit_mod;
2130 if (!g_minstagib && !g_ca && (!g_lms || cvar("g_lms_regenerate")))
2132 self.armorvalue = CalcRotRegen(self.armorvalue, mina, cvar("g_balance_armor_regen"), cvar("g_balance_armor_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxa, cvar("g_balance_armor_rot"), cvar("g_balance_armor_rotlinear"), rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
2133 self.health = CalcRotRegen(self.health, minh, cvar("g_balance_health_regen"), cvar("g_balance_health_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxh, cvar("g_balance_health_rot"), cvar("g_balance_health_rotlinear"), rot_mod * frametime * (time > self.pauserothealth_finished), limith);
2135 // if player rotted to death... die!
2137 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2140 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
2141 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, cvar("g_balance_fuel_regen"), cvar("g_balance_fuel_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished) * (self.items & IT_FUEL_REGEN != 0), maxf, cvar("g_balance_fuel_rot"), cvar("g_balance_fuel_rotlinear"), rot_mod * frametime * (time > self.pauserotfuel_finished), limitf);
2144 float zoomstate_set;
2145 void SetZoomState(float z)
2147 if(z != self.zoomstate)
2150 ClientData_Touch(self);
2155 void GetPressedKeys(void) {
2156 MUTATOR_CALLHOOK(GetPressedKeys);
2157 if (self.movement_x > 0) // get if movement keys are pressed
2158 { // forward key pressed
2159 self.pressedkeys |= KEY_FORWARD;
2160 self.pressedkeys &~= KEY_BACKWARD;
2162 else if (self.movement_x < 0)
2163 { // backward key pressed
2164 self.pressedkeys |= KEY_BACKWARD;
2165 self.pressedkeys &~= KEY_FORWARD;
2169 self.pressedkeys &~= KEY_FORWARD;
2170 self.pressedkeys &~= KEY_BACKWARD;
2173 if (self.movement_y > 0)
2174 { // right key pressed
2175 self.pressedkeys |= KEY_RIGHT;
2176 self.pressedkeys &~= KEY_LEFT;
2178 else if (self.movement_y < 0)
2179 { // left key pressed
2180 self.pressedkeys |= KEY_LEFT;
2181 self.pressedkeys &~= KEY_RIGHT;
2185 self.pressedkeys &~= KEY_RIGHT;
2186 self.pressedkeys &~= KEY_LEFT;
2189 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
2190 self.pressedkeys |= KEY_JUMP;
2192 self.pressedkeys &~= KEY_JUMP;
2193 if (self.BUTTON_CROUCH)
2194 self.pressedkeys |= KEY_CROUCH;
2196 self.pressedkeys &~= KEY_CROUCH;
2199 void update_stats (float number, float hit, float fired) {
2200 // self.stat_hit = number + ((number==0) ? 1 : 64) * hit * sv_accuracy_data_share;
2201 // self.stat_fired = number + ((number==0) ? 1 : 64) * fired * sv_accuracy_data_share;
2204 self.stat_hit = number + 64 * hit * sv_accuracy_data_share;
2205 self.stat_fired = number + 64 * fired * sv_accuracy_data_share;
2207 self.stat_hit = hit * sv_accuracy_data_share;
2208 self.stat_fired = fired * sv_accuracy_data_share;
2213 ======================
2214 spectate mode routines
2215 ======================
2218 .float weapon_count;
2219 void SpectateCopy(entity spectatee) {
2220 if(spectatee.weapon_count < WEP_LAST) {
2221 update_stats (spectatee.weapon_count, spectatee.cvar_cl_accuracy_data_share * floor(spectatee.stats_hit[spectatee.weapon_count - 1]), spectatee.cvar_cl_accuracy_data_share * floor(spectatee.stats_fired[spectatee.weapon_count - 1]));
2222 spectatee.weapon_count ++;
2224 update_stats (0, spectatee.cvar_cl_accuracy_data_share * spectatee.stat_hit, spectatee.cvar_cl_accuracy_data_share * spectatee.stat_fired);
2227 MUTATOR_CALLHOOK(SpectateCopy);
2228 self.armortype = spectatee.armortype;
2229 self.armorvalue = spectatee.armorvalue;
2230 self.ammo_cells = spectatee.ammo_cells;
2231 self.ammo_shells = spectatee.ammo_shells;
2232 self.ammo_nails = spectatee.ammo_nails;
2233 self.ammo_rockets = spectatee.ammo_rockets;
2234 self.ammo_fuel = spectatee.ammo_fuel;
2235 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
2236 self.health = spectatee.health;
2238 self.items = spectatee.items;
2239 self.metertime = spectatee.metertime;
2240 self.strength_finished = spectatee.strength_finished;
2241 self.invincible_finished = spectatee.invincible_finished;
2242 self.pressedkeys = spectatee.pressedkeys;
2243 self.weapons = spectatee.weapons;
2244 self.switchweapon = spectatee.switchweapon;
2245 self.weapon = spectatee.weapon;
2246 self.punchangle = spectatee.punchangle;
2247 self.view_ofs = spectatee.view_ofs;
2248 self.v_angle = spectatee.v_angle;
2249 self.velocity = spectatee.velocity;
2250 self.dmg_take = spectatee.dmg_take;
2251 self.dmg_save = spectatee.dmg_save;
2252 self.dmg_inflictor = spectatee.dmg_inflictor;
2253 self.angles = spectatee.v_angle;
2254 self.fixangle = TRUE;
2255 setorigin(self, spectatee.origin);
2256 setsize(self, spectatee.mins, spectatee.maxs);
2257 SetZoomState(spectatee.zoomstate);
2259 anticheat_spectatecopy(spectatee);
2262 float SpectateUpdate() {
2266 if (self == self.enemy)
2269 if(self.enemy.classname != "player")
2272 SpectateCopy(self.enemy);
2277 float SpectateNext() {
2278 other = find(self.enemy, classname, "player");
2281 other = find(other, classname, "player");
2286 if(self.enemy.classname == "player") {
2288 WriteByte(MSG_ONE, SVC_SETVIEW);
2289 WriteEntity(MSG_ONE, self.enemy);
2290 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2291 self.movetype = MOVETYPE_NONE;
2293 self.enemy.weapon_count = 0;
2295 if(!SpectateUpdate())
2296 PutObserverInServer();
2306 ShowRespawnCountdown()
2308 Update a respawn countdown display.
2311 void ShowRespawnCountdown()
2314 if(self.deadflag == DEAD_NO) // just respawned?
2318 number = ceil(self.death_time - time);
2321 if(number <= self.respawn_countdown)
2323 self.respawn_countdown = number - 1;
2324 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
2325 AnnounceTo(self, strcat(ftos(number), ""));
2330 void LeaveSpectatorMode()
2332 if(isJoinAllowed()) {
2333 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2334 self.classname = "player";
2336 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2337 JoinBestTeam(self, FALSE, TRUE);
2339 if(cvar("g_campaign"))
2340 campaign_bots_may_start = 1;
2342 self.stat_count = WEP_LAST;
2344 PutClientInServer();
2346 if(self.classname == "player")
2347 bprint ("^4", self.netname, "^4 is playing now\n");
2349 if(!cvar("g_campaign"))
2350 centerprint(self,""); // clear MOTD
2354 if (g_ca && self.caplayer) {
2357 stuffcmd(self,"menu_showteamselect\n");
2362 //player may not join because of g_maxplayers is set
2363 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2368 * Determines whether the player is allowed to join. This depends on cvar
2369 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2370 * it checks whether the number of currently playing players exceeds g_maxplayers.
2371 * @return bool TRUE if the player is allowed to join, false otherwise
2373 float isJoinAllowed() {
2374 if (!cvar("g_maxplayers"))
2378 local float currentlyPlaying;
2379 FOR_EACH_REALPLAYER(e) {
2380 if(e.classname == "player")
2381 currentlyPlaying += 1;
2383 if(currentlyPlaying < cvar("g_maxplayers"))
2390 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2391 * g_maxplayers_spectator_blocktime seconds
2393 void checkSpectatorBlock() {
2394 if(self.classname == "spectator" || self.classname == "observer") {
2395 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2396 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2402 float vercmp_recursive(string v1, string v2)
2408 dot1 = strstrofs(v1, ".", 0);
2409 dot2 = strstrofs(v2, ".", 0);
2413 s1 = substring(v1, 0, dot1);
2417 s2 = substring(v2, 0, dot2);
2419 r = stof(s1) - stof(s2);
2423 r = strcasecmp(s1, s2);
2436 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2439 float vercmp(string v1, string v2)
2441 if(strcasecmp(v1, v2) == 0) // early out check
2443 return vercmp_recursive(v1, v2);
2446 void ObserverThink()
2448 if (self.flags & FL_JUMPRELEASED) {
2449 if (self.BUTTON_JUMP && !self.version_mismatch) {
2450 self.welcomemessage_time = 0;
2451 self.flags &~= FL_JUMPRELEASED;
2452 self.flags |= FL_SPAWNING;
2453 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2454 self.welcomemessage_time = 0;
2455 self.flags &~= FL_JUMPRELEASED;
2456 if(SpectateNext() == 1) {
2457 self.classname = "spectator";
2461 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2462 self.flags |= FL_JUMPRELEASED;
2463 if(self.flags & FL_SPAWNING)
2465 self.flags &~= FL_SPAWNING;
2466 LeaveSpectatorMode();
2471 PrintWelcomeMessage(self);
2474 void SpectatorThink()
2476 if (self.flags & FL_JUMPRELEASED) {
2477 if (self.BUTTON_JUMP && !self.version_mismatch) {
2478 self.welcomemessage_time = 0;
2479 self.flags &~= FL_JUMPRELEASED;
2480 self.flags |= FL_SPAWNING;
2481 } else if(self.BUTTON_ATCK) {
2482 self.welcomemessage_time = 0;
2483 self.flags &~= FL_JUMPRELEASED;
2484 if(SpectateNext() == 1) {
2485 self.classname = "spectator";
2487 self.classname = "observer";
2488 self.stat_count = WEP_LAST;
2489 PutClientInServer();
2491 } else if (self.BUTTON_ATCK2) {
2492 self.welcomemessage_time = 0;
2493 self.flags &~= FL_JUMPRELEASED;
2494 self.classname = "observer";
2495 self.stat_count = WEP_LAST;
2496 PutClientInServer();
2498 if(!SpectateUpdate())
2499 PutObserverInServer();
2502 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2503 self.flags |= FL_JUMPRELEASED;
2504 if(self.flags & FL_SPAWNING)
2506 self.flags &~= FL_SPAWNING;
2507 LeaveSpectatorMode();
2513 PrintWelcomeMessage(self);
2514 self.flags |= FL_CLIENT | FL_NOTARGET;
2517 .float touchexplode_time;
2523 Called every frame for each client before the physics are run
2526 void() ctf_setstatus;
2527 void() nexball_setstatus;
2529 void PlayerPreThink (void)
2531 self.stat_game_starttime = game_starttime;
2532 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2533 self.stat_leadlimit = cvar("leadlimit");
2537 // physics frames: update anticheat stuff
2538 anticheat_prethink();
2541 if(blockSpectators && frametime)
2542 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2543 checkSpectatorBlock();
2547 if(self.netname_previous != self.netname)
2549 if(cvar("sv_eventlog"))
2550 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2551 if(self.netname_previous)
2552 strunzone(self.netname_previous);
2553 self.netname_previous = strzone(self.netname);
2557 if(self.version_nagtime)
2558 if(self.cvar_g_xonoticversion)
2559 if(time > self.version_nagtime)
2561 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0)
2563 if(strstr(cvar_string("g_xonoticversion"), "git", 0) >= 0)
2565 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", cvar_string("g_xonoticversion"), " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2566 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", cvar_string("g_xonoticversion"), " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2571 r = vercmp(self.cvar_g_xonoticversion, cvar_string("g_xonoticversion"));
2574 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Xonotic ", cvar_string("g_xonoticversion"), "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.com/^1!\n");
2575 sprint(self, strcat("\{1}^1NOTE: ^3Xonotic ", cvar_string("g_xonoticversion"), "^7 is out, and you still have ^3Xonotic ", self.cvar_g_xonoticversion, "^1 - get the update from ^4http://www.xonotic.com/^1!\n"));
2579 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Xonotic ", cvar_string("g_xonoticversion"), "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n");
2580 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", cvar_string("g_xonoticversion"), "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2584 self.version_nagtime = 0;
2588 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2590 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2591 self.max_armorvalue = 0;
2595 if (TetrisPreFrame())
2599 MUTATOR_CALLHOOK(PlayerPreThink);
2601 if(self.classname == "player") {
2602 // if(self.netname == "Wazat")
2603 // bprint(self.classname, "\n");
2605 CheckRules_Player();
2607 PrintWelcomeMessage(self);
2609 if (intermission_running)
2611 IntermissionThink (); // otherwise a button could be missed between
2612 return; // the think tics
2615 if(self.teleport_time)
2616 if(time > self.teleport_time)
2618 self.teleport_time = 0;
2619 self.effects = self.effects - (self.effects & EF_NODRAW);
2622 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2623 UpdateSelectedPlayer();
2625 //don't allow the player to turn around while game is paused!
2626 if(timeoutStatus == 2) {
2627 self.v_angle = self.lastV_angle;
2628 self.angles = self.lastV_angle;
2629 self.fixangle = TRUE;
2634 if(self.health <= 0 && cvar("g_deathglow"))
2636 if(self.glowmod_x > 0)
2637 self.glowmod_x -= cvar("g_deathglow") * frametime;
2639 self.glowmod_x = -1;
2640 if(self.glowmod_y > 0)
2641 self.glowmod_y -= cvar("g_deathglow") * frametime;
2643 self.glowmod_y = -1;
2644 if(self.glowmod_z > 0)
2645 self.glowmod_z -= cvar("g_deathglow") * frametime;
2647 self.glowmod_z = -1;
2650 self.glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2654 if (self.deadflag != DEAD_NO)
2656 float button_pressed, force_respawn;
2657 if(self.personal && g_race_qualifying)
2659 if(time > self.death_time)
2661 self.death_time = time + 1; // only retry once a second
2670 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2671 force_respawn = (g_lms || (g_ca) || cvar("g_forced_respawn"));
2672 if (self.deadflag == DEAD_DYING)
2675 self.deadflag = DEAD_RESPAWNING;
2676 else if(!button_pressed)
2677 self.deadflag = DEAD_DEAD;
2679 else if (self.deadflag == DEAD_DEAD)
2682 self.deadflag = DEAD_RESPAWNABLE;
2684 else if (self.deadflag == DEAD_RESPAWNABLE)
2687 self.deadflag = DEAD_RESPAWNING;
2689 else if (self.deadflag == DEAD_RESPAWNING)
2691 if(time > self.death_time)
2693 self.death_time = time + 1; // only retry once a second
2697 ShowRespawnCountdown();
2703 if(time > self.touchexplode_time)
2704 if(self.classname == "player")
2705 if(self.deadflag == DEAD_NO)
2706 if not(IS_INDEPENDENT_PLAYER(self))
2707 FOR_EACH_PLAYER(other) if(self != other)
2709 if(time > other.touchexplode_time)
2710 if(other.deadflag == DEAD_NO)
2711 if not(IS_INDEPENDENT_PLAYER(other))
2712 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2714 PlayerTouchExplode(self, other);
2715 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2719 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2723 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2724 dist = self.prevorigin - self.origin;
2726 self.lms_traveled_distance += fabs(vlen(dist));
2728 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2730 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2731 self.lms_traveled_distance = 0;
2734 if(time > self.lms_nextcheck)
2736 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2737 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2739 centerprint(self, cvar_string("g_lms_campcheck_message"));
2740 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2741 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2742 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');
2744 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2745 self.lms_traveled_distance = 0;
2749 self.prevorigin = self.origin;
2751 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2756 self.view_ofs = PL_CROUCH_VIEW_OFS;
2757 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2758 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2765 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2766 if (!trace_startsolid)
2768 self.crouch = FALSE;
2769 self.view_ofs = PL_VIEW_OFS;
2770 setsize (self, PL_MIN, PL_MAX);
2775 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2777 if(self.bloodloss_timer < time)
2779 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2780 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2786 GrapplingHookFrame();
2788 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2791 self.items &~= self.items_added;
2795 self.items_added = 0;
2796 if(self.items & IT_JETPACK)
2797 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2798 self.items_added |= IT_FUEL;
2800 self.items |= self.items_added;
2808 minstagib_ammocheck();
2811 nexball_setstatus();
2813 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2815 //self.angles_y=self.v_angle_y + 90; // temp
2816 } else if(gameover) {
2817 if (intermission_running)
2818 IntermissionThink (); // otherwise a button could be missed between
2820 } else if(self.classname == "observer") {
2822 } else if(self.classname == "spectator") {
2827 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_CAMPINGRIFLE && cvar("g_balance_campingrifle_secondary") == 0));
2829 float oldspectatee_status;
2830 oldspectatee_status = self.spectatee_status;
2831 if(self.classname == "spectator")
2832 self.spectatee_status = num_for_edict(self.enemy);
2833 else if(self.classname == "observer")
2834 self.spectatee_status = num_for_edict(self);
2836 self.spectatee_status = 0;
2837 if(self.spectatee_status != oldspectatee_status)
2839 ClientData_Touch(self);
2841 race_InitSpectator();
2844 if(self.teamkill_soundtime)
2845 if(time > self.teamkill_soundtime)
2847 self.teamkill_soundtime = 0;
2849 entity oldpusher, oldself;
2851 oldself = self; self = self.teamkill_soundsource;
2852 oldpusher = self.pusher; self.pusher = oldself;
2854 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2856 self.pusher = oldpusher;
2860 if(self.taunt_soundtime)
2861 if(time > self.taunt_soundtime)
2863 self.taunt_soundtime = 0;
2864 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2867 target_voicescript_next(self);
2870 float isInvisibleString(string s)
2873 s = strdecolorize(s);
2874 for((i = 0), (n = strlen(s)); i < n; ++i)
2882 case 192: // charmap space
2883 if (!cvar("utf8_enable"))
2886 case 160: // space in unicode fonts
2887 case 0xE000 + 192: // utf8 charmap space
2888 if (cvar("utf8_enable"))
2901 Called every frame for each client after the physics are run
2904 .float idlekick_lasttimeleft;
2905 .entity showheadshotbbox;
2906 void showheadshotbbox_think()
2908 if(self.owner.showheadshotbbox != self)
2913 self.nextthink = time;
2914 setorigin(self, self.owner.origin);
2915 setsize(self, GetHeadshotMins(self.owner), GetHeadshotMaxs(self.owner));
2917 void PlayerPostThink (void)
2919 // Savage: Check for nameless players
2920 if (isInvisibleString(self.netname)) {
2921 self.netname = "Player";
2922 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));
2925 // send the clients accuracy stats to the client
2926 if(self.stat_count > 0)
2929 self.stat_hit = self.stat_count + 64 * floor(self.(stats_hit[self.stat_count - 1]));
2930 self.stat_fired = self.stat_count + 64 * floor(self.(stats_fired[self.stat_count - 1]));
2931 self.stat_count -= 1;
2935 if(self.uid_kicktime)
2936 if(time > self.uid_kicktime)
2938 bprint("^3", self.netname, "^3 was kicked for missing UID.\n");
2944 if(sv_maxidle && frametime)
2946 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2948 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2951 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2952 AnnounceTo(self, "terminated");
2956 else if(timeleft <= 10)
2958 if(timeleft != self.idlekick_lasttimeleft)
2960 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2961 AnnounceTo(self, strcat(ftos(timeleft), ""));
2966 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2968 self.idlekick_lasttimeleft = timeleft;
2972 if(self.impulse == 100)
2974 if (TetrisPostFrame())
2980 if(self.classname == "player") {
2981 CheckRules_Player();
2986 if (intermission_running)
2987 return; // intermission or finale
2989 } else if (self.classname == "observer") {
2991 } else if (self.classname == "spectator") {
2997 for(i = 0; i < 1000; ++i)
3000 end = self.origin + '0 0 1024' + 512 * randomvec();
3001 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
3002 if(trace_fraction < 1)
3003 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
3005 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
3013 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
3015 if(self.waypointsprite_attachedforcarrier)
3016 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, cvar("g_balance_armor_blockpercent")));
3018 if(self.classname == "player" && self.deadflag == DEAD_NO && cvar("r_showbboxes"))
3020 if(!self.showheadshotbbox)
3022 self.showheadshotbbox = spawn();
3023 self.showheadshotbbox.classname = "headshotbbox";
3024 self.showheadshotbbox.owner = self;
3025 self.showheadshotbbox.think = showheadshotbbox_think;
3026 self.showheadshotbbox.nextthink = time;
3027 self = self.showheadshotbbox;
3034 if(self.showheadshotbbox)
3035 remove(self.showheadshotbbox);
3042 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));