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 setmodel_lod(entity e, string modelname)
251 #ifdef ALLOW_VARIABLE_LOD
254 // FIXME: this only supports 3-letter extensions
255 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
259 setmodel(e, s); // players have high precision
260 self.modelindex_lod1 = self.modelindex;
263 self.modelindex_lod1 = -1;
265 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
269 setmodel(e, s); // players have high precision
270 self.modelindex_lod2 = self.modelindex;
273 self.modelindex_lod2 = -1;
275 precache_model(modelname);
276 setmodel(e, modelname); // players have high precision
277 self.modelindex_lod0 = self.modelindex;
279 if(self.modelindex_lod1 < 0)
280 self.modelindex_lod1 = self.modelindex;
282 if(self.modelindex_lod2 < 0)
283 self.modelindex_lod2 = self.modelindex;
285 precache_model(modelname);
286 setmodel(e, modelname); // players have high precision
288 player_setupanimsformodel();
295 putting a client as observer in the server
298 void PutObserverInServer (void)
301 spot = SelectSpawnPoint (TRUE);
302 RemoveGrapplingHook(self); // Wazat's Grappling Hook
304 if(clienttype(self) == CLIENTTYPE_REAL)
307 WriteByte(MSG_ONE, SVC_SETVIEW);
308 WriteEntity(MSG_ONE, self);
312 kh_Key_DropAll(self, TRUE);
315 DropFlag(self.flagcarried);
317 WaypointSprite_PlayerDead();
319 DistributeFragsAmongTeam(self, self.team, 1);
321 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
322 bprint ("^4", self.netname, "^4 has no more lives left\n");
323 else if(self.killcount != -666)
324 bprint ("^4", self.netname, "^4 is spectating now\n");
326 self.classname = "observer";
328 self.takedamage = DAMAGE_NO;
329 self.solid = SOLID_NOT;
330 self.movetype = MOVETYPE_NOCLIP;
331 self.flags = FL_CLIENT | FL_NOTARGET;
332 self.armorvalue = 666;
334 self.armorvalue = cvar("g_balance_armor_start");
335 self.pauserotarmor_finished = 0;
336 self.pauserothealth_finished = 0;
337 self.pauseregen_finished = 0;
338 self.damageforcescale = 0;
346 self.pain_finished = 0;
347 self.strength_finished = 0;
348 self.invincible_finished = 0;
350 self.think = SUB_Null;
354 self.deadflag = DEAD_NO;
355 self.angles = spot.angles;
357 self.fixangle = TRUE;
360 self.view_ofs = PL_VIEW_OFS;
361 setorigin (self, spot.origin);
362 setsize (self, '0 0 0', '0 0 0');
363 self.oldorigin = self.origin;
368 self.weaponmodel = "";
369 self.weaponentity = world;
370 self.killcount = -666;
371 self.velocity = '0 0 0';
372 self.avelocity = '0 0 0';
373 self.punchangle = '0 0 0';
374 self.punchvector = '0 0 0';
375 self.oldvelocity = self.velocity;
376 self.customizeentityforclient = Client_customizeentityforclient;
382 Spawnqueue_Insert(self);
386 Spawnqueue_Unmark(self);
387 Spawnqueue_Remove(self);
399 Called when a client spawns in the server
402 void PutClientInServer (void)
404 if(clienttype(self) == CLIENTTYPE_BOT)
406 self.classname = "player";
408 else if(clienttype(self) == CLIENTTYPE_REAL)
411 WriteByte(MSG_ONE, SVC_SETVIEW);
412 WriteEntity(MSG_ONE, self);
415 // player is dead and becomes observer
416 if(g_lms && self.frags < 1)
417 self.classname = "observer";
421 self.classname = "observer";
423 if(self.classname == "player") {
426 spot = SelectSpawnPoint (FALSE);
428 RemoveGrapplingHook(self); // Wazat's Grappling Hook
430 self.classname = "player";
431 self.iscreature = TRUE;
432 self.movetype = MOVETYPE_WALK;
433 self.solid = SOLID_SLIDEBOX;
434 self.flags = FL_CLIENT;
435 self.takedamage = DAMAGE_AIM;
437 self.air_finished = time + 12;
440 self.ammo_shells = start_ammo_shells;
441 self.ammo_nails = start_ammo_nails;
442 self.ammo_rockets = start_ammo_rockets;
443 self.ammo_cells = start_ammo_cells;
444 self.health = start_health;
445 self.armorvalue = start_armorvalue;
446 self.items = start_items;
447 self.switchweapon = start_switchweapon;
449 self.jump_interval = time;
451 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
452 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
453 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
454 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
455 self.damageforcescale = 2;
462 self.pain_finished = 0;
463 self.strength_finished = 0;
464 self.invincible_finished = 0;
466 //self.speed_finished = 0;
467 //self.slowmo_finished = 0;
468 // players have no think function
469 self.think = SUB_Null;
475 self.deadflag = DEAD_NO;
477 self.angles = spot.angles;
479 self.angles_z = 0; // never spawn tilted even if the spot says to
480 self.fixangle = TRUE; // turn this way immediately
481 self.velocity = '0 0 0';
482 self.avelocity = '0 0 0';
483 self.punchangle = '0 0 0';
484 self.punchvector = '0 0 0';
485 self.oldvelocity = self.velocity;
490 self.customizeentityforclient = Client_customizeentityforclient;
492 if(cvar("sv_defaultcharacter") == 1) {
493 local string defaultmodel;
494 defaultmodel = cvar_string("sv_defaultplayermodel");
495 setmodel_lod (self, defaultmodel);
496 self.skin = stof(cvar_string("sv_defaultplayerskin"));
498 self.playermodel = CheckPlayerModel(self.playermodel);
499 setmodel_lod (self, self.playermodel);
503 s = stof(self.playerskin);
512 self.skin = stof(self.playerskin);
515 if(strlen(cvar_string("sv_defaultplayercolors")))
516 setcolor(self, cvar("sv_defaultplayercolors"));
519 self.view_ofs = PL_VIEW_OFS;
520 setsize (self, PL_MIN, PL_MAX);
521 self.spawnorigin = spot.origin;
522 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
523 // don't reset back to last position, even if new position is stuck in solid
524 self.oldorigin = self.origin;
528 Spawnqueue_Remove(self);
529 Spawnqueue_Mark(self);
532 self.event_damage = PlayerDamage;
534 self.bot_attack = TRUE;
536 self.statdraintime = time + 5;
537 self.button0 = self.button1 = self.button2 = self.button3 = 0;
539 if(self.killcount == -666) {
546 self.cnt = WEP_LASER;
547 self.nixnex_lastchange_id = -1;
549 CL_SpawnWeaponentity();
550 self.alpha = default_player_alpha;
551 self.exteriorweaponentity.alpha = default_weapon_alpha;
553 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
554 self.lms_traveled_distance = 0;
556 if(cvar("spawn_debug"))
558 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
559 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
562 //stuffcmd(self, "chase_active 0");
563 //stuffcmd(self, "set viewsize $tmpviewsize \n");
565 if (cvar("g_spawnsound"))
566 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
569 if(self.team == assault_attacker_team)
570 centerprint(self, "You are attacking!\n");
572 centerprint(self, "You are defending!\n");
575 } else if(self.classname == "observer") {
576 PutObserverInServer ();
585 void SetNewParms (void)
595 void SetChangeParms (void)
604 Called when a client types 'kill' in the console
607 void ClientKill (void)
609 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
612 void FixClientCvars(entity e)
615 // send prediction settings to the client
616 stuffcmd(e, "\nin_bindmap 0 0\n");
617 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
618 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
619 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
620 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
621 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
622 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
623 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
624 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
625 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
626 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
627 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
628 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
629 stuffcmd(e, "cl_movement_edgefriction 1\n");
631 // notify about available teams
634 CheckAllowedTeams(e);
635 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
636 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
639 stuffcmd(e, "set _teams_available 0\n");
646 Called when a client connects to the server
649 string ColoredTeamName(float t);
650 //void dom_player_join_team(entity pl);
651 void ClientConnect (void)
656 if(Ban_IsClientBanned(self))
658 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
664 self.classname = "player_joining";
665 self.flags = self.flags | FL_CLIENT;
666 self.version_nagtime = time + 10 + random() * 10;
670 dprint("BUG player count is lower than zero, this cannot happen!\n");
677 // dom_player_join_team(self);
679 //JoinBestTeam(self, FALSE);
681 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
682 self.classname = "observer";
684 self.classname = "player";
685 campaign_bots_may_start = 1;
688 self.playerid = (playerid_last = playerid_last + 1);
689 if(cvar("sv_eventlog"))
691 if(clienttype(self) == CLIENTTYPE_REAL)
695 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
696 s = strcat(":team:", ftos(self.playerid), ":");
697 s = strcat(s, ftos(self.team));
698 GameLogEcho(s, FALSE);
701 //stuffcmd(self, "set tmpviewsize $viewsize \n");
703 bprint ("^4",self.netname);
704 bprint ("^4 connected");
706 if(g_domination || g_ctf)
708 bprint(" and joined the ");
709 bprint(ColoredTeamName(self.team));
714 self.welcomemessage_time = 0;
716 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
717 // TODO: is this being used for anything else than cd tracks?
718 // Remember: SVC_CDTRACK exists. Maybe it should be used.
720 FixClientCvars(self);
723 WaypointSprite_InitClient(self);
725 // Wazat's grappling hook
726 SetGrappleHookBindings();
728 // get autoswitch state from player when he toggles it
729 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
731 // get version info from player
732 stuffcmd(self, "cmd clientversion $gameversion\n");
734 // send all weapon info strings
735 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
737 while (wep <= WEP_LAST)
739 weapon_action(wep, WR_REGISTER);
743 // get other cvars from player
746 // set cvar for team scoreboard
750 t = cvar("teamplay");
751 // 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
752 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
755 stuffcmd(self, "set teamplay 0\n");
759 self.frags = LMS_NewPlayerLives();
765 self.classname = "observer";
766 Spawnqueue_Insert(self);
769 bot_relinkplayerlist();
771 self.jointime = time;
778 Called when a client disconnects from the server
781 void(entity e) DropFlag;
782 .entity chatbubbleentity;
783 .entity teambubbleentity;
784 void ClientDisconnect (void)
787 if(cvar("sv_eventlog"))
788 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
789 bprint ("^4",self.netname);
790 bprint ("^4 disconnected\n");
792 if (self.chatbubbleentity)
794 remove (self.chatbubbleentity);
795 self.chatbubbleentity = world;
798 if (self.teambubbleentity)
800 remove (self.teambubbleentity);
801 self.teambubbleentity = world;
804 WaypointSprite_PlayerGone();
807 kh_Key_DropAll(self, TRUE);
810 DropFlag(self.flagcarried);
812 DistributeFragsAmongTeam(self, self.team, 1);
815 self.flags = self.flags - (self.flags & FL_CLIENT);
816 bot_relinkplayerlist();
820 if(self.weaponentity)
821 if(self.weaponentity.lasertarget)
822 remove(self.weaponentity.lasertarget);
826 Spawnqueue_Unmark(self);
827 Spawnqueue_Remove(self);
835 void() ChatBubbleThink =
837 self.nextthink = time;
838 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
840 self.owner.chatbubbleentity = world;
844 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
845 if (self.owner.buttonchat && !self.owner.deadflag)
846 self.model = self.mdl;
851 void() UpdateChatBubble =
853 if (!self.modelindex)
855 // spawn a chatbubble entity if needed
856 if (!self.chatbubbleentity)
858 self.chatbubbleentity = spawn();
859 self.chatbubbleentity.owner = self;
860 self.chatbubbleentity.exteriormodeltoclient = self;
861 self.chatbubbleentity.think = ChatBubbleThink;
862 self.chatbubbleentity.nextthink = time;
863 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
864 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
865 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
866 self.chatbubbleentity.model = "";
867 self.chatbubbleentity.effects = EF_LOWPRECISION;
872 void() TeamBubbleThink =
874 self.nextthink = time;
875 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
877 self.owner.teambubbleentity = world;
881 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
882 if (self.owner.buttonchat || self.owner.deadflag)
885 self.model = self.mdl;
889 float() TeamBubble_customizeentityforclient
891 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
894 void() UpdateTeamBubble =
896 if (!self.modelindex || !cvar("teamplay"))
898 // spawn a teambubble entity if needed
899 if (!self.teambubbleentity && cvar("teamplay"))
901 self.teambubbleentity = spawn();
902 self.teambubbleentity.owner = self;
903 self.teambubbleentity.exteriormodeltoclient = self;
904 self.teambubbleentity.think = TeamBubbleThink;
905 self.teambubbleentity.nextthink = time;
906 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
907 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
908 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
909 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
910 self.teambubbleentity.mdl = self.teambubbleentity.model;
911 self.teambubbleentity.model = self.teambubbleentity.mdl;
912 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
913 self.teambubbleentity.effects = EF_LOWPRECISION;
917 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
918 // added to the model skins
919 /*void() UpdateColorModHack =
922 c = self.clientcolors & 15;
923 // LordHavoc: only bothering to support white, green, red, yellow, blue
924 if (teamplay == 0) self.colormod = '0 0 0';
925 else if (c == 0) self.colormod = '1.00 1.00 1.00';
926 else if (c == 3) self.colormod = '0.10 1.73 0.10';
927 else if (c == 4) self.colormod = '1.73 0.10 0.10';
928 else if (c == 12) self.colormod = '1.22 1.22 0.10';
929 else if (c == 13) self.colormod = '0.10 0.10 1.73';
930 else self.colormod = '1 1 1';
939 void player_powerups (void)
943 self.effects = EF_FULLBRIGHT;
944 if (self.items & IT_STRENGTH)
946 if (time > self.strength_finished)
948 self.alpha = default_player_alpha;
949 self.exteriorweaponentity.alpha = default_weapon_alpha;
950 self.items = self.items - (self.items & IT_STRENGTH);
951 sprint(self, "^3Invisibility has worn off\n");
956 if (time < self.strength_finished)
958 self.alpha = cvar("g_minstagib_invis_alpha");
959 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
960 self.items = self.items | IT_STRENGTH;
961 sprint(self, "^3You are invisible\n");
965 if (self.items & IT_INVINCIBLE)
967 if (time > self.invincible_finished)
969 self.items = self.items - (self.items & IT_INVINCIBLE);
970 sprint(self, "^3Speed has worn off\n");
975 if (time < self.invincible_finished)
977 self.items = self.items | IT_INVINCIBLE;
978 sprint(self, "^3You are on speed\n");
984 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
985 if (self.items & IT_STRENGTH)
987 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
988 if (time > self.strength_finished)
990 self.items = self.items - (self.items & IT_STRENGTH);
991 sprint(self, "^3Strength has worn off\n");
996 if (time < self.strength_finished)
998 self.items = self.items | IT_STRENGTH;
999 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1002 if (self.items & IT_INVINCIBLE)
1004 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1005 if (time > self.invincible_finished)
1007 self.items = self.items - (self.items & IT_INVINCIBLE);
1008 sprint(self, "^3Shield has worn off\n");
1013 if (time < self.invincible_finished)
1015 self.items = self.items | IT_INVINCIBLE;
1016 sprint(self, "^3Shield surrounds you\n");
1020 if (cvar("g_fullbrightplayers"))
1021 self.effects = self.effects | EF_FULLBRIGHT;
1023 // midair gamemode: damage only while in the air
1024 // if in midair mode, being on ground grants temporary invulnerability
1025 // (this is so that multishot weapon don't clear the ground flag on the
1026 // first damage in the frame, leaving the player vulnerable to the
1027 // remaining hits in the same frame)
1028 if (self.flags & FL_ONGROUND)
1030 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1032 if (time < self.spawnshieldtime)
1033 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1036 float CalcRegen(float current, float stable, float regenfactor)
1038 if(current > stable)
1040 else if(current > stable - 0.25) // when close enough, "snap"
1043 return min(stable, current + (stable - current) * regenfactor * frametime);
1046 void player_regen (void)
1048 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1049 maxh = cvar("g_balance_health_stable");
1050 maxa = cvar("g_balance_armor_stable");
1051 limith = cvar("g_balance_health_limit");
1052 limita = cvar("g_balance_armor_limit");
1054 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1057 max_mod = regen_mod = rot_mod = limit_mod = 1;
1059 if (self.runes & RUNE_REGEN)
1061 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1063 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1064 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1065 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1069 regen_mod = cvar("g_balance_rune_regen_regenrate");
1070 max_mod = cvar("g_balance_rune_regen_hpmod");
1071 limit_mod = cvar("g_balance_rune_regen_limitmod");
1074 else if (self.runes & CURSE_VENOM)
1076 max_mod = cvar("g_balance_curse_venom_hpmod");
1077 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1078 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1080 rot_mod = cvar("g_balance_curse_venom_rotrate");
1081 limit_mod = cvar("g_balance_curse_venom_limitmod");
1082 //if (!self.runes & RUNE_REGEN)
1083 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1085 maxh = maxh * max_mod;
1086 //maxa = maxa * max_mod;
1087 limith = limith * limit_mod;
1088 limita = limita * limit_mod;
1090 if (self.armorvalue > maxa)
1092 if (time > self.pauserotarmor_finished)
1094 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1095 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1098 else if (self.armorvalue < maxa)
1100 if (time > self.pauseregen_finished)
1102 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1103 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1106 if (self.health > maxh)
1108 if (time > self.pauserothealth_finished)
1110 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1111 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1114 else if (self.health < maxh)
1116 if (time > self.pauseregen_finished)
1118 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1119 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1123 if (self.health > limith)
1124 self.health = limith;
1125 if (self.armorvalue > limita)
1126 self.armorvalue = limita;
1128 // if player rotted to death... die!
1130 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1134 ======================
1135 spectate mode routines
1136 ======================
1138 void SpectateCopy(entity spectatee) {
1139 self.armortype = spectatee.armortype;
1140 self.armorvalue = spectatee.armorvalue;
1141 self.currentammo = spectatee.currentammo;
1142 self.effects = spectatee.effects;
1143 self.health = spectatee.health;
1145 self.items = spectatee.items;
1146 self.punchangle = spectatee.punchangle;
1147 self.view_ofs = spectatee.view_ofs;
1148 self.v_angle = spectatee.v_angle;
1149 self.viewzoom = spectatee.viewzoom;
1150 setorigin(self, spectatee.origin);
1151 setsize(self, spectatee.mins, spectatee.maxs);
1154 void SpectateUpdate() {
1156 PutObserverInServer();
1158 if (self != self.enemy) {
1159 if(self.enemy.flags & FL_NOTARGET)
1160 PutObserverInServer();
1161 SpectateCopy(self.enemy);
1162 self.dmg_take = self.enemy.dmg_take;
1163 self.dmg_save = self.enemy.dmg_save;
1164 self.dmg_inflictor = self.enemy.dmg_inflictor;
1165 self.fixangle = TRUE;
1166 self.angles = self.enemy.v_angle;
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)
1252 if(self.version_nagtime)
1253 if(self.cvar_g_nexuizversion)
1254 if(time > self.version_nagtime)
1256 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1257 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1259 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");
1260 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1262 self.version_nagtime = 0;
1266 if(self.cvar_scr_centertime)
1267 if(time > self.vote_nagtime)
1270 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1274 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1276 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1277 self.max_armorvalue = 0;
1280 if(self.classname == "player") {
1281 local vector m1, m2;
1283 // if(self.netname == "Wazat")
1284 // bprint(self.classname, "\n");
1286 CheckRules_Player();
1289 PrintWelcomeMessage(self);
1291 if(g_lms || !cvar("sv_spectate"))
1292 if((time - self.jointime) <= cvar("welcome_message_time"))
1293 PrintWelcomeMessage(self);
1295 if (intermission_running)
1297 IntermissionThink (); // otherwise a button could be missed between
1298 return; // the think tics
1301 if(time > self.teleport_time)
1303 self.effects = self.effects - (self.effects & EF_NODRAW);
1304 if(self.weaponentity)
1305 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1308 Nixnex_GiveCurrentWeapon();
1310 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1311 UpdateSelectedPlayer();
1313 if (self.deadflag != DEAD_NO)
1315 float button_pressed, force_respawn;
1317 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1318 force_respawn = (g_lms || cvar("g_forced_respawn"));
1319 if (self.deadflag == DEAD_DYING)
1322 self.deadflag = DEAD_RESPAWNING;
1323 else if(!button_pressed)
1324 self.deadflag = DEAD_DEAD;
1326 else if (self.deadflag == DEAD_DEAD)
1329 self.deadflag = DEAD_RESPAWNABLE;
1331 else if (self.deadflag == DEAD_RESPAWNABLE)
1334 self.deadflag = DEAD_RESPAWNING;
1336 else if (self.deadflag == DEAD_RESPAWNING)
1338 if(time > self.death_time)
1341 ShowRespawnCountdown();
1345 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1349 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1350 dist = self.oldorigin - self.origin;
1352 self.lms_traveled_distance += fabs(vlen(dist));
1354 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1356 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1357 self.lms_traveled_distance = 0;
1360 if(time > self.lms_nextcheck)
1362 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1363 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1365 centerprint(self, cvar_string("g_lms_campcheck_message"));
1366 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1367 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1368 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');
1370 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1371 self.lms_traveled_distance = 0;
1375 if (self.button5 && !self.hook.state)
1380 self.view_ofs = PL_CROUCH_VIEW_OFS;
1381 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1382 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1389 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1390 if (!trace_startsolid)
1392 self.crouch = FALSE;
1393 self.view_ofs = PL_VIEW_OFS;
1394 setsize (self, PL_MIN, PL_MAX);
1399 if(cvar("sv_defaultcharacter") == 1) {
1400 local string defaultmodel;
1401 defaultmodel = cvar_string("sv_defaultplayermodel");
1403 if (defaultmodel != self.model)
1407 setmodel_lod (self, defaultmodel);
1408 setsize (self, m1, m2);
1411 if (self.skin != cvar("sv_defaultplayerskin"))
1412 self.skin = cvar("sv_defaultplayerskin");
1414 if (self.playermodel != self.model)
1416 self.playermodel = CheckPlayerModel(self.playermodel);
1419 setmodel_lod (self, self.playermodel);
1420 setsize (self, m1, m2);
1425 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1426 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1430 if (self.skin != stof(self.playerskin))
1431 self.skin = stof(self.playerskin);
1435 if(strlen(cvar_string("sv_defaultplayercolors")))
1436 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1437 setcolor(self, cvar("sv_defaultplayercolors"));
1439 GrapplingHookFrame();
1444 float zoomfactor, zoomspeed, zoomdir;
1445 zoomfactor = self.cvar_cl_zoomfactor;
1446 if(zoomfactor < 1 || zoomfactor > 16)
1448 zoomspeed = self.cvar_cl_zoomspeed;
1449 if(zoomspeed >= 0) // < 0 is instant zoom
1450 if(zoomspeed < 0.5 || zoomspeed > 16)
1453 zoomdir = self.button4;
1455 if(self.weapon == WEP_NEX)
1460 self.has_zoomed = 1;
1464 if(zoomspeed <= 0) // instant zoom
1467 self.viewzoom = 1 / zoomfactor;
1473 // geometric zoom would be:
1474 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1475 // however, testing showed that arithmetic/harmonic zoom works better
1477 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1478 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1479 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1481 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1482 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1483 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1487 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1495 minstagib_ammocheck();
1500 //self.angles_y=self.v_angle_y + 90; // temp
1502 //if (TetrisPreFrame()) return;
1503 } else if(gameover) {
1504 if (intermission_running)
1505 IntermissionThink (); // otherwise a button could be missed between
1507 } else if(self.classname == "observer") {
1509 if (self.flags & FL_JUMPRELEASED) {
1510 if (self.button2 && self.version == cvar("gameversion")) {
1511 self.welcomemessage_time = 0;
1512 self.flags = self.flags - FL_JUMPRELEASED;
1513 LeaveSpectatorMode();
1515 } else if(self.button0 && self.version == cvar("gameversion")) {
1516 self.welcomemessage_time = 0;
1517 self.flags = self.flags - FL_JUMPRELEASED;
1518 if(SpectateNext() == 1) {
1519 self.classname = "spectator";
1523 if (!(self.button0 || self.button2)) {
1524 self.flags = self.flags | FL_JUMPRELEASED;
1527 PrintWelcomeMessage(self);
1528 } else if(self.classname == "spectator") {
1529 if (self.flags & FL_JUMPRELEASED) {
1530 if (self.button2 && self.version == cvar("gameversion")) {
1531 self.welcomemessage_time = 0;
1532 self.flags = self.flags - FL_JUMPRELEASED;
1533 LeaveSpectatorMode();
1535 } else if(self.button0) {
1536 self.welcomemessage_time = 0;
1537 self.flags = self.flags - FL_JUMPRELEASED;
1538 if(SpectateNext() == 1) {
1539 self.classname = "spectator";
1541 self.classname = "observer";
1542 PutClientInServer();
1544 } else if (self.button3) {
1545 self.welcomemessage_time = 0;
1546 self.flags = self.flags - FL_JUMPRELEASED;
1547 self.classname = "observer";
1548 PutClientInServer();
1553 if (!(self.button0 || self.button3)) {
1554 self.flags = self.flags | FL_JUMPRELEASED;
1557 PrintWelcomeMessage(self);
1558 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1567 Called every frame for each client after the physics are run
1570 void PlayerPostThink (void)
1572 // Savage: Check for nameless players
1573 if (strlen(self.netname) < 1) {
1574 self.netname = "Player";
1575 stuffcmd(self, "seta _cl_name Player\n");
1578 if(self.classname == "player") {
1579 CheckRules_Player();
1584 if (intermission_running)
1585 return; // intermission or finale
1587 //PrintWelcomeMessage(self);
1588 //if (TetrisPostFrame()) return;
1590 // restart countdown
1591 if(time < restart_countdown)
1596 sec = ceil(restart_countdown-time);
1597 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1598 centerprint(self, s);
1599 self.movetype = MOVETYPE_NONE;
1600 self.velocity = '0 0 0';
1601 self.avelocity = '0 0 0';
1602 self.movement = '0 0 0';
1604 else if(self.movetype == MOVETYPE_NONE)
1606 self.movetype = MOVETYPE_WALK;
1607 centerprint(self, "\n");
1609 } else if (self.classname == "observer") {
1611 } else if (self.classname == "spectator") {