1 #define SPAWNPOINT_SCORE frags
3 .float wantswelcomemessage;
4 .string netname_previous;
6 void spawnfunc_info_player_survivor (void)
8 spawnfunc_info_player_deathmatch();
11 void spawnfunc_info_player_start (void)
13 spawnfunc_info_player_deathmatch();
16 void spawnfunc_info_player_deathmatch (void)
18 self.classname = "info_player_deathmatch";
19 relocate_spawnpoint();
27 self.team = activator.team;
28 some_spawn_has_been_used = 1;
33 // -1 if a spawn can't be used
34 // otherwise, a weight of the spawnpoint
35 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
37 float shortest, thisdist;
40 // filter out spots for the wrong team
42 if(spot.team != teamcheck)
49 // filter out spots for assault
50 if(spot.target != "") {
53 ent = find(world, targetname, spot.target);
56 if(ent.classname == "target_objective")
58 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
62 else if(ent.classname == "trigger_race_checkpoint")
64 if(self.classname == "player") // spectators may spawn everywhere
69 if(ent.race_checkpoint != 0)
71 if(spot.race_place != race_lowest_place_spawn)
76 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
80 if(pl > race_highest_place_spawn)
82 if(spot.race_place != pl)
91 ent = find(ent, targetname, spot.target);
99 shortest = vlen(world.maxs - world.mins);
100 for(player = playerlist; player; player = player.chain)
103 thisdist = vlen(player.origin - spot.origin);
104 if (thisdist < shortest)
112 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
114 local entity spot, spotlist, spotlistend;
115 spawn_allgood = TRUE;
121 for(spot = firstspot; spot; spot = spot.chain)
123 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
125 if(cvar("spawn_debugview"))
127 setmodel(spot, "models/runematch/rune.mdl");
128 if(spot.SPAWNPOINT_SCORE < mindist)
130 spot.colormod = '1 0 0';
135 spot.colormod = '0 1 0';
136 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
140 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
142 if(spot.SPAWNPOINT_SCORE < mindist)
144 // too short distance
145 spawn_allgood = FALSE;
150 spawn_allbad = FALSE;
153 spotlistend.chain = spot;
160 if(spot.team != teamcheck)
161 error("invalid spawn added");
163 print("added ", etos(spot), "\n");
169 spotlistend.chain = world;
174 for(e = spotlist; e; e = e.chain)
176 print("seen ", etos(e), "\n");
177 if(e.team != teamcheck)
178 error("invalid spawn found");
185 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
187 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
188 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
191 RandomSelection_Init();
192 for(spot = firstspot; spot; spot = spot.chain)
193 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
195 return RandomSelection_chosen_ent;
202 Finds a point to respawn
205 entity SelectSpawnPoint (float anypoint)
207 local float teamcheck;
208 local entity firstspot_new;
209 local entity spot, firstspot, playerlist;
211 spot = find (world, classname, "testplayerstart");
217 if(!anypoint && have_team_spawns)
218 teamcheck = self.team;
220 // get the list of players
221 playerlist = findchain(classname, "player");
222 // get the entire list of spots
223 firstspot = findchain(classname, "info_player_deathmatch");
224 // filter out the bad ones
225 // (note this returns the original list if none survived)
226 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
228 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
229 firstspot = firstspot_new;
231 // there is 50/50 chance of choosing a random spot or the furthest spot
232 // (this means that roughly every other spawn will be furthest, so you
233 // usually won't get fragged at spawn twice in a row)
234 if (arena_roundbased)
236 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
238 firstspot = firstspot_new;
239 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
241 else if (random() > cvar("g_spawn_furthest"))
242 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
244 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
246 if(cvar("spawn_debugview"))
248 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
252 for(e = firstspot; e; e = e.chain)
253 if(e.team != teamcheck)
254 error("invalid spawn found");
259 if(cvar("spawn_debug"))
263 if(some_spawn_has_been_used)
264 return world; // team can't spawn any more, because of actions of other team
266 error("Cannot find a spawn point - please fix the map!");
277 Checks if the argument string can be a valid playermodel.
278 Returns a valid one in doubt.
281 string FallbackPlayerModel = "models/player/marine.zym";
282 string CheckPlayerModel(string plyermodel) {
283 if(strlen(plyermodel) < 4)
284 return FallbackPlayerModel;
285 if( substring(plyermodel,0,14) != "models/player/")
286 return FallbackPlayerModel;
287 else if(cvar("sv_servermodelsonly"))
289 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
290 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
291 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
292 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
293 return FallbackPlayerModel;
294 if(plyermodel != strtolower(plyermodel))
295 return FallbackPlayerModel;
296 if(!fexists(plyermodel))
297 return FallbackPlayerModel;
304 Client_customizeentityforclient
309 float Client_customizeentityforclient()
311 #ifdef ALLOW_VARIABLE_LOD
313 // other: the player viewing me
317 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
320 if(other.cvar_cl_playerdetailreduction <= 0)
322 if(other.cvar_cl_playerdetailreduction <= -2)
323 self.modelindex = self.modelindex_lod2;
324 else if(other.cvar_cl_playerdetailreduction <= -1)
325 self.modelindex = self.modelindex_lod1;
327 self.modelindex = self.modelindex_lod0;
331 distance = vlen(self.origin - other.origin);
332 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
334 self.modelindex = self.modelindex_lod2;
336 self.modelindex = self.modelindex_lod1;
338 self.modelindex = self.modelindex_lod0;
345 void UpdatePlayerSounds();
346 void setmodel_lod(entity e, string modelname)
348 #ifdef ALLOW_VARIABLE_LOD
351 // FIXME: this only supports 3-letter extensions
352 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
356 setmodel(e, s); // players have high precision
357 self.modelindex_lod1 = self.modelindex;
360 self.modelindex_lod1 = -1;
362 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
366 setmodel(e, s); // players have high precision
367 self.modelindex_lod2 = self.modelindex;
370 self.modelindex_lod2 = -1;
372 precache_model(modelname);
373 setmodel(e, modelname); // players have high precision
374 self.modelindex_lod0 = self.modelindex;
376 if(self.modelindex_lod1 < 0)
377 self.modelindex_lod1 = self.modelindex;
379 if(self.modelindex_lod2 < 0)
380 self.modelindex_lod2 = self.modelindex;
382 precache_model(modelname);
383 setmodel(e, modelname); // players have high precision
385 player_setupanimsformodel();
386 UpdatePlayerSounds();
393 putting a client as observer in the server
396 void PutObserverInServer (void)
400 race_PreSpawnObserver();
402 spot = SelectSpawnPoint (TRUE);
404 error("No spawnpoints for observers?!?\n");
405 RemoveGrapplingHook(self); // Wazat's Grappling Hook
407 if(clienttype(self) == CLIENTTYPE_REAL)
410 WriteByte(MSG_ONE, SVC_SETVIEW);
411 WriteEntity(MSG_ONE, self);
415 kh_Key_DropAll(self, TRUE);
417 Portal_ClearAll(self);
420 DropFlag(self.flagcarried, world, world);
422 WaypointSprite_PlayerDead();
424 if(self.killcount != -666)
428 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
429 bprint ("^4", self.netname, "^4 has no more lives left\n");
431 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
434 bprint ("^4", self.netname, "^4 is spectating now\n");
437 PlayerScore_Clear(self); // clear scores when needed
439 self.spectatortime = time;
441 self.classname = "observer";
442 self.iscreature = FALSE;
444 self.takedamage = DAMAGE_NO;
445 self.solid = SOLID_NOT;
446 self.movetype = MOVETYPE_NOCLIP;
447 self.flags = FL_CLIENT | FL_NOTARGET;
448 self.armorvalue = 666;
450 self.armorvalue = cvar("g_balance_armor_start");
451 self.pauserotarmor_finished = 0;
452 self.pauserothealth_finished = 0;
453 self.pauseregen_finished = 0;
454 self.damageforcescale = 0;
461 self.pain_finished = 0;
462 self.strength_finished = 0;
463 self.invincible_finished = 0;
465 self.think = SUB_Null;
469 self.deadflag = DEAD_NO;
470 self.angles = spot.angles;
472 self.fixangle = TRUE;
475 self.view_ofs = PL_VIEW_OFS;
476 setorigin (self, spot.origin);
477 setsize (self, '0 0 0', '0 0 0');
478 self.oldorigin = self.origin;
484 self.weaponmodel = "";
485 self.weaponentity = world;
486 self.killcount = -666;
487 self.velocity = '0 0 0';
488 self.avelocity = '0 0 0';
489 self.punchangle = '0 0 0';
490 self.punchvector = '0 0 0';
491 self.oldvelocity = self.velocity;
492 self.customizeentityforclient = Client_customizeentityforclient;
493 self.wantswelcomemessage = 1;
497 if(self.version_mismatch)
499 Spawnqueue_Unmark(self);
500 Spawnqueue_Remove(self);
504 Spawnqueue_Insert(self);
509 // Only if the player cannot play at all
510 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
511 self.frags = FRAGS_SPECTATOR;
513 self.frags = FRAGS_SPECTATOR; // this was -667 before, is this okay?
516 self.frags = FRAGS_SPECTATOR;
519 float RestrictSkin(float s)
528 void FixPlayermodel()
530 local string defaultmodel;
531 local float defaultskin;
536 if(cvar("sv_defaultcharacter") == 1) {
541 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
542 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
545 if(defaultmodel == "")
547 defaultmodel = cvar_string("sv_defaultplayermodel");
548 defaultskin = cvar("sv_defaultplayerskin");
552 if(self.modelindex == 0)
555 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
556 self.model = ""; // force the != checks to return true
559 if(defaultmodel != "")
561 if (defaultmodel != self.model)
565 setmodel_lod (self, defaultmodel);
566 setsize (self, m1, m2);
569 self.skin = defaultskin;
571 if (self.playermodel != self.model)
573 self.playermodel = CheckPlayerModel(self.playermodel);
576 setmodel_lod (self, self.playermodel);
577 setsize (self, m1, m2);
580 self.skin = RestrictSkin(stof(self.playerskin));
584 if(strlen(cvar_string("sv_defaultplayercolors")))
585 if(self.clientcolors != cvar("sv_defaultplayercolors"))
586 setcolor(self, cvar("sv_defaultplayercolors"));
589 void PlayerTouchExplode(entity p1, entity p2)
592 org = (p1.origin + p2.origin) * 0.5;
593 org_z += (p1.mins_z + p2.mins_z) * 0.5;
600 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
608 Called when a client spawns in the server
611 //void() ctf_playerchanged;
612 void PutClientInServer (void)
614 if(clienttype(self) == CLIENTTYPE_BOT)
616 self.classname = "player";
618 else if(clienttype(self) == CLIENTTYPE_REAL)
621 WriteByte(MSG_ONE, SVC_SETVIEW);
622 WriteEntity(MSG_ONE, self);
625 // player is dead and becomes observer
626 // FIXME fix LMS scoring for new system
629 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
630 self.classname = "observer";
635 self.classname = "observer";
637 if(self.classname == "player") {
638 entity spot, oldself;
642 spot = SelectSpawnPoint (FALSE);
645 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
646 return; // spawn failed
649 RemoveGrapplingHook(self); // Wazat's Grappling Hook
650 self.campingrifle_bulletcounter = 0;
652 self.classname = "player";
653 self.iscreature = TRUE;
654 self.movetype = MOVETYPE_WALK;
655 self.solid = SOLID_SLIDEBOX;
656 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
657 self.frags = FRAGS_PLAYER;
658 if(independent_players)
659 MAKE_INDEPENDENT_PLAYER(self);
660 self.flags = FL_CLIENT;
661 self.takedamage = DAMAGE_AIM;
663 self.effects = EF_FULLBRIGHT;
666 self.air_finished = time + 12;
671 self.ammo_shells = warmup_start_ammo_shells;
672 self.ammo_nails = warmup_start_ammo_nails;
673 self.ammo_rockets = warmup_start_ammo_rockets;
674 self.ammo_cells = warmup_start_ammo_cells;
675 self.health = warmup_start_health;
676 self.armorvalue = warmup_start_armorvalue;
677 self.weapons = warmup_start_weapons;
681 self.ammo_shells = start_ammo_shells;
682 self.ammo_nails = start_ammo_nails;
683 self.ammo_rockets = start_ammo_rockets;
684 self.ammo_cells = start_ammo_cells;
685 self.health = start_health;
686 self.armorvalue = start_armorvalue;
687 self.weapons = start_weapons;
689 self.items = start_items;
690 self.switchweapon = w_getbestweapon(self);
691 self.cnt = self.switchweapon;
693 self.jump_interval = time;
695 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
696 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
697 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
698 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
699 //extend the pause of rotting if client was reset at the beginning of the countdown
700 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
701 self.spawnshieldtime += game_starttime - time;
702 self.pauserotarmor_finished += game_starttime - time;
703 self.pauserothealth_finished += game_starttime - time;
704 self.pauseregen_finished += game_starttime - time;
706 self.damageforcescale = 2;
713 self.pain_finished = 0;
714 self.strength_finished = 0;
715 self.invincible_finished = 0;
717 //self.speed_finished = 0;
718 //self.slowmo_finished = 0;
719 // players have no think function
720 self.think = SUB_Null;
727 self.deadflag = DEAD_NO;
729 self.angles = spot.angles;
731 self.angles_z = 0; // never spawn tilted even if the spot says to
732 self.fixangle = TRUE; // turn this way immediately
733 self.velocity = '0 0 0';
734 self.avelocity = '0 0 0';
735 self.punchangle = '0 0 0';
736 self.punchvector = '0 0 0';
737 self.oldvelocity = self.velocity;
740 WRITESPECTATABLE_MSG_ONE({
741 WriteByte(MSG_ONE, SVC_TEMPENTITY);
742 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
745 self.customizeentityforclient = Client_customizeentityforclient;
751 self.view_ofs = PL_VIEW_OFS;
752 setsize (self, PL_MIN, PL_MAX);
753 self.spawnorigin = spot.origin;
754 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
755 // don't reset back to last position, even if new position is stuck in solid
756 self.oldorigin = self.origin;
760 Spawnqueue_Remove(self);
761 Spawnqueue_Mark(self);
764 self.event_damage = PlayerDamage;
766 self.bot_attack = TRUE;
768 self.statdraintime = time + 5;
769 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
771 if(self.killcount == -666) {
772 PlayerScore_Clear(self);
776 self.cnt = WEP_LASER;
777 self.nixnex_lastchange_id = -1;
779 CL_SpawnWeaponentity();
780 self.alpha = default_player_alpha;
781 self.colormod = '1 1 1' * cvar("g_player_brightness");
782 self.exteriorweaponentity.alpha = default_weapon_alpha;
784 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
785 self.lms_traveled_distance = 0;
786 self.speedrunning = FALSE;
788 race_PostSpawn(spot);
790 if(cvar("spawn_debug"))
792 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
793 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
796 //stuffcmd(self, "chase_active 0");
797 //stuffcmd(self, "set viewsize $tmpviewsize \n");
799 if (cvar("g_spawnsound"))
800 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
803 if(self.team == assault_attacker_team)
804 centerprint(self, "You are attacking!\n");
806 centerprint(self, "You are defending!\n");
809 target_voicescript_clear(self);
818 } else if(self.classname == "observer") {
819 PutObserverInServer ();
823 // ctf_playerchanged();
826 float ClientInit_SendEntity(entity to, float sf)
829 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
830 WriteShort(MSG_ENTITY, CSQC_REVISION);
831 WriteByte(MSG_ENTITY, maxclients);
832 for(i = 1; i <= 24; ++i)
833 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
834 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
835 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
836 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
840 void ClientInit_Spawn()
844 e.classname = "ent_client_init";
845 e.SendEntity = ClientInit_SendEntity;
847 e.effects = EF_NODEPTHTEST;
855 void SetNewParms (void)
857 // initialize parms for a new player
858 parm1 = -(86400 * 366);
866 void SetChangeParms (void)
868 // save parms for level change
869 parm1 = self.parm_idlesince - time;
877 void DecodeLevelParms (void)
880 self.parm_idlesince = parm1;
881 if(self.parm_idlesince == -(86400 * 366))
882 self.parm_idlesince = time;
884 // whatever happens, allow 60 seconds of idling directly after connect for map loading
885 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
892 Called when a client types 'kill' in the console
896 void ClientKill_Now_TeamChange()
898 if(self.killindicator_teamchange == -1)
901 JoinBestTeam( self, FALSE, FALSE );
905 SV_ChangeTeam(self.killindicator_teamchange - 1);
909 void ClientKill_Now()
911 if(self.killindicator_teamchange)
912 ClientKill_Now_TeamChange();
915 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
917 if(self.killindicator)
919 dprint("Cleaned up after a leaked kill indicator.\n");
920 remove(self.killindicator);
921 self.killindicator = world;
924 void KillIndicator_Think()
926 if (!self.owner.modelindex)
928 self.owner.killindicator = world;
936 ClientKill_Now(); // no oldself needed
942 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
943 if(clienttype(self.owner) == CLIENTTYPE_REAL)
946 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
947 if(self.owner.killindicator_teamchange)
949 if(self.owner.killindicator_teamchange == -1)
950 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
952 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
955 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
957 self.nextthink = time + 1;
962 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
966 killtime = cvar("g_balance_kill_delay");
968 self.killindicator_teamchange = targetteam;
970 if(!self.killindicator)
972 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
978 self.killindicator = spawn();
979 self.killindicator.owner = self;
980 self.killindicator.scale = 0.5;
981 setattachment(self.killindicator, self, "");
982 setorigin(self.killindicator, '0 0 52');
983 self.killindicator.think = KillIndicator_Think;
984 self.killindicator.nextthink = time + (self.lip) * 0.05;
985 self.killindicator.cnt = ceil(killtime);
986 self.killindicator.count = bound(0, ceil(killtime), 10);
987 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
989 for(e = world; (e = find(e, classname, "body")) != world; )
993 e.killindicator = spawn();
994 e.killindicator.owner = e;
995 e.killindicator.scale = 0.5;
996 setattachment(e.killindicator, e, "");
997 setorigin(e.killindicator, '0 0 52');
998 e.killindicator.think = KillIndicator_Think;
999 e.killindicator.nextthink = time + (e.lip) * 0.05;
1000 e.killindicator.cnt = ceil(killtime);
1005 if(self.killindicator)
1008 self.killindicator.colormod = TeamColor(targetteam);
1010 self.killindicator.colormod = '0 0 0';
1014 void ClientKill (void)
1016 ClientKill_TeamChange(0);
1019 void DoTeamChange(float destteam)
1022 if(!cvar("teamplay"))
1025 SetPlayerColors(self, destteam);
1028 if(self.classname == "player")
1031 CheckAllowedTeams(self);
1032 t = FindSmallestTeam(self, TRUE);
1035 case COLOR_TEAM1: c0 = c1; break;
1036 case COLOR_TEAM2: c0 = c2; break;
1037 case COLOR_TEAM3: c0 = c3; break;
1038 case COLOR_TEAM4: c0 = c4; break;
1045 destteam = COLOR_TEAM1;
1049 destteam = COLOR_TEAM2;
1053 destteam = COLOR_TEAM3;
1057 destteam = COLOR_TEAM4;
1063 if(destteam == self.team && !self.killindicator)
1065 ClientKill_TeamChange(destteam);
1068 void FixClientCvars(entity e)
1070 // send prediction settings to the client
1071 stuffcmd(e, "\nin_bindmap 0 0\n");
1073 * we no longer need to stuff this. Remove this comment block if you feel
1074 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1075 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1076 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1077 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1078 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1079 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1080 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1081 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1082 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1083 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1084 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1085 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1086 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1087 stuffcmd(e, "cl_movement_edgefriction 1\n");
1094 if(clienttype(self) == CLIENTTYPE_REAL)
1095 if(world.fog) // NOT string_null!
1102 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1103 WriteByte(MSG_ONE, TE_CSQC_FOG);
1104 WriteCoord(MSG_ONE, sv_foginterval);
1105 WriteString(MSG_ONE, world.fog);
1109 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1120 Called when a client connects to the server
1123 //void ctf_clientconnect();
1124 string ColoredTeamName(float t);
1125 void DecodeLevelParms (void);
1126 //void dom_player_join_team(entity pl);
1127 void ClientConnect (void)
1131 if(self.flags & FL_CLIENT)
1133 print("Warning: ClientConnect, but already connected!\n");
1137 if(Ban_MaybeEnforceBan(self))
1142 self.classname = "player_joining";
1144 self.flags = self.flags | FL_CLIENT;
1145 self.version_nagtime = time + 10 + random() * 10;
1149 dprint("BUG player count is lower than zero, this cannot happen!\n");
1153 PlayerScore_Attach(self);
1155 bot_clientconnect();
1157 race_PreSpawnObserver();
1160 // dom_player_join_team(self);
1162 //JoinBestTeam(self, FALSE, FALSE);
1164 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1165 self.classname = "observer";
1167 self.classname = "player";
1168 campaign_bots_may_start = 1;
1171 self.playerid = (playerid_last = playerid_last + 1);
1172 if(cvar("sv_eventlog"))
1174 if(clienttype(self) == CLIENTTYPE_REAL)
1175 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1177 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1178 s = strcat(":team:", ftos(self.playerid), ":");
1179 s = strcat(s, ftos(self.team));
1182 self.netname_previous = strzone(self.netname);
1184 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1186 bprint ("^4",self.netname);
1187 bprint ("^4 connected");
1189 if(g_domination || g_ctf)
1191 bprint(" and joined the ");
1192 bprint(ColoredTeamName(self.team));
1197 self.welcomemessage_time = 0;
1199 stuffcmd(self, strcat(clientstuff, "\n"));
1200 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1201 stuffcmd(self, "cl_particles_reloadeffects\n");
1203 FixClientCvars(self);
1205 // spawnfunc_waypoint sprites
1206 WaypointSprite_InitClient(self);
1208 // Wazat's grappling hook
1209 SetGrappleHookBindings();
1211 // get autoswitch state from player when he toggles it
1212 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1214 // get version info from player
1215 stuffcmd(self, "cmd clientversion $gameversion\n");
1217 // get other cvars from player
1220 // set cvar for team scoreboard
1224 t = cvar("teamplay");
1225 // we have to stuff the correct teamplay value because if this is a listen server, this changes the teamplay mode of the server itself, which is bad
1226 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1229 stuffcmd(self, "set teamplay 0\n");
1231 // notify about available teams
1234 CheckAllowedTeams(self);
1235 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1236 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1239 stuffcmd(self, "set _teams_available 0\n");
1241 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1245 self.classname = "observer";
1246 Spawnqueue_Insert(self);
1250 ctf_clientconnect();
1256 bot_relinkplayerlist();
1258 self.spectatortime = time;
1261 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"));
1264 self.jointime = time;
1265 self.allowedTimeouts = cvar("sv_timeout_number");
1267 if(clienttype(self) == CLIENTTYPE_REAL)
1269 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1276 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1277 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
1278 WriteByte(MSG_ONE, 1);
1281 if(cvar("g_bugrigs"))
1282 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1287 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1289 PlayerScore_Add(self, SP_LMS_RANK, 666);
1290 self.frags = FRAGS_SPECTATOR; // FIXME do we still need this?
1301 Called when a client disconnects from the server
1304 .entity chatbubbleentity;
1305 .entity teambubbleentity;
1307 void ClientDisconnect (void)
1309 if not(self.flags & FL_CLIENT)
1311 print("Warning: ClientDisconnect without ClientConnect\n");
1315 bot_clientdisconnect();
1320 if(cvar("sv_eventlog"))
1321 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1322 bprint ("^4",self.netname);
1323 bprint ("^4 disconnected\n");
1326 kh_Key_DropAll(self, TRUE);
1328 Portal_ClearAll(self);
1330 if(self.flagcarried)
1331 DropFlag(self.flagcarried, world, world);
1333 // Here, everything has been done that requires this player to be a client.
1335 self.flags &~= FL_CLIENT;
1337 if (self.chatbubbleentity)
1338 remove (self.chatbubbleentity);
1340 if (self.teambubbleentity)
1341 remove (self.teambubbleentity);
1343 if (self.killindicator)
1344 remove (self.killindicator);
1346 WaypointSprite_PlayerGone();
1348 bot_relinkplayerlist();
1351 if(self.weaponentity)
1352 if(self.weaponentity.lasertarget)
1353 remove(self.weaponentity.lasertarget);
1357 Spawnqueue_Unmark(self);
1358 Spawnqueue_Remove(self);
1361 PlayerScore_Detach(self);
1363 if(self.netname_previous)
1364 strunzone(self.netname_previous);
1366 ClearPlayerSounds();
1376 void ChatBubbleThink()
1378 self.nextthink = time;
1379 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1381 if(self.owner) // but why can that ever be world?
1382 self.owner.chatbubbleentity = world;
1386 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1387 self.model = self.mdl;
1392 void UpdateChatBubble()
1394 if (!self.modelindex)
1396 // spawn a chatbubble entity if needed
1397 if (!self.chatbubbleentity)
1399 self.chatbubbleentity = spawn();
1400 self.chatbubbleentity.owner = self;
1401 self.chatbubbleentity.exteriormodeltoclient = self;
1402 self.chatbubbleentity.think = ChatBubbleThink;
1403 self.chatbubbleentity.nextthink = time;
1404 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1405 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1406 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1407 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1408 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1409 self.chatbubbleentity.model = "";
1410 self.chatbubbleentity.effects = EF_LOWPRECISION;
1415 void TeamBubbleThink()
1417 self.nextthink = time;
1418 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1420 if(self.owner) // but why can that ever be world?
1421 self.owner.teambubbleentity = world;
1425 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1426 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1429 self.model = self.mdl;
1433 float TeamBubble_customizeentityforclient()
1435 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1438 void UpdateTeamBubble()
1440 if (!self.modelindex || !cvar("teamplay"))
1442 // spawn a teambubble entity if needed
1443 if (!self.teambubbleentity && cvar("teamplay"))
1445 self.teambubbleentity = spawn();
1446 self.teambubbleentity.owner = self;
1447 self.teambubbleentity.exteriormodeltoclient = self;
1448 self.teambubbleentity.think = TeamBubbleThink;
1449 self.teambubbleentity.nextthink = time;
1450 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1451 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1452 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1453 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1454 self.teambubbleentity.mdl = self.teambubbleentity.model;
1455 self.teambubbleentity.model = self.teambubbleentity.mdl;
1456 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1457 self.teambubbleentity.effects = EF_LOWPRECISION;
1461 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1462 // added to the model skins
1463 /*void UpdateColorModHack()
1466 c = self.clientcolors & 15;
1467 // LordHavoc: only bothering to support white, green, red, yellow, blue
1468 if (teamplay == 0) self.colormod = '0 0 0';
1469 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1470 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1471 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1472 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1473 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1474 else self.colormod = '1 1 1';
1480 self.effects |= EF_NODRAW; // prevent another CopyBody
1481 PutClientInServer();
1485 * When sv_timeout is used this function returs strings like
1486 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1487 * Called by centerprint functions
1488 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1490 string getTimeoutText(float addOneSecond) {
1491 if (!cvar("sv_timeout") || !timeoutStatus)
1494 local string retStr;
1495 if (timeoutStatus == 1) {
1496 if (addOneSecond == 1) {
1497 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1500 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1504 else if (timeoutStatus == 2) {
1506 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1507 //don't show messages like "Timeout ends in 0 seconds"...
1508 if ((remainingTimeoutTime + 1) > 0)
1514 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1515 //don't show messages like "Timeout ends in 0 seconds"...
1516 if (remainingTimeoutTime > 0)
1525 void player_powerups (void)
1529 if (self.items & IT_STRENGTH)
1531 if (time > self.strength_finished)
1533 if (g_minstagib_invis_alpha > 0)
1535 self.alpha = default_player_alpha;
1536 self.exteriorweaponentity.alpha = default_weapon_alpha;
1537 self.effects = self.effects | EF_FULLBRIGHT;
1541 self.effects -= self.effects & EF_NODRAW;
1543 self.items = self.items - (self.items & IT_STRENGTH);
1544 sprint(self, "^3Invisibility has worn off\n");
1549 if (time < self.strength_finished)
1551 if (g_minstagib_invis_alpha > 0)
1553 self.alpha = g_minstagib_invis_alpha;
1554 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1555 self.effects -= self.effects & EF_FULLBRIGHT;
1559 self.effects = self.effects | EF_NODRAW;
1561 self.items = self.items | IT_STRENGTH;
1562 sprint(self, "^3You are invisible\n");
1566 if (self.items & IT_INVINCIBLE)
1568 if (time > self.invincible_finished)
1570 self.items = self.items - (self.items & IT_INVINCIBLE);
1571 sprint(self, "^3Speed has worn off\n");
1576 if (time < self.invincible_finished)
1578 self.items = self.items | IT_INVINCIBLE;
1579 sprint(self, "^3You are on speed\n");
1585 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1586 if (self.items & IT_STRENGTH)
1588 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1589 if (time > self.strength_finished)
1591 self.items = self.items - (self.items & IT_STRENGTH);
1592 sprint(self, "^3Strength has worn off\n");
1597 if (time < self.strength_finished)
1599 self.items = self.items | IT_STRENGTH;
1600 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1603 if (self.items & IT_INVINCIBLE)
1605 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1606 if (time > self.invincible_finished)
1608 self.items = self.items - (self.items & IT_INVINCIBLE);
1609 sprint(self, "^3Shield has worn off\n");
1614 if (time < self.invincible_finished)
1616 self.items = self.items | IT_INVINCIBLE;
1617 sprint(self, "^3Shield surrounds you\n");
1621 if (cvar("g_fullbrightplayers"))
1622 self.effects = self.effects | EF_FULLBRIGHT;
1624 // midair gamemode: damage only while in the air
1625 // if in midair mode, being on ground grants temporary invulnerability
1626 // (this is so that multishot weapon don't clear the ground flag on the
1627 // first damage in the frame, leaving the player vulnerable to the
1628 // remaining hits in the same frame)
1629 if (self.flags & FL_ONGROUND)
1631 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1633 if (time >= game_starttime)
1634 if (time < self.spawnshieldtime)
1635 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1638 float CalcRegen(float current, float stable, float regenfactor)
1640 if(current > stable)
1642 else if(current > stable - 0.25) // when close enough, "snap"
1645 return min(stable, current + (stable - current) * regenfactor * frametime);
1648 void player_regen (void)
1650 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1651 maxh = cvar("g_balance_health_stable");
1652 maxa = cvar("g_balance_armor_stable");
1653 limith = cvar("g_balance_health_limit");
1654 limita = cvar("g_balance_armor_limit");
1656 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1659 max_mod = regen_mod = rot_mod = limit_mod = 1;
1661 if (self.runes & RUNE_REGEN)
1663 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1665 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1666 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1667 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1671 regen_mod = cvar("g_balance_rune_regen_regenrate");
1672 max_mod = cvar("g_balance_rune_regen_hpmod");
1673 limit_mod = cvar("g_balance_rune_regen_limitmod");
1676 else if (self.runes & CURSE_VENOM)
1678 max_mod = cvar("g_balance_curse_venom_hpmod");
1679 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1680 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1682 rot_mod = cvar("g_balance_curse_venom_rotrate");
1683 limit_mod = cvar("g_balance_curse_venom_limitmod");
1684 //if (!self.runes & RUNE_REGEN)
1685 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1687 maxh = maxh * max_mod;
1688 //maxa = maxa * max_mod;
1689 limith = limith * limit_mod;
1690 limita = limita * limit_mod;
1692 if (self.armorvalue > maxa)
1694 if (time > self.pauserotarmor_finished)
1696 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1697 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1700 else if (self.armorvalue < maxa)
1702 if (time > self.pauseregen_finished)
1704 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1705 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1708 if (self.health > maxh)
1710 if (time > self.pauserothealth_finished)
1712 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1713 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1716 else if (self.health < maxh)
1718 if (time > self.pauseregen_finished)
1720 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1721 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1725 if (self.health > limith)
1726 self.health = limith;
1727 if (self.armorvalue > limita)
1728 self.armorvalue = limita;
1730 // if player rotted to death... die!
1732 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1736 float zoomstate_set;
1737 void SetZoomState(float z)
1739 if(z != self.zoomstate)
1742 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1743 WriteByte(MSG_ONE, TE_CSQC_ZOOMNOTIFY);
1744 WriteByte(MSG_ONE, z);
1751 ======================
1752 spectate mode routines
1753 ======================
1755 void SpectateCopy(entity spectatee) {
1756 self.armortype = spectatee.armortype;
1757 self.armorvalue = spectatee.armorvalue;
1758 self.currentammo = spectatee.currentammo;
1759 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1760 self.health = spectatee.health;
1762 self.items = spectatee.items;
1763 self.weapons = spectatee.weapons;
1764 self.switchweapon = spectatee.switchweapon;
1765 self.weapon = spectatee.weapon;
1766 self.punchangle = spectatee.punchangle;
1767 self.view_ofs = spectatee.view_ofs;
1768 self.v_angle = spectatee.v_angle;
1769 self.velocity = spectatee.velocity;
1770 self.dmg_take = spectatee.dmg_take;
1771 self.dmg_save = spectatee.dmg_save;
1772 self.dmg_inflictor = spectatee.dmg_inflictor;
1773 self.angles = spectatee.v_angle;
1774 self.fixangle = TRUE;
1775 setorigin(self, spectatee.origin);
1776 setsize(self, spectatee.mins, spectatee.maxs);
1777 SetZoomState(spectatee.zoomstate);
1780 float SpectateUpdate() {
1784 if (self == self.enemy)
1787 if(self.enemy.flags & FL_NOTARGET)
1790 SpectateCopy(self.enemy);
1795 float SpectateNext() {
1796 other = find(self.enemy, classname, "player");
1798 other = find(other, classname, "player");
1803 if(self.enemy.classname == "player") {
1805 WriteByte(MSG_ONE, SVC_SETVIEW);
1806 WriteEntity(MSG_ONE, self.enemy);
1807 self.wantswelcomemessage = 1;
1808 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1809 if(!SpectateUpdate())
1810 PutObserverInServer();
1819 ShowRespawnCountdown()
1821 Update a respawn countdown display.
1824 void ShowRespawnCountdown()
1827 if(self.deadflag == DEAD_NO) // just respawned?
1831 number = ceil(self.death_time - time);
1834 if(number <= self.respawn_countdown)
1836 self.respawn_countdown = number - 1;
1837 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
1838 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
1843 void LeaveSpectatorMode()
1845 if(isJoinAllowed()) {
1846 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1847 self.classname = "player";
1848 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1849 JoinBestTeam(self, FALSE, TRUE);
1850 if(cvar("g_campaign"))
1851 campaign_bots_may_start = 1;
1852 PutClientInServer();
1853 if(!(self.flags & FL_NOTARGET))
1854 bprint ("^4", self.netname, "^4 is playing now\n");
1855 centerprint(self,"");
1858 stuffcmd(self,"menu_showteamselect\n");
1863 //player may not join because of g_maxplayers is set
1864 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1869 * Determines whether the player is allowed to join. This depends on cvar
1870 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1871 * it checks whether the number of currently playing players exceeds g_maxplayers.
1872 * @return bool TRUE if the player is allowed to join, false otherwise
1874 float isJoinAllowed() {
1875 if (!cvar("g_maxplayers"))
1879 local float currentlyPlaying;
1880 FOR_EACH_REALPLAYER(e) {
1881 if(e.classname == "player")
1882 currentlyPlaying += 1;
1884 if(currentlyPlaying < cvar("g_maxplayers"))
1891 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1892 * g_maxplayers_spectator_blocktime seconds
1894 void checkSpectatorBlock() {
1895 if(self.classname == "spectator" || self.classname == "observer") {
1896 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1897 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1903 float vercmp_recursive(string v1, string v2)
1909 dot1 = strstrofs(v1, ".", 0);
1910 dot2 = strstrofs(v2, ".", 0);
1914 s1 = substring(v1, 0, dot1);
1918 s2 = substring(v2, 0, dot2);
1920 r = stof(s1) - stof(s2);
1924 r = strcasecmp(s1, s2);
1937 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1940 float vercmp(string v1, string v2)
1942 if(strcasecmp(v1, v2) == 0) // early out check
1944 return vercmp_recursive(v1, v2);
1947 void ObserverThink()
1949 if (self.flags & FL_JUMPRELEASED) {
1950 if (self.BUTTON_JUMP && !self.version_mismatch) {
1951 self.welcomemessage_time = 0;
1952 self.flags = self.flags - FL_JUMPRELEASED;
1953 LeaveSpectatorMode();
1955 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1956 self.welcomemessage_time = 0;
1957 self.flags = self.flags - FL_JUMPRELEASED;
1958 if(SpectateNext() == 1) {
1959 self.classname = "spectator";
1963 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1964 self.flags = self.flags | FL_JUMPRELEASED;
1967 if(self.BUTTON_ZOOM)
1968 self.wantswelcomemessage = 0;
1969 if(self.wantswelcomemessage)
1970 PrintWelcomeMessage(self);
1973 void SpectatorThink()
1975 if (self.flags & FL_JUMPRELEASED) {
1976 if (self.BUTTON_JUMP && !self.version_mismatch) {
1977 self.welcomemessage_time = 0;
1978 self.flags = self.flags - FL_JUMPRELEASED;
1979 LeaveSpectatorMode();
1981 } else if(self.BUTTON_ATCK) {
1982 self.welcomemessage_time = 0;
1983 self.flags = self.flags - FL_JUMPRELEASED;
1984 if(SpectateNext() == 1) {
1985 self.classname = "spectator";
1987 self.classname = "observer";
1988 PutClientInServer();
1990 } else if (self.BUTTON_ATCK2) {
1991 self.welcomemessage_time = 0;
1992 self.flags = self.flags - FL_JUMPRELEASED;
1993 self.classname = "observer";
1994 PutClientInServer();
1996 if(!SpectateUpdate())
1997 PutObserverInServer();
2000 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2001 self.flags = self.flags | FL_JUMPRELEASED;
2004 if(self.BUTTON_ZOOM)
2005 self.wantswelcomemessage = 0;
2006 if(self.wantswelcomemessage)
2007 PrintWelcomeMessage(self);
2008 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
2011 .float touchexplode_time;
2017 Called every frame for each client before the physics are run
2020 void() ctf_setstatus;
2021 .float spectatee_status;
2022 void PlayerPreThink (void)
2024 self.stat_sys_ticrate = cvar("sys_ticrate");
2025 self.stat_game_starttime = game_starttime;
2027 if(blockSpectators && frametime)
2028 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2029 checkSpectatorBlock();
2033 if(self.netname_previous != self.netname)
2035 if(cvar("sv_eventlog"))
2036 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2037 if(self.netname_previous)
2038 strunzone(self.netname_previous);
2039 self.netname_previous = strzone(self.netname);
2043 if(self.version_nagtime)
2044 if(self.cvar_g_nexuizversion)
2045 if(time > self.version_nagtime)
2047 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2049 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2051 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");
2052 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"));
2057 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2060 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");
2061 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"));
2065 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");
2066 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2070 self.version_nagtime = 0;
2074 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2076 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2077 self.max_armorvalue = 0;
2083 antilag_record(self);
2086 if(self.classname == "player") {
2087 // if(self.netname == "Wazat")
2088 // bprint(self.classname, "\n");
2090 CheckRules_Player();
2092 if(self.BUTTON_INFO)
2093 PrintWelcomeMessage(self);
2095 if(g_lms || !cvar("sv_spectate"))
2096 if((time - self.jointime) <= cvar("welcome_message_time"))
2097 PrintWelcomeMessage(self);
2099 if (intermission_running)
2101 IntermissionThink (); // otherwise a button could be missed between
2102 return; // the think tics
2105 if(self.teleport_time)
2106 if(time > self.teleport_time)
2108 self.teleport_time = 0;
2109 if(! (self.items & IT_STRENGTH))
2110 self.effects = self.effects - (self.effects & EF_NODRAW);
2111 if(self.weaponentity)
2112 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
2115 Nixnex_GiveCurrentWeapon();
2117 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2118 UpdateSelectedPlayer();
2120 //don't allow the player to turn around while game is paused!
2121 if(timeoutStatus == 2) {
2122 self.v_angle = self.lastV_angle;
2123 self.angles = self.lastV_angle;
2124 self.fixangle = TRUE;
2127 if (self.deadflag != DEAD_NO)
2129 float button_pressed, force_respawn;
2131 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2132 force_respawn = (g_lms || cvar("g_forced_respawn"));
2133 if (self.deadflag == DEAD_DYING)
2136 self.deadflag = DEAD_RESPAWNING;
2137 else if(!button_pressed)
2138 self.deadflag = DEAD_DEAD;
2140 else if (self.deadflag == DEAD_DEAD)
2143 self.deadflag = DEAD_RESPAWNABLE;
2145 else if (self.deadflag == DEAD_RESPAWNABLE)
2148 self.deadflag = DEAD_RESPAWNING;
2150 else if (self.deadflag == DEAD_RESPAWNING)
2152 if(time > self.death_time)
2154 self.death_time = time + 1; // only retry once a second
2158 ShowRespawnCountdown();
2163 if(time > self.touchexplode_time)
2164 if(self.classname == "player")
2165 if(self.deadflag == DEAD_NO)
2166 if not(IS_INDEPENDENT_PLAYER(self))
2167 FOR_EACH_PLAYER(other) if(self != other)
2169 if(time > other.touchexplode_time)
2170 if(other.classname == "player")
2171 if(other.deadflag == DEAD_NO)
2172 if not(IS_INDEPENDENT_PLAYER(other))
2173 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2175 PlayerTouchExplode(self, other);
2176 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2180 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2184 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2185 dist = self.oldorigin - self.origin;
2187 self.lms_traveled_distance += fabs(vlen(dist));
2189 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2191 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2192 self.lms_traveled_distance = 0;
2195 if(time > self.lms_nextcheck)
2197 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2198 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2200 centerprint(self, cvar_string("g_lms_campcheck_message"));
2201 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2202 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2203 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');
2205 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2206 self.lms_traveled_distance = 0;
2210 self.oldorigin = self.origin;
2212 if (self.BUTTON_CROUCH && !self.hook.state)
2217 self.view_ofs = PL_CROUCH_VIEW_OFS;
2218 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2219 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2226 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2227 if (!trace_startsolid)
2229 self.crouch = FALSE;
2230 self.view_ofs = PL_VIEW_OFS;
2231 setsize (self, PL_MIN, PL_MAX);
2238 GrapplingHookFrame();
2247 minstagib_ammocheck();
2252 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2254 //self.angles_y=self.v_angle_y + 90; // temp
2256 //if (TetrisPreFrame()) return;
2257 } else if(gameover) {
2258 if (intermission_running)
2259 IntermissionThink (); // otherwise a button could be missed between
2261 } else if(self.classname == "observer") {
2263 } else if(self.classname == "spectator") {
2268 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2270 float oldspectatee_status;
2271 oldspectatee_status = self.spectatee_status;
2272 if(self.classname == "spectator")
2273 self.spectatee_status = num_for_edict(self.enemy);
2274 else if(self.classname == "observer")
2275 self.spectatee_status = num_for_edict(self);
2277 self.spectatee_status = 0;
2278 if(self.spectatee_status != oldspectatee_status)
2281 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2282 WriteByte(MSG_ONE, TE_CSQC_SPECTATING);
2283 WriteByte(MSG_ONE, self.spectatee_status);
2285 race_InitSpectator();
2288 if(self.teamkill_soundtime)
2289 if(time > self.teamkill_soundtime)
2291 self.teamkill_soundtime = 0;
2293 entity oldpusher, oldself;
2295 oldself = self; self = self.teamkill_soundsource;
2296 oldpusher = self.pusher; self.pusher = oldself;
2298 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2300 self.pusher = oldpusher;
2304 if(self.taunt_soundtime)
2305 if(time > self.taunt_soundtime)
2307 self.taunt_soundtime = 0;
2308 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2311 target_voicescript_next(self);
2319 Called every frame for each client after the physics are run
2322 .float idlekick_lasttimeleft;
2323 .float race_penalty;
2324 .float race_penalty_nagged;
2325 .float race_penalty_nagtime;
2326 void PlayerPostThink (void)
2328 // Savage: Check for nameless players
2329 if (strlen(self.netname) < 1) {
2330 self.netname = "Player";
2331 stuffcmd(self, "seta _cl_name Player\n");
2334 if(sv_maxidle && frametime)
2336 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2338 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2341 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2342 announce(self, "announcer/robotic/terminated.wav");
2346 else if(timeleft <= 10)
2348 if(timeleft != self.idlekick_lasttimeleft)
2350 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2351 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2356 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2358 self.idlekick_lasttimeleft = timeleft;
2361 if(self.classname == "player") {
2362 CheckRules_Player();
2367 if (intermission_running)
2368 return; // intermission or finale
2370 //PrintWelcomeMessage(self);
2371 //if (TetrisPostFrame()) return;
2373 // restart countdown
2374 if(time < game_starttime) {
2375 if (!cvar("sv_ready_restart_after_countdown"))
2377 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2379 if(time < game_starttime - 2)
2381 if(!self.race_penalty_nagged)
2383 // TODO better notification for this!
2384 self.race_penalty_nagtime = 0;
2385 self.race_penalty_nagged = 1;
2388 else if(!self.race_penalty)
2390 self.race_penalty_nagtime = 0;
2391 self.race_penalty = time + 5;
2394 if(time > self.race_penalty_nagtime)
2396 if(self.race_penalty > time)
2398 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2400 else if(self.race_penalty_nagged && time < game_starttime - 2)
2402 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2404 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2406 self.movetype = MOVETYPE_NONE;
2407 self.velocity = '0 0 0';
2408 self.avelocity = '0 0 0';
2409 self.movement = '0 0 0';
2412 else if (time < self.race_penalty)
2414 self.movetype = MOVETYPE_NONE;
2415 self.velocity = '0 0 0';
2416 self.avelocity = '0 0 0';
2417 self.movement = '0 0 0';
2421 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2422 if (!cvar("sv_ready_restart_after_countdown"))
2424 if(self.movetype == MOVETYPE_NONE)
2426 self.movetype = MOVETYPE_WALK;
2428 self.race_penalty = 0;
2429 self.race_penalty_nagged = 0;
2433 } else if (self.classname == "observer") {
2435 } else if (self.classname == "spectator") {
2441 for(i = 0; i < 1000; ++i)
2444 end = self.origin + '0 0 1024' + 512 * randomvec();
2445 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2446 if(trace_fraction < 1)
2447 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2449 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2457 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);