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);
55 if(ent.classname == "target_objective")
57 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
61 else if(ent.classname == "trigger_race_checkpoint")
63 if(self.classname == "player") // spectators may spawn everywhere
68 if(ent.race_checkpoint != 0)
70 if(spot.race_place != race_lowest_place_spawn)
75 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
79 if(pl > race_highest_place_spawn)
81 if(spot.race_place != pl)
90 ent = find(ent, targetname, spot.target);
98 shortest = vlen(world.maxs - world.mins);
99 for(player = playerlist; player; player = player.chain)
102 thisdist = vlen(player.origin - spot.origin);
103 if (thisdist < shortest)
111 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
113 local entity spot, spotlist, spotlistend;
114 spawn_allgood = TRUE;
120 for(spot = firstspot; spot; spot = spot.chain)
122 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
124 if(cvar("spawn_debugview"))
126 setmodel(spot, "models/runematch/rune.mdl");
127 if(spot.SPAWNPOINT_SCORE < mindist)
129 spot.colormod = '1 0 0';
134 spot.colormod = '0 1 0';
135 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
139 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
141 if(spot.SPAWNPOINT_SCORE < mindist)
143 // too short distance
144 spawn_allgood = FALSE;
149 spawn_allbad = FALSE;
152 spotlistend.chain = spot;
159 if(spot.team != teamcheck)
160 error("invalid spawn added");
162 print("added ", etos(spot), "\n");
168 spotlistend.chain = world;
173 for(e = spotlist; e; e = e.chain)
175 print("seen ", etos(e), "\n");
176 if(e.team != teamcheck)
177 error("invalid spawn found");
184 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
186 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
187 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
190 RandomSelection_Init();
191 for(spot = firstspot; spot; spot = spot.chain)
192 RandomSelection_Add(spot, 0, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
194 return RandomSelection_chosen_ent;
201 Finds a point to respawn
204 entity SelectSpawnPoint (float anypoint)
206 local float teamcheck;
207 local entity firstspot_new;
208 local entity spot, firstspot, playerlist;
210 spot = find (world, classname, "testplayerstart");
216 if(!anypoint && have_team_spawns)
217 teamcheck = self.team;
219 // get the list of players
220 playerlist = findchain(classname, "player");
221 // get the entire list of spots
222 firstspot = findchain(classname, "info_player_deathmatch");
223 // filter out the bad ones
224 // (note this returns the original list if none survived)
225 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
227 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
228 firstspot = firstspot_new;
230 // there is 50/50 chance of choosing a random spot or the furthest spot
231 // (this means that roughly every other spawn will be furthest, so you
232 // usually won't get fragged at spawn twice in a row)
233 if (arena_roundbased)
235 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
237 firstspot = firstspot_new;
238 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
240 else if (random() > cvar("g_spawn_furthest"))
241 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
243 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
245 if(cvar("spawn_debugview"))
247 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
251 for(e = firstspot; e; e = e.chain)
252 if(e.team != teamcheck)
253 error("invalid spawn found");
258 if(cvar("spawn_debug"))
262 if(some_spawn_has_been_used)
263 return world; // team can't spawn any more, because of actions of other team
265 error("Cannot find a spawn point - please fix the map!");
276 Checks if the argument string can be a valid playermodel.
277 Returns a valid one in doubt.
280 string FallbackPlayerModel = "models/player/marine.zym";
281 string CheckPlayerModel(string plyermodel) {
282 if(strlen(plyermodel) < 4)
283 return FallbackPlayerModel;
284 if( substring(plyermodel,0,14) != "models/player/")
285 return FallbackPlayerModel;
286 else if(cvar("sv_servermodelsonly"))
288 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
289 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
290 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
291 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
292 return FallbackPlayerModel;
293 if(plyermodel != strtolower(plyermodel))
294 return FallbackPlayerModel;
295 if(!fexists(plyermodel))
296 return FallbackPlayerModel;
303 Client_customizeentityforclient
308 float Client_customizeentityforclient()
310 #ifdef ALLOW_VARIABLE_LOD
312 // other: the player viewing me
316 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
319 if(other.cvar_cl_playerdetailreduction <= 0)
321 if(other.cvar_cl_playerdetailreduction <= -2)
322 self.modelindex = self.modelindex_lod2;
323 else if(other.cvar_cl_playerdetailreduction <= -1)
324 self.modelindex = self.modelindex_lod1;
326 self.modelindex = self.modelindex_lod0;
330 distance = vlen(self.origin - other.origin);
331 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
333 self.modelindex = self.modelindex_lod2;
335 self.modelindex = self.modelindex_lod1;
337 self.modelindex = self.modelindex_lod0;
344 void UpdatePlayerSounds();
345 void setmodel_lod(entity e, string modelname)
347 #ifdef ALLOW_VARIABLE_LOD
350 // FIXME: this only supports 3-letter extensions
351 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
355 setmodel(e, s); // players have high precision
356 self.modelindex_lod1 = self.modelindex;
359 self.modelindex_lod1 = -1;
361 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
365 setmodel(e, s); // players have high precision
366 self.modelindex_lod2 = self.modelindex;
369 self.modelindex_lod2 = -1;
371 precache_model(modelname);
372 setmodel(e, modelname); // players have high precision
373 self.modelindex_lod0 = self.modelindex;
375 if(self.modelindex_lod1 < 0)
376 self.modelindex_lod1 = self.modelindex;
378 if(self.modelindex_lod2 < 0)
379 self.modelindex_lod2 = self.modelindex;
381 precache_model(modelname);
382 setmodel(e, modelname); // players have high precision
384 player_setupanimsformodel();
385 UpdatePlayerSounds();
392 putting a client as observer in the server
395 void PutObserverInServer (void)
399 race_PreSpawnObserver();
401 spot = SelectSpawnPoint (TRUE);
403 error("No spawnpoints for observers?!?\n");
404 RemoveGrapplingHook(self); // Wazat's Grappling Hook
406 if(clienttype(self) == CLIENTTYPE_REAL)
409 WriteByte(MSG_ONE, SVC_SETVIEW);
410 WriteEntity(MSG_ONE, self);
414 kh_Key_DropAll(self, TRUE);
416 Portal_ClearAll(self);
419 DropFlag(self.flagcarried, world, world);
421 WaypointSprite_PlayerDead();
423 if(self.killcount != -666)
427 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
428 bprint ("^4", self.netname, "^4 has no more lives left\n");
430 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
433 bprint ("^4", self.netname, "^4 is spectating now\n");
436 PlayerScore_Clear(self); // clear scores when needed
438 self.spectatortime = time;
440 self.classname = "observer";
441 self.iscreature = FALSE;
443 self.takedamage = DAMAGE_NO;
444 self.solid = SOLID_NOT;
445 self.movetype = MOVETYPE_NOCLIP;
446 self.flags = FL_CLIENT | FL_NOTARGET;
447 self.armorvalue = 666;
449 self.armorvalue = cvar("g_balance_armor_start");
450 self.pauserotarmor_finished = 0;
451 self.pauserothealth_finished = 0;
452 self.pauseregen_finished = 0;
453 self.damageforcescale = 0;
460 self.pain_finished = 0;
461 self.strength_finished = 0;
462 self.invincible_finished = 0;
464 self.think = SUB_Null;
468 self.deadflag = DEAD_NO;
469 self.angles = spot.angles;
471 self.fixangle = TRUE;
473 self.touch = SUB_Null;
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)
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 .float touchexplode_time;
591 void PlayerTouchExplode()
593 if(self.owner.classname == "player")
594 if(self.owner.deadflag == DEAD_NO)
595 if(self.enemy.classname == "player")
596 if(self.enemy.deadflag == DEAD_NO)
597 if not(IS_INDEPENDENT_PLAYER(self.owner))
598 if not(IS_INDEPENDENT_PLAYER(self.enemy))
601 org = (self.owner.origin + self.enemy.origin) * 0.5;
602 org_z += (self.owner.mins_z + self.enemy.mins_z) * 0.5;
603 setorigin(self, org);
606 RadiusDamage(self, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
613 if(g_touchexplode && time > self.touchexplode_time && time > other.touchexplode_time)
615 if(self.classname == "player")
616 if(self.deadflag == DEAD_NO)
617 if(other.classname == "player")
618 if(other.deadflag == DEAD_NO)
619 if not(IS_INDEPENDENT_PLAYER(self))
620 if not(IS_INDEPENDENT_PLAYER(other))
624 e.classname = "touchexplode";
625 e.think = PlayerTouchExplode;
630 self.touchexplode_time = other.touchexplode_time = time + 0.2;
639 Called when a client spawns in the server
642 //void() ctf_playerchanged;
643 void PutClientInServer (void)
645 if(clienttype(self) == CLIENTTYPE_BOT)
647 self.classname = "player";
649 else if(clienttype(self) == CLIENTTYPE_REAL)
652 WriteByte(MSG_ONE, SVC_SETVIEW);
653 WriteEntity(MSG_ONE, self);
656 // player is dead and becomes observer
657 // FIXME fix LMS scoring for new system
660 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
661 self.classname = "observer";
666 self.classname = "observer";
668 if(self.classname == "player") {
669 entity spot, oldself;
673 spot = SelectSpawnPoint (FALSE);
676 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
677 return; // spawn failed
680 RemoveGrapplingHook(self); // Wazat's Grappling Hook
682 self.classname = "player";
683 self.iscreature = TRUE;
684 self.movetype = MOVETYPE_WALK;
685 self.solid = SOLID_SLIDEBOX;
686 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
687 if(independent_players)
688 MAKE_INDEPENDENT_PLAYER(self);
689 self.flags = FL_CLIENT;
690 self.takedamage = DAMAGE_AIM;
692 self.effects = EF_FULLBRIGHT;
695 self.air_finished = time + 12;
700 self.ammo_shells = warmup_start_ammo_shells;
701 self.ammo_nails = warmup_start_ammo_nails;
702 self.ammo_rockets = warmup_start_ammo_rockets;
703 self.ammo_cells = warmup_start_ammo_cells;
704 self.health = warmup_start_health;
705 self.armorvalue = warmup_start_armorvalue;
706 self.weapons = warmup_start_weapons;
710 self.ammo_shells = start_ammo_shells;
711 self.ammo_nails = start_ammo_nails;
712 self.ammo_rockets = start_ammo_rockets;
713 self.ammo_cells = start_ammo_cells;
714 self.health = start_health;
715 self.armorvalue = start_armorvalue;
716 self.weapons = start_weapons;
718 self.items = start_items;
719 self.switchweapon = w_getbestweapon(self);
720 self.cnt = self.switchweapon;
722 self.jump_interval = time;
724 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
725 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
726 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
727 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
728 //extend the pause of rotting if client was reset at the beginning of the countdown
729 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
730 self.spawnshieldtime += game_starttime - time;
731 self.pauserotarmor_finished += game_starttime - time;
732 self.pauserothealth_finished += game_starttime - time;
733 self.pauseregen_finished += game_starttime - time;
735 self.damageforcescale = 2;
742 self.pain_finished = 0;
743 self.strength_finished = 0;
744 self.invincible_finished = 0;
746 //self.speed_finished = 0;
747 //self.slowmo_finished = 0;
748 // players have no think function
749 self.think = SUB_Null;
755 self.deadflag = DEAD_NO;
757 self.angles = spot.angles;
759 self.angles_z = 0; // never spawn tilted even if the spot says to
760 self.fixangle = TRUE; // turn this way immediately
761 self.velocity = '0 0 0';
762 self.avelocity = '0 0 0';
763 self.punchangle = '0 0 0';
764 self.punchvector = '0 0 0';
765 self.oldvelocity = self.velocity;
768 WRITESPECTATABLE_MSG_ONE({
769 WriteByte(MSG_ONE, SVC_TEMPENTITY);
770 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
773 self.customizeentityforclient = Client_customizeentityforclient;
779 self.touch = PlayerTouch;
780 self.view_ofs = PL_VIEW_OFS;
781 setsize (self, PL_MIN, PL_MAX);
782 self.spawnorigin = spot.origin;
783 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
784 // don't reset back to last position, even if new position is stuck in solid
785 self.oldorigin = self.origin;
789 Spawnqueue_Remove(self);
790 Spawnqueue_Mark(self);
793 self.event_damage = PlayerDamage;
795 self.bot_attack = TRUE;
797 self.statdraintime = time + 5;
798 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
800 if(self.killcount == -666) {
801 PlayerScore_Clear(self);
806 self.cnt = WEP_LASER;
807 self.nixnex_lastchange_id = -1;
809 CL_SpawnWeaponentity();
810 self.alpha = default_player_alpha;
811 self.colormod = '1 1 1' * cvar("g_player_brightness");
812 self.exteriorweaponentity.alpha = default_weapon_alpha;
814 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
815 self.lms_traveled_distance = 0;
816 self.speedrunning = FALSE;
818 race_PostSpawn(spot);
820 if(cvar("spawn_debug"))
822 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
823 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
826 //stuffcmd(self, "chase_active 0");
827 //stuffcmd(self, "set viewsize $tmpviewsize \n");
829 if (cvar("g_spawnsound"))
830 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
833 if(self.team == assault_attacker_team)
834 centerprint(self, "You are attacking!\n");
836 centerprint(self, "You are defending!\n");
839 target_voicescript_clear(self);
848 } else if(self.classname == "observer") {
849 PutObserverInServer ();
853 // ctf_playerchanged();
860 Send whatever CSQC needs NOW and cannot wait for SendServerInfo to happen...
863 void SendCSQCInfo(void)
866 if(clienttype(self) != CLIENTTYPE_REAL)
869 WriteByte(MSG_ONE, SVC_TEMPENTITY);
870 WriteByte(MSG_ONE, TE_CSQC_INIT);
871 WriteShort(MSG_ONE, CSQC_REVISION);
872 WriteByte(MSG_ONE, maxclients);
873 for(i = 1; i <= 24; ++i)
874 WriteByte(MSG_ONE, (get_weaponinfo(i)).impulse + 1);
875 WriteCoord(MSG_ONE, hook_shotorigin_x);
876 WriteCoord(MSG_ONE, hook_shotorigin_y);
877 WriteCoord(MSG_ONE, hook_shotorigin_z);
885 void SetNewParms (void)
887 // initialize parms for a new player
888 parm1 = -(86400 * 366);
896 void SetChangeParms (void)
898 // save parms for level change
899 parm1 = self.parm_idlesince - time;
907 void DecodeLevelParms (void)
910 self.parm_idlesince = parm1;
911 if(self.parm_idlesince == -(86400 * 366))
912 self.parm_idlesince = time;
919 Called when a client types 'kill' in the console
923 void ClientKill_Now_TeamChange()
925 if(self.killindicator_teamchange == -1)
928 JoinBestTeam( self, FALSE, FALSE );
932 SV_ChangeTeam(self.killindicator_teamchange - 1);
936 void ClientKill_Now()
938 if(self.killindicator_teamchange)
939 ClientKill_Now_TeamChange();
942 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
944 if(self.killindicator)
946 dprint("Cleaned up after a leaked kill indicator.\n");
947 remove(self.killindicator);
948 self.killindicator = world;
951 void KillIndicator_Think()
953 if (!self.owner.modelindex)
955 self.owner.killindicator = world;
963 ClientKill_Now(); // no oldself needed
969 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
970 if(clienttype(self.owner) == CLIENTTYPE_REAL)
973 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
974 if(self.owner.killindicator_teamchange)
976 if(self.owner.killindicator_teamchange == -1)
977 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
979 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
982 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
984 self.nextthink = time + 1;
989 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
993 killtime = cvar("g_balance_kill_delay");
995 self.killindicator_teamchange = targetteam;
997 if(!self.killindicator)
999 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1005 self.killindicator = spawn();
1006 self.killindicator.owner = self;
1007 self.killindicator.scale = 0.5;
1008 setattachment(self.killindicator, self, "");
1009 setorigin(self.killindicator, '0 0 52');
1010 self.killindicator.think = KillIndicator_Think;
1011 self.killindicator.nextthink = time + (self.lip) * 0.05;
1012 self.killindicator.cnt = ceil(killtime);
1013 self.killindicator.count = bound(0, ceil(killtime), 10);
1014 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1016 for(e = world; (e = find(e, classname, "body")) != world; )
1020 e.killindicator = spawn();
1021 e.killindicator.owner = e;
1022 e.killindicator.scale = 0.5;
1023 setattachment(e.killindicator, e, "");
1024 setorigin(e.killindicator, '0 0 52');
1025 e.killindicator.think = KillIndicator_Think;
1026 e.killindicator.nextthink = time + (e.lip) * 0.05;
1027 e.killindicator.cnt = ceil(killtime);
1032 if(self.killindicator)
1035 self.killindicator.colormod = TeamColor(targetteam);
1037 self.killindicator.colormod = '0 0 0';
1041 void ClientKill (void)
1043 ClientKill_TeamChange(0);
1046 void DoTeamChange(float destteam)
1049 if(!cvar("teamplay"))
1052 SetPlayerColors(self, destteam);
1055 if(self.classname == "player")
1058 CheckAllowedTeams(self);
1059 t = FindSmallestTeam(self, TRUE);
1062 case COLOR_TEAM1: c0 = c1; break;
1063 case COLOR_TEAM2: c0 = c2; break;
1064 case COLOR_TEAM3: c0 = c3; break;
1065 case COLOR_TEAM4: c0 = c4; break;
1072 destteam = COLOR_TEAM1;
1076 destteam = COLOR_TEAM2;
1080 destteam = COLOR_TEAM3;
1084 destteam = COLOR_TEAM4;
1090 if(destteam == self.team && !self.killindicator)
1092 ClientKill_TeamChange(destteam);
1095 void FixClientCvars(entity e)
1097 // send prediction settings to the client
1098 stuffcmd(e, "\nin_bindmap 0 0\n");
1100 * we no longer need to stuff this. Remove this comment block if you feel
1101 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1102 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1103 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1104 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1105 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1106 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1107 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1108 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1109 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1110 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1111 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1112 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1113 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1114 stuffcmd(e, "cl_movement_edgefriction 1\n");
1121 if(clienttype(self) == CLIENTTYPE_REAL)
1122 if(world.fog) // NOT string_null!
1129 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1130 WriteByte(MSG_ONE, TE_CSQC_FOG);
1131 WriteCoord(MSG_ONE, sv_foginterval);
1132 WriteString(MSG_ONE, world.fog);
1136 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1147 Called when a client connects to the server
1150 //void ctf_clientconnect();
1151 string ColoredTeamName(float t);
1152 void DecodeLevelParms (void);
1153 //void dom_player_join_team(entity pl);
1154 void ClientConnect (void)
1158 if(self.flags & FL_CLIENT)
1160 print("Warning: ClientConnect, but already connected!\n");
1164 if(Ban_MaybeEnforceBan(self))
1169 self.classname = "player_joining";
1171 self.flags = self.flags | FL_CLIENT;
1172 self.version_nagtime = time + 10 + random() * 10;
1176 dprint("BUG player count is lower than zero, this cannot happen!\n");
1180 PlayerScore_Attach(self);
1182 bot_clientconnect();
1184 race_PreSpawnObserver();
1187 // dom_player_join_team(self);
1189 //JoinBestTeam(self, FALSE, FALSE);
1191 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1192 self.classname = "observer";
1194 self.classname = "player";
1195 campaign_bots_may_start = 1;
1198 self.playerid = (playerid_last = playerid_last + 1);
1199 if(cvar("sv_eventlog"))
1201 if(clienttype(self) == CLIENTTYPE_REAL)
1202 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1204 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1205 s = strcat(":team:", ftos(self.playerid), ":");
1206 s = strcat(s, ftos(self.team));
1209 self.netname_previous = strzone(self.netname);
1211 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1213 bprint ("^4",self.netname);
1214 bprint ("^4 connected");
1216 if(g_domination || g_ctf)
1218 bprint(" and joined the ");
1219 bprint(ColoredTeamName(self.team));
1224 self.welcomemessage_time = 0;
1226 stuffcmd(self, strcat(clientstuff, "\n"));
1227 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1228 stuffcmd(self, "cl_particles_reloadeffects\n");
1230 FixClientCvars(self);
1232 // spawnfunc_waypoint sprites
1233 WaypointSprite_InitClient(self);
1235 // Wazat's grappling hook
1236 SetGrappleHookBindings();
1238 // get autoswitch state from player when he toggles it
1239 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1241 // get version info from player
1242 stuffcmd(self, "cmd clientversion $gameversion\n");
1244 // get other cvars from player
1247 // set cvar for team scoreboard
1251 t = cvar("teamplay");
1252 // 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
1253 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1256 stuffcmd(self, "set teamplay 0\n");
1258 // notify about available teams
1261 CheckAllowedTeams(self);
1262 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1263 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1266 stuffcmd(self, "set _teams_available 0\n");
1268 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1272 self.classname = "observer";
1273 Spawnqueue_Insert(self);
1277 ctf_clientconnect();
1283 bot_relinkplayerlist();
1285 self.spectatortime = time;
1288 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"));
1291 self.jointime = time;
1292 self.allowedTimeouts = cvar("sv_timeout_number");
1294 if(clienttype(self) == CLIENTTYPE_REAL)
1296 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1299 if(mapvote_initialized && !cvar("g_maplist_textonly"))
1301 MapVote_SendData(MSG_ONE);
1302 MapVote_UpdateData(MSG_ONE);
1304 ScoreInfo_Write(MSG_ONE);
1309 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1310 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
1311 WriteByte(MSG_ONE, 1);
1314 if(cvar("g_bugrigs"))
1315 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1320 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1322 PlayerScore_Add(self, SP_LMS_RANK, 666);
1323 self.frags = -666; // FIXME do we still need this?
1334 Called when a client disconnects from the server
1337 .entity chatbubbleentity;
1338 .entity teambubbleentity;
1340 void ClientDisconnect (void)
1342 if not(self.flags & FL_CLIENT)
1344 print("Warning: ClientDisconnect without ClientConnect\n");
1348 bot_clientdisconnect();
1353 if(cvar("sv_eventlog"))
1354 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1355 bprint ("^4",self.netname);
1356 bprint ("^4 disconnected\n");
1359 kh_Key_DropAll(self, TRUE);
1361 Portal_ClearAll(self);
1363 if(self.flagcarried)
1364 DropFlag(self.flagcarried, world, world);
1366 // Here, everything has been done that requires this player to be a client.
1368 self.flags (-) FL_CLIENT;
1370 if (self.chatbubbleentity)
1371 remove (self.chatbubbleentity);
1373 if (self.teambubbleentity)
1374 remove (self.teambubbleentity);
1376 if (self.killindicator)
1377 remove (self.killindicator);
1379 WaypointSprite_PlayerGone();
1381 bot_relinkplayerlist();
1384 if(self.weaponentity)
1385 if(self.weaponentity.lasertarget)
1386 remove(self.weaponentity.lasertarget);
1390 Spawnqueue_Unmark(self);
1391 Spawnqueue_Remove(self);
1394 PlayerScore_Detach(self);
1396 if(self.netname_previous)
1397 strunzone(self.netname_previous);
1399 ClearPlayerSounds();
1409 void ChatBubbleThink()
1411 self.nextthink = time;
1412 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1414 if(self.owner) // but why can that ever be world?
1415 self.owner.chatbubbleentity = world;
1419 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1420 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1421 self.model = self.mdl;
1426 void UpdateChatBubble()
1428 if (!self.modelindex)
1430 // spawn a chatbubble entity if needed
1431 if (!self.chatbubbleentity)
1433 self.chatbubbleentity = spawn();
1434 self.chatbubbleentity.owner = self;
1435 self.chatbubbleentity.exteriormodeltoclient = self;
1436 self.chatbubbleentity.think = ChatBubbleThink;
1437 self.chatbubbleentity.nextthink = time;
1438 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1439 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1440 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1441 self.chatbubbleentity.model = "";
1442 self.chatbubbleentity.effects = EF_LOWPRECISION;
1447 void TeamBubbleThink()
1449 self.nextthink = time;
1450 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1452 if(self.owner) // but why can that ever be world?
1453 self.owner.teambubbleentity = world;
1457 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1458 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1461 self.model = self.mdl;
1465 float TeamBubble_customizeentityforclient()
1467 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1470 void UpdateTeamBubble()
1472 if (!self.modelindex || !cvar("teamplay"))
1474 // spawn a teambubble entity if needed
1475 if (!self.teambubbleentity && cvar("teamplay"))
1477 self.teambubbleentity = spawn();
1478 self.teambubbleentity.owner = self;
1479 self.teambubbleentity.exteriormodeltoclient = self;
1480 self.teambubbleentity.think = TeamBubbleThink;
1481 self.teambubbleentity.nextthink = time;
1482 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1483 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1484 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1485 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1486 self.teambubbleentity.mdl = self.teambubbleentity.model;
1487 self.teambubbleentity.model = self.teambubbleentity.mdl;
1488 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1489 self.teambubbleentity.effects = EF_LOWPRECISION;
1493 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1494 // added to the model skins
1495 /*void UpdateColorModHack()
1498 c = self.clientcolors & 15;
1499 // LordHavoc: only bothering to support white, green, red, yellow, blue
1500 if (teamplay == 0) self.colormod = '0 0 0';
1501 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1502 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1503 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1504 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1505 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1506 else self.colormod = '1 1 1';
1512 self.effects |= EF_NODRAW; // prevent another CopyBody
1513 PutClientInServer();
1517 * When sv_timeout is used this function returs strings like
1518 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1519 * Called by centerprint functions
1520 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1522 string getTimeoutText(float addOneSecond) {
1523 if (!cvar("sv_timeout") || !timeoutStatus)
1526 local string retStr;
1527 if (timeoutStatus == 1) {
1528 if (addOneSecond == 1) {
1529 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1532 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1536 else if (timeoutStatus == 2) {
1538 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1539 //don't show messages like "Timeout ends in 0 seconds"...
1540 if ((remainingTimeoutTime + 1) > 0)
1546 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1547 //don't show messages like "Timeout ends in 0 seconds"...
1548 if (remainingTimeoutTime > 0)
1557 void player_powerups (void)
1561 if (self.items & IT_STRENGTH)
1563 if (time > self.strength_finished)
1565 if (g_minstagib_invis_alpha > 0)
1567 self.alpha = default_player_alpha;
1568 self.exteriorweaponentity.alpha = default_weapon_alpha;
1569 self.effects = self.effects | EF_FULLBRIGHT;
1573 self.effects -= self.effects & EF_NODRAW;
1575 self.items = self.items - (self.items & IT_STRENGTH);
1576 sprint(self, "^3Invisibility has worn off\n");
1581 if (time < self.strength_finished)
1583 if (g_minstagib_invis_alpha > 0)
1585 self.alpha = g_minstagib_invis_alpha;
1586 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1587 self.effects -= self.effects & EF_FULLBRIGHT;
1591 self.effects = self.effects | EF_NODRAW;
1593 self.items = self.items | IT_STRENGTH;
1594 sprint(self, "^3You are invisible\n");
1598 if (self.items & IT_INVINCIBLE)
1600 if (time > self.invincible_finished)
1602 self.items = self.items - (self.items & IT_INVINCIBLE);
1603 sprint(self, "^3Speed has worn off\n");
1608 if (time < self.invincible_finished)
1610 self.items = self.items | IT_INVINCIBLE;
1611 sprint(self, "^3You are on speed\n");
1617 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1618 if (self.items & IT_STRENGTH)
1620 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1621 if (time > self.strength_finished)
1623 self.items = self.items - (self.items & IT_STRENGTH);
1624 sprint(self, "^3Strength has worn off\n");
1629 if (time < self.strength_finished)
1631 self.items = self.items | IT_STRENGTH;
1632 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1635 if (self.items & IT_INVINCIBLE)
1637 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1638 if (time > self.invincible_finished)
1640 self.items = self.items - (self.items & IT_INVINCIBLE);
1641 sprint(self, "^3Shield has worn off\n");
1646 if (time < self.invincible_finished)
1648 self.items = self.items | IT_INVINCIBLE;
1649 sprint(self, "^3Shield surrounds you\n");
1653 if (cvar("g_fullbrightplayers"))
1654 self.effects = self.effects | EF_FULLBRIGHT;
1656 // midair gamemode: damage only while in the air
1657 // if in midair mode, being on ground grants temporary invulnerability
1658 // (this is so that multishot weapon don't clear the ground flag on the
1659 // first damage in the frame, leaving the player vulnerable to the
1660 // remaining hits in the same frame)
1661 if (self.flags & FL_ONGROUND)
1663 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1665 if (time >= game_starttime)
1666 if (time < self.spawnshieldtime)
1667 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1670 float CalcRegen(float current, float stable, float regenfactor)
1672 if(current > stable)
1674 else if(current > stable - 0.25) // when close enough, "snap"
1677 return min(stable, current + (stable - current) * regenfactor * frametime);
1680 void player_regen (void)
1682 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1683 maxh = cvar("g_balance_health_stable");
1684 maxa = cvar("g_balance_armor_stable");
1685 limith = cvar("g_balance_health_limit");
1686 limita = cvar("g_balance_armor_limit");
1688 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1691 max_mod = regen_mod = rot_mod = limit_mod = 1;
1693 if (self.runes & RUNE_REGEN)
1695 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1697 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1698 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1699 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1703 regen_mod = cvar("g_balance_rune_regen_regenrate");
1704 max_mod = cvar("g_balance_rune_regen_hpmod");
1705 limit_mod = cvar("g_balance_rune_regen_limitmod");
1708 else if (self.runes & CURSE_VENOM)
1710 max_mod = cvar("g_balance_curse_venom_hpmod");
1711 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1712 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1714 rot_mod = cvar("g_balance_curse_venom_rotrate");
1715 limit_mod = cvar("g_balance_curse_venom_limitmod");
1716 //if (!self.runes & RUNE_REGEN)
1717 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1719 maxh = maxh * max_mod;
1720 //maxa = maxa * max_mod;
1721 limith = limith * limit_mod;
1722 limita = limita * limit_mod;
1724 if (self.armorvalue > maxa)
1726 if (time > self.pauserotarmor_finished)
1728 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1729 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1732 else if (self.armorvalue < maxa)
1734 if (time > self.pauseregen_finished)
1736 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1737 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1740 if (self.health > maxh)
1742 if (time > self.pauserothealth_finished)
1744 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1745 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1748 else if (self.health < maxh)
1750 if (time > self.pauseregen_finished)
1752 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1753 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1757 if (self.health > limith)
1758 self.health = limith;
1759 if (self.armorvalue > limita)
1760 self.armorvalue = limita;
1762 // if player rotted to death... die!
1764 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1768 float zoomstate_set;
1769 void SetZoomState(float z)
1771 if(z != self.zoomstate)
1774 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1775 WriteByte(MSG_ONE, TE_CSQC_ZOOMNOTIFY);
1776 WriteByte(MSG_ONE, z);
1783 ======================
1784 spectate mode routines
1785 ======================
1787 void SpectateCopy(entity spectatee) {
1788 self.armortype = spectatee.armortype;
1789 self.armorvalue = spectatee.armorvalue;
1790 self.currentammo = spectatee.currentammo;
1791 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1792 self.health = spectatee.health;
1794 self.items = spectatee.items;
1795 self.weapons = spectatee.weapons;
1796 self.switchweapon = spectatee.switchweapon;
1797 self.weapon = spectatee.weapon;
1798 self.punchangle = spectatee.punchangle;
1799 self.view_ofs = spectatee.view_ofs;
1800 self.v_angle = spectatee.v_angle;
1801 self.velocity = spectatee.velocity;
1802 self.dmg_take = spectatee.dmg_take;
1803 self.dmg_save = spectatee.dmg_save;
1804 self.dmg_inflictor = spectatee.dmg_inflictor;
1805 self.angles = spectatee.v_angle;
1806 self.fixangle = TRUE;
1807 setorigin(self, spectatee.origin);
1808 setsize(self, spectatee.mins, spectatee.maxs);
1809 SetZoomState(spectatee.zoomstate);
1812 float SpectateUpdate() {
1816 if (self == self.enemy)
1819 if(self.enemy.flags & FL_NOTARGET)
1822 SpectateCopy(self.enemy);
1827 float SpectateNext() {
1828 other = find(self.enemy, classname, "player");
1830 other = find(other, classname, "player");
1835 if(self.enemy.classname == "player") {
1837 WriteByte(MSG_ONE, SVC_SETVIEW);
1838 WriteEntity(MSG_ONE, self.enemy);
1839 self.wantswelcomemessage = 1;
1840 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1841 if(!SpectateUpdate())
1842 PutObserverInServer();
1851 ShowRespawnCountdown()
1853 Update a respawn countdown display.
1856 void ShowRespawnCountdown()
1859 if(self.deadflag == DEAD_NO) // just respawned?
1863 number = ceil(self.death_time - time);
1866 if(number <= self.respawn_countdown)
1868 self.respawn_countdown = number - 1;
1869 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
1870 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
1875 void LeaveSpectatorMode()
1877 if(isJoinAllowed()) {
1878 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1879 self.classname = "player";
1880 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1881 JoinBestTeam(self, FALSE, TRUE);
1882 if(cvar("g_campaign"))
1883 campaign_bots_may_start = 1;
1884 PutClientInServer();
1885 if(!(self.flags & FL_NOTARGET))
1886 bprint ("^4", self.netname, "^4 is playing now\n");
1887 centerprint(self,"");
1890 stuffcmd(self,"menu_showteamselect\n");
1895 //player may not join because of g_maxplayers is set
1896 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1901 * Determines whether the player is allowed to join. This depends on cvar
1902 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1903 * it checks whether the number of currently playing players exceeds g_maxplayers.
1904 * @return bool TRUE if the player is allowed to join, false otherwise
1906 float isJoinAllowed() {
1907 if (!cvar("g_maxplayers"))
1911 local float currentlyPlaying;
1912 FOR_EACH_REALPLAYER(e) {
1913 if(e.classname == "player")
1914 currentlyPlaying += 1;
1916 if(currentlyPlaying < cvar("g_maxplayers"))
1923 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1924 * g_maxplayers_spectator_blocktime seconds
1926 void checkSpectatorBlock() {
1927 if(self.classname == "spectator" || self.classname == "observer") {
1928 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1929 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1935 float vercmp_recursive(string v1, string v2)
1941 dot1 = strstrofs(v1, ".", 0);
1942 dot2 = strstrofs(v2, ".", 0);
1946 s1 = substring(v1, 0, dot1);
1950 s2 = substring(v2, 0, dot2);
1952 r = stof(s1) - stof(s2);
1956 r = strcasecmp(s1, s2);
1969 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1972 float vercmp(string v1, string v2)
1974 if(strcasecmp(v1, v2) == 0) // early out check
1976 return vercmp_recursive(v1, v2);
1979 void ObserverThink()
1981 if (self.flags & FL_JUMPRELEASED) {
1982 if (self.BUTTON_JUMP && !self.version_mismatch) {
1983 self.welcomemessage_time = 0;
1984 self.flags = self.flags - FL_JUMPRELEASED;
1985 LeaveSpectatorMode();
1987 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1988 self.welcomemessage_time = 0;
1989 self.flags = self.flags - FL_JUMPRELEASED;
1990 if(SpectateNext() == 1) {
1991 self.classname = "spectator";
1995 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1996 self.flags = self.flags | FL_JUMPRELEASED;
1999 if(self.BUTTON_ZOOM)
2000 self.wantswelcomemessage = 0;
2001 if(self.wantswelcomemessage)
2002 PrintWelcomeMessage(self);
2005 void SpectatorThink()
2007 if (self.flags & FL_JUMPRELEASED) {
2008 if (self.BUTTON_JUMP && !self.version_mismatch) {
2009 self.welcomemessage_time = 0;
2010 self.flags = self.flags - FL_JUMPRELEASED;
2011 LeaveSpectatorMode();
2013 } else if(self.BUTTON_ATCK) {
2014 self.welcomemessage_time = 0;
2015 self.flags = self.flags - FL_JUMPRELEASED;
2016 if(SpectateNext() == 1) {
2017 self.classname = "spectator";
2019 self.classname = "observer";
2020 PutClientInServer();
2022 } else if (self.BUTTON_ATCK2) {
2023 self.welcomemessage_time = 0;
2024 self.flags = self.flags - FL_JUMPRELEASED;
2025 self.classname = "observer";
2026 PutClientInServer();
2028 if(!SpectateUpdate())
2029 PutObserverInServer();
2032 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2033 self.flags = self.flags | FL_JUMPRELEASED;
2036 if(self.BUTTON_ZOOM)
2037 self.wantswelcomemessage = 0;
2038 if(self.wantswelcomemessage)
2039 PrintWelcomeMessage(self);
2040 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
2047 Called every frame for each client before the physics are run
2050 void() ctf_setstatus;
2051 .float spectatee_status;
2052 void PlayerPreThink (void)
2054 self.stat_sys_ticrate = cvar("sys_ticrate");
2055 self.stat_game_starttime = game_starttime;
2058 checkSpectatorBlock();
2062 if(self.netname_previous != self.netname)
2064 if(cvar("sv_eventlog"))
2065 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2066 if(self.netname_previous)
2067 strunzone(self.netname_previous);
2068 self.netname_previous = strzone(self.netname);
2072 if(self.version_nagtime)
2073 if(self.cvar_g_nexuizversion)
2074 if(time > self.version_nagtime)
2076 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2078 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2080 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");
2081 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"));
2086 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2089 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");
2090 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"));
2094 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");
2095 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2099 self.version_nagtime = 0;
2103 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2105 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2106 self.max_armorvalue = 0;
2112 antilag_record(self);
2115 if(self.classname == "player") {
2116 // if(self.netname == "Wazat")
2117 // bprint(self.classname, "\n");
2119 CheckRules_Player();
2121 if(self.BUTTON_INFO)
2122 PrintWelcomeMessage(self);
2124 if(g_lms || !cvar("sv_spectate"))
2125 if((time - self.jointime) <= cvar("welcome_message_time"))
2126 PrintWelcomeMessage(self);
2128 if (intermission_running)
2130 IntermissionThink (); // otherwise a button could be missed between
2131 return; // the think tics
2134 if(self.teleport_time)
2135 if(time > self.teleport_time)
2137 self.teleport_time = 0;
2138 self.effects = self.effects - (self.effects & EF_NODRAW);
2139 if(self.weaponentity)
2140 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
2143 Nixnex_GiveCurrentWeapon();
2145 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2146 UpdateSelectedPlayer();
2148 //don't allow the player to turn around while game is paused!
2149 if(timeoutStatus == 2) {
2150 self.v_angle = self.lastV_angle;
2151 self.angles = self.lastV_angle;
2152 self.fixangle = TRUE;
2155 if (self.deadflag != DEAD_NO)
2157 float button_pressed, force_respawn;
2159 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2160 force_respawn = (g_lms || cvar("g_forced_respawn"));
2161 if (self.deadflag == DEAD_DYING)
2164 self.deadflag = DEAD_RESPAWNING;
2165 else if(!button_pressed)
2166 self.deadflag = DEAD_DEAD;
2168 else if (self.deadflag == DEAD_DEAD)
2171 self.deadflag = DEAD_RESPAWNABLE;
2173 else if (self.deadflag == DEAD_RESPAWNABLE)
2176 self.deadflag = DEAD_RESPAWNING;
2178 else if (self.deadflag == DEAD_RESPAWNING)
2180 if(time > self.death_time)
2182 self.death_time = time + 1; // only retry once a second
2186 ShowRespawnCountdown();
2190 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2194 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2195 dist = self.oldorigin - self.origin;
2197 self.lms_traveled_distance += fabs(vlen(dist));
2199 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2201 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2202 self.lms_traveled_distance = 0;
2205 if(time > self.lms_nextcheck)
2207 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2208 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2210 centerprint(self, cvar_string("g_lms_campcheck_message"));
2211 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2212 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2213 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');
2215 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2216 self.lms_traveled_distance = 0;
2220 if (self.BUTTON_CROUCH && !self.hook.state)
2225 self.view_ofs = PL_CROUCH_VIEW_OFS;
2226 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2227 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2234 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2235 if (!trace_startsolid)
2237 self.crouch = FALSE;
2238 self.view_ofs = PL_VIEW_OFS;
2239 setsize (self, PL_MIN, PL_MAX);
2246 GrapplingHookFrame();
2255 minstagib_ammocheck();
2260 //self.angles_y=self.v_angle_y + 90; // temp
2262 //if (TetrisPreFrame()) return;
2263 } else if(gameover) {
2264 if (intermission_running)
2265 IntermissionThink (); // otherwise a button could be missed between
2267 } else if(self.classname == "observer") {
2269 } else if(self.classname == "spectator") {
2274 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2276 float oldspectatee_status;
2277 oldspectatee_status = self.spectatee_status;
2278 if(self.classname == "spectator")
2279 self.spectatee_status = num_for_edict(self.enemy);
2280 else if(self.classname == "observer")
2281 self.spectatee_status = num_for_edict(self);
2283 self.spectatee_status = 0;
2284 if(self.spectatee_status != oldspectatee_status)
2287 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2288 WriteByte(MSG_ONE, TE_CSQC_SPECTATING);
2289 WriteByte(MSG_ONE, self.spectatee_status);
2291 race_InitSpectator();
2294 if(self.teamkill_soundtime)
2295 if(time > self.teamkill_soundtime)
2297 self.teamkill_soundtime = 0;
2299 entity oldpusher, oldself;
2301 oldself = self; self = self.teamkill_soundsource;
2302 oldpusher = self.pusher; self.pusher = oldself;
2304 VoiceMessage("teamshoot_auto");
2306 self.pusher = oldpusher;
2310 target_voicescript_next(self);
2318 Called every frame for each client after the physics are run
2321 .float idlekick_lasttimeleft;
2322 .float race_penalty;
2323 .float race_penalty_nagged;
2324 .float race_penalty_nagtime;
2325 void PlayerPostThink (void)
2327 // Savage: Check for nameless players
2328 if (strlen(self.netname) < 1) {
2329 self.netname = "Player";
2330 stuffcmd(self, "seta _cl_name Player\n");
2336 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2339 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2340 announce(self, "announcer/robotic/terminated.wav");
2344 else if(timeleft <= 10)
2346 if(timeleft != self.idlekick_lasttimeleft)
2348 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2349 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2354 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2356 self.idlekick_lasttimeleft = timeleft;
2359 if(self.classname == "player") {
2360 CheckRules_Player();
2365 if (intermission_running)
2366 return; // intermission or finale
2368 //PrintWelcomeMessage(self);
2369 //if (TetrisPostFrame()) return;
2371 // restart countdown
2372 if(time < game_starttime) {
2373 if (!cvar("sv_ready_restart_after_countdown"))
2375 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2377 if(time < game_starttime - 2)
2379 if(!self.race_penalty_nagged)
2381 // TODO better notification for this!
2382 self.race_penalty_nagtime = 0;
2383 self.race_penalty_nagged = 1;
2386 else if(!self.race_penalty)
2388 self.race_penalty_nagtime = 0;
2389 self.race_penalty = time + 5;
2392 if(time > self.race_penalty_nagtime)
2394 if(self.race_penalty > time)
2396 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2398 else if(self.race_penalty_nagged && time < game_starttime - 2)
2400 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2402 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2404 self.movetype = MOVETYPE_NONE;
2405 self.velocity = '0 0 0';
2406 self.avelocity = '0 0 0';
2407 self.movement = '0 0 0';
2410 else if (time < self.race_penalty)
2412 self.movetype = MOVETYPE_NONE;
2413 self.velocity = '0 0 0';
2414 self.avelocity = '0 0 0';
2415 self.movement = '0 0 0';
2419 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2420 if (!cvar("sv_ready_restart_after_countdown"))
2422 if(self.movetype == MOVETYPE_NONE)
2424 self.movetype = MOVETYPE_WALK;
2426 self.race_penalty = 0;
2427 self.race_penalty_nagged = 0;
2431 } else if (self.classname == "observer") {
2433 } else if (self.classname == "spectator") {
2439 for(i = 0; i < 1000; ++i)
2442 end = self.origin + '0 0 1024' + 512 * randomvec();
2443 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2444 if(trace_fraction < 1)
2445 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2447 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2455 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);