1 void info_player_survivor (void)
3 info_player_deathmatch();
6 void info_player_start (void)
8 info_player_deathmatch();
11 void info_player_deathmatch (void)
13 self.classname = "info_player_deathmatch";
14 relocate_spawnpoint();
17 void() spawnpoint_use =
22 self.team = activator.team;
23 some_spawn_has_been_used = 1;
29 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
31 local entity spot, player, nextspot, previousspot, newfirstspot;
40 nextspot = spot.chain;
41 // count team mismatches as bad spots
43 local float spotactive;
46 // filter out spots for assault
47 if(spot.target != "") {
49 ent = find(world, targetname, spot.target);
51 if(ent.classname == "target_objective")
52 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
54 ent = find(ent, targetname, spot.target);
58 if ((!teamcheck || spot.team == teamcheck) && spotactive > 0)
65 if (vlen(player.origin - spot.origin) < mindist)
67 player = player.chain;
73 previousspot.chain = spot;
80 spawn_allgood = FALSE;
84 // if we couldn't find ANY good points, return world
88 entity Spawn_RandomPoint(entity firstspot)
92 // count number of spots
97 numspots = numspots + 1;
101 numspots = numspots * random();
103 while (spot.chain && numspots >= 1)
105 numspots = numspots - 1;
111 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
113 local entity best, spot, player;
114 local float bestrating, rating;
116 bestrating = -1000000;
125 rating = min(rating, vlen(player.origin - spot.origin));
126 player = player.chain;
128 rating = rating + random() * 16;
129 if (bestrating < rating)
143 Finds a point to respawn
146 entity SelectSpawnPoint (float anypoint)
148 local float teamcheck;
149 local entity firstspot_new;
150 local entity spot, firstspot, playerlist;
152 spot = find (world, classname, "testplayerstart");
158 if(!anypoint && have_team_spawns)
159 teamcheck = self.team;
161 // get the list of players
162 playerlist = findchain(classname, "player");
163 // get the entire list of spots
164 firstspot = findchain(classname, "info_player_deathmatch");
165 // filter out the bad ones
166 // (note this returns the original list if none survived)
167 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
169 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
170 firstspot = firstspot_new;
172 // there is 50/50 chance of choosing a random spot or the furthest spot
173 // (this means that roughly every other spawn will be furthest, so you
174 // usually won't get fragged at spawn twice in a row)
175 if (arena_roundbased)
177 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
179 firstspot = firstspot_new;
180 spot = Spawn_RandomPoint(firstspot);
182 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
183 spot = Spawn_RandomPoint(firstspot);
185 spot = Spawn_FurthestPoint(firstspot, playerlist);
189 if(cvar("spawn_debug"))
193 if(some_spawn_has_been_used)
194 return world; // team can't spawn any more, because of actions of other team
196 error("Cannot find a spawn point - please fix the map!");
207 Checks if the argument string can be a valid playermodel.
208 Returns a valid one in doubt.
211 string FallbackPlayerModel = "models/player/marine.zym";
212 string CheckPlayerModel(string plyermodel) {
213 if(strlen(plyermodel) < 4)
214 return FallbackPlayerModel;
215 if( substring(plyermodel,0,14) != "models/player/")
216 return FallbackPlayerModel;
217 else if(cvar("sv_servermodelsonly"))
219 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
220 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
221 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
222 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
223 return FallbackPlayerModel;
224 if(!fexists(plyermodel))
225 return FallbackPlayerModel;
232 Client_customizeentityforclient
237 float Client_customizeentityforclient()
239 #ifdef ALLOW_VARIABLE_LOD
241 // other: the player viewing me
245 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
248 if(other.cvar_cl_playerdetailreduction <= 0)
250 if(other.cvar_cl_playerdetailreduction <= -2)
251 self.modelindex = self.modelindex_lod2;
252 else if(other.cvar_cl_playerdetailreduction <= -1)
253 self.modelindex = self.modelindex_lod1;
255 self.modelindex = self.modelindex_lod0;
259 distance = vlen(self.origin - other.origin);
260 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
262 self.modelindex = self.modelindex_lod2;
264 self.modelindex = self.modelindex_lod1;
266 self.modelindex = self.modelindex_lod0;
273 void UpdatePlayerSounds();
274 void setmodel_lod(entity e, string modelname)
276 #ifdef ALLOW_VARIABLE_LOD
279 // FIXME: this only supports 3-letter extensions
280 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
284 setmodel(e, s); // players have high precision
285 self.modelindex_lod1 = self.modelindex;
288 self.modelindex_lod1 = -1;
290 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
294 setmodel(e, s); // players have high precision
295 self.modelindex_lod2 = self.modelindex;
298 self.modelindex_lod2 = -1;
300 precache_model(modelname);
301 setmodel(e, modelname); // players have high precision
302 self.modelindex_lod0 = self.modelindex;
304 if(self.modelindex_lod1 < 0)
305 self.modelindex_lod1 = self.modelindex;
307 if(self.modelindex_lod2 < 0)
308 self.modelindex_lod2 = self.modelindex;
310 precache_model(modelname);
311 setmodel(e, modelname); // players have high precision
313 player_setupanimsformodel();
314 UpdatePlayerSounds();
321 putting a client as observer in the server
324 void PutObserverInServer (void)
327 spot = SelectSpawnPoint (TRUE);
329 error("No spawnpoints for observers?!?\n");
330 RemoveGrapplingHook(self); // Wazat's Grappling Hook
332 if(clienttype(self) == CLIENTTYPE_REAL)
335 WriteByte(MSG_ONE, SVC_SETVIEW);
336 WriteEntity(MSG_ONE, self);
340 kh_Key_DropAll(self, TRUE);
343 DropFlag(self.flagcarried);
345 WaypointSprite_PlayerDead();
347 DistributeFragsAmongTeam(self, self.team, 1);
349 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
350 bprint ("^4", self.netname, "^4 has no more lives left\n");
351 else if(self.killcount != -666)
352 bprint ("^4", self.netname, "^4 is spectating now\n");
354 self.classname = "observer";
356 self.takedamage = DAMAGE_NO;
357 self.solid = SOLID_NOT;
358 self.movetype = MOVETYPE_NOCLIP;
359 self.flags = FL_CLIENT | FL_NOTARGET;
360 self.armorvalue = 666;
362 self.armorvalue = cvar("g_balance_armor_start");
363 self.pauserotarmor_finished = 0;
364 self.pauserothealth_finished = 0;
365 self.pauseregen_finished = 0;
366 self.damageforcescale = 0;
374 self.pain_finished = 0;
375 self.strength_finished = 0;
376 self.invincible_finished = 0;
378 self.think = SUB_Null;
382 self.deadflag = DEAD_NO;
383 self.angles = spot.angles;
385 self.fixangle = TRUE;
388 self.view_ofs = PL_VIEW_OFS;
389 setorigin (self, spot.origin);
390 setsize (self, '0 0 0', '0 0 0');
391 self.oldorigin = self.origin;
396 self.weaponmodel = "";
397 self.weaponentity = world;
398 self.killcount = -666;
399 self.velocity = '0 0 0';
400 self.avelocity = '0 0 0';
401 self.punchangle = '0 0 0';
402 self.punchvector = '0 0 0';
403 self.oldvelocity = self.velocity;
404 self.customizeentityforclient = Client_customizeentityforclient;
411 Spawnqueue_Insert(self);
415 Spawnqueue_Unmark(self);
416 Spawnqueue_Remove(self);
423 float RestrictSkin(float s)
432 void FixPlayermodel()
434 local string defaultmodel;
435 local float defaultskin;
438 if(cvar("sv_defaultcharacter") == 1) {
444 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
445 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
448 if(defaultmodel == "")
450 defaultmodel = cvar_string("sv_defaultplayermodel");
451 defaultskin = cvar("sv_defaultplayerskin");
454 if (defaultmodel != self.model)
458 setmodel_lod (self, defaultmodel);
459 setsize (self, m1, m2);
462 self.skin = defaultskin;
464 if (self.playermodel != self.model)
466 self.playermodel = CheckPlayerModel(self.playermodel);
469 setmodel_lod (self, self.playermodel);
470 setsize (self, m1, m2);
473 self.skin = RestrictSkin(stof(self.playerskin));
477 if(strlen(cvar_string("sv_defaultplayercolors")))
478 if(self.clientcolors != cvar("sv_defaultplayercolors"))
479 setcolor(self, cvar("sv_defaultplayercolors"));
486 Called when a client spawns in the server
489 void PutClientInServer (void)
491 if(clienttype(self) == CLIENTTYPE_BOT)
493 self.classname = "player";
495 else if(clienttype(self) == CLIENTTYPE_REAL)
498 WriteByte(MSG_ONE, SVC_SETVIEW);
499 WriteEntity(MSG_ONE, self);
502 // player is dead and becomes observer
503 if(g_lms && self.frags < 1)
504 self.classname = "observer";
508 self.classname = "observer";
510 if(self.classname == "player") {
513 spot = SelectSpawnPoint (FALSE);
516 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
517 return; // spawn failed
520 RemoveGrapplingHook(self); // Wazat's Grappling Hook
522 self.classname = "player";
523 self.iscreature = TRUE;
524 self.movetype = MOVETYPE_WALK;
525 self.solid = SOLID_SLIDEBOX;
526 self.flags = FL_CLIENT;
527 self.takedamage = DAMAGE_AIM;
529 self.effects = EF_FULLBRIGHT;
532 self.air_finished = time + 12;
535 self.ammo_shells = start_ammo_shells;
536 self.ammo_nails = start_ammo_nails;
537 self.ammo_rockets = start_ammo_rockets;
538 self.ammo_cells = start_ammo_cells;
539 self.health = start_health;
540 self.armorvalue = start_armorvalue;
541 self.items = start_items;
542 self.switchweapon = start_switchweapon;
544 self.jump_interval = time;
546 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
547 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
548 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
549 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
550 self.damageforcescale = 2;
557 self.pain_finished = 0;
558 self.strength_finished = 0;
559 self.invincible_finished = 0;
561 //self.speed_finished = 0;
562 //self.slowmo_finished = 0;
563 // players have no think function
564 self.think = SUB_Null;
570 self.deadflag = DEAD_NO;
572 self.angles = spot.angles;
574 self.angles_z = 0; // never spawn tilted even if the spot says to
575 self.fixangle = TRUE; // turn this way immediately
576 self.velocity = '0 0 0';
577 self.avelocity = '0 0 0';
578 self.punchangle = '0 0 0';
579 self.punchvector = '0 0 0';
580 self.oldvelocity = self.velocity;
585 self.customizeentityforclient = Client_customizeentityforclient;
591 self.view_ofs = PL_VIEW_OFS;
592 setsize (self, PL_MIN, PL_MAX);
593 self.spawnorigin = spot.origin;
594 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
595 // don't reset back to last position, even if new position is stuck in solid
596 self.oldorigin = self.origin;
600 Spawnqueue_Remove(self);
601 Spawnqueue_Mark(self);
604 self.event_damage = PlayerDamage;
606 self.bot_attack = TRUE;
608 self.statdraintime = time + 5;
609 self.button0 = self.button1 = self.button2 = self.button3 = 0;
611 if(self.killcount == -666) {
618 self.cnt = WEP_LASER;
619 self.nixnex_lastchange_id = -1;
621 CL_SpawnWeaponentity();
622 self.alpha = default_player_alpha;
623 self.colormod = '1 1 1' * cvar("g_player_brightness");
624 self.exteriorweaponentity.alpha = default_weapon_alpha;
626 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
627 self.lms_traveled_distance = 0;
628 self.speedrunning = FALSE;
630 if(cvar("spawn_debug"))
632 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
633 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
636 //stuffcmd(self, "chase_active 0");
637 //stuffcmd(self, "set viewsize $tmpviewsize \n");
639 if (cvar("g_spawnsound"))
640 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
643 if(self.team == assault_attacker_team)
644 centerprint(self, "You are attacking!\n");
646 centerprint(self, "You are defending!\n");
649 } else if(self.classname == "observer") {
650 PutObserverInServer ();
659 void SetNewParms (void)
669 void SetChangeParms (void)
678 Called when a client types 'kill' in the console
681 void ClientKill (void)
683 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
686 void FixClientCvars(entity e)
689 // send prediction settings to the client
690 stuffcmd(e, "\nin_bindmap 0 0\n");
691 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
692 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
693 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
694 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
695 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
696 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
697 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
698 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
699 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
700 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
701 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
702 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
703 stuffcmd(e, "cl_movement_edgefriction 1\n");
705 // notify about available teams
708 CheckAllowedTeams(e);
709 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
710 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
713 stuffcmd(e, "set _teams_available 0\n");
720 Called when a client connects to the server
723 string ColoredTeamName(float t);
724 //void dom_player_join_team(entity pl);
725 void ClientConnect (void)
730 if(Ban_IsClientBanned(self))
732 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
738 self.classname = "player_joining";
739 self.flags = self.flags | FL_CLIENT;
740 self.version_nagtime = time + 10 + random() * 10;
744 dprint("BUG player count is lower than zero, this cannot happen!\n");
751 // dom_player_join_team(self);
753 //JoinBestTeam(self, FALSE);
755 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
756 self.classname = "observer";
758 self.classname = "player";
759 campaign_bots_may_start = 1;
762 self.playerid = (playerid_last = playerid_last + 1);
763 if(cvar("sv_eventlog"))
765 if(clienttype(self) == CLIENTTYPE_REAL)
769 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
770 s = strcat(":team:", ftos(self.playerid), ":");
771 s = strcat(s, ftos(self.team));
772 GameLogEcho(s, FALSE);
775 //stuffcmd(self, "set tmpviewsize $viewsize \n");
777 bprint ("^4",self.netname);
778 bprint ("^4 connected");
780 if(g_domination || g_ctf)
782 bprint(" and joined the ");
783 bprint(ColoredTeamName(self.team));
788 self.welcomemessage_time = 0;
790 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
791 // TODO: is this being used for anything else than cd tracks?
792 // Remember: SVC_CDTRACK exists. Maybe it should be used.
794 FixClientCvars(self);
797 WaypointSprite_InitClient(self);
799 // Wazat's grappling hook
800 SetGrappleHookBindings();
802 // get autoswitch state from player when he toggles it
803 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
805 // get version info from player
806 stuffcmd(self, "cmd clientversion $gameversion\n");
808 // send all weapon info strings
809 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
811 while (wep <= WEP_LAST)
813 weapon_action(wep, WR_REGISTER);
817 // get other cvars from player
820 // set cvar for team scoreboard
824 t = cvar("teamplay");
825 // 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
826 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
829 stuffcmd(self, "set teamplay 0\n");
833 self.frags = LMS_NewPlayerLives();
839 self.classname = "observer";
840 Spawnqueue_Insert(self);
843 bot_relinkplayerlist();
845 self.jointime = time;
852 Called when a client disconnects from the server
855 void(entity e) DropFlag;
856 .entity chatbubbleentity;
857 .entity teambubbleentity;
858 void ClientDisconnect (void)
861 if(cvar("sv_eventlog"))
862 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
863 bprint ("^4",self.netname);
864 bprint ("^4 disconnected\n");
866 if (self.chatbubbleentity)
868 remove (self.chatbubbleentity);
869 self.chatbubbleentity = world;
872 if (self.teambubbleentity)
874 remove (self.teambubbleentity);
875 self.teambubbleentity = world;
878 WaypointSprite_PlayerGone();
881 kh_Key_DropAll(self, TRUE);
884 DropFlag(self.flagcarried);
886 DistributeFragsAmongTeam(self, self.team, 1);
889 self.flags = self.flags - (self.flags & FL_CLIENT);
890 bot_relinkplayerlist();
894 if(self.weaponentity)
895 if(self.weaponentity.lasertarget)
896 remove(self.weaponentity.lasertarget);
900 Spawnqueue_Unmark(self);
901 Spawnqueue_Remove(self);
909 void() ChatBubbleThink =
911 self.nextthink = time;
912 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
914 self.owner.chatbubbleentity = world;
918 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
919 if (self.owner.buttonchat && !self.owner.deadflag)
920 self.model = self.mdl;
925 void() UpdateChatBubble =
927 if (!self.modelindex)
929 // spawn a chatbubble entity if needed
930 if (!self.chatbubbleentity)
932 self.chatbubbleentity = spawn();
933 self.chatbubbleentity.owner = self;
934 self.chatbubbleentity.exteriormodeltoclient = self;
935 self.chatbubbleentity.think = ChatBubbleThink;
936 self.chatbubbleentity.nextthink = time;
937 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
938 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
939 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
940 self.chatbubbleentity.model = "";
941 self.chatbubbleentity.effects = EF_LOWPRECISION;
946 void() TeamBubbleThink =
948 self.nextthink = time;
949 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
951 self.owner.teambubbleentity = world;
955 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
956 if (self.owner.buttonchat || self.owner.deadflag)
959 self.model = self.mdl;
963 float() TeamBubble_customizeentityforclient
965 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
968 void() UpdateTeamBubble =
970 if (!self.modelindex || !cvar("teamplay"))
972 // spawn a teambubble entity if needed
973 if (!self.teambubbleentity && cvar("teamplay"))
975 self.teambubbleentity = spawn();
976 self.teambubbleentity.owner = self;
977 self.teambubbleentity.exteriormodeltoclient = self;
978 self.teambubbleentity.think = TeamBubbleThink;
979 self.teambubbleentity.nextthink = time;
980 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
981 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
982 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
983 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
984 self.teambubbleentity.mdl = self.teambubbleentity.model;
985 self.teambubbleentity.model = self.teambubbleentity.mdl;
986 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
987 self.teambubbleentity.effects = EF_LOWPRECISION;
991 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
992 // added to the model skins
993 /*void() UpdateColorModHack =
996 c = self.clientcolors & 15;
997 // LordHavoc: only bothering to support white, green, red, yellow, blue
998 if (teamplay == 0) self.colormod = '0 0 0';
999 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1000 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1001 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1002 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1003 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1004 else self.colormod = '1 1 1';
1010 self.effects |= EF_NODRAW; // prevent another CopyBody
1011 PutClientInServer();
1014 void player_powerups (void)
1018 if (self.items & IT_STRENGTH)
1020 if (time > self.strength_finished)
1022 if (g_minstagib_invis_alpha > 0)
1024 self.alpha = default_player_alpha;
1025 self.exteriorweaponentity.alpha = default_weapon_alpha;
1026 self.effects = self.effects | EF_FULLBRIGHT;
1030 self.effects -= self.effects & EF_NODRAW;
1032 self.items = self.items - (self.items & IT_STRENGTH);
1033 sprint(self, "^3Invisibility has worn off\n");
1038 if (time < self.strength_finished)
1040 if (g_minstagib_invis_alpha > 0)
1042 self.alpha = g_minstagib_invis_alpha;
1043 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1044 self.effects -= self.effects & EF_FULLBRIGHT;
1048 self.effects = self.effects | EF_NODRAW;
1050 self.items = self.items | IT_STRENGTH;
1051 sprint(self, "^3You are invisible\n");
1055 if (self.items & IT_INVINCIBLE)
1057 if (time > self.invincible_finished)
1059 self.items = self.items - (self.items & IT_INVINCIBLE);
1060 sprint(self, "^3Speed has worn off\n");
1065 if (time < self.invincible_finished)
1067 self.items = self.items | IT_INVINCIBLE;
1068 sprint(self, "^3You are on speed\n");
1074 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1075 if (self.items & IT_STRENGTH)
1077 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1078 if (time > self.strength_finished)
1080 self.items = self.items - (self.items & IT_STRENGTH);
1081 sprint(self, "^3Strength has worn off\n");
1086 if (time < self.strength_finished)
1088 self.items = self.items | IT_STRENGTH;
1089 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1092 if (self.items & IT_INVINCIBLE)
1094 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1095 if (time > self.invincible_finished)
1097 self.items = self.items - (self.items & IT_INVINCIBLE);
1098 sprint(self, "^3Shield has worn off\n");
1103 if (time < self.invincible_finished)
1105 self.items = self.items | IT_INVINCIBLE;
1106 sprint(self, "^3Shield surrounds you\n");
1110 if (cvar("g_fullbrightplayers"))
1111 self.effects = self.effects | EF_FULLBRIGHT;
1113 // midair gamemode: damage only while in the air
1114 // if in midair mode, being on ground grants temporary invulnerability
1115 // (this is so that multishot weapon don't clear the ground flag on the
1116 // first damage in the frame, leaving the player vulnerable to the
1117 // remaining hits in the same frame)
1118 if (self.flags & FL_ONGROUND)
1120 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1122 if (time < self.spawnshieldtime)
1123 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1126 float CalcRegen(float current, float stable, float regenfactor)
1128 if(current > stable)
1130 else if(current > stable - 0.25) // when close enough, "snap"
1133 return min(stable, current + (stable - current) * regenfactor * frametime);
1136 void player_regen (void)
1138 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1139 maxh = cvar("g_balance_health_stable");
1140 maxa = cvar("g_balance_armor_stable");
1141 limith = cvar("g_balance_health_limit");
1142 limita = cvar("g_balance_armor_limit");
1144 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1147 max_mod = regen_mod = rot_mod = limit_mod = 1;
1149 if (self.runes & RUNE_REGEN)
1151 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1153 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1154 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1155 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1159 regen_mod = cvar("g_balance_rune_regen_regenrate");
1160 max_mod = cvar("g_balance_rune_regen_hpmod");
1161 limit_mod = cvar("g_balance_rune_regen_limitmod");
1164 else if (self.runes & CURSE_VENOM)
1166 max_mod = cvar("g_balance_curse_venom_hpmod");
1167 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1168 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1170 rot_mod = cvar("g_balance_curse_venom_rotrate");
1171 limit_mod = cvar("g_balance_curse_venom_limitmod");
1172 //if (!self.runes & RUNE_REGEN)
1173 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1175 maxh = maxh * max_mod;
1176 //maxa = maxa * max_mod;
1177 limith = limith * limit_mod;
1178 limita = limita * limit_mod;
1180 if (self.armorvalue > maxa)
1182 if (time > self.pauserotarmor_finished)
1184 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1185 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1188 else if (self.armorvalue < maxa)
1190 if (time > self.pauseregen_finished)
1192 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1193 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1196 if (self.health > maxh)
1198 if (time > self.pauserothealth_finished)
1200 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1201 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1204 else if (self.health < maxh)
1206 if (time > self.pauseregen_finished)
1208 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1209 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1213 if (self.health > limith)
1214 self.health = limith;
1215 if (self.armorvalue > limita)
1216 self.armorvalue = limita;
1218 // if player rotted to death... die!
1220 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1224 ======================
1225 spectate mode routines
1226 ======================
1228 void SpectateCopy(entity spectatee) {
1229 self.armortype = spectatee.armortype;
1230 self.armorvalue = spectatee.armorvalue;
1231 self.currentammo = spectatee.currentammo;
1232 self.effects = spectatee.effects;
1233 self.health = spectatee.health;
1235 self.items = spectatee.items;
1236 self.punchangle = spectatee.punchangle;
1237 self.view_ofs = spectatee.view_ofs;
1238 self.v_angle = spectatee.v_angle;
1239 self.viewzoom = spectatee.viewzoom;
1240 self.velocity = spectatee.velocity;
1241 self.dmg_take = spectatee.dmg_take;
1242 self.dmg_save = spectatee.dmg_save;
1243 self.dmg_inflictor = spectatee.dmg_inflictor;
1244 self.angles = spectatee.v_angle;
1245 self.fixangle = TRUE;
1246 setorigin(self, spectatee.origin);
1247 setsize(self, spectatee.mins, spectatee.maxs);
1250 void SpectateUpdate() {
1252 PutObserverInServer();
1254 if (self != self.enemy) {
1255 if(self.enemy.flags & FL_NOTARGET)
1256 PutObserverInServer();
1257 SpectateCopy(self.enemy);
1258 //msg_entity = self;
1259 //WriteByte(MSG_ONE, SVC_SETANGLE);
1260 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1261 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1262 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1266 float SpectateNext() {
1267 other = find(self.enemy, classname, "player");
1269 other = find(other, classname, "player");
1274 if(self.enemy.classname == "player") {
1276 WriteByte(MSG_ONE, SVC_SETVIEW);
1277 WriteEntity(MSG_ONE, self.enemy);
1278 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1288 ShowRespawnCountdown()
1290 Update a respawn countdown display.
1293 void ShowRespawnCountdown()
1296 if(self.deadflag == DEAD_NO) // just respawned?
1300 number = ceil(self.death_time - time);
1303 if(number <= self.respawn_countdown)
1305 self.respawn_countdown = number - 1;
1306 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
1307 play2(self, strcat("announcer/robotic/", ftos(number), "announcer/.ogg"));
1312 void LeaveSpectatorMode()
1314 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1315 self.classname = "player";
1316 if(cvar("g_campaign") || cvar("g_balance_teams"))
1317 JoinBestTeam(self, 0);
1318 if(cvar("g_campaign"))
1319 campaign_bots_may_start = 1;
1320 PutClientInServer();
1321 if(!(self.flags & FL_NOTARGET))
1322 bprint ("^4", self.netname, "^4 is playing now\n");
1323 centerprint(self,"");
1326 stuffcmd(self,"menu_showteamselect\n");
1335 Called every frame for each client before the physics are run
1338 void() ctf_setstatus;
1339 .float vote_nagtime;
1340 void PlayerPreThink (void)
1343 if(self.version_nagtime)
1344 if(self.cvar_g_nexuizversion)
1345 if(time > self.version_nagtime)
1347 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1348 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1350 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");
1351 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1353 self.version_nagtime = 0;
1357 if(self.cvar_scr_centertime)
1358 if(time > self.vote_nagtime)
1361 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1365 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1367 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1368 self.max_armorvalue = 0;
1372 antilag_record(self);
1374 if(self.classname == "player") {
1375 // if(self.netname == "Wazat")
1376 // bprint(self.classname, "\n");
1378 CheckRules_Player();
1381 PrintWelcomeMessage(self);
1383 if(g_lms || !cvar("sv_spectate"))
1384 if((time - self.jointime) <= cvar("welcome_message_time"))
1385 PrintWelcomeMessage(self);
1387 if (intermission_running)
1389 IntermissionThink (); // otherwise a button could be missed between
1390 return; // the think tics
1393 if(self.teleport_time)
1394 if(time > self.teleport_time)
1396 self.teleport_time = 0;
1397 self.effects = self.effects - (self.effects & EF_NODRAW);
1398 if(self.weaponentity)
1399 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1402 Nixnex_GiveCurrentWeapon();
1404 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1405 UpdateSelectedPlayer();
1407 if (self.deadflag != DEAD_NO)
1409 float button_pressed, force_respawn;
1411 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1412 force_respawn = (g_lms || cvar("g_forced_respawn"));
1413 if (self.deadflag == DEAD_DYING)
1416 self.deadflag = DEAD_RESPAWNING;
1417 else if(!button_pressed)
1418 self.deadflag = DEAD_DEAD;
1420 else if (self.deadflag == DEAD_DEAD)
1423 self.deadflag = DEAD_RESPAWNABLE;
1425 else if (self.deadflag == DEAD_RESPAWNABLE)
1428 self.deadflag = DEAD_RESPAWNING;
1430 else if (self.deadflag == DEAD_RESPAWNING)
1432 if(time > self.death_time)
1434 self.death_time = time + 1; // only retry once a second
1438 ShowRespawnCountdown();
1442 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1446 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1447 dist = self.oldorigin - self.origin;
1449 self.lms_traveled_distance += fabs(vlen(dist));
1451 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1453 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1454 self.lms_traveled_distance = 0;
1457 if(time > self.lms_nextcheck)
1459 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1460 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1462 centerprint(self, cvar_string("g_lms_campcheck_message"));
1463 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1464 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1465 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');
1467 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1468 self.lms_traveled_distance = 0;
1472 if (self.button5 && !self.hook.state)
1477 self.view_ofs = PL_CROUCH_VIEW_OFS;
1478 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1479 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1486 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1487 if (!trace_startsolid)
1489 self.crouch = FALSE;
1490 self.view_ofs = PL_VIEW_OFS;
1491 setsize (self, PL_MIN, PL_MAX);
1498 GrapplingHookFrame();
1503 float zoomfactor, zoomspeed, zoomdir;
1504 zoomfactor = self.cvar_cl_zoomfactor;
1505 if(zoomfactor < 1 || zoomfactor > 16)
1507 zoomspeed = self.cvar_cl_zoomspeed;
1508 if(zoomspeed >= 0) // < 0 is instant zoom
1509 if(zoomspeed < 0.5 || zoomspeed > 16)
1512 zoomdir = self.button4;
1514 if(self.weapon == WEP_NEX)
1519 self.has_zoomed = 1;
1523 if(zoomspeed <= 0) // instant zoom
1526 self.viewzoom = 1 / zoomfactor;
1532 // geometric zoom would be:
1533 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1534 // however, testing showed that arithmetic/harmonic zoom works better
1536 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1537 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1538 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1540 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1541 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1542 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1546 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1554 minstagib_ammocheck();
1559 //self.angles_y=self.v_angle_y + 90; // temp
1561 //if (TetrisPreFrame()) return;
1562 } else if(gameover) {
1563 if (intermission_running)
1564 IntermissionThink (); // otherwise a button could be missed between
1566 } else if(self.classname == "observer") {
1568 if (self.flags & FL_JUMPRELEASED) {
1569 if (self.button2 && self.version == cvar("gameversion")) {
1570 self.welcomemessage_time = 0;
1571 self.flags = self.flags - FL_JUMPRELEASED;
1572 LeaveSpectatorMode();
1574 } else if(self.button0 && self.version == cvar("gameversion")) {
1575 self.welcomemessage_time = 0;
1576 self.flags = self.flags - FL_JUMPRELEASED;
1577 if(SpectateNext() == 1) {
1578 self.classname = "spectator";
1582 if (!(self.button0 || self.button2)) {
1583 self.flags = self.flags | FL_JUMPRELEASED;
1586 PrintWelcomeMessage(self);
1587 } else if(self.classname == "spectator") {
1588 if (self.flags & FL_JUMPRELEASED) {
1589 if (self.button2 && self.version == cvar("gameversion")) {
1590 self.welcomemessage_time = 0;
1591 self.flags = self.flags - FL_JUMPRELEASED;
1592 LeaveSpectatorMode();
1594 } else if(self.button0) {
1595 self.welcomemessage_time = 0;
1596 self.flags = self.flags - FL_JUMPRELEASED;
1597 if(SpectateNext() == 1) {
1598 self.classname = "spectator";
1600 self.classname = "observer";
1601 PutClientInServer();
1603 } else if (self.button3) {
1604 self.welcomemessage_time = 0;
1605 self.flags = self.flags - FL_JUMPRELEASED;
1606 self.classname = "observer";
1607 PutClientInServer();
1612 if (!(self.button0 || self.button3)) {
1613 self.flags = self.flags | FL_JUMPRELEASED;
1616 PrintWelcomeMessage(self);
1617 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1626 Called every frame for each client after the physics are run
1629 void PlayerPostThink (void)
1631 // Savage: Check for nameless players
1632 if (strlen(self.netname) < 1) {
1633 self.netname = "Player";
1634 stuffcmd(self, "seta _cl_name Player\n");
1637 if(self.classname == "player") {
1638 CheckRules_Player();
1643 if (intermission_running)
1644 return; // intermission or finale
1646 //PrintWelcomeMessage(self);
1647 //if (TetrisPostFrame()) return;
1649 // restart countdown
1650 if(time < restart_countdown)
1655 sec = ceil(restart_countdown-time);
1656 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1657 centerprint(self, s);
1658 self.movetype = MOVETYPE_NONE;
1659 self.velocity = '0 0 0';
1660 self.avelocity = '0 0 0';
1661 self.movement = '0 0 0';
1663 else if(self.movetype == MOVETYPE_NONE)
1665 self.movetype = MOVETYPE_WALK;
1666 centerprint(self, "\n");
1668 } else if (self.classname == "observer") {
1670 } else if (self.classname == "spectator") {