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 (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 spot, firstspot, playerlist;
151 spot = find (world, classname, "testplayerstart");
157 if(!anypoint && have_team_spawns)
158 teamcheck = self.team;
160 // get the list of players
161 playerlist = findchain(classname, "player");
162 // get the entire list of spots
163 firstspot = findchain(classname, "info_player_deathmatch");
164 // filter out the bad ones
165 // (note this returns the original list if none survived)
166 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
168 // there is 50/50 chance of choosing a random spot or the furthest spot
169 // (this means that roughly every other spawn will be furthest, so you
170 // usually won't get fragged at spawn twice in a row)
171 if (arena_roundbased)
173 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
174 spot = Spawn_RandomPoint(firstspot);
176 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
177 spot = Spawn_RandomPoint(firstspot);
179 spot = Spawn_FurthestPoint(firstspot, playerlist);
183 if(cvar("spawn_debug"))
187 if(some_spawn_has_been_used)
188 return world; // team can't spawn any more, because of actions of other team
190 error("Cannot find a spawn point - please fix the map!");
201 Checks if the argument string can be a valid playermodel.
202 Returns a valid one in doubt.
205 string FallbackPlayerModel = "models/player/marine.zym";
206 string CheckPlayerModel(string plyermodel) {
207 if(strlen(plyermodel) < 4)
208 return FallbackPlayerModel;
209 if( substring(plyermodel,0,14) != "models/player/")
210 return FallbackPlayerModel;
211 else if(cvar("sv_servermodelsonly"))
213 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
214 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
215 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
216 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
217 return FallbackPlayerModel;
218 if(!fexists(plyermodel))
219 return FallbackPlayerModel;
226 Client_customizeentityforclient
231 float Client_customizeentityforclient()
233 #ifdef ALLOW_VARIABLE_LOD
235 // other: the player viewing me
239 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
242 if(other.cvar_cl_playerdetailreduction <= 0)
244 if(other.cvar_cl_playerdetailreduction <= -2)
245 self.modelindex = self.modelindex_lod2;
246 else if(other.cvar_cl_playerdetailreduction <= -1)
247 self.modelindex = self.modelindex_lod1;
249 self.modelindex = self.modelindex_lod0;
253 distance = vlen(self.origin - other.origin);
254 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
256 self.modelindex = self.modelindex_lod2;
258 self.modelindex = self.modelindex_lod1;
260 self.modelindex = self.modelindex_lod0;
267 void UpdatePlayerSounds();
268 void setmodel_lod(entity e, string modelname)
270 #ifdef ALLOW_VARIABLE_LOD
273 // FIXME: this only supports 3-letter extensions
274 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
278 setmodel(e, s); // players have high precision
279 self.modelindex_lod1 = self.modelindex;
282 self.modelindex_lod1 = -1;
284 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
288 setmodel(e, s); // players have high precision
289 self.modelindex_lod2 = self.modelindex;
292 self.modelindex_lod2 = -1;
294 precache_model(modelname);
295 setmodel(e, modelname); // players have high precision
296 self.modelindex_lod0 = self.modelindex;
298 if(self.modelindex_lod1 < 0)
299 self.modelindex_lod1 = self.modelindex;
301 if(self.modelindex_lod2 < 0)
302 self.modelindex_lod2 = self.modelindex;
304 precache_model(modelname);
305 setmodel(e, modelname); // players have high precision
307 player_setupanimsformodel();
308 UpdatePlayerSounds();
315 putting a client as observer in the server
318 void PutObserverInServer (void)
321 spot = SelectSpawnPoint (TRUE);
323 error("No spawnpoints for observers?!?\n");
324 RemoveGrapplingHook(self); // Wazat's Grappling Hook
326 if(clienttype(self) == CLIENTTYPE_REAL)
329 WriteByte(MSG_ONE, SVC_SETVIEW);
330 WriteEntity(MSG_ONE, self);
334 kh_Key_DropAll(self, TRUE);
337 DropFlag(self.flagcarried);
339 WaypointSprite_PlayerDead();
341 DistributeFragsAmongTeam(self, self.team, 1);
343 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
344 bprint ("^4", self.netname, "^4 has no more lives left\n");
345 else if(self.killcount != -666)
346 bprint ("^4", self.netname, "^4 is spectating now\n");
348 self.classname = "observer";
350 self.takedamage = DAMAGE_NO;
351 self.solid = SOLID_NOT;
352 self.movetype = MOVETYPE_NOCLIP;
353 self.flags = FL_CLIENT | FL_NOTARGET;
354 self.armorvalue = 666;
356 self.armorvalue = cvar("g_balance_armor_start");
357 self.pauserotarmor_finished = 0;
358 self.pauserothealth_finished = 0;
359 self.pauseregen_finished = 0;
360 self.damageforcescale = 0;
368 self.pain_finished = 0;
369 self.strength_finished = 0;
370 self.invincible_finished = 0;
372 self.think = SUB_Null;
376 self.deadflag = DEAD_NO;
377 self.angles = spot.angles;
379 self.fixangle = TRUE;
382 self.view_ofs = PL_VIEW_OFS;
383 setorigin (self, spot.origin);
384 setsize (self, '0 0 0', '0 0 0');
385 self.oldorigin = self.origin;
390 self.weaponmodel = "";
391 self.weaponentity = world;
392 self.killcount = -666;
393 self.velocity = '0 0 0';
394 self.avelocity = '0 0 0';
395 self.punchangle = '0 0 0';
396 self.punchvector = '0 0 0';
397 self.oldvelocity = self.velocity;
398 self.customizeentityforclient = Client_customizeentityforclient;
405 Spawnqueue_Insert(self);
409 Spawnqueue_Unmark(self);
410 Spawnqueue_Remove(self);
417 float RestrictSkin(float s)
426 void FixPlayermodel()
428 local string defaultmodel;
429 local float defaultskin;
432 if(cvar("sv_defaultcharacter") == 1) {
438 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
439 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
442 if(defaultmodel == "")
444 defaultmodel = cvar_string("sv_defaultplayermodel");
445 defaultskin = cvar("sv_defaultplayerskin");
448 if (defaultmodel != self.model)
452 setmodel_lod (self, defaultmodel);
453 setsize (self, m1, m2);
456 self.skin = defaultskin;
458 if (self.playermodel != self.model)
460 self.playermodel = CheckPlayerModel(self.playermodel);
463 setmodel_lod (self, self.playermodel);
464 setsize (self, m1, m2);
467 self.skin = RestrictSkin(stof(self.playerskin));
471 if(strlen(cvar_string("sv_defaultplayercolors")))
472 if(self.clientcolors != cvar("sv_defaultplayercolors"))
473 setcolor(self, cvar("sv_defaultplayercolors"));
480 Called when a client spawns in the server
483 void PutClientInServer (void)
485 if(clienttype(self) == CLIENTTYPE_BOT)
487 self.classname = "player";
489 else if(clienttype(self) == CLIENTTYPE_REAL)
492 WriteByte(MSG_ONE, SVC_SETVIEW);
493 WriteEntity(MSG_ONE, self);
496 // player is dead and becomes observer
497 if(g_lms && self.frags < 1)
498 self.classname = "observer";
502 self.classname = "observer";
504 if(self.classname == "player") {
507 spot = SelectSpawnPoint (FALSE);
510 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
511 return; // spawn failed
514 RemoveGrapplingHook(self); // Wazat's Grappling Hook
516 self.classname = "player";
517 self.iscreature = TRUE;
518 self.movetype = MOVETYPE_WALK;
519 self.solid = SOLID_SLIDEBOX;
520 self.flags = FL_CLIENT;
521 self.takedamage = DAMAGE_AIM;
523 self.effects = EF_FULLBRIGHT;
526 self.air_finished = time + 12;
529 self.ammo_shells = start_ammo_shells;
530 self.ammo_nails = start_ammo_nails;
531 self.ammo_rockets = start_ammo_rockets;
532 self.ammo_cells = start_ammo_cells;
533 self.health = start_health;
534 self.armorvalue = start_armorvalue;
535 self.items = start_items;
536 self.switchweapon = start_switchweapon;
538 self.jump_interval = time;
540 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
541 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
542 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
543 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
544 self.damageforcescale = 2;
551 self.pain_finished = 0;
552 self.strength_finished = 0;
553 self.invincible_finished = 0;
555 //self.speed_finished = 0;
556 //self.slowmo_finished = 0;
557 // players have no think function
558 self.think = SUB_Null;
564 self.deadflag = DEAD_NO;
566 self.angles = spot.angles;
568 self.angles_z = 0; // never spawn tilted even if the spot says to
569 self.fixangle = TRUE; // turn this way immediately
570 self.velocity = '0 0 0';
571 self.avelocity = '0 0 0';
572 self.punchangle = '0 0 0';
573 self.punchvector = '0 0 0';
574 self.oldvelocity = self.velocity;
579 self.customizeentityforclient = Client_customizeentityforclient;
585 self.view_ofs = PL_VIEW_OFS;
586 setsize (self, PL_MIN, PL_MAX);
587 self.spawnorigin = spot.origin;
588 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
589 // don't reset back to last position, even if new position is stuck in solid
590 self.oldorigin = self.origin;
594 Spawnqueue_Remove(self);
595 Spawnqueue_Mark(self);
598 self.event_damage = PlayerDamage;
600 self.bot_attack = TRUE;
602 self.statdraintime = time + 5;
603 self.button0 = self.button1 = self.button2 = self.button3 = 0;
605 if(self.killcount == -666) {
612 self.cnt = WEP_LASER;
613 self.nixnex_lastchange_id = -1;
615 CL_SpawnWeaponentity();
616 self.alpha = default_player_alpha;
617 self.colormod = '1 1 1' * cvar("g_player_brightness");
618 self.exteriorweaponentity.alpha = default_weapon_alpha;
620 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
621 self.lms_traveled_distance = 0;
622 self.speedrunning = FALSE;
624 if(cvar("spawn_debug"))
626 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
627 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
630 //stuffcmd(self, "chase_active 0");
631 //stuffcmd(self, "set viewsize $tmpviewsize \n");
633 if (cvar("g_spawnsound"))
634 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
637 if(self.team == assault_attacker_team)
638 centerprint(self, "You are attacking!\n");
640 centerprint(self, "You are defending!\n");
643 } else if(self.classname == "observer") {
644 PutObserverInServer ();
653 void SetNewParms (void)
663 void SetChangeParms (void)
672 Called when a client types 'kill' in the console
675 void ClientKill (void)
677 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
680 void FixClientCvars(entity e)
683 // send prediction settings to the client
684 stuffcmd(e, "\nin_bindmap 0 0\n");
685 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
686 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
687 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
688 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
689 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
690 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
691 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
692 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
693 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
694 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
695 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
696 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
697 stuffcmd(e, "cl_movement_edgefriction 1\n");
699 // notify about available teams
702 CheckAllowedTeams(e);
703 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
704 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
707 stuffcmd(e, "set _teams_available 0\n");
714 Called when a client connects to the server
717 string ColoredTeamName(float t);
718 //void dom_player_join_team(entity pl);
719 void ClientConnect (void)
724 if(Ban_IsClientBanned(self))
726 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
732 self.classname = "player_joining";
733 self.flags = self.flags | FL_CLIENT;
734 self.version_nagtime = time + 10 + random() * 10;
738 dprint("BUG player count is lower than zero, this cannot happen!\n");
745 // dom_player_join_team(self);
747 //JoinBestTeam(self, FALSE);
749 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
750 self.classname = "observer";
752 self.classname = "player";
753 campaign_bots_may_start = 1;
756 self.playerid = (playerid_last = playerid_last + 1);
757 if(cvar("sv_eventlog"))
759 if(clienttype(self) == CLIENTTYPE_REAL)
763 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
764 s = strcat(":team:", ftos(self.playerid), ":");
765 s = strcat(s, ftos(self.team));
766 GameLogEcho(s, FALSE);
769 //stuffcmd(self, "set tmpviewsize $viewsize \n");
771 bprint ("^4",self.netname);
772 bprint ("^4 connected");
774 if(g_domination || g_ctf)
776 bprint(" and joined the ");
777 bprint(ColoredTeamName(self.team));
782 self.welcomemessage_time = 0;
784 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
785 // TODO: is this being used for anything else than cd tracks?
786 // Remember: SVC_CDTRACK exists. Maybe it should be used.
788 FixClientCvars(self);
791 WaypointSprite_InitClient(self);
793 // Wazat's grappling hook
794 SetGrappleHookBindings();
796 // get autoswitch state from player when he toggles it
797 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
799 // get version info from player
800 stuffcmd(self, "cmd clientversion $gameversion\n");
802 // send all weapon info strings
803 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
805 while (wep <= WEP_LAST)
807 weapon_action(wep, WR_REGISTER);
811 // get other cvars from player
814 // set cvar for team scoreboard
818 t = cvar("teamplay");
819 // 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
820 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
823 stuffcmd(self, "set teamplay 0\n");
827 self.frags = LMS_NewPlayerLives();
833 self.classname = "observer";
834 Spawnqueue_Insert(self);
837 bot_relinkplayerlist();
839 self.jointime = time;
846 Called when a client disconnects from the server
849 void(entity e) DropFlag;
850 .entity chatbubbleentity;
851 .entity teambubbleentity;
852 void ClientDisconnect (void)
855 if(cvar("sv_eventlog"))
856 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
857 bprint ("^4",self.netname);
858 bprint ("^4 disconnected\n");
860 if (self.chatbubbleentity)
862 remove (self.chatbubbleentity);
863 self.chatbubbleentity = world;
866 if (self.teambubbleentity)
868 remove (self.teambubbleentity);
869 self.teambubbleentity = world;
872 WaypointSprite_PlayerGone();
875 kh_Key_DropAll(self, TRUE);
878 DropFlag(self.flagcarried);
880 DistributeFragsAmongTeam(self, self.team, 1);
883 self.flags = self.flags - (self.flags & FL_CLIENT);
884 bot_relinkplayerlist();
888 if(self.weaponentity)
889 if(self.weaponentity.lasertarget)
890 remove(self.weaponentity.lasertarget);
894 Spawnqueue_Unmark(self);
895 Spawnqueue_Remove(self);
903 void() ChatBubbleThink =
905 self.nextthink = time;
906 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
908 self.owner.chatbubbleentity = world;
912 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
913 if (self.owner.buttonchat && !self.owner.deadflag)
914 self.model = self.mdl;
919 void() UpdateChatBubble =
921 if (!self.modelindex)
923 // spawn a chatbubble entity if needed
924 if (!self.chatbubbleentity)
926 self.chatbubbleentity = spawn();
927 self.chatbubbleentity.owner = self;
928 self.chatbubbleentity.exteriormodeltoclient = self;
929 self.chatbubbleentity.think = ChatBubbleThink;
930 self.chatbubbleentity.nextthink = time;
931 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
932 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
933 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
934 self.chatbubbleentity.model = "";
935 self.chatbubbleentity.effects = EF_LOWPRECISION;
940 void() TeamBubbleThink =
942 self.nextthink = time;
943 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
945 self.owner.teambubbleentity = world;
949 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
950 if (self.owner.buttonchat || self.owner.deadflag)
953 self.model = self.mdl;
957 float() TeamBubble_customizeentityforclient
959 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
962 void() UpdateTeamBubble =
964 if (!self.modelindex || !cvar("teamplay"))
966 // spawn a teambubble entity if needed
967 if (!self.teambubbleentity && cvar("teamplay"))
969 self.teambubbleentity = spawn();
970 self.teambubbleentity.owner = self;
971 self.teambubbleentity.exteriormodeltoclient = self;
972 self.teambubbleentity.think = TeamBubbleThink;
973 self.teambubbleentity.nextthink = time;
974 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
975 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
976 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
977 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
978 self.teambubbleentity.mdl = self.teambubbleentity.model;
979 self.teambubbleentity.model = self.teambubbleentity.mdl;
980 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
981 self.teambubbleentity.effects = EF_LOWPRECISION;
985 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
986 // added to the model skins
987 /*void() UpdateColorModHack =
990 c = self.clientcolors & 15;
991 // LordHavoc: only bothering to support white, green, red, yellow, blue
992 if (teamplay == 0) self.colormod = '0 0 0';
993 else if (c == 0) self.colormod = '1.00 1.00 1.00';
994 else if (c == 3) self.colormod = '0.10 1.73 0.10';
995 else if (c == 4) self.colormod = '1.73 0.10 0.10';
996 else if (c == 12) self.colormod = '1.22 1.22 0.10';
997 else if (c == 13) self.colormod = '0.10 0.10 1.73';
998 else self.colormod = '1 1 1';
1004 self.effects |= EF_NODRAW; // prevent another CopyBody
1005 PutClientInServer();
1008 void player_powerups (void)
1012 if (self.items & IT_STRENGTH)
1014 if (time > self.strength_finished)
1016 if (g_minstagib_invis_alpha > 0)
1018 self.alpha = default_player_alpha;
1019 self.exteriorweaponentity.alpha = default_weapon_alpha;
1020 self.effects = self.effects | EF_FULLBRIGHT;
1024 self.effects -= self.effects & EF_NODRAW;
1026 self.items = self.items - (self.items & IT_STRENGTH);
1027 sprint(self, "^3Invisibility has worn off\n");
1032 if (time < self.strength_finished)
1034 if (g_minstagib_invis_alpha > 0)
1036 self.alpha = g_minstagib_invis_alpha;
1037 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1038 self.effects -= self.effects & EF_FULLBRIGHT;
1042 self.effects = self.effects | EF_NODRAW;
1044 self.items = self.items | IT_STRENGTH;
1045 sprint(self, "^3You are invisible\n");
1049 if (self.items & IT_INVINCIBLE)
1051 if (time > self.invincible_finished)
1053 self.items = self.items - (self.items & IT_INVINCIBLE);
1054 sprint(self, "^3Speed has worn off\n");
1059 if (time < self.invincible_finished)
1061 self.items = self.items | IT_INVINCIBLE;
1062 sprint(self, "^3You are on speed\n");
1068 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1069 if (self.items & IT_STRENGTH)
1071 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1072 if (time > self.strength_finished)
1074 self.items = self.items - (self.items & IT_STRENGTH);
1075 sprint(self, "^3Strength has worn off\n");
1080 if (time < self.strength_finished)
1082 self.items = self.items | IT_STRENGTH;
1083 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1086 if (self.items & IT_INVINCIBLE)
1088 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1089 if (time > self.invincible_finished)
1091 self.items = self.items - (self.items & IT_INVINCIBLE);
1092 sprint(self, "^3Shield has worn off\n");
1097 if (time < self.invincible_finished)
1099 self.items = self.items | IT_INVINCIBLE;
1100 sprint(self, "^3Shield surrounds you\n");
1104 if (cvar("g_fullbrightplayers"))
1105 self.effects = self.effects | EF_FULLBRIGHT;
1107 // midair gamemode: damage only while in the air
1108 // if in midair mode, being on ground grants temporary invulnerability
1109 // (this is so that multishot weapon don't clear the ground flag on the
1110 // first damage in the frame, leaving the player vulnerable to the
1111 // remaining hits in the same frame)
1112 if (self.flags & FL_ONGROUND)
1114 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1116 if (time < self.spawnshieldtime)
1117 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1120 float CalcRegen(float current, float stable, float regenfactor)
1122 if(current > stable)
1124 else if(current > stable - 0.25) // when close enough, "snap"
1127 return min(stable, current + (stable - current) * regenfactor * frametime);
1130 void player_regen (void)
1132 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1133 maxh = cvar("g_balance_health_stable");
1134 maxa = cvar("g_balance_armor_stable");
1135 limith = cvar("g_balance_health_limit");
1136 limita = cvar("g_balance_armor_limit");
1138 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1141 max_mod = regen_mod = rot_mod = limit_mod = 1;
1143 if (self.runes & RUNE_REGEN)
1145 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1147 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1148 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1149 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1153 regen_mod = cvar("g_balance_rune_regen_regenrate");
1154 max_mod = cvar("g_balance_rune_regen_hpmod");
1155 limit_mod = cvar("g_balance_rune_regen_limitmod");
1158 else if (self.runes & CURSE_VENOM)
1160 max_mod = cvar("g_balance_curse_venom_hpmod");
1161 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1162 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1164 rot_mod = cvar("g_balance_curse_venom_rotrate");
1165 limit_mod = cvar("g_balance_curse_venom_limitmod");
1166 //if (!self.runes & RUNE_REGEN)
1167 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1169 maxh = maxh * max_mod;
1170 //maxa = maxa * max_mod;
1171 limith = limith * limit_mod;
1172 limita = limita * limit_mod;
1174 if (self.armorvalue > maxa)
1176 if (time > self.pauserotarmor_finished)
1178 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1179 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1182 else if (self.armorvalue < maxa)
1184 if (time > self.pauseregen_finished)
1186 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1187 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1190 if (self.health > maxh)
1192 if (time > self.pauserothealth_finished)
1194 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1195 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1198 else if (self.health < maxh)
1200 if (time > self.pauseregen_finished)
1202 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1203 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1207 if (self.health > limith)
1208 self.health = limith;
1209 if (self.armorvalue > limita)
1210 self.armorvalue = limita;
1212 // if player rotted to death... die!
1214 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1218 ======================
1219 spectate mode routines
1220 ======================
1222 void SpectateCopy(entity spectatee) {
1223 self.armortype = spectatee.armortype;
1224 self.armorvalue = spectatee.armorvalue;
1225 self.currentammo = spectatee.currentammo;
1226 self.effects = spectatee.effects;
1227 self.health = spectatee.health;
1229 self.items = spectatee.items;
1230 self.punchangle = spectatee.punchangle;
1231 self.view_ofs = spectatee.view_ofs;
1232 self.v_angle = spectatee.v_angle;
1233 self.viewzoom = spectatee.viewzoom;
1234 self.velocity = spectatee.velocity;
1235 self.dmg_take = spectatee.dmg_take;
1236 self.dmg_save = spectatee.dmg_save;
1237 self.dmg_inflictor = spectatee.dmg_inflictor;
1238 self.angles = spectatee.v_angle;
1239 self.fixangle = TRUE;
1240 setorigin(self, spectatee.origin);
1241 setsize(self, spectatee.mins, spectatee.maxs);
1244 void SpectateUpdate() {
1246 PutObserverInServer();
1248 if (self != self.enemy) {
1249 if(self.enemy.flags & FL_NOTARGET)
1250 PutObserverInServer();
1251 SpectateCopy(self.enemy);
1252 //msg_entity = self;
1253 //WriteByte(MSG_ONE, SVC_SETANGLE);
1254 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1255 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1256 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1260 float SpectateNext() {
1261 other = find(self.enemy, classname, "player");
1263 other = find(other, classname, "player");
1268 if(self.enemy.classname == "player") {
1270 WriteByte(MSG_ONE, SVC_SETVIEW);
1271 WriteEntity(MSG_ONE, self.enemy);
1272 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1282 ShowRespawnCountdown()
1284 Update a respawn countdown display.
1287 void ShowRespawnCountdown()
1290 if(self.deadflag == DEAD_NO) // just respawned?
1294 number = ceil(self.death_time - time);
1297 if(number <= self.respawn_countdown)
1299 self.respawn_countdown = number - 1;
1300 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
1301 play2(self, strcat("announcer/robotic/", ftos(number), "announcer/.ogg"));
1306 void LeaveSpectatorMode()
1308 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1309 self.classname = "player";
1310 if(cvar("g_campaign") || cvar("g_balance_teams"))
1311 JoinBestTeam(self, 0);
1312 if(cvar("g_campaign"))
1313 campaign_bots_may_start = 1;
1314 PutClientInServer();
1315 if(!(self.flags & FL_NOTARGET))
1316 bprint ("^4", self.netname, "^4 is playing now\n");
1317 centerprint(self,"");
1320 stuffcmd(self,"menu_showteamselect\n");
1329 Called every frame for each client before the physics are run
1332 void() ctf_setstatus;
1333 .float vote_nagtime;
1334 void PlayerPreThink (void)
1337 if(self.version_nagtime)
1338 if(self.cvar_g_nexuizversion)
1339 if(time > self.version_nagtime)
1341 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1342 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1344 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");
1345 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1347 self.version_nagtime = 0;
1351 if(self.cvar_scr_centertime)
1352 if(time > self.vote_nagtime)
1355 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1359 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1361 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1362 self.max_armorvalue = 0;
1366 antilag_record(self);
1368 if(self.classname == "player") {
1369 // if(self.netname == "Wazat")
1370 // bprint(self.classname, "\n");
1372 CheckRules_Player();
1375 PrintWelcomeMessage(self);
1377 if(g_lms || !cvar("sv_spectate"))
1378 if((time - self.jointime) <= cvar("welcome_message_time"))
1379 PrintWelcomeMessage(self);
1381 if (intermission_running)
1383 IntermissionThink (); // otherwise a button could be missed between
1384 return; // the think tics
1387 if(self.teleport_time)
1388 if(time > self.teleport_time)
1390 self.teleport_time = 0;
1391 self.effects = self.effects - (self.effects & EF_NODRAW);
1392 if(self.weaponentity)
1393 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1396 Nixnex_GiveCurrentWeapon();
1398 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1399 UpdateSelectedPlayer();
1401 if (self.deadflag != DEAD_NO)
1403 float button_pressed, force_respawn;
1405 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1406 force_respawn = (g_lms || cvar("g_forced_respawn"));
1407 if (self.deadflag == DEAD_DYING)
1410 self.deadflag = DEAD_RESPAWNING;
1411 else if(!button_pressed)
1412 self.deadflag = DEAD_DEAD;
1414 else if (self.deadflag == DEAD_DEAD)
1417 self.deadflag = DEAD_RESPAWNABLE;
1419 else if (self.deadflag == DEAD_RESPAWNABLE)
1422 self.deadflag = DEAD_RESPAWNING;
1424 else if (self.deadflag == DEAD_RESPAWNING)
1426 if(time > self.death_time)
1428 self.death_time = time + 1; // only retry once a second
1432 ShowRespawnCountdown();
1436 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1440 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1441 dist = self.oldorigin - self.origin;
1443 self.lms_traveled_distance += fabs(vlen(dist));
1445 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1447 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1448 self.lms_traveled_distance = 0;
1451 if(time > self.lms_nextcheck)
1453 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1454 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1456 centerprint(self, cvar_string("g_lms_campcheck_message"));
1457 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1458 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1459 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');
1461 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1462 self.lms_traveled_distance = 0;
1466 if (self.button5 && !self.hook.state)
1471 self.view_ofs = PL_CROUCH_VIEW_OFS;
1472 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1473 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1480 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1481 if (!trace_startsolid)
1483 self.crouch = FALSE;
1484 self.view_ofs = PL_VIEW_OFS;
1485 setsize (self, PL_MIN, PL_MAX);
1492 GrapplingHookFrame();
1497 float zoomfactor, zoomspeed, zoomdir;
1498 zoomfactor = self.cvar_cl_zoomfactor;
1499 if(zoomfactor < 1 || zoomfactor > 16)
1501 zoomspeed = self.cvar_cl_zoomspeed;
1502 if(zoomspeed >= 0) // < 0 is instant zoom
1503 if(zoomspeed < 0.5 || zoomspeed > 16)
1506 zoomdir = self.button4;
1508 if(self.weapon == WEP_NEX)
1513 self.has_zoomed = 1;
1517 if(zoomspeed <= 0) // instant zoom
1520 self.viewzoom = 1 / zoomfactor;
1526 // geometric zoom would be:
1527 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1528 // however, testing showed that arithmetic/harmonic zoom works better
1530 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1531 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1532 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1534 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1535 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1536 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1540 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1548 minstagib_ammocheck();
1553 //self.angles_y=self.v_angle_y + 90; // temp
1555 //if (TetrisPreFrame()) return;
1556 } else if(gameover) {
1557 if (intermission_running)
1558 IntermissionThink (); // otherwise a button could be missed between
1560 } else if(self.classname == "observer") {
1562 if (self.flags & FL_JUMPRELEASED) {
1563 if (self.button2 && self.version == cvar("gameversion")) {
1564 self.welcomemessage_time = 0;
1565 self.flags = self.flags - FL_JUMPRELEASED;
1566 LeaveSpectatorMode();
1568 } else if(self.button0 && self.version == cvar("gameversion")) {
1569 self.welcomemessage_time = 0;
1570 self.flags = self.flags - FL_JUMPRELEASED;
1571 if(SpectateNext() == 1) {
1572 self.classname = "spectator";
1576 if (!(self.button0 || self.button2)) {
1577 self.flags = self.flags | FL_JUMPRELEASED;
1580 PrintWelcomeMessage(self);
1581 } else if(self.classname == "spectator") {
1582 if (self.flags & FL_JUMPRELEASED) {
1583 if (self.button2 && self.version == cvar("gameversion")) {
1584 self.welcomemessage_time = 0;
1585 self.flags = self.flags - FL_JUMPRELEASED;
1586 LeaveSpectatorMode();
1588 } else if(self.button0) {
1589 self.welcomemessage_time = 0;
1590 self.flags = self.flags - FL_JUMPRELEASED;
1591 if(SpectateNext() == 1) {
1592 self.classname = "spectator";
1594 self.classname = "observer";
1595 PutClientInServer();
1597 } else if (self.button3) {
1598 self.welcomemessage_time = 0;
1599 self.flags = self.flags - FL_JUMPRELEASED;
1600 self.classname = "observer";
1601 PutClientInServer();
1606 if (!(self.button0 || self.button3)) {
1607 self.flags = self.flags | FL_JUMPRELEASED;
1610 PrintWelcomeMessage(self);
1611 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1620 Called every frame for each client after the physics are run
1623 void PlayerPostThink (void)
1625 // Savage: Check for nameless players
1626 if (strlen(self.netname) < 1) {
1627 self.netname = "Player";
1628 stuffcmd(self, "seta _cl_name Player\n");
1631 if(self.classname == "player") {
1632 CheckRules_Player();
1637 if (intermission_running)
1638 return; // intermission or finale
1640 //PrintWelcomeMessage(self);
1641 //if (TetrisPostFrame()) return;
1643 // restart countdown
1644 if(time < restart_countdown)
1649 sec = ceil(restart_countdown-time);
1650 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1651 centerprint(self, s);
1652 self.movetype = MOVETYPE_NONE;
1653 self.velocity = '0 0 0';
1654 self.avelocity = '0 0 0';
1655 self.movement = '0 0 0';
1657 else if(self.movetype == MOVETYPE_NONE)
1659 self.movetype = MOVETYPE_WALK;
1660 centerprint(self, "\n");
1662 } else if (self.classname == "observer") {
1664 } else if (self.classname == "spectator") {