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 float ClientData_Send(entity to, float sf)
20 if(to.classname == "spectator")
26 sf |= 1; // forced scoreboard
27 if(to.spectatee_status)
28 sf |= 2; // spectator ent number follows
31 if(e.porto_v_angle_held)
32 sf |= 8; // angles held
34 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
35 WriteByte(MSG_ENTITY, sf);
38 WriteByte(MSG_ENTITY, to.spectatee_status);
42 WriteAngle(MSG_ENTITY, e.v_angle_x);
43 WriteAngle(MSG_ENTITY, e.v_angle_y);
49 void ClientData_Attach()
51 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
52 self.clientdata.drawonlytoclient = self;
53 self.clientdata.owner = self;
56 void ClientData_Detach()
58 remove(self.clientdata);
59 self.clientdata = world;
62 void ClientData_Touch(entity e)
64 e.clientdata.SendFlags = 1;
66 // make it spectatable
68 FOR_EACH_REALCLIENT(e2)
71 if(e2.classname == "spectator")
73 e2.clientdata.SendFlags = 1;
78 .vector spawnpoint_score;
79 .string netname_previous;
81 void spawnfunc_info_player_survivor (void)
83 spawnfunc_info_player_deathmatch();
86 void spawnfunc_info_player_start (void)
88 spawnfunc_info_player_deathmatch();
91 void spawnfunc_info_player_deathmatch (void)
93 self.classname = "info_player_deathmatch";
94 relocate_spawnpoint();
100 if(have_team_spawns > 0)
102 self.team = activator.team;
103 some_spawn_has_been_used = 1;
108 // _x: prio (-1 if unusable)
110 vector Spawn_Score(entity spot, float mindist, float teamcheck)
112 float shortest, thisdist;
118 // filter out spots for the wrong team
120 if(spot.team != teamcheck)
124 if(spot.target == "")
127 if(clienttype(self) == CLIENTTYPE_REAL)
129 if(spot.restriction == 1)
134 if(spot.restriction == 2)
138 shortest = vlen(world.maxs - world.mins);
139 FOR_EACH_PLAYER(player) if (player != self)
141 thisdist = vlen(player.origin - spot.origin);
142 if (thisdist < shortest)
145 if(shortest > mindist)
146 prio += SPAWN_PRIO_GOOD_DISTANCE;
148 spawn_score = prio * '1 0 0' + shortest * '0 1 0';
151 // filter out spots for assault
152 if(spot.target != "") {
157 for(ent = world; (ent = find(ent, targetname, spot.target)); )
160 if(ent.spawn_evalfunc)
162 entity oldself = self;
164 spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
166 if(spawn_score_x < 0)
173 dprint("WARNING: spawnpoint at ", vtos(spot.origin), " could not find its target ", spot.target, "\n");
178 MUTATOR_CALLHOOK(Spawn_Score);
182 void Spawn_ScoreAll(entity firstspot, float mindist, float teamcheck)
185 for(spot = firstspot; spot; spot = spot.chain)
186 spot.spawnpoint_score = Spawn_Score(spot, mindist, teamcheck);
189 entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
191 entity spot, spotlist, spotlistend;
196 Spawn_ScoreAll(firstspot, mindist, teamcheck);
198 for(spot = firstspot; spot; spot = spot.chain)
200 if(spot.spawnpoint_score_x >= 0) // spawning allowed here
203 spotlistend.chain = spot;
210 spotlistend.chain = world;
215 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
217 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
218 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
221 RandomSelection_Init();
222 for(spot = firstspot; spot; spot = spot.chain)
223 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);
225 return RandomSelection_chosen_ent;
232 Finds a point to respawn
235 entity SelectSpawnPoint (float anypoint)
238 entity spot, firstspot;
240 spot = find (world, classname, "testplayerstart");
244 if(anypoint || autocvar_g_spawn_useallspawns)
246 else if(have_team_spawns > 0)
248 if(have_team_spawns_forteam[self.team] == 0)
250 // we request a spawn for a team, and we have team
251 // spawns, but that team has no spawns?
252 if(have_team_spawns_forteam[0])
256 // if not, any spawn has to do
260 teamcheck = self.team; // MUST be team
262 else if(have_team_spawns == 0 && have_team_spawns_forteam[0])
263 teamcheck = 0; // MUST be noteam
266 // 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
269 // get the entire list of spots
270 firstspot = findchain(classname, "info_player_deathmatch");
271 // filter out the bad ones
272 // (note this returns the original list if none survived)
275 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
280 if (arena_roundbased && !g_ca)
284 firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
286 // there is 50/50 chance of choosing a random spot or the furthest spot
287 // (this means that roughly every other spawn will be furthest, so you
288 // usually won't get fragged at spawn twice in a row)
289 if (random() > autocvar_g_spawn_furthest)
290 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
292 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
297 if(autocvar_spawn_debug)
301 if(some_spawn_has_been_used)
302 return world; // team can't spawn any more, because of actions of other team
304 error("Cannot find a spawn point - please fix the map!");
315 Checks if the argument string can be a valid playermodel.
316 Returns a valid one in doubt.
319 string FallbackPlayerModel;
320 string CheckPlayerModel(string plyermodel) {
321 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
323 // note: we cannot summon Don Strunzone here, some player may
324 // still have the model string set. In case anyone manages how
325 // to change a cvar default, we'll have a small leak here.
326 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
328 // only in right path
329 if( substring(plyermodel,0,14) != "models/player/")
330 return FallbackPlayerModel;
331 // only good file extensions
332 if(substring(plyermodel,-4,4) != ".zym")
333 if(substring(plyermodel,-4,4) != ".dpm")
334 if(substring(plyermodel,-4,4) != ".iqm")
335 if(substring(plyermodel,-4,4) != ".md3")
336 if(substring(plyermodel,-4,4) != ".psk")
337 return FallbackPlayerModel;
338 // forbid the LOD models
339 if(substring(plyermodel, -9,5) == "_lod1")
340 return FallbackPlayerModel;
341 if(substring(plyermodel, -9,5) == "_lod2")
342 return FallbackPlayerModel;
343 if(plyermodel != strtolower(plyermodel))
344 return FallbackPlayerModel;
345 // also, restrict to server models
346 if(autocvar_sv_servermodelsonly)
348 if(!fexists(plyermodel))
349 return FallbackPlayerModel;
354 void setplayermodel(entity e, string modelname)
356 precache_model(modelname);
357 setmodel(e, modelname);
358 player_setupanimsformodel();
359 UpdatePlayerSounds();
366 putting a client as observer in the server
369 void FixPlayermodel();
370 void PutObserverInServer (void)
373 self.hud = HUD_NORMAL;
374 race_PreSpawnObserver();
376 spot = SelectSpawnPoint (TRUE);
378 error("No spawnpoints for observers?!?\n");
379 RemoveGrapplingHook(self); // Wazat's Grappling Hook
381 if(clienttype(self) == CLIENTTYPE_REAL)
384 WriteByte(MSG_ONE, SVC_SETVIEW);
385 WriteEntity(MSG_ONE, self);
388 MUTATOR_CALLHOOK(MakePlayerObserver);
390 Portal_ClearAll(self);
395 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
400 vehicles_exit(VHEF_RELESE);
402 WaypointSprite_PlayerDead();
404 if not(g_ca) // don't reset teams when moving a ca player to the spectators
405 self.team = -1; // move this as it is needed to log the player spectating in eventlog
407 if(self.killcount != -666) {
409 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0 && self.lms_spectate_warning != 2)
410 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_NOLIVES, self.netname);
412 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_LMS_FORFEIT, self.netname);
413 } else { Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, self.netname); }
415 if(self.just_joined == FALSE) {
416 LogTeamchange(self.playerid, -1, 4);
418 self.just_joined = FALSE;
421 PlayerScore_Clear(self); // clear scores when needed
423 accuracy_resend(self);
425 self.spectatortime = time;
427 self.classname = "observer";
428 self.iscreature = FALSE;
429 self.teleportable = TELEPORT_SIMPLE;
430 self.damagedbycontents = FALSE;
432 self.takedamage = DAMAGE_NO;
433 self.solid = SOLID_NOT;
434 self.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
435 self.flags = FL_CLIENT | FL_NOTARGET;
436 self.armorvalue = 666;
438 self.armorvalue = autocvar_g_balance_armor_start;
439 self.pauserotarmor_finished = 0;
440 self.pauserothealth_finished = 0;
441 self.pauseregen_finished = 0;
442 self.damageforcescale = 0;
444 self.respawn_time = 0;
449 self.pain_finished = 0;
450 self.strength_finished = 0;
451 self.invincible_finished = 0;
452 self.superweapons_finished = 0;
455 self.think = func_null;
458 self.deadflag = DEAD_NO;
459 self.angles = spot.angles;
461 self.fixangle = TRUE;
464 setorigin (self, (spot.origin + PL_VIEW_OFS)); // offset it so that the spectator spawns higher off the ground, looks better this way
465 self.prevorigin = self.origin;
467 WEPSET_CLEAR_E(self);
470 setmodel(self, "null");
471 self.drawonlytoclient = self;
473 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
474 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
477 self.weaponname = "";
478 self.switchingweapon = 0;
479 self.weaponmodel = "";
480 self.weaponentity = world;
481 self.exteriorweaponentity = world;
482 self.killcount = -666;
483 self.velocity = '0 0 0';
484 self.avelocity = '0 0 0';
485 self.punchangle = '0 0 0';
486 self.punchvector = '0 0 0';
487 self.oldvelocity = self.velocity;
488 self.fire_endtime = -1;
492 if(self.version_mismatch)
494 self.frags = FRAGS_SPECTATOR;
495 Spawnqueue_Unmark(self);
496 Spawnqueue_Remove(self);
500 self.frags = FRAGS_LMS_LOSER;
501 Spawnqueue_Insert(self);
506 // Only if the player cannot play at all
507 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
508 self.frags = FRAGS_SPECTATOR;
510 self.frags = FRAGS_LMS_LOSER;
515 self.frags = FRAGS_LMS_LOSER;
517 self.frags = FRAGS_SPECTATOR;
519 else if((g_race && g_race_qualifying) || g_cts)
521 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
522 self.frags = FRAGS_LMS_LOSER;
524 self.frags = FRAGS_SPECTATOR;
527 self.frags = FRAGS_SPECTATOR;
530 .float model_randomizer;
531 void FixPlayermodel()
534 float defaultskin, chmdl, oldskin, n, i;
541 if(autocvar_sv_defaultcharacter == 1)
546 s = Team_ColorName_Lower(self.team);
549 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
550 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
554 if(defaultmodel == "")
556 defaultmodel = autocvar_sv_defaultplayermodel;
557 defaultskin = autocvar_sv_defaultplayerskin;
560 n = tokenize_console(defaultmodel);
562 defaultmodel = argv(floor(n * self.model_randomizer));
564 i = strstrofs(defaultmodel, ":", 0);
567 defaultskin = stof(substring(defaultmodel, i+1, -1));
568 defaultmodel = substring(defaultmodel, 0, i);
572 if(defaultmodel != "")
574 if (defaultmodel != self.model)
578 setplayermodel (self, defaultmodel);
579 setsize (self, m1, m2);
584 self.skin = defaultskin;
586 if (self.playermodel != self.model || self.playermodel == "")
588 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
591 setplayermodel (self, self.playermodel);
592 setsize (self, m1, m2);
597 self.skin = stof(self.playerskin);
600 if(chmdl || oldskin != self.skin) // model or skin has changed
602 self.species = player_getspecies(); // update species
603 UpdatePlayerSounds(); // update skin sounds
607 if(strlen(autocvar_sv_defaultplayercolors))
608 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
609 setcolor(self, stof(autocvar_sv_defaultplayercolors));
612 void PlayerTouchExplode(entity p1, entity p2)
615 org = (p1.origin + p2.origin) * 0.5;
616 org_z += (p1.mins_z + p2.mins_z) * 0.5;
623 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
631 Called when a client spawns in the server
635 void PutClientInServer (void)
637 if(clienttype(self) == CLIENTTYPE_BOT)
639 self.classname = "player";
643 else if(clienttype(self) == CLIENTTYPE_REAL)
646 WriteByte(MSG_ONE, SVC_SETVIEW);
647 WriteEntity(MSG_ONE, self);
653 // player is dead and becomes observer
654 // FIXME fix LMS scoring for new system
657 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
658 self.classname = "observer";
661 if((g_arena && !self.spawned) || (g_ca && !allowed_to_spawn))
662 self.classname = "observer";
665 self.classname = "observer";
667 if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {
668 entity spot, oldself;
671 accuracy_resend(self);
674 JoinBestTeam(self, FALSE, TRUE);
678 spot = SelectSpawnPoint (FALSE);
681 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
682 return; // spawn failed
685 RemoveGrapplingHook(self); // Wazat's Grappling Hook
687 self.classname = "player";
688 self.wasplayer = TRUE;
689 self.iscreature = TRUE;
690 self.teleportable = TELEPORT_NORMAL;
691 self.damagedbycontents = TRUE;
692 self.movetype = MOVETYPE_WALK;
693 self.solid = SOLID_SLIDEBOX;
694 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
695 if(autocvar_g_playerclip_collisions)
696 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
697 if(clienttype(self) == CLIENTTYPE_BOT && autocvar_g_botclip_collisions)
698 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
699 self.frags = FRAGS_PLAYER;
700 if(INDEPENDENT_PLAYERS)
701 MAKE_INDEPENDENT_PLAYER(self);
702 self.flags = FL_CLIENT;
703 if(autocvar__notarget)
704 self.flags |= FL_NOTARGET;
705 self.takedamage = DAMAGE_AIM;
707 self.effects |= EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
708 self.air_finished = time + 12;
710 if(autocvar_g_balance_nex_charge)
712 if(autocvar_g_balance_nex_secondary_chargepool)
713 self.nex_chargepool_ammo = 1;
714 self.nex_charge = autocvar_g_balance_nex_charge_start;
719 self.ammo_shells = warmup_start_ammo_shells;
720 self.ammo_nails = warmup_start_ammo_nails;
721 self.ammo_rockets = warmup_start_ammo_rockets;
722 self.ammo_cells = warmup_start_ammo_cells;
723 self.ammo_fuel = warmup_start_ammo_fuel;
724 self.health = warmup_start_health;
725 self.armorvalue = warmup_start_armorvalue;
726 WEPSET_COPY_EA(self, warmup_start_weapons);
730 self.ammo_shells = start_ammo_shells;
731 self.ammo_nails = start_ammo_nails;
732 self.ammo_rockets = start_ammo_rockets;
733 self.ammo_cells = start_ammo_cells;
734 self.ammo_fuel = start_ammo_fuel;
735 self.health = start_health;
736 self.armorvalue = start_armorvalue;
737 WEPSET_COPY_EA(self, start_weapons);
740 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // exception for minstagib, as minstanex is a superweapon
741 self.superweapons_finished = time + autocvar_g_balance_superweapons_time;
743 self.superweapons_finished = 0;
745 if(g_weaponarena_random)
747 if(g_weaponarena_random_with_laser)
748 WEPSET_ANDNOT_EW(self, WEP_LASER);
749 W_RandomWeapons(self, g_weaponarena_random);
750 if(g_weaponarena_random_with_laser)
751 WEPSET_OR_EW(self, WEP_LASER);
754 self.items = start_items;
756 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
757 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
758 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
759 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
760 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
761 //extend the pause of rotting if client was reset at the beginning of the countdown
762 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
763 self.spawnshieldtime += game_starttime - time;
764 self.pauserotarmor_finished += game_starttime - time;
765 self.pauserothealth_finished += game_starttime - time;
766 self.pauseregen_finished += game_starttime - time;
768 self.damageforcescale = 2;
770 self.respawn_time = 0;
774 self.pain_finished = 0;
775 self.strength_finished = 0;
776 self.invincible_finished = 0;
778 // players have no think function
779 self.think = func_null;
783 self.ballistics_density = autocvar_g_ballistics_density_player;
787 self.deadflag = DEAD_NO;
789 self.angles = spot.angles;
791 self.angles_z = 0; // never spawn tilted even if the spot says to
792 self.fixangle = TRUE; // turn this way immediately
793 self.velocity = '0 0 0';
794 self.avelocity = '0 0 0';
795 self.punchangle = '0 0 0';
796 self.punchvector = '0 0 0';
797 self.oldvelocity = self.velocity;
798 self.fire_endtime = -1;
801 WRITESPECTATABLE_MSG_ONE({
802 WriteByte(MSG_ONE, SVC_TEMPENTITY);
803 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
808 self.drawonlytoclient = world;
811 self.view_ofs = PL_VIEW_OFS;
812 setsize (self, PL_MIN, PL_MAX);
813 self.spawnorigin = spot.origin;
814 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
815 // don't reset back to last position, even if new position is stuck in solid
816 self.oldorigin = self.origin;
817 self.prevorigin = self.origin;
818 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
819 self.lastteleporttime = time; // prevent insane speeds due to changing origin
820 self.hud = HUD_NORMAL;
824 Spawnqueue_Remove(self);
825 Spawnqueue_Mark(self);
830 self.event_damage = PlayerDamage;
832 self.bot_attack = TRUE;
834 self.statdraintime = time + 5;
835 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
837 if(self.killcount == -666) {
838 PlayerScore_Clear(self);
842 CL_SpawnWeaponentity();
843 self.alpha = default_player_alpha;
844 self.colormod = '1 1 1' * autocvar_g_player_brightness;
845 self.exteriorweaponentity.alpha = default_weapon_alpha;
847 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
848 self.lms_traveled_distance = 0;
849 self.speedrunning = FALSE;
851 race_PostSpawn(spot);
853 //stuffcmd(self, "chase_active 0");
854 //stuffcmd(self, "set viewsize $tmpviewsize \n");
857 if(self.team == assault_attacker_team)
858 Send_Notification(NOTIF_TEAM, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
860 Send_Notification(NOTIF_TEAM, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
863 target_voicescript_clear(self);
865 // reset fields the weapons may use
866 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
868 weapon_action(j, WR_RESETPLAYER);
870 // all weapons must be fully loaded when we spawn
872 e = get_weaponinfo(j);
873 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
874 self.(weapon_load[j]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
882 self.target = string_null;
889 MUTATOR_CALLHOOK(PlayerSpawn);
891 if(autocvar_spawn_debug)
893 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
894 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
897 self.switchweapon = w_getbestweapon(self);
898 self.cnt = -1; // W_LastWeapon will not complain
900 self.weaponname = "";
901 self.switchingweapon = 0;
905 self.alivetime = time;
909 if (autocvar_g_spawnsound)
910 soundat(world, self.origin, CH_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
911 } else if(self.classname == "observer") {
912 PutObserverInServer ();
916 .float ebouncefactor, ebouncestop; // electro's values
917 // TODO do we need all these fields, or should we stop autodetecting runtime
918 // changes and just have a console command to update this?
919 float ClientInit_SendEntity(entity to, float sf)
921 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
922 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
923 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
924 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
925 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
926 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
927 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[0]));
928 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[1]));
929 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[2]));
930 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[3]));
931 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[0]));
932 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[1]));
933 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[2]));
934 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[3]));
935 if(sv_foginterval && world.fog != "")
936 WriteString(MSG_ENTITY, world.fog);
938 WriteString(MSG_ENTITY, "");
939 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
940 WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
941 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_bouncefactor
942 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_bouncestop
943 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
944 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
945 WriteByte(MSG_ENTITY, autocvar_g_balance_nex_secondary); // client has to know if it should zoom or not
946 WriteByte(MSG_ENTITY, autocvar_g_balance_rifle_secondary); // client has to know if it should zoom or not
947 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
948 WriteByte(MSG_ENTITY, autocvar_g_balance_minelayer_limit); // minelayer max mines
949 WriteByte(MSG_ENTITY, autocvar_g_balance_hagar_secondary_load_max); // hagar max loadable rockets
950 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
951 WriteByte(MSG_ENTITY, autocvar_g_balance_porto_secondary);
955 void ClientInit_CheckUpdate()
957 self.nextthink = time;
958 if(self.count != autocvar_g_balance_armor_blockpercent)
960 self.count = autocvar_g_balance_armor_blockpercent;
963 if(self.cnt != autocvar_g_balance_weaponswitchdelay)
965 self.cnt = autocvar_g_balance_weaponswitchdelay;
968 if(self.bouncefactor != autocvar_g_balance_grenadelauncher_bouncefactor)
970 self.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
973 if(self.bouncestop != autocvar_g_balance_grenadelauncher_bouncestop)
975 self.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
978 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
980 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
983 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
985 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
990 void ClientInit_Spawn()
995 e.classname = "clientinit";
996 e.think = ClientInit_CheckUpdate;
997 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
1001 ClientInit_CheckUpdate();
1010 void SetNewParms (void)
1012 // initialize parms for a new player
1013 parm1 = -(86400 * 366);
1021 void SetChangeParms (void)
1023 // save parms for level change
1024 parm1 = self.parm_idlesince - time;
1032 void DecodeLevelParms (void)
1035 self.parm_idlesince = parm1;
1036 if(self.parm_idlesince == -(86400 * 366))
1037 self.parm_idlesince = time;
1039 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1040 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1047 Called when a client types 'kill' in the console
1051 .float clientkill_nexttime;
1052 void ClientKill_Now_TeamChange()
1054 if(self.killindicator_teamchange == -1)
1056 JoinBestTeam( self, FALSE, TRUE );
1058 else if(self.killindicator_teamchange == -2)
1063 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1064 PutObserverInServer();
1067 SV_ChangeTeam(self.killindicator_teamchange - 1);
1070 void ClientKill_Now()
1074 vehicles_exit(VHEF_RELESE);
1075 if(!self.killindicator_teamchange)
1077 self.vehicle_health = -1;
1078 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
1082 if(self.killindicator && !wasfreed(self.killindicator))
1083 remove(self.killindicator);
1085 self.killindicator = world;
1087 if(self.killindicator_teamchange)
1088 ClientKill_Now_TeamChange();
1091 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1093 // now I am sure the player IS dead
1095 void KillIndicator_Think()
1099 self.owner.killindicator = world;
1104 if (self.owner.alpha < 0 && !self.owner.vehicle)
1106 self.owner.killindicator = world;
1114 ClientKill_Now(); // no oldself needed
1117 else if(g_cts && self.health == 1) // health == 1 means that it's silent
1119 self.nextthink = time + 1;
1125 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1126 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1129 { Send_Notification(NOTIF_ONE, self.owner, MSG_ANNCE, Announcer_PickNumber(self.cnt)); }
1131 self.nextthink = time + 1;
1136 float clientkilltime;
1137 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
1146 killtime = autocvar_g_balance_kill_delay;
1148 if(g_race_qualifying || g_cts)
1151 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
1153 remove(self.killindicator);
1154 self.killindicator = world;
1156 ClientKill_Now(); // allow instant kill in this case
1160 self.killindicator_teamchange = targetteam;
1162 if(!self.killindicator)
1164 if(self.deadflag == DEAD_NO)
1166 killtime = max(killtime, self.clientkill_nexttime - time);
1167 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
1170 if(killtime <= 0 || self.classname != "player" || self.deadflag != DEAD_NO)
1176 starttime = max(time, clientkilltime);
1178 self.killindicator = spawn();
1179 self.killindicator.owner = self;
1180 self.killindicator.scale = 0.5;
1181 setattachment(self.killindicator, self, "");
1182 setorigin(self.killindicator, '0 0 52');
1183 self.killindicator.think = KillIndicator_Think;
1184 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
1185 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
1186 self.killindicator.cnt = ceil(killtime);
1187 self.killindicator.count = bound(0, ceil(killtime), 10);
1188 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1190 for(e = world; (e = find(e, classname, "body")) != world; )
1194 e.killindicator = spawn();
1195 e.killindicator.owner = e;
1196 e.killindicator.scale = 0.5;
1197 setattachment(e.killindicator, e, "");
1198 setorigin(e.killindicator, '0 0 52');
1199 e.killindicator.think = KillIndicator_Think;
1200 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
1201 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
1202 e.killindicator.cnt = ceil(killtime);
1207 if(self.killindicator)
1209 if(targetteam == 0) // just die
1211 self.killindicator.colormod = '0 0 0';
1212 if(clienttype(self) == CLIENTTYPE_REAL)
1213 if(self.killindicator.cnt > 0)
1214 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, self.killindicator.cnt);
1216 else if(targetteam == -1) // auto
1218 self.killindicator.colormod = '0 1 0';
1219 if(clienttype(self) == CLIENTTYPE_REAL)
1220 if(self.killindicator.cnt > 0)
1221 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, self.killindicator.cnt);
1223 else if(targetteam == -2) // spectate
1225 self.killindicator.colormod = '0.5 0.5 0.5';
1226 if(clienttype(self) == CLIENTTYPE_REAL)
1227 if(self.killindicator.cnt > 0)
1228 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, self.killindicator.cnt);
1232 self.killindicator.colormod = Team_ColorRGB(targetteam);
1233 if(clienttype(self) == CLIENTTYPE_REAL)
1234 if(self.killindicator.cnt > 0)
1235 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, APP_TEAM_NUM_4(targetteam, CENTER_TEAMCHANGE_), self.killindicator.cnt);
1241 void ClientKill (void)
1246 if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either
1250 else if(self.freezetag_frozen)
1255 ClientKill_TeamChange(0);
1258 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
1260 e.killindicator = spawn();
1261 e.killindicator.owner = e;
1262 e.killindicator.think = KillIndicator_Think;
1263 e.killindicator.nextthink = time + (e.lip) * 0.05;
1264 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
1265 e.killindicator.health = 1; // this is used to indicate that it should be silent
1269 void FixClientCvars(entity e)
1271 // send prediction settings to the client
1272 stuffcmd(e, "\nin_bindmap 0 0\n");
1274 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1275 if(autocvar_g_antilag == 3) // client side hitscan
1276 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1277 if(autocvar_sv_gentle)
1278 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1280 * we no longer need to stuff this. Remove this comment block if you feel
1281 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1282 stuffcmd(e, strcat("cl_gravity ", ftos(autocvar_sv_gravity), "\n"));
1283 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(autocvar_sv_accelerate), "\n"));
1284 stuffcmd(e, strcat("cl_movement_friction ", ftos(autocvar_sv_friction), "\n"));
1285 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(autocvar_sv_maxspeed), "\n"));
1286 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(autocvar_sv_airaccelerate), "\n"));
1287 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(autocvar_sv_maxairspeed), "\n"));
1288 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(autocvar_sv_stopspeed), "\n"));
1289 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(autocvar_sv_jumpvelocity), "\n"));
1290 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(autocvar_sv_stepheight), "\n"));
1291 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(autocvar_sv_friction_on_land), "\n"));
1292 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(autocvar_sv_airaccel_qw), "\n"));
1293 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(autocvar_sv_airaccel_sideways_friction), "\n"));
1294 stuffcmd(e, "cl_movement_edgefriction 1\n");
1298 float PlayerInIDList(entity p, string idlist)
1303 // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
1304 if not(p.crypto_idfp)
1307 // this function allows abbreviated player IDs too!
1308 n = tokenize_console(idlist);
1309 for(i = 0; i < n; ++i)
1312 if(s == substring(p.crypto_idfp, 0, strlen(s)))
1323 Called when a client connects to the server
1326 void DecodeLevelParms (void);
1327 //void dom_player_join_team(entity pl);
1328 void set_dom_state(entity e);
1329 void ClientConnect (void)
1333 if(self.flags & FL_CLIENT)
1335 print("Warning: ClientConnect, but already connected!\n");
1339 if(Ban_MaybeEnforceBanOnce(self))
1345 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_WATERMARK, WATERMARK);
1348 self.classname = "player_joining";
1350 self.flags = FL_CLIENT;
1351 self.version_nagtime = time + 10 + random() * 10;
1355 dprint("BUG player count is lower than zero, this cannot happen!\n");
1359 PlayerScore_Attach(self);
1360 ClientData_Attach();
1361 accuracy_init(self);
1363 bot_clientconnect();
1369 race_PreSpawnObserver();
1371 // identify the right forced team
1372 if(autocvar_g_campaign)
1374 if(clienttype(self) == CLIENTTYPE_REAL) // only players, not bots
1376 switch(autocvar_g_campaign_forceteam)
1378 case 1: self.team_forced = NUM_TEAM_1; break;
1379 case 2: self.team_forced = NUM_TEAM_2; break;
1380 case 3: self.team_forced = NUM_TEAM_3; break;
1381 case 4: self.team_forced = NUM_TEAM_4; break;
1382 default: self.team_forced = 0;
1386 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1387 self.team_forced = NUM_TEAM_1;
1388 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1389 self.team_forced = NUM_TEAM_2;
1390 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1391 self.team_forced = NUM_TEAM_3;
1392 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1393 self.team_forced = NUM_TEAM_4;
1394 else if(autocvar_g_forced_team_otherwise == "red")
1395 self.team_forced = NUM_TEAM_1;
1396 else if(autocvar_g_forced_team_otherwise == "blue")
1397 self.team_forced = NUM_TEAM_2;
1398 else if(autocvar_g_forced_team_otherwise == "yellow")
1399 self.team_forced = NUM_TEAM_3;
1400 else if(autocvar_g_forced_team_otherwise == "pink")
1401 self.team_forced = NUM_TEAM_4;
1402 else if(autocvar_g_forced_team_otherwise == "spectate")
1403 self.team_forced = -1;
1404 else if(autocvar_g_forced_team_otherwise == "spectator")
1405 self.team_forced = -1;
1407 self.team_forced = 0;
1410 if(self.team_forced > 0)
1411 self.team_forced = 0;
1413 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1415 if((autocvar_sv_spectate == 1 && !g_lms) || autocvar_g_campaign || self.team_forced < 0) {
1416 self.classname = "observer";
1420 if(autocvar_g_balance_teams)
1422 self.classname = "player";
1423 campaign_bots_may_start = 1;
1427 self.classname = "observer"; // do it anyway
1432 self.classname = "player";
1433 campaign_bots_may_start = 1;
1437 self.playerid = (playerid_last = playerid_last + 1);
1439 PlayerStats_AddEvent(sprintf("kills-%d", self.playerid));
1441 if(clienttype(self) == CLIENTTYPE_BOT)
1442 PlayerStats_AddPlayer(self);
1444 if(autocvar_sv_eventlog)
1445 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
1447 LogTeamchange(self.playerid, self.team, 1);
1449 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1451 self.netname_previous = strzone(self.netname);
1453 if((self.classname == STR_PLAYER && teamplay))
1454 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(self, INFO_JOIN_CONNECT_TEAM_), self.netname);
1456 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_CONNECT, self.netname);
1458 stuffcmd(self, strcat(clientstuff, "\n"));
1459 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1461 FixClientCvars(self);
1463 // spawnfunc_waypoint sprites
1464 WaypointSprite_InitClient(self);
1466 // Wazat's grappling hook
1467 SetGrappleHookBindings();
1469 // get version info from player
1470 stuffcmd(self, "cmd clientversion $gameversion\n");
1472 // get other cvars from player
1475 // notify about available teams
1478 CheckAllowedTeams(self);
1479 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1480 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1483 stuffcmd(self, "set _teams_available 0\n");
1487 self.classname = "observer";
1489 Spawnqueue_Insert(self);
1494 bot_relinkplayerlist();
1496 self.spectatortime = time;
1499 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1502 self.jointime = time;
1503 self.allowed_timeouts = autocvar_sv_timeout_number;
1505 if(clienttype(self) == CLIENTTYPE_REAL)
1507 if(!autocvar_g_campaign)
1509 self.motd_actived_time = -1;
1510 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1513 if(autocvar_g_bugrigs || WEPSET_EQ_AW(g_weaponarena_weapons, WEP_TUBA))
1514 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1519 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1521 PlayerScore_Add(self, SP_LMS_RANK, 666);
1522 self.frags = FRAGS_SPECTATOR;
1526 if(!sv_foginterval && world.fog != "")
1527 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1529 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", self.netaddress, " "), 0) >= 0)
1531 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1532 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1535 self.hitplotfh = -1;
1537 if(g_race || g_cts) {
1545 race_send_recordtime(MSG_ONE);
1546 race_send_speedaward(MSG_ONE);
1548 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
1549 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
1550 race_send_speedaward_alltimebest(MSG_ONE);
1553 for (i = 1; i <= RANKINGS_CNT; ++i) {
1554 race_SendRankings(i, 0, 0, MSG_ONE);
1557 else if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
1558 send_CSQC_teamnagger();
1562 CSQCMODEL_AUTOINIT();
1564 self.model_randomizer = random();
1566 if(clienttype(self) != CLIENTTYPE_REAL)
1571 MUTATOR_CALLHOOK(ClientConnect);
1577 Called when a client disconnects from the server
1580 .entity chatbubbleentity;
1582 void ClientDisconnect (void)
1585 vehicles_exit(VHEF_RELESE);
1587 if not(self.flags & FL_CLIENT)
1589 print("Warning: ClientDisconnect without ClientConnect\n");
1593 PlayerStats_AddGlobalInfo(self);
1595 CheatShutdownClient();
1597 if(self.hitplotfh >= 0)
1599 fclose(self.hitplotfh);
1600 self.hitplotfh = -1;
1604 anticheat_shutdown();
1606 playerdemo_shutdown();
1608 bot_clientdisconnect();
1613 if(autocvar_sv_eventlog)
1614 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1616 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, self.netname);
1618 MUTATOR_CALLHOOK(ClientDisconnect);
1620 Portal_ClearAll(self);
1622 RemoveGrapplingHook(self);
1624 // Here, everything has been done that requires this player to be a client.
1626 self.flags &~= FL_CLIENT;
1628 if (self.chatbubbleentity)
1629 remove (self.chatbubbleentity);
1631 if (self.killindicator)
1632 remove (self.killindicator);
1634 WaypointSprite_PlayerGone();
1636 bot_relinkplayerlist();
1640 Spawnqueue_Unmark(self);
1641 Spawnqueue_Remove(self);
1644 accuracy_free(self);
1645 ClientData_Detach();
1646 PlayerScore_Detach(self);
1648 if(self.netname_previous)
1649 strunzone(self.netname_previous);
1650 if(self.clientstatus)
1651 strunzone(self.clientstatus);
1652 if(self.weaponorder_byimpulse)
1653 strunzone(self.weaponorder_byimpulse);
1655 ClearPlayerSounds();
1658 remove(self.personal);
1668 void ChatBubbleThink()
1670 self.nextthink = time;
1671 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1673 if(self.owner) // but why can that ever be world?
1674 self.owner.chatbubbleentity = world;
1678 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1680 || self.owner.tetris_on
1683 self.model = self.mdl;
1688 void UpdateChatBubble()
1692 // spawn a chatbubble entity if needed
1693 if (!self.chatbubbleentity)
1695 self.chatbubbleentity = spawn();
1696 self.chatbubbleentity.owner = self;
1697 self.chatbubbleentity.exteriormodeltoclient = self;
1698 self.chatbubbleentity.think = ChatBubbleThink;
1699 self.chatbubbleentity.nextthink = time;
1700 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1701 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1702 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1703 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1704 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1705 self.chatbubbleentity.model = "";
1706 self.chatbubbleentity.effects = EF_LOWPRECISION;
1711 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1712 // added to the model skins
1713 /*void UpdateColorModHack()
1716 c = self.clientcolors & 15;
1717 // LordHavoc: only bothering to support white, green, red, yellow, blue
1718 if (!teamplay) self.colormod = '0 0 0';
1719 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1720 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1721 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1722 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1723 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1724 else self.colormod = '1 1 1';
1729 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1731 self.solid = SOLID_NOT;
1732 self.takedamage = DAMAGE_NO;
1733 self.movetype = MOVETYPE_FLY;
1734 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1735 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1736 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1737 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1738 if(autocvar_g_respawn_ghosts_maxtime)
1739 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1744 self.effects |= EF_NODRAW; // prevent another CopyBody
1745 PutClientInServer();
1748 void play_countdown(float finished, string samp)
1750 if(clienttype(self) == CLIENTTYPE_REAL)
1751 if(floor(finished - time - frametime) != floor(finished - time))
1752 if(finished - time < 6)
1753 sound (self, CH_INFO, samp, VOL_BASE, ATTN_NORM);
1756 void player_powerups (void)
1758 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1759 olditems = self.items;
1761 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1762 self.modelflags |= MF_ROCKET;
1764 self.modelflags &~= MF_ROCKET;
1766 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1768 if(self.alpha < 0 || self.deadflag) // don't apply the flags if the player is gibbed
1771 Fire_ApplyDamage(self);
1772 Fire_ApplyEffect(self);
1776 if (self.items & IT_STRENGTH)
1778 play_countdown(self.strength_finished, "misc/poweroff.wav");
1779 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1780 if (time > self.strength_finished)
1782 self.items = self.items - (self.items & IT_STRENGTH);
1783 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, self.netname);
1784 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1789 if (time < self.strength_finished)
1791 self.items = self.items | IT_STRENGTH;
1792 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, self.netname);
1793 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1796 if (self.items & IT_INVINCIBLE)
1798 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1799 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1800 if (time > self.invincible_finished)
1802 self.items = self.items - (self.items & IT_INVINCIBLE);
1803 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, self.netname);
1804 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1809 if (time < self.invincible_finished)
1811 self.items = self.items | IT_INVINCIBLE;
1812 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, self.netname);
1813 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SHIELD);
1816 if (self.items & IT_SUPERWEAPON)
1818 if (!WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
1820 self.superweapons_finished = 0;
1821 self.items = self.items - (self.items & IT_SUPERWEAPON);
1822 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, self.netname);
1823 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1825 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1827 // don't let them run out
1831 play_countdown(self.superweapons_finished, "misc/poweroff.wav");
1832 if (time > self.superweapons_finished)
1834 self.items = self.items - (self.items & IT_SUPERWEAPON);
1835 WEPSET_ANDNOT_EA(self, WEPBIT_SUPERWEAPONS);
1836 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, self.netname);
1837 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1841 else if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
1843 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1845 self.items = self.items | IT_SUPERWEAPON;
1846 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, self.netname);
1847 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1851 self.superweapons_finished = 0;
1852 WEPSET_ANDNOT_EA(self, WEPBIT_SUPERWEAPONS);
1857 self.superweapons_finished = 0;
1861 if(autocvar_g_nodepthtestplayers)
1862 self.effects = self.effects | EF_NODEPTHTEST;
1864 if(autocvar_g_fullbrightplayers)
1865 self.effects = self.effects | EF_FULLBRIGHT;
1867 // midair gamemode: damage only while in the air
1868 // if in midair mode, being on ground grants temporary invulnerability
1869 // (this is so that multishot weapon don't clear the ground flag on the
1870 // first damage in the frame, leaving the player vulnerable to the
1871 // remaining hits in the same frame)
1872 if (self.flags & FL_ONGROUND)
1874 self.spawnshieldtime = max(self.spawnshieldtime, time + autocvar_g_midair_shieldtime);
1876 if (time >= game_starttime)
1877 if (time < self.spawnshieldtime)
1878 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1880 MUTATOR_CALLHOOK(PlayerPowerups);
1883 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1885 if(current > stable)
1887 else if(current > stable - 0.25) // when close enough, "snap"
1890 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1893 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1895 if(current < stable)
1897 else if(current < stable + 0.25) // when close enough, "snap"
1900 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1903 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1905 if(current > rotstable)
1907 if(rotframetime > 0)
1909 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1910 current = max(rotstable, current - rotlinear * rotframetime);
1913 else if(current < regenstable)
1915 if(regenframetime > 0)
1917 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1918 current = min(regenstable, current + regenlinear * regenframetime);
1928 void player_regen (void)
1930 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1931 maxh = autocvar_g_balance_health_rotstable;
1932 maxa = autocvar_g_balance_armor_rotstable;
1933 maxf = autocvar_g_balance_fuel_rotstable;
1934 minh = autocvar_g_balance_health_regenstable;
1935 mina = autocvar_g_balance_armor_regenstable;
1936 minf = autocvar_g_balance_fuel_regenstable;
1937 limith = autocvar_g_balance_health_limit;
1938 limita = autocvar_g_balance_armor_limit;
1939 limitf = autocvar_g_balance_fuel_limit;
1941 max_mod = regen_mod = rot_mod = limit_mod = 1;
1943 maxh = maxh * max_mod;
1944 //maxa = maxa * max_mod;
1945 //maxf = maxf * max_mod;
1946 minh = minh * max_mod;
1947 //mina = mina * max_mod;
1948 //minf = minf * max_mod;
1949 limith = limith * limit_mod;
1950 limita = limita * limit_mod;
1951 //limitf = limitf * limit_mod;
1956 if (!g_minstagib && !g_ca && (!g_lms || autocvar_g_lms_regenerate))
1958 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);
1959 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);
1961 // if player rotted to death... die!
1963 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1966 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1967 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);
1970 float zoomstate_set;
1971 void SetZoomState(float z)
1973 if(z != self.zoomstate)
1976 ClientData_Touch(self);
1981 void GetPressedKeys(void) {
1982 MUTATOR_CALLHOOK(GetPressedKeys);
1983 if (self.movement_x > 0) // get if movement keys are pressed
1984 { // forward key pressed
1985 self.pressedkeys |= KEY_FORWARD;
1986 self.pressedkeys &~= KEY_BACKWARD;
1988 else if (self.movement_x < 0)
1989 { // backward key pressed
1990 self.pressedkeys |= KEY_BACKWARD;
1991 self.pressedkeys &~= KEY_FORWARD;
1995 self.pressedkeys &~= KEY_FORWARD;
1996 self.pressedkeys &~= KEY_BACKWARD;
1999 if (self.movement_y > 0)
2000 { // right key pressed
2001 self.pressedkeys |= KEY_RIGHT;
2002 self.pressedkeys &~= KEY_LEFT;
2004 else if (self.movement_y < 0)
2005 { // left key pressed
2006 self.pressedkeys |= KEY_LEFT;
2007 self.pressedkeys &~= KEY_RIGHT;
2011 self.pressedkeys &~= KEY_RIGHT;
2012 self.pressedkeys &~= KEY_LEFT;
2015 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
2016 self.pressedkeys |= KEY_JUMP;
2018 self.pressedkeys &~= KEY_JUMP;
2019 if (self.BUTTON_CROUCH)
2020 self.pressedkeys |= KEY_CROUCH;
2022 self.pressedkeys &~= KEY_CROUCH;
2024 if (self.BUTTON_ATCK)
2025 self.pressedkeys |= KEY_ATCK;
2027 self.pressedkeys &~= KEY_ATCK;
2028 if (self.BUTTON_ATCK2)
2029 self.pressedkeys |= KEY_ATCK2;
2031 self.pressedkeys &~= KEY_ATCK2;
2035 ======================
2036 spectate mode routines
2037 ======================
2040 void SpectateCopy(entity spectatee) {
2042 MUTATOR_CALLHOOK(SpectateCopy);
2043 self.armortype = spectatee.armortype;
2044 self.armorvalue = spectatee.armorvalue;
2045 self.ammo_cells = spectatee.ammo_cells;
2046 self.ammo_shells = spectatee.ammo_shells;
2047 self.ammo_nails = spectatee.ammo_nails;
2048 self.ammo_rockets = spectatee.ammo_rockets;
2049 self.ammo_fuel = spectatee.ammo_fuel;
2050 self.clip_load = spectatee.clip_load;
2051 self.clip_size = spectatee.clip_size;
2052 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
2053 self.health = spectatee.health;
2055 self.items = spectatee.items;
2056 self.last_pickup = spectatee.last_pickup;
2057 self.hit_time = spectatee.hit_time;
2058 self.metertime = spectatee.metertime;
2059 self.strength_finished = spectatee.strength_finished;
2060 self.invincible_finished = spectatee.invincible_finished;
2061 self.pressedkeys = spectatee.pressedkeys;
2062 WEPSET_COPY_EE(self, spectatee);
2063 self.switchweapon = spectatee.switchweapon;
2064 self.switchingweapon = spectatee.switchingweapon;
2065 self.weapon = spectatee.weapon;
2066 self.nex_charge = spectatee.nex_charge;
2067 self.nex_chargepool_ammo = spectatee.nex_chargepool_ammo;
2068 self.hagar_load = spectatee.hagar_load;
2069 self.minelayer_mines = spectatee.minelayer_mines;
2070 self.punchangle = spectatee.punchangle;
2071 self.view_ofs = spectatee.view_ofs;
2072 self.velocity = spectatee.velocity;
2073 self.dmg_take = spectatee.dmg_take;
2074 self.dmg_save = spectatee.dmg_save;
2075 self.dmg_inflictor = spectatee.dmg_inflictor;
2076 self.v_angle = spectatee.v_angle;
2077 self.angles = spectatee.v_angle;
2078 self.stat_respawn_time = spectatee.stat_respawn_time;
2079 if(!self.BUTTON_USE)
2080 self.fixangle = TRUE;
2081 setorigin(self, spectatee.origin);
2082 setsize(self, spectatee.mins, spectatee.maxs);
2083 SetZoomState(spectatee.zoomstate);
2085 anticheat_spectatecopy(spectatee);
2086 self.hud = spectatee.hud;
2087 if(spectatee.vehicle)
2089 self.fixangle = FALSE;
2090 //self.velocity = spectatee.vehicle.velocity;
2091 self.vehicle_health = spectatee.vehicle_health;
2092 self.vehicle_shield = spectatee.vehicle_shield;
2093 self.vehicle_energy = spectatee.vehicle_energy;
2094 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
2095 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
2096 self.vehicle_reload1 = spectatee.vehicle_reload1;
2097 self.vehicle_reload2 = spectatee.vehicle_reload2;
2101 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
2102 WriteAngle(MSG_ONE, spectatee.v_angle_x);
2103 WriteAngle(MSG_ONE, spectatee.v_angle_y);
2104 WriteAngle(MSG_ONE, spectatee.v_angle_z);
2106 //WriteByte (MSG_ONE, SVC_SETVIEW);
2107 // WriteEntity(MSG_ONE, self);
2108 //makevectors(spectatee.v_angle);
2109 //setorigin(self, spectatee.origin - v_forward * 400 + v_up * 300);*/
2113 float SpectateUpdate() {
2117 if (self == self.enemy)
2120 if(self.enemy.classname != "player")
2123 SpectateCopy(self.enemy);
2129 // Returns next available player to spectate if g_ca_spectate_enemies == 0
2130 entity CA_SpectateNext(entity start) {
2131 if (start.team == self.team) {
2136 // continue from current player
2137 while(other && other.team != self.team) {
2138 other = find(other, classname, "player");
2142 // restart from begining
2143 other = find(other, classname, "player");
2144 while(other && other.team != self.team) {
2145 other = find(other, classname, "player");
2152 float SpectateNext(entity _prefer) {
2157 other = find(self.enemy, classname, "player");
2159 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer) {
2160 // CA and ca players when spectating enemies is forbidden
2161 other = CA_SpectateNext(other);
2163 // other modes and ca spectators or spectating enemies is allowed
2165 other = find(other, classname, "player");
2171 if(self.enemy.classname == "player") {
2172 /*if(self.enemy.vehicle)
2176 WriteByte(MSG_ONE, SVC_SETVIEW);
2177 WriteEntity(MSG_ONE, self.enemy);
2178 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2180 self.movetype = MOVETYPE_NONE;
2181 accuracy_resend(self);
2186 WriteByte(MSG_ONE, SVC_SETVIEW);
2187 WriteEntity(MSG_ONE, self.enemy);
2188 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2189 self.movetype = MOVETYPE_NONE;
2190 accuracy_resend(self);
2192 if(!SpectateUpdate())
2193 PutObserverInServer();
2203 ShowRespawnCountdown()
2205 Update a respawn countdown display.
2208 void ShowRespawnCountdown()
2211 if(self.deadflag == DEAD_NO) // just respawned?
2215 number = ceil(self.respawn_time - time);
2218 if(number <= self.respawn_countdown)
2220 self.respawn_countdown = number - 1;
2221 if(ceil(self.respawn_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
2222 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(number));
2227 void LeaveSpectatorMode()
2229 if(nJoinAllowed(self))
2231 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
2233 self.classname = "player";
2235 if(autocvar_g_campaign || autocvar_g_balance_teams)
2236 { JoinBestTeam(self, FALSE, TRUE); }
2238 if(autocvar_g_campaign)
2239 { campaign_bots_may_start = 1; }
2241 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_PREVENT_JOIN);
2243 PutClientInServer();
2245 if(IS_PLAYER(self)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_PLAY, self.netname); }
2247 else if not(g_ca && self.caplayer) { stuffcmd(self, "menu_showteamselect\n"); }
2251 // Player may not join because g_maxplayers is set
2252 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_PREVENT);
2257 * Determines whether the player is allowed to join. This depends on cvar
2258 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2259 * it checks whether the number of currently playing players exceeds g_maxplayers.
2260 * @return int number of free slots for players, 0 if none
2262 float nJoinAllowed(entity ignore) {
2264 // this is called that way when checking if anyone may be able to join (to build qcstatus)
2265 // so report 0 free slots if restricted
2267 if(autocvar_g_forced_team_otherwise == "spectate")
2269 if(autocvar_g_forced_team_otherwise == "spectator")
2273 if(self.team_forced < 0)
2274 return 0; // forced spectators can never join
2276 // TODO simplify this
2278 float totalClients = 0;
2283 if (!autocvar_g_maxplayers)
2284 return maxclients - totalClients;
2286 float currentlyPlaying = 0;
2287 FOR_EACH_REALPLAYER(e)
2288 currentlyPlaying += 1;
2290 if(currentlyPlaying < autocvar_g_maxplayers)
2291 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
2297 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2298 * g_maxplayers_spectator_blocktime seconds
2300 void checkSpectatorBlock() {
2301 if(self.classname == "spectator" || self.classname == "observer") {
2302 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2303 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
2309 void PrintWelcomeMessage()
2311 if(self.motd_actived_time == 0)
2313 if (autocvar_g_campaign) {
2314 if ((self.classname == "player" && self.BUTTON_INFO) || (self.classname != "player")) {
2315 self.motd_actived_time = time;
2316 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, campaign_message);
2319 if (self.BUTTON_INFO) {
2320 self.motd_actived_time = time;
2321 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
2325 else if(self.motd_actived_time > 0) // showing MOTD or campaign message
2327 if (autocvar_g_campaign) {
2328 if (self.BUTTON_INFO)
2329 self.motd_actived_time = time;
2330 else if ((time - self.motd_actived_time > 2) && self.classname == "player") { // hide it some seconds after BUTTON_INFO has been released
2331 self.motd_actived_time = 0;
2332 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2335 if (self.BUTTON_INFO)
2336 self.motd_actived_time = time;
2337 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2338 self.motd_actived_time = 0;
2339 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2343 else //if(self.motd_actived_time < 0) // just connected, motd is active
2345 if(self.BUTTON_INFO) // BUTTON_INFO hides initial MOTD
2346 self.motd_actived_time = -2; // wait until BUTTON_INFO gets released
2347 else if(self.motd_actived_time == -2 || IS_PLAYER(self) || time - self.jointime > autocvar_welcome_message_time)
2349 // instanctly hide MOTD
2350 self.motd_actived_time = 0;
2351 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2356 void ObserverThink()
2358 float prefered_movetype;
2359 if (self.flags & FL_JUMPRELEASED) {
2360 if (self.BUTTON_JUMP && !self.version_mismatch) {
2361 self.flags &~= FL_JUMPRELEASED;
2362 self.flags |= FL_SPAWNING;
2363 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2364 self.flags &~= FL_JUMPRELEASED;
2365 if(SpectateNext(world) == 1) {
2366 self.classname = "spectator";
2369 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2370 if (self.movetype != prefered_movetype)
2371 self.movetype = prefered_movetype;
2374 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2375 self.flags |= FL_JUMPRELEASED;
2376 if(self.flags & FL_SPAWNING)
2378 self.flags &~= FL_SPAWNING;
2379 LeaveSpectatorMode();
2386 void SpectatorThink()
2388 if (self.flags & FL_JUMPRELEASED) {
2389 if (self.BUTTON_JUMP && !self.version_mismatch) {
2390 self.flags &~= FL_JUMPRELEASED;
2391 self.flags |= FL_SPAWNING;
2392 } else if(self.BUTTON_ATCK) {
2393 self.flags &~= FL_JUMPRELEASED;
2394 if(SpectateNext(world) == 1) {
2395 self.classname = "spectator";
2397 self.classname = "observer";
2398 PutClientInServer();
2400 } else if (self.BUTTON_ATCK2) {
2401 self.flags &~= FL_JUMPRELEASED;
2402 self.classname = "observer";
2403 PutClientInServer();
2405 if(!SpectateUpdate())
2406 PutObserverInServer();
2409 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2410 self.flags |= FL_JUMPRELEASED;
2411 if(self.flags & FL_SPAWNING)
2413 self.flags &~= FL_SPAWNING;
2414 LeaveSpectatorMode();
2418 if(!SpectateUpdate())
2419 PutObserverInServer();
2422 self.flags |= FL_CLIENT | FL_NOTARGET;
2427 if(self.classname != "player")
2432 vehicles_exit(VHEF_NORMAL);
2436 // a use key was pressed; call handlers
2437 MUTATOR_CALLHOOK(PlayerUseKey);
2440 .float touchexplode_time;
2446 Called every frame for each client before the physics are run
2449 .float usekeypressed;
2450 void() nexball_setstatus;
2452 void PlayerPreThink (void)
2454 WarpZone_PlayerPhysics_FixVAngle();
2456 self.stat_game_starttime = game_starttime;
2457 self.stat_allow_oldnexbeam = autocvar_g_allow_oldnexbeam;
2458 self.stat_leadlimit = autocvar_leadlimit;
2460 if(g_arena || (g_ca && !allowed_to_spawn))
2461 self.stat_respawn_time = 0;
2463 self.stat_respawn_time = self.respawn_time;
2467 // physics frames: update anticheat stuff
2468 anticheat_prethink();
2471 if(blockSpectators && frametime)
2472 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2473 checkSpectatorBlock();
2477 if(self.netname_previous != self.netname)
2479 if(autocvar_sv_eventlog)
2480 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2481 if(self.netname_previous)
2482 strunzone(self.netname_previous);
2483 self.netname_previous = strzone(self.netname);
2487 if(self.version_nagtime)
2488 if(self.cvar_g_xonoticversion)
2489 if(time > self.version_nagtime)
2491 // don't notify git users
2492 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2494 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2496 // notify release users if connecting to git
2497 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");
2498 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2503 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2506 // give users new version
2507 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");
2508 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2512 // notify users about old server version
2513 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");
2514 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2518 self.version_nagtime = 0;
2522 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2524 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_GODMODE_OFF, self.max_armorvalue);
2525 self.max_armorvalue = 0;
2529 if (TetrisPreFrame())
2533 MUTATOR_CALLHOOK(PlayerPreThink);
2535 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2537 if(self.BUTTON_USE && !self.usekeypressed)
2539 self.usekeypressed = self.BUTTON_USE;
2542 if(clienttype(self) == CLIENTTYPE_REAL)
2543 PrintWelcomeMessage();
2545 if(self.classname == "player") {
2547 CheckRules_Player();
2549 if (intermission_running)
2551 IntermissionThink (); // otherwise a button could be missed between
2552 return; // the think tics
2555 //don't allow the player to turn around while game is paused!
2556 if(timeout_status == TIMEOUT_ACTIVE) {
2557 // FIXME turn this into CSQC stuff
2558 self.v_angle = self.lastV_angle;
2559 self.angles = self.lastV_angle;
2560 self.fixangle = TRUE;
2565 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge)
2567 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);
2568 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);
2569 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);
2571 if(self.nex_charge > autocvar_g_balance_nex_charge_animlimit)
2573 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);
2574 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);
2575 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);
2579 self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2584 if (self.deadflag != DEAD_NO)
2586 float button_pressed, force_respawn;
2587 if(self.personal && g_race_qualifying)
2589 if(time > self.respawn_time)
2591 self.respawn_time = time + 1; // only retry once a second
2600 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2601 force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
2602 if (self.deadflag == DEAD_DYING)
2605 self.deadflag = DEAD_RESPAWNING;
2606 else if(!button_pressed)
2607 self.deadflag = DEAD_DEAD;
2609 else if (self.deadflag == DEAD_DEAD)
2612 self.deadflag = DEAD_RESPAWNABLE;
2614 else if (self.deadflag == DEAD_RESPAWNABLE)
2617 self.deadflag = DEAD_RESPAWNING;
2619 else if (self.deadflag == DEAD_RESPAWNING)
2621 if(time > self.respawn_time)
2623 self.respawn_time = time + 1; // only retry once a second
2627 ShowRespawnCountdown();
2630 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2631 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2632 self.stat_respawn_time *= -1;
2636 // FIXME from now on self.deadflag is always 0 (and self.health is never < 1)
2637 // so (self.deadflag == DEAD_NO) is always true in the code below
2640 if(time > self.touchexplode_time)
2641 if(self.classname == "player")
2642 if(self.deadflag == DEAD_NO)
2643 if not(IS_INDEPENDENT_PLAYER(self))
2644 FOR_EACH_PLAYER(other) if(self != other)
2646 if(time > other.touchexplode_time)
2647 if(other.deadflag == DEAD_NO)
2648 if not(IS_INDEPENDENT_PLAYER(other))
2649 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2651 PlayerTouchExplode(self, other);
2652 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2656 if(g_lms && !self.deadflag && autocvar_g_lms_campcheck_interval)
2660 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2661 dist = self.prevorigin - self.origin;
2663 self.lms_traveled_distance += fabs(vlen(dist));
2665 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime))
2667 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
2668 self.lms_traveled_distance = 0;
2671 if(time > self.lms_nextcheck)
2673 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2674 if(self.lms_traveled_distance < autocvar_g_lms_campcheck_distance)
2676 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_LMS_CAMPCHECK);
2677 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2678 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2679 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');
2681 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval;
2682 self.lms_traveled_distance = 0;
2686 self.prevorigin = self.origin;
2688 float do_crouch = self.BUTTON_CROUCH;
2691 if(self.health <= g_bloodloss)
2695 if(self.freezetag_frozen)
2697 if(self.weapon == WEP_SHOTGUN && self.weaponentity.wframe == WFRAME_FIRE2 && time < self.weapon_nextthink)
2705 self.view_ofs = PL_CROUCH_VIEW_OFS;
2706 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2707 // setanim(self, self.anim_duck, FALSE, TRUE, TRUE); // this anim is BROKEN anyway
2714 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2715 if (!trace_startsolid)
2717 self.crouch = FALSE;
2718 self.view_ofs = PL_VIEW_OFS;
2719 setsize (self, PL_MIN, PL_MAX);
2724 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2726 if(self.bloodloss_timer < time)
2728 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2729 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2735 GrapplingHookFrame();
2737 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2740 self.items &~= self.items_added;
2744 self.items_added = 0;
2745 if(self.items & IT_JETPACK)
2746 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2747 self.items_added |= IT_FUEL;
2749 self.items |= self.items_added;
2754 // rot nex charge to the charge limit
2755 if(autocvar_g_balance_nex_charge_rot_rate && self.nex_charge > autocvar_g_balance_nex_charge_limit && self.nex_charge_rottime < time)
2756 self.nex_charge = bound(autocvar_g_balance_nex_charge_limit, self.nex_charge - autocvar_g_balance_nex_charge_rot_rate * frametime / W_TICSPERFRAME, 1);
2762 nexball_setstatus();
2765 secrets_setstatus();
2767 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2769 //self.angles_y=self.v_angle_y + 90; // temp
2770 } else if(gameover) {
2771 if (intermission_running)
2772 IntermissionThink (); // otherwise a button could be missed between
2774 } else if(self.classname == "observer") {
2776 } else if(self.classname == "spectator") {
2781 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));
2783 float oldspectatee_status;
2784 oldspectatee_status = self.spectatee_status;
2785 if(self.classname == "spectator")
2786 self.spectatee_status = num_for_edict(self.enemy);
2787 else if(self.classname == "observer")
2788 self.spectatee_status = num_for_edict(self);
2790 self.spectatee_status = 0;
2791 if(self.spectatee_status != oldspectatee_status)
2793 ClientData_Touch(self);
2795 race_InitSpectator();
2798 if(self.teamkill_soundtime)
2799 if(time > self.teamkill_soundtime)
2801 self.teamkill_soundtime = 0;
2803 entity oldpusher, oldself;
2805 oldself = self; self = self.teamkill_soundsource;
2806 oldpusher = self.pusher; self.pusher = oldself;
2808 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2810 self.pusher = oldpusher;
2814 if(self.taunt_soundtime)
2815 if(time > self.taunt_soundtime)
2817 self.taunt_soundtime = 0;
2818 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2821 target_voicescript_next(self);
2823 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2825 self.clip_load = self.clip_size = 0;
2828 float isInvisibleString(string s)
2831 s = strdecolorize(s);
2832 for((i = 0), (n = strlen(s)); i < n; ++i)
2840 case 192: // charmap space
2841 if (!autocvar_utf8_enable)
2844 case 160: // space in unicode fonts
2845 case 0xE000 + 192: // utf8 charmap space
2846 if (autocvar_utf8_enable)
2859 Called every frame for each client after the physics are run
2862 .float idlekick_lasttimeleft;
2863 void PlayerPostThink (void)
2865 // Savage: Check for nameless players
2866 if (isInvisibleString(self.netname)) {
2867 self.netname = "Player";
2868 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));
2871 if(sv_maxidle && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2873 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2875 if(self.idlekick_lasttimeleft) { self.idlekick_lasttimeleft = 0; }
2880 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2881 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2883 if(!self.idlekick_lasttimeleft)
2884 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2888 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, self.netname);
2892 else if(timeleft <= 10)
2894 if(timeleft != self.idlekick_lasttimeleft)
2895 Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(timeleft));
2896 self.idlekick_lasttimeleft = timeleft;
2902 if(self.impulse == 100)
2904 if (!TetrisPostFrame())
2910 //CheckPlayerJump();
2912 if(self.classname == "player") {
2913 CheckRules_Player();
2917 if (intermission_running)
2918 return; // intermission or finale
2928 for(i = 0; i < 1000; ++i)
2931 end = self.origin + '0 0 1024' + 512 * randomvec();
2932 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2933 if(trace_fraction < 1)
2934 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2936 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2942 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
2944 if(self.waypointsprite_attachedforcarrier)
2945 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent));
2949 if((g_cts || g_race) && self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
2951 if not(self.stored_netname)
2952 self.stored_netname = strzone(uid2name(self.crypto_idfp));
2953 if(self.stored_netname != self.netname)
2955 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
2956 strunzone(self.stored_netname);
2957 self.stored_netname = strzone(self.netname);
2963 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));
2966 CSQCMODEL_AUTOUPDATE();