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
27 if (spot.team == teamcheck)
34 if (vlen(player.origin - spot.origin) < mindist)
36 player = player.chain;
42 previousspot.chain = spot;
49 spawn_allgood = FALSE;
53 // if we couldn't find ANY good points, return the original list
55 newfirstspot = firstspot;
59 entity Spawn_RandomPoint(entity firstspot)
63 // count number of spots
68 numspots = numspots + 1;
72 numspots = numspots * random();
74 while (spot.chain && numspots >= 1)
76 numspots = numspots - 1;
82 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
84 local entity best, spot, player;
85 local float bestrating, rating;
87 bestrating = -1000000;
96 rating = min(rating, vlen(player.origin - spot.origin));
97 player = player.chain;
99 rating = rating + random() * 16;
100 if (bestrating < rating)
114 Finds a point to respawn
117 entity SelectSpawnPoint (float anypoint)
119 local float teamcheck;
120 local entity spot, firstspot, playerlist;
122 spot = find (world, classname, "testplayerstart");
128 if(!anypoint && cvar("g_ctf") )
129 teamcheck = self.team;
131 // get the list of players
132 playerlist = findchain(classname, "player");
133 // get the entire list of spots
134 firstspot = findchain(classname, "info_player_deathmatch");
135 // filter out the bad ones
136 // (note this returns the original list if none survived)
137 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
139 // there is 50/50 chance of choosing a random spot or the furthest spot
140 // (this means that roughly every other spawn will be furthest, so you
141 // usually won't get fragged at spawn twice in a row)
142 if (arena_roundbased)
144 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
145 spot = Spawn_RandomPoint(firstspot);
147 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
148 spot = Spawn_RandomPoint(firstspot);
150 spot = Spawn_FurthestPoint(firstspot, playerlist);
154 if(cvar("spawn_debug"))
157 error ("PutClientInServer: no start points on level");
167 Checks if the argument string can be a valid playermodel.
168 Returns a valid one in doubt.
171 string FallbackPlayerModel = "models/player/marine.zym";
172 string CheckPlayerModel(string plyermodel) {
173 if(strlen(plyermodel) < 4)
174 return FallbackPlayerModel;
175 if( substring(plyermodel,0,14) != "models/player/")
176 return FallbackPlayerModel;
177 else if(cvar("sv_servermodelsonly"))
179 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
180 return FallbackPlayerModel;
181 if(!fexists(plyermodel))
182 return FallbackPlayerModel;
189 Client_customizeentityforclient
194 float Client_customizeentityforclient()
196 #ifdef ALLOW_VARIABLE_LOD
198 // other: the player viewing me
202 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
205 if(other.cvar_cl_playerdetailreduction <= 0)
207 if(other.cvar_cl_playerdetailreduction <= -2)
208 self.modelindex = self.modelindex_lod2;
209 else if(other.cvar_cl_playerdetailreduction <= -1)
210 self.modelindex = self.modelindex_lod1;
212 self.modelindex = self.modelindex_lod0;
216 distance = vlen(self.origin - other.origin);
217 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
219 self.modelindex = self.modelindex_lod2;
221 self.modelindex = self.modelindex_lod1;
223 self.modelindex = self.modelindex_lod0;
230 void setmodel_lod(entity e, string modelname)
232 #ifdef ALLOW_VARIABLE_LOD
235 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1.zym");
239 setmodel(e, s); // players have high precision
240 self.modelindex_lod1 = self.modelindex;
243 self.modelindex_lod1 = -1;
245 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2.zym");
249 setmodel(e, s); // players have high precision
250 self.modelindex_lod2 = self.modelindex;
253 self.modelindex_lod2 = -1;
255 precache_model(modelname);
256 setmodel(e, modelname); // players have high precision
257 self.modelindex_lod0 = self.modelindex;
259 if(self.modelindex_lod1 < 0)
260 self.modelindex_lod1 = self.modelindex;
262 if(self.modelindex_lod2 < 0)
263 self.modelindex_lod2 = self.modelindex;
265 precache_model(modelname);
266 setmodel(e, modelname); // players have high precision
274 putting a client as observer in the server
277 void PutObserverInServer (void)
280 spot = SelectSpawnPoint (FALSE);
281 RemoveGrapplingHook(self); // Wazat's Grappling Hook
283 if(clienttype(self) == CLIENTTYPE_REAL)
286 WriteByte(MSG_ONE, SVC_SETVIEW);
287 WriteEntity(MSG_ONE, self);
291 kh_Key_DropAll(self, TRUE);
294 DropFlag(self.flagcarried);
296 WaypointSprite_PlayerDead();
298 DistributeFragsAmongTeam(self, self.team, 1);
300 if(self.frags <= 0 && self.frags > -666 && cvar("g_lms") && self.killcount != -666)
301 bprint ("^4", self.netname, "^4 has no more lives left\n");
302 else if(self.killcount != -666)
303 bprint ("^4", self.netname, "^4 is spectating now\n");
305 self.classname = "observer";
307 self.takedamage = DAMAGE_NO;
308 self.solid = SOLID_NOT;
309 self.movetype = MOVETYPE_NOCLIP;
310 self.flags = FL_CLIENT | FL_NOTARGET;
311 self.armorvalue = 666;
313 self.armorvalue = cvar("g_balance_armor_start");
314 self.pauserotarmor_finished = 0;
315 self.pauserothealth_finished = 0;
316 self.pauseregen_finished = 0;
317 self.damageforcescale = 0;
327 self.pain_finished = 0;
328 self.strength_finished = 0;
329 self.invincible_finished = 0;
331 self.think = SUB_Null;
335 self.deadflag = DEAD_NO;
336 self.angles = spot.angles;
338 self.fixangle = TRUE;
341 self.view_ofs = PL_VIEW_OFS;
342 setorigin (self, spot.origin);
343 setsize (self, '0 0 0', '0 0 0');
344 self.oldorigin = self.origin;
349 self.weaponmodel = "";
350 self.weaponentity = world;
351 self.killcount = -666;
352 self.velocity = '0 0 0';
353 self.avelocity = '0 0 0';
354 self.punchangle = '0 0 0';
355 self.punchvector = '0 0 0';
356 self.oldvelocity = self.velocity;
357 self.customizeentityforclient = Client_customizeentityforclient;
363 Spawnqueue_Insert(self);
367 Spawnqueue_Unmark(self);
368 Spawnqueue_Remove(self);
371 else if(!cvar("g_lms"))
380 Called when a client spawns in the server
383 void PutClientInServer (void)
385 if(clienttype(self) == CLIENTTYPE_BOT)
387 self.classname = "player";
389 else if(clienttype(self) == CLIENTTYPE_REAL)
392 WriteByte(MSG_ONE, SVC_SETVIEW);
393 WriteEntity(MSG_ONE, self);
396 // player is dead and becomes observer
397 if(cvar("g_lms") && self.frags < 1)
398 self.classname = "observer";
402 self.classname = "observer";
404 if(self.classname == "player") {
407 spot = SelectSpawnPoint (FALSE);
409 RemoveGrapplingHook(self); // Wazat's Grappling Hook
411 self.classname = "player";
412 self.iscreature = TRUE;
413 self.movetype = MOVETYPE_WALK;
414 self.solid = SOLID_SLIDEBOX;
415 self.flags = FL_CLIENT;
416 self.takedamage = DAMAGE_AIM;
418 self.air_finished = time + 12;
421 self.ammo_shells = start_ammo_shells;
422 self.ammo_nails = start_ammo_nails;
423 self.ammo_rockets = start_ammo_rockets;
424 self.ammo_cells = start_ammo_cells;
425 self.health = start_health;
426 self.armorvalue = start_armorvalue;
427 self.items = start_items;
428 self.switchweapon = start_switchweapon;
430 self.jump_interval = time;
432 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
433 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
434 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
435 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
436 self.damageforcescale = 2;
445 self.pain_finished = 0;
446 self.strength_finished = 0;
447 self.invincible_finished = 0;
449 //self.speed_finished = 0;
450 //self.slowmo_finished = 0;
451 // players have no think function
452 self.think = SUB_Null;
458 self.deadflag = DEAD_NO;
460 self.angles = spot.angles;
462 self.angles_z = 0; // never spawn tilted even if the spot says to
463 self.fixangle = TRUE; // turn this way immediately
464 self.velocity = '0 0 0';
465 self.avelocity = '0 0 0';
466 self.punchangle = '0 0 0';
467 self.punchvector = '0 0 0';
468 self.oldvelocity = self.velocity;
473 self.customizeentityforclient = Client_customizeentityforclient;
475 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
476 local string defaultmodel;
477 defaultmodel = cvar_string("sv_defaultplayermodel");
478 setmodel_lod (self, defaultmodel);
479 self.skin = stof(cvar_string("sv_defaultplayerskin"));
481 self.playermodel = CheckPlayerModel(self.playermodel);
482 setmodel_lod (self, self.playermodel);
484 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
486 self.skin = stof(self.playerskin);
490 self.view_ofs = PL_VIEW_OFS;
491 setsize (self, PL_MIN, PL_MAX);
492 self.spawnorigin = spot.origin;
493 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
494 // don't reset back to last position, even if new position is stuck in solid
495 self.oldorigin = self.origin;
499 Spawnqueue_Remove(self);
500 Spawnqueue_Mark(self);
503 self.event_damage = PlayerDamage;
505 self.bot_attack = TRUE;
507 self.statdraintime = time + 5;
508 self.button0 = self.button1 = self.button2 = self.button3 = 0;
510 if(self.killcount == -666) {
517 self.cnt = WEP_LASER;
518 self.nixnex_lastchange_id = -1;
520 CL_SpawnWeaponentity();
521 self.alpha = default_player_alpha;
522 self.exteriorweaponentity.alpha = default_weapon_alpha;
524 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
525 self.lms_traveled_distance = 0;
527 if(cvar("spawn_debug"))
529 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
530 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
533 //stuffcmd(self, "chase_active 0");
534 //stuffcmd(self, "set viewsize $tmpviewsize \n");
536 if (cvar("g_spawnsound"))
537 sound (self, CHAN_AUTO, "misc/teleport.wav", 1, ATTN_NORM);
539 } else if(self.classname == "observer") {
540 PutObserverInServer ();
549 void SetNewParms (void)
559 void SetChangeParms (void)
568 Called when a client types 'kill' in the console
571 void ClientKill (void)
573 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
576 void FixClientCvars(entity e)
578 // send prediction settings to the client
579 stuffcmd(e, "\nin_bindmap 0 0\n");
580 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
581 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
582 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
583 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
584 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
585 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
586 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
587 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
588 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
589 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
590 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
591 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
592 stuffcmd(e, "cl_movement_edgefriction 1\n");
599 Called when a client connects to the server
602 string ColoredTeamName(float t);
603 //void dom_player_join_team(entity pl);
604 void ClientConnect (void)
608 self.classname = "player_joining";
609 self.flags = self.flags | FL_CLIENT;
610 self.version_nagtime = time + 10 + random() * 10;
614 dprint("BUG player count is lower than zero, this cannot happen!\n");
620 //if(cvar("g_domination"))
621 // dom_player_join_team(self);
623 //JoinBestTeam(self, FALSE);
625 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
626 self.classname = "observer";
628 self.classname = "player";
629 campaign_bots_may_start = 1;
632 self.playerid = (playerid_last = playerid_last + 1);
633 if(cvar("sv_eventlog"))
635 if(clienttype(self) == CLIENTTYPE_REAL)
639 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
640 s = strcat(":team:", ftos(self.playerid), ":");
641 s = strcat(s, ftos(self.team));
642 GameLogEcho(s, FALSE);
645 //stuffcmd(self, "set tmpviewsize $viewsize \n");
647 bprint ("^4",self.netname);
648 bprint ("^4 connected");
650 if(cvar("g_domination") || cvar("g_ctf"))
652 bprint(" and joined the ");
653 bprint(ColoredTeamName(self.team));
658 self.welcomemessage_time = 0;
660 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
661 // TODO: is this being used for anything else than cd tracks?
662 // Remember: SVC_CDTRACK exists. Maybe it should be used.
664 FixClientCvars(self);
667 WaypointSprite_InitClient(self);
669 // Wazat's grappling hook
670 SetGrappleHookBindings();
672 // get autoswitch state from player when he toggles it
673 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
675 // get version info from player
676 stuffcmd(self, "cmd clientversion $gameversion\n");
678 // get other cvars from player
681 // set cvar for team scoreboard
685 t = cvar("teamplay");
686 // 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
687 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
690 stuffcmd(self, "set teamplay 0\n");
694 self.frags = cvar("fraglimit");
695 // no fraglimit was set, so player gets 999 lives
699 self.frags = LMS_NewPlayerLives();
705 else if(cvar("g_arena"))
707 self.classname = "observer";
708 Spawnqueue_Insert(self);
711 bot_relinkplayerlist();
713 self.jointime = time;
720 Called when a client disconnects from the server
723 void(entity e) DropFlag;
724 .entity chatbubbleentity;
725 .entity teambubbleentity;
726 void ClientDisconnect (void)
729 if(cvar("sv_eventlog"))
730 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
731 bprint ("^4",self.netname);
732 bprint ("^4 disconnected\n");
734 if (self.chatbubbleentity)
736 remove (self.chatbubbleentity);
737 self.chatbubbleentity = world;
740 if (self.teambubbleentity)
742 remove (self.teambubbleentity);
743 self.teambubbleentity = world;
746 WaypointSprite_PlayerGone();
749 kh_Key_DropAll(self, TRUE);
752 DropFlag(self.flagcarried);
754 DistributeFragsAmongTeam(self, self.team, 1);
757 self.flags = self.flags - (self.flags & FL_CLIENT);
758 bot_relinkplayerlist();
762 if(self.weaponentity)
763 if(self.weaponentity.lasertarget)
764 remove(self.weaponentity.lasertarget);
768 Spawnqueue_Unmark(self);
769 Spawnqueue_Remove(self);
777 void() ChatBubbleThink =
779 self.nextthink = time;
780 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
782 self.owner.chatbubbleentity = world;
786 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
787 if (self.owner.buttonchat && !self.owner.deadflag)
788 self.model = self.mdl;
793 void() UpdateChatBubble =
795 if (!self.modelindex)
797 // spawn a chatbubble entity if needed
798 if (!self.chatbubbleentity)
800 self.chatbubbleentity = spawn();
801 self.chatbubbleentity.owner = self;
802 self.chatbubbleentity.exteriormodeltoclient = self;
803 self.chatbubbleentity.think = ChatBubbleThink;
804 self.chatbubbleentity.nextthink = time;
805 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
806 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
807 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
808 self.chatbubbleentity.model = "";
809 self.chatbubbleentity.effects = EF_LOWPRECISION;
814 void() TeamBubbleThink =
816 self.nextthink = time;
817 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
819 self.owner.teambubbleentity = world;
823 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
824 if (self.owner.buttonchat || self.owner.deadflag)
827 self.model = self.mdl;
831 float() TeamBubble_customizeentityforclient
833 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
836 void() UpdateTeamBubble =
838 if (!self.modelindex || !cvar("teamplay"))
840 // spawn a teambubble entity if needed
841 if (!self.teambubbleentity && cvar("teamplay"))
843 self.teambubbleentity = spawn();
844 self.teambubbleentity.owner = self;
845 self.teambubbleentity.exteriormodeltoclient = self;
846 self.teambubbleentity.think = TeamBubbleThink;
847 self.teambubbleentity.nextthink = time;
848 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
849 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
850 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
851 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
852 self.teambubbleentity.mdl = self.teambubbleentity.model;
853 self.teambubbleentity.model = self.teambubbleentity.mdl;
854 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
855 self.teambubbleentity.effects = EF_LOWPRECISION;
859 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
860 // added to the model skins
861 /*void() UpdateColorModHack =
864 c = self.clientcolors & 15;
865 // LordHavoc: only bothering to support white, green, red, yellow, blue
866 if (teamplay == 0) self.colormod = '0 0 0';
867 else if (c == 0) self.colormod = '1.00 1.00 1.00';
868 else if (c == 3) self.colormod = '0.10 1.73 0.10';
869 else if (c == 4) self.colormod = '1.73 0.10 0.10';
870 else if (c == 12) self.colormod = '1.22 1.22 0.10';
871 else if (c == 13) self.colormod = '0.10 0.10 1.73';
872 else self.colormod = '1 1 1';
881 void player_powerups (void)
883 if (cvar("g_minstagib"))
885 self.effects = EF_FULLBRIGHT;
886 if (self.items & IT_STRENGTH)
888 if (time > self.strength_finished)
890 self.alpha = default_player_alpha;
891 self.exteriorweaponentity.alpha = default_weapon_alpha;
892 self.items = self.items - (self.items & IT_STRENGTH);
893 sprint(self, "^3Invisibility has worn off\n");
898 if (time < self.strength_finished)
900 self.alpha = cvar("g_minstagib_invis_alpha");
901 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
902 self.items = self.items | IT_STRENGTH;
903 sprint(self, "^3You are invisible\n");
907 if (self.items & IT_INVINCIBLE)
909 if (time > self.invincible_finished)
911 self.items = self.items - (self.items & IT_INVINCIBLE);
912 sprint(self, "^3Speed has worn off\n");
917 if (time < self.invincible_finished)
919 self.items = self.items | IT_INVINCIBLE;
920 sprint(self, "^3You are on speed\n");
926 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
927 if (self.items & IT_STRENGTH)
929 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
930 if (time > self.strength_finished)
932 self.items = self.items - (self.items & IT_STRENGTH);
933 sprint(self, "^3Strength has worn off\n");
938 if (time < self.strength_finished)
940 self.items = self.items | IT_STRENGTH;
941 sprint(self, "^3Strength infuses your weapons with devastating power\n");
944 if (self.items & IT_INVINCIBLE)
946 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
947 if (time > self.invincible_finished)
949 self.items = self.items - (self.items & IT_INVINCIBLE);
950 sprint(self, "^3Shield has worn off\n");
955 if (time < self.invincible_finished)
957 self.items = self.items | IT_INVINCIBLE;
958 sprint(self, "^3Shield surrounds you\n");
962 if (cvar("g_fullbrightplayers"))
963 self.effects = self.effects | EF_FULLBRIGHT;
965 // midair gamemode: damage only while in the air
966 // if in midair mode, being on ground grants temporary invulnerability
967 // (this is so that multishot weapon don't clear the ground flag on the
968 // first damage in the frame, leaving the player vulnerable to the
969 // remaining hits in the same frame)
970 if (self.flags & FL_ONGROUND)
971 if (cvar("g_midair"))
972 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
974 if (time < self.spawnshieldtime)
975 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
978 float CalcRegen(float current, float stable, float regenfactor)
982 else if(current > stable - 0.25) // when close enough, "snap"
985 return min(stable, current + (stable - current) * regenfactor * frametime);
988 void player_regen (void)
990 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
991 maxh = cvar("g_balance_health_stable");
992 maxa = cvar("g_balance_armor_stable");
993 limith = cvar("g_balance_health_limit");
994 limita = cvar("g_balance_armor_limit");
996 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
999 max_mod = regen_mod = rot_mod = limit_mod = 1;
1001 if (self.runes & RUNE_REGEN)
1003 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1005 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1006 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1007 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1011 regen_mod = cvar("g_balance_rune_regen_regenrate");
1012 max_mod = cvar("g_balance_rune_regen_hpmod");
1013 limit_mod = cvar("g_balance_rune_regen_limitmod");
1016 else if (self.runes & CURSE_VENOM)
1018 max_mod = cvar("g_balance_curse_venom_hpmod");
1019 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1020 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1022 rot_mod = cvar("g_balance_curse_venom_rotrate");
1023 limit_mod = cvar("g_balance_curse_venom_limitmod");
1024 //if (!self.runes & RUNE_REGEN)
1025 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1027 maxh = maxh * max_mod;
1028 //maxa = maxa * max_mod;
1029 limith = limith * limit_mod;
1030 limita = limita * limit_mod;
1032 if (self.armorvalue > maxa)
1034 if (time > self.pauserotarmor_finished)
1036 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1037 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1040 else if (self.armorvalue < maxa)
1042 if (time > self.pauseregen_finished)
1044 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1045 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1048 if (self.health > maxh)
1050 if (time > self.pauserothealth_finished)
1052 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1053 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1056 else if (self.health < maxh)
1058 if (time > self.pauseregen_finished)
1060 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1061 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1065 if (self.health > limith)
1066 self.health = limith;
1067 if (self.armorvalue > limita)
1068 self.armorvalue = limita;
1070 // if player rotted to death... die!
1072 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1076 ======================
1077 spectate mode routines
1078 ======================
1080 void SpectateCopy(entity spectatee) {
1081 self.armortype = spectatee.armortype;
1082 self.armorvalue = spectatee.armorvalue;
1083 self.currentammo = spectatee.currentammo;
1084 self.effects = spectatee.effects;
1085 self.health = spectatee.health;
1087 self.items = spectatee.items;
1088 self.punchangle = spectatee.punchangle;
1089 self.view_ofs = spectatee.view_ofs;
1090 self.v_angle = spectatee.v_angle;
1091 self.viewzoom = spectatee.viewzoom;
1092 setorigin(self, spectatee.origin);
1093 setsize(self, spectatee.mins, spectatee.maxs);
1096 void SpectateUpdate() {
1098 PutObserverInServer();
1100 if (self != self.enemy) {
1101 if(self.enemy.flags & FL_NOTARGET)
1102 PutObserverInServer();
1103 SpectateCopy(self.enemy);
1104 self.dmg_take = self.enemy.dmg_take;
1105 self.dmg_save = self.enemy.dmg_save;
1106 self.dmg_inflictor = self.enemy.dmg_inflictor;
1107 self.fixangle = TRUE;
1108 self.angles = self.enemy.v_angle;
1109 //msg_entity = self;
1110 //WriteByte(MSG_ONE, SVC_SETANGLE);
1111 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1112 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1113 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1117 float SpectateNext() {
1118 other = find(self.enemy, classname, "player");
1120 other = find(other, classname, "player");
1125 if(self.enemy.classname == "player") {
1127 WriteByte(MSG_ONE, SVC_SETVIEW);
1128 WriteEntity(MSG_ONE, self.enemy);
1129 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1139 ShowRespawnCountdown()
1141 Update a respawn countdown display.
1144 void ShowRespawnCountdown()
1147 if(self.deadflag == DEAD_NO) // just respawned?
1151 number = ceil(self.death_time - time);
1154 if(number <= self.respawn_countdown)
1156 self.respawn_countdown = number - 1;
1157 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
1158 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1163 void LeaveSpectatorMode()
1165 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1166 self.classname = "player";
1167 if(cvar("g_campaign") || cvar("g_balance_teams"))
1168 JoinBestTeam(self, 0);
1169 if(cvar("g_campaign"))
1170 campaign_bots_may_start = 1;
1171 PutClientInServer();
1172 if(!(self.flags & FL_NOTARGET))
1173 bprint ("^4", self.netname, "^4 is playing now\n");
1174 centerprint(self,"");
1177 stuffcmd(self,"menu_showteamselect\n");
1186 Called every frame for each client before the physics are run
1189 void() ctf_setstatus;
1190 .float vote_nagtime;
1191 void PlayerPreThink (void)
1194 if(self.version_nagtime)
1195 if(self.cvar_g_nexuizversion)
1196 if(time > self.version_nagtime)
1198 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1199 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1201 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");
1202 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1204 self.version_nagtime = 0;
1208 if(self.cvar_scr_centertime)
1209 if(time > self.vote_nagtime)
1212 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1216 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1218 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1219 self.max_armorvalue = 0;
1222 if(self.classname == "player") {
1223 local vector m1, m2;
1225 // if(self.netname == "Wazat")
1226 // bprint(self.classname, "\n");
1228 CheckRules_Player();
1231 PrintWelcomeMessage(self);
1233 if(cvar("g_lms") || !cvar("sv_spectate"))
1234 if((time - self.jointime) <= cvar("welcome_message_time"))
1235 PrintWelcomeMessage(self);
1237 if (intermission_running)
1239 IntermissionThink (); // otherwise a button could be missed between
1240 return; // the think tics
1243 if(time > self.teleport_time)
1245 self.effects = self.effects - (self.effects & EF_NODRAW);
1246 if(self.weaponentity)
1247 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1250 Nixnex_GiveCurrentWeapon();
1251 UpdateSelectedPlayer();
1253 if (self.deadflag != DEAD_NO)
1255 float button_pressed, force_respawn;
1257 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1258 force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1259 if (self.deadflag == DEAD_DYING)
1262 self.deadflag = DEAD_RESPAWNING;
1263 else if(!button_pressed)
1264 self.deadflag = DEAD_DEAD;
1266 else if (self.deadflag == DEAD_DEAD)
1269 self.deadflag = DEAD_RESPAWNABLE;
1271 else if (self.deadflag == DEAD_RESPAWNABLE)
1274 self.deadflag = DEAD_RESPAWNING;
1276 else if (self.deadflag == DEAD_RESPAWNING)
1278 if(time > self.death_time)
1281 ShowRespawnCountdown();
1285 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1289 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1290 dist = self.oldorigin - self.origin;
1292 self.lms_traveled_distance += fabs(vlen(dist));
1294 if(cvar("g_campaign"))
1295 if(!campaign_bots_may_start)
1297 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1298 self.lms_traveled_distance = 0;
1301 if(time > self.lms_nextcheck)
1303 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1304 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1306 centerprint(self, cvar_string("g_lms_campcheck_message"));
1307 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1308 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1309 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');
1311 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1312 self.lms_traveled_distance = 0;
1316 if (self.button5 && !self.hook.state)
1321 self.view_ofs = PL_CROUCH_VIEW_OFS;
1322 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1329 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1330 if (!trace_startsolid)
1332 self.crouch = FALSE;
1333 self.view_ofs = PL_VIEW_OFS;
1334 setsize (self, PL_MIN, PL_MAX);
1339 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1340 local string defaultmodel;
1341 defaultmodel = cvar_string("sv_defaultplayermodel");
1343 if (defaultmodel != self.model)
1347 setmodel_lod (self, defaultmodel);
1348 setsize (self, m1, m2);
1351 if (self.skin != cvar("sv_defaultplayerskin"))
1352 self.skin = cvar("sv_defaultplayerskin");
1354 if (self.playermodel != self.model)
1356 self.playermodel = CheckPlayerModel(self.playermodel);
1359 setmodel_lod (self, self.playermodel);
1360 setsize (self, m1, m2);
1365 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1366 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1370 if (self.skin != stof(self.playerskin))
1371 self.skin = stof(self.playerskin);
1375 GrapplingHookFrame();
1380 float zoomfactor, zoomspeed, zoomdir;
1381 zoomfactor = self.cvar_cl_zoomfactor;
1382 if(zoomfactor < 1 || zoomfactor > 16)
1384 zoomspeed = self.cvar_cl_zoomspeed;
1385 if(zoomspeed >= 0) // < 0 is instant zoom
1386 if(zoomspeed < 0.5 || zoomspeed > 16)
1389 zoomdir = self.button4;
1391 if(self.weapon == WEP_NEX)
1392 if(!cvar("g_minstagib"))
1396 self.has_zoomed = 1;
1400 if(zoomspeed <= 0) // instant zoom
1403 self.viewzoom = 1 / zoomfactor;
1409 // geometric zoom would be:
1410 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1411 // however, testing showed that arithmetic/harmonic zoom works better
1413 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1414 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1415 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1417 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1418 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1419 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1423 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1430 if (cvar("g_minstagib"))
1431 minstagib_ammocheck();
1436 //self.angles_y=self.v_angle_y + 90; // temp
1438 //if (TetrisPreFrame()) return;
1439 } else if(gameover) {
1440 if (intermission_running)
1441 IntermissionThink (); // otherwise a button could be missed between
1443 } else if(self.classname == "observer") {
1445 if (self.flags & FL_JUMPRELEASED) {
1446 if (self.button2 && self.version == cvar("gameversion")) {
1447 self.welcomemessage_time = 0;
1448 self.flags = self.flags - FL_JUMPRELEASED;
1449 LeaveSpectatorMode();
1451 } else if(self.button0 && self.version == cvar("gameversion")) {
1452 self.welcomemessage_time = 0;
1453 self.flags = self.flags - FL_JUMPRELEASED;
1454 if(SpectateNext() == 1) {
1455 self.classname = "spectator";
1459 if (!(self.button0 || self.button2)) {
1460 self.flags = self.flags | FL_JUMPRELEASED;
1463 PrintWelcomeMessage(self);
1464 } else if(self.classname == "spectator") {
1465 if (self.flags & FL_JUMPRELEASED) {
1466 if (self.button2 && self.version == cvar("gameversion")) {
1467 self.welcomemessage_time = 0;
1468 self.flags = self.flags - FL_JUMPRELEASED;
1469 LeaveSpectatorMode();
1471 } else if(self.button0) {
1472 self.welcomemessage_time = 0;
1473 self.flags = self.flags - FL_JUMPRELEASED;
1474 if(SpectateNext() == 1) {
1475 self.classname = "spectator";
1477 self.classname = "observer";
1478 PutClientInServer();
1480 } else if (self.button3) {
1481 self.welcomemessage_time = 0;
1482 self.flags = self.flags - FL_JUMPRELEASED;
1483 self.classname = "observer";
1484 PutClientInServer();
1489 if (!(self.button0 || self.button3)) {
1490 self.flags = self.flags | FL_JUMPRELEASED;
1493 PrintWelcomeMessage(self);
1494 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1503 Called every frame for each client after the physics are run
1506 void PlayerPostThink (void)
1508 // Savage: Check for nameless players
1509 if (strlen(self.netname) < 1) {
1510 self.netname = "Player";
1511 stuffcmd(self, "seta _cl_name Player\n");
1514 if(self.classname == "player") {
1515 CheckRules_Player();
1520 if (intermission_running)
1521 return; // intermission or finale
1523 //PrintWelcomeMessage(self);
1524 //if (TetrisPostFrame()) return;
1525 } else if (self.classname == "observer") {
1527 } else if (self.classname == "spectator") {