1 .float spectatee_status;
3 .float bloodloss_timer;
6 float ClientData_Send(entity to, float sf)
17 if(to.classname == "spectator")
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)
68 if(e2.classname == "spectator")
70 e2.clientdata.SendFlags = 1;
75 #define SPAWNPOINT_SCORE frags
77 .string netname_previous;
79 void spawnfunc_info_player_survivor (void)
81 spawnfunc_info_player_deathmatch();
84 void spawnfunc_info_player_start (void)
86 spawnfunc_info_player_deathmatch();
89 void spawnfunc_info_player_deathmatch (void)
91 self.classname = "info_player_deathmatch";
92 relocate_spawnpoint();
100 self.team = activator.team;
101 some_spawn_has_been_used = 1;
106 // -1 if a spawn can't be used
107 // otherwise, a weight of the spawnpoint
108 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
110 float shortest, thisdist;
113 // filter out spots for the wrong team
115 if(spot.team != teamcheck)
119 if(spot.target == "")
122 // filter out spots for assault
123 if(spot.target != "") {
126 ent = find(world, targetname, spot.target);
129 if(ent.classname == "target_objective")
131 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
135 else if(ent.classname == "trigger_race_checkpoint")
137 if(self.classname == "player") // spectators may spawn everywhere
139 if(g_race_qualifying)
142 if(ent.race_checkpoint != 0)
144 if(spot.race_place != race_lowest_place_spawn)
149 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
152 pl = self.race_place;
153 if(pl > race_highest_place_spawn)
155 if(spot.race_place != pl)
164 ent = find(ent, targetname, spot.target);
172 shortest = vlen(world.maxs - world.mins);
173 for(player = playerlist; player; player = player.chain)
176 thisdist = vlen(player.origin - spot.origin);
177 if (thisdist < shortest)
185 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
187 local entity spot, spotlist, spotlistend;
188 spawn_allgood = TRUE;
194 for(spot = firstspot; spot; spot = spot.chain)
196 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
198 if(cvar("spawn_debugview"))
200 setmodel(spot, "models/runematch/rune.mdl");
201 if(spot.SPAWNPOINT_SCORE < mindist)
203 spot.colormod = '1 0 0';
208 spot.colormod = '0 1 0';
209 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
213 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
215 if(spot.SPAWNPOINT_SCORE < mindist)
217 // too short distance
218 spawn_allgood = FALSE;
223 spawn_allbad = FALSE;
226 spotlistend.chain = spot;
233 if(spot.team != teamcheck)
234 error("invalid spawn added");
236 print("added ", etos(spot), "\n");
242 spotlistend.chain = world;
247 for(e = spotlist; e; e = e.chain)
249 print("seen ", etos(e), "\n");
250 if(e.team != teamcheck)
251 error("invalid spawn found");
258 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
260 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
261 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
264 RandomSelection_Init();
265 for(spot = firstspot; spot; spot = spot.chain)
266 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
268 return RandomSelection_chosen_ent;
275 Finds a point to respawn
278 entity SelectSpawnPoint (float anypoint)
280 local float teamcheck;
281 local entity firstspot_new;
282 local entity spot, firstspot, playerlist;
284 spot = find (world, classname, "testplayerstart");
290 if(!anypoint && have_team_spawns)
291 teamcheck = self.team;
293 // get the list of players
294 playerlist = findchain(classname, "player");
295 // get the entire list of spots
296 firstspot = findchain(classname, "info_player_deathmatch");
297 // filter out the bad ones
298 // (note this returns the original list if none survived)
299 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
301 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
302 firstspot = firstspot_new;
304 // there is 50/50 chance of choosing a random spot or the furthest spot
305 // (this means that roughly every other spawn will be furthest, so you
306 // usually won't get fragged at spawn twice in a row)
307 if (arena_roundbased)
309 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
311 firstspot = firstspot_new;
312 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
314 else if (random() > cvar("g_spawn_furthest"))
315 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
317 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
319 if(cvar("spawn_debugview"))
321 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
325 for(e = firstspot; e; e = e.chain)
326 if(e.team != teamcheck)
327 error("invalid spawn found");
332 if(cvar("spawn_debug"))
336 if(some_spawn_has_been_used)
337 return world; // team can't spawn any more, because of actions of other team
339 error("Cannot find a spawn point - please fix the map!");
350 Checks if the argument string can be a valid playermodel.
351 Returns a valid one in doubt.
354 string FallbackPlayerModel = "models/player/marine.zym";
355 string CheckPlayerModel(string plyermodel) {
356 if(strlen(plyermodel) < 4)
357 return FallbackPlayerModel;
358 if( substring(plyermodel,0,14) != "models/player/")
359 return FallbackPlayerModel;
360 else if(cvar("sv_servermodelsonly"))
362 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
363 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
364 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
365 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
366 return FallbackPlayerModel;
367 if(plyermodel != strtolower(plyermodel))
368 return FallbackPlayerModel;
369 if(!fexists(plyermodel))
370 return FallbackPlayerModel;
377 Client_customizeentityforclient
382 float Client_customizeentityforclient()
384 #ifdef ALLOW_VARIABLE_LOD
386 // other: the player viewing me
390 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
393 if(other.cvar_cl_playerdetailreduction <= 0)
395 if(other.cvar_cl_playerdetailreduction <= -2)
396 self.modelindex = self.modelindex_lod2;
397 else if(other.cvar_cl_playerdetailreduction <= -1)
398 self.modelindex = self.modelindex_lod1;
400 self.modelindex = self.modelindex_lod0;
404 distance = vlen(self.origin - other.origin);
405 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
407 self.modelindex = self.modelindex_lod2;
409 self.modelindex = self.modelindex_lod1;
411 self.modelindex = self.modelindex_lod0;
418 void UpdatePlayerSounds();
419 void setmodel_lod(entity e, string modelname)
421 #ifdef ALLOW_VARIABLE_LOD
424 // FIXME: this only supports 3-letter extensions
425 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
429 setmodel(e, s); // players have high precision
430 self.modelindex_lod1 = self.modelindex;
433 self.modelindex_lod1 = -1;
435 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
439 setmodel(e, s); // players have high precision
440 self.modelindex_lod2 = self.modelindex;
443 self.modelindex_lod2 = -1;
445 precache_model(modelname);
446 setmodel(e, modelname); // players have high precision
447 self.modelindex_lod0 = self.modelindex;
449 if(self.modelindex_lod1 < 0)
450 self.modelindex_lod1 = self.modelindex;
452 if(self.modelindex_lod2 < 0)
453 self.modelindex_lod2 = self.modelindex;
455 precache_model(modelname);
456 setmodel(e, modelname); // players have high precision
458 player_setupanimsformodel();
459 UpdatePlayerSounds();
466 putting a client as observer in the server
469 void PutObserverInServer (void)
473 race_PreSpawnObserver();
475 spot = SelectSpawnPoint (TRUE);
477 error("No spawnpoints for observers?!?\n");
478 RemoveGrapplingHook(self); // Wazat's Grappling Hook
480 if(clienttype(self) == CLIENTTYPE_REAL)
483 WriteByte(MSG_ONE, SVC_SETVIEW);
484 WriteEntity(MSG_ONE, self);
488 kh_Key_DropAll(self, TRUE);
490 Portal_ClearAll(self);
493 DropFlag(self.flagcarried, world, world);
495 WaypointSprite_PlayerDead();
497 if(self.killcount != -666)
501 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
502 bprint ("^4", self.netname, "^4 has no more lives left\n");
504 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
507 bprint ("^4", self.netname, "^4 is spectating now\n");
510 PlayerScore_Clear(self); // clear scores when needed
512 self.spectatortime = time;
514 self.classname = "observer";
515 self.iscreature = FALSE;
517 self.takedamage = DAMAGE_NO;
518 self.solid = SOLID_NOT;
519 self.movetype = MOVETYPE_NOCLIP;
520 self.flags = FL_CLIENT | FL_NOTARGET;
521 self.armorvalue = 666;
523 self.armorvalue = cvar("g_balance_armor_start");
524 self.pauserotarmor_finished = 0;
525 self.pauserothealth_finished = 0;
526 self.pauseregen_finished = 0;
527 self.damageforcescale = 0;
534 self.pain_finished = 0;
535 self.strength_finished = 0;
536 self.invincible_finished = 0;
538 self.think = SUB_Null;
542 self.deadflag = DEAD_NO;
543 self.angles = spot.angles;
545 self.fixangle = TRUE;
548 self.view_ofs = PL_VIEW_OFS;
549 setorigin (self, spot.origin);
550 setsize (self, '0 0 0', '0 0 0');
551 self.oldorigin = self.origin;
557 self.weaponmodel = "";
558 self.weaponentity = world;
559 self.killcount = -666;
560 self.velocity = '0 0 0';
561 self.avelocity = '0 0 0';
562 self.punchangle = '0 0 0';
563 self.punchvector = '0 0 0';
564 self.oldvelocity = self.velocity;
565 self.customizeentityforclient = Client_customizeentityforclient;
569 if(self.version_mismatch)
571 Spawnqueue_Unmark(self);
572 Spawnqueue_Remove(self);
576 Spawnqueue_Insert(self);
581 // Only if the player cannot play at all
582 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
583 self.frags = FRAGS_SPECTATOR;
585 self.frags = FRAGS_LMS_LOSER;
588 self.frags = FRAGS_SPECTATOR;
591 float RestrictSkin(float s)
600 void FixPlayermodel()
602 local string defaultmodel;
603 local float defaultskin;
608 if(cvar("sv_defaultcharacter") == 1) {
613 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
614 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
617 if(defaultmodel == "")
619 defaultmodel = cvar_string("sv_defaultplayermodel");
620 defaultskin = cvar("sv_defaultplayerskin");
624 if(self.modelindex == 0)
627 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
628 self.model = ""; // force the != checks to return true
631 if(defaultmodel != "")
633 if (defaultmodel != self.model)
637 setmodel_lod (self, defaultmodel);
638 setsize (self, m1, m2);
641 self.skin = defaultskin;
643 if (self.playermodel != self.model)
645 self.playermodel = CheckPlayerModel(self.playermodel);
648 setmodel_lod (self, self.playermodel);
649 setsize (self, m1, m2);
652 self.skin = RestrictSkin(stof(self.playerskin));
656 if(strlen(cvar_string("sv_defaultplayercolors")))
657 if(self.clientcolors != cvar("sv_defaultplayercolors"))
658 setcolor(self, cvar("sv_defaultplayercolors"));
661 void PlayerTouchExplode(entity p1, entity p2)
664 org = (p1.origin + p2.origin) * 0.5;
665 org_z += (p1.mins_z + p2.mins_z) * 0.5;
672 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
680 Called when a client spawns in the server
683 //void() ctf_playerchanged;
684 void PutClientInServer (void)
686 if(clienttype(self) == CLIENTTYPE_BOT)
688 self.classname = "player";
690 else if(clienttype(self) == CLIENTTYPE_REAL)
693 WriteByte(MSG_ONE, SVC_SETVIEW);
694 WriteEntity(MSG_ONE, self);
697 // player is dead and becomes observer
698 // FIXME fix LMS scoring for new system
701 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
702 self.classname = "observer";
707 self.classname = "observer";
709 if(self.classname == "player") {
710 entity spot, oldself;
714 spot = SelectSpawnPoint (FALSE);
717 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
718 return; // spawn failed
721 RemoveGrapplingHook(self); // Wazat's Grappling Hook
722 self.campingrifle_bulletcounter = 0;
724 self.classname = "player";
725 self.wasplayer = TRUE;
726 self.iscreature = TRUE;
727 self.movetype = MOVETYPE_WALK;
728 self.solid = SOLID_SLIDEBOX;
729 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
730 self.frags = FRAGS_PLAYER;
731 if(independent_players)
732 MAKE_INDEPENDENT_PLAYER(self);
733 self.flags = FL_CLIENT;
734 self.takedamage = DAMAGE_AIM;
736 self.effects = EF_FULLBRIGHT;
739 self.air_finished = time + 12;
744 self.ammo_shells = warmup_start_ammo_shells;
745 self.ammo_nails = warmup_start_ammo_nails;
746 self.ammo_rockets = warmup_start_ammo_rockets;
747 self.ammo_cells = warmup_start_ammo_cells;
748 self.health = warmup_start_health;
749 self.armorvalue = warmup_start_armorvalue;
750 self.weapons = warmup_start_weapons;
754 self.ammo_shells = start_ammo_shells;
755 self.ammo_nails = start_ammo_nails;
756 self.ammo_rockets = start_ammo_rockets;
757 self.ammo_cells = start_ammo_cells;
758 self.health = start_health;
759 self.armorvalue = start_armorvalue;
760 self.weapons = start_weapons;
762 self.items = start_items;
763 self.switchweapon = w_getbestweapon(self);
764 self.cnt = self.switchweapon;
766 self.jump_interval = time;
768 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
769 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
770 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
771 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
772 //extend the pause of rotting if client was reset at the beginning of the countdown
773 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
774 self.spawnshieldtime += game_starttime - time;
775 self.pauserotarmor_finished += game_starttime - time;
776 self.pauserothealth_finished += game_starttime - time;
777 self.pauseregen_finished += game_starttime - time;
779 self.damageforcescale = 2;
786 self.pain_finished = 0;
787 self.strength_finished = 0;
788 self.invincible_finished = 0;
790 //self.speed_finished = 0;
791 //self.slowmo_finished = 0;
792 // players have no think function
793 self.think = SUB_Null;
800 self.deadflag = DEAD_NO;
802 self.angles = spot.angles;
804 self.angles_z = 0; // never spawn tilted even if the spot says to
805 self.fixangle = TRUE; // turn this way immediately
806 self.velocity = '0 0 0';
807 self.avelocity = '0 0 0';
808 self.punchangle = '0 0 0';
809 self.punchvector = '0 0 0';
810 self.oldvelocity = self.velocity;
813 WRITESPECTATABLE_MSG_ONE({
814 WriteByte(MSG_ONE, SVC_TEMPENTITY);
815 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
818 self.customizeentityforclient = Client_customizeentityforclient;
824 self.view_ofs = PL_VIEW_OFS;
825 setsize (self, PL_MIN, PL_MAX);
826 self.spawnorigin = spot.origin;
827 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
828 // don't reset back to last position, even if new position is stuck in solid
829 self.oldorigin = self.origin;
833 Spawnqueue_Remove(self);
834 Spawnqueue_Mark(self);
837 self.event_damage = PlayerDamage;
839 self.bot_attack = TRUE;
841 self.statdraintime = time + 5;
842 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
844 if(self.killcount == -666) {
845 PlayerScore_Clear(self);
849 self.cnt = WEP_LASER;
850 self.nixnex_lastchange_id = -1;
852 CL_SpawnWeaponentity();
853 self.alpha = default_player_alpha;
854 self.colormod = '1 1 1' * cvar("g_player_brightness");
855 self.exteriorweaponentity.alpha = default_weapon_alpha;
857 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
858 self.lms_traveled_distance = 0;
859 self.speedrunning = FALSE;
861 race_PostSpawn(spot);
863 if(cvar("spawn_debug"))
865 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
866 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
869 //stuffcmd(self, "chase_active 0");
870 //stuffcmd(self, "set viewsize $tmpviewsize \n");
872 if (cvar("g_spawnsound"))
873 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
876 if(self.team == assault_attacker_team)
877 centerprint(self, "You are attacking!");
879 centerprint(self, "You are defending!");
882 target_voicescript_clear(self);
891 } else if(self.classname == "observer") {
892 PutObserverInServer ();
896 // ctf_playerchanged();
899 float ClientInit_SendEntity(entity to, float sf)
902 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
903 WriteShort(MSG_ENTITY, CSQC_REVISION);
904 for(i = 1; i <= 24; ++i)
905 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
906 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
907 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
908 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
910 if(sv_foginterval && world.fog != "")
911 WriteString(MSG_ENTITY, world.fog);
913 WriteString(MSG_ENTITY, "");
918 void ClientInit_Spawn()
920 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
928 void SetNewParms (void)
930 // initialize parms for a new player
931 parm1 = -(86400 * 366);
939 void SetChangeParms (void)
941 // save parms for level change
942 parm1 = self.parm_idlesince - time;
950 void DecodeLevelParms (void)
953 self.parm_idlesince = parm1;
954 if(self.parm_idlesince == -(86400 * 366))
955 self.parm_idlesince = time;
957 // whatever happens, allow 60 seconds of idling directly after connect for map loading
958 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
965 Called when a client types 'kill' in the console
969 void ClientKill_Now_TeamChange()
971 if(self.killindicator_teamchange == -1)
974 JoinBestTeam( self, FALSE, FALSE );
978 SV_ChangeTeam(self.killindicator_teamchange - 1);
982 void ClientKill_Now()
984 if(self.killindicator_teamchange)
985 ClientKill_Now_TeamChange();
988 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
990 if(self.killindicator)
992 dprint("Cleaned up after a leaked kill indicator.\n");
993 remove(self.killindicator);
994 self.killindicator = world;
997 void KillIndicator_Think()
999 if (!self.owner.modelindex)
1001 self.owner.killindicator = world;
1009 ClientKill_Now(); // no oldself needed
1015 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1016 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1019 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1020 if(self.owner.killindicator_teamchange)
1022 if(self.owner.killindicator_teamchange == -1)
1023 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1025 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1028 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1030 self.nextthink = time + 1;
1035 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1039 killtime = cvar("g_balance_kill_delay");
1041 self.killindicator_teamchange = targetteam;
1043 if(!self.killindicator)
1045 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1051 self.killindicator = spawn();
1052 self.killindicator.owner = self;
1053 self.killindicator.scale = 0.5;
1054 setattachment(self.killindicator, self, "");
1055 setorigin(self.killindicator, '0 0 52');
1056 self.killindicator.think = KillIndicator_Think;
1057 self.killindicator.nextthink = time + (self.lip) * 0.05;
1058 self.killindicator.cnt = ceil(killtime);
1059 self.killindicator.count = bound(0, ceil(killtime), 10);
1060 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1062 for(e = world; (e = find(e, classname, "body")) != world; )
1066 e.killindicator = spawn();
1067 e.killindicator.owner = e;
1068 e.killindicator.scale = 0.5;
1069 setattachment(e.killindicator, e, "");
1070 setorigin(e.killindicator, '0 0 52');
1071 e.killindicator.think = KillIndicator_Think;
1072 e.killindicator.nextthink = time + (e.lip) * 0.05;
1073 e.killindicator.cnt = ceil(killtime);
1078 if(self.killindicator)
1081 self.killindicator.colormod = TeamColor(targetteam);
1083 self.killindicator.colormod = '0 0 0';
1087 void ClientKill (void)
1089 ClientKill_TeamChange(0);
1092 void DoTeamChange(float destteam)
1098 SetPlayerColors(self, destteam);
1101 if(self.classname == "player")
1104 CheckAllowedTeams(self);
1105 t = FindSmallestTeam(self, TRUE);
1108 case COLOR_TEAM1: c0 = c1; break;
1109 case COLOR_TEAM2: c0 = c2; break;
1110 case COLOR_TEAM3: c0 = c3; break;
1111 case COLOR_TEAM4: c0 = c4; break;
1118 destteam = COLOR_TEAM1;
1122 destteam = COLOR_TEAM2;
1126 destteam = COLOR_TEAM3;
1130 destteam = COLOR_TEAM4;
1136 if(destteam == self.team && !self.killindicator)
1138 ClientKill_TeamChange(destteam);
1141 void FixClientCvars(entity e)
1143 // send prediction settings to the client
1144 stuffcmd(e, "\nin_bindmap 0 0\n");
1146 * we no longer need to stuff this. Remove this comment block if you feel
1147 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1148 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1149 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1150 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1151 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1152 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1153 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1154 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1155 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1156 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1157 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1158 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1159 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1160 stuffcmd(e, "cl_movement_edgefriction 1\n");
1168 Called when a client connects to the server
1171 //void ctf_clientconnect();
1172 string ColoredTeamName(float t);
1173 void DecodeLevelParms (void);
1174 //void dom_player_join_team(entity pl);
1175 void ClientConnect (void)
1180 if(self.flags & FL_CLIENT)
1182 print("Warning: ClientConnect, but already connected!\n");
1186 if(Ban_MaybeEnforceBan(self))
1191 self.classname = "player_joining";
1193 self.flags = FL_CLIENT;
1194 self.version_nagtime = time + 10 + random() * 10;
1198 dprint("BUG player count is lower than zero, this cannot happen!\n");
1202 PlayerScore_Attach(self);
1203 ClientData_Attach();
1205 bot_clientconnect();
1207 race_PreSpawnObserver();
1210 // dom_player_join_team(self);
1212 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1214 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1215 self.classname = "observer";
1219 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1221 self.classname = "player";
1222 campaign_bots_may_start = 1;
1226 self.classname = "observer"; // do it anyway
1231 self.classname = "player";
1232 campaign_bots_may_start = 1;
1236 self.playerid = (playerid_last = playerid_last + 1);
1237 if(cvar("sv_eventlog"))
1239 if(clienttype(self) == CLIENTTYPE_REAL)
1240 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1242 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1243 s = strcat(":team:", ftos(self.playerid), ":");
1244 s = strcat(s, ftos(self.team));
1247 self.netname_previous = strzone(self.netname);
1249 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1251 bprint ("^4",self.netname);
1252 bprint ("^4 connected");
1254 if(g_domination || g_ctf)
1256 bprint(" and joined the ");
1257 bprint(ColoredTeamName(self.team));
1262 self.welcomemessage_time = 0;
1264 stuffcmd(self, strcat(clientstuff, "\n"));
1265 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1266 stuffcmd(self, "cl_particles_reloadeffects\n");
1268 FixClientCvars(self);
1270 // spawnfunc_waypoint sprites
1271 WaypointSprite_InitClient(self);
1273 // Wazat's grappling hook
1274 SetGrappleHookBindings();
1276 // get autoswitch state from player when he toggles it
1277 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1279 // get version info from player
1280 stuffcmd(self, "cmd clientversion $gameversion\n");
1282 // get other cvars from player
1285 // set cvar for team scoreboard
1286 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1288 // notify about available teams
1291 CheckAllowedTeams(self);
1292 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1293 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1296 stuffcmd(self, "set _teams_available 0\n");
1298 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1302 self.classname = "observer";
1303 Spawnqueue_Insert(self);
1307 ctf_clientconnect();
1313 bot_relinkplayerlist();
1315 self.spectatortime = time;
1318 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1321 self.jointime = time;
1322 self.allowedTimeouts = cvar("sv_timeout_number");
1324 if(clienttype(self) == CLIENTTYPE_REAL)
1326 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1328 if(cvar("g_bugrigs"))
1329 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1334 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1336 PlayerScore_Add(self, SP_LMS_RANK, 666);
1337 self.frags = FRAGS_SPECTATOR;
1341 if(!sv_foginterval && world.fog != "")
1342 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1349 Called when a client disconnects from the server
1352 .entity chatbubbleentity;
1353 .entity teambubbleentity;
1355 void ClientDisconnect (void)
1357 if not(self.flags & FL_CLIENT)
1359 print("Warning: ClientDisconnect without ClientConnect\n");
1363 bot_clientdisconnect();
1368 if(cvar("sv_eventlog"))
1369 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1370 bprint ("^4",self.netname);
1371 bprint ("^4 disconnected\n");
1374 kh_Key_DropAll(self, TRUE);
1376 Portal_ClearAll(self);
1378 if(self.flagcarried)
1379 DropFlag(self.flagcarried, world, world);
1381 // Here, everything has been done that requires this player to be a client.
1383 self.flags &~= FL_CLIENT;
1385 if (self.chatbubbleentity)
1386 remove (self.chatbubbleentity);
1388 if (self.teambubbleentity)
1389 remove (self.teambubbleentity);
1391 if (self.killindicator)
1392 remove (self.killindicator);
1394 WaypointSprite_PlayerGone();
1396 bot_relinkplayerlist();
1399 if(self.weaponentity)
1400 if(self.weaponentity.lasertarget)
1401 remove(self.weaponentity.lasertarget);
1405 Spawnqueue_Unmark(self);
1406 Spawnqueue_Remove(self);
1409 ClientData_Detach();
1410 PlayerScore_Detach(self);
1412 if(self.netname_previous)
1413 strunzone(self.netname_previous);
1415 ClearPlayerSounds();
1425 void ChatBubbleThink()
1427 self.nextthink = time;
1428 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1430 if(self.owner) // but why can that ever be world?
1431 self.owner.chatbubbleentity = world;
1435 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1436 self.model = self.mdl;
1441 void UpdateChatBubble()
1443 if (!self.modelindex)
1445 // spawn a chatbubble entity if needed
1446 if (!self.chatbubbleentity)
1448 self.chatbubbleentity = spawn();
1449 self.chatbubbleentity.owner = self;
1450 self.chatbubbleentity.exteriormodeltoclient = self;
1451 self.chatbubbleentity.think = ChatBubbleThink;
1452 self.chatbubbleentity.nextthink = time;
1453 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1454 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1455 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1456 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1457 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1458 self.chatbubbleentity.model = "";
1459 self.chatbubbleentity.effects = EF_LOWPRECISION;
1464 void TeamBubbleThink()
1466 self.nextthink = time;
1467 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1469 if(self.owner) // but why can that ever be world?
1470 self.owner.teambubbleentity = world;
1474 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1475 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1478 self.model = self.mdl;
1482 float TeamBubble_customizeentityforclient()
1484 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1487 void UpdateTeamBubble()
1489 if (!self.modelindex || !teams_matter)
1491 // spawn a teambubble entity if needed
1492 if (!self.teambubbleentity && teams_matter)
1494 self.teambubbleentity = spawn();
1495 self.teambubbleentity.owner = self;
1496 self.teambubbleentity.exteriormodeltoclient = self;
1497 self.teambubbleentity.think = TeamBubbleThink;
1498 self.teambubbleentity.nextthink = time;
1499 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1500 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1501 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1502 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1503 self.teambubbleentity.mdl = self.teambubbleentity.model;
1504 self.teambubbleentity.model = self.teambubbleentity.mdl;
1505 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1506 self.teambubbleentity.effects = EF_LOWPRECISION;
1510 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1511 // added to the model skins
1512 /*void UpdateColorModHack()
1515 c = self.clientcolors & 15;
1516 // LordHavoc: only bothering to support white, green, red, yellow, blue
1517 if (!teams_matter) self.colormod = '0 0 0';
1518 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1519 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1520 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1521 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1522 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1523 else self.colormod = '1 1 1';
1529 self.effects |= EF_NODRAW; // prevent another CopyBody
1530 PutClientInServer();
1534 * When sv_timeout is used this function returs strings like
1535 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1536 * Called by centerprint functions
1537 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1539 string getTimeoutText(float addOneSecond) {
1540 if (!cvar("sv_timeout") || !timeoutStatus)
1543 local string retStr;
1544 if (timeoutStatus == 1) {
1545 if (addOneSecond == 1) {
1546 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1549 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1553 else if (timeoutStatus == 2) {
1555 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1556 //don't show messages like "Timeout ends in 0 seconds"...
1557 if ((remainingTimeoutTime + 1) > 0)
1563 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1564 //don't show messages like "Timeout ends in 0 seconds"...
1565 if (remainingTimeoutTime > 0)
1574 void player_powerups (void)
1578 if (self.items & IT_STRENGTH)
1580 if (time > self.strength_finished)
1582 self.alpha = default_player_alpha;
1583 self.exteriorweaponentity.alpha = default_weapon_alpha;
1584 self.items &~= IT_STRENGTH;
1585 sprint(self, "^3Invisibility has worn off\n");
1590 if (time < self.strength_finished)
1592 self.alpha = g_minstagib_invis_alpha;
1593 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1594 self.items |= IT_STRENGTH;
1595 sprint(self, "^3You are invisible\n");
1599 if (self.items & IT_INVINCIBLE)
1601 if (time > self.invincible_finished)
1603 self.items = self.items - (self.items & IT_INVINCIBLE);
1604 sprint(self, "^3Speed has worn off\n");
1609 if (time < self.invincible_finished)
1611 self.items = self.items | IT_INVINCIBLE;
1612 sprint(self, "^3You are on speed\n");
1618 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1620 if(!self.modelindex) // don't apply the flags if the player is gibbed
1623 if (self.items & IT_STRENGTH)
1625 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1626 if (time > self.strength_finished)
1628 self.items = self.items - (self.items & IT_STRENGTH);
1629 sprint(self, "^3Strength has worn off\n");
1634 if (time < self.strength_finished)
1636 self.items = self.items | IT_STRENGTH;
1637 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1640 if (self.items & IT_INVINCIBLE)
1642 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1643 if (time > self.invincible_finished)
1645 self.items = self.items - (self.items & IT_INVINCIBLE);
1646 sprint(self, "^3Shield has worn off\n");
1651 if (time < self.invincible_finished)
1653 self.items = self.items | IT_INVINCIBLE;
1654 sprint(self, "^3Shield surrounds you\n");
1658 if (cvar("g_fullbrightplayers"))
1659 self.effects = self.effects | EF_FULLBRIGHT;
1661 // midair gamemode: damage only while in the air
1662 // if in midair mode, being on ground grants temporary invulnerability
1663 // (this is so that multishot weapon don't clear the ground flag on the
1664 // first damage in the frame, leaving the player vulnerable to the
1665 // remaining hits in the same frame)
1666 if (self.flags & FL_ONGROUND)
1668 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1670 if (time >= game_starttime)
1671 if (time < self.spawnshieldtime)
1672 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1675 float CalcRegen(float current, float stable, float regenfactor)
1677 if(current > stable)
1679 else if(current > stable - 0.25) // when close enough, "snap"
1682 return min(stable, current + (stable - current) * regenfactor * frametime);
1685 void player_regen (void)
1687 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1688 maxh = cvar("g_balance_health_stable");
1689 maxa = cvar("g_balance_armor_stable");
1690 limith = cvar("g_balance_health_limit");
1691 limita = cvar("g_balance_armor_limit");
1693 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1696 max_mod = regen_mod = rot_mod = limit_mod = 1;
1698 if (self.runes & RUNE_REGEN)
1700 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1702 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1703 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1704 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1708 regen_mod = cvar("g_balance_rune_regen_regenrate");
1709 max_mod = cvar("g_balance_rune_regen_hpmod");
1710 limit_mod = cvar("g_balance_rune_regen_limitmod");
1713 else if (self.runes & CURSE_VENOM)
1715 max_mod = cvar("g_balance_curse_venom_hpmod");
1716 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1717 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1719 rot_mod = cvar("g_balance_curse_venom_rotrate");
1720 limit_mod = cvar("g_balance_curse_venom_limitmod");
1721 //if (!self.runes & RUNE_REGEN)
1722 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1724 maxh = maxh * max_mod;
1725 //maxa = maxa * max_mod;
1726 limith = limith * limit_mod;
1727 limita = limita * limit_mod;
1729 if (self.armorvalue > maxa)
1731 if (time > self.pauserotarmor_finished)
1733 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1734 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1737 else if (self.armorvalue < maxa)
1739 if (time > self.pauseregen_finished)
1741 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1742 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1745 if (self.health > maxh)
1747 if (time > self.pauserothealth_finished)
1749 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1750 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1753 else if (self.health < maxh)
1755 if (time > self.pauseregen_finished)
1757 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1758 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1762 if (self.health > limith)
1763 self.health = limith;
1764 if (self.armorvalue > limita)
1765 self.armorvalue = limita;
1767 // if player rotted to death... die!
1769 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1772 float zoomstate_set;
1773 void SetZoomState(float z)
1775 if(z != self.zoomstate)
1776 ClientData_Touch(self);
1780 void GetPressedKeys(void) {
1781 if (self.movement_x > 0) // get if movement keys are pressed
1782 { // forward key pressed
1783 self.pressedkeys |= KEY_FORWARD;
1784 self.pressedkeys &~= KEY_BACKWARD;
1786 else if (self.movement_x < 0)
1787 { // backward key pressed
1788 self.pressedkeys |= KEY_BACKWARD;
1789 self.pressedkeys &~= KEY_FORWARD;
1793 self.pressedkeys &~= KEY_FORWARD;
1794 self.pressedkeys &~= KEY_BACKWARD;
1797 if (self.movement_y > 0)
1798 { // right key pressed
1799 self.pressedkeys |= KEY_RIGHT;
1800 self.pressedkeys &~= KEY_LEFT;
1802 else if (self.movement_y < 0)
1803 { // left key pressed
1804 self.pressedkeys |= KEY_LEFT;
1805 self.pressedkeys &~= KEY_RIGHT;
1809 self.pressedkeys &~= KEY_RIGHT;
1810 self.pressedkeys &~= KEY_LEFT;
1813 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1814 self.pressedkeys |= KEY_JUMP;
1816 self.pressedkeys &~= KEY_JUMP;
1817 if (self.BUTTON_CROUCH)
1818 self.pressedkeys |= KEY_CROUCH;
1820 self.pressedkeys &~= KEY_CROUCH;
1824 ======================
1825 spectate mode routines
1826 ======================
1828 void SpectateCopy(entity spectatee) {
1829 self.armortype = spectatee.armortype;
1830 self.armorvalue = spectatee.armorvalue;
1831 self.currentammo = spectatee.currentammo;
1832 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1833 self.health = spectatee.health;
1835 self.items = spectatee.items;
1836 self.strength_finished = spectatee.strength_finished;
1837 self.invincible_finished = spectatee.invincible_finished;
1838 self.pressedkeys = spectatee.pressedkeys;
1839 self.weapons = spectatee.weapons;
1840 self.switchweapon = spectatee.switchweapon;
1841 self.weapon = spectatee.weapon;
1842 self.punchangle = spectatee.punchangle;
1843 self.view_ofs = spectatee.view_ofs;
1844 self.v_angle = spectatee.v_angle;
1845 self.velocity = spectatee.velocity;
1846 self.dmg_take = spectatee.dmg_take;
1847 self.dmg_save = spectatee.dmg_save;
1848 self.dmg_inflictor = spectatee.dmg_inflictor;
1849 self.angles = spectatee.v_angle;
1850 self.fixangle = TRUE;
1851 setorigin(self, spectatee.origin);
1852 setsize(self, spectatee.mins, spectatee.maxs);
1853 SetZoomState(spectatee.zoomstate);
1856 float SpectateUpdate() {
1860 if (self == self.enemy)
1863 if(self.enemy.flags & FL_NOTARGET)
1866 SpectateCopy(self.enemy);
1871 float SpectateNext() {
1872 other = find(self.enemy, classname, "player");
1874 other = find(other, classname, "player");
1879 if(self.enemy.classname == "player") {
1881 WriteByte(MSG_ONE, SVC_SETVIEW);
1882 WriteEntity(MSG_ONE, self.enemy);
1883 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1884 if(!SpectateUpdate())
1885 PutObserverInServer();
1894 ShowRespawnCountdown()
1896 Update a respawn countdown display.
1899 void ShowRespawnCountdown()
1902 if(self.deadflag == DEAD_NO) // just respawned?
1906 number = ceil(self.death_time - time);
1909 if(number <= self.respawn_countdown)
1911 self.respawn_countdown = number - 1;
1912 if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1913 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
1918 void LeaveSpectatorMode()
1920 if(isJoinAllowed()) {
1921 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
1922 self.classname = "player";
1923 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1924 JoinBestTeam(self, FALSE, TRUE);
1925 if(cvar("g_campaign"))
1926 campaign_bots_may_start = 1;
1927 PutClientInServer();
1928 if(!(self.flags & FL_NOTARGET))
1929 bprint ("^4", self.netname, "^4 is playing now\n");
1930 centerprint(self,"");
1933 stuffcmd(self,"menu_showteamselect\n");
1938 //player may not join because of g_maxplayers is set
1939 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1944 * Determines whether the player is allowed to join. This depends on cvar
1945 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1946 * it checks whether the number of currently playing players exceeds g_maxplayers.
1947 * @return bool TRUE if the player is allowed to join, false otherwise
1949 float isJoinAllowed() {
1950 if (!cvar("g_maxplayers"))
1954 local float currentlyPlaying;
1955 FOR_EACH_REALPLAYER(e) {
1956 if(e.classname == "player")
1957 currentlyPlaying += 1;
1959 if(currentlyPlaying < cvar("g_maxplayers"))
1966 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1967 * g_maxplayers_spectator_blocktime seconds
1969 void checkSpectatorBlock() {
1970 if(self.classname == "spectator" || self.classname == "observer") {
1971 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1972 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1978 float vercmp_recursive(string v1, string v2)
1984 dot1 = strstrofs(v1, ".", 0);
1985 dot2 = strstrofs(v2, ".", 0);
1989 s1 = substring(v1, 0, dot1);
1993 s2 = substring(v2, 0, dot2);
1995 r = stof(s1) - stof(s2);
1999 r = strcasecmp(s1, s2);
2012 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2015 float vercmp(string v1, string v2)
2017 if(strcasecmp(v1, v2) == 0) // early out check
2019 return vercmp_recursive(v1, v2);
2022 void ObserverThink()
2024 if (self.flags & FL_JUMPRELEASED) {
2025 if (self.BUTTON_JUMP && !self.version_mismatch) {
2026 self.welcomemessage_time = 0;
2027 self.flags &~= FL_JUMPRELEASED;
2028 LeaveSpectatorMode();
2030 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2031 self.welcomemessage_time = 0;
2032 self.flags &~= FL_JUMPRELEASED;
2033 if(SpectateNext() == 1) {
2034 self.classname = "spectator";
2038 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2039 self.flags |= FL_JUMPRELEASED;
2042 PrintWelcomeMessage(self);
2045 void SpectatorThink()
2047 if (self.flags & FL_JUMPRELEASED) {
2048 if (self.BUTTON_JUMP && !self.version_mismatch) {
2049 self.welcomemessage_time = 0;
2050 self.flags &~= FL_JUMPRELEASED;
2051 LeaveSpectatorMode();
2053 } else if(self.BUTTON_ATCK) {
2054 self.welcomemessage_time = 0;
2055 self.flags &~= FL_JUMPRELEASED;
2056 if(SpectateNext() == 1) {
2057 self.classname = "spectator";
2059 self.classname = "observer";
2060 PutClientInServer();
2062 } else if (self.BUTTON_ATCK2) {
2063 self.welcomemessage_time = 0;
2064 self.flags &~= FL_JUMPRELEASED;
2065 self.classname = "observer";
2066 PutClientInServer();
2068 if(!SpectateUpdate())
2069 PutObserverInServer();
2072 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2073 self.flags |= FL_JUMPRELEASED;
2076 PrintWelcomeMessage(self);
2077 self.flags |= FL_CLIENT | FL_NOTARGET;
2080 .float touchexplode_time;
2086 Called every frame for each client before the physics are run
2089 void() ctf_setstatus;
2090 void PlayerPreThink (void)
2092 self.stat_sys_ticrate = cvar("sys_ticrate");
2093 self.stat_game_starttime = game_starttime;
2094 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2096 if(blockSpectators && frametime)
2097 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2098 checkSpectatorBlock();
2102 if(self.netname_previous != self.netname)
2104 if(cvar("sv_eventlog"))
2105 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2106 if(self.netname_previous)
2107 strunzone(self.netname_previous);
2108 self.netname_previous = strzone(self.netname);
2112 if(self.version_nagtime)
2113 if(self.cvar_g_nexuizversion)
2114 if(time > self.version_nagtime)
2116 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2118 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2120 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2121 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2126 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2129 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n");
2130 sprint(self, strcat("\{1}^1NOTE: ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n"));
2134 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2135 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2139 self.version_nagtime = 0;
2143 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2145 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2146 self.max_armorvalue = 0;
2150 antilag_record(self);
2152 if(self.classname == "player") {
2153 // if(self.netname == "Wazat")
2154 // bprint(self.classname, "\n");
2156 CheckRules_Player();
2158 PrintWelcomeMessage(self);
2160 if (intermission_running)
2162 IntermissionThink (); // otherwise a button could be missed between
2163 return; // the think tics
2166 if(self.teleport_time)
2167 if(time > self.teleport_time)
2169 self.teleport_time = 0;
2170 self.effects = self.effects - (self.effects & EF_NODRAW);
2173 Nixnex_GiveCurrentWeapon();
2175 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2176 UpdateSelectedPlayer();
2178 //don't allow the player to turn around while game is paused!
2179 if(timeoutStatus == 2) {
2180 self.v_angle = self.lastV_angle;
2181 self.angles = self.lastV_angle;
2182 self.fixangle = TRUE;
2185 if (self.deadflag != DEAD_NO)
2187 float button_pressed, force_respawn;
2189 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2190 force_respawn = (g_lms || cvar("g_forced_respawn"));
2191 if (self.deadflag == DEAD_DYING)
2194 self.deadflag = DEAD_RESPAWNING;
2195 else if(!button_pressed)
2196 self.deadflag = DEAD_DEAD;
2198 else if (self.deadflag == DEAD_DEAD)
2201 self.deadflag = DEAD_RESPAWNABLE;
2203 else if (self.deadflag == DEAD_RESPAWNABLE)
2206 self.deadflag = DEAD_RESPAWNING;
2208 else if (self.deadflag == DEAD_RESPAWNING)
2210 if(time > self.death_time)
2212 self.death_time = time + 1; // only retry once a second
2216 ShowRespawnCountdown();
2221 if(time > self.touchexplode_time)
2222 if(self.classname == "player")
2223 if(self.deadflag == DEAD_NO)
2224 if not(IS_INDEPENDENT_PLAYER(self))
2225 FOR_EACH_PLAYER(other) if(self != other)
2227 if(time > other.touchexplode_time)
2228 if(other.classname == "player")
2229 if(other.deadflag == DEAD_NO)
2230 if not(IS_INDEPENDENT_PLAYER(other))
2231 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2233 PlayerTouchExplode(self, other);
2234 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2238 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2242 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2243 dist = self.oldorigin - self.origin;
2245 self.lms_traveled_distance += fabs(vlen(dist));
2247 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2249 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2250 self.lms_traveled_distance = 0;
2253 if(time > self.lms_nextcheck)
2255 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2256 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2258 centerprint(self, cvar_string("g_lms_campcheck_message"));
2259 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2260 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2261 Damage(self, self, self, bound(0, cvar("g_lms_campcheck_damage"), self.health + self.armorvalue * cvar("g_balance_armor_blockpercent") + 5), DEATH_CAMP, self.origin, '0 0 0');
2263 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2264 self.lms_traveled_distance = 0;
2268 self.oldorigin = self.origin;
2270 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2275 self.view_ofs = PL_CROUCH_VIEW_OFS;
2276 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2277 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2284 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2285 if (!trace_startsolid)
2287 self.crouch = FALSE;
2288 self.view_ofs = PL_VIEW_OFS;
2289 setsize (self, PL_MIN, PL_MAX);
2294 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2296 if(self.bloodloss_timer < time)
2298 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2299 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2305 GrapplingHookFrame();
2314 minstagib_ammocheck();
2319 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2321 //self.angles_y=self.v_angle_y + 90; // temp
2323 //if (TetrisPreFrame()) return;
2324 } else if(gameover) {
2325 if (intermission_running)
2326 IntermissionThink (); // otherwise a button could be missed between
2328 } else if(self.classname == "observer") {
2330 } else if(self.classname == "spectator") {
2335 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2337 float oldspectatee_status;
2338 oldspectatee_status = self.spectatee_status;
2339 if(self.classname == "spectator")
2340 self.spectatee_status = num_for_edict(self.enemy);
2341 else if(self.classname == "observer")
2342 self.spectatee_status = num_for_edict(self);
2344 self.spectatee_status = 0;
2345 if(self.spectatee_status != oldspectatee_status)
2347 ClientData_Touch(self);
2349 race_InitSpectator();
2352 if(self.teamkill_soundtime)
2353 if(time > self.teamkill_soundtime)
2355 self.teamkill_soundtime = 0;
2357 entity oldpusher, oldself;
2359 oldself = self; self = self.teamkill_soundsource;
2360 oldpusher = self.pusher; self.pusher = oldself;
2362 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2364 self.pusher = oldpusher;
2368 if(self.taunt_soundtime)
2369 if(time > self.taunt_soundtime)
2371 self.taunt_soundtime = 0;
2372 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2375 target_voicescript_next(self);
2383 Called every frame for each client after the physics are run
2386 .float idlekick_lasttimeleft;
2387 .float race_penalty;
2388 .float race_penalty_nagged;
2389 .float race_penalty_nagtime;
2390 void PlayerPostThink (void)
2392 // Savage: Check for nameless players
2393 if (strlen(self.netname) < 1) {
2394 self.netname = "Player";
2395 stuffcmd(self, "seta _cl_name Player\n");
2398 if(sv_maxidle && frametime)
2400 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2402 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2405 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2406 announce(self, "announcer/robotic/terminated.wav");
2410 else if(timeleft <= 10)
2412 if(timeleft != self.idlekick_lasttimeleft)
2414 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2415 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2420 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2422 self.idlekick_lasttimeleft = timeleft;
2425 if(self.classname == "player") {
2426 CheckRules_Player();
2431 if (intermission_running)
2432 return; // intermission or finale
2434 //if (TetrisPostFrame()) return;
2436 // restart countdown
2437 if(time < game_starttime) {
2438 if (!cvar("sv_ready_restart_after_countdown"))
2440 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2442 if(time < game_starttime - 2)
2444 if(!self.race_penalty_nagged)
2446 // TODO better notification for this!
2447 self.race_penalty_nagtime = 0;
2448 self.race_penalty_nagged = 1;
2451 else if(!self.race_penalty)
2453 self.race_penalty_nagtime = 0;
2454 self.race_penalty = time + 5;
2457 if(time > self.race_penalty_nagtime)
2459 if(self.race_penalty > time)
2461 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2463 else if(self.race_penalty_nagged && time < game_starttime - 2)
2465 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2467 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2469 self.movetype = MOVETYPE_NONE;
2470 self.velocity = '0 0 0';
2471 self.avelocity = '0 0 0';
2472 self.movement = '0 0 0';
2475 else if (time < self.race_penalty)
2477 self.movetype = MOVETYPE_NONE;
2478 self.velocity = '0 0 0';
2479 self.avelocity = '0 0 0';
2480 self.movement = '0 0 0';
2484 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2485 if (!cvar("sv_ready_restart_after_countdown"))
2487 if(self.movetype == MOVETYPE_NONE)
2489 self.movetype = MOVETYPE_WALK;
2491 self.race_penalty = 0;
2492 self.race_penalty_nagged = 0;
2496 } else if (self.classname == "observer") {
2498 } else if (self.classname == "spectator") {
2504 for(i = 0; i < 1000; ++i)
2507 end = self.origin + '0 0 1024' + 512 * randomvec();
2508 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2509 if(trace_fraction < 1)
2510 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2512 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2520 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);