1 void info_player_survivor (void)
3 info_player_deathmatch();
6 void info_player_start (void)
8 info_player_deathmatch();
11 void info_player_deathmatch (void)
13 self.classname = "info_player_deathmatch";
14 relocate_spawnpoint();
17 void() spawnpoint_use =
22 self.team = activator.team;
23 some_spawn_has_been_used = 1;
29 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
31 local entity spot, player, nextspot, previousspot, newfirstspot;
40 nextspot = spot.chain;
41 // count team mismatches as bad spots
43 local float spotactive;
46 // filter out spots for assault
47 if(spot.target != "") {
49 ent = find(world, targetname, spot.target);
51 if(ent.classname == "target_objective")
52 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
54 ent = find(ent, targetname, spot.target);
58 if ((!teamcheck || spot.team == teamcheck) && spotactive > 0)
65 if (vlen(player.origin - spot.origin) < mindist)
67 player = player.chain;
73 previousspot.chain = spot;
80 spawn_allgood = FALSE;
84 // if we couldn't find ANY good points, return world
88 entity Spawn_RandomPoint(entity firstspot)
92 // count number of spots
97 numspots = numspots + 1;
101 numspots = numspots * random();
103 while (spot.chain && numspots >= 1)
105 numspots = numspots - 1;
111 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
113 local entity best, spot, player;
114 local float bestrating, rating;
116 bestrating = -1000000;
125 rating = min(rating, vlen(player.origin - spot.origin));
126 player = player.chain;
128 rating = rating + random() * 16;
129 if (bestrating < rating)
143 Finds a point to respawn
146 entity SelectSpawnPoint (float anypoint)
148 local float teamcheck;
149 local entity firstspot_new;
150 local entity spot, firstspot, playerlist;
152 spot = find (world, classname, "testplayerstart");
158 if(!anypoint && have_team_spawns)
159 teamcheck = self.team;
161 // get the list of players
162 playerlist = findchain(classname, "player");
163 // get the entire list of spots
164 firstspot = findchain(classname, "info_player_deathmatch");
165 // filter out the bad ones
166 // (note this returns the original list if none survived)
167 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
169 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
171 // there is 50/50 chance of choosing a random spot or the furthest spot
172 // (this means that roughly every other spawn will be furthest, so you
173 // usually won't get fragged at spawn twice in a row)
174 if (arena_roundbased)
176 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
178 firstspot = firstspot_new;
179 spot = Spawn_RandomPoint(firstspot);
181 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
182 spot = Spawn_RandomPoint(firstspot);
184 spot = Spawn_FurthestPoint(firstspot, playerlist);
188 if(cvar("spawn_debug"))
192 if(some_spawn_has_been_used)
193 return world; // team can't spawn any more, because of actions of other team
195 error("Cannot find a spawn point - please fix the map!");
206 Checks if the argument string can be a valid playermodel.
207 Returns a valid one in doubt.
210 string FallbackPlayerModel = "models/player/marine.zym";
211 string CheckPlayerModel(string plyermodel) {
212 if(strlen(plyermodel) < 4)
213 return FallbackPlayerModel;
214 if( substring(plyermodel,0,14) != "models/player/")
215 return FallbackPlayerModel;
216 else if(cvar("sv_servermodelsonly"))
218 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
219 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
220 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
221 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
222 return FallbackPlayerModel;
223 if(!fexists(plyermodel))
224 return FallbackPlayerModel;
231 Client_customizeentityforclient
236 float Client_customizeentityforclient()
238 #ifdef ALLOW_VARIABLE_LOD
240 // other: the player viewing me
244 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
247 if(other.cvar_cl_playerdetailreduction <= 0)
249 if(other.cvar_cl_playerdetailreduction <= -2)
250 self.modelindex = self.modelindex_lod2;
251 else if(other.cvar_cl_playerdetailreduction <= -1)
252 self.modelindex = self.modelindex_lod1;
254 self.modelindex = self.modelindex_lod0;
258 distance = vlen(self.origin - other.origin);
259 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
261 self.modelindex = self.modelindex_lod2;
263 self.modelindex = self.modelindex_lod1;
265 self.modelindex = self.modelindex_lod0;
272 void UpdatePlayerSounds();
273 void setmodel_lod(entity e, string modelname)
275 #ifdef ALLOW_VARIABLE_LOD
278 // FIXME: this only supports 3-letter extensions
279 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
283 setmodel(e, s); // players have high precision
284 self.modelindex_lod1 = self.modelindex;
287 self.modelindex_lod1 = -1;
289 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
293 setmodel(e, s); // players have high precision
294 self.modelindex_lod2 = self.modelindex;
297 self.modelindex_lod2 = -1;
299 precache_model(modelname);
300 setmodel(e, modelname); // players have high precision
301 self.modelindex_lod0 = self.modelindex;
303 if(self.modelindex_lod1 < 0)
304 self.modelindex_lod1 = self.modelindex;
306 if(self.modelindex_lod2 < 0)
307 self.modelindex_lod2 = self.modelindex;
309 precache_model(modelname);
310 setmodel(e, modelname); // players have high precision
312 player_setupanimsformodel();
313 UpdatePlayerSounds();
320 putting a client as observer in the server
323 void PutObserverInServer (void)
326 spot = SelectSpawnPoint (TRUE);
328 error("No spawnpoints for observers?!?\n");
329 RemoveGrapplingHook(self); // Wazat's Grappling Hook
331 if(clienttype(self) == CLIENTTYPE_REAL)
334 WriteByte(MSG_ONE, SVC_SETVIEW);
335 WriteEntity(MSG_ONE, self);
339 kh_Key_DropAll(self, TRUE);
342 DropFlag(self.flagcarried);
344 WaypointSprite_PlayerDead();
346 DistributeFragsAmongTeam(self, self.team, 1);
348 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
349 bprint ("^4", self.netname, "^4 has no more lives left\n");
350 else if(self.killcount != -666)
351 bprint ("^4", self.netname, "^4 is spectating now\n");
353 self.classname = "observer";
355 self.takedamage = DAMAGE_NO;
356 self.solid = SOLID_NOT;
357 self.movetype = MOVETYPE_NOCLIP;
358 self.flags = FL_CLIENT | FL_NOTARGET;
359 self.armorvalue = 666;
361 self.armorvalue = cvar("g_balance_armor_start");
362 self.pauserotarmor_finished = 0;
363 self.pauserothealth_finished = 0;
364 self.pauseregen_finished = 0;
365 self.damageforcescale = 0;
373 self.pain_finished = 0;
374 self.strength_finished = 0;
375 self.invincible_finished = 0;
377 self.think = SUB_Null;
381 self.deadflag = DEAD_NO;
382 self.angles = spot.angles;
384 self.fixangle = TRUE;
387 self.view_ofs = PL_VIEW_OFS;
388 setorigin (self, spot.origin);
389 setsize (self, '0 0 0', '0 0 0');
390 self.oldorigin = self.origin;
395 self.weaponmodel = "";
396 self.weaponentity = world;
397 self.killcount = -666;
398 self.velocity = '0 0 0';
399 self.avelocity = '0 0 0';
400 self.punchangle = '0 0 0';
401 self.punchvector = '0 0 0';
402 self.oldvelocity = self.velocity;
403 self.customizeentityforclient = Client_customizeentityforclient;
410 Spawnqueue_Insert(self);
414 Spawnqueue_Unmark(self);
415 Spawnqueue_Remove(self);
422 float RestrictSkin(float s)
431 void FixPlayermodel()
433 local string defaultmodel;
434 local float defaultskin;
437 if(cvar("sv_defaultcharacter") == 1) {
443 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
444 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
447 if(defaultmodel == "")
449 defaultmodel = cvar_string("sv_defaultplayermodel");
450 defaultskin = cvar("sv_defaultplayerskin");
453 if (defaultmodel != self.model)
457 setmodel_lod (self, defaultmodel);
458 setsize (self, m1, m2);
461 self.skin = defaultskin;
463 if (self.playermodel != self.model)
465 self.playermodel = CheckPlayerModel(self.playermodel);
468 setmodel_lod (self, self.playermodel);
469 setsize (self, m1, m2);
472 self.skin = RestrictSkin(stof(self.playerskin));
476 if(strlen(cvar_string("sv_defaultplayercolors")))
477 if(self.clientcolors != cvar("sv_defaultplayercolors"))
478 setcolor(self, cvar("sv_defaultplayercolors"));
485 Called when a client spawns in the server
488 void PutClientInServer (void)
490 if(clienttype(self) == CLIENTTYPE_BOT)
492 self.classname = "player";
494 else if(clienttype(self) == CLIENTTYPE_REAL)
497 WriteByte(MSG_ONE, SVC_SETVIEW);
498 WriteEntity(MSG_ONE, self);
501 // player is dead and becomes observer
502 if(g_lms && self.frags < 1)
503 self.classname = "observer";
507 self.classname = "observer";
509 if(self.classname == "player") {
512 spot = SelectSpawnPoint (FALSE);
515 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
516 return; // spawn failed
519 RemoveGrapplingHook(self); // Wazat's Grappling Hook
521 self.classname = "player";
522 self.iscreature = TRUE;
523 self.movetype = MOVETYPE_WALK;
524 self.solid = SOLID_SLIDEBOX;
525 self.flags = FL_CLIENT;
526 self.takedamage = DAMAGE_AIM;
528 self.effects = EF_FULLBRIGHT;
531 self.air_finished = time + 12;
534 self.ammo_shells = start_ammo_shells;
535 self.ammo_nails = start_ammo_nails;
536 self.ammo_rockets = start_ammo_rockets;
537 self.ammo_cells = start_ammo_cells;
538 self.health = start_health;
539 self.armorvalue = start_armorvalue;
540 self.items = start_items;
541 self.switchweapon = start_switchweapon;
543 self.jump_interval = time;
545 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
546 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
547 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
548 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
549 self.damageforcescale = 2;
556 self.pain_finished = 0;
557 self.strength_finished = 0;
558 self.invincible_finished = 0;
560 //self.speed_finished = 0;
561 //self.slowmo_finished = 0;
562 // players have no think function
563 self.think = SUB_Null;
569 self.deadflag = DEAD_NO;
571 self.angles = spot.angles;
573 self.angles_z = 0; // never spawn tilted even if the spot says to
574 self.fixangle = TRUE; // turn this way immediately
575 self.velocity = '0 0 0';
576 self.avelocity = '0 0 0';
577 self.punchangle = '0 0 0';
578 self.punchvector = '0 0 0';
579 self.oldvelocity = self.velocity;
584 self.customizeentityforclient = Client_customizeentityforclient;
590 self.view_ofs = PL_VIEW_OFS;
591 setsize (self, PL_MIN, PL_MAX);
592 self.spawnorigin = spot.origin;
593 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
594 // don't reset back to last position, even if new position is stuck in solid
595 self.oldorigin = self.origin;
599 Spawnqueue_Remove(self);
600 Spawnqueue_Mark(self);
603 self.event_damage = PlayerDamage;
605 self.bot_attack = TRUE;
607 self.statdraintime = time + 5;
608 self.button0 = self.button1 = self.button2 = self.button3 = 0;
610 if(self.killcount == -666) {
617 self.cnt = WEP_LASER;
618 self.nixnex_lastchange_id = -1;
620 CL_SpawnWeaponentity();
621 self.alpha = default_player_alpha;
622 self.colormod = '1 1 1' * cvar("g_player_brightness");
623 self.exteriorweaponentity.alpha = default_weapon_alpha;
625 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
626 self.lms_traveled_distance = 0;
627 self.speedrunning = FALSE;
629 if(cvar("spawn_debug"))
631 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
632 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
635 //stuffcmd(self, "chase_active 0");
636 //stuffcmd(self, "set viewsize $tmpviewsize \n");
638 if (cvar("g_spawnsound"))
639 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
642 if(self.team == assault_attacker_team)
643 centerprint(self, "You are attacking!\n");
645 centerprint(self, "You are defending!\n");
648 } else if(self.classname == "observer") {
649 PutObserverInServer ();
658 void SetNewParms (void)
668 void SetChangeParms (void)
677 Called when a client types 'kill' in the console
680 void ClientKill (void)
682 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
685 void FixClientCvars(entity e)
688 // send prediction settings to the client
689 stuffcmd(e, "\nin_bindmap 0 0\n");
690 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
691 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
692 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
693 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
694 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
695 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
696 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
697 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
698 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
699 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
700 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
701 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
702 stuffcmd(e, "cl_movement_edgefriction 1\n");
704 // notify about available teams
707 CheckAllowedTeams(e);
708 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
709 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
712 stuffcmd(e, "set _teams_available 0\n");
719 Called when a client connects to the server
722 string ColoredTeamName(float t);
723 //void dom_player_join_team(entity pl);
724 void ClientConnect (void)
729 if(Ban_IsClientBanned(self))
731 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
737 self.classname = "player_joining";
738 self.flags = self.flags | FL_CLIENT;
739 self.version_nagtime = time + 10 + random() * 10;
743 dprint("BUG player count is lower than zero, this cannot happen!\n");
750 // dom_player_join_team(self);
752 //JoinBestTeam(self, FALSE);
754 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
755 self.classname = "observer";
757 self.classname = "player";
758 campaign_bots_may_start = 1;
761 self.playerid = (playerid_last = playerid_last + 1);
762 if(cvar("sv_eventlog"))
764 if(clienttype(self) == CLIENTTYPE_REAL)
768 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
769 s = strcat(":team:", ftos(self.playerid), ":");
770 s = strcat(s, ftos(self.team));
771 GameLogEcho(s, FALSE);
774 //stuffcmd(self, "set tmpviewsize $viewsize \n");
776 bprint ("^4",self.netname);
777 bprint ("^4 connected");
779 if(g_domination || g_ctf)
781 bprint(" and joined the ");
782 bprint(ColoredTeamName(self.team));
787 self.welcomemessage_time = 0;
789 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
790 // TODO: is this being used for anything else than cd tracks?
791 // Remember: SVC_CDTRACK exists. Maybe it should be used.
793 FixClientCvars(self);
796 WaypointSprite_InitClient(self);
798 // Wazat's grappling hook
799 SetGrappleHookBindings();
801 // get autoswitch state from player when he toggles it
802 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
804 // get version info from player
805 stuffcmd(self, "cmd clientversion $gameversion\n");
807 // send all weapon info strings
808 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
810 while (wep <= WEP_LAST)
812 weapon_action(wep, WR_REGISTER);
816 // get other cvars from player
819 // set cvar for team scoreboard
823 t = cvar("teamplay");
824 // 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
825 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
828 stuffcmd(self, "set teamplay 0\n");
832 self.frags = LMS_NewPlayerLives();
838 self.classname = "observer";
839 Spawnqueue_Insert(self);
842 bot_relinkplayerlist();
844 self.jointime = time;
851 Called when a client disconnects from the server
854 void(entity e) DropFlag;
855 .entity chatbubbleentity;
856 .entity teambubbleentity;
857 void ClientDisconnect (void)
860 if(cvar("sv_eventlog"))
861 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
862 bprint ("^4",self.netname);
863 bprint ("^4 disconnected\n");
865 if (self.chatbubbleentity)
867 remove (self.chatbubbleentity);
868 self.chatbubbleentity = world;
871 if (self.teambubbleentity)
873 remove (self.teambubbleentity);
874 self.teambubbleentity = world;
877 WaypointSprite_PlayerGone();
880 kh_Key_DropAll(self, TRUE);
883 DropFlag(self.flagcarried);
885 DistributeFragsAmongTeam(self, self.team, 1);
888 self.flags = self.flags - (self.flags & FL_CLIENT);
889 bot_relinkplayerlist();
893 if(self.weaponentity)
894 if(self.weaponentity.lasertarget)
895 remove(self.weaponentity.lasertarget);
899 Spawnqueue_Unmark(self);
900 Spawnqueue_Remove(self);
908 void() ChatBubbleThink =
910 self.nextthink = time;
911 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
913 self.owner.chatbubbleentity = world;
917 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
918 if (self.owner.buttonchat && !self.owner.deadflag)
919 self.model = self.mdl;
924 void() UpdateChatBubble =
926 if (!self.modelindex)
928 // spawn a chatbubble entity if needed
929 if (!self.chatbubbleentity)
931 self.chatbubbleentity = spawn();
932 self.chatbubbleentity.owner = self;
933 self.chatbubbleentity.exteriormodeltoclient = self;
934 self.chatbubbleentity.think = ChatBubbleThink;
935 self.chatbubbleentity.nextthink = time;
936 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
937 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
938 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
939 self.chatbubbleentity.model = "";
940 self.chatbubbleentity.effects = EF_LOWPRECISION;
945 void() TeamBubbleThink =
947 self.nextthink = time;
948 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
950 self.owner.teambubbleentity = world;
954 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
955 if (self.owner.buttonchat || self.owner.deadflag)
958 self.model = self.mdl;
962 float() TeamBubble_customizeentityforclient
964 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
967 void() UpdateTeamBubble =
969 if (!self.modelindex || !cvar("teamplay"))
971 // spawn a teambubble entity if needed
972 if (!self.teambubbleentity && cvar("teamplay"))
974 self.teambubbleentity = spawn();
975 self.teambubbleentity.owner = self;
976 self.teambubbleentity.exteriormodeltoclient = self;
977 self.teambubbleentity.think = TeamBubbleThink;
978 self.teambubbleentity.nextthink = time;
979 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
980 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
981 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
982 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
983 self.teambubbleentity.mdl = self.teambubbleentity.model;
984 self.teambubbleentity.model = self.teambubbleentity.mdl;
985 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
986 self.teambubbleentity.effects = EF_LOWPRECISION;
990 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
991 // added to the model skins
992 /*void() UpdateColorModHack =
995 c = self.clientcolors & 15;
996 // LordHavoc: only bothering to support white, green, red, yellow, blue
997 if (teamplay == 0) self.colormod = '0 0 0';
998 else if (c == 0) self.colormod = '1.00 1.00 1.00';
999 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1000 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1001 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1002 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1003 else self.colormod = '1 1 1';
1009 self.effects |= EF_NODRAW; // prevent another CopyBody
1010 PutClientInServer();
1013 void player_powerups (void)
1017 if (self.items & IT_STRENGTH)
1019 if (time > self.strength_finished)
1021 if (g_minstagib_invis_alpha > 0)
1023 self.alpha = default_player_alpha;
1024 self.exteriorweaponentity.alpha = default_weapon_alpha;
1025 self.effects = self.effects | EF_FULLBRIGHT;
1029 self.effects -= self.effects & EF_NODRAW;
1031 self.items = self.items - (self.items & IT_STRENGTH);
1032 sprint(self, "^3Invisibility has worn off\n");
1037 if (time < self.strength_finished)
1039 if (g_minstagib_invis_alpha > 0)
1041 self.alpha = g_minstagib_invis_alpha;
1042 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1043 self.effects -= self.effects & EF_FULLBRIGHT;
1047 self.effects = self.effects | EF_NODRAW;
1049 self.items = self.items | IT_STRENGTH;
1050 sprint(self, "^3You are invisible\n");
1054 if (self.items & IT_INVINCIBLE)
1056 if (time > self.invincible_finished)
1058 self.items = self.items - (self.items & IT_INVINCIBLE);
1059 sprint(self, "^3Speed has worn off\n");
1064 if (time < self.invincible_finished)
1066 self.items = self.items | IT_INVINCIBLE;
1067 sprint(self, "^3You are on speed\n");
1073 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1074 if (self.items & IT_STRENGTH)
1076 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1077 if (time > self.strength_finished)
1079 self.items = self.items - (self.items & IT_STRENGTH);
1080 sprint(self, "^3Strength has worn off\n");
1085 if (time < self.strength_finished)
1087 self.items = self.items | IT_STRENGTH;
1088 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1091 if (self.items & IT_INVINCIBLE)
1093 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1094 if (time > self.invincible_finished)
1096 self.items = self.items - (self.items & IT_INVINCIBLE);
1097 sprint(self, "^3Shield has worn off\n");
1102 if (time < self.invincible_finished)
1104 self.items = self.items | IT_INVINCIBLE;
1105 sprint(self, "^3Shield surrounds you\n");
1109 if (cvar("g_fullbrightplayers"))
1110 self.effects = self.effects | EF_FULLBRIGHT;
1112 // midair gamemode: damage only while in the air
1113 // if in midair mode, being on ground grants temporary invulnerability
1114 // (this is so that multishot weapon don't clear the ground flag on the
1115 // first damage in the frame, leaving the player vulnerable to the
1116 // remaining hits in the same frame)
1117 if (self.flags & FL_ONGROUND)
1119 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1121 if (time < self.spawnshieldtime)
1122 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1125 float CalcRegen(float current, float stable, float regenfactor)
1127 if(current > stable)
1129 else if(current > stable - 0.25) // when close enough, "snap"
1132 return min(stable, current + (stable - current) * regenfactor * frametime);
1135 void player_regen (void)
1137 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1138 maxh = cvar("g_balance_health_stable");
1139 maxa = cvar("g_balance_armor_stable");
1140 limith = cvar("g_balance_health_limit");
1141 limita = cvar("g_balance_armor_limit");
1143 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1146 max_mod = regen_mod = rot_mod = limit_mod = 1;
1148 if (self.runes & RUNE_REGEN)
1150 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1152 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1153 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1154 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1158 regen_mod = cvar("g_balance_rune_regen_regenrate");
1159 max_mod = cvar("g_balance_rune_regen_hpmod");
1160 limit_mod = cvar("g_balance_rune_regen_limitmod");
1163 else if (self.runes & CURSE_VENOM)
1165 max_mod = cvar("g_balance_curse_venom_hpmod");
1166 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1167 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1169 rot_mod = cvar("g_balance_curse_venom_rotrate");
1170 limit_mod = cvar("g_balance_curse_venom_limitmod");
1171 //if (!self.runes & RUNE_REGEN)
1172 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1174 maxh = maxh * max_mod;
1175 //maxa = maxa * max_mod;
1176 limith = limith * limit_mod;
1177 limita = limita * limit_mod;
1179 if (self.armorvalue > maxa)
1181 if (time > self.pauserotarmor_finished)
1183 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1184 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1187 else if (self.armorvalue < maxa)
1189 if (time > self.pauseregen_finished)
1191 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1192 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1195 if (self.health > maxh)
1197 if (time > self.pauserothealth_finished)
1199 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1200 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1203 else if (self.health < maxh)
1205 if (time > self.pauseregen_finished)
1207 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1208 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1212 if (self.health > limith)
1213 self.health = limith;
1214 if (self.armorvalue > limita)
1215 self.armorvalue = limita;
1217 // if player rotted to death... die!
1219 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1223 ======================
1224 spectate mode routines
1225 ======================
1227 void SpectateCopy(entity spectatee) {
1228 self.armortype = spectatee.armortype;
1229 self.armorvalue = spectatee.armorvalue;
1230 self.currentammo = spectatee.currentammo;
1231 self.effects = spectatee.effects;
1232 self.health = spectatee.health;
1234 self.items = spectatee.items;
1235 self.punchangle = spectatee.punchangle;
1236 self.view_ofs = spectatee.view_ofs;
1237 self.v_angle = spectatee.v_angle;
1238 self.viewzoom = spectatee.viewzoom;
1239 self.velocity = spectatee.velocity;
1240 self.dmg_take = spectatee.dmg_take;
1241 self.dmg_save = spectatee.dmg_save;
1242 self.dmg_inflictor = spectatee.dmg_inflictor;
1243 self.angles = spectatee.v_angle;
1244 self.fixangle = TRUE;
1245 setorigin(self, spectatee.origin);
1246 setsize(self, spectatee.mins, spectatee.maxs);
1249 void SpectateUpdate() {
1251 PutObserverInServer();
1253 if (self != self.enemy) {
1254 if(self.enemy.flags & FL_NOTARGET)
1255 PutObserverInServer();
1256 SpectateCopy(self.enemy);
1257 //msg_entity = self;
1258 //WriteByte(MSG_ONE, SVC_SETANGLE);
1259 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1260 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1261 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1265 float SpectateNext() {
1266 other = find(self.enemy, classname, "player");
1268 other = find(other, classname, "player");
1273 if(self.enemy.classname == "player") {
1275 WriteByte(MSG_ONE, SVC_SETVIEW);
1276 WriteEntity(MSG_ONE, self.enemy);
1277 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1287 ShowRespawnCountdown()
1289 Update a respawn countdown display.
1292 void ShowRespawnCountdown()
1295 if(self.deadflag == DEAD_NO) // just respawned?
1299 number = ceil(self.death_time - time);
1302 if(number <= self.respawn_countdown)
1304 self.respawn_countdown = number - 1;
1305 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
1306 play2(self, strcat("announcer/robotic/", ftos(number), "announcer/.ogg"));
1311 void LeaveSpectatorMode()
1313 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1314 self.classname = "player";
1315 if(cvar("g_campaign") || cvar("g_balance_teams"))
1316 JoinBestTeam(self, 0);
1317 if(cvar("g_campaign"))
1318 campaign_bots_may_start = 1;
1319 PutClientInServer();
1320 if(!(self.flags & FL_NOTARGET))
1321 bprint ("^4", self.netname, "^4 is playing now\n");
1322 centerprint(self,"");
1325 stuffcmd(self,"menu_showteamselect\n");
1334 Called every frame for each client before the physics are run
1337 void() ctf_setstatus;
1338 .float vote_nagtime;
1339 void PlayerPreThink (void)
1342 if(self.version_nagtime)
1343 if(self.cvar_g_nexuizversion)
1344 if(time > self.version_nagtime)
1346 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1347 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1349 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");
1350 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1352 self.version_nagtime = 0;
1356 if(self.cvar_scr_centertime)
1357 if(time > self.vote_nagtime)
1360 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1364 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1366 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1367 self.max_armorvalue = 0;
1371 antilag_record(self);
1373 if(self.classname == "player") {
1374 // if(self.netname == "Wazat")
1375 // bprint(self.classname, "\n");
1377 CheckRules_Player();
1380 PrintWelcomeMessage(self);
1382 if(g_lms || !cvar("sv_spectate"))
1383 if((time - self.jointime) <= cvar("welcome_message_time"))
1384 PrintWelcomeMessage(self);
1386 if (intermission_running)
1388 IntermissionThink (); // otherwise a button could be missed between
1389 return; // the think tics
1392 if(self.teleport_time)
1393 if(time > self.teleport_time)
1395 self.teleport_time = 0;
1396 self.effects = self.effects - (self.effects & EF_NODRAW);
1397 if(self.weaponentity)
1398 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1401 Nixnex_GiveCurrentWeapon();
1403 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1404 UpdateSelectedPlayer();
1406 if (self.deadflag != DEAD_NO)
1408 float button_pressed, force_respawn;
1410 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1411 force_respawn = (g_lms || cvar("g_forced_respawn"));
1412 if (self.deadflag == DEAD_DYING)
1415 self.deadflag = DEAD_RESPAWNING;
1416 else if(!button_pressed)
1417 self.deadflag = DEAD_DEAD;
1419 else if (self.deadflag == DEAD_DEAD)
1422 self.deadflag = DEAD_RESPAWNABLE;
1424 else if (self.deadflag == DEAD_RESPAWNABLE)
1427 self.deadflag = DEAD_RESPAWNING;
1429 else if (self.deadflag == DEAD_RESPAWNING)
1431 if(time > self.death_time)
1433 self.death_time = time + 1; // only retry once a second
1437 ShowRespawnCountdown();
1441 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1445 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1446 dist = self.oldorigin - self.origin;
1448 self.lms_traveled_distance += fabs(vlen(dist));
1450 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1452 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1453 self.lms_traveled_distance = 0;
1456 if(time > self.lms_nextcheck)
1458 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1459 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1461 centerprint(self, cvar_string("g_lms_campcheck_message"));
1462 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1463 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1464 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');
1466 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1467 self.lms_traveled_distance = 0;
1471 if (self.button5 && !self.hook.state)
1476 self.view_ofs = PL_CROUCH_VIEW_OFS;
1477 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1478 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1485 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1486 if (!trace_startsolid)
1488 self.crouch = FALSE;
1489 self.view_ofs = PL_VIEW_OFS;
1490 setsize (self, PL_MIN, PL_MAX);
1497 GrapplingHookFrame();
1502 float zoomfactor, zoomspeed, zoomdir;
1503 zoomfactor = self.cvar_cl_zoomfactor;
1504 if(zoomfactor < 1 || zoomfactor > 16)
1506 zoomspeed = self.cvar_cl_zoomspeed;
1507 if(zoomspeed >= 0) // < 0 is instant zoom
1508 if(zoomspeed < 0.5 || zoomspeed > 16)
1511 zoomdir = self.button4;
1513 if(self.weapon == WEP_NEX)
1518 self.has_zoomed = 1;
1522 if(zoomspeed <= 0) // instant zoom
1525 self.viewzoom = 1 / zoomfactor;
1531 // geometric zoom would be:
1532 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1533 // however, testing showed that arithmetic/harmonic zoom works better
1535 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1536 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1537 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1539 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1540 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1541 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1545 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1553 minstagib_ammocheck();
1558 //self.angles_y=self.v_angle_y + 90; // temp
1560 //if (TetrisPreFrame()) return;
1561 } else if(gameover) {
1562 if (intermission_running)
1563 IntermissionThink (); // otherwise a button could be missed between
1565 } else if(self.classname == "observer") {
1567 if (self.flags & FL_JUMPRELEASED) {
1568 if (self.button2 && self.version == cvar("gameversion")) {
1569 self.welcomemessage_time = 0;
1570 self.flags = self.flags - FL_JUMPRELEASED;
1571 LeaveSpectatorMode();
1573 } else if(self.button0 && self.version == cvar("gameversion")) {
1574 self.welcomemessage_time = 0;
1575 self.flags = self.flags - FL_JUMPRELEASED;
1576 if(SpectateNext() == 1) {
1577 self.classname = "spectator";
1581 if (!(self.button0 || self.button2)) {
1582 self.flags = self.flags | FL_JUMPRELEASED;
1585 PrintWelcomeMessage(self);
1586 } else if(self.classname == "spectator") {
1587 if (self.flags & FL_JUMPRELEASED) {
1588 if (self.button2 && self.version == cvar("gameversion")) {
1589 self.welcomemessage_time = 0;
1590 self.flags = self.flags - FL_JUMPRELEASED;
1591 LeaveSpectatorMode();
1593 } else if(self.button0) {
1594 self.welcomemessage_time = 0;
1595 self.flags = self.flags - FL_JUMPRELEASED;
1596 if(SpectateNext() == 1) {
1597 self.classname = "spectator";
1599 self.classname = "observer";
1600 PutClientInServer();
1602 } else if (self.button3) {
1603 self.welcomemessage_time = 0;
1604 self.flags = self.flags - FL_JUMPRELEASED;
1605 self.classname = "observer";
1606 PutClientInServer();
1611 if (!(self.button0 || self.button3)) {
1612 self.flags = self.flags | FL_JUMPRELEASED;
1615 PrintWelcomeMessage(self);
1616 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1625 Called every frame for each client after the physics are run
1628 void PlayerPostThink (void)
1630 // Savage: Check for nameless players
1631 if (strlen(self.netname) < 1) {
1632 self.netname = "Player";
1633 stuffcmd(self, "seta _cl_name Player\n");
1636 if(self.classname == "player") {
1637 CheckRules_Player();
1642 if (intermission_running)
1643 return; // intermission or finale
1645 //PrintWelcomeMessage(self);
1646 //if (TetrisPostFrame()) return;
1648 // restart countdown
1649 if(time < restart_countdown)
1654 sec = ceil(restart_countdown-time);
1655 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1656 centerprint(self, s);
1657 self.movetype = MOVETYPE_NONE;
1658 self.velocity = '0 0 0';
1659 self.avelocity = '0 0 0';
1660 self.movement = '0 0 0';
1662 else if(self.movetype == MOVETYPE_NONE)
1664 self.movetype = MOVETYPE_WALK;
1665 centerprint(self, "\n");
1667 } else if (self.classname == "observer") {
1669 } else if (self.classname == "spectator") {