1 void send_CSQC_teamnagger() {
2 WriteByte(MSG_BROADCAST, SVC_TEMPENTITY);
3 WriteByte(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
6 float ClientData_Send(entity to, float sf)
23 sf |= 1; // forced scoreboard
24 if(to.spectatee_status)
25 sf |= 2; // spectator ent number follows
28 if(e.porto_v_angle_held)
29 sf |= 8; // angles held
31 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
32 WriteByte(MSG_ENTITY, sf);
35 WriteByte(MSG_ENTITY, to.spectatee_status);
39 WriteAngle(MSG_ENTITY, e.v_angle_x);
40 WriteAngle(MSG_ENTITY, e.v_angle_y);
46 void ClientData_Attach()
48 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
49 self.clientdata.drawonlytoclient = self;
50 self.clientdata.owner = self;
53 void ClientData_Detach()
55 remove(self.clientdata);
56 self.clientdata = world;
59 void ClientData_Touch(entity e)
61 e.clientdata.SendFlags = 1;
63 // make it spectatable
65 FOR_EACH_REALCLIENT(e2)
70 e2.clientdata.SendFlags = 1;
74 .string netname_previous;
76 void SetSpectator(entity player, entity spectatee);
83 Checks if the argument string can be a valid playermodel.
84 Returns a valid one in doubt.
87 string FallbackPlayerModel;
88 string CheckPlayerModel(string plyermodel) {
89 if(FallbackPlayerModel != cvar_defstring("_cl_playermodel"))
91 // note: we cannot summon Don Strunzone here, some player may
92 // still have the model string set. In case anyone manages how
93 // to change a cvar default, we'll have a small leak here.
94 FallbackPlayerModel = strzone(cvar_defstring("_cl_playermodel"));
97 if( substring(plyermodel,0,14) != "models/player/")
98 return FallbackPlayerModel;
99 // only good file extensions
100 if(substring(plyermodel,-4,4) != ".zym")
101 if(substring(plyermodel,-4,4) != ".dpm")
102 if(substring(plyermodel,-4,4) != ".iqm")
103 if(substring(plyermodel,-4,4) != ".md3")
104 if(substring(plyermodel,-4,4) != ".psk")
105 return FallbackPlayerModel;
106 // forbid the LOD models
107 if(substring(plyermodel, -9,5) == "_lod1")
108 return FallbackPlayerModel;
109 if(substring(plyermodel, -9,5) == "_lod2")
110 return FallbackPlayerModel;
111 if(plyermodel != strtolower(plyermodel))
112 return FallbackPlayerModel;
113 // also, restrict to server models
114 if(autocvar_sv_servermodelsonly)
116 if(!fexists(plyermodel))
117 return FallbackPlayerModel;
122 void setplayermodel(entity e, string modelname)
124 precache_model(modelname);
125 setmodel(e, modelname);
126 player_setupanimsformodel();
127 UpdatePlayerSounds();
134 putting a client as observer in the server
137 void FixPlayermodel();
138 void PutObserverInServer (void)
141 self.hud = HUD_NORMAL;
143 if(IS_PLAYER(self)) { pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1); }
145 spot = SelectSpawnPoint (TRUE);
147 error("No spawnpoints for observers?!?\n");
148 RemoveGrapplingHook(self); // Wazat's Grappling Hook
150 if(IS_REAL_CLIENT(self))
153 WriteByte(MSG_ONE, SVC_SETVIEW);
154 WriteEntity(MSG_ONE, self);
157 self.frags = FRAGS_SPECTATOR;
159 MUTATOR_CALLHOOK(MakePlayerObserver);
161 Portal_ClearAll(self);
168 PS_GR_P_ADDVAL(self, PLAYERSTATS_ALIVETIME, time - self.alivetime);
173 vehicles_exit(VHEF_RELEASE);
175 WaypointSprite_PlayerDead();
177 if (!g_ca) // don't reset teams when moving a ca player to the spectators
178 self.team = -1; // move this as it is needed to log the player spectating in eventlog
180 if(self.killcount != -666)
182 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_SPECTATE, self.netname);
183 if(autocvar_g_chat_nospectators == 1 || (cvar("g_warmup") && !(warmup_stage || gameover) && autocvar_g_chat_nospectators == 2))
184 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CHAT_NOSPECTATORS);
186 if(self.just_joined == FALSE) {
187 LogTeamchange(self.playerid, -1, 4);
189 self.just_joined = FALSE;
192 PlayerScore_Clear(self); // clear scores when needed
194 accuracy_resend(self);
196 self.spectatortime = time;
198 self.classname = "observer";
199 self.iscreature = FALSE;
200 self.teleportable = TELEPORT_SIMPLE;
201 self.damagedbycontents = FALSE;
203 self.takedamage = DAMAGE_NO;
204 self.solid = SOLID_NOT;
205 self.movetype = MOVETYPE_FLY_WORLDONLY; // user preference is controlled by playerprethink
206 self.flags = FL_CLIENT | FL_NOTARGET;
207 self.armorvalue = 666;
209 self.armorvalue = autocvar_g_balance_armor_start;
210 self.pauserotarmor_finished = 0;
211 self.pauserothealth_finished = 0;
212 self.pauseregen_finished = 0;
213 self.damageforcescale = 0;
215 self.respawn_flags = 0;
216 self.respawn_time = 0;
217 self.stat_respawn_time = 0;
222 self.pain_finished = 0;
223 self.strength_finished = 0;
224 self.invincible_finished = 0;
225 self.superweapons_finished = 0;
228 self.think = func_null;
231 self.deadflag = DEAD_NO;
232 self.angles = spot.angles;
234 self.fixangle = TRUE;
236 self.revival_time = 0;
238 setorigin (self, (spot.origin + PL_VIEW_OFS)); // offset it so that the spectator spawns higher off the ground, looks better this way
239 self.prevorigin = self.origin;
241 self.weapons = '0 0 0';
244 setmodel(self, "null");
245 self.drawonlytoclient = self;
247 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX); // give the spectator some space between walls for MOVETYPE_FLY_WORLDONLY
248 self.view_ofs = '0 0 0'; // so that your view doesn't go into the ceiling with MOVETYPE_FLY_WORLDONLY, previously "PL_VIEW_OFS"
251 self.weaponname = "";
252 self.switchingweapon = 0;
253 self.weaponmodel = "";
254 self.weaponentity = world;
255 self.exteriorweaponentity = world;
256 self.killcount = -666;
257 self.velocity = '0 0 0';
258 self.avelocity = '0 0 0';
259 self.punchangle = '0 0 0';
260 self.punchvector = '0 0 0';
261 self.oldvelocity = self.velocity;
262 self.fire_endtime = -1;
263 self.event_damage = func_null;
266 .float model_randomizer;
267 void FixPlayermodel()
270 float defaultskin, chmdl, oldskin, n, i;
277 if(autocvar_sv_defaultcharacter == 1)
282 s = Static_Team_ColorName_Lower(self.team);
285 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", s));
286 defaultskin = cvar(strcat("sv_defaultplayerskin_", s));
290 if(defaultmodel == "")
292 defaultmodel = autocvar_sv_defaultplayermodel;
293 defaultskin = autocvar_sv_defaultplayerskin;
296 n = tokenize_console(defaultmodel);
299 defaultmodel = argv(floor(n * self.model_randomizer));
300 // However, do NOT randomize if the player-selected model is in the list.
301 for (i = 0; i < n; ++i)
302 if ((argv(i) == self.playermodel && defaultskin == stof(self.playerskin)) || argv(i) == strcat(self.playermodel, ":", self.playerskin))
303 defaultmodel = argv(i);
306 i = strstrofs(defaultmodel, ":", 0);
309 defaultskin = stof(substring(defaultmodel, i+1, -1));
310 defaultmodel = substring(defaultmodel, 0, i);
314 if(defaultmodel != "")
316 if (defaultmodel != self.model)
320 setplayermodel (self, defaultmodel);
321 setsize (self, m1, m2);
326 self.skin = defaultskin;
328 if (self.playermodel != self.model || self.playermodel == "")
330 self.playermodel = CheckPlayerModel(self.playermodel); // this is never "", so no endless loop
333 setplayermodel (self, self.playermodel);
334 setsize (self, m1, m2);
339 self.skin = stof(self.playerskin);
342 if(chmdl || oldskin != self.skin) // model or skin has changed
344 self.species = player_getspecies(); // update species
345 UpdatePlayerSounds(); // update skin sounds
349 if(strlen(autocvar_sv_defaultplayercolors))
350 if(self.clientcolors != stof(autocvar_sv_defaultplayercolors))
351 setcolor(self, stof(autocvar_sv_defaultplayercolors));
358 Called when a client spawns in the server
361 void PutClientInServer (void)
363 if(IS_BOT_CLIENT(self))
364 self.classname = "player";
365 else if(IS_REAL_CLIENT(self))
368 WriteByte(MSG_ONE, SVC_SETVIEW);
369 WriteEntity(MSG_ONE, self);
372 SetSpectator(self, world);
377 MUTATOR_CALLHOOK(PutClientInServer);
380 self.classname = "observer";
384 entity spot, oldself;
387 accuracy_resend(self);
390 JoinBestTeam(self, FALSE, TRUE);
392 spot = SelectSpawnPoint (FALSE);
395 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_NOSPAWNS);
396 return; // spawn failed
399 RemoveGrapplingHook(self); // Wazat's Grappling Hook
401 self.classname = "player";
402 self.wasplayer = TRUE;
403 self.iscreature = TRUE;
404 self.teleportable = TELEPORT_NORMAL;
405 self.damagedbycontents = TRUE;
406 self.movetype = MOVETYPE_WALK;
407 self.solid = SOLID_SLIDEBOX;
408 self.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID;
409 if(autocvar_g_playerclip_collisions)
410 self.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
411 if(IS_BOT_CLIENT(self) && autocvar_g_botclip_collisions)
412 self.dphitcontentsmask |= DPCONTENTS_BOTCLIP;
413 self.frags = FRAGS_PLAYER;
414 if(INDEPENDENT_PLAYERS)
415 MAKE_INDEPENDENT_PLAYER(self);
416 self.flags = FL_CLIENT;
417 if(autocvar__notarget)
418 self.flags |= FL_NOTARGET;
419 self.takedamage = DAMAGE_AIM;
421 self.effects |= EF_TELEPORT_BIT | EF_RESTARTANIM_BIT;
422 self.air_finished = time + 12;
424 if(WEP_CVAR(vortex, charge))
426 if(WEP_CVAR_SEC(vortex, chargepool))
427 self.vortex_chargepool_ammo = 1;
428 self.vortex_charge = WEP_CVAR(vortex, charge_start);
433 self.ammo_shells = warmup_start_ammo_shells;
434 self.ammo_nails = warmup_start_ammo_nails;
435 self.ammo_rockets = warmup_start_ammo_rockets;
436 self.ammo_cells = warmup_start_ammo_cells;
437 self.ammo_plasma = warmup_start_ammo_plasma;
438 self.ammo_fuel = warmup_start_ammo_fuel;
439 self.health = warmup_start_health;
440 self.armorvalue = warmup_start_armorvalue;
441 self.weapons = WARMUP_START_WEAPONS;
445 self.ammo_shells = start_ammo_shells;
446 self.ammo_nails = start_ammo_nails;
447 self.ammo_rockets = start_ammo_rockets;
448 self.ammo_cells = start_ammo_cells;
449 self.ammo_plasma = start_ammo_plasma;
450 self.ammo_fuel = start_ammo_fuel;
451 self.health = start_health;
452 self.armorvalue = start_armorvalue;
453 self.weapons = start_weapons;
456 if(self.weapons & WEPSET_SUPERWEAPONS)
457 self.superweapons_finished = time + autocvar_g_balance_superweapons_time;
459 self.superweapons_finished = 0;
461 if(g_weaponarena_random) // WEAPONTODO: more stuff that should be in a mutator. also: rename those cvars
463 if(g_weaponarena_random_with_blaster)
464 self.weapons &= ~WEPSET_BLASTER;
465 W_RandomWeapons(self, g_weaponarena_random);
466 if(g_weaponarena_random_with_blaster)
467 self.weapons |= WEPSET_BLASTER;
470 self.items = start_items;
472 self.spawnshieldtime = time + autocvar_g_spawnshieldtime;
473 self.pauserotarmor_finished = time + autocvar_g_balance_pause_armor_rot_spawn;
474 self.pauserothealth_finished = time + autocvar_g_balance_pause_health_rot_spawn;
475 self.pauserotfuel_finished = time + autocvar_g_balance_pause_fuel_rot_spawn;
476 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen_spawn;
477 //extend the pause of rotting if client was reset at the beginning of the countdown
478 if(!autocvar_sv_ready_restart_after_countdown && time < game_starttime) { // TODO why is this cvar NOTted?
479 self.spawnshieldtime += game_starttime - time;
480 self.pauserotarmor_finished += game_starttime - time;
481 self.pauserothealth_finished += game_starttime - time;
482 self.pauseregen_finished += game_starttime - time;
484 self.damageforcescale = 2;
486 self.respawn_flags = 0;
487 self.respawn_time = 0;
488 self.stat_respawn_time = 0;
492 self.pain_finished = 0;
493 self.strength_finished = 0;
494 self.invincible_finished = 0;
496 // players have no think function
497 self.think = func_null;
501 self.ballistics_density = autocvar_g_ballistics_density_player;
505 self.deadflag = DEAD_NO;
507 self.angles = spot.angles;
509 self.angles_z = 0; // never spawn tilted even if the spot says to
510 if(IS_BOT_CLIENT(self))
511 self.v_angle = self.angles;
512 self.fixangle = TRUE; // turn this way immediately
513 self.velocity = '0 0 0';
514 self.avelocity = '0 0 0';
515 self.punchangle = '0 0 0';
516 self.punchvector = '0 0 0';
517 self.oldvelocity = self.velocity;
518 self.fire_endtime = -1;
519 self.revival_time = 0;
521 entity spawnevent = spawn();
522 spawnevent.owner = self;
523 Net_LinkEntity(spawnevent, FALSE, 0.5, SpawnEvent_Send);
525 // Cut off any still running player sounds.
526 stopsound(self, CH_PLAYER_SINGLE);
530 self.drawonlytoclient = world;
533 self.view_ofs = PL_VIEW_OFS;
534 setsize (self, PL_MIN, PL_MAX);
535 self.spawnorigin = spot.origin;
536 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
537 // don't reset back to last position, even if new position is stuck in solid
538 self.oldorigin = self.origin;
539 self.prevorigin = self.origin;
540 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
541 self.lastteleporttime = time; // prevent insane speeds due to changing origin
542 self.hud = HUD_NORMAL;
544 self.event_damage = PlayerDamage;
546 self.bot_attack = TRUE;
547 self.monster_attack = TRUE;
549 self.spider_slowness = 0;
551 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
553 if(self.killcount == -666) {
554 PlayerScore_Clear(self);
558 CL_SpawnWeaponentity();
559 self.alpha = default_player_alpha;
560 self.colormod = '1 1 1' * autocvar_g_player_brightness;
561 self.exteriorweaponentity.alpha = default_weapon_alpha;
563 self.speedrunning = FALSE;
565 //stuffcmd(self, "chase_active 0");
566 //stuffcmd(self, "set viewsize $tmpviewsize \n");
568 target_voicescript_clear(self);
570 // reset fields the weapons may use
571 for (j = WEP_FIRST; j <= WEP_LAST; ++j)
573 WEP_ACTION(j, WR_RESETPLAYER);
575 // all weapons must be fully loaded when we spawn
577 e = get_weaponinfo(j);
578 if(e.spawnflags & WEP_FLAG_RELOADABLE) // prevent accessing undefined cvars
579 self.(weapon_load[j]) = e.reloading_ammo;
587 self.target = string_null;
596 MUTATOR_CALLHOOK(PlayerSpawn);
598 if(autocvar_spawn_debug)
600 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
601 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
604 self.switchweapon = w_getbestweapon(self);
605 self.cnt = -1; // W_LastWeapon will not complain
607 self.weaponname = "";
608 self.switchingweapon = 0;
612 self.alivetime = time;
616 else if(IS_OBSERVER(self))
618 PutObserverInServer ();
622 .float ebouncefactor, ebouncestop; // electro's values
623 // TODO do we need all these fields, or should we stop autodetecting runtime
624 // changes and just have a console command to update this?
625 float ClientInit_SendEntity(entity to, float sf)
627 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
628 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
629 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[0]));
630 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[1]));
631 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[2]));
632 WriteInt24_t(MSG_ENTITY, compressShotOrigin(hook_shotorigin[3]));
633 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[0]));
634 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[1]));
635 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[2]));
636 WriteInt24_t(MSG_ENTITY, compressShotOrigin(arc_shotorigin[3]));
638 if(sv_foginterval && world.fog != "")
639 WriteString(MSG_ENTITY, world.fog);
641 WriteString(MSG_ENTITY, "");
642 WriteByte(MSG_ENTITY, self.count * 255.0); // g_balance_armor_blockpercent
643 WriteCoord(MSG_ENTITY, self.bouncefactor); // g_balance_mortar_bouncefactor // WEAPONTODO
644 WriteCoord(MSG_ENTITY, self.bouncestop); // g_balance_mortar_bouncestop
645 WriteCoord(MSG_ENTITY, self.ebouncefactor); // g_balance_mortar_bouncefactor
646 WriteCoord(MSG_ENTITY, self.ebouncestop); // g_balance_mortar_bouncestop
647 WriteByte(MSG_ENTITY, WEP_CVAR(vortex, secondary)); // client has to know if it should zoom or not // WEAPONTODO
648 WriteByte(MSG_ENTITY, WEP_CVAR(rifle, secondary)); // client has to know if it should zoom or not // WEAPONTODO
649 WriteByte(MSG_ENTITY, serverflags); // client has to know if it should zoom or not
650 WriteByte(MSG_ENTITY, WEP_CVAR(minelayer, limit)); // minelayer max mines // WEAPONTODO
651 WriteByte(MSG_ENTITY, WEP_CVAR_SEC(hagar, load_max)); // hagar max loadable rockets // WEAPONTODO
652 WriteCoord(MSG_ENTITY, autocvar_g_trueaim_minrange);
653 WriteByte(MSG_ENTITY, WEP_CVAR(porto, secondary)); // WEAPONTODO
657 void ClientInit_CheckUpdate()
659 self.nextthink = time;
660 if(self.count != autocvar_g_balance_armor_blockpercent)
662 self.count = autocvar_g_balance_armor_blockpercent;
665 if(self.bouncefactor != autocvar_g_balance_mortar_bouncefactor) // WEAPONTODO
667 self.bouncefactor = autocvar_g_balance_mortar_bouncefactor;
670 if(self.bouncestop != autocvar_g_balance_mortar_bouncestop)
672 self.bouncestop = autocvar_g_balance_mortar_bouncestop;
675 if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
677 self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
680 if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
682 self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
687 void ClientInit_Spawn()
692 e.classname = "clientinit";
693 e.think = ClientInit_CheckUpdate;
694 Net_LinkEntity(e, FALSE, 0, ClientInit_SendEntity);
698 ClientInit_CheckUpdate();
707 void SetNewParms (void)
709 // initialize parms for a new player
710 parm1 = -(86400 * 366);
718 void SetChangeParms (void)
720 // save parms for level change
721 parm1 = self.parm_idlesince - time;
729 void DecodeLevelParms (void)
732 self.parm_idlesince = parm1;
733 if(self.parm_idlesince == -(86400 * 366))
734 self.parm_idlesince = time;
736 // whatever happens, allow 60 seconds of idling directly after connect for map loading
737 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
744 Called when a client types 'kill' in the console
748 .float clientkill_nexttime;
749 void ClientKill_Now_TeamChange()
751 if(self.killindicator_teamchange == -1)
753 JoinBestTeam( self, FALSE, TRUE );
755 else if(self.killindicator_teamchange == -2)
758 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
759 PutObserverInServer();
762 SV_ChangeTeam(self.killindicator_teamchange - 1);
763 self.killindicator_teamchange = 0;
766 void ClientKill_Now()
770 vehicles_exit(VHEF_RELEASE);
771 if(!self.killindicator_teamchange)
773 self.vehicle_health = -1;
774 Damage(self, self, self, 1 , DEATH_KILL, self.origin, '0 0 0');
778 if(self.killindicator && !wasfreed(self.killindicator))
779 remove(self.killindicator);
781 self.killindicator = world;
783 if(self.killindicator_teamchange)
784 ClientKill_Now_TeamChange();
787 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
789 // now I am sure the player IS dead
791 void KillIndicator_Think()
795 self.owner.killindicator = world;
800 if (self.owner.alpha < 0 && !self.owner.vehicle)
802 self.owner.killindicator = world;
810 ClientKill_Now(); // no oldself needed
813 else if(g_cts && self.health == 1) // health == 1 means that it's silent
815 self.nextthink = time + 1;
821 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
822 if(IS_REAL_CLIENT(self.owner))
825 { Send_Notification(NOTIF_ONE, self.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, self.cnt)); }
827 self.nextthink = time + 1;
832 float clientkilltime;
833 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2 = spec
842 killtime = autocvar_g_balance_kill_delay;
844 if(g_race_qualifying || g_cts)
847 if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
849 remove(self.killindicator);
850 self.killindicator = world;
852 ClientKill_Now(); // allow instant kill in this case
856 self.killindicator_teamchange = targetteam;
858 if(!self.killindicator)
860 if(self.deadflag == DEAD_NO)
862 killtime = max(killtime, self.clientkill_nexttime - time);
863 self.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
866 if(killtime <= 0 || !IS_PLAYER(self) || self.deadflag != DEAD_NO)
872 starttime = max(time, clientkilltime);
874 self.killindicator = spawn();
875 self.killindicator.owner = self;
876 self.killindicator.scale = 0.5;
877 setattachment(self.killindicator, self, "");
878 setorigin(self.killindicator, '0 0 52');
879 self.killindicator.think = KillIndicator_Think;
880 self.killindicator.nextthink = starttime + (self.lip) * 0.05;
881 clientkilltime = max(clientkilltime, self.killindicator.nextthink + 0.05);
882 self.killindicator.cnt = ceil(killtime);
883 self.killindicator.count = bound(0, ceil(killtime), 10);
884 //sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
886 for(e = world; (e = find(e, classname, "body")) != world; )
890 e.killindicator = spawn();
891 e.killindicator.owner = e;
892 e.killindicator.scale = 0.5;
893 setattachment(e.killindicator, e, "");
894 setorigin(e.killindicator, '0 0 52');
895 e.killindicator.think = KillIndicator_Think;
896 e.killindicator.nextthink = starttime + (e.lip) * 0.05;
897 clientkilltime = max(clientkilltime, e.killindicator.nextthink + 0.05);
898 e.killindicator.cnt = ceil(killtime);
903 if(self.killindicator)
905 if(targetteam == 0) // just die
907 self.killindicator.colormod = '0 0 0';
908 if(IS_REAL_CLIENT(self))
909 if(self.killindicator.cnt > 0)
910 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SUICIDE, self.killindicator.cnt);
912 else if(targetteam == -1) // auto
914 self.killindicator.colormod = '0 1 0';
915 if(IS_REAL_CLIENT(self))
916 if(self.killindicator.cnt > 0)
917 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_AUTO, self.killindicator.cnt);
919 else if(targetteam == -2) // spectate
921 self.killindicator.colormod = '0.5 0.5 0.5';
922 if(IS_REAL_CLIENT(self))
923 if(self.killindicator.cnt > 0)
924 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_TEAMCHANGE_SPECTATE, self.killindicator.cnt);
928 self.killindicator.colormod = Team_ColorRGB(targetteam);
929 if(IS_REAL_CLIENT(self))
930 if(self.killindicator.cnt > 0)
931 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, APP_TEAM_NUM_4(targetteam, CENTER_TEAMCHANGE_), self.killindicator.cnt);
937 void ClientKill (void)
940 if(self.player_blocked) return;
941 if(self.frozen) return;
943 ClientKill_TeamChange(0);
946 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
948 e.killindicator = spawn();
949 e.killindicator.owner = e;
950 e.killindicator.think = KillIndicator_Think;
951 e.killindicator.nextthink = time + (e.lip) * 0.05;
952 e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
953 e.killindicator.health = 1; // this is used to indicate that it should be silent
957 void FixClientCvars(entity e)
959 // send prediction settings to the client
960 stuffcmd(e, "\nin_bindmap 0 0\n");
962 stuffcmd(e, "cl_cmd settemp cl_movecliptokeyboard 2\n");
963 if(autocvar_g_antilag == 3) // client side hitscan
964 stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
965 if(autocvar_sv_gentle)
966 stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
969 float PlayerInIDList(entity p, string idlist)
974 // NOTE: we do NOT check crypto_keyfp here, an unsigned ID is fine too for this
978 // this function allows abbreviated player IDs too!
979 n = tokenize_console(idlist);
980 for(i = 0; i < n; ++i)
983 if(s == substring(p.crypto_idfp, 0, strlen(s)))
994 Called when a client connects to the server
997 void DecodeLevelParms (void);
998 //void dom_player_join_team(entity pl);
999 void set_dom_state(entity e);
1000 void ClientConnect (void)
1006 print("Warning: ClientConnect, but already connected!\n");
1010 if(Ban_MaybeEnforceBanOnce(self))
1016 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_WATERMARK, WATERMARK);
1019 self.classname = "player_joining";
1021 self.flags = FL_CLIENT;
1022 self.version_nagtime = time + 10 + random() * 10;
1026 dprint("BUG player count is lower than zero, this cannot happen!\n");
1030 if(IS_REAL_CLIENT(self)) { PlayerStats_PlayerBasic_CheckUpdate(self); }
1032 PlayerScore_Attach(self);
1033 ClientData_Attach();
1034 accuracy_init(self);
1036 bot_clientconnect();
1042 // identify the right forced team
1043 if(autocvar_g_campaign)
1045 if(IS_REAL_CLIENT(self)) // only players, not bots
1047 switch(autocvar_g_campaign_forceteam)
1049 case 1: self.team_forced = NUM_TEAM_1; break;
1050 case 2: self.team_forced = NUM_TEAM_2; break;
1051 case 3: self.team_forced = NUM_TEAM_3; break;
1052 case 4: self.team_forced = NUM_TEAM_4; break;
1053 default: self.team_forced = 0;
1057 else if(PlayerInIDList(self, autocvar_g_forced_team_red))
1058 self.team_forced = NUM_TEAM_1;
1059 else if(PlayerInIDList(self, autocvar_g_forced_team_blue))
1060 self.team_forced = NUM_TEAM_2;
1061 else if(PlayerInIDList(self, autocvar_g_forced_team_yellow))
1062 self.team_forced = NUM_TEAM_3;
1063 else if(PlayerInIDList(self, autocvar_g_forced_team_pink))
1064 self.team_forced = NUM_TEAM_4;
1065 else if(autocvar_g_forced_team_otherwise == "red")
1066 self.team_forced = NUM_TEAM_1;
1067 else if(autocvar_g_forced_team_otherwise == "blue")
1068 self.team_forced = NUM_TEAM_2;
1069 else if(autocvar_g_forced_team_otherwise == "yellow")
1070 self.team_forced = NUM_TEAM_3;
1071 else if(autocvar_g_forced_team_otherwise == "pink")
1072 self.team_forced = NUM_TEAM_4;
1073 else if(autocvar_g_forced_team_otherwise == "spectate")
1074 self.team_forced = -1;
1075 else if(autocvar_g_forced_team_otherwise == "spectator")
1076 self.team_forced = -1;
1078 self.team_forced = 0;
1081 if(self.team_forced > 0)
1082 self.team_forced = 0;
1084 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1086 if((autocvar_sv_spectate == 1) || autocvar_g_campaign || self.team_forced < 0) {
1087 self.classname = "observer";
1091 if(autocvar_g_balance_teams)
1093 self.classname = "player";
1094 campaign_bots_may_start = 1;
1098 self.classname = "observer"; // do it anyway
1103 self.classname = "player";
1104 campaign_bots_may_start = 1;
1108 self.playerid = (playerid_last = playerid_last + 1);
1110 PlayerStats_GameReport_AddEvent(sprintf("kills-%d", self.playerid));
1112 if(IS_BOT_CLIENT(self))
1113 PlayerStats_GameReport_AddPlayer(self);
1115 if(autocvar_sv_eventlog)
1116 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", ((IS_REAL_CLIENT(self)) ? self.netaddress : "bot"), ":", self.netname));
1118 LogTeamchange(self.playerid, self.team, 1);
1120 self.just_joined = TRUE; // stop spamming the eventlog with additional lines when the client connects
1122 self.netname_previous = strzone(self.netname);
1124 if(IS_PLAYER(self) && teamplay)
1125 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_ENT_4(self, INFO_JOIN_CONNECT_TEAM_), self.netname);
1127 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_CONNECT, self.netname);
1129 stuffcmd(self, strcat(clientstuff, "\n"));
1130 stuffcmd(self, "cl_particles_reloadeffects\n"); // TODO do we still need this?
1132 FixClientCvars(self);
1134 // spawnfunc_waypoint sprites
1135 WaypointSprite_InitClient(self);
1137 // Wazat's grappling hook
1138 SetGrappleHookBindings();
1141 stuffcmd(self, "alias +jetpack +button10\n");
1142 stuffcmd(self, "alias -jetpack -button10\n");
1144 // get version info from player
1145 stuffcmd(self, "cmd clientversion $gameversion\n");
1147 // get other cvars from player
1150 // notify about available teams
1153 CheckAllowedTeams(self);
1154 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1155 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1158 stuffcmd(self, "set _teams_available 0\n");
1162 bot_relinkplayerlist();
1164 self.spectatortime = time;
1167 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1170 self.jointime = time;
1171 self.allowed_timeouts = autocvar_sv_timeout_number;
1173 if(IS_REAL_CLIENT(self))
1175 if(!autocvar_g_campaign)
1177 self.motd_actived_time = -1;
1178 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
1181 if(autocvar_g_bugrigs || (g_weaponarena_weapons == WEPSET_TUBA))
1182 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1185 if(!sv_foginterval && world.fog != "")
1186 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1188 W_HitPlotOpen(self);
1190 if(autocvar_sv_teamnagger && !(autocvar_bot_vs_human && (c3==-1 && c4==-1)) && !g_ca && !g_cts && !g_race) // teamnagger is currently bad for ca, race & cts
1191 send_CSQC_teamnagger();
1195 CSQCMODEL_AUTOINIT();
1197 self.model_randomizer = random();
1199 if(IS_REAL_CLIENT(self))
1202 MUTATOR_CALLHOOK(ClientConnect);
1208 Called when a client disconnects from the server
1211 .entity chatbubbleentity;
1213 void ClientDisconnect (void)
1216 vehicles_exit(VHEF_RELEASE);
1218 if (!IS_CLIENT(self))
1220 print("Warning: ClientDisconnect without ClientConnect\n");
1224 PlayerStats_GameReport_FinalizePlayer(self);
1226 if(IS_PLAYER(self)) { pointparticles(particleeffectnum("spawn_event_neutral"), self.origin, '0 0 0', 1); }
1228 CheatShutdownClient();
1230 W_HitPlotClose(self);
1233 anticheat_shutdown();
1235 playerdemo_shutdown();
1237 bot_clientdisconnect();
1242 if(autocvar_sv_eventlog)
1243 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1245 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_DISCONNECT, self.netname);
1247 MUTATOR_CALLHOOK(ClientDisconnect);
1249 Portal_ClearAll(self);
1253 RemoveGrapplingHook(self);
1255 // Here, everything has been done that requires this player to be a client.
1257 self.flags &= ~FL_CLIENT;
1259 if (self.chatbubbleentity)
1260 remove (self.chatbubbleentity);
1262 if (self.killindicator)
1263 remove (self.killindicator);
1265 WaypointSprite_PlayerGone();
1267 bot_relinkplayerlist();
1269 accuracy_free(self);
1270 ClientData_Detach();
1271 PlayerScore_Detach(self);
1273 if(self.netname_previous)
1274 strunzone(self.netname_previous);
1275 if(self.clientstatus)
1276 strunzone(self.clientstatus);
1277 if(self.weaponorder_byimpulse)
1278 strunzone(self.weaponorder_byimpulse);
1280 ClearPlayerSounds();
1283 remove(self.personal);
1293 void ChatBubbleThink()
1295 self.nextthink = time;
1296 if ((self.owner.alpha < 0) || self.owner.chatbubbleentity != self)
1298 if(self.owner) // but why can that ever be world?
1299 self.owner.chatbubbleentity = world;
1303 if ((self.owner.BUTTON_CHAT && !self.owner.deadflag)
1305 || self.owner.tetris_on
1308 self.model = self.mdl;
1313 void UpdateChatBubble()
1317 // spawn a chatbubble entity if needed
1318 if (!self.chatbubbleentity)
1320 self.chatbubbleentity = spawn();
1321 self.chatbubbleentity.owner = self;
1322 self.chatbubbleentity.exteriormodeltoclient = self;
1323 self.chatbubbleentity.think = ChatBubbleThink;
1324 self.chatbubbleentity.nextthink = time;
1325 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1326 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1327 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1328 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1329 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1330 self.chatbubbleentity.model = "";
1331 self.chatbubbleentity.effects = EF_LOWPRECISION;
1336 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1337 // added to the model skins
1338 /*void UpdateColorModHack()
1341 c = self.clientcolors & 15;
1342 // LordHavoc: only bothering to support white, green, red, yellow, blue
1343 if (!teamplay) self.colormod = '0 0 0';
1344 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1345 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1346 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1347 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1348 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1349 else self.colormod = '1 1 1';
1354 if(self.alpha >= 0 && autocvar_g_respawn_ghosts)
1356 self.solid = SOLID_NOT;
1357 self.takedamage = DAMAGE_NO;
1358 self.movetype = MOVETYPE_FLY;
1359 self.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed;
1360 self.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3;
1361 self.effects |= CSQCMODEL_EF_RESPAWNGHOST;
1362 pointparticles(particleeffectnum("respawn_ghost"), self.origin, '0 0 0', 1);
1363 if(autocvar_g_respawn_ghosts_maxtime)
1364 SUB_SetFade (self, time + autocvar_g_respawn_ghosts_maxtime / 2 + random () * (autocvar_g_respawn_ghosts_maxtime - autocvar_g_respawn_ghosts_maxtime / 2), 1.5);
1369 self.effects |= EF_NODRAW; // prevent another CopyBody
1370 PutClientInServer();
1373 void play_countdown(float finished, string samp)
1375 if(IS_REAL_CLIENT(self))
1376 if(floor(finished - time - frametime) != floor(finished - time))
1377 if(finished - time < 6)
1378 sound (self, CH_INFO, samp, VOL_BASE, ATTEN_NORM);
1381 void player_powerups (void)
1383 // add a way to see what the items were BEFORE all of these checks for the mutator hook
1384 olditems = self.items;
1386 if((self.items & IT_USING_JETPACK) && !self.deadflag && !gameover)
1387 self.modelflags |= MF_ROCKET;
1389 self.modelflags &= ~MF_ROCKET;
1391 self.effects &= ~(EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT | EF_FLAME | EF_NODEPTHTEST);
1393 if((self.alpha < 0 || self.deadflag) && !self.vehicle) // don't apply the flags if the player is gibbed
1396 Fire_ApplyDamage(self);
1397 Fire_ApplyEffect(self);
1401 if (self.items & IT_STRENGTH)
1403 play_countdown(self.strength_finished, "misc/poweroff.wav");
1404 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1405 if (time > self.strength_finished)
1407 self.items = self.items - (self.items & IT_STRENGTH);
1408 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_STRENGTH, self.netname);
1409 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_STRENGTH);
1414 if (time < self.strength_finished)
1416 self.items = self.items | IT_STRENGTH;
1417 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_STRENGTH, self.netname);
1418 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_STRENGTH);
1421 if (self.items & IT_INVINCIBLE)
1423 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1424 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1425 if (time > self.invincible_finished)
1427 self.items = self.items - (self.items & IT_INVINCIBLE);
1428 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERDOWN_SHIELD, self.netname);
1429 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERDOWN_SHIELD);
1434 if (time < self.invincible_finished)
1436 self.items = self.items | IT_INVINCIBLE;
1437 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_POWERUP_SHIELD, self.netname);
1438 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_POWERUP_SHIELD);
1441 if (self.items & IT_SUPERWEAPON)
1443 if (!(self.weapons & WEPSET_SUPERWEAPONS))
1445 self.superweapons_finished = 0;
1446 self.items = self.items - (self.items & IT_SUPERWEAPON);
1447 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_LOST, self.netname);
1448 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_LOST);
1450 else if (self.items & IT_UNLIMITED_SUPERWEAPONS)
1452 // don't let them run out
1456 play_countdown(self.superweapons_finished, "misc/poweroff.wav");
1457 if (time > self.superweapons_finished)
1459 self.items = self.items - (self.items & IT_SUPERWEAPON);
1460 self.weapons &= ~WEPSET_SUPERWEAPONS;
1461 //Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_BROKEN, self.netname);
1462 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_BROKEN);
1466 else if(self.weapons & WEPSET_SUPERWEAPONS)
1468 if (time < self.superweapons_finished || (self.items & IT_UNLIMITED_SUPERWEAPONS))
1470 self.items = self.items | IT_SUPERWEAPON;
1471 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_SUPERWEAPON_PICKUP, self.netname);
1472 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_SUPERWEAPON_PICKUP);
1476 self.superweapons_finished = 0;
1477 self.weapons &= ~WEPSET_SUPERWEAPONS;
1482 self.superweapons_finished = 0;
1486 if(autocvar_g_nodepthtestplayers)
1487 self.effects = self.effects | EF_NODEPTHTEST;
1489 if(autocvar_g_fullbrightplayers)
1490 self.effects = self.effects | EF_FULLBRIGHT;
1492 if (time >= game_starttime)
1493 if (time < self.spawnshieldtime)
1494 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1496 MUTATOR_CALLHOOK(PlayerPowerups);
1499 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1501 if(current > stable)
1503 else if(current > stable - 0.25) // when close enough, "snap"
1506 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1509 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1511 if(current < stable)
1513 else if(current < stable + 0.25) // when close enough, "snap"
1516 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1519 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1521 if(current > rotstable)
1523 if(rotframetime > 0)
1525 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1526 current = max(rotstable, current - rotlinear * rotframetime);
1529 else if(current < regenstable)
1531 if(regenframetime > 0)
1533 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1534 current = min(regenstable, current + regenlinear * regenframetime);
1544 void player_regen (void)
1546 float max_mod, regen_mod, rot_mod, limit_mod;
1547 max_mod = regen_mod = rot_mod = limit_mod = 1;
1548 regen_mod_max = max_mod;
1549 regen_mod_regen = regen_mod;
1550 regen_mod_rot = rot_mod;
1551 regen_mod_limit = limit_mod;
1552 if(!MUTATOR_CALLHOOK(PlayerRegen))
1555 float minh, mina, maxh, maxa, limith, limita;
1556 maxh = autocvar_g_balance_health_rotstable;
1557 maxa = autocvar_g_balance_armor_rotstable;
1558 minh = autocvar_g_balance_health_regenstable;
1559 mina = autocvar_g_balance_armor_regenstable;
1560 limith = autocvar_g_balance_health_limit;
1561 limita = autocvar_g_balance_armor_limit;
1563 max_mod = regen_mod_max;
1564 regen_mod = regen_mod_regen;
1565 rot_mod = regen_mod_rot;
1566 limit_mod = regen_mod_limit;
1568 maxh = maxh * max_mod;
1569 minh = minh * max_mod;
1570 limith = limith * limit_mod;
1571 limita = limita * limit_mod;
1573 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);
1574 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);
1577 // if player rotted to death... die!
1578 // check this outside above checks, as player may still be able to rot to death
1582 vehicles_exit(VHEF_RELEASE);
1583 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1586 if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
1588 float minf, maxf, limitf;
1590 maxf = autocvar_g_balance_fuel_rotstable;
1591 minf = autocvar_g_balance_fuel_regenstable;
1592 limitf = autocvar_g_balance_fuel_limit;
1594 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > self.pauseregen_finished) * ((self.items & IT_FUEL_REGEN) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > self.pauserotfuel_finished), limitf);
1598 float zoomstate_set;
1599 void SetZoomState(float z)
1601 if(z != self.zoomstate)
1604 ClientData_Touch(self);
1609 void GetPressedKeys(void) {
1610 MUTATOR_CALLHOOK(GetPressedKeys);
1611 if (self.movement_x > 0) // get if movement keys are pressed
1612 { // forward key pressed
1613 self.pressedkeys |= KEY_FORWARD;
1614 self.pressedkeys &= ~KEY_BACKWARD;
1616 else if (self.movement_x < 0)
1617 { // backward key pressed
1618 self.pressedkeys |= KEY_BACKWARD;
1619 self.pressedkeys &= ~KEY_FORWARD;
1623 self.pressedkeys &= ~KEY_FORWARD;
1624 self.pressedkeys &= ~KEY_BACKWARD;
1627 if (self.movement_y > 0)
1628 { // right key pressed
1629 self.pressedkeys |= KEY_RIGHT;
1630 self.pressedkeys &= ~KEY_LEFT;
1632 else if (self.movement_y < 0)
1633 { // left key pressed
1634 self.pressedkeys |= KEY_LEFT;
1635 self.pressedkeys &= ~KEY_RIGHT;
1639 self.pressedkeys &= ~KEY_RIGHT;
1640 self.pressedkeys &= ~KEY_LEFT;
1643 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1644 self.pressedkeys |= KEY_JUMP;
1646 self.pressedkeys &= ~KEY_JUMP;
1647 if (self.BUTTON_CROUCH)
1648 self.pressedkeys |= KEY_CROUCH;
1650 self.pressedkeys &= ~KEY_CROUCH;
1652 if (self.BUTTON_ATCK)
1653 self.pressedkeys |= KEY_ATCK;
1655 self.pressedkeys &= ~KEY_ATCK;
1656 if (self.BUTTON_ATCK2)
1657 self.pressedkeys |= KEY_ATCK2;
1659 self.pressedkeys &= ~KEY_ATCK2;
1663 ======================
1664 spectate mode routines
1665 ======================
1668 void SpectateCopy(entity spectatee) {
1670 MUTATOR_CALLHOOK(SpectateCopy);
1671 self.armortype = spectatee.armortype;
1672 self.armorvalue = spectatee.armorvalue;
1673 self.ammo_cells = spectatee.ammo_cells;
1674 self.ammo_plasma = spectatee.ammo_plasma;
1675 self.ammo_shells = spectatee.ammo_shells;
1676 self.ammo_nails = spectatee.ammo_nails;
1677 self.ammo_rockets = spectatee.ammo_rockets;
1678 self.ammo_fuel = spectatee.ammo_fuel;
1679 self.clip_load = spectatee.clip_load;
1680 self.clip_size = spectatee.clip_size;
1681 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1682 self.health = spectatee.health;
1684 self.items = spectatee.items;
1685 self.last_pickup = spectatee.last_pickup;
1686 self.hit_time = spectatee.hit_time;
1687 self.metertime = spectatee.metertime;
1688 self.strength_finished = spectatee.strength_finished;
1689 self.invincible_finished = spectatee.invincible_finished;
1690 self.pressedkeys = spectatee.pressedkeys;
1691 self.weapons = spectatee.weapons;
1692 self.switchweapon = spectatee.switchweapon;
1693 self.switchingweapon = spectatee.switchingweapon;
1694 self.weapon = spectatee.weapon;
1695 self.vortex_charge = spectatee.vortex_charge;
1696 self.vortex_chargepool_ammo = spectatee.vortex_chargepool_ammo;
1697 self.hagar_load = spectatee.hagar_load;
1698 self.arc_heat_percent = spectatee.arc_heat_percent;
1699 self.minelayer_mines = spectatee.minelayer_mines;
1700 self.punchangle = spectatee.punchangle;
1701 self.view_ofs = spectatee.view_ofs;
1702 self.velocity = spectatee.velocity;
1703 self.dmg_take = spectatee.dmg_take;
1704 self.dmg_save = spectatee.dmg_save;
1705 self.dmg_inflictor = spectatee.dmg_inflictor;
1706 self.v_angle = spectatee.v_angle;
1707 self.angles = spectatee.v_angle;
1708 self.frozen = spectatee.frozen;
1709 self.revive_progress = spectatee.revive_progress;
1710 if(!self.BUTTON_USE)
1711 self.fixangle = TRUE;
1712 setorigin(self, spectatee.origin);
1713 setsize(self, spectatee.mins, spectatee.maxs);
1714 SetZoomState(spectatee.zoomstate);
1716 anticheat_spectatecopy(spectatee);
1717 self.hud = spectatee.hud;
1718 if(spectatee.vehicle)
1720 self.fixangle = FALSE;
1721 //self.velocity = spectatee.vehicle.velocity;
1722 self.vehicle_health = spectatee.vehicle_health;
1723 self.vehicle_shield = spectatee.vehicle_shield;
1724 self.vehicle_energy = spectatee.vehicle_energy;
1725 self.vehicle_ammo1 = spectatee.vehicle_ammo1;
1726 self.vehicle_ammo2 = spectatee.vehicle_ammo2;
1727 self.vehicle_reload1 = spectatee.vehicle_reload1;
1728 self.vehicle_reload2 = spectatee.vehicle_reload2;
1732 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
1733 WriteAngle(MSG_ONE, spectatee.v_angle_x);
1734 WriteAngle(MSG_ONE, spectatee.v_angle_y);
1735 WriteAngle(MSG_ONE, spectatee.v_angle_z);
1737 //WriteByte (MSG_ONE, SVC_SETVIEW);
1738 // WriteEntity(MSG_ONE, self);
1739 //makevectors(spectatee.v_angle);
1740 //setorigin(self, spectatee.origin - v_forward * 400 + v_up * 300);*/
1744 float SpectateUpdate()
1749 if(!IS_PLAYER(self.enemy) || self == self.enemy)
1751 SetSpectator(self, world);
1755 SpectateCopy(self.enemy);
1762 if(self.enemy.classname != "player")
1764 /*if(self.enemy.vehicle)
1768 WriteByte(MSG_ONE, SVC_SETVIEW);
1769 WriteEntity(MSG_ONE, self.enemy);
1770 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1772 self.movetype = MOVETYPE_NONE;
1773 accuracy_resend(self);
1778 WriteByte(MSG_ONE, SVC_SETVIEW);
1779 WriteEntity(MSG_ONE, self.enemy);
1780 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1781 self.movetype = MOVETYPE_NONE;
1782 accuracy_resend(self);
1784 if(!SpectateUpdate())
1785 PutObserverInServer();
1790 void SetSpectator(entity player, entity spectatee)
1792 entity old_spectatee = player.enemy;
1794 player.enemy = spectatee;
1797 // these are required to fix the spectator bug with arc
1798 if(old_spectatee && old_spectatee.arc_beam) { old_spectatee.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1799 if(player.enemy && player.enemy.arc_beam) { player.enemy.arc_beam.SendFlags |= ARC_SF_SETTINGS; }
1802 float Spectate(entity pl)
1804 if(g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
1805 if(pl.team != self.team)
1808 SetSpectator(self, pl);
1809 return SpectateSet();
1812 // Returns next available player to spectate if g_ca_spectate_enemies == 0
1813 entity CA_SpectateNext(entity start) {
1814 if (start.team == self.team) {
1819 // continue from current player
1820 while(other && other.team != self.team) {
1821 other = find(other, classname, "player");
1825 // restart from begining
1826 other = find(other, classname, "player");
1827 while(other && other.team != self.team) {
1828 other = find(other, classname, "player");
1835 float SpectateNext()
1837 other = find(self.enemy, classname, "player");
1839 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer) {
1840 // CA and ca players when spectating enemies is forbidden
1841 other = CA_SpectateNext(other);
1843 // other modes and ca spectators or spectating enemies is allowed
1845 other = find(other, classname, "player");
1848 if(other) { SetSpectator(self, other); }
1850 return SpectateSet();
1853 float SpectatePrev()
1855 // NOTE: chain order is from the highest to the lower entnum (unlike find)
1856 other = findchain(classname, "player");
1857 if (!other) // no player
1860 entity first = other;
1861 // skip players until current spectated player
1863 while(other && other != self.enemy)
1864 other = other.chain;
1866 if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
1868 do { other = other.chain; }
1869 while(other && other.team != self.team);
1874 while(other.team != self.team)
1875 other = other.chain;
1876 if(other == self.enemy)
1883 other = other.chain;
1887 SetSpectator(self, other);
1888 return SpectateSet();
1893 ShowRespawnCountdown()
1895 Update a respawn countdown display.
1898 void ShowRespawnCountdown()
1901 if(self.deadflag == DEAD_NO) // just respawned?
1905 number = ceil(self.respawn_time - time);
1908 if(number <= self.respawn_countdown)
1910 self.respawn_countdown = number - 1;
1911 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
1912 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_RESPAWN, number)); }
1917 void LeaveSpectatorMode()
1921 if(nJoinAllowed(self))
1923 if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (self.wasplayer && autocvar_g_changeteam_banned) || self.team_forced > 0)
1925 self.classname = "player";
1926 nades_RemoveBonus(self);
1928 if(autocvar_g_campaign || autocvar_g_balance_teams)
1929 { JoinBestTeam(self, FALSE, TRUE); }
1931 if(autocvar_g_campaign)
1932 { campaign_bots_may_start = 1; }
1934 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_PREVENT_JOIN);
1936 PutClientInServer();
1938 if(IS_PLAYER(self)) { Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_JOIN_PLAY, self.netname); }
1941 stuffcmd(self, "menu_showteamselect\n");
1945 // Player may not join because g_maxplayers is set
1946 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_JOIN_PREVENT);
1951 * Determines whether the player is allowed to join. This depends on cvar
1952 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1953 * it checks whether the number of currently playing players exceeds g_maxplayers.
1954 * @return int number of free slots for players, 0 if none
1956 float nJoinAllowed(entity ignore) {
1958 // this is called that way when checking if anyone may be able to join (to build qcstatus)
1959 // so report 0 free slots if restricted
1961 if(autocvar_g_forced_team_otherwise == "spectate")
1963 if(autocvar_g_forced_team_otherwise == "spectator")
1967 if(self.team_forced < 0)
1968 return 0; // forced spectators can never join
1970 // TODO simplify this
1972 float totalClients = 0;
1977 if (!autocvar_g_maxplayers)
1978 return maxclients - totalClients;
1980 float currentlyPlaying = 0;
1981 FOR_EACH_REALCLIENT(e)
1982 if(IS_PLAYER(e) || e.caplayer)
1983 currentlyPlaying += 1;
1985 if(currentlyPlaying < autocvar_g_maxplayers)
1986 return min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
1992 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1993 * g_maxplayers_spectator_blocktime seconds
1995 void checkSpectatorBlock() {
1996 if(IS_SPEC(self) || IS_OBSERVER(self))
1998 if(IS_REAL_CLIENT(self))
2000 if( time > (self.spectatortime + autocvar_g_maxplayers_spectator_blocktime) ) {
2001 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
2007 void PrintWelcomeMessage()
2009 if(self.motd_actived_time == 0)
2011 if (autocvar_g_campaign) {
2012 if ((IS_PLAYER(self) && self.BUTTON_INFO) || (!IS_PLAYER(self))) {
2013 self.motd_actived_time = time;
2014 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, campaign_message);
2017 if (self.BUTTON_INFO) {
2018 self.motd_actived_time = time;
2019 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
2023 else if(self.motd_actived_time > 0) // showing MOTD or campaign message
2025 if (autocvar_g_campaign) {
2026 if (self.BUTTON_INFO)
2027 self.motd_actived_time = time;
2028 else if ((time - self.motd_actived_time > 2) && IS_PLAYER(self)) { // hide it some seconds after BUTTON_INFO has been released
2029 self.motd_actived_time = 0;
2030 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2033 if (self.BUTTON_INFO)
2034 self.motd_actived_time = time;
2035 else if (time - self.motd_actived_time > 2) { // hide it some seconds after BUTTON_INFO has been released
2036 self.motd_actived_time = 0;
2037 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2041 else //if(self.motd_actived_time < 0) // just connected, motd is active
2043 if(self.BUTTON_INFO) // BUTTON_INFO hides initial MOTD
2044 self.motd_actived_time = -2; // wait until BUTTON_INFO gets released
2045 else if(self.motd_actived_time == -2 || IS_PLAYER(self))
2047 // instanctly hide MOTD
2048 self.motd_actived_time = 0;
2049 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_MOTD);
2054 void ObserverThink()
2056 float prefered_movetype;
2057 if (self.flags & FL_JUMPRELEASED) {
2058 if (self.BUTTON_JUMP && !self.version_mismatch) {
2059 self.flags &= ~FL_JUMPRELEASED;
2060 self.flags |= FL_SPAWNING;
2061 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2062 self.flags &= ~FL_JUMPRELEASED;
2063 if(SpectateNext()) {
2064 self.classname = "spectator";
2067 prefered_movetype = ((!self.BUTTON_USE ? self.cvar_cl_clippedspectating : !self.cvar_cl_clippedspectating) ? MOVETYPE_FLY_WORLDONLY : MOVETYPE_NOCLIP);
2068 if (self.movetype != prefered_movetype)
2069 self.movetype = prefered_movetype;
2072 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2073 self.flags |= FL_JUMPRELEASED;
2074 if(self.flags & FL_SPAWNING)
2076 self.flags &= ~FL_SPAWNING;
2077 LeaveSpectatorMode();
2084 void SpectatorThink()
2086 if (self.flags & FL_JUMPRELEASED) {
2087 if (self.BUTTON_JUMP && !self.version_mismatch) {
2088 self.flags &= ~FL_JUMPRELEASED;
2089 self.flags |= FL_SPAWNING;
2090 } else if(self.BUTTON_ATCK || self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209)) {
2091 self.flags &= ~FL_JUMPRELEASED;
2092 if(SpectateNext()) {
2093 self.classname = "spectator";
2095 self.classname = "observer";
2096 PutClientInServer();
2099 } else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229)) {
2100 self.flags &= ~FL_JUMPRELEASED;
2101 if(SpectatePrev()) {
2102 self.classname = "spectator";
2104 self.classname = "observer";
2105 PutClientInServer();
2108 } else if (self.BUTTON_ATCK2) {
2109 self.flags &= ~FL_JUMPRELEASED;
2110 self.classname = "observer";
2111 PutClientInServer();
2113 if(!SpectateUpdate())
2114 PutObserverInServer();
2117 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2118 self.flags |= FL_JUMPRELEASED;
2119 if(self.flags & FL_SPAWNING)
2121 self.flags &= ~FL_SPAWNING;
2122 LeaveSpectatorMode();
2126 if(!SpectateUpdate())
2127 PutObserverInServer();
2130 self.flags |= FL_CLIENT | FL_NOTARGET;
2133 void vehicles_enter (entity pl, entity veh);
2136 if (!IS_PLAYER(self))
2143 vehicles_exit(VHEF_NORMAL);
2147 else if(autocvar_g_vehicles_enter)
2150 if(self.deadflag == DEAD_NO)
2153 entity head, closest_target = world;
2154 head = WarpZone_FindRadius(self.origin, autocvar_g_vehicles_enter_radius, TRUE);
2156 while(head) // find the closest acceptable target to enter
2158 if(head.vehicle_flags & VHF_ISVEHICLE)
2159 if(head.deadflag == DEAD_NO)
2160 if(!head.owner || ((head.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(head.owner, self)))
2161 if(head.takedamage != DAMAGE_NO)
2165 if(vlen(self.origin - head.origin) < vlen(self.origin - closest_target.origin))
2166 { closest_target = head; }
2168 else { closest_target = head; }
2174 if(closest_target) { vehicles_enter(self, closest_target); return; }
2178 // a use key was pressed; call handlers
2179 MUTATOR_CALLHOOK(PlayerUseKey);
2182 float isInvisibleString(string s)
2185 s = strdecolorize(s);
2186 for((i = 0), (n = strlen(s)); i < n; ++i)
2194 case 192: // charmap space
2195 if (!autocvar_utf8_enable)
2198 case 160: // space in unicode fonts
2199 case 0xE000 + 192: // utf8 charmap space
2200 if (autocvar_utf8_enable)
2213 Called every frame for each client before the physics are run
2216 .float usekeypressed;
2217 void() nexball_setstatus;
2219 .float last_vehiclecheck;
2220 void PlayerPreThink (void)
2222 WarpZone_PlayerPhysics_FixVAngle();
2224 self.stat_game_starttime = game_starttime;
2225 self.stat_round_starttime = round_starttime;
2226 self.stat_allow_oldvortexbeam = autocvar_g_allow_oldvortexbeam;
2227 self.stat_leadlimit = autocvar_leadlimit;
2231 // physics frames: update anticheat stuff
2232 anticheat_prethink();
2235 if(blockSpectators && frametime)
2236 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2237 checkSpectatorBlock();
2241 // Savage: Check for nameless players
2242 if (isInvisibleString(self.netname)) {
2243 string new_name = strzone(strcat("Player@", self.netaddress));
2244 if(autocvar_sv_eventlog)
2245 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", new_name));
2246 if(self.netname_previous)
2247 strunzone(self.netname_previous);
2248 self.netname_previous = strzone(new_name);
2249 self.netname = self.netname_previous;
2250 // stuffcmd(self, strcat("name ", self.netname, "\n"));
2251 } else if(self.netname_previous != self.netname) {
2252 if(autocvar_sv_eventlog)
2253 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2254 if(self.netname_previous)
2255 strunzone(self.netname_previous);
2256 self.netname_previous = strzone(self.netname);
2260 if(self.version_nagtime)
2261 if(self.cvar_g_xonoticversion)
2262 if(time > self.version_nagtime)
2264 // don't notify git users
2265 if(strstr(self.cvar_g_xonoticversion, "git", 0) < 0 && strstr(self.cvar_g_xonoticversion, "autobuild", 0) < 0)
2267 if(strstr(autocvar_g_xonoticversion, "git", 0) >= 0 || strstr(autocvar_g_xonoticversion, "autobuild", 0) >= 0)
2269 // notify release users if connecting to git
2270 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");
2271 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_BETA, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2276 r = vercmp(self.cvar_g_xonoticversion, autocvar_g_xonoticversion);
2279 // give users new version
2280 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");
2281 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OUTDATED, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2285 // notify users about old server version
2286 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");
2287 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_VERSION_OLD, autocvar_g_xonoticversion, self.cvar_g_xonoticversion);
2291 self.version_nagtime = 0;
2295 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2297 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_GODMODE_OFF, self.max_armorvalue);
2298 self.max_armorvalue = 0;
2302 if (TetrisPreFrame())
2306 if(self.frozen == 2)
2308 self.revive_progress = bound(0, self.revive_progress + frametime * self.revive_speed, 1);
2309 self.health = max(1, self.revive_progress * start_health);
2310 self.iceblock.alpha = bound(0.2, 1 - self.revive_progress, 1);
2312 if(self.revive_progress >= 1)
2315 else if(self.frozen == 3)
2317 self.revive_progress = bound(0, self.revive_progress - frametime * self.revive_speed, 1);
2318 self.health = max(0, autocvar_g_nades_ice_health + (start_health-autocvar_g_nades_ice_health) * self.revive_progress );
2323 vehicles_exit(VHEF_RELEASE);
2324 self.event_damage(self, self.frozen_by, 1, DEATH_NADE_ICE_FREEZE, self.origin, '0 0 0');
2326 else if ( self.revive_progress <= 0 )
2330 MUTATOR_CALLHOOK(PlayerPreThink);
2332 if(autocvar_g_vehicles_enter)
2333 if(time > self.last_vehiclecheck)
2338 if(self.deadflag == DEAD_NO)
2341 for(veh = world; (veh = findflags(veh, vehicle_flags, VHF_ISVEHICLE)); )
2342 if(vlen(veh.origin - self.origin) < autocvar_g_vehicles_enter_radius)
2343 if(veh.deadflag == DEAD_NO)
2344 if(veh.takedamage != DAMAGE_NO)
2345 if((veh.vehicle_flags & VHF_MULTISLOT) && SAME_TEAM(veh.owner, self))
2346 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_GUNNER);
2348 if(!veh.team || SAME_TEAM(self, veh))
2349 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER);
2350 else if(autocvar_g_vehicles_steal)
2351 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_VEHICLE_ENTER_STEAL);
2353 self.last_vehiclecheck = time + 1;
2356 if(!self.cvar_cl_newusekeysupported) // FIXME remove this - it was a stupid idea to begin with, we can JUST use the button
2358 if(self.BUTTON_USE && !self.usekeypressed)
2360 self.usekeypressed = self.BUTTON_USE;
2363 if(IS_REAL_CLIENT(self))
2364 PrintWelcomeMessage();
2369 CheckRules_Player();
2371 if (intermission_running)
2373 IntermissionThink (); // otherwise a button could be missed between
2374 return; // the think tics
2377 //don't allow the player to turn around while game is paused!
2378 if(timeout_status == TIMEOUT_ACTIVE) {
2379 // FIXME turn this into CSQC stuff
2380 self.v_angle = self.lastV_angle;
2381 self.angles = self.lastV_angle;
2382 self.fixangle = TRUE;
2387 if(self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge))
2389 self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2390 self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2391 self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
2393 if(self.vortex_charge > WEP_CVAR(vortex, charge_animlimit))
2395 self.weaponentity_glowmod_x = self.weaponentity_glowmod_x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2396 self.weaponentity_glowmod_y = self.weaponentity_glowmod_y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2397 self.weaponentity_glowmod_z = self.weaponentity_glowmod_z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
2401 self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, TRUE) * 2;
2406 if (self.deadflag != DEAD_NO)
2408 if(self.personal && g_race_qualifying)
2410 if(time > self.respawn_time)
2412 self.respawn_time = time + 1; // only retry once a second
2413 self.stat_respawn_time = self.respawn_time;
2420 float button_pressed;
2423 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2425 if (self.deadflag == DEAD_DYING)
2427 if((self.respawn_flags & RESPAWN_FORCE) && !autocvar_g_respawn_delay_max)
2428 self.deadflag = DEAD_RESPAWNING;
2429 else if(!button_pressed)
2430 self.deadflag = DEAD_DEAD;
2432 else if (self.deadflag == DEAD_DEAD)
2435 self.deadflag = DEAD_RESPAWNABLE;
2436 else if(time >= self.respawn_time_max && (self.respawn_flags & RESPAWN_FORCE))
2437 self.deadflag = DEAD_RESPAWNING;
2439 else if (self.deadflag == DEAD_RESPAWNABLE)
2442 self.deadflag = DEAD_RESPAWNING;
2444 else if (self.deadflag == DEAD_RESPAWNING)
2446 if(time > self.respawn_time)
2448 self.respawn_time = time + 1; // only retry once a second
2449 self.respawn_time_max = self.respawn_time;
2454 ShowRespawnCountdown();
2456 if(self.respawn_flags & RESPAWN_SILENT)
2457 self.stat_respawn_time = 0;
2458 else if((self.respawn_flags & RESPAWN_FORCE) && autocvar_g_respawn_delay_max)
2459 self.stat_respawn_time = self.respawn_time_max;
2461 self.stat_respawn_time = self.respawn_time;
2464 // if respawning, invert stat_respawn_time to indicate this, the client translates it
2465 if(self.deadflag == DEAD_RESPAWNING && self.stat_respawn_time > 0)
2466 self.stat_respawn_time *= -1;
2471 self.prevorigin = self.origin;
2473 float do_crouch = self.BUTTON_CROUCH;
2481 // WEAPONTODO: THIS SHIT NEEDS TO GO EVENTUALLY
2482 // It cannot be predicted by the engine!
2483 if((self.weapon == WEP_SHOCKWAVE || self.weapon == WEP_SHOTGUN) && self.weaponentity.wframe == WFRAME_FIRE2 && time < self.weapon_nextthink)
2491 self.view_ofs = PL_CROUCH_VIEW_OFS;
2492 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2493 // setanim(self, self.anim_duck, FALSE, TRUE, TRUE); // this anim is BROKEN anyway
2500 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2501 if (!trace_startsolid)
2503 self.crouch = FALSE;
2504 self.view_ofs = PL_VIEW_OFS;
2505 setsize (self, PL_MIN, PL_MAX);
2512 GrapplingHookFrame();
2514 // LordHavoc: allow firing on move frames (sub-ticrate), this gives better timing on slow servers
2517 self.items &= ~self.items_added;
2521 self.items_added = 0;
2522 if(self.items & IT_JETPACK)
2523 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2524 self.items_added |= IT_FUEL;
2526 self.items |= self.items_added;
2531 // WEAPONTODO: Add a weapon request for this
2532 // rot vortex charge to the charge limit
2533 if(WEP_CVAR(vortex, charge_rot_rate) && self.vortex_charge > WEP_CVAR(vortex, charge_limit) && self.vortex_charge_rottime < time)
2534 self.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), self.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1);
2540 secrets_setstatus();
2543 monsters_setstatus();
2545 self.dmg_team = max(0, self.dmg_team - autocvar_g_teamdamage_resetspeed * frametime);
2547 //self.angles_y=self.v_angle_y + 90; // temp
2548 } else if(gameover) {
2549 if (intermission_running)
2550 IntermissionThink (); // otherwise a button could be missed between
2552 } else if(IS_OBSERVER(self)) {
2554 } else if(IS_SPEC(self)) {
2558 // WEAPONTODO: Add weapon request for this
2560 SetZoomState(self.BUTTON_ZOOM || self.BUTTON_ZOOMSCRIPT || (self.BUTTON_ATCK2 && self.weapon == WEP_VORTEX) || (self.BUTTON_ATCK2 && self.weapon == WEP_RIFLE && WEP_CVAR(rifle, secondary) == 0)); // WEAPONTODO
2562 float oldspectatee_status;
2563 oldspectatee_status = self.spectatee_status;
2565 self.spectatee_status = num_for_edict(self.enemy);
2566 else if(IS_OBSERVER(self))
2567 self.spectatee_status = num_for_edict(self);
2569 self.spectatee_status = 0;
2570 if(self.spectatee_status != oldspectatee_status)
2572 ClientData_Touch(self);
2575 if(self.teamkill_soundtime)
2576 if(time > self.teamkill_soundtime)
2578 self.teamkill_soundtime = 0;
2580 entity oldpusher, oldself;
2582 oldself = self; self = self.teamkill_soundsource;
2583 oldpusher = self.pusher; self.pusher = oldself;
2585 PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2587 self.pusher = oldpusher;
2591 if(self.taunt_soundtime)
2592 if(time > self.taunt_soundtime)
2594 self.taunt_soundtime = 0;
2595 PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
2598 target_voicescript_next(self);
2600 // WEAPONTODO: Move into weaponsystem somehow
2601 // if a player goes unarmed after holding a loaded weapon, empty his clip size and remove the crosshair ammo ring
2603 self.clip_load = self.clip_size = 0;
2610 Called every frame for each client after the physics are run
2613 .float idlekick_lasttimeleft;
2614 void PlayerPostThink (void)
2616 if(sv_maxidle > 0 && frametime) // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2617 if(IS_PLAYER(self) || sv_maxidle_spectatorsareidle)
2619 if (time - self.parm_idlesince < 1) // instead of (time == self.parm_idlesince) to support sv_maxidle <= 10
2621 if(self.idlekick_lasttimeleft)
2623 self.idlekick_lasttimeleft = 0;
2624 Kill_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER_CPID, CPID_IDLING);
2630 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2631 if(timeleft == min(10, sv_maxidle - 1)) // - 1 to support sv_maxidle <= 10
2633 if(!self.idlekick_lasttimeleft)
2634 Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_DISCONNECT_IDLING, timeleft);
2638 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_QUIT_KICK_IDLING, self.netname);
2642 else if(timeleft <= 10)
2644 if(timeleft != self.idlekick_lasttimeleft)
2645 { Send_Notification(NOTIF_ONE, self, MSG_ANNCE, Announcer_PickNumber(CNT_IDLE, timeleft)); }
2646 self.idlekick_lasttimeleft = timeleft;
2652 if(self.impulse == 100)
2654 if (!TetrisPostFrame())
2660 //CheckPlayerJump();
2662 if(IS_PLAYER(self)) {
2663 CheckRules_Player();
2667 if (intermission_running)
2668 return; // intermission or finale
2678 for(i = 0; i < 1000; ++i)
2681 end = self.origin + '0 0 1024' + 512 * randomvec();
2682 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2683 if(trace_fraction < 1)
2684 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2686 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2692 if(self.waypointsprite_attachedforcarrier)
2693 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, autocvar_g_balance_armor_blockpercent, DEATH_WEAPON));
2697 CSQCMODEL_AUTOUPDATE();