1 .float wantswelcomemessage;
3 void info_player_survivor (void)
5 info_player_deathmatch();
8 void info_player_start (void)
10 info_player_deathmatch();
13 void info_player_deathmatch (void)
15 self.classname = "info_player_deathmatch";
16 relocate_spawnpoint();
19 void() spawnpoint_use =
24 self.team = activator.team;
25 some_spawn_has_been_used = 1;
31 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
33 local entity spot, player, nextspot, previousspot, newfirstspot;
42 nextspot = spot.chain;
43 // count team mismatches as bad spots
45 local float spotactive;
48 // filter out spots for assault
49 if(spot.target != "") {
51 ent = find(world, targetname, spot.target);
53 if(ent.classname == "target_objective")
54 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
56 ent = find(ent, targetname, spot.target);
60 if ((!teamcheck || spot.team == teamcheck) && spotactive > 0)
67 if (vlen(player.origin - spot.origin) < mindist)
69 player = player.chain;
75 previousspot.chain = spot;
82 spawn_allgood = FALSE;
86 // if we couldn't find ANY good points, return world
90 entity Spawn_RandomPoint(entity firstspot)
94 // count number of spots
99 numspots = numspots + 1;
103 numspots = numspots * random();
105 while (spot.chain && numspots >= 1)
107 numspots = numspots - 1;
113 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
115 local entity best, spot, player;
116 local float bestrating, rating;
118 bestrating = -1000000;
127 rating = min(rating, vlen(player.origin - spot.origin));
128 player = player.chain;
130 rating = rating + random() * 16;
131 if (bestrating < rating)
145 Finds a point to respawn
148 entity SelectSpawnPoint (float anypoint)
150 local float teamcheck;
151 local entity firstspot_new;
152 local entity spot, firstspot, playerlist;
154 spot = find (world, classname, "testplayerstart");
160 if(!anypoint && have_team_spawns)
161 teamcheck = self.team;
163 // get the list of players
164 playerlist = findchain(classname, "player");
165 // get the entire list of spots
166 firstspot = findchain(classname, "info_player_deathmatch");
167 // filter out the bad ones
168 // (note this returns the original list if none survived)
169 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
171 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
172 firstspot = firstspot_new;
174 // there is 50/50 chance of choosing a random spot or the furthest spot
175 // (this means that roughly every other spawn will be furthest, so you
176 // usually won't get fragged at spawn twice in a row)
177 if (arena_roundbased)
179 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
181 firstspot = firstspot_new;
182 spot = Spawn_RandomPoint(firstspot);
184 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
185 spot = Spawn_RandomPoint(firstspot);
187 spot = Spawn_FurthestPoint(firstspot, playerlist);
191 if(cvar("spawn_debug"))
195 if(some_spawn_has_been_used)
196 return world; // team can't spawn any more, because of actions of other team
198 error("Cannot find a spawn point - please fix the map!");
209 Checks if the argument string can be a valid playermodel.
210 Returns a valid one in doubt.
213 string FallbackPlayerModel = "models/player/marine.zym";
214 string CheckPlayerModel(string plyermodel) {
215 if(strlen(plyermodel) < 4)
216 return FallbackPlayerModel;
217 if( substring(plyermodel,0,14) != "models/player/")
218 return FallbackPlayerModel;
219 else if(cvar("sv_servermodelsonly"))
221 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
222 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
223 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
224 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
225 return FallbackPlayerModel;
226 if(!fexists(plyermodel))
227 return FallbackPlayerModel;
234 Client_customizeentityforclient
239 float Client_customizeentityforclient()
241 #ifdef ALLOW_VARIABLE_LOD
243 // other: the player viewing me
247 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
250 if(other.cvar_cl_playerdetailreduction <= 0)
252 if(other.cvar_cl_playerdetailreduction <= -2)
253 self.modelindex = self.modelindex_lod2;
254 else if(other.cvar_cl_playerdetailreduction <= -1)
255 self.modelindex = self.modelindex_lod1;
257 self.modelindex = self.modelindex_lod0;
261 distance = vlen(self.origin - other.origin);
262 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
264 self.modelindex = self.modelindex_lod2;
266 self.modelindex = self.modelindex_lod1;
268 self.modelindex = self.modelindex_lod0;
275 void UpdatePlayerSounds();
276 void setmodel_lod(entity e, string modelname)
278 #ifdef ALLOW_VARIABLE_LOD
281 // FIXME: this only supports 3-letter extensions
282 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
286 setmodel(e, s); // players have high precision
287 self.modelindex_lod1 = self.modelindex;
290 self.modelindex_lod1 = -1;
292 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
296 setmodel(e, s); // players have high precision
297 self.modelindex_lod2 = self.modelindex;
300 self.modelindex_lod2 = -1;
302 precache_model(modelname);
303 setmodel(e, modelname); // players have high precision
304 self.modelindex_lod0 = self.modelindex;
306 if(self.modelindex_lod1 < 0)
307 self.modelindex_lod1 = self.modelindex;
309 if(self.modelindex_lod2 < 0)
310 self.modelindex_lod2 = self.modelindex;
312 precache_model(modelname);
313 setmodel(e, modelname); // players have high precision
315 player_setupanimsformodel();
316 UpdatePlayerSounds();
323 putting a client as observer in the server
326 void PutObserverInServer (void)
329 spot = SelectSpawnPoint (TRUE);
331 error("No spawnpoints for observers?!?\n");
332 RemoveGrapplingHook(self); // Wazat's Grappling Hook
334 if(clienttype(self) == CLIENTTYPE_REAL)
337 WriteByte(MSG_ONE, SVC_SETVIEW);
338 WriteEntity(MSG_ONE, self);
342 kh_Key_DropAll(self, TRUE);
345 DropFlag(self.flagcarried);
347 WaypointSprite_PlayerDead();
349 DistributeFragsAmongTeam(self, self.team, 1);
351 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
352 bprint ("^4", self.netname, "^4 has no more lives left\n");
353 else if(self.killcount != -666)
354 bprint ("^4", self.netname, "^4 is spectating now\n");
356 self.classname = "observer";
358 self.takedamage = DAMAGE_NO;
359 self.solid = SOLID_NOT;
360 self.movetype = MOVETYPE_NOCLIP;
361 self.flags = FL_CLIENT | FL_NOTARGET;
362 self.armorvalue = 666;
364 self.armorvalue = cvar("g_balance_armor_start");
365 self.pauserotarmor_finished = 0;
366 self.pauserothealth_finished = 0;
367 self.pauseregen_finished = 0;
368 self.damageforcescale = 0;
376 self.pain_finished = 0;
377 self.strength_finished = 0;
378 self.invincible_finished = 0;
380 self.think = SUB_Null;
384 self.deadflag = DEAD_NO;
385 self.angles = spot.angles;
387 self.fixangle = TRUE;
390 self.view_ofs = PL_VIEW_OFS;
391 setorigin (self, spot.origin);
392 setsize (self, '0 0 0', '0 0 0');
393 self.oldorigin = self.origin;
398 self.weaponmodel = "";
399 self.weaponentity = world;
400 self.killcount = -666;
401 self.velocity = '0 0 0';
402 self.avelocity = '0 0 0';
403 self.punchangle = '0 0 0';
404 self.punchvector = '0 0 0';
405 self.oldvelocity = self.velocity;
406 self.customizeentityforclient = Client_customizeentityforclient;
408 self.wantswelcomemessage = 1;
414 Spawnqueue_Insert(self);
418 Spawnqueue_Unmark(self);
419 Spawnqueue_Remove(self);
426 float RestrictSkin(float s)
435 void FixPlayermodel()
437 local string defaultmodel;
438 local float defaultskin;
443 if(cvar("sv_defaultcharacter") == 1) {
448 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
449 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
452 if(defaultmodel == "")
454 defaultmodel = cvar_string("sv_defaultplayermodel");
455 defaultskin = cvar("sv_defaultplayerskin");
459 if(defaultmodel != "")
461 if (defaultmodel != self.model)
465 setmodel_lod (self, defaultmodel);
466 setsize (self, m1, m2);
469 self.skin = defaultskin;
471 if (self.playermodel != self.model)
473 self.playermodel = CheckPlayerModel(self.playermodel);
476 setmodel_lod (self, self.playermodel);
477 setsize (self, m1, m2);
480 self.skin = RestrictSkin(stof(self.playerskin));
484 if(strlen(cvar_string("sv_defaultplayercolors")))
485 if(self.clientcolors != cvar("sv_defaultplayercolors"))
486 setcolor(self, cvar("sv_defaultplayercolors"));
493 Called when a client spawns in the server
496 void PutClientInServer (void)
498 if(clienttype(self) == CLIENTTYPE_BOT)
500 self.classname = "player";
502 else if(clienttype(self) == CLIENTTYPE_REAL)
505 WriteByte(MSG_ONE, SVC_SETVIEW);
506 WriteEntity(MSG_ONE, self);
509 // player is dead and becomes observer
510 if(g_lms && self.frags < 1)
511 self.classname = "observer";
515 self.classname = "observer";
517 if(self.classname == "player") {
520 spot = SelectSpawnPoint (FALSE);
523 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
524 return; // spawn failed
527 RemoveGrapplingHook(self); // Wazat's Grappling Hook
529 self.classname = "player";
530 self.iscreature = TRUE;
531 self.movetype = MOVETYPE_WALK;
532 self.solid = SOLID_SLIDEBOX;
533 self.flags = FL_CLIENT;
534 self.takedamage = DAMAGE_AIM;
536 self.effects = EF_FULLBRIGHT;
539 self.air_finished = time + 12;
542 self.ammo_shells = start_ammo_shells;
543 self.ammo_nails = start_ammo_nails;
544 self.ammo_rockets = start_ammo_rockets;
545 self.ammo_cells = start_ammo_cells;
546 self.health = start_health;
547 self.armorvalue = start_armorvalue;
548 self.items = start_items;
549 self.switchweapon = start_switchweapon;
550 self.cnt = start_switchweapon;
552 self.jump_interval = time;
554 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
555 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
556 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
557 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
558 self.damageforcescale = 2;
565 self.pain_finished = 0;
566 self.strength_finished = 0;
567 self.invincible_finished = 0;
569 //self.speed_finished = 0;
570 //self.slowmo_finished = 0;
571 // players have no think function
572 self.think = SUB_Null;
578 self.deadflag = DEAD_NO;
580 self.angles = spot.angles;
582 self.angles_z = 0; // never spawn tilted even if the spot says to
583 self.fixangle = TRUE; // turn this way immediately
584 self.velocity = '0 0 0';
585 self.avelocity = '0 0 0';
586 self.punchangle = '0 0 0';
587 self.punchvector = '0 0 0';
588 self.oldvelocity = self.velocity;
593 self.customizeentityforclient = Client_customizeentityforclient;
599 self.view_ofs = PL_VIEW_OFS;
600 setsize (self, PL_MIN, PL_MAX);
601 self.spawnorigin = spot.origin;
602 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
603 // don't reset back to last position, even if new position is stuck in solid
604 self.oldorigin = self.origin;
608 Spawnqueue_Remove(self);
609 Spawnqueue_Mark(self);
612 self.event_damage = PlayerDamage;
614 self.bot_attack = TRUE;
616 self.statdraintime = time + 5;
617 self.button0 = self.button1 = self.button2 = self.button3 = 0;
619 if(self.killcount == -666) {
626 self.cnt = WEP_LASER;
627 self.nixnex_lastchange_id = -1;
629 CL_SpawnWeaponentity();
630 self.alpha = default_player_alpha;
631 self.colormod = '1 1 1' * cvar("g_player_brightness");
632 self.exteriorweaponentity.alpha = default_weapon_alpha;
634 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
635 self.lms_traveled_distance = 0;
636 self.speedrunning = FALSE;
638 if(cvar("spawn_debug"))
640 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
641 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
644 //stuffcmd(self, "chase_active 0");
645 //stuffcmd(self, "set viewsize $tmpviewsize \n");
647 if (cvar("g_spawnsound"))
648 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
651 if(self.team == assault_attacker_team)
652 centerprint(self, "You are attacking!\n");
654 centerprint(self, "You are defending!\n");
657 } else if(self.classname == "observer") {
658 PutObserverInServer ();
667 void SetNewParms (void)
677 void SetChangeParms (void)
686 Called when a client types 'kill' in the console
690 void ClientKill_Now_TeamChange()
692 if(self.killindicator_teamchange == -1)
695 JoinBestTeam( self, FALSE, FALSE );
699 SV_ChangeTeam(self.killindicator_teamchange - 1);
703 void ClientKill_Now()
705 if(self.killindicator_teamchange)
706 ClientKill_Now_TeamChange();
709 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
711 void KillIndicator_Think()
713 if (!self.owner.modelindex)
715 self.owner.killindicator = world;
723 ClientKill_Now(); // no oldself needed
730 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
731 play2(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".ogg"));
733 if(self.owner.killindicator_teamchange)
735 if(self.owner.killindicator_teamchange == -1)
736 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
738 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
741 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
742 self.nextthink = time + 1;
747 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
750 killtime = cvar("g_balance_kill_delay");
752 self.killindicator_teamchange = targetteam;
754 if(!self.killindicator)
756 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
762 self.killindicator = spawn();
763 self.killindicator.owner = self;
764 self.killindicator.scale = 0.5;
765 setattachment(self.killindicator, self, "");
766 setorigin(self.killindicator, '0 0 52');
767 self.killindicator.think = KillIndicator_Think;
768 self.killindicator.nextthink = time;
769 self.killindicator.cnt = ceil(killtime);
770 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
773 if(self.killindicator)
776 self.killindicator.colormod = TeamColor(targetteam);
778 self.killindicator.colormod = '0 0 0';
782 void ClientKill (void)
784 ClientKill_TeamChange(0);
787 void DoTeamChange(float destteam)
789 if(!cvar("teamplay"))
792 SetPlayerColors(self, destteam);
795 if(destteam == self.team && !self.killindicator)
797 ClientKill_TeamChange(destteam);
800 void FixClientCvars(entity e)
802 // send prediction settings to the client
803 stuffcmd(e, "\nin_bindmap 0 0\n");
805 * we no longer need to stuff this. Remove this comment block if you feel
806 * 2.3 and higher (or was it 2.2.3?) don't need these any more
807 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
808 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
809 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
810 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
811 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
812 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
813 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
814 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
815 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
816 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
817 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
818 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
819 stuffcmd(e, "cl_movement_edgefriction 1\n");
827 Called when a client connects to the server
830 string ColoredTeamName(float t);
831 //void dom_player_join_team(entity pl);
832 void ClientConnect (void)
837 if(Ban_IsClientBanned(self))
839 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
845 self.classname = "player_joining";
846 self.flags = self.flags | FL_CLIENT;
847 self.version_nagtime = time + 10 + random() * 10;
851 dprint("BUG player count is lower than zero, this cannot happen!\n");
858 // dom_player_join_team(self);
860 //JoinBestTeam(self, FALSE, FALSE);
862 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
863 self.classname = "observer";
865 self.classname = "player";
866 campaign_bots_may_start = 1;
869 self.playerid = (playerid_last = playerid_last + 1);
870 if(cvar("sv_eventlog"))
872 if(clienttype(self) == CLIENTTYPE_REAL)
876 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
877 s = strcat(":team:", ftos(self.playerid), ":");
878 s = strcat(s, ftos(self.team));
879 GameLogEcho(s, FALSE);
882 //stuffcmd(self, "set tmpviewsize $viewsize \n");
884 bprint ("^4",self.netname);
885 bprint ("^4 connected");
887 if(g_domination || g_ctf)
889 bprint(" and joined the ");
890 bprint(ColoredTeamName(self.team));
895 self.welcomemessage_time = 0;
897 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
898 // TODO: is this being used for anything else than cd tracks?
899 // Remember: SVC_CDTRACK exists. Maybe it should be used.
901 stuffcmd(self, "cl_particles_reloadeffects\n");
903 FixClientCvars(self);
906 WaypointSprite_InitClient(self);
908 // Wazat's grappling hook
909 SetGrappleHookBindings();
911 // get autoswitch state from player when he toggles it
912 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
914 // get version info from player
915 stuffcmd(self, "cmd clientversion $gameversion\n");
917 // send all weapon info strings
918 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
920 while (wep <= WEP_LAST)
922 weapon_action(wep, WR_REGISTER);
926 // get other cvars from player
929 // set cvar for team scoreboard
933 t = cvar("teamplay");
934 // 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
935 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
938 stuffcmd(self, "set teamplay 0\n");
940 // notify about available teams
943 CheckAllowedTeams(self);
944 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
945 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
948 stuffcmd(self, "set _teams_available 0\n");
950 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
954 self.frags = LMS_NewPlayerLives();
960 self.classname = "observer";
961 Spawnqueue_Insert(self);
964 bot_relinkplayerlist();
966 self.jointime = time;
973 Called when a client disconnects from the server
976 void(entity e) DropFlag;
977 .entity chatbubbleentity;
978 .entity teambubbleentity;
979 void ClientDisconnect (void)
982 if(cvar("sv_eventlog"))
983 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
984 bprint ("^4",self.netname);
985 bprint ("^4 disconnected\n");
987 if (self.chatbubbleentity)
989 remove (self.chatbubbleentity);
990 self.chatbubbleentity = world;
993 if (self.teambubbleentity)
995 remove (self.teambubbleentity);
996 self.teambubbleentity = world;
999 if (self.killindicator)
1001 remove (self.killindicator);
1002 self.killindicator = world;
1005 WaypointSprite_PlayerGone();
1008 kh_Key_DropAll(self, TRUE);
1010 if(self.flagcarried)
1011 DropFlag(self.flagcarried);
1013 DistributeFragsAmongTeam(self, self.team, 1);
1016 self.flags = self.flags - (self.flags & FL_CLIENT);
1017 bot_relinkplayerlist();
1021 if(self.weaponentity)
1022 if(self.weaponentity.lasertarget)
1023 remove(self.weaponentity.lasertarget);
1027 Spawnqueue_Unmark(self);
1028 Spawnqueue_Remove(self);
1036 void() ChatBubbleThink =
1038 self.nextthink = time;
1039 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1041 self.owner.chatbubbleentity = world;
1045 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
1046 if (self.owner.buttonchat && !self.owner.deadflag)
1047 self.model = self.mdl;
1052 void() UpdateChatBubble =
1054 if (!self.modelindex)
1056 // spawn a chatbubble entity if needed
1057 if (!self.chatbubbleentity)
1059 self.chatbubbleentity = spawn();
1060 self.chatbubbleentity.owner = self;
1061 self.chatbubbleentity.exteriormodeltoclient = self;
1062 self.chatbubbleentity.think = ChatBubbleThink;
1063 self.chatbubbleentity.nextthink = time;
1064 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1065 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1066 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1067 self.chatbubbleentity.model = "";
1068 self.chatbubbleentity.effects = EF_LOWPRECISION;
1073 void() TeamBubbleThink =
1075 self.nextthink = time;
1076 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1078 self.owner.teambubbleentity = world;
1082 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1083 if (self.owner.buttonchat || self.owner.deadflag || self.owner.killindicator)
1086 self.model = self.mdl;
1090 float() TeamBubble_customizeentityforclient
1092 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1095 void() UpdateTeamBubble =
1097 if (!self.modelindex || !cvar("teamplay"))
1099 // spawn a teambubble entity if needed
1100 if (!self.teambubbleentity && cvar("teamplay"))
1102 self.teambubbleentity = spawn();
1103 self.teambubbleentity.owner = self;
1104 self.teambubbleentity.exteriormodeltoclient = self;
1105 self.teambubbleentity.think = TeamBubbleThink;
1106 self.teambubbleentity.nextthink = time;
1107 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1108 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1109 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
1110 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1111 self.teambubbleentity.mdl = self.teambubbleentity.model;
1112 self.teambubbleentity.model = self.teambubbleentity.mdl;
1113 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1114 self.teambubbleentity.effects = EF_LOWPRECISION;
1118 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1119 // added to the model skins
1120 /*void() UpdateColorModHack =
1123 c = self.clientcolors & 15;
1124 // LordHavoc: only bothering to support white, green, red, yellow, blue
1125 if (teamplay == 0) self.colormod = '0 0 0';
1126 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1127 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1128 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1129 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1130 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1131 else self.colormod = '1 1 1';
1137 self.effects |= EF_NODRAW; // prevent another CopyBody
1138 PutClientInServer();
1141 void player_powerups (void)
1145 if (self.items & IT_STRENGTH)
1147 if (time > self.strength_finished)
1149 if (g_minstagib_invis_alpha > 0)
1151 self.alpha = default_player_alpha;
1152 self.exteriorweaponentity.alpha = default_weapon_alpha;
1153 self.effects = self.effects | EF_FULLBRIGHT;
1157 self.effects -= self.effects & EF_NODRAW;
1159 self.items = self.items - (self.items & IT_STRENGTH);
1160 sprint(self, "^3Invisibility has worn off\n");
1165 if (time < self.strength_finished)
1167 if (g_minstagib_invis_alpha > 0)
1169 self.alpha = g_minstagib_invis_alpha;
1170 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1171 self.effects -= self.effects & EF_FULLBRIGHT;
1175 self.effects = self.effects | EF_NODRAW;
1177 self.items = self.items | IT_STRENGTH;
1178 sprint(self, "^3You are invisible\n");
1182 if (self.items & IT_INVINCIBLE)
1184 if (time > self.invincible_finished)
1186 self.items = self.items - (self.items & IT_INVINCIBLE);
1187 sprint(self, "^3Speed has worn off\n");
1192 if (time < self.invincible_finished)
1194 self.items = self.items | IT_INVINCIBLE;
1195 sprint(self, "^3You are on speed\n");
1201 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1202 if (self.items & IT_STRENGTH)
1204 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1205 if (time > self.strength_finished)
1207 self.items = self.items - (self.items & IT_STRENGTH);
1208 sprint(self, "^3Strength has worn off\n");
1213 if (time < self.strength_finished)
1215 self.items = self.items | IT_STRENGTH;
1216 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1219 if (self.items & IT_INVINCIBLE)
1221 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1222 if (time > self.invincible_finished)
1224 self.items = self.items - (self.items & IT_INVINCIBLE);
1225 sprint(self, "^3Shield has worn off\n");
1230 if (time < self.invincible_finished)
1232 self.items = self.items | IT_INVINCIBLE;
1233 sprint(self, "^3Shield surrounds you\n");
1237 if (cvar("g_fullbrightplayers"))
1238 self.effects = self.effects | EF_FULLBRIGHT;
1240 // midair gamemode: damage only while in the air
1241 // if in midair mode, being on ground grants temporary invulnerability
1242 // (this is so that multishot weapon don't clear the ground flag on the
1243 // first damage in the frame, leaving the player vulnerable to the
1244 // remaining hits in the same frame)
1245 if (self.flags & FL_ONGROUND)
1247 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1249 if (time < self.spawnshieldtime)
1250 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1253 float CalcRegen(float current, float stable, float regenfactor)
1255 if(current > stable)
1257 else if(current > stable - 0.25) // when close enough, "snap"
1260 return min(stable, current + (stable - current) * regenfactor * frametime);
1263 void player_regen (void)
1265 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1266 maxh = cvar("g_balance_health_stable");
1267 maxa = cvar("g_balance_armor_stable");
1268 limith = cvar("g_balance_health_limit");
1269 limita = cvar("g_balance_armor_limit");
1271 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1274 max_mod = regen_mod = rot_mod = limit_mod = 1;
1276 if (self.runes & RUNE_REGEN)
1278 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1280 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1281 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1282 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1286 regen_mod = cvar("g_balance_rune_regen_regenrate");
1287 max_mod = cvar("g_balance_rune_regen_hpmod");
1288 limit_mod = cvar("g_balance_rune_regen_limitmod");
1291 else if (self.runes & CURSE_VENOM)
1293 max_mod = cvar("g_balance_curse_venom_hpmod");
1294 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1295 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1297 rot_mod = cvar("g_balance_curse_venom_rotrate");
1298 limit_mod = cvar("g_balance_curse_venom_limitmod");
1299 //if (!self.runes & RUNE_REGEN)
1300 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1302 maxh = maxh * max_mod;
1303 //maxa = maxa * max_mod;
1304 limith = limith * limit_mod;
1305 limita = limita * limit_mod;
1307 if (self.armorvalue > maxa)
1309 if (time > self.pauserotarmor_finished)
1311 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1312 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1315 else if (self.armorvalue < maxa)
1317 if (time > self.pauseregen_finished)
1319 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1320 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1323 if (self.health > maxh)
1325 if (time > self.pauserothealth_finished)
1327 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1328 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1331 else if (self.health < maxh)
1333 if (time > self.pauseregen_finished)
1335 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1336 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1340 if (self.health > limith)
1341 self.health = limith;
1342 if (self.armorvalue > limita)
1343 self.armorvalue = limita;
1345 // if player rotted to death... die!
1347 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1351 ======================
1352 spectate mode routines
1353 ======================
1355 void SpectateCopy(entity spectatee) {
1356 self.armortype = spectatee.armortype;
1357 self.armorvalue = spectatee.armorvalue;
1358 self.currentammo = spectatee.currentammo;
1359 self.effects = spectatee.effects;
1360 self.health = spectatee.health;
1362 self.items = spectatee.items;
1363 self.punchangle = spectatee.punchangle;
1364 self.view_ofs = spectatee.view_ofs;
1365 self.v_angle = spectatee.v_angle;
1366 self.viewzoom = spectatee.viewzoom;
1367 self.velocity = spectatee.velocity;
1368 self.dmg_take = spectatee.dmg_take;
1369 self.dmg_save = spectatee.dmg_save;
1370 self.dmg_inflictor = spectatee.dmg_inflictor;
1371 self.angles = spectatee.v_angle;
1372 self.fixangle = TRUE;
1373 setorigin(self, spectatee.origin);
1374 setsize(self, spectatee.mins, spectatee.maxs);
1377 void SpectateUpdate() {
1379 PutObserverInServer();
1381 if (self != self.enemy) {
1382 if(self.enemy.flags & FL_NOTARGET)
1383 PutObserverInServer();
1384 SpectateCopy(self.enemy);
1385 //msg_entity = self;
1386 //WriteByte(MSG_ONE, SVC_SETANGLE);
1387 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1388 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1389 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1393 float SpectateNext() {
1394 other = find(self.enemy, classname, "player");
1396 other = find(other, classname, "player");
1401 if(self.enemy.classname == "player") {
1403 WriteByte(MSG_ONE, SVC_SETVIEW);
1404 WriteEntity(MSG_ONE, self.enemy);
1405 self.wantswelcomemessage = 1;
1406 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1416 ShowRespawnCountdown()
1418 Update a respawn countdown display.
1421 void ShowRespawnCountdown()
1424 if(self.deadflag == DEAD_NO) // just respawned?
1428 number = ceil(self.death_time - time);
1431 if(number <= self.respawn_countdown)
1433 self.respawn_countdown = number - 1;
1434 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
1435 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1440 void LeaveSpectatorMode()
1442 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1443 self.classname = "player";
1444 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1445 JoinBestTeam(self, FALSE, TRUE);
1446 if(cvar("g_campaign"))
1447 campaign_bots_may_start = 1;
1448 PutClientInServer();
1449 if(!(self.flags & FL_NOTARGET))
1450 bprint ("^4", self.netname, "^4 is playing now\n");
1451 centerprint(self,"");
1454 stuffcmd(self,"menu_showteamselect\n");
1463 Called every frame for each client before the physics are run
1466 void() ctf_setstatus;
1467 .float vote_nagtime;
1468 void PlayerPreThink (void)
1471 if(self.version_nagtime)
1472 if(self.cvar_g_nexuizversion)
1473 if(time > self.version_nagtime)
1475 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1476 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1478 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n");
1479 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1481 self.version_nagtime = 0;
1485 if(self.cvar_scr_centertime)
1486 if(time > self.vote_nagtime)
1489 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1493 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1495 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1496 self.max_armorvalue = 0;
1500 antilag_record(self);
1502 if(self.classname == "player") {
1503 // if(self.netname == "Wazat")
1504 // bprint(self.classname, "\n");
1506 CheckRules_Player();
1509 PrintWelcomeMessage(self);
1511 if(g_lms || !cvar("sv_spectate"))
1512 if((time - self.jointime) <= cvar("welcome_message_time"))
1513 PrintWelcomeMessage(self);
1515 if (intermission_running)
1517 IntermissionThink (); // otherwise a button could be missed between
1518 return; // the think tics
1521 if(self.teleport_time)
1522 if(time > self.teleport_time)
1524 self.teleport_time = 0;
1525 self.effects = self.effects - (self.effects & EF_NODRAW);
1526 if(self.weaponentity)
1527 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1530 Nixnex_GiveCurrentWeapon();
1532 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1533 UpdateSelectedPlayer();
1535 if (self.deadflag != DEAD_NO)
1537 float button_pressed, force_respawn;
1539 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1540 force_respawn = (g_lms || cvar("g_forced_respawn"));
1541 if (self.deadflag == DEAD_DYING)
1544 self.deadflag = DEAD_RESPAWNING;
1545 else if(!button_pressed)
1546 self.deadflag = DEAD_DEAD;
1548 else if (self.deadflag == DEAD_DEAD)
1551 self.deadflag = DEAD_RESPAWNABLE;
1553 else if (self.deadflag == DEAD_RESPAWNABLE)
1556 self.deadflag = DEAD_RESPAWNING;
1558 else if (self.deadflag == DEAD_RESPAWNING)
1560 if(time > self.death_time)
1562 self.death_time = time + 1; // only retry once a second
1566 ShowRespawnCountdown();
1570 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1574 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1575 dist = self.oldorigin - self.origin;
1577 self.lms_traveled_distance += fabs(vlen(dist));
1579 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1581 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1582 self.lms_traveled_distance = 0;
1585 if(time > self.lms_nextcheck)
1587 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1588 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1590 centerprint(self, cvar_string("g_lms_campcheck_message"));
1591 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1592 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1593 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');
1595 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1596 self.lms_traveled_distance = 0;
1600 if (self.button5 && !self.hook.state)
1605 self.view_ofs = PL_CROUCH_VIEW_OFS;
1606 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1607 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1614 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1615 if (!trace_startsolid)
1617 self.crouch = FALSE;
1618 self.view_ofs = PL_VIEW_OFS;
1619 setsize (self, PL_MIN, PL_MAX);
1626 GrapplingHookFrame();
1631 float zoomfactor, zoomspeed, zoomdir;
1632 zoomfactor = self.cvar_cl_zoomfactor;
1633 if(zoomfactor < 1 || zoomfactor > 16)
1635 zoomspeed = self.cvar_cl_zoomspeed;
1636 if(zoomspeed >= 0) // < 0 is instant zoom
1637 if(zoomspeed < 0.5 || zoomspeed > 16)
1640 zoomdir = self.button4;
1642 if(self.weapon == WEP_NEX)
1647 self.has_zoomed = 1;
1651 if(zoomspeed <= 0) // instant zoom
1654 self.viewzoom = 1 / zoomfactor;
1660 // geometric zoom would be:
1661 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1662 // however, testing showed that arithmetic/harmonic zoom works better
1664 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1665 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1666 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1668 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1669 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1670 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1674 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1682 minstagib_ammocheck();
1687 //self.angles_y=self.v_angle_y + 90; // temp
1689 //if (TetrisPreFrame()) return;
1690 } else if(gameover) {
1691 if (intermission_running)
1692 IntermissionThink (); // otherwise a button could be missed between
1694 } else if(self.classname == "observer") {
1695 if (self.flags & FL_JUMPRELEASED) {
1696 if (self.button2 && self.version == cvar("gameversion")) {
1697 self.welcomemessage_time = 0;
1698 self.flags = self.flags - FL_JUMPRELEASED;
1699 LeaveSpectatorMode();
1701 } else if(self.button0 && self.version == cvar("gameversion")) {
1702 self.welcomemessage_time = 0;
1703 self.flags = self.flags - FL_JUMPRELEASED;
1704 if(SpectateNext() == 1) {
1705 self.classname = "spectator";
1709 if (!(self.button0 || self.button2)) {
1710 self.flags = self.flags | FL_JUMPRELEASED;
1714 self.wantswelcomemessage = 0;
1715 if(self.wantswelcomemessage)
1716 PrintWelcomeMessage(self);
1717 } else if(self.classname == "spectator") {
1718 if (self.flags & FL_JUMPRELEASED) {
1719 if (self.button2 && self.version == cvar("gameversion")) {
1720 self.welcomemessage_time = 0;
1721 self.flags = self.flags - FL_JUMPRELEASED;
1722 LeaveSpectatorMode();
1724 } else if(self.button0) {
1725 self.welcomemessage_time = 0;
1726 self.flags = self.flags - FL_JUMPRELEASED;
1727 if(SpectateNext() == 1) {
1728 self.classname = "spectator";
1730 self.classname = "observer";
1731 PutClientInServer();
1733 } else if (self.button3) {
1734 self.welcomemessage_time = 0;
1735 self.flags = self.flags - FL_JUMPRELEASED;
1736 self.classname = "observer";
1737 PutClientInServer();
1742 if (!(self.button0 || self.button3)) {
1743 self.flags = self.flags | FL_JUMPRELEASED;
1747 self.wantswelcomemessage = 0;
1748 if(self.wantswelcomemessage)
1749 PrintWelcomeMessage(self);
1750 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1759 Called every frame for each client after the physics are run
1762 void PlayerPostThink (void)
1764 // Savage: Check for nameless players
1765 if (strlen(self.netname) < 1) {
1766 self.netname = "Player";
1767 stuffcmd(self, "seta _cl_name Player\n");
1770 if(self.classname == "player") {
1771 CheckRules_Player();
1776 if (intermission_running)
1777 return; // intermission or finale
1779 //PrintWelcomeMessage(self);
1780 //if (TetrisPostFrame()) return;
1782 // restart countdown
1783 if(time < restart_countdown)
1788 sec = ceil(restart_countdown-time);
1789 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1790 centerprint(self, s);
1791 self.movetype = MOVETYPE_NONE;
1792 self.velocity = '0 0 0';
1793 self.avelocity = '0 0 0';
1794 self.movement = '0 0 0';
1796 else if(self.movetype == MOVETYPE_NONE)
1798 self.movetype = MOVETYPE_WALK;
1799 centerprint(self, "\n");
1801 } else if (self.classname == "observer") {
1803 } else if (self.classname == "spectator") {