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 float some_spawn_has_been_used;
18 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 (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 the original list
86 newfirstspot = firstspot;
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 spot, firstspot, playerlist;
153 spot = find (world, classname, "testplayerstart");
159 if(!anypoint && (g_ctf || g_assault || g_onslaught))
160 teamcheck = self.team;
162 // get the list of players
163 playerlist = findchain(classname, "player");
164 // get the entire list of spots
165 firstspot = findchain(classname, "info_player_deathmatch");
166 // filter out the bad ones
167 // (note this returns the original list if none survived)
168 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
170 // there is 50/50 chance of choosing a random spot or the furthest spot
171 // (this means that roughly every other spawn will be furthest, so you
172 // usually won't get fragged at spawn twice in a row)
173 if (arena_roundbased)
175 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
176 spot = Spawn_RandomPoint(firstspot);
178 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
179 spot = Spawn_RandomPoint(firstspot);
181 spot = Spawn_FurthestPoint(firstspot, playerlist);
185 if(cvar("spawn_debug"))
189 if(some_spawn_has_been_used)
190 return world; // team can't spawn any more, because of actions of other team
192 error("Cannot find a spawn point - please fix the map!");
203 Checks if the argument string can be a valid playermodel.
204 Returns a valid one in doubt.
207 string FallbackPlayerModel = "models/player/marine.zym";
208 string CheckPlayerModel(string plyermodel) {
209 if(strlen(plyermodel) < 4)
210 return FallbackPlayerModel;
211 if( substring(plyermodel,0,14) != "models/player/")
212 return FallbackPlayerModel;
213 else if(cvar("sv_servermodelsonly"))
215 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
216 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
217 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
218 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
219 return FallbackPlayerModel;
220 if(!fexists(plyermodel))
221 return FallbackPlayerModel;
228 Client_customizeentityforclient
233 float Client_customizeentityforclient()
235 #ifdef ALLOW_VARIABLE_LOD
237 // other: the player viewing me
241 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
244 if(other.cvar_cl_playerdetailreduction <= 0)
246 if(other.cvar_cl_playerdetailreduction <= -2)
247 self.modelindex = self.modelindex_lod2;
248 else if(other.cvar_cl_playerdetailreduction <= -1)
249 self.modelindex = self.modelindex_lod1;
251 self.modelindex = self.modelindex_lod0;
255 distance = vlen(self.origin - other.origin);
256 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
258 self.modelindex = self.modelindex_lod2;
260 self.modelindex = self.modelindex_lod1;
262 self.modelindex = self.modelindex_lod0;
269 void UpdatePlayerSounds();
270 void setmodel_lod(entity e, string modelname)
272 #ifdef ALLOW_VARIABLE_LOD
275 // FIXME: this only supports 3-letter extensions
276 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
280 setmodel(e, s); // players have high precision
281 self.modelindex_lod1 = self.modelindex;
284 self.modelindex_lod1 = -1;
286 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
290 setmodel(e, s); // players have high precision
291 self.modelindex_lod2 = self.modelindex;
294 self.modelindex_lod2 = -1;
296 precache_model(modelname);
297 setmodel(e, modelname); // players have high precision
298 self.modelindex_lod0 = self.modelindex;
300 if(self.modelindex_lod1 < 0)
301 self.modelindex_lod1 = self.modelindex;
303 if(self.modelindex_lod2 < 0)
304 self.modelindex_lod2 = self.modelindex;
306 precache_model(modelname);
307 setmodel(e, modelname); // players have high precision
309 player_setupanimsformodel();
310 UpdatePlayerSounds();
317 putting a client as observer in the server
320 void PutObserverInServer (void)
323 spot = SelectSpawnPoint (TRUE);
325 error("No spawnpoints for observers?!?\n");
326 RemoveGrapplingHook(self); // Wazat's Grappling Hook
328 if(clienttype(self) == CLIENTTYPE_REAL)
331 WriteByte(MSG_ONE, SVC_SETVIEW);
332 WriteEntity(MSG_ONE, self);
336 kh_Key_DropAll(self, TRUE);
339 DropFlag(self.flagcarried);
341 WaypointSprite_PlayerDead();
343 DistributeFragsAmongTeam(self, self.team, 1);
345 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
346 bprint ("^4", self.netname, "^4 has no more lives left\n");
347 else if(self.killcount != -666)
348 bprint ("^4", self.netname, "^4 is spectating now\n");
350 self.classname = "observer";
352 self.takedamage = DAMAGE_NO;
353 self.solid = SOLID_NOT;
354 self.movetype = MOVETYPE_NOCLIP;
355 self.flags = FL_CLIENT | FL_NOTARGET;
356 self.armorvalue = 666;
358 self.armorvalue = cvar("g_balance_armor_start");
359 self.pauserotarmor_finished = 0;
360 self.pauserothealth_finished = 0;
361 self.pauseregen_finished = 0;
362 self.damageforcescale = 0;
370 self.pain_finished = 0;
371 self.strength_finished = 0;
372 self.invincible_finished = 0;
374 self.think = SUB_Null;
378 self.deadflag = DEAD_NO;
379 self.angles = spot.angles;
381 self.fixangle = TRUE;
384 self.view_ofs = PL_VIEW_OFS;
385 setorigin (self, spot.origin);
386 setsize (self, '0 0 0', '0 0 0');
387 self.oldorigin = self.origin;
392 self.weaponmodel = "";
393 self.weaponentity = world;
394 self.killcount = -666;
395 self.velocity = '0 0 0';
396 self.avelocity = '0 0 0';
397 self.punchangle = '0 0 0';
398 self.punchvector = '0 0 0';
399 self.oldvelocity = self.velocity;
400 self.customizeentityforclient = Client_customizeentityforclient;
407 Spawnqueue_Insert(self);
411 Spawnqueue_Unmark(self);
412 Spawnqueue_Remove(self);
419 float RestrictSkin(float s)
428 void FixPlayermodel()
430 local string defaultmodel;
431 local float defaultskin;
434 if(cvar("sv_defaultcharacter") == 1) {
440 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
441 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
444 if(defaultmodel == "")
446 defaultmodel = cvar_string("sv_defaultplayermodel");
447 defaultskin = cvar("sv_defaultplayerskin");
450 if (defaultmodel != self.model)
454 setmodel_lod (self, defaultmodel);
455 setsize (self, m1, m2);
458 self.skin = defaultskin;
460 if (self.playermodel != self.model)
462 self.playermodel = CheckPlayerModel(self.playermodel);
465 setmodel_lod (self, self.playermodel);
466 setsize (self, m1, m2);
469 self.skin = RestrictSkin(stof(self.playerskin));
473 if(strlen(cvar_string("sv_defaultplayercolors")))
474 if(self.clientcolors != cvar("sv_defaultplayercolors"))
475 setcolor(self, cvar("sv_defaultplayercolors"));
482 Called when a client spawns in the server
485 void PutClientInServer (void)
487 if(clienttype(self) == CLIENTTYPE_BOT)
489 self.classname = "player";
491 else if(clienttype(self) == CLIENTTYPE_REAL)
494 WriteByte(MSG_ONE, SVC_SETVIEW);
495 WriteEntity(MSG_ONE, self);
498 // player is dead and becomes observer
499 if(g_lms && self.frags < 1)
500 self.classname = "observer";
504 self.classname = "observer";
506 if(self.classname == "player") {
509 spot = SelectSpawnPoint (FALSE);
512 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
513 return; // spawn failed
516 RemoveGrapplingHook(self); // Wazat's Grappling Hook
518 self.classname = "player";
519 self.iscreature = TRUE;
520 self.movetype = MOVETYPE_WALK;
521 self.solid = SOLID_SLIDEBOX;
522 self.flags = FL_CLIENT;
523 self.takedamage = DAMAGE_AIM;
525 self.effects = EF_FULLBRIGHT;
528 self.air_finished = time + 12;
531 self.ammo_shells = start_ammo_shells;
532 self.ammo_nails = start_ammo_nails;
533 self.ammo_rockets = start_ammo_rockets;
534 self.ammo_cells = start_ammo_cells;
535 self.health = start_health;
536 self.armorvalue = start_armorvalue;
537 self.items = start_items;
538 self.switchweapon = start_switchweapon;
540 self.jump_interval = time;
542 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
543 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
544 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
545 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
546 self.damageforcescale = 2;
553 self.pain_finished = 0;
554 self.strength_finished = 0;
555 self.invincible_finished = 0;
557 //self.speed_finished = 0;
558 //self.slowmo_finished = 0;
559 // players have no think function
560 self.think = SUB_Null;
566 self.deadflag = DEAD_NO;
568 self.angles = spot.angles;
570 self.angles_z = 0; // never spawn tilted even if the spot says to
571 self.fixangle = TRUE; // turn this way immediately
572 self.velocity = '0 0 0';
573 self.avelocity = '0 0 0';
574 self.punchangle = '0 0 0';
575 self.punchvector = '0 0 0';
576 self.oldvelocity = self.velocity;
581 self.customizeentityforclient = Client_customizeentityforclient;
587 self.view_ofs = PL_VIEW_OFS;
588 setsize (self, PL_MIN, PL_MAX);
589 self.spawnorigin = spot.origin;
590 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
591 // don't reset back to last position, even if new position is stuck in solid
592 self.oldorigin = self.origin;
596 Spawnqueue_Remove(self);
597 Spawnqueue_Mark(self);
600 self.event_damage = PlayerDamage;
602 self.bot_attack = TRUE;
604 self.statdraintime = time + 5;
605 self.button0 = self.button1 = self.button2 = self.button3 = 0;
607 if(self.killcount == -666) {
614 self.cnt = WEP_LASER;
615 self.nixnex_lastchange_id = -1;
617 CL_SpawnWeaponentity();
618 self.alpha = default_player_alpha;
619 self.colormod = '1 1 1' * cvar("g_player_brightness");
620 self.exteriorweaponentity.alpha = default_weapon_alpha;
622 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
623 self.lms_traveled_distance = 0;
624 self.speedrunning = FALSE;
626 if(cvar("spawn_debug"))
628 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
629 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
632 //stuffcmd(self, "chase_active 0");
633 //stuffcmd(self, "set viewsize $tmpviewsize \n");
635 if (cvar("g_spawnsound"))
636 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
639 if(self.team == assault_attacker_team)
640 centerprint(self, "You are attacking!\n");
642 centerprint(self, "You are defending!\n");
645 } else if(self.classname == "observer") {
646 PutObserverInServer ();
655 void SetNewParms (void)
665 void SetChangeParms (void)
674 Called when a client types 'kill' in the console
677 void ClientKill (void)
679 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
682 void FixClientCvars(entity e)
685 // send prediction settings to the client
686 stuffcmd(e, "\nin_bindmap 0 0\n");
687 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
688 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
689 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
690 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
691 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
692 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
693 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
694 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
695 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
696 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
697 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
698 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
699 stuffcmd(e, "cl_movement_edgefriction 1\n");
701 // notify about available teams
704 CheckAllowedTeams(e);
705 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
706 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
709 stuffcmd(e, "set _teams_available 0\n");
716 Called when a client connects to the server
719 string ColoredTeamName(float t);
720 //void dom_player_join_team(entity pl);
721 void ClientConnect (void)
726 if(Ban_IsClientBanned(self))
728 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
734 self.classname = "player_joining";
735 self.flags = self.flags | FL_CLIENT;
736 self.version_nagtime = time + 10 + random() * 10;
740 dprint("BUG player count is lower than zero, this cannot happen!\n");
747 // dom_player_join_team(self);
749 //JoinBestTeam(self, FALSE);
751 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
752 self.classname = "observer";
754 self.classname = "player";
755 campaign_bots_may_start = 1;
758 self.playerid = (playerid_last = playerid_last + 1);
759 if(cvar("sv_eventlog"))
761 if(clienttype(self) == CLIENTTYPE_REAL)
765 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
766 s = strcat(":team:", ftos(self.playerid), ":");
767 s = strcat(s, ftos(self.team));
768 GameLogEcho(s, FALSE);
771 //stuffcmd(self, "set tmpviewsize $viewsize \n");
773 bprint ("^4",self.netname);
774 bprint ("^4 connected");
776 if(g_domination || g_ctf)
778 bprint(" and joined the ");
779 bprint(ColoredTeamName(self.team));
784 self.welcomemessage_time = 0;
786 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
787 // TODO: is this being used for anything else than cd tracks?
788 // Remember: SVC_CDTRACK exists. Maybe it should be used.
790 FixClientCvars(self);
793 WaypointSprite_InitClient(self);
795 // Wazat's grappling hook
796 SetGrappleHookBindings();
798 // get autoswitch state from player when he toggles it
799 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
801 // get version info from player
802 stuffcmd(self, "cmd clientversion $gameversion\n");
804 // send all weapon info strings
805 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
807 while (wep <= WEP_LAST)
809 weapon_action(wep, WR_REGISTER);
813 // get other cvars from player
816 // set cvar for team scoreboard
820 t = cvar("teamplay");
821 // 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
822 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
825 stuffcmd(self, "set teamplay 0\n");
829 self.frags = LMS_NewPlayerLives();
835 self.classname = "observer";
836 Spawnqueue_Insert(self);
839 bot_relinkplayerlist();
841 self.jointime = time;
848 Called when a client disconnects from the server
851 void(entity e) DropFlag;
852 .entity chatbubbleentity;
853 .entity teambubbleentity;
854 void ClientDisconnect (void)
857 if(cvar("sv_eventlog"))
858 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
859 bprint ("^4",self.netname);
860 bprint ("^4 disconnected\n");
862 if (self.chatbubbleentity)
864 remove (self.chatbubbleentity);
865 self.chatbubbleentity = world;
868 if (self.teambubbleentity)
870 remove (self.teambubbleentity);
871 self.teambubbleentity = world;
874 WaypointSprite_PlayerGone();
877 kh_Key_DropAll(self, TRUE);
880 DropFlag(self.flagcarried);
882 DistributeFragsAmongTeam(self, self.team, 1);
885 self.flags = self.flags - (self.flags & FL_CLIENT);
886 bot_relinkplayerlist();
890 if(self.weaponentity)
891 if(self.weaponentity.lasertarget)
892 remove(self.weaponentity.lasertarget);
896 Spawnqueue_Unmark(self);
897 Spawnqueue_Remove(self);
905 void() ChatBubbleThink =
907 self.nextthink = time;
908 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
910 self.owner.chatbubbleentity = world;
914 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
915 if (self.owner.buttonchat && !self.owner.deadflag)
916 self.model = self.mdl;
921 void() UpdateChatBubble =
923 if (!self.modelindex)
925 // spawn a chatbubble entity if needed
926 if (!self.chatbubbleentity)
928 self.chatbubbleentity = spawn();
929 self.chatbubbleentity.owner = self;
930 self.chatbubbleentity.exteriormodeltoclient = self;
931 self.chatbubbleentity.think = ChatBubbleThink;
932 self.chatbubbleentity.nextthink = time;
933 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
934 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
935 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
936 self.chatbubbleentity.model = "";
937 self.chatbubbleentity.effects = EF_LOWPRECISION;
942 void() TeamBubbleThink =
944 self.nextthink = time;
945 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
947 self.owner.teambubbleentity = world;
951 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
952 if (self.owner.buttonchat || self.owner.deadflag)
955 self.model = self.mdl;
959 float() TeamBubble_customizeentityforclient
961 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
964 void() UpdateTeamBubble =
966 if (!self.modelindex || !cvar("teamplay"))
968 // spawn a teambubble entity if needed
969 if (!self.teambubbleentity && cvar("teamplay"))
971 self.teambubbleentity = spawn();
972 self.teambubbleentity.owner = self;
973 self.teambubbleentity.exteriormodeltoclient = self;
974 self.teambubbleentity.think = TeamBubbleThink;
975 self.teambubbleentity.nextthink = time;
976 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
977 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
978 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
979 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
980 self.teambubbleentity.mdl = self.teambubbleentity.model;
981 self.teambubbleentity.model = self.teambubbleentity.mdl;
982 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
983 self.teambubbleentity.effects = EF_LOWPRECISION;
987 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
988 // added to the model skins
989 /*void() UpdateColorModHack =
992 c = self.clientcolors & 15;
993 // LordHavoc: only bothering to support white, green, red, yellow, blue
994 if (teamplay == 0) self.colormod = '0 0 0';
995 else if (c == 0) self.colormod = '1.00 1.00 1.00';
996 else if (c == 3) self.colormod = '0.10 1.73 0.10';
997 else if (c == 4) self.colormod = '1.73 0.10 0.10';
998 else if (c == 12) self.colormod = '1.22 1.22 0.10';
999 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1000 else self.colormod = '1 1 1';
1006 self.effects |= EF_NODRAW; // prevent another CopyBody
1007 PutClientInServer();
1010 void player_powerups (void)
1014 if (self.items & IT_STRENGTH)
1016 if (time > self.strength_finished)
1018 if (g_minstagib_invis_alpha > 0)
1020 self.alpha = default_player_alpha;
1021 self.exteriorweaponentity.alpha = default_weapon_alpha;
1022 self.effects = self.effects | EF_FULLBRIGHT;
1026 self.effects -= self.effects & EF_NODRAW;
1028 self.items = self.items - (self.items & IT_STRENGTH);
1029 sprint(self, "^3Invisibility has worn off\n");
1034 if (time < self.strength_finished)
1036 if (g_minstagib_invis_alpha > 0)
1038 self.alpha = g_minstagib_invis_alpha;
1039 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1040 self.effects -= self.effects & EF_FULLBRIGHT;
1044 self.effects = self.effects | EF_NODRAW;
1046 self.items = self.items | IT_STRENGTH;
1047 sprint(self, "^3You are invisible\n");
1051 if (self.items & IT_INVINCIBLE)
1053 if (time > self.invincible_finished)
1055 self.items = self.items - (self.items & IT_INVINCIBLE);
1056 sprint(self, "^3Speed has worn off\n");
1061 if (time < self.invincible_finished)
1063 self.items = self.items | IT_INVINCIBLE;
1064 sprint(self, "^3You are on speed\n");
1070 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1071 if (self.items & IT_STRENGTH)
1073 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1074 if (time > self.strength_finished)
1076 self.items = self.items - (self.items & IT_STRENGTH);
1077 sprint(self, "^3Strength has worn off\n");
1082 if (time < self.strength_finished)
1084 self.items = self.items | IT_STRENGTH;
1085 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1088 if (self.items & IT_INVINCIBLE)
1090 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1091 if (time > self.invincible_finished)
1093 self.items = self.items - (self.items & IT_INVINCIBLE);
1094 sprint(self, "^3Shield has worn off\n");
1099 if (time < self.invincible_finished)
1101 self.items = self.items | IT_INVINCIBLE;
1102 sprint(self, "^3Shield surrounds you\n");
1106 if (cvar("g_fullbrightplayers"))
1107 self.effects = self.effects | EF_FULLBRIGHT;
1109 // midair gamemode: damage only while in the air
1110 // if in midair mode, being on ground grants temporary invulnerability
1111 // (this is so that multishot weapon don't clear the ground flag on the
1112 // first damage in the frame, leaving the player vulnerable to the
1113 // remaining hits in the same frame)
1114 if (self.flags & FL_ONGROUND)
1116 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1118 if (time < self.spawnshieldtime)
1119 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1122 float CalcRegen(float current, float stable, float regenfactor)
1124 if(current > stable)
1126 else if(current > stable - 0.25) // when close enough, "snap"
1129 return min(stable, current + (stable - current) * regenfactor * frametime);
1132 void player_regen (void)
1134 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1135 maxh = cvar("g_balance_health_stable");
1136 maxa = cvar("g_balance_armor_stable");
1137 limith = cvar("g_balance_health_limit");
1138 limita = cvar("g_balance_armor_limit");
1140 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1143 max_mod = regen_mod = rot_mod = limit_mod = 1;
1145 if (self.runes & RUNE_REGEN)
1147 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1149 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1150 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1151 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1155 regen_mod = cvar("g_balance_rune_regen_regenrate");
1156 max_mod = cvar("g_balance_rune_regen_hpmod");
1157 limit_mod = cvar("g_balance_rune_regen_limitmod");
1160 else if (self.runes & CURSE_VENOM)
1162 max_mod = cvar("g_balance_curse_venom_hpmod");
1163 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1164 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1166 rot_mod = cvar("g_balance_curse_venom_rotrate");
1167 limit_mod = cvar("g_balance_curse_venom_limitmod");
1168 //if (!self.runes & RUNE_REGEN)
1169 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1171 maxh = maxh * max_mod;
1172 //maxa = maxa * max_mod;
1173 limith = limith * limit_mod;
1174 limita = limita * limit_mod;
1176 if (self.armorvalue > maxa)
1178 if (time > self.pauserotarmor_finished)
1180 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1181 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1184 else if (self.armorvalue < maxa)
1186 if (time > self.pauseregen_finished)
1188 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1189 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1192 if (self.health > maxh)
1194 if (time > self.pauserothealth_finished)
1196 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1197 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1200 else if (self.health < maxh)
1202 if (time > self.pauseregen_finished)
1204 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1205 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1209 if (self.health > limith)
1210 self.health = limith;
1211 if (self.armorvalue > limita)
1212 self.armorvalue = limita;
1214 // if player rotted to death... die!
1216 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1220 ======================
1221 spectate mode routines
1222 ======================
1224 void SpectateCopy(entity spectatee) {
1225 self.armortype = spectatee.armortype;
1226 self.armorvalue = spectatee.armorvalue;
1227 self.currentammo = spectatee.currentammo;
1228 self.effects = spectatee.effects;
1229 self.health = spectatee.health;
1231 self.items = spectatee.items;
1232 self.punchangle = spectatee.punchangle;
1233 self.view_ofs = spectatee.view_ofs;
1234 self.v_angle = spectatee.v_angle;
1235 self.viewzoom = spectatee.viewzoom;
1236 self.velocity = spectatee.velocity;
1237 self.dmg_take = spectatee.dmg_take;
1238 self.dmg_save = spectatee.dmg_save;
1239 self.dmg_inflictor = spectatee.dmg_inflictor;
1240 self.angles = spectatee.v_angle;
1241 self.fixangle = TRUE;
1242 setorigin(self, spectatee.origin);
1243 setsize(self, spectatee.mins, spectatee.maxs);
1246 void SpectateUpdate() {
1248 PutObserverInServer();
1250 if (self != self.enemy) {
1251 if(self.enemy.flags & FL_NOTARGET)
1252 PutObserverInServer();
1253 SpectateCopy(self.enemy);
1254 //msg_entity = self;
1255 //WriteByte(MSG_ONE, SVC_SETANGLE);
1256 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1257 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1258 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1262 float SpectateNext() {
1263 other = find(self.enemy, classname, "player");
1265 other = find(other, classname, "player");
1270 if(self.enemy.classname == "player") {
1272 WriteByte(MSG_ONE, SVC_SETVIEW);
1273 WriteEntity(MSG_ONE, self.enemy);
1274 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1284 ShowRespawnCountdown()
1286 Update a respawn countdown display.
1289 void ShowRespawnCountdown()
1292 if(self.deadflag == DEAD_NO) // just respawned?
1296 number = ceil(self.death_time - time);
1299 if(number <= self.respawn_countdown)
1301 self.respawn_countdown = number - 1;
1302 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
1303 play2(self, strcat("announcer/robotic/", ftos(number), "announcer/.ogg"));
1308 void LeaveSpectatorMode()
1310 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1311 self.classname = "player";
1312 if(cvar("g_campaign") || cvar("g_balance_teams"))
1313 JoinBestTeam(self, 0);
1314 if(cvar("g_campaign"))
1315 campaign_bots_may_start = 1;
1316 PutClientInServer();
1317 if(!(self.flags & FL_NOTARGET))
1318 bprint ("^4", self.netname, "^4 is playing now\n");
1319 centerprint(self,"");
1322 stuffcmd(self,"menu_showteamselect\n");
1331 Called every frame for each client before the physics are run
1334 void() ctf_setstatus;
1335 .float vote_nagtime;
1336 void PlayerPreThink (void)
1339 if(self.version_nagtime)
1340 if(self.cvar_g_nexuizversion)
1341 if(time > self.version_nagtime)
1343 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1344 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1346 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");
1347 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1349 self.version_nagtime = 0;
1353 if(self.cvar_scr_centertime)
1354 if(time > self.vote_nagtime)
1357 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1361 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1363 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1364 self.max_armorvalue = 0;
1368 antilag_record(self);
1370 if(self.classname == "player") {
1371 // if(self.netname == "Wazat")
1372 // bprint(self.classname, "\n");
1374 CheckRules_Player();
1377 PrintWelcomeMessage(self);
1379 if(g_lms || !cvar("sv_spectate"))
1380 if((time - self.jointime) <= cvar("welcome_message_time"))
1381 PrintWelcomeMessage(self);
1383 if (intermission_running)
1385 IntermissionThink (); // otherwise a button could be missed between
1386 return; // the think tics
1389 if(self.teleport_time)
1390 if(time > self.teleport_time)
1392 self.teleport_time = 0;
1393 self.effects = self.effects - (self.effects & EF_NODRAW);
1394 if(self.weaponentity)
1395 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1398 Nixnex_GiveCurrentWeapon();
1400 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1401 UpdateSelectedPlayer();
1403 if (self.deadflag != DEAD_NO)
1405 float button_pressed, force_respawn;
1407 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1408 force_respawn = (g_lms || cvar("g_forced_respawn"));
1409 if (self.deadflag == DEAD_DYING)
1412 self.deadflag = DEAD_RESPAWNING;
1413 else if(!button_pressed)
1414 self.deadflag = DEAD_DEAD;
1416 else if (self.deadflag == DEAD_DEAD)
1419 self.deadflag = DEAD_RESPAWNABLE;
1421 else if (self.deadflag == DEAD_RESPAWNABLE)
1424 self.deadflag = DEAD_RESPAWNING;
1426 else if (self.deadflag == DEAD_RESPAWNING)
1428 if(time > self.death_time)
1430 self.death_time = time + 1; // only retry once a second
1434 ShowRespawnCountdown();
1438 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1442 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1443 dist = self.oldorigin - self.origin;
1445 self.lms_traveled_distance += fabs(vlen(dist));
1447 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1449 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1450 self.lms_traveled_distance = 0;
1453 if(time > self.lms_nextcheck)
1455 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1456 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1458 centerprint(self, cvar_string("g_lms_campcheck_message"));
1459 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1460 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1461 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');
1463 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1464 self.lms_traveled_distance = 0;
1468 if (self.button5 && !self.hook.state)
1473 self.view_ofs = PL_CROUCH_VIEW_OFS;
1474 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1475 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1482 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1483 if (!trace_startsolid)
1485 self.crouch = FALSE;
1486 self.view_ofs = PL_VIEW_OFS;
1487 setsize (self, PL_MIN, PL_MAX);
1494 GrapplingHookFrame();
1499 float zoomfactor, zoomspeed, zoomdir;
1500 zoomfactor = self.cvar_cl_zoomfactor;
1501 if(zoomfactor < 1 || zoomfactor > 16)
1503 zoomspeed = self.cvar_cl_zoomspeed;
1504 if(zoomspeed >= 0) // < 0 is instant zoom
1505 if(zoomspeed < 0.5 || zoomspeed > 16)
1508 zoomdir = self.button4;
1510 if(self.weapon == WEP_NEX)
1515 self.has_zoomed = 1;
1519 if(zoomspeed <= 0) // instant zoom
1522 self.viewzoom = 1 / zoomfactor;
1528 // geometric zoom would be:
1529 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1530 // however, testing showed that arithmetic/harmonic zoom works better
1532 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1533 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1534 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1536 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1537 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1538 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1542 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1550 minstagib_ammocheck();
1555 //self.angles_y=self.v_angle_y + 90; // temp
1557 //if (TetrisPreFrame()) return;
1558 } else if(gameover) {
1559 if (intermission_running)
1560 IntermissionThink (); // otherwise a button could be missed between
1562 } else if(self.classname == "observer") {
1564 if (self.flags & FL_JUMPRELEASED) {
1565 if (self.button2 && self.version == cvar("gameversion")) {
1566 self.welcomemessage_time = 0;
1567 self.flags = self.flags - FL_JUMPRELEASED;
1568 LeaveSpectatorMode();
1570 } else if(self.button0 && self.version == cvar("gameversion")) {
1571 self.welcomemessage_time = 0;
1572 self.flags = self.flags - FL_JUMPRELEASED;
1573 if(SpectateNext() == 1) {
1574 self.classname = "spectator";
1578 if (!(self.button0 || self.button2)) {
1579 self.flags = self.flags | FL_JUMPRELEASED;
1582 PrintWelcomeMessage(self);
1583 } else if(self.classname == "spectator") {
1584 if (self.flags & FL_JUMPRELEASED) {
1585 if (self.button2 && self.version == cvar("gameversion")) {
1586 self.welcomemessage_time = 0;
1587 self.flags = self.flags - FL_JUMPRELEASED;
1588 LeaveSpectatorMode();
1590 } else if(self.button0) {
1591 self.welcomemessage_time = 0;
1592 self.flags = self.flags - FL_JUMPRELEASED;
1593 if(SpectateNext() == 1) {
1594 self.classname = "spectator";
1596 self.classname = "observer";
1597 PutClientInServer();
1599 } else if (self.button3) {
1600 self.welcomemessage_time = 0;
1601 self.flags = self.flags - FL_JUMPRELEASED;
1602 self.classname = "observer";
1603 PutClientInServer();
1608 if (!(self.button0 || self.button3)) {
1609 self.flags = self.flags | FL_JUMPRELEASED;
1612 PrintWelcomeMessage(self);
1613 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1622 Called every frame for each client after the physics are run
1625 void PlayerPostThink (void)
1627 // Savage: Check for nameless players
1628 if (strlen(self.netname) < 1) {
1629 self.netname = "Player";
1630 stuffcmd(self, "seta _cl_name Player\n");
1633 if(self.classname == "player") {
1634 CheckRules_Player();
1639 if (intermission_running)
1640 return; // intermission or finale
1642 //PrintWelcomeMessage(self);
1643 //if (TetrisPostFrame()) return;
1645 // restart countdown
1646 if(time < restart_countdown)
1651 sec = ceil(restart_countdown-time);
1652 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1653 centerprint(self, s);
1654 self.movetype = MOVETYPE_NONE;
1655 self.velocity = '0 0 0';
1656 self.avelocity = '0 0 0';
1657 self.movement = '0 0 0';
1659 else if(self.movetype == MOVETYPE_NONE)
1661 self.movetype = MOVETYPE_WALK;
1662 centerprint(self, "\n");
1664 } else if (self.classname == "observer") {
1666 } else if (self.classname == "spectator") {