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);
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 sound (self, CHAN_AUTO, "misc/teleport.wav", 1, ATTN_NORM);
537 } else if(self.classname == "observer") {
538 PutObserverInServer ();
547 void SetNewParms (void)
557 void SetChangeParms (void)
566 Called when a client types 'kill' in the console
569 void ClientKill (void)
571 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
574 void FixClientCvars(entity e)
576 // send prediction settings to the client
577 stuffcmd(e, "\nin_bindmap 0 0\n");
578 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
579 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
580 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
581 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
582 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
583 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
584 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
585 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
586 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
587 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
588 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
589 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
590 stuffcmd(e, "cl_movement_edgefriction 1\n");
597 Called when a client connects to the server
600 string ColoredTeamName(float t);
601 //void dom_player_join_team(entity pl);
602 void ClientConnect (void)
606 self.classname = "player_joining";
607 self.flags = self.flags | FL_CLIENT;
608 self.version_nagtime = time + 10 + random() * 10;
612 dprint("BUG player count is lower than zero, this cannot happen!\n");
618 //if(cvar("g_domination"))
619 // dom_player_join_team(self);
621 //JoinBestTeam(self, FALSE);
623 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
624 self.classname = "observer";
626 self.classname = "player";
627 campaign_bots_may_start = 1;
630 self.playerid = (playerid_last = playerid_last + 1);
631 if(cvar("sv_eventlog"))
633 if(clienttype(self) == CLIENTTYPE_REAL)
637 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
638 s = strcat(":team:", ftos(self.playerid), ":");
639 s = strcat(s, ftos(self.team));
640 GameLogEcho(s, FALSE);
643 //stuffcmd(self, "set tmpviewsize $viewsize \n");
645 bprint ("^4",self.netname);
646 bprint ("^4 connected");
648 if(cvar("g_domination") || cvar("g_ctf"))
650 bprint(" and joined the ");
651 bprint(ColoredTeamName(self.team));
656 self.welcomemessage_time = 0;
658 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
659 // TODO: is this being used for anything else than cd tracks?
660 // Remember: SVC_CDTRACK exists. Maybe it should be used.
662 FixClientCvars(self);
665 WaypointSprite_InitClient(self);
667 // Wazat's grappling hook
668 SetGrappleHookBindings();
670 // get autoswitch state from player when he toggles it
671 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
673 // get version info from player
674 stuffcmd(self, "cmd clientversion $gameversion\n");
676 // get other cvars from player
679 // set cvar for team scoreboard
683 t = cvar("teamplay");
684 // 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
685 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
688 stuffcmd(self, "set teamplay 0\n");
692 self.frags = cvar("fraglimit");
693 // no fraglimit was set, so player gets 999 lives
697 self.frags = LMS_NewPlayerLives();
703 else if(cvar("g_arena"))
705 self.classname = "observer";
706 Spawnqueue_Insert(self);
709 bot_relinkplayerlist();
711 self.jointime = time;
718 Called when a client disconnects from the server
721 void(entity e) DropFlag;
722 .entity chatbubbleentity;
723 .entity teambubbleentity;
724 void ClientDisconnect (void)
727 if(cvar("sv_eventlog"))
728 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
729 bprint ("^4",self.netname);
730 bprint ("^4 disconnected\n");
732 if (self.chatbubbleentity)
734 remove (self.chatbubbleentity);
735 self.chatbubbleentity = world;
738 if (self.teambubbleentity)
740 remove (self.teambubbleentity);
741 self.teambubbleentity = world;
744 WaypointSprite_PlayerGone();
747 kh_Key_DropAll(self);
750 DropFlag(self.flagcarried);
752 DistributeFragsAmongTeam(self, self.team, 1);
755 self.flags = self.flags - (self.flags & FL_CLIENT);
756 bot_relinkplayerlist();
760 if(self.weaponentity)
761 if(self.weaponentity.lasertarget)
762 remove(self.weaponentity.lasertarget);
766 Spawnqueue_Unmark(self);
767 Spawnqueue_Remove(self);
775 void() ChatBubbleThink =
777 self.nextthink = time;
778 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
780 self.owner.chatbubbleentity = world;
784 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
785 if (self.owner.buttonchat && !self.owner.deadflag)
786 self.model = self.mdl;
791 void() UpdateChatBubble =
793 if (!self.modelindex)
795 // spawn a chatbubble entity if needed
796 if (!self.chatbubbleentity)
798 self.chatbubbleentity = spawn();
799 self.chatbubbleentity.owner = self;
800 self.chatbubbleentity.exteriormodeltoclient = self;
801 self.chatbubbleentity.think = ChatBubbleThink;
802 self.chatbubbleentity.nextthink = time;
803 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
804 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
805 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
806 self.chatbubbleentity.model = "";
807 self.chatbubbleentity.effects = EF_LOWPRECISION;
812 void() TeamBubbleThink =
814 self.nextthink = time;
815 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
817 self.owner.teambubbleentity = world;
821 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
822 if (self.owner.buttonchat || self.owner.deadflag)
825 self.model = self.mdl;
829 float() TeamBubble_customizeentityforclient
831 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
834 void() UpdateTeamBubble =
836 if (!self.modelindex || !cvar("teamplay"))
838 // spawn a teambubble entity if needed
839 if (!self.teambubbleentity && cvar("teamplay"))
841 self.teambubbleentity = spawn();
842 self.teambubbleentity.owner = self;
843 self.teambubbleentity.exteriormodeltoclient = self;
844 self.teambubbleentity.think = TeamBubbleThink;
845 self.teambubbleentity.nextthink = time;
846 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
847 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
848 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
849 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
850 self.teambubbleentity.mdl = self.teambubbleentity.model;
851 self.teambubbleentity.model = self.teambubbleentity.mdl;
852 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
853 self.teambubbleentity.effects = EF_LOWPRECISION;
857 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
858 // added to the model skins
859 /*void() UpdateColorModHack =
862 c = self.clientcolors & 15;
863 // LordHavoc: only bothering to support white, green, red, yellow, blue
864 if (teamplay == 0) self.colormod = '0 0 0';
865 else if (c == 0) self.colormod = '1.00 1.00 1.00';
866 else if (c == 3) self.colormod = '0.10 1.73 0.10';
867 else if (c == 4) self.colormod = '1.73 0.10 0.10';
868 else if (c == 12) self.colormod = '1.22 1.22 0.10';
869 else if (c == 13) self.colormod = '0.10 0.10 1.73';
870 else self.colormod = '1 1 1';
879 void player_powerups (void)
881 if (cvar("g_minstagib"))
883 self.effects = EF_FULLBRIGHT;
884 if (self.items & IT_STRENGTH)
886 if (time > self.strength_finished)
888 self.alpha = default_player_alpha;
889 self.exteriorweaponentity.alpha = default_weapon_alpha;
890 self.items = self.items - (self.items & IT_STRENGTH);
891 sprint(self, "^3Invisibility has worn off\n");
896 if (time < self.strength_finished)
898 self.alpha = cvar("g_minstagib_invis_alpha");
899 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
900 self.items = self.items | IT_STRENGTH;
901 sprint(self, "^3You are invisible\n");
905 if (self.items & IT_INVINCIBLE)
907 if (time > self.invincible_finished)
909 self.items = self.items - (self.items & IT_INVINCIBLE);
910 sprint(self, "^3Speed has worn off\n");
915 if (time < self.invincible_finished)
917 self.items = self.items | IT_INVINCIBLE;
918 sprint(self, "^3You are on speed\n");
924 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
925 if (self.items & IT_STRENGTH)
927 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
928 if (time > self.strength_finished)
930 self.items = self.items - (self.items & IT_STRENGTH);
931 sprint(self, "^3Strength has worn off\n");
936 if (time < self.strength_finished)
938 self.items = self.items | IT_STRENGTH;
939 sprint(self, "^3Strength infuses your weapons with devastating power\n");
942 if (self.items & IT_INVINCIBLE)
944 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
945 if (time > self.invincible_finished)
947 self.items = self.items - (self.items & IT_INVINCIBLE);
948 sprint(self, "^3Shield has worn off\n");
953 if (time < self.invincible_finished)
955 self.items = self.items | IT_INVINCIBLE;
956 sprint(self, "^3Shield surrounds you\n");
960 if (cvar("g_fullbrightplayers"))
961 self.effects = self.effects | EF_FULLBRIGHT;
963 // midair gamemode: damage only while in the air
964 // if in midair mode, being on ground grants temporary invulnerability
965 // (this is so that multishot weapon don't clear the ground flag on the
966 // first damage in the frame, leaving the player vulnerable to the
967 // remaining hits in the same frame)
968 if (self.flags & FL_ONGROUND)
969 if (cvar("g_midair"))
970 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
972 if (time < self.spawnshieldtime)
973 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
976 float CalcRegen(float current, float stable, float regenfactor)
980 else if(current > stable - 0.25) // when close enough, "snap"
983 return min(stable, current + (stable - current) * regenfactor * frametime);
986 void player_regen (void)
988 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
989 maxh = cvar("g_balance_health_stable");
990 maxa = cvar("g_balance_armor_stable");
991 limith = cvar("g_balance_health_limit");
992 limita = cvar("g_balance_armor_limit");
994 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
997 max_mod = regen_mod = rot_mod = limit_mod = 1;
999 if (self.runes & RUNE_REGEN)
1001 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1003 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1004 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1005 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1009 regen_mod = cvar("g_balance_rune_regen_regenrate");
1010 max_mod = cvar("g_balance_rune_regen_hpmod");
1011 limit_mod = cvar("g_balance_rune_regen_limitmod");
1014 else if (self.runes & CURSE_VENOM)
1016 max_mod = cvar("g_balance_curse_venom_hpmod");
1017 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1018 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1020 rot_mod = cvar("g_balance_curse_venom_rotrate");
1021 limit_mod = cvar("g_balance_curse_venom_limitmod");
1022 //if (!self.runes & RUNE_REGEN)
1023 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1025 maxh = maxh * max_mod;
1026 //maxa = maxa * max_mod;
1027 limith = limith * limit_mod;
1028 limita = limita * limit_mod;
1030 if (self.armorvalue > maxa)
1032 if (time > self.pauserotarmor_finished)
1034 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1035 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1038 else if (self.armorvalue < maxa)
1040 if (time > self.pauseregen_finished)
1042 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1043 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1046 if (self.health > maxh)
1048 if (time > self.pauserothealth_finished)
1050 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1051 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1054 else if (self.health < maxh)
1056 if (time > self.pauseregen_finished)
1058 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1059 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1063 if (self.health > limith)
1064 self.health = limith;
1065 if (self.armorvalue > limita)
1066 self.armorvalue = limita;
1068 // if player rotted to death... die!
1070 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1074 ======================
1075 spectate mode routines
1076 ======================
1078 void SpectateCopy(entity spectatee) {
1079 self.armortype = spectatee.armortype;
1080 self.armorvalue = spectatee.armorvalue;
1081 self.currentammo = spectatee.currentammo;
1082 self.effects = spectatee.effects;
1083 self.health = spectatee.health;
1085 self.items = spectatee.items;
1086 self.punchangle = spectatee.punchangle;
1087 self.view_ofs = spectatee.view_ofs;
1088 self.v_angle = spectatee.v_angle;
1089 self.viewzoom = spectatee.viewzoom;
1090 setorigin(self, spectatee.origin);
1091 setsize(self, spectatee.mins, spectatee.maxs);
1094 void SpectateUpdate() {
1096 PutObserverInServer();
1098 if (self != self.enemy) {
1099 if(self.enemy.flags & FL_NOTARGET)
1100 PutObserverInServer();
1101 SpectateCopy(self.enemy);
1102 self.dmg_take = self.enemy.dmg_take;
1103 self.dmg_save = self.enemy.dmg_save;
1104 self.dmg_inflictor = self.enemy.dmg_inflictor;
1105 self.fixangle = TRUE;
1106 self.angles = self.enemy.v_angle;
1107 //msg_entity = self;
1108 //WriteByte(MSG_ONE, SVC_SETANGLE);
1109 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1110 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1111 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1115 float SpectateNext() {
1116 other = find(self.enemy, classname, "player");
1118 other = find(other, classname, "player");
1123 if(self.enemy.classname == "player") {
1125 WriteByte(MSG_ONE, SVC_SETVIEW);
1126 WriteEntity(MSG_ONE, self.enemy);
1127 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1137 ShowRespawnCountdown()
1139 Update a respawn countdown display.
1142 void ShowRespawnCountdown()
1145 if(self.deadflag == DEAD_NO) // just respawned?
1149 number = ceil(self.death_time - time);
1152 if(number <= self.respawn_countdown)
1154 self.respawn_countdown = number - 1;
1155 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
1156 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1161 void LeaveSpectatorMode()
1163 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1164 self.classname = "player";
1165 if(cvar("g_campaign") || cvar("g_balance_teams"))
1166 JoinBestTeam(self, 0);
1167 if(cvar("g_campaign"))
1168 campaign_bots_may_start = 1;
1169 PutClientInServer();
1170 if(!(self.flags & FL_NOTARGET))
1171 bprint ("^4", self.netname, "^4 is playing now\n");
1172 centerprint(self,"");
1175 stuffcmd(self,"menu_showteamselect\n");
1184 Called every frame for each client before the physics are run
1187 void() ctf_setstatus;
1188 .float vote_nagtime;
1189 void PlayerPreThink (void)
1192 if(self.version_nagtime)
1193 if(self.cvar_g_nexuizversion)
1194 if(time > self.version_nagtime)
1196 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1197 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1199 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");
1200 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1202 self.version_nagtime = 0;
1206 if(self.cvar_scr_centertime)
1207 if(time > self.vote_nagtime)
1210 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1213 if(self.classname == "player") {
1214 local vector m1, m2;
1216 // if(self.netname == "Wazat")
1217 // bprint(self.classname, "\n");
1219 CheckRules_Player();
1222 PrintWelcomeMessage(self);
1224 if(cvar("g_lms") || !cvar("sv_spectate"))
1225 if((time - self.jointime) <= cvar("welcome_message_time"))
1226 PrintWelcomeMessage(self);
1228 if (intermission_running)
1230 IntermissionThink (); // otherwise a button could be missed between
1231 return; // the think tics
1234 if(time > self.teleport_time)
1236 self.effects = self.effects - (self.effects & EF_NODRAW);
1237 if(self.weaponentity)
1238 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1241 Nixnex_GiveCurrentWeapon();
1242 UpdateSelectedPlayer();
1244 if (self.deadflag != DEAD_NO)
1246 float button_pressed, force_respawn;
1248 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1249 force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1250 if (self.deadflag == DEAD_DYING)
1253 self.deadflag = DEAD_RESPAWNING;
1254 else if(!button_pressed)
1255 self.deadflag = DEAD_DEAD;
1257 else if (self.deadflag == DEAD_DEAD)
1260 self.deadflag = DEAD_RESPAWNABLE;
1262 else if (self.deadflag == DEAD_RESPAWNABLE)
1265 self.deadflag = DEAD_RESPAWNING;
1267 else if (self.deadflag == DEAD_RESPAWNING)
1269 if(time > self.death_time)
1272 ShowRespawnCountdown();
1276 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1280 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1281 dist = self.oldorigin - self.origin;
1283 self.lms_traveled_distance += fabs(vlen(dist));
1285 if(cvar("g_campaign"))
1286 if(!campaign_bots_may_start)
1288 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1289 self.lms_traveled_distance = 0;
1292 if(time > self.lms_nextcheck)
1294 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1295 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1297 centerprint(self, cvar_string("g_lms_campcheck_message"));
1298 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1299 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1300 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');
1302 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1303 self.lms_traveled_distance = 0;
1307 if (self.button5 && !self.hook.state)
1312 self.view_ofs = PL_CROUCH_VIEW_OFS;
1313 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1320 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1321 if (!trace_startsolid)
1323 self.crouch = FALSE;
1324 self.view_ofs = PL_VIEW_OFS;
1325 setsize (self, PL_MIN, PL_MAX);
1330 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1331 local string defaultmodel;
1332 defaultmodel = cvar_string("sv_defaultplayermodel");
1334 if (defaultmodel != self.model)
1338 setmodel_lod (self, defaultmodel);
1339 setsize (self, m1, m2);
1342 if (self.skin != cvar("sv_defaultplayerskin"))
1343 self.skin = cvar("sv_defaultplayerskin");
1345 if (self.playermodel != self.model)
1347 self.playermodel = CheckPlayerModel(self.playermodel);
1350 setmodel_lod (self, self.playermodel);
1351 setsize (self, m1, m2);
1356 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1357 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1361 if (self.skin != stof(self.playerskin))
1362 self.skin = stof(self.playerskin);
1366 GrapplingHookFrame();
1371 float zoomfactor, zoomspeed, zoomdir;
1372 zoomfactor = self.cvar_cl_zoomfactor;
1373 if(zoomfactor < 1 || zoomfactor > 16)
1375 zoomspeed = self.cvar_cl_zoomspeed;
1376 if(zoomspeed >= 0) // < 0 is instant zoom
1377 if(zoomspeed < 0.5 || zoomspeed > 16)
1380 zoomdir = self.button4;
1382 if(self.weapon == WEP_NEX)
1383 if(!cvar("g_minstagib"))
1387 self.has_zoomed = 1;
1391 if(zoomspeed <= 0) // instant zoom
1394 self.viewzoom = 1 / zoomfactor;
1400 // geometric zoom would be:
1401 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1402 // however, testing showed that arithmetic/harmonic zoom works better
1404 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1405 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1406 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1408 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1409 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1410 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1414 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1421 if (cvar("g_minstagib"))
1422 minstagib_ammocheck();
1427 //self.angles_y=self.v_angle_y + 90; // temp
1429 //if (TetrisPreFrame()) return;
1430 } else if(gameover) {
1431 if (intermission_running)
1432 IntermissionThink (); // otherwise a button could be missed between
1434 } else if(self.classname == "observer") {
1436 if (self.flags & FL_JUMPRELEASED) {
1437 if (self.button2 && self.version == cvar("gameversion")) {
1438 self.welcomemessage_time = 0;
1439 self.flags = self.flags - FL_JUMPRELEASED;
1440 LeaveSpectatorMode();
1442 } else if(self.button0 && self.version == cvar("gameversion")) {
1443 self.welcomemessage_time = 0;
1444 self.flags = self.flags - FL_JUMPRELEASED;
1445 if(SpectateNext() == 1) {
1446 self.classname = "spectator";
1450 if (!(self.button0 || self.button2)) {
1451 self.flags = self.flags | FL_JUMPRELEASED;
1454 PrintWelcomeMessage(self);
1455 } else if(self.classname == "spectator") {
1456 if (self.flags & FL_JUMPRELEASED) {
1457 if (self.button2 && self.version == cvar("gameversion")) {
1458 self.welcomemessage_time = 0;
1459 self.flags = self.flags - FL_JUMPRELEASED;
1460 LeaveSpectatorMode();
1462 } else if(self.button0) {
1463 self.welcomemessage_time = 0;
1464 self.flags = self.flags - FL_JUMPRELEASED;
1465 if(SpectateNext() == 1) {
1466 self.classname = "spectator";
1468 self.classname = "observer";
1469 PutClientInServer();
1471 } else if (self.button3) {
1472 self.welcomemessage_time = 0;
1473 self.flags = self.flags - FL_JUMPRELEASED;
1474 self.classname = "observer";
1475 PutClientInServer();
1480 if (!(self.button0 || self.button3)) {
1481 self.flags = self.flags | FL_JUMPRELEASED;
1484 PrintWelcomeMessage(self);
1485 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1494 Called every frame for each client after the physics are run
1497 void PlayerPostThink (void)
1499 // Savage: Check for nameless players
1500 if (strlen(self.netname) < 1) {
1501 self.netname = "Player";
1502 stuffcmd(self, "seta _cl_name Player\n");
1505 if(self.classname == "player") {
1506 CheckRules_Player();
1511 if (intermission_running)
1512 return; // intermission or finale
1514 //PrintWelcomeMessage(self);
1515 //if (TetrisPostFrame()) return;
1516 } else if (self.classname == "observer") {
1518 } else if (self.classname == "spectator") {