1 // let's abuse an existing field
2 #define SPAWNPOINT_SCORE frags
4 .float wantswelcomemessage;
5 .string netname_previous;
7 void spawnfunc_info_player_survivor (void)
9 spawnfunc_info_player_deathmatch();
12 void spawnfunc_info_player_start (void)
14 spawnfunc_info_player_deathmatch();
17 void spawnfunc_info_player_deathmatch (void)
19 self.classname = "info_player_deathmatch";
20 relocate_spawnpoint();
28 self.team = activator.team;
29 some_spawn_has_been_used = 1;
34 // -1 if a spawn can't be used
35 // otherwise, a weight of the spawnpoint
36 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
38 float shortest, thisdist;
41 // filter out spots for the wrong team
43 if(spot.team != teamcheck)
50 // filter out spots for assault
51 if(spot.target != "") {
54 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)
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"));
593 Called when a client spawns in the server
596 //void() ctf_playerchanged;
597 void PutClientInServer (void)
599 if(clienttype(self) == CLIENTTYPE_BOT)
601 self.classname = "player";
603 else if(clienttype(self) == CLIENTTYPE_REAL)
606 WriteByte(MSG_ONE, SVC_SETVIEW);
607 WriteEntity(MSG_ONE, self);
610 // player is dead and becomes observer
611 // FIXME fix LMS scoring for new system
614 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
615 self.classname = "observer";
620 self.classname = "observer";
622 if(self.classname == "player") {
623 entity spot, oldself;
628 spot = SelectSpawnPoint (FALSE);
631 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
632 return; // spawn failed
635 RemoveGrapplingHook(self); // Wazat's Grappling Hook
637 self.classname = "player";
638 self.iscreature = TRUE;
639 self.movetype = MOVETYPE_WALK;
640 self.solid = SOLID_SLIDEBOX;
641 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
642 if(independent_players)
643 MAKE_INDEPENDENT_PLAYER(self);
644 self.flags = FL_CLIENT;
645 self.takedamage = DAMAGE_AIM;
647 self.effects = EF_FULLBRIGHT;
650 self.air_finished = time + 12;
655 self.ammo_shells = warmup_start_ammo_shells;
656 self.ammo_nails = warmup_start_ammo_nails;
657 self.ammo_rockets = warmup_start_ammo_rockets;
658 self.ammo_cells = warmup_start_ammo_cells;
659 self.health = warmup_start_health;
660 self.armorvalue = warmup_start_armorvalue;
661 self.weapons = warmup_start_weapons;
665 self.ammo_shells = start_ammo_shells;
666 self.ammo_nails = start_ammo_nails;
667 self.ammo_rockets = start_ammo_rockets;
668 self.ammo_cells = start_ammo_cells;
669 self.health = start_health;
670 self.armorvalue = start_armorvalue;
671 self.weapons = start_weapons;
673 self.items = start_items;
674 self.switchweapon = w_getbestweapon(self);
675 self.cnt = self.switchweapon;
677 self.jump_interval = time;
679 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
680 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
681 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
682 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
683 //extend the pause of rotting if client was reset at the beginning of the countdown
684 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
685 self.spawnshieldtime += game_starttime - time;
686 self.pauserotarmor_finished += game_starttime - time;
687 self.pauserothealth_finished += game_starttime - time;
688 self.pauseregen_finished += game_starttime - time;
690 self.damageforcescale = 2;
697 self.pain_finished = 0;
698 self.strength_finished = 0;
699 self.invincible_finished = 0;
701 //self.speed_finished = 0;
702 //self.slowmo_finished = 0;
703 // players have no think function
704 self.think = SUB_Null;
710 self.deadflag = DEAD_NO;
712 self.angles = spot.angles;
714 self.angles_z = 0; // never spawn tilted even if the spot says to
715 self.fixangle = TRUE; // turn this way immediately
716 self.velocity = '0 0 0';
717 self.avelocity = '0 0 0';
718 self.punchangle = '0 0 0';
719 self.punchvector = '0 0 0';
720 self.oldvelocity = self.velocity;
723 WRITESPECTATABLE_MSG_ONE({
724 WriteByte(MSG_ONE, SVC_TEMPENTITY);
725 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
728 self.customizeentityforclient = Client_customizeentityforclient;
734 self.view_ofs = PL_VIEW_OFS;
735 setsize (self, PL_MIN, PL_MAX);
736 self.spawnorigin = spot.origin;
737 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
738 // don't reset back to last position, even if new position is stuck in solid
739 self.oldorigin = self.origin;
743 Spawnqueue_Remove(self);
744 Spawnqueue_Mark(self);
747 self.event_damage = PlayerDamage;
749 self.bot_attack = TRUE;
751 self.statdraintime = time + 5;
752 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
754 if(self.killcount == -666) {
755 PlayerScore_Clear(self);
760 self.cnt = WEP_LASER;
761 self.nixnex_lastchange_id = -1;
763 CL_SpawnWeaponentity();
764 self.alpha = default_player_alpha;
765 self.colormod = '1 1 1' * cvar("g_player_brightness");
766 self.exteriorweaponentity.alpha = default_weapon_alpha;
768 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
769 self.lms_traveled_distance = 0;
770 self.speedrunning = FALSE;
772 race_PostSpawn(spot);
774 if(cvar("spawn_debug"))
776 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
777 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
780 //stuffcmd(self, "chase_active 0");
781 //stuffcmd(self, "set viewsize $tmpviewsize \n");
783 if (cvar("g_spawnsound"))
784 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
787 if(self.team == assault_attacker_team)
788 centerprint(self, "You are attacking!\n");
790 centerprint(self, "You are defending!\n");
793 target_voicescript_clear(self);
796 spot.target = string_null;
805 } else if(self.classname == "observer") {
806 PutObserverInServer ();
810 // ctf_playerchanged();
817 Send whatever CSQC needs NOW and cannot wait for SendServerInfo to happen...
820 void SendCSQCInfo(void)
823 if(clienttype(self) != CLIENTTYPE_REAL)
826 WriteByte(MSG_ONE, SVC_TEMPENTITY);
827 WriteByte(MSG_ONE, TE_CSQC_INIT);
828 WriteShort(MSG_ONE, CSQC_REVISION);
829 WriteByte(MSG_ONE, maxclients);
830 for(i = 1; i <= 24; ++i)
831 WriteByte(MSG_ONE, (get_weaponinfo(i)).impulse + 1);
832 WriteCoord(MSG_ONE, hook_shotorigin_x);
833 WriteCoord(MSG_ONE, hook_shotorigin_y);
834 WriteCoord(MSG_ONE, hook_shotorigin_z);
842 void SetNewParms (void)
844 // initialize parms for a new player
845 parm1 = -(86400 * 366);
853 void SetChangeParms (void)
855 // save parms for level change
856 parm1 = self.parm_idlesince - time;
864 void DecodeLevelParms (void)
867 self.parm_idlesince = parm1;
868 if(self.parm_idlesince == -(86400 * 366))
869 self.parm_idlesince = time;
876 Called when a client types 'kill' in the console
880 void ClientKill_Now_TeamChange()
882 if(self.killindicator_teamchange == -1)
885 JoinBestTeam( self, FALSE, FALSE );
889 SV_ChangeTeam(self.killindicator_teamchange - 1);
893 void ClientKill_Now()
895 if(self.killindicator_teamchange)
896 ClientKill_Now_TeamChange();
899 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
901 if(self.killindicator)
903 dprint("Cleaned up after a leaked kill indicator.\n");
904 remove(self.killindicator);
905 self.killindicator = world;
908 void KillIndicator_Think()
910 if (!self.owner.modelindex)
912 self.owner.killindicator = world;
920 ClientKill_Now(); // no oldself needed
926 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
927 if(clienttype(self.owner) == CLIENTTYPE_REAL)
930 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
931 if(self.owner.killindicator_teamchange)
933 if(self.owner.killindicator_teamchange == -1)
934 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
936 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
939 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
941 self.nextthink = time + 1;
946 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
950 killtime = cvar("g_balance_kill_delay");
952 self.killindicator_teamchange = targetteam;
954 if(!self.killindicator)
956 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
962 self.killindicator = spawn();
963 self.killindicator.owner = self;
964 self.killindicator.scale = 0.5;
965 setattachment(self.killindicator, self, "");
966 setorigin(self.killindicator, '0 0 52');
967 self.killindicator.think = KillIndicator_Think;
968 self.killindicator.nextthink = time + (self.lip) * 0.05;
969 self.killindicator.cnt = ceil(killtime);
970 self.killindicator.count = bound(0, ceil(killtime), 10);
971 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
973 for(e = world; (e = find(e, classname, "body")) != world; )
977 e.killindicator = spawn();
978 e.killindicator.owner = e;
979 e.killindicator.scale = 0.5;
980 setattachment(e.killindicator, e, "");
981 setorigin(e.killindicator, '0 0 52');
982 e.killindicator.think = KillIndicator_Think;
983 e.killindicator.nextthink = time + (e.lip) * 0.05;
984 e.killindicator.cnt = ceil(killtime);
989 if(self.killindicator)
992 self.killindicator.colormod = TeamColor(targetteam);
994 self.killindicator.colormod = '0 0 0';
998 void ClientKill (void)
1000 ClientKill_TeamChange(0);
1003 void DoTeamChange(float destteam)
1006 if(!cvar("teamplay"))
1009 SetPlayerColors(self, destteam);
1012 if(self.classname == "player")
1015 CheckAllowedTeams(self);
1016 t = FindSmallestTeam(self, TRUE);
1019 case COLOR_TEAM1: c0 = c1; break;
1020 case COLOR_TEAM2: c0 = c2; break;
1021 case COLOR_TEAM3: c0 = c3; break;
1022 case COLOR_TEAM4: c0 = c4; break;
1029 destteam = COLOR_TEAM1;
1033 destteam = COLOR_TEAM2;
1037 destteam = COLOR_TEAM3;
1041 destteam = COLOR_TEAM4;
1047 if(destteam == self.team && !self.killindicator)
1049 ClientKill_TeamChange(destteam);
1052 void FixClientCvars(entity e)
1054 // send prediction settings to the client
1055 stuffcmd(e, "\nin_bindmap 0 0\n");
1057 * we no longer need to stuff this. Remove this comment block if you feel
1058 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1059 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1060 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1061 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1062 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1063 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1064 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1065 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1066 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1067 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1068 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1069 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1070 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1071 stuffcmd(e, "cl_movement_edgefriction 1\n");
1078 if(clienttype(self) == CLIENTTYPE_REAL)
1079 if(world.fog) // NOT string_null!
1086 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1087 WriteByte(MSG_ONE, TE_CSQC_FOG);
1088 WriteCoord(MSG_ONE, sv_foginterval);
1089 WriteString(MSG_ONE, world.fog);
1093 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1104 Called when a client connects to the server
1107 //void ctf_clientconnect();
1108 string ColoredTeamName(float t);
1109 void DecodeLevelParms (void);
1110 //void dom_player_join_team(entity pl);
1111 void ClientConnect (void)
1115 if(self.flags & FL_CLIENT)
1117 print("Warning: ClientConnect, but already connected!\n");
1121 if(Ban_MaybeEnforceBan(self))
1126 self.classname = "player_joining";
1128 self.flags = self.flags | FL_CLIENT;
1129 self.version_nagtime = time + 10 + random() * 10;
1133 dprint("BUG player count is lower than zero, this cannot happen!\n");
1137 PlayerScore_Attach(self);
1139 bot_clientconnect();
1141 race_PreSpawnObserver();
1144 // dom_player_join_team(self);
1146 //JoinBestTeam(self, FALSE, FALSE);
1148 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1149 self.classname = "observer";
1151 self.classname = "player";
1152 campaign_bots_may_start = 1;
1155 self.playerid = (playerid_last = playerid_last + 1);
1156 if(cvar("sv_eventlog"))
1158 if(clienttype(self) == CLIENTTYPE_REAL)
1159 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1161 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1162 s = strcat(":team:", ftos(self.playerid), ":");
1163 s = strcat(s, ftos(self.team));
1166 self.netname_previous = strzone(self.netname);
1168 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1170 bprint ("^4",self.netname);
1171 bprint ("^4 connected");
1173 if(g_domination || g_ctf)
1175 bprint(" and joined the ");
1176 bprint(ColoredTeamName(self.team));
1181 self.welcomemessage_time = 0;
1183 stuffcmd(self, strcat(clientstuff, "\n"));
1184 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1185 stuffcmd(self, "cl_particles_reloadeffects\n");
1187 FixClientCvars(self);
1189 // spawnfunc_waypoint sprites
1190 WaypointSprite_InitClient(self);
1192 // Wazat's grappling hook
1193 SetGrappleHookBindings();
1195 // get autoswitch state from player when he toggles it
1196 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1198 // get version info from player
1199 stuffcmd(self, "cmd clientversion $gameversion\n");
1201 // get other cvars from player
1204 // set cvar for team scoreboard
1208 t = cvar("teamplay");
1209 // 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
1210 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
1213 stuffcmd(self, "set teamplay 0\n");
1215 // notify about available teams
1218 CheckAllowedTeams(self);
1219 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1220 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1223 stuffcmd(self, "set _teams_available 0\n");
1225 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1229 self.classname = "observer";
1230 Spawnqueue_Insert(self);
1234 ctf_clientconnect();
1240 bot_relinkplayerlist();
1242 self.spectatortime = time;
1245 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"));
1248 self.jointime = time;
1249 self.allowedTimeouts = cvar("sv_timeout_number");
1251 if(clienttype(self) == CLIENTTYPE_REAL)
1253 sprint(self, strcat("nexuiz-csqc protocol ", ftos(CSQC_REVISION), "\n"));
1256 if(mapvote_initialized && !cvar("g_maplist_textonly"))
1258 MapVote_SendData(MSG_ONE);
1259 MapVote_UpdateData(MSG_ONE);
1261 ScoreInfo_Write(MSG_ONE);
1267 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1268 WriteByte(MSG_ONE, TE_CSQC_WARMUP);
1269 WriteByte(MSG_ONE, 1);
1274 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1276 PlayerScore_Add(self, SP_LMS_RANK, 666);
1277 self.frags = -666; // FIXME do we still need this?
1288 Called when a client disconnects from the server
1291 .entity chatbubbleentity;
1292 .entity teambubbleentity;
1294 void ClientDisconnect (void)
1296 if not(self.flags & FL_CLIENT)
1298 print("Warning: ClientDisconnect without ClientConnect\n");
1302 bot_clientdisconnect();
1307 if(cvar("sv_eventlog"))
1308 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1309 bprint ("^4",self.netname);
1310 bprint ("^4 disconnected\n");
1313 kh_Key_DropAll(self, TRUE);
1315 Portal_ClearAll(self);
1317 if(self.flagcarried)
1318 DropFlag(self.flagcarried, world, world);
1320 // Here, everything has been done that requires this player to be a client.
1322 self.flags (-) FL_CLIENT;
1324 if (self.chatbubbleentity)
1325 remove (self.chatbubbleentity);
1327 if (self.teambubbleentity)
1328 remove (self.teambubbleentity);
1330 if (self.killindicator)
1331 remove (self.killindicator);
1333 WaypointSprite_PlayerGone();
1335 bot_relinkplayerlist();
1338 if(self.weaponentity)
1339 if(self.weaponentity.lasertarget)
1340 remove(self.weaponentity.lasertarget);
1344 Spawnqueue_Unmark(self);
1345 Spawnqueue_Remove(self);
1348 PlayerScore_Detach(self);
1350 if(self.netname_previous)
1351 strunzone(self.netname_previous);
1353 ClearPlayerSounds();
1363 void ChatBubbleThink()
1365 self.nextthink = time;
1366 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1368 if(self.owner) // but why can that ever be world?
1369 self.owner.chatbubbleentity = world;
1373 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1374 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1375 self.model = self.mdl;
1380 void UpdateChatBubble()
1382 if (!self.modelindex)
1384 // spawn a chatbubble entity if needed
1385 if (!self.chatbubbleentity)
1387 self.chatbubbleentity = spawn();
1388 self.chatbubbleentity.owner = self;
1389 self.chatbubbleentity.exteriormodeltoclient = self;
1390 self.chatbubbleentity.think = ChatBubbleThink;
1391 self.chatbubbleentity.nextthink = time;
1392 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1393 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1394 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1395 self.chatbubbleentity.model = "";
1396 self.chatbubbleentity.effects = EF_LOWPRECISION;
1401 void TeamBubbleThink()
1403 self.nextthink = time;
1404 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1406 if(self.owner) // but why can that ever be world?
1407 self.owner.teambubbleentity = world;
1411 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1412 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1415 self.model = self.mdl;
1419 float TeamBubble_customizeentityforclient()
1421 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1424 void UpdateTeamBubble()
1426 if (!self.modelindex || !cvar("teamplay"))
1428 // spawn a teambubble entity if needed
1429 if (!self.teambubbleentity && cvar("teamplay"))
1431 self.teambubbleentity = spawn();
1432 self.teambubbleentity.owner = self;
1433 self.teambubbleentity.exteriormodeltoclient = self;
1434 self.teambubbleentity.think = TeamBubbleThink;
1435 self.teambubbleentity.nextthink = time;
1436 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1437 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1438 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1439 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1440 self.teambubbleentity.mdl = self.teambubbleentity.model;
1441 self.teambubbleentity.model = self.teambubbleentity.mdl;
1442 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1443 self.teambubbleentity.effects = EF_LOWPRECISION;
1447 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1448 // added to the model skins
1449 /*void UpdateColorModHack()
1452 c = self.clientcolors & 15;
1453 // LordHavoc: only bothering to support white, green, red, yellow, blue
1454 if (teamplay == 0) self.colormod = '0 0 0';
1455 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1456 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1457 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1458 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1459 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1460 else self.colormod = '1 1 1';
1466 self.effects |= EF_NODRAW; // prevent another CopyBody
1467 PutClientInServer();
1471 * When sv_timeout is used this function returs strings like
1472 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1473 * Called by centerprint functions
1474 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1476 string getTimeoutText(float addOneSecond) {
1477 if (!cvar("sv_timeout") || !timeoutStatus)
1480 local string retStr;
1481 if (timeoutStatus == 1) {
1482 if (addOneSecond == 1) {
1483 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1486 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1490 else if (timeoutStatus == 2) {
1492 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1493 //don't show messages like "Timeout ends in 0 seconds"...
1494 if ((remainingTimeoutTime + 1) > 0)
1500 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1501 //don't show messages like "Timeout ends in 0 seconds"...
1502 if (remainingTimeoutTime > 0)
1511 void player_powerups (void)
1515 if (self.items & IT_STRENGTH)
1517 if (time > self.strength_finished)
1519 if (g_minstagib_invis_alpha > 0)
1521 self.alpha = default_player_alpha;
1522 self.exteriorweaponentity.alpha = default_weapon_alpha;
1523 self.effects = self.effects | EF_FULLBRIGHT;
1527 self.effects -= self.effects & EF_NODRAW;
1529 self.items = self.items - (self.items & IT_STRENGTH);
1530 sprint(self, "^3Invisibility has worn off\n");
1535 if (time < self.strength_finished)
1537 if (g_minstagib_invis_alpha > 0)
1539 self.alpha = g_minstagib_invis_alpha;
1540 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1541 self.effects -= self.effects & EF_FULLBRIGHT;
1545 self.effects = self.effects | EF_NODRAW;
1547 self.items = self.items | IT_STRENGTH;
1548 sprint(self, "^3You are invisible\n");
1552 if (self.items & IT_INVINCIBLE)
1554 if (time > self.invincible_finished)
1556 self.items = self.items - (self.items & IT_INVINCIBLE);
1557 sprint(self, "^3Speed has worn off\n");
1562 if (time < self.invincible_finished)
1564 self.items = self.items | IT_INVINCIBLE;
1565 sprint(self, "^3You are on speed\n");
1571 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1572 if (self.items & IT_STRENGTH)
1574 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1575 if (time > self.strength_finished)
1577 self.items = self.items - (self.items & IT_STRENGTH);
1578 sprint(self, "^3Strength has worn off\n");
1583 if (time < self.strength_finished)
1585 self.items = self.items | IT_STRENGTH;
1586 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1589 if (self.items & IT_INVINCIBLE)
1591 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1592 if (time > self.invincible_finished)
1594 self.items = self.items - (self.items & IT_INVINCIBLE);
1595 sprint(self, "^3Shield has worn off\n");
1600 if (time < self.invincible_finished)
1602 self.items = self.items | IT_INVINCIBLE;
1603 sprint(self, "^3Shield surrounds you\n");
1607 if (cvar("g_fullbrightplayers"))
1608 self.effects = self.effects | EF_FULLBRIGHT;
1610 // midair gamemode: damage only while in the air
1611 // if in midair mode, being on ground grants temporary invulnerability
1612 // (this is so that multishot weapon don't clear the ground flag on the
1613 // first damage in the frame, leaving the player vulnerable to the
1614 // remaining hits in the same frame)
1615 if (self.flags & FL_ONGROUND)
1617 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1619 if (time >= game_starttime)
1620 if (time < self.spawnshieldtime)
1621 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1624 float CalcRegen(float current, float stable, float regenfactor)
1626 if(current > stable)
1628 else if(current > stable - 0.25) // when close enough, "snap"
1631 return min(stable, current + (stable - current) * regenfactor * frametime);
1634 void player_regen (void)
1636 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1637 maxh = cvar("g_balance_health_stable");
1638 maxa = cvar("g_balance_armor_stable");
1639 limith = cvar("g_balance_health_limit");
1640 limita = cvar("g_balance_armor_limit");
1642 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1645 max_mod = regen_mod = rot_mod = limit_mod = 1;
1647 if (self.runes & RUNE_REGEN)
1649 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1651 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1652 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1653 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1657 regen_mod = cvar("g_balance_rune_regen_regenrate");
1658 max_mod = cvar("g_balance_rune_regen_hpmod");
1659 limit_mod = cvar("g_balance_rune_regen_limitmod");
1662 else if (self.runes & CURSE_VENOM)
1664 max_mod = cvar("g_balance_curse_venom_hpmod");
1665 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1666 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1668 rot_mod = cvar("g_balance_curse_venom_rotrate");
1669 limit_mod = cvar("g_balance_curse_venom_limitmod");
1670 //if (!self.runes & RUNE_REGEN)
1671 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1673 maxh = maxh * max_mod;
1674 //maxa = maxa * max_mod;
1675 limith = limith * limit_mod;
1676 limita = limita * limit_mod;
1678 if (self.armorvalue > maxa)
1680 if (time > self.pauserotarmor_finished)
1682 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1683 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1686 else if (self.armorvalue < maxa)
1688 if (time > self.pauseregen_finished)
1690 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1691 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1694 if (self.health > maxh)
1696 if (time > self.pauserothealth_finished)
1698 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1699 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1702 else if (self.health < maxh)
1704 if (time > self.pauseregen_finished)
1706 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1707 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1711 if (self.health > limith)
1712 self.health = limith;
1713 if (self.armorvalue > limita)
1714 self.armorvalue = limita;
1716 // if player rotted to death... die!
1718 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1722 float zoomstate_set;
1723 void SetZoomState(float z)
1725 if(z != self.zoomstate)
1728 WriteByte(MSG_ONE, SVC_TEMPENTITY);
1729 WriteByte(MSG_ONE, TE_CSQC_ZOOMNOTIFY);
1730 WriteByte(MSG_ONE, z);
1737 ======================
1738 spectate mode routines
1739 ======================
1741 void SpectateCopy(entity spectatee) {
1742 self.armortype = spectatee.armortype;
1743 self.armorvalue = spectatee.armorvalue;
1744 self.currentammo = spectatee.currentammo;
1745 self.effects = spectatee.effects;
1746 self.health = spectatee.health;
1748 self.items = spectatee.items;
1749 self.weapons = spectatee.weapons;
1750 self.switchweapon = spectatee.switchweapon;
1751 self.weapon = spectatee.weapon;
1752 self.punchangle = spectatee.punchangle;
1753 self.view_ofs = spectatee.view_ofs;
1754 self.v_angle = spectatee.v_angle;
1755 self.velocity = spectatee.velocity;
1756 self.dmg_take = spectatee.dmg_take;
1757 self.dmg_save = spectatee.dmg_save;
1758 self.dmg_inflictor = spectatee.dmg_inflictor;
1759 self.angles = spectatee.v_angle;
1760 self.fixangle = TRUE;
1761 setorigin(self, spectatee.origin);
1762 setsize(self, spectatee.mins, spectatee.maxs);
1763 SetZoomState(spectatee.zoomstate);
1766 float SpectateUpdate() {
1770 if (self == self.enemy)
1773 if(self.enemy.flags & FL_NOTARGET)
1776 SpectateCopy(self.enemy);
1781 float SpectateNext() {
1782 other = find(self.enemy, classname, "player");
1784 other = find(other, classname, "player");
1789 if(self.enemy.classname == "player") {
1791 WriteByte(MSG_ONE, SVC_SETVIEW);
1792 WriteEntity(MSG_ONE, self.enemy);
1793 self.wantswelcomemessage = 1;
1794 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1795 if(!SpectateUpdate())
1796 PutObserverInServer();
1805 ShowRespawnCountdown()
1807 Update a respawn countdown display.
1810 void ShowRespawnCountdown()
1813 if(self.deadflag == DEAD_NO) // just respawned?
1817 number = ceil(self.death_time - time);
1820 if(number <= self.respawn_countdown)
1822 self.respawn_countdown = number - 1;
1823 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
1824 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
1829 void LeaveSpectatorMode()
1831 if(isJoinAllowed()) {
1832 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1833 self.classname = "player";
1834 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1835 JoinBestTeam(self, FALSE, TRUE);
1836 if(cvar("g_campaign"))
1837 campaign_bots_may_start = 1;
1838 PutClientInServer();
1839 if(!(self.flags & FL_NOTARGET))
1840 bprint ("^4", self.netname, "^4 is playing now\n");
1841 centerprint(self,"");
1844 stuffcmd(self,"menu_showteamselect\n");
1849 //player may not join because of g_maxplayers is set
1850 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
1855 * Determines whether the player is allowed to join. This depends on cvar
1856 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
1857 * it checks whether the number of currently playing players exceeds g_maxplayers.
1858 * @return bool TRUE if the player is allowed to join, false otherwise
1860 float isJoinAllowed() {
1861 if (!cvar("g_maxplayers"))
1865 local float currentlyPlaying;
1866 FOR_EACH_REALPLAYER(e) {
1867 if(e.classname == "player")
1868 currentlyPlaying += 1;
1870 if(currentlyPlaying < cvar("g_maxplayers"))
1877 * Checks whether the client is an observer or spectator, if so, he will get kicked after
1878 * g_maxplayers_spectator_blocktime seconds
1880 void checkSpectatorBlock() {
1881 if(self.classname == "spectator" || self.classname == "observer") {
1882 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
1883 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
1889 float vercmp_recursive(string v1, string v2)
1895 dot1 = strstrofs(v1, ".", 0);
1896 dot2 = strstrofs(v2, ".", 0);
1900 s1 = substring(v1, 0, dot1);
1904 s2 = substring(v2, 0, dot2);
1906 r = stof(s1) - stof(s2);
1910 r = strcasecmp(s1, s2);
1923 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
1926 float vercmp(string v1, string v2)
1928 if(strcasecmp(v1, v2) == 0) // early out check
1930 return vercmp_recursive(v1, v2);
1933 void ObserverThink()
1935 if (self.flags & FL_JUMPRELEASED) {
1936 if (self.BUTTON_JUMP && !self.version_mismatch) {
1937 self.welcomemessage_time = 0;
1938 self.flags = self.flags - FL_JUMPRELEASED;
1939 LeaveSpectatorMode();
1941 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
1942 self.welcomemessage_time = 0;
1943 self.flags = self.flags - FL_JUMPRELEASED;
1944 if(SpectateNext() == 1) {
1945 self.classname = "spectator";
1949 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
1950 self.flags = self.flags | FL_JUMPRELEASED;
1954 if(self.BUTTON_ZOOM)
1955 self.wantswelcomemessage = 0;
1957 if(self.wantswelcomemessage)
1958 PrintWelcomeMessage(self);
1961 void SpectatorThink()
1963 if (self.flags & FL_JUMPRELEASED) {
1964 if (self.BUTTON_JUMP && !self.version_mismatch) {
1965 self.welcomemessage_time = 0;
1966 self.flags = self.flags - FL_JUMPRELEASED;
1967 LeaveSpectatorMode();
1969 } else if(self.BUTTON_ATCK) {
1970 self.welcomemessage_time = 0;
1971 self.flags = self.flags - FL_JUMPRELEASED;
1972 if(SpectateNext() == 1) {
1973 self.classname = "spectator";
1975 self.classname = "observer";
1976 PutClientInServer();
1978 } else if (self.BUTTON_ATCK2) {
1979 self.welcomemessage_time = 0;
1980 self.flags = self.flags - FL_JUMPRELEASED;
1981 self.classname = "observer";
1982 PutClientInServer();
1984 if(!SpectateUpdate())
1985 PutObserverInServer();
1988 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
1989 self.flags = self.flags | FL_JUMPRELEASED;
1993 if(self.BUTTON_ZOOM)
1994 self.wantswelcomemessage = 0;
1996 if(self.wantswelcomemessage)
1997 PrintWelcomeMessage(self);
1998 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
2005 Called every frame for each client before the physics are run
2008 void() ctf_setstatus;
2009 .float spectatee_status;
2010 void PlayerPreThink (void)
2012 self.stat_sys_ticrate = cvar("sys_ticrate");
2013 self.stat_game_starttime = game_starttime;
2016 checkSpectatorBlock();
2020 if(self.netname_previous != self.netname)
2022 if(cvar("sv_eventlog"))
2023 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2024 if(self.netname_previous)
2025 strunzone(self.netname_previous);
2026 self.netname_previous = strzone(self.netname);
2030 if(self.version_nagtime)
2031 if(self.cvar_g_nexuizversion)
2032 if(time > self.version_nagtime)
2034 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2036 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2038 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");
2039 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"));
2044 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2047 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");
2048 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"));
2052 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");
2053 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2057 self.version_nagtime = 0;
2061 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2063 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2064 self.max_armorvalue = 0;
2070 antilag_record(self);
2073 if(self.classname == "player") {
2074 // if(self.netname == "Wazat")
2075 // bprint(self.classname, "\n");
2077 CheckRules_Player();
2079 if(self.BUTTON_INFO)
2080 PrintWelcomeMessage(self);
2082 if(g_lms || !cvar("sv_spectate"))
2083 if((time - self.jointime) <= cvar("welcome_message_time"))
2084 PrintWelcomeMessage(self);
2086 if (intermission_running)
2088 IntermissionThink (); // otherwise a button could be missed between
2089 return; // the think tics
2092 if(self.teleport_time)
2093 if(time > self.teleport_time)
2095 self.teleport_time = 0;
2096 self.effects = self.effects - (self.effects & EF_NODRAW);
2097 if(self.weaponentity)
2098 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
2101 Nixnex_GiveCurrentWeapon();
2103 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2104 UpdateSelectedPlayer();
2106 //don't allow the player to turn around while game is paused!
2107 if(timeoutStatus == 2) {
2108 self.v_angle = self.lastV_angle;
2109 self.angles = self.lastV_angle;
2110 self.fixangle = TRUE;
2113 if (self.deadflag != DEAD_NO)
2115 float button_pressed, force_respawn;
2117 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2118 force_respawn = (g_lms || cvar("g_forced_respawn"));
2119 if (self.deadflag == DEAD_DYING)
2122 self.deadflag = DEAD_RESPAWNING;
2123 else if(!button_pressed)
2124 self.deadflag = DEAD_DEAD;
2126 else if (self.deadflag == DEAD_DEAD)
2129 self.deadflag = DEAD_RESPAWNABLE;
2131 else if (self.deadflag == DEAD_RESPAWNABLE)
2134 self.deadflag = DEAD_RESPAWNING;
2136 else if (self.deadflag == DEAD_RESPAWNING)
2138 if(time > self.death_time)
2140 self.death_time = time + 1; // only retry once a second
2144 ShowRespawnCountdown();
2148 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2152 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2153 dist = self.oldorigin - self.origin;
2155 self.lms_traveled_distance += fabs(vlen(dist));
2157 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2159 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2160 self.lms_traveled_distance = 0;
2163 if(time > self.lms_nextcheck)
2165 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2166 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2168 centerprint(self, cvar_string("g_lms_campcheck_message"));
2169 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2170 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2171 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');
2173 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2174 self.lms_traveled_distance = 0;
2178 if (self.BUTTON_CROUCH && !self.hook.state)
2183 self.view_ofs = PL_CROUCH_VIEW_OFS;
2184 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2185 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
2192 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2193 if (!trace_startsolid)
2195 self.crouch = FALSE;
2196 self.view_ofs = PL_VIEW_OFS;
2197 setsize (self, PL_MIN, PL_MAX);
2204 GrapplingHookFrame();
2213 minstagib_ammocheck();
2218 //self.angles_y=self.v_angle_y + 90; // temp
2220 //if (TetrisPreFrame()) return;
2221 } else if(gameover) {
2222 if (intermission_running)
2223 IntermissionThink (); // otherwise a button could be missed between
2225 } else if(self.classname == "observer") {
2227 } else if(self.classname == "spectator") {
2232 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2234 float oldspectatee_status;
2235 oldspectatee_status = self.spectatee_status;
2236 if(self.classname == "spectator")
2237 self.spectatee_status = num_for_edict(self.enemy);
2238 else if(self.classname == "observer")
2239 self.spectatee_status = num_for_edict(self);
2241 self.spectatee_status = 0;
2242 if(self.spectatee_status != oldspectatee_status)
2245 WriteByte(MSG_ONE, SVC_TEMPENTITY);
2246 WriteByte(MSG_ONE, TE_CSQC_SPECTATING);
2247 WriteByte(MSG_ONE, self.spectatee_status);
2249 race_InitSpectator();
2252 if(self.teamkill_soundtime)
2253 if(time > self.teamkill_soundtime)
2255 self.teamkill_soundtime = 0;
2257 entity oldpusher, oldself;
2259 oldself = self; self = self.teamkill_soundsource;
2260 oldpusher = self.pusher; self.pusher = oldself;
2262 VoiceMessage("teamshoot_auto");
2264 self.pusher = oldpusher;
2268 target_voicescript_next(self);
2276 Called every frame for each client after the physics are run
2279 .float idlekick_lasttimeleft;
2280 .float race_penalty;
2281 .float race_penalty_nagged;
2282 .float race_penalty_nagtime;
2283 void PlayerPostThink (void)
2285 // Savage: Check for nameless players
2286 if (strlen(self.netname) < 1) {
2287 self.netname = "Player";
2288 stuffcmd(self, "seta _cl_name Player\n");
2294 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2297 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2298 announce(self, "announcer/robotic/terminated.wav");
2302 else if(timeleft <= 10)
2304 if(timeleft != self.idlekick_lasttimeleft)
2306 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2307 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2312 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2314 self.idlekick_lasttimeleft = timeleft;
2317 if(self.classname == "player") {
2318 CheckRules_Player();
2323 if (intermission_running)
2324 return; // intermission or finale
2326 //PrintWelcomeMessage(self);
2327 //if (TetrisPostFrame()) return;
2329 // restart countdown
2330 if(time < game_starttime) {
2331 if (!cvar("sv_ready_restart_after_countdown"))
2333 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2335 if(time < game_starttime - 2)
2337 if(!self.race_penalty_nagged)
2339 // TODO better notification for this!
2340 self.race_penalty_nagtime = 0;
2341 self.race_penalty_nagged = 1;
2344 else if(!self.race_penalty)
2346 self.race_penalty_nagtime = 0;
2347 self.race_penalty = time + 5;
2350 if(time > self.race_penalty_nagtime)
2352 if(self.race_penalty > time)
2354 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2356 else if(self.race_penalty_nagged && time < game_starttime - 2)
2358 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2360 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2362 self.movetype = MOVETYPE_NONE;
2363 self.velocity = '0 0 0';
2364 self.avelocity = '0 0 0';
2365 self.movement = '0 0 0';
2368 else if (time < self.race_penalty)
2370 self.movetype = MOVETYPE_NONE;
2371 self.velocity = '0 0 0';
2372 self.avelocity = '0 0 0';
2373 self.movement = '0 0 0';
2377 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2378 if (!cvar("sv_ready_restart_after_countdown"))
2380 if(self.movetype == MOVETYPE_NONE)
2382 self.movetype = MOVETYPE_WALK;
2384 self.race_penalty = 0;
2385 self.race_penalty_nagged = 0;
2389 } else if (self.classname == "observer") {
2391 } else if (self.classname == "spectator") {
2397 for(i = 0; i < 1000; ++i)
2400 end = self.origin + '0 0 1024' + 512 * randomvec();
2401 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2402 if(trace_fraction < 1)
2403 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2405 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2413 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);