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_BROADCAST, SVC_TEMPENTITY);
11 WriteByte(MSG_BROADCAST, TE_CSQC_ANNOUNCE);
12 WriteString(MSG_BROADCAST, 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;
93 .string netname_previous;
99 Checks if the argument string can be a valid playermodel.
100 Returns a valid one in doubt.
103 string FallbackPlayerModel;
104 string CheckPlayerModel(string plyermodel) {
105 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
107 // note: we cannot summon Don Strunzone here, some player may
108 // still have the model string set. In case anyone manages how
109 // to change a cvar default, we'll have a small leak here.
110 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
112 // only in right path
113 if( substring(plyermodel,0,14) != "models/player/")
114 return FallbackPlayerModel;
115 // only good file extensions
116 if(substring(plyermodel,-4,4) != ".zym")
117 if(substring(plyermodel,-4,4) != ".dpm")
118 if(substring(plyermodel,-4,4) != ".iqm")
119 if(substring(plyermodel,-4,4) != ".md3")
120 if(substring(plyermodel,-4,4) != ".psk")
121 return FallbackPlayerModel;
122 // forbid the LOD models
123 if(substring(plyermodel, -9,5) == "_lod1")
124 return FallbackPlayerModel;
125 if(substring(plyermodel, -9,5) == "_lod2")
126 return FallbackPlayerModel;
127 if(plyermodel != strtolower(plyermodel))
128 return FallbackPlayerModel;
129 // also, restrict to server models
130 if(autocvar_sv_servermodelsonly)
132 if(!fexists(plyermodel))
133 return FallbackPlayerModel;
138 void setplayermodel(entity e, string modelname)
140 precache_model(modelname);
141 setmodel(e, modelname);
142 player_setupanimsformodel();
143 UpdatePlayerSounds();
150 putting a client as observer in the server
153 void FixPlayermodel();
154 void PutObserverInServer (void)
157 self.hud = HUD_NORMAL;
158 race_PreSpawnObserver();
160 spot = SelectSpawnPoint (TRUE);
162 error("No spawnpoints for observers?!?\n");
163 RemoveGrapplingHook(self); // Wazat's Grappling Hook
165 if(clienttype(self) == CLIENTTYPE_REAL)
168 WriteByte(MSG_ONE, SVC_SETVIEW);
169 WriteEntity(MSG_ONE, self);
173 MUTATOR_CALLHOOK(MakePlayerObserver);
175 minstagib_stop_countdown(self);
177 Portal_ClearAll(self);
182 PlayerStats_Event(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
187 vehicles_exit(VHEF_RELESE);
189 WaypointSprite_PlayerDead();
191 if not(g_ca) // don't reset teams when moving a ca player to the spectators
192 self.team = -1; // move this as it is needed to log the player spectating in eventlog
194 if(self.killcount != -666) {
196 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
197 bprint ("^4", self.netname, "^4 has no more lives left\n");
199 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
201 bprint ("^4", self.netname, "^4 is spectating now\n");
203 if(self.just_joined == FALSE) {
204 LogTeamchange(self.playerid, -1, 4);
206 self.just_joined = FALSE;
209 PlayerScore_Clear(self); // clear scores when needed
211 accuracy_resend(self);
213 self.spectatortime = time;
215 self.classname = "observer";
216 self.iscreature = FALSE;
217 self.teleportable = TELEPORT_SIMPLE;
218 self.damagedbycontents = FALSE;
220 self.takedamage = DAMAGE_NO;
221 self.solid = SOLID_NOT;
222 self.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
223 self.flags = FL_CLIENT | FL_NOTARGET;
224 self.armorvalue = 666;
226 self.armorvalue = autocvar_g_balance_armor_start;
227 self.pauserotarmor_finished = 0;
228 self.pauserothealth_finished = 0;
229 self.pauseregen_finished = 0;
230 self.damageforcescale = 0;
232 self.respawn_time = 0;
237 self.pain_finished = 0;
238 self.strength_finished = 0;
239 self.invincible_finished = 0;
240 self.superweapons_finished = 0;
243 self.think = func_null;
247 self.deadflag = DEAD_NO;
248 self.angles = spot.angles;
250 self.fixangle = TRUE;
253 setorigin (self, (spot.origin + PL_VIEW_OFS)); // offset it so that the spectator spawns higher off the ground, looks better this way
254 self.prevorigin = self.origin;
256 WEPSET_CLEAR_E(self);
259 setmodel(self, "null");
260 self.drawonlytoclient = self;
262 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
263 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
266 self.weaponname = "";
267 self.switchingweapon = 0;
268 self.weaponmodel = "";
269 self.weaponentity = world;
270 self.exteriorweaponentity = world;
271 self.killcount = -666;
272 self.velocity = '0 0 0';
273 self.avelocity = '0 0 0';
274 self.punchangle = '0 0 0';
275 self.punchvector = '0 0 0';
276 self.oldvelocity = self.velocity;
277 self.fire_endtime = -1;
281 if(self.version_mismatch)
283 self.frags = FRAGS_SPECTATOR;
284 Spawnqueue_Unmark(self);
285 Spawnqueue_Remove(self);
289 self.frags = FRAGS_LMS_LOSER;
290 Spawnqueue_Insert(self);
295 // Only if the player cannot play at all
296 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
297 self.frags = FRAGS_SPECTATOR;
299 self.frags = FRAGS_LMS_LOSER;
304 self.frags = FRAGS_LMS_LOSER;
306 self.frags = FRAGS_SPECTATOR;
308 else if((g_race && g_race_qualifying) || g_cts)
310 if(PlayerScore_Add(self, SP_RACE_FASTEST, 0))
311 self.frags = FRAGS_LMS_LOSER;
313 self.frags = FRAGS_SPECTATOR;
316 self.frags = FRAGS_SPECTATOR;
319 .float model_randomizer;
320 void FixPlayermodel()
323 float defaultskin, chmdl, oldskin, n, i;
330 if(autocvar_sv_defaultcharacter == 1)
335 s = Team_ColorNameLowerCase(self.team);
338 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
339 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
343 if(defaultmodel == "")
345 defaultmodel = autocvar_sv_defaultplayermodel;
346 defaultskin = autocvar_sv_defaultplayerskin;
349 n = tokenize_console(defaultmodel);
351 defaultmodel = argv(floor(n * self.model_randomizer));
353 i = strstrofs(defaultmodel, ":", 0);
356 defaultskin = stof(substring(defaultmodel, i+1, -1));
357 defaultmodel = substring(defaultmodel, 0, i);
361 if(defaultmodel != "")
363 if (defaultmodel != self.model)
367 setplayermodel (self, defaultmodel);
368 setsize (self, m1, m2);
373 self.skin = defaultskin;
375 if (self.playermodel != self.model || self.playermodel == "")
377 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
380 setplayermodel (self, self.playermodel);
381 setsize (self, m1, m2);
386 self.skin = stof(self.playerskin);
389 if(chmdl || oldskin != self.skin)
390 self.species = player_getspecies(); // model or skin has changed
393 if(strlen(autocvar_sv_defaultplayercolors))
394 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
395 setcolor(self, stof(autocvar_sv_defaultplayercolors));
398 void PlayerTouchExplode(entity p1, entity p2)
401 org = (p1.origin + p2.origin) * 0.5;
402 org_z += (p1.mins_z + p2.mins_z) * 0.5;
409 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
417 Called when a client spawns in the server
421 void PutClientInServer (void)
423 if(clienttype(self) == CLIENTTYPE_BOT)
425 self.classname = "player";
429 else if(clienttype(self) == CLIENTTYPE_REAL)
432 WriteByte(MSG_ONE, SVC_SETVIEW);
433 WriteEntity(MSG_ONE, self);
439 // player is dead and becomes observer
440 // FIXME fix LMS scoring for new system
443 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
444 self.classname = "observer";
447 if((g_arena && !self.spawned) || (g_ca && !allowed_to_spawn))
448 self.classname = "observer";
451 self.classname = "observer";
453 if(self.classname == "player" && (!g_ca || (g_ca && allowed_to_spawn))) {
454 entity spot, oldself;
457 accuracy_resend(self);
460 JoinBestTeam(self, FALSE, TRUE);
464 spot = SelectSpawnPoint (FALSE);
467 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
468 return; // spawn failed
471 RemoveGrapplingHook(self); // Wazat's Grappling Hook
473 self.classname = "player";
474 self.wasplayer = TRUE;
475 self.iscreature = TRUE;
476 self.teleportable = TELEPORT_NORMAL;
477 self.damagedbycontents = TRUE;
478 self.movetype = MOVETYPE_WALK;
479 self.solid = SOLID_SLIDEBOX;
480 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
481 if(autocvar_g_playerclip_collisions)
482 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
483 if(clienttype(self) == CLIENTTYPE_BOT && autocvar_g_botclip_collisions)
484 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
485 self.frags = FRAGS_PLAYER;
486 if(INDEPENDENT_PLAYERS)
487 MAKE_INDEPENDENT_PLAYER(self);
488 self.flags = FL_CLIENT;
489 if(autocvar__notarget)
490 self.flags |= FL_NOTARGET;
491 self.takedamage = DAMAGE_AIM;
493 self.effects = EF_FULLBRIGHT;
496 self.effects |= EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
497 self.air_finished = time + 12;
499 if(autocvar_g_balance_nex_charge)
501 if(autocvar_g_balance_nex_secondary_chargepool)
502 self.nex_chargepool_ammo = 1;
503 self.nex_charge = autocvar_g_balance_nex_charge_start;
508 self.ammo_shells = warmup_start_ammo_shells;
509 self.ammo_nails = warmup_start_ammo_nails;
510 self.ammo_rockets = warmup_start_ammo_rockets;
511 self.ammo_cells = warmup_start_ammo_cells;
512 self.ammo_fuel = warmup_start_ammo_fuel;
513 self.health = warmup_start_health;
514 self.armorvalue = warmup_start_armorvalue;
515 WEPSET_COPY_EA(self, warmup_start_weapons);
519 self.ammo_shells = start_ammo_shells;
520 self.ammo_nails = start_ammo_nails;
521 self.ammo_rockets = start_ammo_rockets;
522 self.ammo_cells = start_ammo_cells;
523 self.ammo_fuel = start_ammo_fuel;
524 self.health = start_health;
525 self.armorvalue = start_armorvalue;
526 WEPSET_COPY_EA(self, start_weapons);
529 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // exception for minstagib, as minstanex is a superweapon
530 self.superweapons_finished = time + autocvar_g_balance_superweapons_time;
532 self.superweapons_finished = 0;
534 if(g_weaponarena_random)
536 if(g_weaponarena_random_with_laser)
537 WEPSET_ANDNOT_EW(self, WEP_LASER);
538 W_RandomWeapons(self, g_weaponarena_random);
539 if(g_weaponarena_random_with_laser)
540 WEPSET_OR_EW(self, WEP_LASER);
543 self.items = start_items;
545 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
546 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
547 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
548 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
549 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
550 //extend the pause of rotting if client was reset at the beginning of the countdown
551 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
552 self.spawnshieldtime += game_starttime - time;
553 self.pauserotarmor_finished += game_starttime - time;
554 self.pauserothealth_finished += game_starttime - time;
555 self.pauseregen_finished += game_starttime - time;
557 self.damageforcescale = 2;
559 self.respawn_time = 0;
563 self.pain_finished = 0;
564 self.strength_finished = 0;
565 self.invincible_finished = 0;
567 // players have no think function
568 self.think = func_null;
572 self.ballistics_density = autocvar_g_ballistics_density_player;
578 self.deadflag = DEAD_NO;
580 self.angles = spot.angles;
582 self.angles_z = 0; // never spawn tilted even if the spot says to
583 self.fixangle = TRUE; // turn this way immediately
584 self.velocity = '0 0 0';
585 self.avelocity = '0 0 0';
586 self.punchangle = '0 0 0';
587 self.punchvector = '0 0 0';
588 self.oldvelocity = self.velocity;
589 self.fire_endtime = -1;
592 WRITESPECTATABLE_MSG_ONE({
593 WriteByte(MSG_ONE, SVC_TEMPENTITY);
594 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
599 self.drawonlytoclient = world;
602 self.view_ofs = PL_VIEW_OFS;
603 setsize (self, PL_MIN, PL_MAX);
604 self.spawnorigin = spot.origin;
605 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
606 // don't reset back to last position, even if new position is stuck in solid
607 self.oldorigin = self.origin;
608 self.prevorigin = self.origin;
609 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
610 self.lastteleporttime = time; // prevent insane speeds due to changing origin
611 self.hud = HUD_NORMAL;
615 Spawnqueue_Remove(self);
616 Spawnqueue_Mark(self);
621 self.event_damage = PlayerDamage;
623 self.bot_attack = TRUE;
625 self.statdraintime = time + 5;
626 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
628 if(self.killcount == -666) {
629 PlayerScore_Clear(self);
633 CL_SpawnWeaponentity();
634 self.alpha = default_player_alpha;
635 self.colormod = '1 1 1' * autocvar_g_player_brightness;
636 self.exteriorweaponentity.alpha = default_weapon_alpha;
638 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
639 self.lms_traveled_distance = 0;
640 self.speedrunning = FALSE;
642 race_PostSpawn(spot);
644 //stuffcmd(self, "chase_active 0");
645 //stuffcmd(self, "set viewsize $tmpviewsize \n");
648 if(self.team == assault_attacker_team)
649 centerprint(self, "You are attacking!");
651 centerprint(self, "You are defending!");
654 target_voicescript_clear(self);
656 // reset fields the weapons may use
657 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
659 weapon_action(j, WR_RESETPLAYER);
661 // all weapons must be fully loaded when we spawn
663 e = get_weaponinfo(j);
664 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
665 self.(weapon_load[j]) = cvar(strcat("g_balance_", e.netname, "_reload_ammo"));
673 self.target = string_null;
680 MUTATOR_CALLHOOK(PlayerSpawn);
682 if(autocvar_spawn_debug)
684 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
685 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
688 self.switchweapon = w_getbestweapon(self);
689 self.cnt = -1; // W_LastWeapon will not complain
691 self.weaponname = "";
692 self.switchingweapon = 0;
696 self.alivetime = time;
700 if (autocvar_g_spawnsound)
701 soundat(world, self.origin, CH_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
702 } else if(self.classname == "observer") {
703 PutObserverInServer ();
707 .float ebouncefactor, ebouncestop; // electro's values
708 // TODO do we need all these fields, or should we stop autodetecting runtime
709 // changes and just have a console command to update this?
710 float ClientInit_SendEntity(entity to, float sf)
712 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
713 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
714 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
715 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
716 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
717 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
718 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[0]));
719 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[1]));
720 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[2]));
721 WriteInt24_t(MSG_ENTITY, compressShotOrigin(electro_shotorigin[3]));
722 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[0]));
723 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[1]));
724 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[2]));
725 WriteInt24_t(MSG_ENTITY, compressShotOrigin(gauntlet_shotorigin[3]));
726 if(sv_foginterval && world.fog != "")
727 WriteString(MSG_ENTITY, world.fog);
729 WriteString(MSG_ENTITY, "");
730 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
731 WriteByte(MSG_ENTITY, self.cnt * 255.0); // g_balance_weaponswitchdelay
732 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_grenadelauncher_bouncefactor
733 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_grenadelauncher_bouncestop
734 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_grenadelauncher_bouncefactor
735 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_grenadelauncher_bouncestop
736 WriteByte(MSG_ENTITY, autocvar_g_balance_nex_secondary); // client has to know if it should zoom or not
737 WriteByte(MSG_ENTITY, autocvar_g_balance_rifle_secondary); // client has to know if it should zoom or not
738 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
739 WriteByte(MSG_ENTITY, autocvar_g_balance_minelayer_limit); // minelayer max mines
740 WriteByte(MSG_ENTITY, autocvar_g_balance_hagar_secondary_load_max); // hagar max loadable rockets
741 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
742 WriteByte(MSG_ENTITY, autocvar_g_balance_porto_secondary);
746 void ClientInit_CheckUpdate()
748 self.nextthink = time;
749 if(self.count != autocvar_g_balance_armor_blockpercent)
751 self.count = autocvar_g_balance_armor_blockpercent;
754 if(self.cnt != autocvar_g_balance_weaponswitchdelay)
756 self.cnt = autocvar_g_balance_weaponswitchdelay;
759 if(self.bouncefactor != autocvar_g_balance_grenadelauncher_bouncefactor)
761 self.bouncefactor = autocvar_g_balance_grenadelauncher_bouncefactor;
764 if(self.bouncestop != autocvar_g_balance_grenadelauncher_bouncestop)
766 self.bouncestop = autocvar_g_balance_grenadelauncher_bouncestop;
769 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
771 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
774 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
776 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
781 void ClientInit_Spawn()
786 e.classname = "clientinit";
787 e.think = ClientInit_CheckUpdate;
788 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
792 ClientInit_CheckUpdate();
801 void SetNewParms (void)
803 // initialize parms for a new player
804 parm1 = -(86400 * 366);
812 void SetChangeParms (void)
814 // save parms for level change
815 parm1 = self.parm_idlesince - time;
823 void DecodeLevelParms (void)
826 self.parm_idlesince = parm1;
827 if(self.parm_idlesince == -(86400 * 366))
828 self.parm_idlesince = time;
830 // whatever happens, allow 60 seconds of idling directly after connect for map loading
831 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
838 Called when a client types 'kill' in the console
842 .float clientkill_nexttime;
843 void ClientKill_Now_TeamChange()
845 if(self.killindicator_teamchange == -1)
847 JoinBestTeam( self, FALSE, TRUE );
849 else if(self.killindicator_teamchange == -2)
854 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"));
855 PutObserverInServer();
858 SV_ChangeTeam(self.killindicator_teamchange - 1);
861 void ClientKill_Now()
865 vehicles_exit(VHEF_RELESE);
866 if(!self.killindicator_teamchange)
868 self.vehicle_health = -1;
869 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
873 if(self.killindicator && !wasfreed(self.killindicator))
874 remove(self.killindicator);
876 self.killindicator = world;
878 if(self.killindicator_teamchange)
879 ClientKill_Now_TeamChange();
882 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
884 // now I am sure the player IS dead
886 void KillIndicator_Think()
890 self.owner.killindicator = world;
895 if (self.owner.alpha < 0 && !self.owner.vehicle)
897 self.owner.killindicator = world;
905 ClientKill_Now(); // no oldself needed
908 else if(g_cts && self.health == 1) // health == 1 means that it's silent
910 self.nextthink = time + 1;
916 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
917 if(clienttype(self.owner) == CLIENTTYPE_REAL)
920 AnnounceTo(self.owner, strcat(ftos(self.cnt), ""));
922 self.nextthink = time + 1;
927 float clientkilltime;
928 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
937 killtime = autocvar_g_balance_kill_delay;
939 if(g_race_qualifying || g_cts)
942 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
944 remove(self.killindicator);
945 self.killindicator = world;
947 ClientKill_Now(); // allow instant kill in this case
951 self.killindicator_teamchange = targetteam;
953 if(!self.killindicator)
955 if(self.deadflag == DEAD_NO)
957 killtime = max(killtime, self.clientkill_nexttime - time);
958 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
961 if(killtime <= 0 || self.classname != "player" || self.deadflag != DEAD_NO)
967 starttime = max(time, clientkilltime);
969 self.killindicator = spawn();
970 self.killindicator.owner = self;
971 self.killindicator.scale = 0.5;
972 setattachment(self.killindicator, self, "");
973 setorigin(self.killindicator, '0 0 52');
974 self.killindicator.think = KillIndicator_Think;
975 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
976 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
977 self.killindicator.cnt = ceil(killtime);
978 self.killindicator.count = bound(0, ceil(killtime), 10);
979 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
981 for(e = world; (e = find(e, classname, "body")) != world; )
985 e.killindicator = spawn();
986 e.killindicator.owner = e;
987 e.killindicator.scale = 0.5;
988 setattachment(e.killindicator, e, "");
989 setorigin(e.killindicator, '0 0 52');
990 e.killindicator.think = KillIndicator_Think;
991 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
992 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
993 e.killindicator.cnt = ceil(killtime);
998 if(self.killindicator)
1000 if(targetteam == 0) // just die
1002 self.killindicator.colormod = '0 0 0';
1003 if(clienttype(self) == CLIENTTYPE_REAL)
1004 if(self.killindicator.cnt > 0)
1005 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "^1Suicide in %d seconds", 1, self.killindicator.cnt);
1007 else if(targetteam == -1) // auto
1009 self.killindicator.colormod = '0 1 0';
1010 if(clienttype(self) == CLIENTTYPE_REAL)
1011 if(self.killindicator.cnt > 0)
1012 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Changing team in %d seconds", 1, self.killindicator.cnt);
1014 else if(targetteam == -2) // spectate
1016 self.killindicator.colormod = '0.5 0.5 0.5';
1017 if(clienttype(self) == CLIENTTYPE_REAL)
1018 if(self.killindicator.cnt > 0)
1019 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, "Spectating in %d seconds", 1, self.killindicator.cnt);
1023 self.killindicator.colormod = TeamColor(targetteam);
1024 if(clienttype(self) == CLIENTTYPE_REAL)
1025 if(self.killindicator.cnt > 0)
1026 Send_CSQC_Centerprint_Generic(self, CPID_TEAMCHANGE, strcat("Changing to ", ColoredTeamName(targetteam), " in %d seconds"), 1, self.killindicator.cnt);
1032 void ClientKill (void)
1037 if((g_arena || g_ca) && ((champion && champion.classname == "player" && player_count > 1) || player_count == 1)) // don't allow a kill in this case either
1041 else if(self.freezetag_frozen)
1046 ClientKill_TeamChange(0);
1049 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
1051 e.killindicator = spawn();
1052 e.killindicator.owner = e;
1053 e.killindicator.think = KillIndicator_Think;
1054 e.killindicator.nextthink = time + (e.lip) * 0.05;
1055 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
1056 e.killindicator.health = 1; // this is used to indicate that it should be silent
1060 void FixClientCvars(entity e)
1062 // send prediction settings to the client
1063 stuffcmd(e, "\nin_bindmap 0 0\n");
1065 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
1066 if(autocvar_g_antilag == 3) // client side hitscan
1067 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
1069 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
1071 * we no longer need to stuff this. Remove this comment block if you feel
1072 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1073 stuffcmd(e, strcat("cl_gravity ", ftos(autocvar_sv_gravity), "\n"));
1074 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(autocvar_sv_accelerate), "\n"));
1075 stuffcmd(e, strcat("cl_movement_friction ", ftos(autocvar_sv_friction), "\n"));
1076 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(autocvar_sv_maxspeed), "\n"));
1077 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(autocvar_sv_airaccelerate), "\n"));
1078 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(autocvar_sv_maxairspeed), "\n"));
1079 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(autocvar_sv_stopspeed), "\n"));
1080 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(autocvar_sv_jumpvelocity), "\n"));
1081 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(autocvar_sv_stepheight), "\n"));
1082 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(autocvar_sv_friction_on_land), "\n"));
1083 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(autocvar_sv_airaccel_qw), "\n"));
1084 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(autocvar_sv_airaccel_sideways_friction), "\n"));
1085 stuffcmd(e, "cl_movement_edgefriction 1\n");
1089 float PlayerInIDList(entity p, string idlist)
1094 // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
1095 if not(p.crypto_idfp)
1098 // this function allows abbreviated player IDs too!
1099 n = tokenize_console(idlist);
1100 for(i = 0; i < n; ++i)
1103 if(s == substring(p.crypto_idfp, 0, strlen(s)))
1114 Called when a client connects to the server
1117 string ColoredTeamName(float t);
1118 void DecodeLevelParms (void);
1119 //void dom_player_join_team(entity pl);
1120 void set_dom_state(entity e);
1121 void ClientConnect (void)
1125 if(self.flags & FL_CLIENT)
1127 print("Warning: ClientConnect, but already connected!\n");
1131 if(Ban_MaybeEnforceBanOnce(self))
1137 sprint(self, strcat("^4SVQC Build information: ^1", WATERMARK, "\n"));
1140 self.classname = "player_joining";
1142 self.flags = FL_CLIENT;
1143 self.version_nagtime = time + 10 + random() * 10;
1147 dprint("BUG player count is lower than zero, this cannot happen!\n");
1151 PlayerScore_Attach(self);
1152 ClientData_Attach();
1153 accuracy_init(self);
1155 bot_clientconnect();
1161 race_PreSpawnObserver();
1163 // identify the right forced team
1164 if(autocvar_g_campaign)
1166 if(clienttype(self) == CLIENTTYPE_REAL) // only players, not bots
1168 switch(autocvar_g_campaign_forceteam)
1170 case 1: self.team_forced = COLOR_TEAM1; break;
1171 case 2: self.team_forced = COLOR_TEAM2; break;
1172 case 3: self.team_forced = COLOR_TEAM3; break;
1173 case 4: self.team_forced = COLOR_TEAM4; break;
1174 default: self.team_forced = 0;
1178 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1179 self.team_forced = COLOR_TEAM1;
1180 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1181 self.team_forced = COLOR_TEAM2;
1182 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1183 self.team_forced = COLOR_TEAM3;
1184 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1185 self.team_forced = COLOR_TEAM4;
1186 else if(autocvar_g_forced_team_otherwise == "red")
1187 self.team_forced = COLOR_TEAM1;
1188 else if(autocvar_g_forced_team_otherwise == "blue")
1189 self.team_forced = COLOR_TEAM2;
1190 else if(autocvar_g_forced_team_otherwise == "yellow")
1191 self.team_forced = COLOR_TEAM3;
1192 else if(autocvar_g_forced_team_otherwise == "pink")
1193 self.team_forced = COLOR_TEAM4;
1194 else if(autocvar_g_forced_team_otherwise == "spectate")
1195 self.team_forced = -1;
1196 else if(autocvar_g_forced_team_otherwise == "spectator")
1197 self.team_forced = -1;
1199 self.team_forced = 0;
1202 if(self.team_forced > 0)
1203 self.team_forced = 0;
1205 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1207 if((autocvar_sv_spectate == 1 && !g_lms) || autocvar_g_campaign || self.team_forced < 0) {
1208 self.classname = "observer";
1212 if(autocvar_g_balance_teams)
1214 self.classname = "player";
1215 campaign_bots_may_start = 1;
1219 self.classname = "observer"; // do it anyway
1224 self.classname = "player";
1225 campaign_bots_may_start = 1;
1229 self.playerid = (playerid_last = playerid_last + 1);
1231 PlayerStats_AddEvent(sprintf("kills-%d", self.playerid));
1233 if(clienttype(self) == CLIENTTYPE_BOT)
1234 PlayerStats_AddPlayer(self);
1236 if(autocvar_sv_eventlog)
1237 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((clienttype(self) == CLIENTTYPE_REAL) ? self.netaddress : "bot"), ":", self.netname));
1239 LogTeamchange(self.playerid, self.team, 1);
1241 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1243 self.netname_previous = strzone(self.netname);
1245 bprint("^4", self.netname, "^4 connected");
1247 if(self.classname != "observer" && (g_domination || g_ctf))
1248 bprint(" and joined the ", ColoredTeamName(self.team));
1252 stuffcmd(self, strcat(clientstuff, "\n"));
1253 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1255 FixClientCvars(self);
1257 // spawnfunc_waypoint sprites
1258 WaypointSprite_InitClient(self);
1260 // Wazat's grappling hook
1261 SetGrappleHookBindings();
1263 // get version info from player
1264 stuffcmd(self, "cmd clientversion $gameversion\n");
1266 // get other cvars from player
1269 // notify about available teams
1272 CheckAllowedTeams(self);
1273 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1274 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1277 stuffcmd(self, "set _teams_available 0\n");
1281 self.classname = "observer";
1283 Spawnqueue_Insert(self);
1288 bot_relinkplayerlist();
1290 self.spectatortime = time;
1293 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"));
1296 self.jointime = time;
1297 self.allowed_timeouts = autocvar_sv_timeout_number;
1299 if(clienttype(self) == CLIENTTYPE_REAL)
1301 if(autocvar_g_bugrigs || WEPSET_EQ_AW(g_weaponarena_weapons, WEP_TUBA))
1302 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1307 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1309 PlayerScore_Add(self, SP_LMS_RANK, 666);
1310 self.frags = FRAGS_SPECTATOR;
1314 if(!sv_foginterval && world.fog != "")
1315 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1317 if(autocvar_g_hitplots || strstrofs(strcat(" ", autocvar_g_hitplots_individuals, " "), strcat(" ", self.netaddress, " "), 0) >= 0)
1319 self.hitplotfh = fopen(strcat("hits-", matchid, "-", self.netaddress, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1320 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1323 self.hitplotfh = -1;
1325 if(g_race || g_cts) {
1333 race_send_recordtime(MSG_ONE);
1334 race_send_speedaward(MSG_ONE);
1336 speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
1337 speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
1338 race_send_speedaward_alltimebest(MSG_ONE);
1341 for (i = 1; i <= RANKINGS_CNT; ++i) {
1342 race_SendRankings(i, 0, 0, MSG_ONE);
1345 else if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca) // teamnagger is currently bad for ca
1346 send_CSQC_teamnagger();
1350 if(!autocvar_g_campaign)
1351 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), autocvar_welcome_message_time, 0);
1353 CSQCMODEL_AUTOINIT();
1355 self.model_randomizer = random();
1357 if(clienttype(self) != CLIENTTYPE_REAL)
1362 MUTATOR_CALLHOOK(ClientConnect);
1368 Called when a client disconnects from the server
1371 .entity chatbubbleentity;
1373 void ClientDisconnect (void)
1376 vehicles_exit(VHEF_RELESE);
1378 if not(self.flags & FL_CLIENT)
1380 print("Warning: ClientDisconnect without ClientConnect\n");
1384 PlayerStats_AddGlobalInfo(self);
1386 CheatShutdownClient();
1388 if(self.hitplotfh >= 0)
1390 fclose(self.hitplotfh);
1391 self.hitplotfh = -1;
1395 anticheat_shutdown();
1397 playerdemo_shutdown();
1399 bot_clientdisconnect();
1404 if(autocvar_sv_eventlog)
1405 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1406 bprint ("^4",self.netname);
1407 bprint ("^4 disconnected\n");
1410 MUTATOR_CALLHOOK(ClientDisconnect);
1412 Portal_ClearAll(self);
1414 RemoveGrapplingHook(self);
1416 // Here, everything has been done that requires this player to be a client.
1418 self.flags &~= FL_CLIENT;
1420 if (self.chatbubbleentity)
1421 remove (self.chatbubbleentity);
1423 if (self.killindicator)
1424 remove (self.killindicator);
1426 WaypointSprite_PlayerGone();
1428 bot_relinkplayerlist();
1432 Spawnqueue_Unmark(self);
1433 Spawnqueue_Remove(self);
1436 accuracy_free(self);
1437 ClientData_Detach();
1438 PlayerScore_Detach(self);
1440 if(self.netname_previous)
1441 strunzone(self.netname_previous);
1442 if(self.clientstatus)
1443 strunzone(self.clientstatus);
1444 if(self.weaponorder_byimpulse)
1445 strunzone(self.weaponorder_byimpulse);
1447 ClearPlayerSounds();
1450 remove(self.personal);
1460 void ChatBubbleThink()
1462 self.nextthink = time;
1463 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1465 if(self.owner) // but why can that ever be world?
1466 self.owner.chatbubbleentity = world;
1470 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1472 || self.owner.tetris_on
1475 self.model = self.mdl;
1480 void UpdateChatBubble()
1484 // spawn a chatbubble entity if needed
1485 if (!self.chatbubbleentity)
1487 self.chatbubbleentity = spawn();
1488 self.chatbubbleentity.owner = self;
1489 self.chatbubbleentity.exteriormodeltoclient = self;
1490 self.chatbubbleentity.think = ChatBubbleThink;
1491 self.chatbubbleentity.nextthink = time;
1492 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1493 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1494 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1495 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1496 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1497 self.chatbubbleentity.model = "";
1498 self.chatbubbleentity.effects = EF_LOWPRECISION;
1503 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1504 // added to the model skins
1505 /*void UpdateColorModHack()
1508 c = self.clientcolors & 15;
1509 // LordHavoc: only bothering to support white, green, red, yellow, blue
1510 if (!teamplay) self.colormod = '0 0 0';
1511 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1512 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1513 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1514 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1515 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1516 else self.colormod = '1 1 1';
1521 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1523 self.solid = SOLID_NOT;
1524 self.takedamage = DAMAGE_NO;
1525 self.movetype = MOVETYPE_FLY;
1526 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1527 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1528 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1529 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1530 if(autocvar_g_respawn_ghosts_maxtime)
1531 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1536 self.effects |= EF_NODRAW; // prevent another CopyBody
1537 PutClientInServer();
1540 void play_countdown(float finished, string samp)
1542 if(clienttype(self) == CLIENTTYPE_REAL)
1543 if(floor(finished - time - frametime) != floor(finished - time))
1544 if(finished - time < 6)
1545 sound (self, CH_INFO, samp, VOL_BASE, ATTN_NORM);
1548 void player_powerups (void)
1550 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1551 olditems = self.items;
1553 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1554 self.modelflags |= MF_ROCKET;
1556 self.modelflags &~= MF_ROCKET;
1558 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1560 if(self.alpha < 0 || self.deadflag) // don't apply the flags if the player is gibbed
1563 Fire_ApplyDamage(self);
1564 Fire_ApplyEffect(self);
1568 self.effects |= EF_FULLBRIGHT;
1570 if (self.items & IT_STRENGTH)
1572 play_countdown(self.strength_finished, "misc/poweroff.wav");
1573 if (time > self.strength_finished)
1575 self.alpha = default_player_alpha;
1576 self.exteriorweaponentity.alpha = default_weapon_alpha;
1577 self.items &~= IT_STRENGTH;
1578 sprint(self, "^3Invisibility has worn off\n");
1583 if (time < self.strength_finished)
1585 self.alpha = g_minstagib_invis_alpha;
1586 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1587 self.items |= IT_STRENGTH;
1588 sprint(self, "^3You are invisible\n");
1592 if (self.items & IT_INVINCIBLE)
1594 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1595 if (time > self.invincible_finished)
1597 self.items = self.items - (self.items & IT_INVINCIBLE);
1598 sprint(self, "^3Speed has worn off\n");
1603 if (time < self.invincible_finished)
1605 self.items = self.items | IT_INVINCIBLE;
1606 sprint(self, "^3You are on speed\n");
1610 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.
1612 if (self.items & IT_STRENGTH)
1614 play_countdown(self.strength_finished, "misc/poweroff.wav");
1615 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1616 if (time > self.strength_finished)
1618 self.items = self.items - (self.items & IT_STRENGTH);
1619 sprint(self, "^3Strength has worn off\n");
1624 if (time < self.strength_finished)
1626 self.items = self.items | IT_STRENGTH;
1627 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1630 if (self.items & IT_INVINCIBLE)
1632 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1633 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1634 if (time > self.invincible_finished)
1636 self.items = self.items - (self.items & IT_INVINCIBLE);
1637 sprint(self, "^3Shield has worn off\n");
1642 if (time < self.invincible_finished)
1644 self.items = self.items | IT_INVINCIBLE;
1645 sprint(self, "^3Shield surrounds you\n");
1648 if (self.items & IT_SUPERWEAPON)
1650 if (!WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
1652 self.superweapons_finished = 0;
1653 self.items = self.items - (self.items & IT_SUPERWEAPON);
1654 sprint(self, "^3Superweapons have been lost\n");
1656 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1658 // don't let them run out
1662 play_countdown(self.superweapons_finished, "misc/poweroff.wav");
1663 if (time > self.superweapons_finished)
1665 self.items = self.items - (self.items & IT_SUPERWEAPON);
1666 WEPSET_ANDNOT_EA(self, WEPBIT_SUPERWEAPONS);
1667 sprint(self, "^3Superweapons have broken down\n");
1671 else if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
1673 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1675 self.items = self.items | IT_SUPERWEAPON;
1676 sprint(self, "^3You now have a superweapon\n");
1680 self.superweapons_finished = 0;
1681 WEPSET_ANDNOT_EA(self, WEPBIT_SUPERWEAPONS);
1686 self.superweapons_finished = 0;
1690 if(autocvar_g_nodepthtestplayers)
1691 self.effects = self.effects | EF_NODEPTHTEST;
1693 if(autocvar_g_fullbrightplayers)
1694 self.effects = self.effects | EF_FULLBRIGHT;
1696 // midair gamemode: damage only while in the air
1697 // if in midair mode, being on ground grants temporary invulnerability
1698 // (this is so that multishot weapon don't clear the ground flag on the
1699 // first damage in the frame, leaving the player vulnerable to the
1700 // remaining hits in the same frame)
1701 if (self.flags & FL_ONGROUND)
1703 self.spawnshieldtime = max(self.spawnshieldtime, time + autocvar_g_midair_shieldtime);
1705 if (time >= game_starttime)
1706 if (time < self.spawnshieldtime)
1707 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1709 MUTATOR_CALLHOOK(PlayerPowerups);
1712 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1714 if(current > stable)
1716 else if(current > stable - 0.25) // when close enough, "snap"
1719 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1722 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1724 if(current < stable)
1726 else if(current < stable + 0.25) // when close enough, "snap"
1729 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1732 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1734 if(current > rotstable)
1736 if(rotframetime > 0)
1738 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1739 current = max(rotstable, current - rotlinear * rotframetime);
1742 else if(current < regenstable)
1744 if(regenframetime > 0)
1746 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1747 current = min(regenstable, current + regenlinear * regenframetime);
1757 void player_regen (void)
1759 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1760 maxh = autocvar_g_balance_health_rotstable;
1761 maxa = autocvar_g_balance_armor_rotstable;
1762 maxf = autocvar_g_balance_fuel_rotstable;
1763 minh = autocvar_g_balance_health_regenstable;
1764 mina = autocvar_g_balance_armor_regenstable;
1765 minf = autocvar_g_balance_fuel_regenstable;
1766 limith = autocvar_g_balance_health_limit;
1767 limita = autocvar_g_balance_armor_limit;
1768 limitf = autocvar_g_balance_fuel_limit;
1770 max_mod = regen_mod = rot_mod = limit_mod = 1;
1772 if (self.runes & RUNE_REGEN)
1774 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1776 regen_mod = autocvar_g_balance_rune_regen_combo_regenrate;
1777 max_mod = autocvar_g_balance_rune_regen_combo_hpmod;
1778 limit_mod = autocvar_g_balance_rune_regen_combo_limitmod;
1782 regen_mod = autocvar_g_balance_rune_regen_regenrate;
1783 max_mod = autocvar_g_balance_rune_regen_hpmod;
1784 limit_mod = autocvar_g_balance_rune_regen_limitmod;
1787 else if (self.runes & CURSE_VENOM)
1789 max_mod = autocvar_g_balance_curse_venom_hpmod;
1790 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1791 rot_mod = autocvar_g_balance_rune_regen_combo_rotrate;
1793 rot_mod = autocvar_g_balance_curse_venom_rotrate;
1794 limit_mod = autocvar_g_balance_curse_venom_limitmod;
1795 //if (!self.runes & RUNE_REGEN)
1796 // rot_mod = autocvar_g_balance_curse_venom_rotrate;
1798 maxh = maxh * max_mod;
1799 //maxa = maxa * max_mod;
1800 //maxf = maxf * max_mod;
1801 minh = minh * max_mod;
1802 //mina = mina * max_mod;
1803 //minf = minf * max_mod;
1804 limith = limith * limit_mod;
1805 limita = limita * limit_mod;
1806 //limitf = limitf * limit_mod;
1811 if (!g_minstagib && !g_ca && (!g_lms || autocvar_g_lms_regenerate))
1813 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);
1814 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);
1816 // if player rotted to death... die!
1818 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1821 if not(self.items & IT_UNLIMITED_WEAPON_AMMO)
1822 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);
1825 float zoomstate_set;
1826 void SetZoomState(float z)
1828 if(z != self.zoomstate)
1831 ClientData_Touch(self);
1836 void GetPressedKeys(void) {
1837 MUTATOR_CALLHOOK(GetPressedKeys);
1838 if (self.movement_x > 0) // get if movement keys are pressed
1839 { // forward key pressed
1840 self.pressedkeys |= KEY_FORWARD;
1841 self.pressedkeys &~= KEY_BACKWARD;
1843 else if (self.movement_x < 0)
1844 { // backward key pressed
1845 self.pressedkeys |= KEY_BACKWARD;
1846 self.pressedkeys &~= KEY_FORWARD;
1850 self.pressedkeys &~= KEY_FORWARD;
1851 self.pressedkeys &~= KEY_BACKWARD;
1854 if (self.movement_y > 0)
1855 { // right key pressed
1856 self.pressedkeys |= KEY_RIGHT;
1857 self.pressedkeys &~= KEY_LEFT;
1859 else if (self.movement_y < 0)
1860 { // left key pressed
1861 self.pressedkeys |= KEY_LEFT;
1862 self.pressedkeys &~= KEY_RIGHT;
1866 self.pressedkeys &~= KEY_RIGHT;
1867 self.pressedkeys &~= KEY_LEFT;
1870 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1871 self.pressedkeys |= KEY_JUMP;
1873 self.pressedkeys &~= KEY_JUMP;
1874 if (self.BUTTON_CROUCH)
1875 self.pressedkeys |= KEY_CROUCH;
1877 self.pressedkeys &~= KEY_CROUCH;
1879 if (self.BUTTON_ATCK)
1880 self.pressedkeys |= KEY_ATCK;
1882 self.pressedkeys &~= KEY_ATCK;
1883 if (self.BUTTON_ATCK2)
1884 self.pressedkeys |= KEY_ATCK2;
1886 self.pressedkeys &~= KEY_ATCK2;
1890 ======================
1891 spectate mode routines
1892 ======================
1895 void SpectateCopy(entity spectatee) {
1897 MUTATOR_CALLHOOK(SpectateCopy);
1898 self.armortype = spectatee.armortype;
1899 self.armorvalue = spectatee.armorvalue;
1900 self.ammo_cells = spectatee.ammo_cells;
1901 self.ammo_shells = spectatee.ammo_shells;
1902 self.ammo_nails = spectatee.ammo_nails;
1903 self.ammo_rockets = spectatee.ammo_rockets;
1904 self.ammo_fuel = spectatee.ammo_fuel;
1905 self.clip_load = spectatee.clip_load;
1906 self.clip_size = spectatee.clip_size;
1907 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1908 self.health = spectatee.health;
1910 self.items = spectatee.items;
1911 self.last_pickup = spectatee.last_pickup;
1912 self.hit_time = spectatee.hit_time;
1913 self.metertime = spectatee.metertime;
1914 self.strength_finished = spectatee.strength_finished;
1915 self.invincible_finished = spectatee.invincible_finished;
1916 self.pressedkeys = spectatee.pressedkeys;
1917 WEPSET_COPY_EE(self, spectatee);
1918 self.switchweapon = spectatee.switchweapon;
1919 self.switchingweapon = spectatee.switchingweapon;
1920 self.weapon = spectatee.weapon;
1921 self.nex_charge = spectatee.nex_charge;
1922 self.nex_chargepool_ammo = spectatee.nex_chargepool_ammo;
1923 self.hagar_load = spectatee.hagar_load;
1924 self.minelayer_mines = spectatee.minelayer_mines;
1925 self.punchangle = spectatee.punchangle;
1926 self.view_ofs = spectatee.view_ofs;
1927 self.velocity = spectatee.velocity;
1928 self.dmg_take = spectatee.dmg_take;
1929 self.dmg_save = spectatee.dmg_save;
1930 self.dmg_inflictor = spectatee.dmg_inflictor;
1931 self.v_angle = spectatee.v_angle;
1932 self.angles = spectatee.v_angle;
1933 self.stat_respawn_time = spectatee.stat_respawn_time;
1934 if(!self.BUTTON_USE)
1935 self.fixangle = TRUE;
1936 setorigin(self, spectatee.origin);
1937 setsize(self, spectatee.mins, spectatee.maxs);
1938 SetZoomState(spectatee.zoomstate);
1940 anticheat_spectatecopy(spectatee);
1941 self.hud = spectatee.hud;
1942 if(spectatee.vehicle)
1944 self.fixangle = FALSE;
1945 //self.velocity = spectatee.vehicle.velocity;
1946 self.vehicle_health = spectatee.vehicle_health;
1947 self.vehicle_shield = spectatee.vehicle_shield;
1948 self.vehicle_energy = spectatee.vehicle_energy;
1949 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
1950 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
1951 self.vehicle_reload1 = spectatee.vehicle_reload1;
1952 self.vehicle_reload2 = spectatee.vehicle_reload2;
1956 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1957 WriteAngle(MSG_ONE, spectatee.v_angle_x);
1958 WriteAngle(MSG_ONE, spectatee.v_angle_y);
1959 WriteAngle(MSG_ONE, spectatee.v_angle_z);
1961 //WriteByte (MSG_ONE, SVC_SETVIEW);
1962 // WriteEntity(MSG_ONE, self);
1963 //makevectors(spectatee.v_angle);
1964 //setorigin(self, spectatee.origin - v_forward * 400 + v_up * 300);*/
1968 float SpectateUpdate() {
1972 if (self == self.enemy)
1975 if(self.enemy.classname != "player")
1978 SpectateCopy(self.enemy);
1984 // Returns next available player to spectate if g_ca_spectate_enemies == 0
1985 entity CA_SpectateNext(entity start) {
1986 if (start.team == self.team) {
1991 // continue from current player
1992 while(other && other.team != self.team) {
1993 other = find(other, classname, "player");
1997 // restart from begining
1998 other = find(other, classname, "player");
1999 while(other && other.team != self.team) {
2000 other = find(other, classname, "player");
2007 float SpectateNext(entity _prefer) {
2012 other = find(self.enemy, classname, "player");
2014 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer) {
2015 // CA and ca players when spectating enemies is forbidden
2016 other = CA_SpectateNext(other);
2018 // other modes and ca spectators or spectating enemies is allowed
2020 other = find(other, classname, "player");
2026 if(self.enemy.classname == "player") {
2027 /*if(self.enemy.vehicle)
2031 WriteByte(MSG_ONE, SVC_SETVIEW);
2032 WriteEntity(MSG_ONE, self.enemy);
2033 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2035 self.movetype = MOVETYPE_NONE;
2036 accuracy_resend(self);
2041 WriteByte(MSG_ONE, SVC_SETVIEW);
2042 WriteEntity(MSG_ONE, self.enemy);
2043 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2044 self.movetype = MOVETYPE_NONE;
2045 accuracy_resend(self);
2047 if(!SpectateUpdate())
2048 PutObserverInServer();
2058 ShowRespawnCountdown()
2060 Update a respawn countdown display.
2063 void ShowRespawnCountdown()
2066 if(self.deadflag == DEAD_NO) // just respawned?
2070 number = ceil(self.respawn_time - time);
2073 if(number <= self.respawn_countdown)
2075 self.respawn_countdown = number - 1;
2076 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
2077 AnnounceTo(self, strcat(ftos(number), ""));
2082 .float prevent_join_msgtime;
2083 void LeaveSpectatorMode()
2085 if(nJoinAllowed(self)) {
2086 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0) {
2087 self.classname = "player";
2089 if(autocvar_g_campaign || autocvar_g_balance_teams)
2090 JoinBestTeam(self, FALSE, TRUE);
2092 if(autocvar_g_campaign)
2093 campaign_bots_may_start = 1;
2095 PutClientInServer();
2097 if(self.classname == "player")
2098 bprint ("^4", self.netname, "^4 is playing now\n");
2100 if(!autocvar_g_campaign)
2101 if (time < self.jointime + autocvar_welcome_message_time)
2102 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD); // clear MOTD
2104 if (self.prevent_join_msgtime)
2106 Send_CSQC_Centerprint_Generic_Expire(self, CPID_PREVENT_JOIN);
2107 self.prevent_join_msgtime = 0;
2112 if (g_ca && self.caplayer) {
2115 stuffcmd(self,"menu_showteamselect\n");
2120 //player may not join because of g_maxplayers is set
2121 if (time - self.prevent_join_msgtime > 2)
2123 Send_CSQC_Centerprint_Generic(self, CPID_PREVENT_JOIN, PREVENT_JOIN_TEXT, 0, 0);
2124 self.prevent_join_msgtime = time;
2130 * Determines whether the player is allowed to join. This depends on cvar
2131 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2132 * it checks whether the number of currently playing players exceeds g_maxplayers.
2133 * @return int number of free slots for players, 0 if none
2135 float nJoinAllowed(entity ignore) {
2137 // this is called that way when checking if anyone may be able to join (to build qcstatus)
2138 // so report 0 free slots if restricted
2140 if(autocvar_g_forced_team_otherwise == "spectate")
2142 if(autocvar_g_forced_team_otherwise == "spectator")
2146 if(self.team_forced < 0)
2147 return 0; // forced spectators can never join
2149 // TODO simplify this
2151 float totalClients = 0;
2156 if (!autocvar_g_maxplayers)
2157 return maxclients - totalClients;
2159 float currentlyPlaying = 0;
2160 FOR_EACH_REALPLAYER(e)
2161 currentlyPlaying += 1;
2163 if(currentlyPlaying < autocvar_g_maxplayers)
2164 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
2170 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2171 * g_maxplayers_spectator_blocktime seconds
2173 void checkSpectatorBlock() {
2174 if(self.classname == "spectator" || self.classname == "observer") {
2175 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2176 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2182 .float motd_actived_time; // used for both motd and campaign_message
2183 void PrintWelcomeMessage()
2185 if (self.motd_actived_time == 0) { // is there already a message showing?
2186 if (autocvar_g_campaign) {
2187 if ((self.classname == "player" && self.BUTTON_INFO) || (self.classname != "player")) {
2188 self.motd_actived_time = time;
2189 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, campaign_message, -1, 0);
2192 if ((time - self.jointime > autocvar_welcome_message_time) && self.BUTTON_INFO) {
2193 self.motd_actived_time = time;
2194 Send_CSQC_Centerprint_Generic(self, CPID_MOTD, getwelcomemessage(), -1, 0);
2197 } else { // showing MOTD or campaign message
2198 if (autocvar_g_campaign) {
2199 if (self.BUTTON_INFO)
2200 self.motd_actived_time = time;
2201 else if ((time - self.motd_actived_time > 2) && self.classname == "player") { // hide it some seconds after BUTTON_INFO has been released
2202 self.motd_actived_time = 0;
2203 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2206 if ((time - self.jointime) > autocvar_welcome_message_time) {
2207 if (self.BUTTON_INFO)
2208 self.motd_actived_time = time;
2209 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2210 self.motd_actived_time = 0;
2211 Send_CSQC_Centerprint_Generic_Expire(self, CPID_MOTD);
2218 void ObserverThink()
2220 float prefered_movetype;
2221 if (self.flags & FL_JUMPRELEASED) {
2222 if (self.BUTTON_JUMP && !self.version_mismatch) {
2223 self.flags &~= FL_JUMPRELEASED;
2224 self.flags |= FL_SPAWNING;
2225 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2226 self.flags &~= FL_JUMPRELEASED;
2227 if(SpectateNext(world) == 1) {
2228 self.classname = "spectator";
2231 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2232 if (self.movetype != prefered_movetype)
2233 self.movetype = prefered_movetype;
2236 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2237 self.flags |= FL_JUMPRELEASED;
2238 if(self.flags & FL_SPAWNING)
2240 self.flags &~= FL_SPAWNING;
2241 LeaveSpectatorMode();
2247 PrintWelcomeMessage();
2250 void SpectatorThink()
2252 if (self.flags & FL_JUMPRELEASED) {
2253 if (self.BUTTON_JUMP && !self.version_mismatch) {
2254 self.flags &~= FL_JUMPRELEASED;
2255 self.flags |= FL_SPAWNING;
2256 } else if(self.BUTTON_ATCK) {
2257 self.flags &~= FL_JUMPRELEASED;
2258 if(SpectateNext(world) == 1) {
2259 self.classname = "spectator";
2261 self.classname = "observer";
2262 PutClientInServer();
2264 } else if (self.BUTTON_ATCK2) {
2265 self.flags &~= FL_JUMPRELEASED;
2266 self.classname = "observer";
2267 PutClientInServer();
2269 if(!SpectateUpdate())
2270 PutObserverInServer();
2273 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2274 self.flags |= FL_JUMPRELEASED;
2275 if(self.flags & FL_SPAWNING)
2277 self.flags &~= FL_SPAWNING;
2278 LeaveSpectatorMode();
2282 if(!SpectateUpdate())
2283 PutObserverInServer();
2286 PrintWelcomeMessage();
2287 self.flags |= FL_CLIENT | FL_NOTARGET;
2292 if(self.classname != "player")
2297 vehicles_exit(VHEF_NORMAL);
2301 // a use key was pressed; call handlers
2302 MUTATOR_CALLHOOK(PlayerUseKey);
2305 .float touchexplode_time;
2311 Called every frame for each client before the physics are run
2314 .float usekeypressed;
2315 void() nexball_setstatus;
2317 void PlayerPreThink (void)
2319 WarpZone_PlayerPhysics_FixVAngle();
2321 self.stat_game_starttime = game_starttime;
2322 self.stat_allow_oldnexbeam = autocvar_g_allow_oldnexbeam;
2323 self.stat_leadlimit = autocvar_leadlimit;
2325 if(g_arena || (g_ca && !allowed_to_spawn))
2326 self.stat_respawn_time = 0;
2328 self.stat_respawn_time = self.respawn_time;
2332 // physics frames: update anticheat stuff
2333 anticheat_prethink();
2336 if(blockSpectators && frametime)
2337 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2338 checkSpectatorBlock();
2342 if(self.netname_previous != self.netname)
2344 if(autocvar_sv_eventlog)
2345 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2346 if(self.netname_previous)
2347 strunzone(self.netname_previous);
2348 self.netname_previous = strzone(self.netname);
2352 if(self.version_nagtime)
2353 if(self.cvar_g_xonoticversion)
2354 if(time > self.version_nagtime)
2356 // don't notify git users
2357 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2359 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2361 // notify release users if connecting to git
2362 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");
2363 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, " (beta)^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2368 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2371 // give users new version
2372 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");
2373 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"));
2377 // notify users about old server version
2378 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");
2379 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Xonotic ", autocvar_g_xonoticversion, "^7, you have ^3Xonotic ", self.cvar_g_xonoticversion, "^1\n"));
2383 self.version_nagtime = 0;
2387 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2389 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2390 self.max_armorvalue = 0;
2394 if (TetrisPreFrame())
2398 MUTATOR_CALLHOOK(PlayerPreThink);
2400 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2402 if(self.BUTTON_USE && !self.usekeypressed)
2404 self.usekeypressed = self.BUTTON_USE;
2407 PrintWelcomeMessage();
2409 if(self.classname == "player") {
2410 // if(self.netname == "Wazat")
2411 // bprint(self.classname, "\n");
2413 CheckRules_Player();
2415 if (intermission_running)
2417 IntermissionThink (); // otherwise a button could be missed between
2418 return; // the think tics
2421 //don't allow the player to turn around while game is paused!
2422 if(timeout_status == TIMEOUT_ACTIVE) {
2423 // FIXME turn this into CSQC stuff
2424 self.v_angle = self.lastV_angle;
2425 self.angles = self.lastV_angle;
2426 self.fixangle = TRUE;
2431 #ifndef NO_LEGACY_NETWORKING
2432 self.glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2435 if(self.weapon == WEP_NEX && autocvar_g_balance_nex_charge)
2437 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);
2438 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);
2439 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);
2441 if(self.nex_charge > autocvar_g_balance_nex_charge_animlimit)
2443 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);
2444 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);
2445 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);
2449 self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2455 minstagib_ammocheck();
2457 if (self.deadflag != DEAD_NO)
2459 float button_pressed, force_respawn;
2460 if(self.personal && g_race_qualifying)
2462 if(time > self.respawn_time)
2464 self.respawn_time = time + 1; // only retry once a second
2473 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2474 force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
2475 if (self.deadflag == DEAD_DYING)
2478 self.deadflag = DEAD_RESPAWNING;
2479 else if(!button_pressed)
2480 self.deadflag = DEAD_DEAD;
2482 else if (self.deadflag == DEAD_DEAD)
2485 self.deadflag = DEAD_RESPAWNABLE;
2487 else if (self.deadflag == DEAD_RESPAWNABLE)
2490 self.deadflag = DEAD_RESPAWNING;
2492 else if (self.deadflag == DEAD_RESPAWNING)
2494 if(time > self.respawn_time)
2496 self.respawn_time = time + 1; // only retry once a second
2500 ShowRespawnCountdown();
2503 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2504 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2505 self.stat_respawn_time *= -1;
2509 // FIXME from now on self.deadflag is always 0 (and self.health is never < 1)
2510 // so (self.deadflag == DEAD_NO) is always true in the code below
2513 if(time > self.touchexplode_time)
2514 if(self.classname == "player")
2515 if(self.deadflag == DEAD_NO)
2516 if not(IS_INDEPENDENT_PLAYER(self))
2517 FOR_EACH_PLAYER(other) if(self != other)
2519 if(time > other.touchexplode_time)
2520 if(other.deadflag == DEAD_NO)
2521 if not(IS_INDEPENDENT_PLAYER(other))
2522 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2524 PlayerTouchExplode(self, other);
2525 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2529 if(g_lms && !self.deadflag && autocvar_g_lms_campcheck_interval)
2533 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2534 dist = self.prevorigin - self.origin;
2536 self.lms_traveled_distance += fabs(vlen(dist));
2538 if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime))
2540 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval*2;
2541 self.lms_traveled_distance = 0;
2544 if(time > self.lms_nextcheck)
2546 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2547 if(self.lms_traveled_distance < autocvar_g_lms_campcheck_distance)
2549 centerprint(self, autocvar_g_lms_campcheck_message);
2550 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2551 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2552 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');
2554 self.lms_nextcheck = time + autocvar_g_lms_campcheck_interval;
2555 self.lms_traveled_distance = 0;
2559 self.prevorigin = self.origin;
2562 if (((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss) && self.animstate_startframe != self.anim_melee_x && !self.freezetag_frozen) // prevent crouching if using melee attack
2567 self.view_ofs = PL_CROUCH_VIEW_OFS;
2568 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2569 // setanim(self, self.anim_duck, FALSE, TRUE, TRUE); // this anim is BROKEN anyway
2576 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2577 if (!trace_startsolid)
2579 self.crouch = FALSE;
2580 self.view_ofs = PL_VIEW_OFS;
2581 setsize (self, PL_MIN, PL_MAX);
2586 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2588 if(self.bloodloss_timer < time)
2590 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2591 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2597 GrapplingHookFrame();
2599 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2602 self.items &~= self.items_added;
2606 self.items_added = 0;
2607 if(self.items & IT_JETPACK)
2608 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2609 self.items_added |= IT_FUEL;
2611 self.items |= self.items_added;
2616 // rot nex charge to the charge limit
2617 if(autocvar_g_balance_nex_charge_rot_rate && self.nex_charge > autocvar_g_balance_nex_charge_limit && self.nex_charge_rottime < time)
2618 self.nex_charge = bound(autocvar_g_balance_nex_charge_limit, self.nex_charge - autocvar_g_balance_nex_charge_rot_rate * frametime / W_TICSPERFRAME, 1);
2624 nexball_setstatus();
2627 secrets_setstatus();
2629 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2631 //self.angles_y=self.v_angle_y + 90; // temp
2632 } else if(gameover) {
2633 if (intermission_running)
2634 IntermissionThink (); // otherwise a button could be missed between
2636 } else if(self.classname == "observer") {
2638 } else if(self.classname == "spectator") {
2643 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));
2645 float oldspectatee_status;
2646 oldspectatee_status = self.spectatee_status;
2647 if(self.classname == "spectator")
2648 self.spectatee_status = num_for_edict(self.enemy);
2649 else if(self.classname == "observer")
2650 self.spectatee_status = num_for_edict(self);
2652 self.spectatee_status = 0;
2653 if(self.spectatee_status != oldspectatee_status)
2655 ClientData_Touch(self);
2657 race_InitSpectator();
2660 if(self.teamkill_soundtime)
2661 if(time > self.teamkill_soundtime)
2663 self.teamkill_soundtime = 0;
2665 entity oldpusher, oldself;
2667 oldself = self; self = self.teamkill_soundsource;
2668 oldpusher = self.pusher; self.pusher = oldself;
2670 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2672 self.pusher = oldpusher;
2676 if(self.taunt_soundtime)
2677 if(time > self.taunt_soundtime)
2679 self.taunt_soundtime = 0;
2680 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2683 target_voicescript_next(self);
2685 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2687 self.clip_load = self.clip_size = 0;
2690 float isInvisibleString(string s)
2693 s = strdecolorize(s);
2694 for((i = 0), (n = strlen(s)); i < n; ++i)
2702 case 192: // charmap space
2703 if (!autocvar_utf8_enable)
2706 case 160: // space in unicode fonts
2707 case 0xE000 + 192: // utf8 charmap space
2708 if (autocvar_utf8_enable)
2721 Called every frame for each client after the physics are run
2724 .float idlekick_lasttimeleft;
2725 .entity showheadshotbbox;
2726 void showheadshotbbox_think()
2728 if(self.owner.showheadshotbbox != self)
2733 self.nextthink = time;
2734 setorigin(self, self.owner.origin);
2735 setsize(self, GetHeadshotMins(self.owner), GetHeadshotMaxs(self.owner));
2737 void PlayerPostThink (void)
2739 // Savage: Check for nameless players
2740 if (isInvisibleString(self.netname)) {
2741 self.netname = "Player";
2742 stuffcmd(self, strcat("name ", self.netname, substring(ftos(random()), 2, -1), "\n"));
2745 if(sv_maxidle && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2747 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2749 if(self.idlekick_lasttimeleft)
2751 Send_CSQC_Centerprint_Generic_Expire(self, CPID_DISCONNECT_IDLING);
2752 self.idlekick_lasttimeleft = 0;
2758 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2759 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2761 if(!self.idlekick_lasttimeleft)
2762 Send_CSQC_Centerprint_Generic(self, CPID_DISCONNECT_IDLING, "^3Stop idling!\n^3Disconnecting in %d seconds...", 1, timeleft);
2766 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2767 AnnounceTo(self, "terminated");
2771 else if(timeleft <= 10)
2773 if(timeleft != self.idlekick_lasttimeleft)
2774 AnnounceTo(self, ftos(timeleft));
2775 self.idlekick_lasttimeleft = timeleft;
2781 if(self.impulse == 100)
2783 if (!TetrisPostFrame())
2789 //CheckPlayerJump();
2791 if(self.classname == "player") {
2792 CheckRules_Player();
2796 if (intermission_running)
2797 return; // intermission or finale
2807 for(i = 0; i < 1000; ++i)
2810 end = self.origin + '0 0 1024' + 512 * randomvec();
2811 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2812 if(trace_fraction < 1)
2813 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2815 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2821 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
2823 if(self.waypointsprite_attachedforcarrier)
2824 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent));
2826 if(self.classname == "player" && self.deadflag == DEAD_NO && autocvar_r_showbboxes)
2828 if(!self.showheadshotbbox)
2830 self.showheadshotbbox = spawn();
2831 self.showheadshotbbox.classname = "headshotbbox";
2832 self.showheadshotbbox.owner = self;
2833 self.showheadshotbbox.think = showheadshotbbox_think;
2834 self.showheadshotbbox.nextthink = time;
2835 self = self.showheadshotbbox;
2842 if(self.showheadshotbbox)
2843 if(self.showheadshotbbox && !wasfreed(self.showheadshotbbox))
2844 remove(self.showheadshotbbox);
2849 if((g_cts || g_race) && self.cvar_cl_allow_uidtracking == 1 && self.cvar_cl_allow_uid2name == 1)
2851 if not(self.stored_netname)
2852 self.stored_netname = strzone(uid2name(self.crypto_idfp));
2853 if(self.stored_netname != self.netname)
2855 db_put(ServerProgsDB, strcat("/uid2name/", self.crypto_idfp), self.netname);
2856 strunzone(self.stored_netname);
2857 self.stored_netname = strzone(self.netname);
2863 dprint(sprintf("%f %.6f\n", time, race_GetFractionalLapCount(self)));
2866 CSQCMODEL_AUTOUPDATE();