1 void info_player_start (void)
3 info_player_deathmatch();
6 void info_player_deathmatch (void)
8 self.classname = "info_player_deathmatch";
14 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
16 local entity spot, player, nextspot, previousspot, newfirstspot;
25 nextspot = spot.chain;
26 // count team mismatches as bad spots
28 local float spotactive;
31 // filter out spots for assault
32 if(spot.target != "") {
34 ent = find(world, targetname, spot.target);
36 if(ent.classname == "target_objective")
37 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
39 ent = find(ent, targetname, spot.target);
43 if (spot.team == teamcheck && spotactive > 0)
50 if (vlen(player.origin - spot.origin) < mindist)
52 player = player.chain;
58 previousspot.chain = spot;
65 spawn_allgood = FALSE;
69 // if we couldn't find ANY good points, return the original list
71 newfirstspot = firstspot;
75 entity Spawn_RandomPoint(entity firstspot)
79 // count number of spots
84 numspots = numspots + 1;
88 numspots = numspots * random();
90 while (spot.chain && numspots >= 1)
92 numspots = numspots - 1;
98 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
100 local entity best, spot, player;
101 local float bestrating, rating;
103 bestrating = -1000000;
112 rating = min(rating, vlen(player.origin - spot.origin));
113 player = player.chain;
115 rating = rating + random() * 16;
116 if (bestrating < rating)
130 Finds a point to respawn
133 entity SelectSpawnPoint (float anypoint)
135 local float teamcheck;
136 local entity spot, firstspot, playerlist;
138 spot = find (world, classname, "testplayerstart");
144 if(!anypoint && (g_ctf || g_assault))
145 teamcheck = self.team;
147 // get the list of players
148 playerlist = findchain(classname, "player");
149 // get the entire list of spots
150 firstspot = findchain(classname, "info_player_deathmatch");
151 // filter out the bad ones
152 // (note this returns the original list if none survived)
153 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
155 // there is 50/50 chance of choosing a random spot or the furthest spot
156 // (this means that roughly every other spawn will be furthest, so you
157 // usually won't get fragged at spawn twice in a row)
158 if (arena_roundbased)
160 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
161 spot = Spawn_RandomPoint(firstspot);
163 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
164 spot = Spawn_RandomPoint(firstspot);
166 spot = Spawn_FurthestPoint(firstspot, playerlist);
170 if(cvar("spawn_debug"))
173 error ("PutClientInServer: no start points on level");
183 Checks if the argument string can be a valid playermodel.
184 Returns a valid one in doubt.
187 string FallbackPlayerModel = "models/player/marine.zym";
188 string CheckPlayerModel(string plyermodel) {
189 if(strlen(plyermodel) < 4)
190 return FallbackPlayerModel;
191 if( substring(plyermodel,0,14) != "models/player/")
192 return FallbackPlayerModel;
193 else if(cvar("sv_servermodelsonly"))
195 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
196 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
197 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
198 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
199 return FallbackPlayerModel;
200 if(!fexists(plyermodel))
201 return FallbackPlayerModel;
208 Client_customizeentityforclient
213 float Client_customizeentityforclient()
215 #ifdef ALLOW_VARIABLE_LOD
217 // other: the player viewing me
221 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
224 if(other.cvar_cl_playerdetailreduction <= 0)
226 if(other.cvar_cl_playerdetailreduction <= -2)
227 self.modelindex = self.modelindex_lod2;
228 else if(other.cvar_cl_playerdetailreduction <= -1)
229 self.modelindex = self.modelindex_lod1;
231 self.modelindex = self.modelindex_lod0;
235 distance = vlen(self.origin - other.origin);
236 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
238 self.modelindex = self.modelindex_lod2;
240 self.modelindex = self.modelindex_lod1;
242 self.modelindex = self.modelindex_lod0;
249 void UpdateVoiceMessages();
250 void setmodel_lod(entity e, string modelname)
252 #ifdef ALLOW_VARIABLE_LOD
255 // FIXME: this only supports 3-letter extensions
256 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
260 setmodel(e, s); // players have high precision
261 self.modelindex_lod1 = self.modelindex;
264 self.modelindex_lod1 = -1;
266 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
270 setmodel(e, s); // players have high precision
271 self.modelindex_lod2 = self.modelindex;
274 self.modelindex_lod2 = -1;
276 precache_model(modelname);
277 setmodel(e, modelname); // players have high precision
278 self.modelindex_lod0 = self.modelindex;
280 if(self.modelindex_lod1 < 0)
281 self.modelindex_lod1 = self.modelindex;
283 if(self.modelindex_lod2 < 0)
284 self.modelindex_lod2 = self.modelindex;
286 precache_model(modelname);
287 setmodel(e, modelname); // players have high precision
289 player_setupanimsformodel();
290 UpdateVoiceMessages();
297 putting a client as observer in the server
300 void PutObserverInServer (void)
303 spot = SelectSpawnPoint (TRUE);
304 RemoveGrapplingHook(self); // Wazat's Grappling Hook
306 if(clienttype(self) == CLIENTTYPE_REAL)
309 WriteByte(MSG_ONE, SVC_SETVIEW);
310 WriteEntity(MSG_ONE, self);
314 kh_Key_DropAll(self, TRUE);
317 DropFlag(self.flagcarried);
319 WaypointSprite_PlayerDead();
321 DistributeFragsAmongTeam(self, self.team, 1);
323 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
324 bprint ("^4", self.netname, "^4 has no more lives left\n");
325 else if(self.killcount != -666)
326 bprint ("^4", self.netname, "^4 is spectating now\n");
328 self.classname = "observer";
330 self.takedamage = DAMAGE_NO;
331 self.solid = SOLID_NOT;
332 self.movetype = MOVETYPE_NOCLIP;
333 self.flags = FL_CLIENT | FL_NOTARGET;
334 self.armorvalue = 666;
336 self.armorvalue = cvar("g_balance_armor_start");
337 self.pauserotarmor_finished = 0;
338 self.pauserothealth_finished = 0;
339 self.pauseregen_finished = 0;
340 self.damageforcescale = 0;
348 self.pain_finished = 0;
349 self.strength_finished = 0;
350 self.invincible_finished = 0;
352 self.think = SUB_Null;
356 self.deadflag = DEAD_NO;
357 self.angles = spot.angles;
359 self.fixangle = TRUE;
362 self.view_ofs = PL_VIEW_OFS;
363 setorigin (self, spot.origin);
364 setsize (self, '0 0 0', '0 0 0');
365 self.oldorigin = self.origin;
370 self.weaponmodel = "";
371 self.weaponentity = world;
372 self.killcount = -666;
373 self.velocity = '0 0 0';
374 self.avelocity = '0 0 0';
375 self.punchangle = '0 0 0';
376 self.punchvector = '0 0 0';
377 self.oldvelocity = self.velocity;
378 self.customizeentityforclient = Client_customizeentityforclient;
384 Spawnqueue_Insert(self);
388 Spawnqueue_Unmark(self);
389 Spawnqueue_Remove(self);
396 float RestrictSkin(float s)
402 return math_mod(s, 3);
409 Called when a client spawns in the server
412 void PutClientInServer (void)
414 if(clienttype(self) == CLIENTTYPE_BOT)
416 self.classname = "player";
418 else if(clienttype(self) == CLIENTTYPE_REAL)
421 WriteByte(MSG_ONE, SVC_SETVIEW);
422 WriteEntity(MSG_ONE, self);
425 // player is dead and becomes observer
426 if(g_lms && self.frags < 1)
427 self.classname = "observer";
431 self.classname = "observer";
433 if(self.classname == "player") {
436 spot = SelectSpawnPoint (FALSE);
438 RemoveGrapplingHook(self); // Wazat's Grappling Hook
440 self.classname = "player";
441 self.iscreature = TRUE;
442 self.movetype = MOVETYPE_WALK;
443 self.solid = SOLID_SLIDEBOX;
444 self.flags = FL_CLIENT;
445 self.takedamage = DAMAGE_AIM;
447 self.air_finished = time + 12;
450 self.ammo_shells = start_ammo_shells;
451 self.ammo_nails = start_ammo_nails;
452 self.ammo_rockets = start_ammo_rockets;
453 self.ammo_cells = start_ammo_cells;
454 self.health = start_health;
455 self.armorvalue = start_armorvalue;
456 self.items = start_items;
457 self.switchweapon = start_switchweapon;
459 self.jump_interval = time;
461 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
462 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
463 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
464 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
465 self.damageforcescale = 2;
472 self.pain_finished = 0;
473 self.strength_finished = 0;
474 self.invincible_finished = 0;
476 //self.speed_finished = 0;
477 //self.slowmo_finished = 0;
478 // players have no think function
479 self.think = SUB_Null;
485 self.deadflag = DEAD_NO;
487 self.angles = spot.angles;
489 self.angles_z = 0; // never spawn tilted even if the spot says to
490 self.fixangle = TRUE; // turn this way immediately
491 self.velocity = '0 0 0';
492 self.avelocity = '0 0 0';
493 self.punchangle = '0 0 0';
494 self.punchvector = '0 0 0';
495 self.oldvelocity = self.velocity;
500 self.customizeentityforclient = Client_customizeentityforclient;
502 if(cvar("sv_defaultcharacter") == 1) {
503 local string defaultmodel;
504 defaultmodel = cvar_string("sv_defaultplayermodel");
505 setmodel_lod (self, defaultmodel);
506 self.skin = stof(cvar_string("sv_defaultplayerskin"));
508 self.playermodel = CheckPlayerModel(self.playermodel);
509 setmodel_lod (self, self.playermodel);
510 self.skin = RestrictSkin(stof(self.playerskin));
513 if(strlen(cvar_string("sv_defaultplayercolors")))
514 setcolor(self, cvar("sv_defaultplayercolors"));
517 self.view_ofs = PL_VIEW_OFS;
518 setsize (self, PL_MIN, PL_MAX);
519 self.spawnorigin = spot.origin;
520 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
521 // don't reset back to last position, even if new position is stuck in solid
522 self.oldorigin = self.origin;
526 Spawnqueue_Remove(self);
527 Spawnqueue_Mark(self);
530 self.event_damage = PlayerDamage;
532 self.bot_attack = TRUE;
534 self.statdraintime = time + 5;
535 self.button0 = self.button1 = self.button2 = self.button3 = 0;
537 if(self.killcount == -666) {
544 self.cnt = WEP_LASER;
545 self.nixnex_lastchange_id = -1;
547 CL_SpawnWeaponentity();
548 self.alpha = default_player_alpha;
549 self.colormod = '1 1 1' * cvar("g_player_brightness");
550 self.exteriorweaponentity.alpha = default_weapon_alpha;
552 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
553 self.lms_traveled_distance = 0;
555 if(cvar("spawn_debug"))
557 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
558 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
561 //stuffcmd(self, "chase_active 0");
562 //stuffcmd(self, "set viewsize $tmpviewsize \n");
564 if (cvar("g_spawnsound"))
565 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
568 if(self.team == assault_attacker_team)
569 centerprint(self, "You are attacking!\n");
571 centerprint(self, "You are defending!\n");
574 } else if(self.classname == "observer") {
575 PutObserverInServer ();
584 void SetNewParms (void)
594 void SetChangeParms (void)
603 Called when a client types 'kill' in the console
606 void ClientKill (void)
608 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
611 void FixClientCvars(entity e)
614 // send prediction settings to the client
615 stuffcmd(e, "\nin_bindmap 0 0\n");
616 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
617 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
618 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
619 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
620 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
621 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
622 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
623 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
624 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
625 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
626 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
627 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
628 stuffcmd(e, "cl_movement_edgefriction 1\n");
630 // notify about available teams
633 CheckAllowedTeams(e);
634 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
635 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
638 stuffcmd(e, "set _teams_available 0\n");
645 Called when a client connects to the server
648 string ColoredTeamName(float t);
649 //void dom_player_join_team(entity pl);
650 void ClientConnect (void)
655 if(Ban_IsClientBanned(self))
657 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
663 self.classname = "player_joining";
664 self.flags = self.flags | FL_CLIENT;
665 self.version_nagtime = time + 10 + random() * 10;
669 dprint("BUG player count is lower than zero, this cannot happen!\n");
676 // dom_player_join_team(self);
678 //JoinBestTeam(self, FALSE);
680 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
681 self.classname = "observer";
683 self.classname = "player";
684 campaign_bots_may_start = 1;
687 self.playerid = (playerid_last = playerid_last + 1);
688 if(cvar("sv_eventlog"))
690 if(clienttype(self) == CLIENTTYPE_REAL)
694 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
695 s = strcat(":team:", ftos(self.playerid), ":");
696 s = strcat(s, ftos(self.team));
697 GameLogEcho(s, FALSE);
700 //stuffcmd(self, "set tmpviewsize $viewsize \n");
702 bprint ("^4",self.netname);
703 bprint ("^4 connected");
705 if(g_domination || g_ctf)
707 bprint(" and joined the ");
708 bprint(ColoredTeamName(self.team));
713 self.welcomemessage_time = 0;
715 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
716 // TODO: is this being used for anything else than cd tracks?
717 // Remember: SVC_CDTRACK exists. Maybe it should be used.
719 FixClientCvars(self);
722 WaypointSprite_InitClient(self);
724 // Wazat's grappling hook
725 SetGrappleHookBindings();
727 // get autoswitch state from player when he toggles it
728 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
730 // get version info from player
731 stuffcmd(self, "cmd clientversion $gameversion\n");
733 // send all weapon info strings
734 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
736 while (wep <= WEP_LAST)
738 weapon_action(wep, WR_REGISTER);
742 // get other cvars from player
745 // set cvar for team scoreboard
749 t = cvar("teamplay");
750 // 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
751 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
754 stuffcmd(self, "set teamplay 0\n");
758 self.frags = LMS_NewPlayerLives();
764 self.classname = "observer";
765 Spawnqueue_Insert(self);
768 bot_relinkplayerlist();
770 self.jointime = time;
777 Called when a client disconnects from the server
780 void(entity e) DropFlag;
781 .entity chatbubbleentity;
782 .entity teambubbleentity;
783 void ClientDisconnect (void)
786 if(cvar("sv_eventlog"))
787 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
788 bprint ("^4",self.netname);
789 bprint ("^4 disconnected\n");
791 if (self.chatbubbleentity)
793 remove (self.chatbubbleentity);
794 self.chatbubbleentity = world;
797 if (self.teambubbleentity)
799 remove (self.teambubbleentity);
800 self.teambubbleentity = world;
803 WaypointSprite_PlayerGone();
806 kh_Key_DropAll(self, TRUE);
809 DropFlag(self.flagcarried);
811 DistributeFragsAmongTeam(self, self.team, 1);
814 self.flags = self.flags - (self.flags & FL_CLIENT);
815 bot_relinkplayerlist();
819 if(self.weaponentity)
820 if(self.weaponentity.lasertarget)
821 remove(self.weaponentity.lasertarget);
825 Spawnqueue_Unmark(self);
826 Spawnqueue_Remove(self);
834 void() ChatBubbleThink =
836 self.nextthink = time;
837 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
839 self.owner.chatbubbleentity = world;
843 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
844 if (self.owner.buttonchat && !self.owner.deadflag)
845 self.model = self.mdl;
850 void() UpdateChatBubble =
852 if (!self.modelindex)
854 // spawn a chatbubble entity if needed
855 if (!self.chatbubbleentity)
857 self.chatbubbleentity = spawn();
858 self.chatbubbleentity.owner = self;
859 self.chatbubbleentity.exteriormodeltoclient = self;
860 self.chatbubbleentity.think = ChatBubbleThink;
861 self.chatbubbleentity.nextthink = time;
862 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
863 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
864 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
865 self.chatbubbleentity.model = "";
866 self.chatbubbleentity.effects = EF_LOWPRECISION;
871 void() TeamBubbleThink =
873 self.nextthink = time;
874 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
876 self.owner.teambubbleentity = world;
880 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
881 if (self.owner.buttonchat || self.owner.deadflag)
884 self.model = self.mdl;
888 float() TeamBubble_customizeentityforclient
890 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
893 void() UpdateTeamBubble =
895 if (!self.modelindex || !cvar("teamplay"))
897 // spawn a teambubble entity if needed
898 if (!self.teambubbleentity && cvar("teamplay"))
900 self.teambubbleentity = spawn();
901 self.teambubbleentity.owner = self;
902 self.teambubbleentity.exteriormodeltoclient = self;
903 self.teambubbleentity.think = TeamBubbleThink;
904 self.teambubbleentity.nextthink = time;
905 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
906 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
907 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
908 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
909 self.teambubbleentity.mdl = self.teambubbleentity.model;
910 self.teambubbleentity.model = self.teambubbleentity.mdl;
911 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
912 self.teambubbleentity.effects = EF_LOWPRECISION;
916 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
917 // added to the model skins
918 /*void() UpdateColorModHack =
921 c = self.clientcolors & 15;
922 // LordHavoc: only bothering to support white, green, red, yellow, blue
923 if (teamplay == 0) self.colormod = '0 0 0';
924 else if (c == 0) self.colormod = '1.00 1.00 1.00';
925 else if (c == 3) self.colormod = '0.10 1.73 0.10';
926 else if (c == 4) self.colormod = '1.73 0.10 0.10';
927 else if (c == 12) self.colormod = '1.22 1.22 0.10';
928 else if (c == 13) self.colormod = '0.10 0.10 1.73';
929 else self.colormod = '1 1 1';
938 void player_powerups (void)
942 self.effects = EF_FULLBRIGHT;
943 if (self.items & IT_STRENGTH)
945 if (time > self.strength_finished)
947 self.alpha = default_player_alpha;
948 self.exteriorweaponentity.alpha = default_weapon_alpha;
949 self.items = self.items - (self.items & IT_STRENGTH);
950 sprint(self, "^3Invisibility has worn off\n");
955 if (time < self.strength_finished)
957 self.alpha = cvar("g_minstagib_invis_alpha");
958 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
959 self.items = self.items | IT_STRENGTH;
960 sprint(self, "^3You are invisible\n");
964 if (self.items & IT_INVINCIBLE)
966 if (time > self.invincible_finished)
968 self.items = self.items - (self.items & IT_INVINCIBLE);
969 sprint(self, "^3Speed has worn off\n");
974 if (time < self.invincible_finished)
976 self.items = self.items | IT_INVINCIBLE;
977 sprint(self, "^3You are on speed\n");
983 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
984 if (self.items & IT_STRENGTH)
986 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
987 if (time > self.strength_finished)
989 self.items = self.items - (self.items & IT_STRENGTH);
990 sprint(self, "^3Strength has worn off\n");
995 if (time < self.strength_finished)
997 self.items = self.items | IT_STRENGTH;
998 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1001 if (self.items & IT_INVINCIBLE)
1003 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1004 if (time > self.invincible_finished)
1006 self.items = self.items - (self.items & IT_INVINCIBLE);
1007 sprint(self, "^3Shield has worn off\n");
1012 if (time < self.invincible_finished)
1014 self.items = self.items | IT_INVINCIBLE;
1015 sprint(self, "^3Shield surrounds you\n");
1019 if (cvar("g_fullbrightplayers"))
1020 self.effects = self.effects | EF_FULLBRIGHT;
1022 // midair gamemode: damage only while in the air
1023 // if in midair mode, being on ground grants temporary invulnerability
1024 // (this is so that multishot weapon don't clear the ground flag on the
1025 // first damage in the frame, leaving the player vulnerable to the
1026 // remaining hits in the same frame)
1027 if (self.flags & FL_ONGROUND)
1029 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1031 if (time < self.spawnshieldtime)
1032 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1035 float CalcRegen(float current, float stable, float regenfactor)
1037 if(current > stable)
1039 else if(current > stable - 0.25) // when close enough, "snap"
1042 return min(stable, current + (stable - current) * regenfactor * frametime);
1045 void player_regen (void)
1047 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1048 maxh = cvar("g_balance_health_stable");
1049 maxa = cvar("g_balance_armor_stable");
1050 limith = cvar("g_balance_health_limit");
1051 limita = cvar("g_balance_armor_limit");
1053 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1056 max_mod = regen_mod = rot_mod = limit_mod = 1;
1058 if (self.runes & RUNE_REGEN)
1060 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1062 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1063 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1064 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1068 regen_mod = cvar("g_balance_rune_regen_regenrate");
1069 max_mod = cvar("g_balance_rune_regen_hpmod");
1070 limit_mod = cvar("g_balance_rune_regen_limitmod");
1073 else if (self.runes & CURSE_VENOM)
1075 max_mod = cvar("g_balance_curse_venom_hpmod");
1076 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1077 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1079 rot_mod = cvar("g_balance_curse_venom_rotrate");
1080 limit_mod = cvar("g_balance_curse_venom_limitmod");
1081 //if (!self.runes & RUNE_REGEN)
1082 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1084 maxh = maxh * max_mod;
1085 //maxa = maxa * max_mod;
1086 limith = limith * limit_mod;
1087 limita = limita * limit_mod;
1089 if (self.armorvalue > maxa)
1091 if (time > self.pauserotarmor_finished)
1093 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1094 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1097 else if (self.armorvalue < maxa)
1099 if (time > self.pauseregen_finished)
1101 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1102 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1105 if (self.health > maxh)
1107 if (time > self.pauserothealth_finished)
1109 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1110 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1113 else if (self.health < maxh)
1115 if (time > self.pauseregen_finished)
1117 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1118 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1122 if (self.health > limith)
1123 self.health = limith;
1124 if (self.armorvalue > limita)
1125 self.armorvalue = limita;
1127 // if player rotted to death... die!
1129 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1133 ======================
1134 spectate mode routines
1135 ======================
1137 void SpectateCopy(entity spectatee) {
1138 self.armortype = spectatee.armortype;
1139 self.armorvalue = spectatee.armorvalue;
1140 self.currentammo = spectatee.currentammo;
1141 self.effects = spectatee.effects;
1142 self.health = spectatee.health;
1144 self.items = spectatee.items;
1145 self.punchangle = spectatee.punchangle;
1146 self.view_ofs = spectatee.view_ofs;
1147 self.v_angle = spectatee.v_angle;
1148 self.viewzoom = spectatee.viewzoom;
1149 self.velocity = spectatee.velocity;
1150 self.dmg_take = spectatee.dmg_take;
1151 self.dmg_save = spectatee.dmg_save;
1152 self.dmg_inflictor = spectatee.dmg_inflictor;
1153 self.angles = spectatee.v_angle;
1154 self.fixangle = TRUE;
1155 setorigin(self, spectatee.origin);
1156 setsize(self, spectatee.mins, spectatee.maxs);
1159 void SpectateUpdate() {
1161 PutObserverInServer();
1163 if (self != self.enemy) {
1164 if(self.enemy.flags & FL_NOTARGET)
1165 PutObserverInServer();
1166 SpectateCopy(self.enemy);
1167 //msg_entity = self;
1168 //WriteByte(MSG_ONE, SVC_SETANGLE);
1169 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1170 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1171 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1175 float SpectateNext() {
1176 other = find(self.enemy, classname, "player");
1178 other = find(other, classname, "player");
1183 if(self.enemy.classname == "player") {
1185 WriteByte(MSG_ONE, SVC_SETVIEW);
1186 WriteEntity(MSG_ONE, self.enemy);
1187 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1197 ShowRespawnCountdown()
1199 Update a respawn countdown display.
1202 void ShowRespawnCountdown()
1205 if(self.deadflag == DEAD_NO) // just respawned?
1209 number = ceil(self.death_time - time);
1212 if(number <= self.respawn_countdown)
1214 self.respawn_countdown = number - 1;
1215 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
1216 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1221 void LeaveSpectatorMode()
1223 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1224 self.classname = "player";
1225 if(cvar("g_campaign") || cvar("g_balance_teams"))
1226 JoinBestTeam(self, 0);
1227 if(cvar("g_campaign"))
1228 campaign_bots_may_start = 1;
1229 PutClientInServer();
1230 if(!(self.flags & FL_NOTARGET))
1231 bprint ("^4", self.netname, "^4 is playing now\n");
1232 centerprint(self,"");
1235 stuffcmd(self,"menu_showteamselect\n");
1244 Called every frame for each client before the physics are run
1247 void() ctf_setstatus;
1248 .float vote_nagtime;
1249 void PlayerPreThink (void)
1254 if(self.version_nagtime)
1255 if(self.cvar_g_nexuizversion)
1256 if(time > self.version_nagtime)
1258 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1259 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1261 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");
1262 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1264 self.version_nagtime = 0;
1268 if(self.cvar_scr_centertime)
1269 if(time > self.vote_nagtime)
1272 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1276 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1278 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1279 self.max_armorvalue = 0;
1282 if(self.classname == "player") {
1283 local vector m1, m2;
1285 // if(self.netname == "Wazat")
1286 // bprint(self.classname, "\n");
1288 CheckRules_Player();
1291 PrintWelcomeMessage(self);
1293 if(g_lms || !cvar("sv_spectate"))
1294 if((time - self.jointime) <= cvar("welcome_message_time"))
1295 PrintWelcomeMessage(self);
1297 if (intermission_running)
1299 IntermissionThink (); // otherwise a button could be missed between
1300 return; // the think tics
1303 if(time > self.teleport_time)
1305 self.effects = self.effects - (self.effects & EF_NODRAW);
1306 if(self.weaponentity)
1307 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1310 Nixnex_GiveCurrentWeapon();
1312 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1313 UpdateSelectedPlayer();
1315 if (self.deadflag != DEAD_NO)
1317 float button_pressed, force_respawn;
1319 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1320 force_respawn = (g_lms || cvar("g_forced_respawn"));
1321 if (self.deadflag == DEAD_DYING)
1324 self.deadflag = DEAD_RESPAWNING;
1325 else if(!button_pressed)
1326 self.deadflag = DEAD_DEAD;
1328 else if (self.deadflag == DEAD_DEAD)
1331 self.deadflag = DEAD_RESPAWNABLE;
1333 else if (self.deadflag == DEAD_RESPAWNABLE)
1336 self.deadflag = DEAD_RESPAWNING;
1338 else if (self.deadflag == DEAD_RESPAWNING)
1340 if(time > self.death_time)
1343 ShowRespawnCountdown();
1347 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1351 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1352 dist = self.oldorigin - self.origin;
1354 self.lms_traveled_distance += fabs(vlen(dist));
1356 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1358 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1359 self.lms_traveled_distance = 0;
1362 if(time > self.lms_nextcheck)
1364 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1365 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1367 centerprint(self, cvar_string("g_lms_campcheck_message"));
1368 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1369 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1370 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');
1372 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1373 self.lms_traveled_distance = 0;
1377 if (self.button5 && !self.hook.state)
1382 self.view_ofs = PL_CROUCH_VIEW_OFS;
1383 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1384 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1391 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1392 if (!trace_startsolid)
1394 self.crouch = FALSE;
1395 self.view_ofs = PL_VIEW_OFS;
1396 setsize (self, PL_MIN, PL_MAX);
1401 if(cvar("sv_defaultcharacter") == 1) {
1402 local string defaultmodel;
1403 defaultmodel = cvar_string("sv_defaultplayermodel");
1405 if (defaultmodel != self.model)
1409 setmodel_lod (self, defaultmodel);
1410 setsize (self, m1, m2);
1413 if (self.skin != cvar("sv_defaultplayerskin"))
1414 self.skin = cvar("sv_defaultplayerskin");
1416 if (self.playermodel != self.model)
1418 self.playermodel = CheckPlayerModel(self.playermodel);
1421 setmodel_lod (self, self.playermodel);
1422 setsize (self, m1, m2);
1425 f = RestrictSkin(stof(self.playerskin));
1430 if(strlen(cvar_string("sv_defaultplayercolors")))
1431 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1432 setcolor(self, cvar("sv_defaultplayercolors"));
1434 GrapplingHookFrame();
1439 float zoomfactor, zoomspeed, zoomdir;
1440 zoomfactor = self.cvar_cl_zoomfactor;
1441 if(zoomfactor < 1 || zoomfactor > 16)
1443 zoomspeed = self.cvar_cl_zoomspeed;
1444 if(zoomspeed >= 0) // < 0 is instant zoom
1445 if(zoomspeed < 0.5 || zoomspeed > 16)
1448 zoomdir = self.button4;
1450 if(self.weapon == WEP_NEX)
1455 self.has_zoomed = 1;
1459 if(zoomspeed <= 0) // instant zoom
1462 self.viewzoom = 1 / zoomfactor;
1468 // geometric zoom would be:
1469 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1470 // however, testing showed that arithmetic/harmonic zoom works better
1472 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1473 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1474 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1476 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1477 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1478 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1482 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1490 minstagib_ammocheck();
1495 //self.angles_y=self.v_angle_y + 90; // temp
1497 //if (TetrisPreFrame()) return;
1498 } else if(gameover) {
1499 if (intermission_running)
1500 IntermissionThink (); // otherwise a button could be missed between
1502 } else if(self.classname == "observer") {
1504 if (self.flags & FL_JUMPRELEASED) {
1505 if (self.button2 && self.version == cvar("gameversion")) {
1506 self.welcomemessage_time = 0;
1507 self.flags = self.flags - FL_JUMPRELEASED;
1508 LeaveSpectatorMode();
1510 } else if(self.button0 && self.version == cvar("gameversion")) {
1511 self.welcomemessage_time = 0;
1512 self.flags = self.flags - FL_JUMPRELEASED;
1513 if(SpectateNext() == 1) {
1514 self.classname = "spectator";
1518 if (!(self.button0 || self.button2)) {
1519 self.flags = self.flags | FL_JUMPRELEASED;
1522 PrintWelcomeMessage(self);
1523 } else if(self.classname == "spectator") {
1524 if (self.flags & FL_JUMPRELEASED) {
1525 if (self.button2 && self.version == cvar("gameversion")) {
1526 self.welcomemessage_time = 0;
1527 self.flags = self.flags - FL_JUMPRELEASED;
1528 LeaveSpectatorMode();
1530 } else if(self.button0) {
1531 self.welcomemessage_time = 0;
1532 self.flags = self.flags - FL_JUMPRELEASED;
1533 if(SpectateNext() == 1) {
1534 self.classname = "spectator";
1536 self.classname = "observer";
1537 PutClientInServer();
1539 } else if (self.button3) {
1540 self.welcomemessage_time = 0;
1541 self.flags = self.flags - FL_JUMPRELEASED;
1542 self.classname = "observer";
1543 PutClientInServer();
1548 if (!(self.button0 || self.button3)) {
1549 self.flags = self.flags | FL_JUMPRELEASED;
1552 PrintWelcomeMessage(self);
1553 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1562 Called every frame for each client after the physics are run
1565 void PlayerPostThink (void)
1567 // Savage: Check for nameless players
1568 if (strlen(self.netname) < 1) {
1569 self.netname = "Player";
1570 stuffcmd(self, "seta _cl_name Player\n");
1573 if(self.classname == "player") {
1574 CheckRules_Player();
1579 if (intermission_running)
1580 return; // intermission or finale
1582 //PrintWelcomeMessage(self);
1583 //if (TetrisPostFrame()) return;
1585 // restart countdown
1586 if(time < restart_countdown)
1591 sec = ceil(restart_countdown-time);
1592 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1593 centerprint(self, s);
1594 self.movetype = MOVETYPE_NONE;
1595 self.velocity = '0 0 0';
1596 self.avelocity = '0 0 0';
1597 self.movement = '0 0 0';
1599 else if(self.movetype == MOVETYPE_NONE)
1601 self.movetype = MOVETYPE_WALK;
1602 centerprint(self, "\n");
1604 } else if (self.classname == "observer") {
1606 } else if (self.classname == "spectator") {