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, entity playerlist, float teamcheck, float anypoint)
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 // filter out spots for assault
155 if(spot.target != "") {
161 for(ent = world; (ent = find(ent, targetname, spot.target)); )
164 if(ent.classname == "target_objective")
166 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
169 else if(ent.classname == "trigger_race_checkpoint")
171 if(!anypoint) // spectators may spawn everywhere
173 if(g_race_qualifying)
176 if(ent.race_checkpoint != 0)
178 if(spot.race_place != race_lowest_place_spawn)
183 if(ent.race_checkpoint != self.race_respawn_checkpoint)
185 // try reusing the previous spawn
186 if(ent == self.race_respawn_spotref || spot == self.race_respawn_spotref)
188 if(ent.race_checkpoint == 0)
191 pl = self.race_place;
192 if(pl > race_highest_place_spawn)
194 if(pl == 0 && !self.race_started)
195 pl = race_highest_place_spawn; // use last place if he has not even touched finish yet
196 if(spot.race_place != pl)
207 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
211 if(good < found) // at least one was bad
216 shortest = vlen(world.maxs - world.mins);
217 for(player = playerlist; player; player = player.chain)
220 thisdist = vlen(player.origin - spot.origin);
221 if (thisdist < shortest)
224 return prio * '1 0 0' + shortest * '0 1 0';
229 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck, float anypoint)
231 entity spot, spotlist, spotlistend;
232 spawn_allgood = TRUE;
238 for(spot = firstspot; spot; spot = spot.chain)
240 spot.spawnpoint_score = Spawn_Score(spot, playerlist, teamcheck, anypoint);
242 if(autocvar_spawn_debugview)
244 setmodel(spot, "models/runematch/rune.mdl");
245 if(spot.spawnpoint_score_y < mindist)
247 spot.colormod = '1 0 0';
252 spot.colormod = '0 1 0';
253 spot.scale = spot.spawnpoint_score_y / mindist;
257 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
259 if(spot.spawnpoint_score_y < mindist)
261 // too short distance
262 spawn_allgood = FALSE;
267 spawn_allbad = FALSE;
270 spotlistend.chain = spot;
277 if(spot.team != teamcheck)
278 error("invalid spawn added");
280 print("added ", etos(spot), "\n");
286 spotlistend.chain = world;
291 for(e = spotlist; e; e = e.chain)
293 print("seen ", etos(e), "\n");
294 if(e.team != teamcheck)
295 error("invalid spawn found");
302 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
304 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
305 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
308 RandomSelection_Init();
309 for(spot = firstspot; spot; spot = spot.chain)
310 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);
312 return RandomSelection_chosen_ent;
319 Finds a point to respawn
322 entity SelectSpawnPoint (float anypoint)
325 entity firstspot_new;
326 entity spot, firstspot, playerlist;
328 spot = find (world, classname, "testplayerstart");
334 else if(have_team_spawns > 0)
336 if(have_team_spawns_forteam[self.team] == 0)
338 // we request a spawn for a team, and we have team
339 // spawns, but that team has no spawns?
340 if(have_team_spawns_forteam[0])
344 // if not, any spawn has to do
348 teamcheck = self.team; // MUST be team
350 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
351 teamcheck = 0; // MUST be noteam
354 // 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
357 // get the list of players
358 playerlist = findchain(classname, "player");
359 // get the entire list of spots
360 firstspot = findchain(classname, "info_player_deathmatch");
361 // filter out the bad ones
362 // (note this returns the original list if none survived)
365 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
369 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck, anypoint);
371 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck, anypoint);
372 firstspot = firstspot_new;
374 // there is 50/50 chance of choosing a random spot or the furthest spot
375 // (this means that roughly every other spawn will be furthest, so you
376 // usually won't get fragged at spawn twice in a row)
377 if (arena_roundbased && !g_ca)
379 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck, anypoint);
381 firstspot = firstspot_new;
382 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
384 else if (random() > autocvar_g_spawn_furthest)
385 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
387 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
390 if(autocvar_spawn_debugview)
392 print("spot mindistance: ", vtos(spot.spawnpoint_score), "\n");
396 for(e = firstspot; e; e = e.chain)
397 if(e.team != teamcheck)
398 error("invalid spawn found");
403 if(autocvar_spawn_debug)
407 if(some_spawn_has_been_used)
408 return world; // team can't spawn any more, because of actions of other team
410 error("Cannot find a spawn point - please fix the map!");
421 Checks if the argument string can be a valid playermodel.
422 Returns a valid one in doubt.
425 string FallbackPlayerModel;
426 string CheckPlayerModel(string plyermodel) {
427 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
429 // note: we cannot summon Don Strunzone here, some player may
430 // still have the model string set. In case anyone manages how
431 // to change a cvar default, we'll have a small leak here.
432 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
434 if(strlen(plyermodel) < 4)
435 return FallbackPlayerModel;
436 if( substring(plyermodel,0,14) != "models/player/")
437 return FallbackPlayerModel;
438 else if(autocvar_sv_servermodelsonly)
440 if(substring(plyermodel,-4,4) != ".zym")
441 if(substring(plyermodel,-4,4) != ".dpm")
442 if(substring(plyermodel,-4,4) != ".iqm")
443 if(substring(plyermodel,-4,4) != ".md3")
444 if(substring(plyermodel,-4,4) != ".psk")
445 return FallbackPlayerModel;
446 // forbid the LOD models
447 if(substring(plyermodel, -9,5) == "_lod1")
448 return FallbackPlayerModel;
449 if(substring(plyermodel, -9,5) == "_lod2")
450 return FallbackPlayerModel;
451 if(plyermodel != strtolower(plyermodel))
452 return FallbackPlayerModel;
453 if(!fexists(plyermodel))
454 return FallbackPlayerModel;
459 void setplayermodel(entity e, string modelname)
461 precache_model(modelname);
462 setmodel(e, modelname);
463 player_setupanimsformodel();
464 UpdatePlayerSounds();
471 putting a client as observer in the server
474 void FixPlayermodel();
475 void PutObserverInServer (void)
478 self.hud = HUD_NORMAL;
479 race_PreSpawnObserver();
481 spot = SelectSpawnPoint (TRUE);
483 error("No spawnpoints for observers?!?\n");
484 RemoveGrapplingHook(self); // Wazat's Grappling Hook
486 if(clienttype(self) == CLIENTTYPE_REAL)
489 WriteByte(MSG_ONE, SVC_SETVIEW);
490 WriteEntity(MSG_ONE, self);
494 MUTATOR_CALLHOOK(MakePlayerObserver);
497 minstagib_stop_countdown();
499 Portal_ClearAll(self);
503 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
508 vehicles_exit(VHEF_RELESE);
511 DropFlag(self.flagcarried, world, world);
513 if(self.ballcarried && g_nexball)
514 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
516 WaypointSprite_PlayerDead();
518 if not(g_ca) // don't reset teams when moving a ca player to the spectators
519 self.team = -1; // move this as it is needed to log the player spectating in eventlog
521 if(self.killcount != -666) {
523 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
524 bprint ("^4", self.netname, "^4 has no more lives left\n");
526 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
528 bprint ("^4", self.netname, "^4 is spectating now\n");
530 if(self.just_joined == FALSE) {
531 LogTeamchange(self.playerid, -1, 4);
533 self.just_joined = FALSE;
536 PlayerScore_Clear(self); // clear scores when needed
538 accuracy_resend(self);
540 self.spectatortime = time;
542 self.classname = "observer";
543 self.iscreature = FALSE;
544 self.damagedbycontents = FALSE;
546 self.takedamage = DAMAGE_NO;
547 self.solid = SOLID_NOT;
548 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
549 self.flags = FL_CLIENT | FL_NOTARGET;
550 self.armorvalue = 666;
552 self.armorvalue = autocvar_g_balance_armor_start;
553 self.pauserotarmor_finished = 0;
554 self.pauserothealth_finished = 0;
555 self.pauseregen_finished = 0;
556 self.damageforcescale = 0;
563 self.pain_finished = 0;
564 self.strength_finished = 0;
565 self.invincible_finished = 0;
567 self.think = SUB_Null;
571 self.deadflag = DEAD_NO;
572 self.angles = spot.angles;
574 self.fixangle = TRUE;
577 setorigin (self, spot.origin);
578 self.prevorigin = self.origin;
583 setmodel(self, "null");
584 self.drawonlytoclient = self;
586 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
587 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
590 self.weaponname = "";
591 self.switchingweapon = 0;
592 self.weaponmodel = "";
593 self.weaponentity = world;
594 self.exteriorweaponentity = world;
595 self.killcount = -666;
596 self.velocity = '0 0 0';
597 self.avelocity = '0 0 0';
598 self.punchangle = '0 0 0';
599 self.punchvector = '0 0 0';
600 self.oldvelocity = self.velocity;
601 self.fire_endtime = -1;
605 if(self.version_mismatch)
607 Spawnqueue_Unmark(self);
608 Spawnqueue_Remove(self);
612 Spawnqueue_Insert(self);
617 // Only if the player cannot play at all
618 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
619 self.frags = FRAGS_SPECTATOR;
621 self.frags = FRAGS_LMS_LOSER;
626 self.frags = FRAGS_LMS_LOSER;
628 self.frags = FRAGS_SPECTATOR;
631 self.frags = FRAGS_SPECTATOR;
634 void FixPlayermodel()
637 float defaultskin, chmdl, oldskin;
642 if(autocvar_sv_defaultcharacter == 1) {
648 s = Team_ColorNameLowerCase(self.team);
651 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
652 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
656 if(defaultmodel == "")
658 defaultmodel = autocvar_sv_defaultplayermodel;
659 defaultskin = autocvar_sv_defaultplayerskin;
663 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
666 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
667 self.model = ""; // force the != checks to return true
670 if(defaultmodel != "")
672 if (defaultmodel != self.model)
676 setplayermodel (self, defaultmodel);
677 setsize (self, m1, m2);
682 self.skin = defaultskin;
684 if (self.playermodel != self.model || self.playermodel == "")
686 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
689 setplayermodel (self, self.playermodel);
690 setsize (self, m1, m2);
695 self.skin = stof(self.playerskin);
698 if(chmdl || oldskin != self.skin)
699 self.species = player_getspecies(); // model or skin has changed
702 if(strlen(autocvar_sv_defaultplayercolors))
703 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
704 setcolor(self, stof(autocvar_sv_defaultplayercolors));
707 void PlayerTouchExplode(entity p1, entity p2)
710 org = (p1.origin + p2.origin) * 0.5;
711 org_z += (p1.mins_z + p2.mins_z) * 0.5;
718 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
726 Called when a client spawns in the server
729 //void() ctf_playerchanged;
730 void PutClientInServer (void)
732 if(clienttype(self) == CLIENTTYPE_BOT)
734 self.classname = "player";
736 else if(clienttype(self) == CLIENTTYPE_REAL)
739 WriteByte(MSG_ONE, SVC_SETVIEW);
740 WriteEntity(MSG_ONE, self);
746 // player is dead and becomes observer
747 // FIXME fix LMS scoring for new system
750 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
751 self.classname = "observer";
754 if(g_arena || (g_ca && !allowed_to_spawn))
756 self.classname = "observer";
759 self.classname = "observer";
761 if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {
762 entity spot, oldself;
765 accuracy_resend(self);
768 JoinBestTeam(self, FALSE, TRUE);
772 spot = SelectSpawnPoint (FALSE);
775 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
776 return; // spawn failed
779 RemoveGrapplingHook(self); // Wazat's Grappling Hook
781 self.classname = "player";
782 self.wasplayer = TRUE;
783 self.iscreature = TRUE;
784 self.damagedbycontents = TRUE;
785 self.movetype = MOVETYPE_WALK;
786 self.solid = SOLID_SLIDEBOX;
787 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
788 if(autocvar_g_playerclip_collisions)
789 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
790 if(clienttype(self) == CLIENTTYPE_BOT && autocvar_g_botclip_collisions)
791 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
792 self.frags = FRAGS_PLAYER;
793 if(INDEPENDENT_PLAYERS)
794 MAKE_INDEPENDENT_PLAYER(self);
795 self.flags = FL_CLIENT;
796 if(autocvar__notarget)
797 self.flags |= FL_NOTARGET;
798 self.takedamage = DAMAGE_AIM;
800 self.effects = EF_FULLBRIGHT;
803 self.effects |= EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
804 self.air_finished = time + 12;
806 if(autocvar_g_balance_nex_charge)
808 if(autocvar_g_balance_nex_secondary_chargepool)
809 self.nex_chargepool_ammo = 1;
810 self.nex_charge = autocvar_g_balance_nex_charge_start;
815 self.ammo_shells = warmup_start_ammo_shells;
816 self.ammo_nails = warmup_start_ammo_nails;
817 self.ammo_rockets = warmup_start_ammo_rockets;
818 self.ammo_cells = warmup_start_ammo_cells;
819 self.ammo_fuel = warmup_start_ammo_fuel;
820 self.health = warmup_start_health;
821 self.armorvalue = warmup_start_armorvalue;
822 self.weapons = warmup_start_weapons;
826 self.ammo_shells = start_ammo_shells;
827 self.ammo_nails = start_ammo_nails;
828 self.ammo_rockets = start_ammo_rockets;
829 self.ammo_cells = start_ammo_cells;
830 self.ammo_fuel = start_ammo_fuel;
831 self.health = start_health;
832 self.armorvalue = start_armorvalue;
833 self.weapons = start_weapons;
836 if(g_weaponarena_random)
838 if(g_weaponarena_random_with_laser)
839 self.weapons &~= WEPBIT_LASER;
840 self.weapons = randombits(self.weapons, g_weaponarena_random, FALSE);
841 if(g_weaponarena_random_with_laser)
842 self.weapons |= WEPBIT_LASER;
845 self.items = start_items;
846 self.jump_interval = time;
848 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
849 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
850 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
851 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
852 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
853 //extend the pause of rotting if client was reset at the beginning of the countdown
854 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
855 self.spawnshieldtime += game_starttime - time;
856 self.pauserotarmor_finished += game_starttime - time;
857 self.pauserothealth_finished += game_starttime - time;
858 self.pauseregen_finished += game_starttime - time;
860 self.damageforcescale = 2;
867 self.pain_finished = 0;
868 self.strength_finished = 0;
869 self.invincible_finished = 0;
871 // players have no think function
872 self.think = SUB_Null;
876 self.ballistics_density = autocvar_g_ballistics_density_player;
882 self.deadflag = DEAD_NO;
884 self.angles = spot.angles;
886 self.angles_z = 0; // never spawn tilted even if the spot says to
887 self.fixangle = TRUE; // turn this way immediately
888 self.velocity = '0 0 0';
889 self.avelocity = '0 0 0';
890 self.punchangle = '0 0 0';
891 self.punchvector = '0 0 0';
892 self.oldvelocity = self.velocity;
893 self.fire_endtime = -1;
896 WRITESPECTATABLE_MSG_ONE({
897 WriteByte(MSG_ONE, SVC_TEMPENTITY);
898 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
903 self.drawonlytoclient = world;
906 self.view_ofs = PL_VIEW_OFS;
907 setsize (self, PL_MIN, PL_MAX);
908 self.spawnorigin = spot.origin;
909 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
910 // don't reset back to last position, even if new position is stuck in solid
911 self.oldorigin = self.origin;
912 self.prevorigin = self.origin;
913 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
914 self.lastteleporttime = time; // prevent insane speeds due to changing origin
915 self.hud = HUD_NORMAL;
919 Spawnqueue_Remove(self);
920 Spawnqueue_Mark(self);
926 self.event_damage = PlayerDamage;
928 self.bot_attack = TRUE;
930 self.statdraintime = time + 5;
931 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
933 if(self.killcount == -666) {
934 PlayerScore_Clear(self);
938 CL_SpawnWeaponentity();
939 self.alpha = default_player_alpha;
940 self.colormod = '1 1 1' * autocvar_g_player_brightness;
941 self.exteriorweaponentity.alpha = default_weapon_alpha;
943 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
944 self.lms_traveled_distance = 0;
945 self.speedrunning = FALSE;
947 race_PostSpawn(spot);
949 if(autocvar_spawn_debug)
951 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
952 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
955 //stuffcmd(self, "chase_active 0");
956 //stuffcmd(self, "set viewsize $tmpviewsize \n");
958 if (autocvar_g_spawnsound)
959 sound (self, CH_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
962 if(self.team == assault_attacker_team)
963 centerprint(self, "You are attacking!");
965 centerprint(self, "You are defending!");
968 target_voicescript_clear(self);
970 // reset fields the weapons may use
971 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
973 weapon_action(j, WR_RESETPLAYER);
975 // all weapons must be fully loaded when we spawn
977 e = get_weaponinfo(j);
978 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
979 self.(weapon_load[j]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
987 self.target = string_null;
993 MUTATOR_CALLHOOK(PlayerSpawn);
995 self.switchweapon = w_getbestweapon(self);
996 self.cnt = -1; // W_LastWeapon will not complain
998 self.weaponname = "";
999 self.switchingweapon = 0;
1002 self.alivetime = time;
1003 } else if(self.classname == "observer" || (g_ca && !allowed_to_spawn)) {
1004 PutObserverInServer ();
1008 // ctf_playerchanged();
1011 .float ebouncefactor, ebouncestop; // electro's values
1012 // TODO do we need all these fields, or should we stop autodetecting runtime
1013 // changes and just have a console command to update this?
1014 float ClientInit_SendEntity(entity to, float sf)
1016 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
1017 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
1018 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
1019 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
1020 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
1021 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
1022 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[0]));
1023 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[1]));
1024 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[2]));
1025 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[3]));
1026 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[0]));
1027 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[1]));
1028 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[2]));
1029 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[3]));
1030 if(sv_foginterval && world.fog != "")
1031 WriteString(MSG_ENTITY, world.fog);
1033 WriteString(MSG_ENTITY, "");
1034 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
1035 WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
1036 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_bouncefactor
1037 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_bouncestop
1038 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
1039 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
1040 WriteByte(MSG_ENTITY, autocvar_g_balance_nex_secondary); // client has to know if it should zoom or not
1041 WriteByte(MSG_ENTITY, autocvar_g_balance_rifle_secondary); // client has to know if it should zoom or not
1042 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
1043 WriteByte(MSG_ENTITY, autocvar_g_balance_minelayer_limit); // minelayer max mines
1044 WriteByte(MSG_ENTITY, autocvar_g_balance_hagar_secondary_load_max); // hagar max loadable rockets
1045 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
1049 void ClientInit_CheckUpdate()
1051 self.nextthink = time;
1052 if(self.count != autocvar_g_balance_armor_blockpercent)
1054 self.count = autocvar_g_balance_armor_blockpercent;
1055 self.SendFlags |= 1;
1057 if(self.cnt != autocvar_g_balance_weaponswitchdelay)
1059 self.cnt = autocvar_g_balance_weaponswitchdelay;
1060 self.SendFlags |= 1;
1062 if(self.bouncefactor != autocvar_g_balance_grenadelauncher_bouncefactor)
1064 self.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
1065 self.SendFlags |= 1;
1067 if(self.bouncestop != autocvar_g_balance_grenadelauncher_bouncestop)
1069 self.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
1070 self.SendFlags |= 1;
1072 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
1074 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
1075 self.SendFlags |= 1;
1077 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
1079 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
1080 self.SendFlags |= 1;
1084 void ClientInit_Spawn()
1089 e.classname = "clientinit";
1090 e.think = ClientInit_CheckUpdate;
1091 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
1095 ClientInit_CheckUpdate();
1104 void SetNewParms (void)
1106 // initialize parms for a new player
1107 parm1 = -(86400 * 366);
1115 void SetChangeParms (void)
1117 // save parms for level change
1118 parm1 = self.parm_idlesince - time;
1126 void DecodeLevelParms (void)
1129 self.parm_idlesince = parm1;
1130 if(self.parm_idlesince == -(86400 * 366))
1131 self.parm_idlesince = time;
1133 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1134 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1141 Called when a client types 'kill' in the console
1145 .float clientkill_nexttime;
1146 void ClientKill_Now_TeamChange()
1148 if(self.killindicator_teamchange == -1)
1151 JoinBestTeam( self, FALSE, FALSE );
1153 else if(self.killindicator_teamchange == -2)
1158 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"));
1159 PutObserverInServer();
1162 SV_ChangeTeam(self.killindicator_teamchange - 1);
1165 void ClientKill_Now()
1169 vehicles_exit(VHEF_RELESE);
1170 if(!self.killindicator_teamchange)
1172 self.vehicle_health = -1;
1173 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
1177 if(self.killindicator && !wasfreed(self.killindicator))
1178 remove(self.killindicator);
1180 self.killindicator = world;
1182 if(self.killindicator_teamchange)
1183 ClientKill_Now_TeamChange();
1186 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1188 // now I am sure the player IS dead
1190 void KillIndicator_Think()
1194 self.owner.killindicator = world;
1199 if (!self.owner.modelindex)
1201 self.owner.killindicator = world;
1209 ClientKill_Now(); // no oldself needed
1212 else if(g_cts && self.health == 1) // health == 1 means that it's silent
1214 self.nextthink = time + 1;
1220 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1221 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1224 AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));
1226 self.nextthink = time + 1;
1231 float clientkilltime;
1232 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
1241 killtime = autocvar_g_balance_kill_delay;
1243 if(g_race_qualifying || g_cts)
1246 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
1248 remove(self.killindicator);
1249 self.killindicator = world;
1251 ClientKill_Now(); // allow instant kill in this case
1255 self.killindicator_teamchange = targetteam;
1257 if(!self.killindicator)
1259 if(self.modelindex && self.deadflag == DEAD_NO)
1261 killtime = max(killtime, self.clientkill_nexttime - time);
1262 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
1265 if(killtime <= 0 || self.classname != "player" || self.deadflag != DEAD_NO)
1271 starttime = max(time, clientkilltime);
1273 self.killindicator = spawn();
1274 self.killindicator.owner = self;
1275 self.killindicator.scale = 0.5;
1276 setattachment(self.killindicator, self, "");
1277 setorigin(self.killindicator, '0 0 52');
1278 self.killindicator.think = KillIndicator_Think;
1279 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
1280 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
1281 self.killindicator.cnt = ceil(killtime);
1282 self.killindicator.count = bound(0, ceil(killtime), 10);
1283 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1285 for(e = world; (e = find(e, classname, "body")) != world; )
1289 e.killindicator = spawn();
1290 e.killindicator.owner = e;
1291 e.killindicator.scale = 0.5;
1292 setattachment(e.killindicator, e, "");
1293 setorigin(e.killindicator, '0 0 52');
1294 e.killindicator.think = KillIndicator_Think;
1295 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
1296 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
1297 e.killindicator.cnt = ceil(killtime);
1302 if(self.killindicator)
1304 if(targetteam == 0) // just die
1306 self.killindicator.colormod = '0 0 0';
1307 if(clienttype(self) == CLIENTTYPE_REAL)
1308 if(self.killindicator.cnt > 0)
1309 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "^1Suicide in %d seconds", 1, self.killindicator.cnt);
1311 else if(targetteam == -1) // auto
1313 self.killindicator.colormod = '0 1 0';
1314 if(clienttype(self) == CLIENTTYPE_REAL)
1315 if(self.killindicator.cnt > 0)
1316 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Changing team in %d seconds", 1, self.killindicator.cnt);
1318 else if(targetteam == -2) // spectate
1320 self.killindicator.colormod = '0.5 0.5 0.5';
1321 if(clienttype(self) == CLIENTTYPE_REAL)
1322 if(self.killindicator.cnt > 0)
1323 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Spectating in %d seconds", 1, self.killindicator.cnt);
1327 self.killindicator.colormod = TeamColor(targetteam);
1328 if(clienttype(self) == CLIENTTYPE_REAL)
1329 if(self.killindicator.cnt > 0)
1330 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, strcat("Changing to ", ColoredTeamName(targetteam), " in %d seconds"), 1, self.killindicator.cnt);
1336 void ClientKill (void)
1341 if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either
1345 else if(self.freezetag_frozen)
1350 ClientKill_TeamChange(0);
1353 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
1355 e.killindicator = spawn();
1356 e.killindicator.owner = e;
1357 e.killindicator.think = KillIndicator_Think;
1358 e.killindicator.nextthink = time + (e.lip) * 0.05;
1359 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
1360 e.killindicator.health = 1; // this is used to indicate that it should be silent
1364 void FixClientCvars(entity e)
1366 // send prediction settings to the client
1367 stuffcmd(e, "\nin_bindmap 0 0\n");
1369 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1370 if(autocvar_g_antilag == 3) // client side hitscan
1371 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1373 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1375 * we no longer need to stuff this. Remove this comment block if you feel
1376 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1377 stuffcmd(e, strcat("cl_gravity ", ftos(autocvar_sv_gravity), "\n"));
1378 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(autocvar_sv_accelerate), "\n"));
1379 stuffcmd(e, strcat("cl_movement_friction ", ftos(autocvar_sv_friction), "\n"));
1380 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(autocvar_sv_maxspeed), "\n"));
1381 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(autocvar_sv_airaccelerate), "\n"));
1382 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(autocvar_sv_maxairspeed), "\n"));
1383 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(autocvar_sv_stopspeed), "\n"));
1384 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(autocvar_sv_jumpvelocity), "\n"));
1385 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(autocvar_sv_stepheight), "\n"));
1386 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(autocvar_sv_friction_on_land), "\n"));
1387 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(autocvar_sv_airaccel_qw), "\n"));
1388 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(autocvar_sv_airaccel_sideways_friction), "\n"));
1389 stuffcmd(e, "cl_movement_edgefriction 1\n");
1393 float PlayerInIDList(entity p, string idlist)
1398 // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
1399 if not(p.crypto_idfp)
1402 // this function allows abbreviated player IDs too!
1403 n = tokenize_console(idlist);
1404 for(i = 0; i < n; ++i)
1407 if(s == substring(p.crypto_idfp, 0, strlen(s)))
1414 #ifndef NO_LEGACY_NETWORKING
1422 Called when a client connects to the server
1425 //void ctf_clientconnect();
1426 string ColoredTeamName(float t);
1427 void DecodeLevelParms (void);
1428 //void dom_player_join_team(entity pl);
1429 void set_dom_state(entity e);
1430 void ClientConnect (void)
1434 if(self.flags & FL_CLIENT)
1436 print("Warning: ClientConnect, but already connected!\n");
1440 if(Ban_MaybeEnforceBan(self))
1446 sprint(self, strcat("^4SVQC Build information: ^1", WATERMARK(), "\n"));
1449 self.classname = "player_joining";
1451 self.flags = FL_CLIENT;
1452 self.version_nagtime = time + 10 + random() * 10;
1456 dprint("BUG player count is lower than zero, this cannot happen!\n");
1460 PlayerScore_Attach(self);
1461 ClientData_Attach();
1462 accuracy_init(self);
1464 bot_clientconnect();
1470 race_PreSpawnObserver();
1473 // dom_player_join_team(self);
1475 // identify the right forced team
1476 if(autocvar_g_campaign)
1478 if(clienttype(self) == CLIENTTYPE_REAL) // only players, not bots
1480 switch(autocvar_g_campaign_forceteam)
1482 case 1: self.team_forced = COLOR_TEAM1; break;
1483 case 2: self.team_forced = COLOR_TEAM2; break;
1484 case 3: self.team_forced = COLOR_TEAM3; break;
1485 case 4: self.team_forced = COLOR_TEAM4; break;
1486 default: self.team_forced = 0;
1490 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1491 self.team_forced = COLOR_TEAM1;
1492 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1493 self.team_forced = COLOR_TEAM2;
1494 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1495 self.team_forced = COLOR_TEAM3;
1496 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1497 self.team_forced = COLOR_TEAM4;
1498 else if(autocvar_g_forced_team_otherwise == "red")
1499 self.team_forced = COLOR_TEAM1;
1500 else if(autocvar_g_forced_team_otherwise == "blue")
1501 self.team_forced = COLOR_TEAM2;
1502 else if(autocvar_g_forced_team_otherwise == "yellow")
1503 self.team_forced = COLOR_TEAM3;
1504 else if(autocvar_g_forced_team_otherwise == "pink")
1505 self.team_forced = COLOR_TEAM4;
1506 else if(autocvar_g_forced_team_otherwise == "spectate")
1507 self.team_forced = -1;
1508 else if(autocvar_g_forced_team_otherwise == "spectator")
1509 self.team_forced = -1;
1511 self.team_forced = 0;
1514 if(self.team_forced > 0)
1515 self.team_forced = 0;
1517 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1519 if((autocvar_sv_spectate == 1 && !g_lms) || autocvar_g_campaign || self.team_forced < 0) {
1520 self.classname = "observer";
1524 if(autocvar_g_balance_teams || autocvar_g_balance_teams_force)
1526 self.classname = "player";
1527 campaign_bots_may_start = 1;
1531 self.classname = "observer"; // do it anyway
1536 self.classname = "player";
1537 campaign_bots_may_start = 1;
1541 self.playerid = (playerid_last = playerid_last + 1);
1543 PlayerStats_AddEvent(sprintf("kills-%d", self.playerid));
1545 if(clienttype(self) == CLIENTTYPE_BOT)
1546 PlayerStats_AddPlayer(self);
1548 if(autocvar_sv_eventlog)
1549 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
1551 LogTeamchange(self.playerid, self.team, 1);
1553 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1555 self.netname_previous = strzone(self.netname);
1557 bprint("^4", self.netname, "^4 connected");
1559 if(self.classname != "observer" && (g_domination || g_ctf))
1560 bprint(" and joined the ", ColoredTeamName(self.team));
1564 stuffcmd(self, strcat(clientstuff, "\n"));
1565 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1567 FixClientCvars(self);
1569 // spawnfunc_waypoint sprites
1570 WaypointSprite_InitClient(self);
1572 // Wazat's grappling hook
1573 SetGrappleHookBindings();
1575 // get version info from player
1576 stuffcmd(self, "cmd clientversion $gameversion\n");
1578 // get other cvars from player
1581 // notify about available teams
1584 CheckAllowedTeams(self);
1585 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1586 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1589 stuffcmd(self, "set _teams_available 0\n");
1591 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1595 self.classname = "observer";
1597 Spawnqueue_Insert(self);
1601 ctf_clientconnect();
1606 bot_relinkplayerlist();
1608 self.spectatortime = time;
1611 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"));
1614 self.jointime = time;
1615 self.allowedTimeouts = autocvar_sv_timeout_number;
1617 if(clienttype(self) == CLIENTTYPE_REAL)
1619 if(autocvar_g_bugrigs || g_weaponarena == WEPBIT_TUBA)
1620 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1625 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1627 PlayerScore_Add(self, SP_LMS_RANK, 666);
1628 self.frags = FRAGS_SPECTATOR;
1632 if(!sv_foginterval && world.fog != "")
1633 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1635 SoundEntity_Attach(self);
1637 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", self.netaddress, " "), 0) >= 0)
1639 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1640 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1643 self.hitplotfh = -1;
1645 if(g_race || g_cts) {
1651 t = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
1654 race_send_recordtime(MSG_ONE);
1655 race_send_speedaward(MSG_ONE);
1657 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
1658 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
1659 race_send_speedaward_alltimebest(MSG_ONE);
1662 for (i = 1; i <= RANKINGS_CNT; ++i) {
1663 race_SendRankings(i, 0, 0, MSG_ONE);
1666 else if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
1667 send_CSQC_teamnagger();
1670 set_dom_state(self);
1674 if(!autocvar_g_campaign)
1675 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), autocvar_welcome_message_time, 0);
1677 #ifndef NO_LEGACY_NETWORKING
1678 if(autocvar_sv_use_csqc_players)
1680 CSQCModel_LinkEntity();
1681 self.iscsqcmodel = 1;
1684 CSQCModel_LinkEntity();
1692 Called when a client disconnects from the server
1695 .entity chatbubbleentity;
1697 void ClientDisconnect (void)
1700 vehicles_exit(VHEF_RELESE);
1702 if not(self.flags & FL_CLIENT)
1704 print("Warning: ClientDisconnect without ClientConnect\n");
1708 PlayerStats_AddGlobalInfo(self);
1710 CheatShutdownClient();
1712 if(self.hitplotfh >= 0)
1714 fclose(self.hitplotfh);
1715 self.hitplotfh = -1;
1719 anticheat_shutdown();
1721 playerdemo_shutdown();
1723 bot_clientdisconnect();
1728 if(autocvar_sv_eventlog)
1729 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1730 bprint ("^4",self.netname);
1731 bprint ("^4 disconnected\n");
1733 SoundEntity_Detach(self);
1736 MUTATOR_CALLHOOK(ClientDisconnect);
1738 Portal_ClearAll(self);
1740 RemoveGrapplingHook(self);
1741 if(self.flagcarried)
1742 DropFlag(self.flagcarried, world, world);
1743 if(self.ballcarried && g_nexball)
1744 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1746 // Here, everything has been done that requires this player to be a client.
1748 self.flags &~= FL_CLIENT;
1750 if (self.chatbubbleentity)
1751 remove (self.chatbubbleentity);
1753 if (self.killindicator)
1754 remove (self.killindicator);
1756 WaypointSprite_PlayerGone();
1758 bot_relinkplayerlist();
1762 Spawnqueue_Unmark(self);
1763 Spawnqueue_Remove(self);
1766 accuracy_free(self);
1767 ClientData_Detach();
1768 PlayerScore_Detach(self);
1770 if(self.netname_previous)
1771 strunzone(self.netname_previous);
1772 if(self.clientstatus)
1773 strunzone(self.clientstatus);
1774 if(self.weaponorder_byimpulse)
1775 strunzone(self.weaponorder_byimpulse);
1777 ClearPlayerSounds();
1780 remove(self.personal);
1790 void ChatBubbleThink()
1792 self.nextthink = time;
1793 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1795 if(self.owner) // but why can that ever be world?
1796 self.owner.chatbubbleentity = world;
1800 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1802 || self.owner.tetris_on
1805 self.model = self.mdl;
1810 void UpdateChatBubble()
1812 if (!self.modelindex)
1814 // spawn a chatbubble entity if needed
1815 if (!self.chatbubbleentity)
1817 self.chatbubbleentity = spawn();
1818 self.chatbubbleentity.owner = self;
1819 self.chatbubbleentity.exteriormodeltoclient = self;
1820 self.chatbubbleentity.think = ChatBubbleThink;
1821 self.chatbubbleentity.nextthink = time;
1822 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1823 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1824 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1825 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1826 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1827 self.chatbubbleentity.model = "";
1828 self.chatbubbleentity.effects = EF_LOWPRECISION;
1833 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1834 // added to the model skins
1835 /*void UpdateColorModHack()
1838 c = self.clientcolors & 15;
1839 // LordHavoc: only bothering to support white, green, red, yellow, blue
1840 if (!teamplay) self.colormod = '0 0 0';
1841 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1842 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1843 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1844 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1845 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1846 else self.colormod = '1 1 1';
1852 if(self.modelindex != 0 && autocvar_g_respawn_ghosts)
1854 self.solid = SOLID_NOT;
1855 self.takedamage = DAMAGE_NO;
1856 self.movetype = MOVETYPE_FLY;
1857 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1858 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1859 self.effects |= EF_ADDITIVE;
1860 self.oldcolormap = self.colormap;
1861 self.colormap = 0; // this originally was 512, but raises a warning in the engine, so get rid of it
1862 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1863 if(autocvar_g_respawn_ghosts_maxtime)
1864 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1868 self.effects |= EF_NODRAW; // prevent another CopyBody
1869 if(self.oldcolormap)
1871 self.colormap = self.oldcolormap;
1872 self.oldcolormap = 0;
1874 PutClientInServer();
1877 void play_countdown(float finished, string samp)
1879 if(clienttype(self) == CLIENTTYPE_REAL)
1880 if(floor(finished - time - frametime) != floor(finished - time))
1881 if(finished - time < 6)
1882 sound (self, CH_INFO, samp, VOL_BASE, ATTN_NORM);
1885 void player_powerups (void)
1887 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1888 olditems = self.items;
1890 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1892 SoundEntity_StartSound(self, CH_TRIGGER_SINGLE, "misc/jetpack_fly.wav", VOL_BASE, autocvar_g_jetpack_attenuation);
1893 self.modelflags |= MF_ROCKET;
1897 SoundEntity_StopSound(self, CH_TRIGGER_SINGLE);
1898 self.modelflags &~= MF_ROCKET;
1901 self.effects &~= (EF_DIMLIGHT | EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1903 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1906 Fire_ApplyDamage(self);
1907 Fire_ApplyEffect(self);
1911 self.effects |= EF_FULLBRIGHT;
1913 if (self.items & IT_STRENGTH)
1915 play_countdown(self.strength_finished, "misc/poweroff.wav");
1916 if (time > self.strength_finished)
1918 self.alpha = default_player_alpha;
1919 self.exteriorweaponentity.alpha = default_weapon_alpha;
1920 self.items &~= IT_STRENGTH;
1921 sprint(self, "^3Invisibility has worn off\n");
1926 if (time < self.strength_finished)
1928 self.alpha = g_minstagib_invis_alpha;
1929 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1930 self.items |= IT_STRENGTH;
1931 sprint(self, "^3You are invisible\n");
1935 if (self.items & IT_INVINCIBLE)
1937 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1938 if (time > self.invincible_finished && autocvar_g_balance_powerup_timer)
1940 self.items = self.items - (self.items & IT_INVINCIBLE);
1941 sprint(self, "^3Speed has worn off\n");
1946 if (time < self.invincible_finished)
1948 self.items = self.items | IT_INVINCIBLE;
1949 sprint(self, "^3You are on speed\n");
1953 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.
1955 if (self.items & IT_STRENGTH)
1957 play_countdown(self.strength_finished, "misc/poweroff.wav");
1958 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1959 if (time > self.strength_finished && autocvar_g_balance_powerup_timer)
1961 self.items = self.items - (self.items & IT_STRENGTH);
1962 sprint(self, "^3Strength has worn off\n");
1967 if (time < self.strength_finished)
1969 self.items = self.items | IT_STRENGTH;
1970 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1973 if (self.items & IT_INVINCIBLE)
1975 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1976 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1977 if (time > self.invincible_finished && autocvar_g_balance_powerup_timer)
1979 self.items = self.items - (self.items & IT_INVINCIBLE);
1980 sprint(self, "^3Shield has worn off\n");
1985 if (time < self.invincible_finished)
1987 self.items = self.items | IT_INVINCIBLE;
1988 sprint(self, "^3Shield surrounds you\n");
1992 if(autocvar_g_nodepthtestplayers)
1993 self.effects = self.effects | EF_NODEPTHTEST;
1995 if(autocvar_g_fullbrightplayers)
1996 self.effects = self.effects | EF_FULLBRIGHT;
1998 // midair gamemode: damage only while in the air
1999 // if in midair mode, being on ground grants temporary invulnerability
2000 // (this is so that multishot weapon don't clear the ground flag on the
2001 // first damage in the frame, leaving the player vulnerable to the
2002 // remaining hits in the same frame)
2003 if (self.flags & FL_ONGROUND)
2005 self.spawnshieldtime = max(self.spawnshieldtime, time + autocvar_g_midair_shieldtime);
2007 if (time >= game_starttime)
2008 if (time < self.spawnshieldtime)
2009 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
2012 MUTATOR_CALLHOOK(PlayerPowerups);
2015 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
2017 if(current > stable)
2019 else if(current > stable - 0.25) // when close enough, "snap"
2022 return min(stable, current + (stable - current) * regenfactor * regenframetime);
2025 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
2027 if(current < stable)
2029 else if(current < stable + 0.25) // when close enough, "snap"
2032 return max(stable, current + (stable - current) * rotfactor * rotframetime);
2035 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
2037 if(current > rotstable)
2039 if(rotframetime > 0)
2041 current = CalcRot(current, rotstable, rotfactor, rotframetime);
2042 current = max(rotstable, current - rotlinear * rotframetime);
2045 else if(current < regenstable)
2047 if(regenframetime > 0)
2049 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
2050 current = min(regenstable, current + regenlinear * regenframetime);
2060 void player_regen (void)
2062 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
2063 maxh = autocvar_g_balance_health_rotstable;
2064 maxa = autocvar_g_balance_armor_rotstable;
2065 maxf = autocvar_g_balance_fuel_rotstable;
2066 minh = autocvar_g_balance_health_regenstable;
2067 mina = autocvar_g_balance_armor_regenstable;
2068 minf = autocvar_g_balance_fuel_regenstable;
2069 limith = autocvar_g_balance_health_limit;
2070 limita = autocvar_g_balance_armor_limit;
2071 limitf = autocvar_g_balance_fuel_limit;
2073 max_mod = regen_mod = rot_mod = limit_mod = 1;
2075 if (self.runes & RUNE_REGEN)
2077 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
2079 regen_mod = autocvar_g_balance_rune_regen_combo_regenrate;
2080 max_mod = autocvar_g_balance_rune_regen_combo_hpmod;
2081 limit_mod = autocvar_g_balance_rune_regen_combo_limitmod;
2085 regen_mod = autocvar_g_balance_rune_regen_regenrate;
2086 max_mod = autocvar_g_balance_rune_regen_hpmod;
2087 limit_mod = autocvar_g_balance_rune_regen_limitmod;
2090 else if (self.runes & CURSE_VENOM)
2092 max_mod = autocvar_g_balance_curse_venom_hpmod;
2093 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
2094 rot_mod = autocvar_g_balance_rune_regen_combo_rotrate;
2096 rot_mod = autocvar_g_balance_curse_venom_rotrate;
2097 limit_mod = autocvar_g_balance_curse_venom_limitmod;
2098 //if (!self.runes & RUNE_REGEN)
2099 // rot_mod = autocvar_g_balance_curse_venom_rotrate;
2101 maxh = maxh * max_mod;
2102 //maxa = maxa * max_mod;
2103 //maxf = maxf * max_mod;
2104 minh = minh * max_mod;
2105 //mina = mina * max_mod;
2106 //minf = minf * max_mod;
2107 limith = limith * limit_mod;
2108 limita = limita * limit_mod;
2109 //limitf = limitf * limit_mod;
2114 if (!g_minstagib && !g_ca && (!g_lms || autocvar_g_lms_regenerate))
2116 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);
2117 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);
2119 // if player rotted to death... die!
2121 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2124 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
2125 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);
2128 float zoomstate_set;
2129 void SetZoomState(float z)
2131 if(z != self.zoomstate)
2134 ClientData_Touch(self);
2139 void GetPressedKeys(void) {
2140 MUTATOR_CALLHOOK(GetPressedKeys);
2141 if (self.movement_x > 0) // get if movement keys are pressed
2142 { // forward key pressed
2143 self.pressedkeys |= KEY_FORWARD;
2144 self.pressedkeys &~= KEY_BACKWARD;
2146 else if (self.movement_x < 0)
2147 { // backward key pressed
2148 self.pressedkeys |= KEY_BACKWARD;
2149 self.pressedkeys &~= KEY_FORWARD;
2153 self.pressedkeys &~= KEY_FORWARD;
2154 self.pressedkeys &~= KEY_BACKWARD;
2157 if (self.movement_y > 0)
2158 { // right key pressed
2159 self.pressedkeys |= KEY_RIGHT;
2160 self.pressedkeys &~= KEY_LEFT;
2162 else if (self.movement_y < 0)
2163 { // left key pressed
2164 self.pressedkeys |= KEY_LEFT;
2165 self.pressedkeys &~= KEY_RIGHT;
2169 self.pressedkeys &~= KEY_RIGHT;
2170 self.pressedkeys &~= KEY_LEFT;
2173 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
2174 self.pressedkeys |= KEY_JUMP;
2176 self.pressedkeys &~= KEY_JUMP;
2177 if (self.BUTTON_CROUCH)
2178 self.pressedkeys |= KEY_CROUCH;
2180 self.pressedkeys &~= KEY_CROUCH;
2184 ======================
2185 spectate mode routines
2186 ======================
2189 void SpectateCopy(entity spectatee) {
2191 MUTATOR_CALLHOOK(SpectateCopy);
2192 self.armortype = spectatee.armortype;
2193 self.armorvalue = spectatee.armorvalue;
2194 self.ammo_cells = spectatee.ammo_cells;
2195 self.ammo_shells = spectatee.ammo_shells;
2196 self.ammo_nails = spectatee.ammo_nails;
2197 self.ammo_rockets = spectatee.ammo_rockets;
2198 self.ammo_fuel = spectatee.ammo_fuel;
2199 self.clip_load = spectatee.clip_load;
2200 self.clip_size = spectatee.clip_size;
2201 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
2202 self.health = spectatee.health;
2204 self.items = spectatee.items;
2205 self.last_pickup = spectatee.last_pickup;
2206 self.hit_time = spectatee.hit_time;
2207 self.metertime = spectatee.metertime;
2208 self.strength_finished = spectatee.strength_finished;
2209 self.invincible_finished = spectatee.invincible_finished;
2210 self.pressedkeys = spectatee.pressedkeys;
2211 self.weapons = spectatee.weapons;
2212 self.switchweapon = spectatee.switchweapon;
2213 self.switchingweapon = spectatee.switchingweapon;
2214 self.weapon = spectatee.weapon;
2215 self.nex_charge = spectatee.nex_charge;
2216 self.nex_chargepool_ammo = spectatee.nex_chargepool_ammo;
2217 self.hagar_load = spectatee.hagar_load;
2218 self.minelayer_mines = spectatee.minelayer_mines;
2219 self.punchangle = spectatee.punchangle;
2220 self.view_ofs = spectatee.view_ofs;
2221 self.v_angle = spectatee.v_angle;
2222 self.velocity = spectatee.velocity;
2223 self.dmg_take = spectatee.dmg_take;
2224 self.dmg_save = spectatee.dmg_save;
2225 self.dmg_inflictor = spectatee.dmg_inflictor;
2226 self.angles = spectatee.v_angle;
2227 if(!self.BUTTON_USE)
2228 self.fixangle = TRUE;
2229 setorigin(self, spectatee.origin);
2230 setsize(self, spectatee.mins, spectatee.maxs);
2231 SetZoomState(spectatee.zoomstate);
2233 anticheat_spectatecopy(spectatee);
2235 //self.vehicle = spectatee.vehicle;
2237 self.hud = spectatee.hud;
2238 if(spectatee.vehicle)
2240 setorigin(self, spectatee.origin);
2241 self.velocity = spectatee.vehicle.velocity;
2242 self.v_angle += spectatee.vehicle.angles;
2243 //self.v_angle_x *= -1;
2244 self.vehicle_health = spectatee.vehicle_health;
2245 self.vehicle_shield = spectatee.vehicle_shield;
2246 self.vehicle_energy = spectatee.vehicle_energy;
2247 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
2248 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
2249 self.vehicle_reload1 = spectatee.vehicle_reload1;
2250 self.vehicle_reload2 = spectatee.vehicle_reload2;
2253 WriteByte (MSG_ONE, SVC_SETVIEWPORT);
2254 WriteEntity(MSG_ONE, spectatee);
2255 //self.tur_head = spectatee.vehicle.vehicle_viewport;
2259 float SpectateUpdate() {
2263 if (self == self.enemy)
2266 if(self.enemy.classname != "player")
2269 SpectateCopy(self.enemy);
2275 // Returns next available player to spectate if g_ca_spectate_enemies == 0
2276 entity CA_SpectateNext(entity start) {
2277 if (start.team == self.team) {
2282 // continue from current player
2283 while(other && other.team != self.team) {
2284 other = find(other, classname, "player");
2288 // restart from begining
2289 other = find(other, classname, "player");
2290 while(other && other.team != self.team) {
2291 other = find(other, classname, "player");
2298 float SpectateNext() {
2299 other = find(self.enemy, classname, "player");
2300 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer) {
2301 // CA and ca players when spectating enemies is forbidden
2302 other = CA_SpectateNext(other);
2304 // other modes and ca spectators or spectating enemies is allowed
2306 other = find(other, classname, "player");
2312 if(self.enemy.classname == "player") {
2313 if(self.enemy.vehicle)
2316 WriteByte(MSG_ONE, SVC_SETVIEWPORT);
2317 WriteEntity(MSG_ONE, self.enemy);
2318 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2319 self.movetype = MOVETYPE_NONE;
2320 accuracy_resend(self);
2325 WriteByte(MSG_ONE, SVC_SETVIEW);
2326 WriteEntity(MSG_ONE, self.enemy);
2327 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2328 self.movetype = MOVETYPE_NONE;
2329 accuracy_resend(self);
2331 if(!SpectateUpdate())
2332 PutObserverInServer();
2342 ShowRespawnCountdown()
2344 Update a respawn countdown display.
2347 void ShowRespawnCountdown()
2350 if(self.deadflag == DEAD_NO) // just respawned?
2354 number = ceil(self.death_time - time);
2357 if(number <= self.respawn_countdown)
2359 self.respawn_countdown = number - 1;
2360 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
2361 AnnounceTo(self, strcat(ftos(number), ""));
2366 .float prevent_join_msgtime;
2367 void LeaveSpectatorMode()
2369 if(nJoinAllowed(1)) {
2370 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) {
2371 self.classname = "player";
2373 if(autocvar_g_campaign || autocvar_g_balance_teams || autocvar_g_balance_teams_force)
2374 JoinBestTeam(self, FALSE, TRUE);
2376 if(autocvar_g_campaign)
2377 campaign_bots_may_start = 1;
2379 PutClientInServer();
2381 if(self.classname == "player")
2382 bprint ("^4", self.netname, "^4 is playing now\n");
2384 if(!autocvar_g_campaign)
2385 if (time < self.jointime + autocvar_welcome_message_time)
2386 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD); // clear MOTD
2388 if (self.prevent_join_msgtime)
2390 Send_CSQC_Centerprint_Generic_Expire(self, CPID_PREVENT_JOIN);
2391 self.prevent_join_msgtime = 0;
2396 if (g_ca && self.caplayer) {
2399 stuffcmd(self,"menu_showteamselect\n");
2404 //player may not join because of g_maxplayers is set
2405 if (time - self.prevent_join_msgtime > 2)
2407 Send_CSQC_Centerprint_Generic(self, CPID_PREVENT_JOIN, PREVENT_JOIN_TEXT, 0, 0);
2408 self.prevent_join_msgtime = time;
2414 * Determines whether the player is allowed to join. This depends on cvar
2415 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2416 * it checks whether the number of currently playing players exceeds g_maxplayers.
2417 * @return int number of free slots for players, 0 if none
2419 float nJoinAllowed(float includeMe) {
2420 if(self.team_forced < 0)
2421 return FALSE; // forced spectators can never join
2423 // TODO simplify this
2430 if (!autocvar_g_maxplayers)
2431 return maxclients - totalClients + includeMe;
2433 float currentlyPlaying;
2434 FOR_EACH_REALPLAYER(e)
2435 currentlyPlaying += 1;
2437 if(currentlyPlaying < autocvar_g_maxplayers)
2438 return min(maxclients - totalClients + includeMe, autocvar_g_maxplayers - currentlyPlaying);
2444 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2445 * g_maxplayers_spectator_blocktime seconds
2447 void checkSpectatorBlock() {
2448 if(self.classname == "spectator" || self.classname == "observer") {
2449 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2450 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2456 .float motd_actived_time; // used for both motd and campaign_message
2457 void PrintWelcomeMessage()
2459 if (self.motd_actived_time == 0) { // is there already a message showing?
2460 if (autocvar_g_campaign) {
2461 if ((self.classname == "player" && self.BUTTON_INFO) || (self.classname != "player")) {
2462 self.motd_actived_time = time;
2463 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, campaign_message, -1, 0);
2466 if ((time - self.jointime > autocvar_welcome_message_time) && self.BUTTON_INFO) {
2467 self.motd_actived_time = time;
2468 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), -1, 0);
2471 } else { // showing MOTD or campaign message
2472 if (autocvar_g_campaign) {
2473 if (self.BUTTON_INFO)
2474 self.motd_actived_time = time;
2475 else if ((time - self.motd_actived_time > 2) && self.classname == "player") { // hide it some seconds after BUTTON_INFO has been released
2476 self.motd_actived_time = 0;
2477 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2480 if ((time - self.jointime) > autocvar_welcome_message_time) {
2481 if (self.BUTTON_INFO)
2482 self.motd_actived_time = time;
2483 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2484 self.motd_actived_time = 0;
2485 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2492 void ObserverThink()
2494 float prefered_movetype;
2495 if (self.flags & FL_JUMPRELEASED) {
2496 if (self.BUTTON_JUMP && !self.version_mismatch) {
2497 self.flags &~= FL_JUMPRELEASED;
2498 self.flags |= FL_SPAWNING;
2499 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2500 self.flags &~= FL_JUMPRELEASED;
2501 if(SpectateNext() == 1) {
2502 self.classname = "spectator";
2505 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2506 if (self.movetype != prefered_movetype)
2507 self.movetype = prefered_movetype;
2510 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2511 self.flags |= FL_JUMPRELEASED;
2512 if(self.flags & FL_SPAWNING)
2514 self.flags &~= FL_SPAWNING;
2515 LeaveSpectatorMode();
2521 PrintWelcomeMessage();
2524 void SpectatorThink()
2526 if (self.flags & FL_JUMPRELEASED) {
2527 if (self.BUTTON_JUMP && !self.version_mismatch) {
2528 self.flags &~= FL_JUMPRELEASED;
2529 self.flags |= FL_SPAWNING;
2530 } else if(self.BUTTON_ATCK) {
2531 self.flags &~= FL_JUMPRELEASED;
2532 if(SpectateNext() == 1) {
2533 self.classname = "spectator";
2535 self.classname = "observer";
2536 PutClientInServer();
2538 } else if (self.BUTTON_ATCK2) {
2539 self.flags &~= FL_JUMPRELEASED;
2540 self.classname = "observer";
2541 PutClientInServer();
2543 if(!SpectateUpdate())
2544 PutObserverInServer();
2547 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2548 self.flags |= FL_JUMPRELEASED;
2549 if(self.flags & FL_SPAWNING)
2551 self.flags &~= FL_SPAWNING;
2552 LeaveSpectatorMode();
2556 if(!SpectateUpdate())
2557 PutObserverInServer();
2560 PrintWelcomeMessage();
2561 self.flags |= FL_CLIENT | FL_NOTARGET;
2567 if(self.classname != "player")
2572 vehicles_exit(VHEF_NORMAL);
2576 // a use key was pressed; call handlers
2580 MUTATOR_CALLHOOK(PlayerUseKey);
2583 .float touchexplode_time;
2589 Called every frame for each client before the physics are run
2592 .float usekeypressed;
2593 void() ctf_setstatus;
2594 void() nexball_setstatus;
2596 void PlayerPreThink (void)
2598 WarpZone_PlayerPhysics_FixVAngle();
2600 self.stat_game_starttime = game_starttime;
2601 self.stat_allow_oldnexbeam = autocvar_g_allow_oldnexbeam;
2602 self.stat_leadlimit = autocvar_leadlimit;
2606 // physics frames: update anticheat stuff
2607 anticheat_prethink();
2610 if(blockSpectators && frametime)
2611 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2612 checkSpectatorBlock();
2616 if(self.netname_previous != self.netname)
2618 if(autocvar_sv_eventlog)
2619 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2620 if(self.netname_previous)
2621 strunzone(self.netname_previous);
2622 self.netname_previous = strzone(self.netname);
2626 if(self.version_nagtime)
2627 if(self.cvar_g_xonoticversion)
2628 if(time > self.version_nagtime)
2630 // don't notify git users
2631 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2633 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2635 // notify release users if connecting to git
2636 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");
2637 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2642 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2645 // give users new version
2646 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");
2647 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"));
2651 // notify users about old server version
2652 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");
2653 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2657 self.version_nagtime = 0;
2661 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2663 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2664 self.max_armorvalue = 0;
2668 if (TetrisPreFrame())
2672 MUTATOR_CALLHOOK(PlayerPreThink);
2674 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2676 if(self.BUTTON_USE && !self.usekeypressed)
2678 self.usekeypressed = self.BUTTON_USE;
2681 PrintWelcomeMessage();
2683 if(self.classname == "player") {
2684 // if(self.netname == "Wazat")
2685 // bprint(self.classname, "\n");
2687 CheckRules_Player();
2689 if (intermission_running)
2691 IntermissionThink (); // otherwise a button could be missed between
2692 return; // the think tics
2695 //don't allow the player to turn around while game is paused!
2696 if(timeoutStatus == 2) {
2697 // FIXME turn this into CSQC stuff
2698 self.v_angle = self.lastV_angle;
2699 self.angles = self.lastV_angle;
2700 self.fixangle = TRUE;
2705 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge)
2707 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);
2708 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);
2709 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);
2711 if(self.nex_charge > autocvar_g_balance_nex_charge_animlimit)
2713 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);
2714 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);
2715 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);
2719 self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2725 minstagib_ammocheck();
2727 if (self.deadflag != DEAD_NO)
2729 float button_pressed, force_respawn;
2730 if(self.personal && g_race_qualifying)
2732 if(time > self.death_time)
2734 self.death_time = time + 1; // only retry once a second
2743 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2744 force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
2745 if (self.deadflag == DEAD_DYING)
2748 self.deadflag = DEAD_RESPAWNING;
2749 else if(!button_pressed)
2750 self.deadflag = DEAD_DEAD;
2752 else if (self.deadflag == DEAD_DEAD)
2755 self.deadflag = DEAD_RESPAWNABLE;
2757 else if (self.deadflag == DEAD_RESPAWNABLE)
2760 self.deadflag = DEAD_RESPAWNING;
2762 else if (self.deadflag == DEAD_RESPAWNING)
2764 if(time > self.death_time)
2766 self.death_time = time + 1; // only retry once a second
2770 ShowRespawnCountdown();
2774 // FIXME from now on self.deadflag is always 0 (and self.health is never < 1)
2775 // so (self.deadflag == DEAD_NO) is always true in the code below
2778 if(time > self.touchexplode_time)
2779 if(self.classname == "player")
2780 if(self.deadflag == DEAD_NO)
2781 if not(IS_INDEPENDENT_PLAYER(self))
2782 FOR_EACH_PLAYER(other) if(self != other)
2784 if(time > other.touchexplode_time)
2785 if(other.deadflag == DEAD_NO)
2786 if not(IS_INDEPENDENT_PLAYER(other))
2787 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2789 PlayerTouchExplode(self, other);
2790 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2794 if(g_lms && !self.deadflag && autocvar_g_lms_campcheck_interval)
2798 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2799 dist = self.prevorigin - self.origin;
2801 self.lms_traveled_distance += fabs(vlen(dist));
2803 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime))
2805 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
2806 self.lms_traveled_distance = 0;
2809 if(time > self.lms_nextcheck)
2811 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2812 if(self.lms_traveled_distance < autocvar_g_lms_campcheck_distance)
2814 centerprint(self, autocvar_g_lms_campcheck_message);
2815 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2816 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2817 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');
2819 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval;
2820 self.lms_traveled_distance = 0;
2824 self.prevorigin = self.origin;
2826 if (((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss) && self.animstate_startframe != self.anim_melee_x) // prevent crouching if using melee attack
2831 self.view_ofs = PL_CROUCH_VIEW_OFS;
2832 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2833 // setanim(self, self.anim_duck, FALSE, TRUE, TRUE); // this anim is BROKEN anyway
2840 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2841 if (!trace_startsolid)
2843 self.crouch = FALSE;
2844 self.view_ofs = PL_VIEW_OFS;
2845 setsize (self, PL_MIN, PL_MAX);
2850 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2852 if(self.bloodloss_timer < time)
2854 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2855 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2861 GrapplingHookFrame();
2863 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2866 self.items &~= self.items_added;
2870 self.items_added = 0;
2871 if(self.items & IT_JETPACK)
2872 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2873 self.items_added |= IT_FUEL;
2875 self.items |= self.items_added;
2880 // rot nex charge to the charge limit
2881 if(autocvar_g_balance_nex_charge_rot_rate && self.nex_charge > autocvar_g_balance_nex_charge_limit && self.nex_charge_rottime < time)
2882 self.nex_charge = bound(autocvar_g_balance_nex_charge_limit, self.nex_charge - autocvar_g_balance_nex_charge_rot_rate * frametime / W_TICSPERFRAME, 1);
2891 nexball_setstatus();
2894 secrets_setstatus();
2896 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2898 //self.angles_y=self.v_angle_y + 90; // temp
2899 } else if(gameover) {
2900 if (intermission_running)
2901 IntermissionThink (); // otherwise a button could be missed between
2903 } else if(self.classname == "observer") {
2905 } else if(self.classname == "spectator") {
2910 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));
2912 float oldspectatee_status;
2913 oldspectatee_status = self.spectatee_status;
2914 if(self.classname == "spectator")
2915 self.spectatee_status = num_for_edict(self.enemy);
2916 else if(self.classname == "observer")
2917 self.spectatee_status = num_for_edict(self);
2919 self.spectatee_status = 0;
2920 if(self.spectatee_status != oldspectatee_status)
2922 ClientData_Touch(self);
2924 race_InitSpectator();
2927 if(self.teamkill_soundtime)
2928 if(time > self.teamkill_soundtime)
2930 self.teamkill_soundtime = 0;
2932 entity oldpusher, oldself;
2934 oldself = self; self = self.teamkill_soundsource;
2935 oldpusher = self.pusher; self.pusher = oldself;
2937 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2939 self.pusher = oldpusher;
2943 if(self.taunt_soundtime)
2944 if(time > self.taunt_soundtime)
2946 self.taunt_soundtime = 0;
2947 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2950 target_voicescript_next(self);
2952 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2954 self.clip_load = self.clip_size = 0;
2957 float isInvisibleString(string s)
2960 s = strdecolorize(s);
2961 for((i = 0), (n = strlen(s)); i < n; ++i)
2969 case 192: // charmap space
2970 if (!autocvar_utf8_enable)
2973 case 160: // space in unicode fonts
2974 case 0xE000 + 192: // utf8 charmap space
2975 if (autocvar_utf8_enable)
2988 Called every frame for each client after the physics are run
2991 .float idlekick_lasttimeleft;
2992 .entity showheadshotbbox;
2993 void showheadshotbbox_think()
2995 if(self.owner.showheadshotbbox != self)
3000 self.nextthink = time;
3001 setorigin(self, self.owner.origin);
3002 setsize(self, GetHeadshotMins(self.owner), GetHeadshotMaxs(self.owner));
3004 void PlayerPostThink (void)
3006 // Savage: Check for nameless players
3007 if (isInvisibleString(self.netname)) {
3008 self.netname = "Player";
3009 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));
3012 if(sv_maxidle && frametime)
3014 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
3016 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
3018 if(self.idlekick_lasttimeleft)
3020 Send_CSQC_Centerprint_Generic_Expire(self, CPID_DISCONNECT_IDLING);
3021 self.idlekick_lasttimeleft = 0;
3025 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
3026 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
3028 if(!self.idlekick_lasttimeleft)
3029 Send_CSQC_Centerprint_Generic(self, CPID_DISCONNECT_IDLING, "^3Stop idling!\n^3Disconnecting in %d seconds...", 1, timeleft);
3033 bprint("^3", self.netname, "^3 was kicked for idling.\n");
3034 AnnounceTo(self, "terminated");
3038 else if(timeleft <= 10)
3040 if(timeleft != self.idlekick_lasttimeleft)
3041 AnnounceTo(self, ftos(timeleft));
3042 self.idlekick_lasttimeleft = timeleft;
3047 if(self.impulse == 100)
3049 if (TetrisPostFrame())
3055 //CheckPlayerJump();
3057 if(self.classname == "player") {
3058 CheckRules_Player();
3062 if (intermission_running)
3063 return; // intermission or finale
3065 } else if (self.classname == "observer") {
3067 } else if (self.classname == "spectator") {
3073 for(i = 0; i < 1000; ++i)
3076 end = self.origin + '0 0 1024' + 512 * randomvec();
3077 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
3078 if(trace_fraction < 1)
3079 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
3081 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
3089 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
3091 if(self.waypointsprite_attachedforcarrier)
3092 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent));
3094 if(self.classname == "player" && self.deadflag == DEAD_NO && autocvar_r_showbboxes)
3096 if(!self.showheadshotbbox)
3098 self.showheadshotbbox = spawn();
3099 self.showheadshotbbox.classname = "headshotbbox";
3100 self.showheadshotbbox.owner = self;
3101 self.showheadshotbbox.think = showheadshotbbox_think;
3102 self.showheadshotbbox.nextthink = time;
3103 self = self.showheadshotbbox;
3110 if(self.showheadshotbbox)
3111 if(self.showheadshotbbox && !wasfreed(self.showheadshotbbox))
3112 remove(self.showheadshotbbox);
3117 if((g_cts || g_race) && self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
3119 if(!self.stored_netname)
3120 self.stored_netname = strzone(uid2name(self.crypto_idfp));
3121 if(self.stored_netname != self.netname)
3123 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
3124 strunzone(self.stored_netname);
3125 self.stored_netname = strzone(self.netname);
3131 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));
3134 #ifndef NO_LEGACY_NETWORKING
3135 if(autocvar_sv_use_csqc_players && !self.iscsqcmodel)
3137 CSQCModel_LinkEntity();
3138 self.iscsqcmodel = 1;
3141 if(!autocvar_sv_use_csqc_players && self.iscsqcmodel)
3143 CSQCModel_UnlinkEntity();
3144 self.iscsqcmodel = 0;
3147 if(self.iscsqcmodel)
3148 CSQCModel_CheckUpdate();
3150 CSQCModel_CheckUpdate();