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 =
21 self.team = activator.team;
22 some_spawn_has_been_used = 1;
28 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
30 local entity spot, player, nextspot, previousspot, newfirstspot;
39 nextspot = spot.chain;
40 // count team mismatches as bad spots
42 local float spotactive;
45 // filter out spots for assault
46 if(spot.target != "") {
48 ent = find(world, targetname, spot.target);
50 if(ent.classname == "target_objective")
51 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
53 ent = find(ent, targetname, spot.target);
57 if (spot.team == teamcheck && spotactive > 0)
64 if (vlen(player.origin - spot.origin) < mindist)
66 player = player.chain;
72 previousspot.chain = spot;
79 spawn_allgood = FALSE;
83 // if we couldn't find ANY good points, return world
87 entity Spawn_RandomPoint(entity firstspot)
91 // count number of spots
96 numspots = numspots + 1;
100 numspots = numspots * random();
102 while (spot.chain && numspots >= 1)
104 numspots = numspots - 1;
110 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
112 local entity best, spot, player;
113 local float bestrating, rating;
115 bestrating = -1000000;
124 rating = min(rating, vlen(player.origin - spot.origin));
125 player = player.chain;
127 rating = rating + random() * 16;
128 if (bestrating < rating)
142 Finds a point to respawn
145 entity SelectSpawnPoint (float anypoint)
147 local float teamcheck;
148 local entity spot, firstspot, playerlist;
150 spot = find (world, classname, "testplayerstart");
156 if(!anypoint && have_team_spawns)
157 teamcheck = self.team;
159 // get the list of players
160 playerlist = findchain(classname, "player");
161 // get the entire list of spots
162 firstspot = findchain(classname, "info_player_deathmatch");
163 // filter out the bad ones
164 // (note this returns the original list if none survived)
165 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
167 // there is 50/50 chance of choosing a random spot or the furthest spot
168 // (this means that roughly every other spawn will be furthest, so you
169 // usually won't get fragged at spawn twice in a row)
170 if (arena_roundbased)
172 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
173 spot = Spawn_RandomPoint(firstspot);
175 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
176 spot = Spawn_RandomPoint(firstspot);
178 spot = Spawn_FurthestPoint(firstspot, playerlist);
182 if(cvar("spawn_debug"))
186 if(some_spawn_has_been_used)
187 return world; // team can't spawn any more, because of actions of other team
189 error("Cannot find a spawn point - please fix the map!");
200 Checks if the argument string can be a valid playermodel.
201 Returns a valid one in doubt.
204 string FallbackPlayerModel = "models/player/marine.zym";
205 string CheckPlayerModel(string plyermodel) {
206 if(strlen(plyermodel) < 4)
207 return FallbackPlayerModel;
208 if( substring(plyermodel,0,14) != "models/player/")
209 return FallbackPlayerModel;
210 else if(cvar("sv_servermodelsonly"))
212 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
213 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
214 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
215 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
216 return FallbackPlayerModel;
217 if(!fexists(plyermodel))
218 return FallbackPlayerModel;
225 Client_customizeentityforclient
230 float Client_customizeentityforclient()
232 #ifdef ALLOW_VARIABLE_LOD
234 // other: the player viewing me
238 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
241 if(other.cvar_cl_playerdetailreduction <= 0)
243 if(other.cvar_cl_playerdetailreduction <= -2)
244 self.modelindex = self.modelindex_lod2;
245 else if(other.cvar_cl_playerdetailreduction <= -1)
246 self.modelindex = self.modelindex_lod1;
248 self.modelindex = self.modelindex_lod0;
252 distance = vlen(self.origin - other.origin);
253 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
255 self.modelindex = self.modelindex_lod2;
257 self.modelindex = self.modelindex_lod1;
259 self.modelindex = self.modelindex_lod0;
266 void UpdatePlayerSounds();
267 void setmodel_lod(entity e, string modelname)
269 #ifdef ALLOW_VARIABLE_LOD
272 // FIXME: this only supports 3-letter extensions
273 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
277 setmodel(e, s); // players have high precision
278 self.modelindex_lod1 = self.modelindex;
281 self.modelindex_lod1 = -1;
283 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
287 setmodel(e, s); // players have high precision
288 self.modelindex_lod2 = self.modelindex;
291 self.modelindex_lod2 = -1;
293 precache_model(modelname);
294 setmodel(e, modelname); // players have high precision
295 self.modelindex_lod0 = self.modelindex;
297 if(self.modelindex_lod1 < 0)
298 self.modelindex_lod1 = self.modelindex;
300 if(self.modelindex_lod2 < 0)
301 self.modelindex_lod2 = self.modelindex;
303 precache_model(modelname);
304 setmodel(e, modelname); // players have high precision
306 player_setupanimsformodel();
307 UpdatePlayerSounds();
314 putting a client as observer in the server
317 void PutObserverInServer (void)
320 spot = SelectSpawnPoint (TRUE);
322 error("No spawnpoints for observers?!?\n");
323 RemoveGrapplingHook(self); // Wazat's Grappling Hook
325 if(clienttype(self) == CLIENTTYPE_REAL)
328 WriteByte(MSG_ONE, SVC_SETVIEW);
329 WriteEntity(MSG_ONE, self);
333 kh_Key_DropAll(self, TRUE);
336 DropFlag(self.flagcarried);
338 WaypointSprite_PlayerDead();
340 DistributeFragsAmongTeam(self, self.team, 1);
342 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
343 bprint ("^4", self.netname, "^4 has no more lives left\n");
344 else if(self.killcount != -666)
345 bprint ("^4", self.netname, "^4 is spectating now\n");
347 self.classname = "observer";
349 self.takedamage = DAMAGE_NO;
350 self.solid = SOLID_NOT;
351 self.movetype = MOVETYPE_NOCLIP;
352 self.flags = FL_CLIENT | FL_NOTARGET;
353 self.armorvalue = 666;
355 self.armorvalue = cvar("g_balance_armor_start");
356 self.pauserotarmor_finished = 0;
357 self.pauserothealth_finished = 0;
358 self.pauseregen_finished = 0;
359 self.damageforcescale = 0;
367 self.pain_finished = 0;
368 self.strength_finished = 0;
369 self.invincible_finished = 0;
371 self.think = SUB_Null;
375 self.deadflag = DEAD_NO;
376 self.angles = spot.angles;
378 self.fixangle = TRUE;
381 self.view_ofs = PL_VIEW_OFS;
382 setorigin (self, spot.origin);
383 setsize (self, '0 0 0', '0 0 0');
384 self.oldorigin = self.origin;
389 self.weaponmodel = "";
390 self.weaponentity = world;
391 self.killcount = -666;
392 self.velocity = '0 0 0';
393 self.avelocity = '0 0 0';
394 self.punchangle = '0 0 0';
395 self.punchvector = '0 0 0';
396 self.oldvelocity = self.velocity;
397 self.customizeentityforclient = Client_customizeentityforclient;
404 Spawnqueue_Insert(self);
408 Spawnqueue_Unmark(self);
409 Spawnqueue_Remove(self);
416 float RestrictSkin(float s)
425 void FixPlayermodel()
427 local string defaultmodel;
428 local float defaultskin;
431 if(cvar("sv_defaultcharacter") == 1) {
437 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
438 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
441 if(defaultmodel == "")
443 defaultmodel = cvar_string("sv_defaultplayermodel");
444 defaultskin = cvar("sv_defaultplayerskin");
447 if (defaultmodel != self.model)
451 setmodel_lod (self, defaultmodel);
452 setsize (self, m1, m2);
455 self.skin = defaultskin;
457 if (self.playermodel != self.model)
459 self.playermodel = CheckPlayerModel(self.playermodel);
462 setmodel_lod (self, self.playermodel);
463 setsize (self, m1, m2);
466 self.skin = RestrictSkin(stof(self.playerskin));
470 if(strlen(cvar_string("sv_defaultplayercolors")))
471 if(self.clientcolors != cvar("sv_defaultplayercolors"))
472 setcolor(self, cvar("sv_defaultplayercolors"));
479 Called when a client spawns in the server
482 void PutClientInServer (void)
484 if(clienttype(self) == CLIENTTYPE_BOT)
486 self.classname = "player";
488 else if(clienttype(self) == CLIENTTYPE_REAL)
491 WriteByte(MSG_ONE, SVC_SETVIEW);
492 WriteEntity(MSG_ONE, self);
495 // player is dead and becomes observer
496 if(g_lms && self.frags < 1)
497 self.classname = "observer";
501 self.classname = "observer";
503 if(self.classname == "player") {
506 spot = SelectSpawnPoint (FALSE);
509 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
510 return; // spawn failed
513 RemoveGrapplingHook(self); // Wazat's Grappling Hook
515 self.classname = "player";
516 self.iscreature = TRUE;
517 self.movetype = MOVETYPE_WALK;
518 self.solid = SOLID_SLIDEBOX;
519 self.flags = FL_CLIENT;
520 self.takedamage = DAMAGE_AIM;
522 self.effects = EF_FULLBRIGHT;
525 self.air_finished = time + 12;
528 self.ammo_shells = start_ammo_shells;
529 self.ammo_nails = start_ammo_nails;
530 self.ammo_rockets = start_ammo_rockets;
531 self.ammo_cells = start_ammo_cells;
532 self.health = start_health;
533 self.armorvalue = start_armorvalue;
534 self.items = start_items;
535 self.switchweapon = start_switchweapon;
537 self.jump_interval = time;
539 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
540 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
541 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
542 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
543 self.damageforcescale = 2;
550 self.pain_finished = 0;
551 self.strength_finished = 0;
552 self.invincible_finished = 0;
554 //self.speed_finished = 0;
555 //self.slowmo_finished = 0;
556 // players have no think function
557 self.think = SUB_Null;
563 self.deadflag = DEAD_NO;
565 self.angles = spot.angles;
567 self.angles_z = 0; // never spawn tilted even if the spot says to
568 self.fixangle = TRUE; // turn this way immediately
569 self.velocity = '0 0 0';
570 self.avelocity = '0 0 0';
571 self.punchangle = '0 0 0';
572 self.punchvector = '0 0 0';
573 self.oldvelocity = self.velocity;
578 self.customizeentityforclient = Client_customizeentityforclient;
584 self.view_ofs = PL_VIEW_OFS;
585 setsize (self, PL_MIN, PL_MAX);
586 self.spawnorigin = spot.origin;
587 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
588 // don't reset back to last position, even if new position is stuck in solid
589 self.oldorigin = self.origin;
593 Spawnqueue_Remove(self);
594 Spawnqueue_Mark(self);
597 self.event_damage = PlayerDamage;
599 self.bot_attack = TRUE;
601 self.statdraintime = time + 5;
602 self.button0 = self.button1 = self.button2 = self.button3 = 0;
604 if(self.killcount == -666) {
611 self.cnt = WEP_LASER;
612 self.nixnex_lastchange_id = -1;
614 CL_SpawnWeaponentity();
615 self.alpha = default_player_alpha;
616 self.colormod = '1 1 1' * cvar("g_player_brightness");
617 self.exteriorweaponentity.alpha = default_weapon_alpha;
619 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
620 self.lms_traveled_distance = 0;
621 self.speedrunning = FALSE;
623 if(cvar("spawn_debug"))
625 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
626 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
629 //stuffcmd(self, "chase_active 0");
630 //stuffcmd(self, "set viewsize $tmpviewsize \n");
632 if (cvar("g_spawnsound"))
633 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
636 if(self.team == assault_attacker_team)
637 centerprint(self, "You are attacking!\n");
639 centerprint(self, "You are defending!\n");
642 } else if(self.classname == "observer") {
643 PutObserverInServer ();
652 void SetNewParms (void)
662 void SetChangeParms (void)
671 Called when a client types 'kill' in the console
674 void ClientKill (void)
676 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
679 void FixClientCvars(entity e)
682 // send prediction settings to the client
683 stuffcmd(e, "\nin_bindmap 0 0\n");
684 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
685 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
686 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
687 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
688 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
689 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
690 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
691 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
692 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
693 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
694 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
695 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
696 stuffcmd(e, "cl_movement_edgefriction 1\n");
698 // notify about available teams
701 CheckAllowedTeams(e);
702 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
703 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
706 stuffcmd(e, "set _teams_available 0\n");
713 Called when a client connects to the server
716 string ColoredTeamName(float t);
717 //void dom_player_join_team(entity pl);
718 void ClientConnect (void)
723 if(Ban_IsClientBanned(self))
725 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
731 self.classname = "player_joining";
732 self.flags = self.flags | FL_CLIENT;
733 self.version_nagtime = time + 10 + random() * 10;
737 dprint("BUG player count is lower than zero, this cannot happen!\n");
744 // dom_player_join_team(self);
746 //JoinBestTeam(self, FALSE);
748 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
749 self.classname = "observer";
751 self.classname = "player";
752 campaign_bots_may_start = 1;
755 self.playerid = (playerid_last = playerid_last + 1);
756 if(cvar("sv_eventlog"))
758 if(clienttype(self) == CLIENTTYPE_REAL)
762 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
763 s = strcat(":team:", ftos(self.playerid), ":");
764 s = strcat(s, ftos(self.team));
765 GameLogEcho(s, FALSE);
768 //stuffcmd(self, "set tmpviewsize $viewsize \n");
770 bprint ("^4",self.netname);
771 bprint ("^4 connected");
773 if(g_domination || g_ctf)
775 bprint(" and joined the ");
776 bprint(ColoredTeamName(self.team));
781 self.welcomemessage_time = 0;
783 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
784 // TODO: is this being used for anything else than cd tracks?
785 // Remember: SVC_CDTRACK exists. Maybe it should be used.
787 FixClientCvars(self);
790 WaypointSprite_InitClient(self);
792 // Wazat's grappling hook
793 SetGrappleHookBindings();
795 // get autoswitch state from player when he toggles it
796 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
798 // get version info from player
799 stuffcmd(self, "cmd clientversion $gameversion\n");
801 // send all weapon info strings
802 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
804 while (wep <= WEP_LAST)
806 weapon_action(wep, WR_REGISTER);
810 // get other cvars from player
813 // set cvar for team scoreboard
817 t = cvar("teamplay");
818 // 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
819 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
822 stuffcmd(self, "set teamplay 0\n");
826 self.frags = LMS_NewPlayerLives();
832 self.classname = "observer";
833 Spawnqueue_Insert(self);
836 bot_relinkplayerlist();
838 self.jointime = time;
845 Called when a client disconnects from the server
848 void(entity e) DropFlag;
849 .entity chatbubbleentity;
850 .entity teambubbleentity;
851 void ClientDisconnect (void)
854 if(cvar("sv_eventlog"))
855 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
856 bprint ("^4",self.netname);
857 bprint ("^4 disconnected\n");
859 if (self.chatbubbleentity)
861 remove (self.chatbubbleentity);
862 self.chatbubbleentity = world;
865 if (self.teambubbleentity)
867 remove (self.teambubbleentity);
868 self.teambubbleentity = world;
871 WaypointSprite_PlayerGone();
874 kh_Key_DropAll(self, TRUE);
877 DropFlag(self.flagcarried);
879 DistributeFragsAmongTeam(self, self.team, 1);
882 self.flags = self.flags - (self.flags & FL_CLIENT);
883 bot_relinkplayerlist();
887 if(self.weaponentity)
888 if(self.weaponentity.lasertarget)
889 remove(self.weaponentity.lasertarget);
893 Spawnqueue_Unmark(self);
894 Spawnqueue_Remove(self);
902 void() ChatBubbleThink =
904 self.nextthink = time;
905 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
907 self.owner.chatbubbleentity = world;
911 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
912 if (self.owner.buttonchat && !self.owner.deadflag)
913 self.model = self.mdl;
918 void() UpdateChatBubble =
920 if (!self.modelindex)
922 // spawn a chatbubble entity if needed
923 if (!self.chatbubbleentity)
925 self.chatbubbleentity = spawn();
926 self.chatbubbleentity.owner = self;
927 self.chatbubbleentity.exteriormodeltoclient = self;
928 self.chatbubbleentity.think = ChatBubbleThink;
929 self.chatbubbleentity.nextthink = time;
930 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
931 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
932 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
933 self.chatbubbleentity.model = "";
934 self.chatbubbleentity.effects = EF_LOWPRECISION;
939 void() TeamBubbleThink =
941 self.nextthink = time;
942 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
944 self.owner.teambubbleentity = world;
948 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
949 if (self.owner.buttonchat || self.owner.deadflag)
952 self.model = self.mdl;
956 float() TeamBubble_customizeentityforclient
958 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
961 void() UpdateTeamBubble =
963 if (!self.modelindex || !cvar("teamplay"))
965 // spawn a teambubble entity if needed
966 if (!self.teambubbleentity && cvar("teamplay"))
968 self.teambubbleentity = spawn();
969 self.teambubbleentity.owner = self;
970 self.teambubbleentity.exteriormodeltoclient = self;
971 self.teambubbleentity.think = TeamBubbleThink;
972 self.teambubbleentity.nextthink = time;
973 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
974 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
975 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
976 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
977 self.teambubbleentity.mdl = self.teambubbleentity.model;
978 self.teambubbleentity.model = self.teambubbleentity.mdl;
979 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
980 self.teambubbleentity.effects = EF_LOWPRECISION;
984 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
985 // added to the model skins
986 /*void() UpdateColorModHack =
989 c = self.clientcolors & 15;
990 // LordHavoc: only bothering to support white, green, red, yellow, blue
991 if (teamplay == 0) self.colormod = '0 0 0';
992 else if (c == 0) self.colormod = '1.00 1.00 1.00';
993 else if (c == 3) self.colormod = '0.10 1.73 0.10';
994 else if (c == 4) self.colormod = '1.73 0.10 0.10';
995 else if (c == 12) self.colormod = '1.22 1.22 0.10';
996 else if (c == 13) self.colormod = '0.10 0.10 1.73';
997 else self.colormod = '1 1 1';
1003 self.effects |= EF_NODRAW; // prevent another CopyBody
1004 PutClientInServer();
1007 void player_powerups (void)
1011 if (self.items & IT_STRENGTH)
1013 if (time > self.strength_finished)
1015 if (g_minstagib_invis_alpha > 0)
1017 self.alpha = default_player_alpha;
1018 self.exteriorweaponentity.alpha = default_weapon_alpha;
1019 self.effects = self.effects | EF_FULLBRIGHT;
1023 self.effects -= self.effects & EF_NODRAW;
1025 self.items = self.items - (self.items & IT_STRENGTH);
1026 sprint(self, "^3Invisibility has worn off\n");
1031 if (time < self.strength_finished)
1033 if (g_minstagib_invis_alpha > 0)
1035 self.alpha = g_minstagib_invis_alpha;
1036 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1037 self.effects -= self.effects & EF_FULLBRIGHT;
1041 self.effects = self.effects | EF_NODRAW;
1043 self.items = self.items | IT_STRENGTH;
1044 sprint(self, "^3You are invisible\n");
1048 if (self.items & IT_INVINCIBLE)
1050 if (time > self.invincible_finished)
1052 self.items = self.items - (self.items & IT_INVINCIBLE);
1053 sprint(self, "^3Speed has worn off\n");
1058 if (time < self.invincible_finished)
1060 self.items = self.items | IT_INVINCIBLE;
1061 sprint(self, "^3You are on speed\n");
1067 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1068 if (self.items & IT_STRENGTH)
1070 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1071 if (time > self.strength_finished)
1073 self.items = self.items - (self.items & IT_STRENGTH);
1074 sprint(self, "^3Strength has worn off\n");
1079 if (time < self.strength_finished)
1081 self.items = self.items | IT_STRENGTH;
1082 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1085 if (self.items & IT_INVINCIBLE)
1087 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1088 if (time > self.invincible_finished)
1090 self.items = self.items - (self.items & IT_INVINCIBLE);
1091 sprint(self, "^3Shield has worn off\n");
1096 if (time < self.invincible_finished)
1098 self.items = self.items | IT_INVINCIBLE;
1099 sprint(self, "^3Shield surrounds you\n");
1103 if (cvar("g_fullbrightplayers"))
1104 self.effects = self.effects | EF_FULLBRIGHT;
1106 // midair gamemode: damage only while in the air
1107 // if in midair mode, being on ground grants temporary invulnerability
1108 // (this is so that multishot weapon don't clear the ground flag on the
1109 // first damage in the frame, leaving the player vulnerable to the
1110 // remaining hits in the same frame)
1111 if (self.flags & FL_ONGROUND)
1113 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1115 if (time < self.spawnshieldtime)
1116 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1119 float CalcRegen(float current, float stable, float regenfactor)
1121 if(current > stable)
1123 else if(current > stable - 0.25) // when close enough, "snap"
1126 return min(stable, current + (stable - current) * regenfactor * frametime);
1129 void player_regen (void)
1131 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1132 maxh = cvar("g_balance_health_stable");
1133 maxa = cvar("g_balance_armor_stable");
1134 limith = cvar("g_balance_health_limit");
1135 limita = cvar("g_balance_armor_limit");
1137 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1140 max_mod = regen_mod = rot_mod = limit_mod = 1;
1142 if (self.runes & RUNE_REGEN)
1144 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1146 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1147 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1148 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1152 regen_mod = cvar("g_balance_rune_regen_regenrate");
1153 max_mod = cvar("g_balance_rune_regen_hpmod");
1154 limit_mod = cvar("g_balance_rune_regen_limitmod");
1157 else if (self.runes & CURSE_VENOM)
1159 max_mod = cvar("g_balance_curse_venom_hpmod");
1160 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1161 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1163 rot_mod = cvar("g_balance_curse_venom_rotrate");
1164 limit_mod = cvar("g_balance_curse_venom_limitmod");
1165 //if (!self.runes & RUNE_REGEN)
1166 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1168 maxh = maxh * max_mod;
1169 //maxa = maxa * max_mod;
1170 limith = limith * limit_mod;
1171 limita = limita * limit_mod;
1173 if (self.armorvalue > maxa)
1175 if (time > self.pauserotarmor_finished)
1177 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1178 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1181 else if (self.armorvalue < maxa)
1183 if (time > self.pauseregen_finished)
1185 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1186 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1189 if (self.health > maxh)
1191 if (time > self.pauserothealth_finished)
1193 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1194 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1197 else if (self.health < maxh)
1199 if (time > self.pauseregen_finished)
1201 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1202 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1206 if (self.health > limith)
1207 self.health = limith;
1208 if (self.armorvalue > limita)
1209 self.armorvalue = limita;
1211 // if player rotted to death... die!
1213 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1217 ======================
1218 spectate mode routines
1219 ======================
1221 void SpectateCopy(entity spectatee) {
1222 self.armortype = spectatee.armortype;
1223 self.armorvalue = spectatee.armorvalue;
1224 self.currentammo = spectatee.currentammo;
1225 self.effects = spectatee.effects;
1226 self.health = spectatee.health;
1228 self.items = spectatee.items;
1229 self.punchangle = spectatee.punchangle;
1230 self.view_ofs = spectatee.view_ofs;
1231 self.v_angle = spectatee.v_angle;
1232 self.viewzoom = spectatee.viewzoom;
1233 self.velocity = spectatee.velocity;
1234 self.dmg_take = spectatee.dmg_take;
1235 self.dmg_save = spectatee.dmg_save;
1236 self.dmg_inflictor = spectatee.dmg_inflictor;
1237 self.angles = spectatee.v_angle;
1238 self.fixangle = TRUE;
1239 setorigin(self, spectatee.origin);
1240 setsize(self, spectatee.mins, spectatee.maxs);
1243 void SpectateUpdate() {
1245 PutObserverInServer();
1247 if (self != self.enemy) {
1248 if(self.enemy.flags & FL_NOTARGET)
1249 PutObserverInServer();
1250 SpectateCopy(self.enemy);
1251 //msg_entity = self;
1252 //WriteByte(MSG_ONE, SVC_SETANGLE);
1253 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1254 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1255 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1259 float SpectateNext() {
1260 other = find(self.enemy, classname, "player");
1262 other = find(other, classname, "player");
1267 if(self.enemy.classname == "player") {
1269 WriteByte(MSG_ONE, SVC_SETVIEW);
1270 WriteEntity(MSG_ONE, self.enemy);
1271 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1281 ShowRespawnCountdown()
1283 Update a respawn countdown display.
1286 void ShowRespawnCountdown()
1289 if(self.deadflag == DEAD_NO) // just respawned?
1293 number = ceil(self.death_time - time);
1296 if(number <= self.respawn_countdown)
1298 self.respawn_countdown = number - 1;
1299 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
1300 play2(self, strcat("announcer/robotic/", ftos(number), "announcer/.ogg"));
1305 void LeaveSpectatorMode()
1307 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1308 self.classname = "player";
1309 if(cvar("g_campaign") || cvar("g_balance_teams"))
1310 JoinBestTeam(self, 0);
1311 if(cvar("g_campaign"))
1312 campaign_bots_may_start = 1;
1313 PutClientInServer();
1314 if(!(self.flags & FL_NOTARGET))
1315 bprint ("^4", self.netname, "^4 is playing now\n");
1316 centerprint(self,"");
1319 stuffcmd(self,"menu_showteamselect\n");
1328 Called every frame for each client before the physics are run
1331 void() ctf_setstatus;
1332 .float vote_nagtime;
1333 void PlayerPreThink (void)
1336 if(self.version_nagtime)
1337 if(self.cvar_g_nexuizversion)
1338 if(time > self.version_nagtime)
1340 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1341 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1343 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");
1344 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1346 self.version_nagtime = 0;
1350 if(self.cvar_scr_centertime)
1351 if(time > self.vote_nagtime)
1354 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1358 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1360 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1361 self.max_armorvalue = 0;
1365 antilag_record(self);
1367 if(self.classname == "player") {
1368 // if(self.netname == "Wazat")
1369 // bprint(self.classname, "\n");
1371 CheckRules_Player();
1374 PrintWelcomeMessage(self);
1376 if(g_lms || !cvar("sv_spectate"))
1377 if((time - self.jointime) <= cvar("welcome_message_time"))
1378 PrintWelcomeMessage(self);
1380 if (intermission_running)
1382 IntermissionThink (); // otherwise a button could be missed between
1383 return; // the think tics
1386 if(self.teleport_time)
1387 if(time > self.teleport_time)
1389 self.teleport_time = 0;
1390 self.effects = self.effects - (self.effects & EF_NODRAW);
1391 if(self.weaponentity)
1392 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1395 Nixnex_GiveCurrentWeapon();
1397 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1398 UpdateSelectedPlayer();
1400 if (self.deadflag != DEAD_NO)
1402 float button_pressed, force_respawn;
1404 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1405 force_respawn = (g_lms || cvar("g_forced_respawn"));
1406 if (self.deadflag == DEAD_DYING)
1409 self.deadflag = DEAD_RESPAWNING;
1410 else if(!button_pressed)
1411 self.deadflag = DEAD_DEAD;
1413 else if (self.deadflag == DEAD_DEAD)
1416 self.deadflag = DEAD_RESPAWNABLE;
1418 else if (self.deadflag == DEAD_RESPAWNABLE)
1421 self.deadflag = DEAD_RESPAWNING;
1423 else if (self.deadflag == DEAD_RESPAWNING)
1425 if(time > self.death_time)
1427 self.death_time = time + 1; // only retry once a second
1431 ShowRespawnCountdown();
1435 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1439 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1440 dist = self.oldorigin - self.origin;
1442 self.lms_traveled_distance += fabs(vlen(dist));
1444 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1446 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1447 self.lms_traveled_distance = 0;
1450 if(time > self.lms_nextcheck)
1452 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1453 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1455 centerprint(self, cvar_string("g_lms_campcheck_message"));
1456 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1457 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1458 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');
1460 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1461 self.lms_traveled_distance = 0;
1465 if (self.button5 && !self.hook.state)
1470 self.view_ofs = PL_CROUCH_VIEW_OFS;
1471 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1472 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1479 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1480 if (!trace_startsolid)
1482 self.crouch = FALSE;
1483 self.view_ofs = PL_VIEW_OFS;
1484 setsize (self, PL_MIN, PL_MAX);
1491 GrapplingHookFrame();
1496 float zoomfactor, zoomspeed, zoomdir;
1497 zoomfactor = self.cvar_cl_zoomfactor;
1498 if(zoomfactor < 1 || zoomfactor > 16)
1500 zoomspeed = self.cvar_cl_zoomspeed;
1501 if(zoomspeed >= 0) // < 0 is instant zoom
1502 if(zoomspeed < 0.5 || zoomspeed > 16)
1505 zoomdir = self.button4;
1507 if(self.weapon == WEP_NEX)
1512 self.has_zoomed = 1;
1516 if(zoomspeed <= 0) // instant zoom
1519 self.viewzoom = 1 / zoomfactor;
1525 // geometric zoom would be:
1526 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1527 // however, testing showed that arithmetic/harmonic zoom works better
1529 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1530 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1531 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1533 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1534 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1535 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1539 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1547 minstagib_ammocheck();
1552 //self.angles_y=self.v_angle_y + 90; // temp
1554 //if (TetrisPreFrame()) return;
1555 } else if(gameover) {
1556 if (intermission_running)
1557 IntermissionThink (); // otherwise a button could be missed between
1559 } else if(self.classname == "observer") {
1561 if (self.flags & FL_JUMPRELEASED) {
1562 if (self.button2 && self.version == cvar("gameversion")) {
1563 self.welcomemessage_time = 0;
1564 self.flags = self.flags - FL_JUMPRELEASED;
1565 LeaveSpectatorMode();
1567 } else if(self.button0 && self.version == cvar("gameversion")) {
1568 self.welcomemessage_time = 0;
1569 self.flags = self.flags - FL_JUMPRELEASED;
1570 if(SpectateNext() == 1) {
1571 self.classname = "spectator";
1575 if (!(self.button0 || self.button2)) {
1576 self.flags = self.flags | FL_JUMPRELEASED;
1579 PrintWelcomeMessage(self);
1580 } else if(self.classname == "spectator") {
1581 if (self.flags & FL_JUMPRELEASED) {
1582 if (self.button2 && self.version == cvar("gameversion")) {
1583 self.welcomemessage_time = 0;
1584 self.flags = self.flags - FL_JUMPRELEASED;
1585 LeaveSpectatorMode();
1587 } else if(self.button0) {
1588 self.welcomemessage_time = 0;
1589 self.flags = self.flags - FL_JUMPRELEASED;
1590 if(SpectateNext() == 1) {
1591 self.classname = "spectator";
1593 self.classname = "observer";
1594 PutClientInServer();
1596 } else if (self.button3) {
1597 self.welcomemessage_time = 0;
1598 self.flags = self.flags - FL_JUMPRELEASED;
1599 self.classname = "observer";
1600 PutClientInServer();
1605 if (!(self.button0 || self.button3)) {
1606 self.flags = self.flags | FL_JUMPRELEASED;
1609 PrintWelcomeMessage(self);
1610 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1619 Called every frame for each client after the physics are run
1622 void PlayerPostThink (void)
1624 // Savage: Check for nameless players
1625 if (strlen(self.netname) < 1) {
1626 self.netname = "Player";
1627 stuffcmd(self, "seta _cl_name Player\n");
1630 if(self.classname == "player") {
1631 CheckRules_Player();
1636 if (intermission_running)
1637 return; // intermission or finale
1639 //PrintWelcomeMessage(self);
1640 //if (TetrisPostFrame()) return;
1642 // restart countdown
1643 if(time < restart_countdown)
1648 sec = ceil(restart_countdown-time);
1649 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1650 centerprint(self, s);
1651 self.movetype = MOVETYPE_NONE;
1652 self.velocity = '0 0 0';
1653 self.avelocity = '0 0 0';
1654 self.movement = '0 0 0';
1656 else if(self.movetype == MOVETYPE_NONE)
1658 self.movetype = MOVETYPE_WALK;
1659 centerprint(self, "\n");
1661 } else if (self.classname == "observer") {
1663 } else if (self.classname == "spectator") {