1 void info_player_start (void)
3 self.classname = "info_player_deathmatch";
7 void info_player_deathmatch (void)
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");
240 self.modelindex_lod1 = self.modelindex;
243 self.modelindex_lod1 = -1;
245 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2.zym");
250 self.modelindex_lod2 = self.modelindex;
253 self.modelindex_lod2 = -1;
255 precache_model(modelname);
256 setmodel(e, modelname);
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);
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);
293 DropFlag(self.flagcarried);
295 DistributeFragsAmongTeam(self, self.team, 1);
297 if(self.frags <= 0 && self.frags > -666 && cvar("g_lms") && self.killcount != -666)
298 bprint ("^4", self.netname, "^4 has no more lives left\n");
299 else if(self.killcount != -666)
300 bprint ("^4", self.netname, "^4 is spectating now\n");
302 self.classname = "observer";
304 self.takedamage = DAMAGE_NO;
305 self.solid = SOLID_NOT;
306 self.movetype = MOVETYPE_NOCLIP;
307 self.flags = FL_CLIENT | FL_NOTARGET;
308 self.armorvalue = 666;
310 self.armorvalue = cvar("g_balance_armor_start");
311 self.pauserotarmor_finished = 0;
312 self.pauserothealth_finished = 0;
313 self.pauseregen_finished = 0;
314 self.damageforcescale = 0;
324 self.pain_finished = 0;
325 self.strength_finished = 0;
326 self.invincible_finished = 0;
328 self.think = SUB_Null;
332 self.deadflag = DEAD_NO;
333 self.angles = spot.angles;
335 self.fixangle = TRUE;
338 self.view_ofs = PL_VIEW_OFS;
339 setorigin (self, spot.origin);
340 setsize (self, '0 0 0', '0 0 0');
341 self.oldorigin = self.origin;
346 self.weaponmodel = "";
347 self.weaponentity = world;
348 self.killcount = -666;
349 self.velocity = '0 0 0';
350 self.avelocity = '0 0 0';
351 self.punchangle = '0 0 0';
352 self.punchvector = '0 0 0';
353 self.oldvelocity = self.velocity;
354 self.customizeentityforclient = Client_customizeentityforclient;
360 Spawnqueue_Insert(self);
364 Spawnqueue_Unmark(self);
365 Spawnqueue_Remove(self);
368 else if(!cvar("g_lms"))
377 Called when a client spawns in the server
380 void PutClientInServer (void)
382 if(clienttype(self) == CLIENTTYPE_BOT)
384 self.classname = "player";
386 else if(clienttype(self) == CLIENTTYPE_REAL)
389 WriteByte(MSG_ONE, SVC_SETVIEW);
390 WriteEntity(MSG_ONE, self);
393 // player is dead and becomes observer
394 if(cvar("g_lms") && self.frags < 1)
395 self.classname = "observer";
399 self.classname = "observer";
401 if(self.classname == "player") {
404 spot = SelectSpawnPoint (FALSE);
406 RemoveGrapplingHook(self); // Wazat's Grappling Hook
408 self.classname = "player";
409 self.iscreature = TRUE;
410 self.movetype = MOVETYPE_WALK;
411 self.solid = SOLID_SLIDEBOX;
412 self.flags = FL_CLIENT;
413 self.takedamage = DAMAGE_AIM;
415 self.health = cvar("g_balance_health_start");
416 self.air_finished = time + 12;
418 self.armorvalue = cvar("g_balance_armor_start");
419 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
420 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
421 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
422 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
423 self.damageforcescale = 2;
432 self.pain_finished = 0;
433 self.strength_finished = 0;
434 self.invincible_finished = 0;
436 //self.speed_finished = 0;
437 //self.slowmo_finished = 0;
438 // players have no think function
439 self.think = SUB_Null;
442 self.switchweapon = 0;
447 self.deadflag = DEAD_NO;
449 self.angles = spot.angles;
451 self.angles_z = 0; // never spawn tilted even if the spot says to
452 self.fixangle = TRUE; // turn this way immediately
453 self.velocity = '0 0 0';
454 self.avelocity = '0 0 0';
455 self.punchangle = '0 0 0';
456 self.punchvector = '0 0 0';
457 self.oldvelocity = self.velocity;
462 self.customizeentityforclient = Client_customizeentityforclient;
464 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
465 local string defaultmodel;
466 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
467 setmodel_lod (self, defaultmodel);
468 self.skin = stof(cvar_string("sv_defaultplayerskin"));
470 self.playermodel = CheckPlayerModel(self.playermodel);
471 setmodel_lod (self, self.playermodel);
473 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
475 self.skin = stof(self.playerskin);
479 self.view_ofs = PL_VIEW_OFS;
480 setsize (self, PL_MIN, PL_MAX);
481 self.spawnorigin = spot.origin;
482 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
483 // don't reset back to last position, even if new position is stuck in solid
484 self.oldorigin = self.origin;
488 self.ammo_shells = cvar("g_lms_start_ammo_shells");
489 self.ammo_nails = cvar("g_lms_start_ammo_nails");
490 self.ammo_rockets = cvar("g_lms_start_ammo_rockets");
491 self.ammo_cells = cvar("g_lms_start_ammo_cells");
492 self.health = cvar("g_lms_start_health");
493 self.armorvalue = cvar("g_lms_start_armor");
495 else if (cvar("g_use_ammunition")) {
496 self.ammo_shells = cvar("g_start_ammo_shells");
497 self.ammo_nails = cvar("g_start_ammo_nails");
498 self.ammo_rockets = cvar("g_start_ammo_rockets");
499 self.ammo_cells = cvar("g_start_ammo_cells");
501 self.ammo_shells = 999;
502 self.ammo_nails = 999;
503 self.ammo_rockets = 999;
504 self.ammo_cells = 999;
508 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
510 self.items = self.items | IT_LASER;
511 self.switchweapon = WEP_LASER;
513 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
515 self.items = self.items | IT_SHOTGUN;
516 self.switchweapon = WEP_SHOTGUN;
518 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
520 self.items = self.items | IT_UZI;
521 self.switchweapon = WEP_UZI;
523 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
525 self.items = self.items | IT_GRENADE_LAUNCHER;
526 self.switchweapon = WEP_GRENADE_LAUNCHER;
528 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
530 self.items = self.items | IT_ELECTRO;
531 self.switchweapon = WEP_ELECTRO;
533 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
535 self.items = self.items | IT_CRYLINK;
536 self.switchweapon = WEP_CRYLINK;
538 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
540 self.items = self.items | IT_NEX;
541 self.switchweapon = WEP_NEX;
543 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
545 self.items = self.items | IT_HAGAR;
546 self.switchweapon = WEP_HAGAR;
548 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
550 self.items = self.items | IT_ROCKET_LAUNCHER;
551 self.switchweapon = WEP_ROCKET_LAUNCHER;
554 if(cvar("g_instagib"))
557 self.switchweapon = WEP_NEX;
558 self.ammo_cells = 999;
561 if(cvar("g_rocketarena"))
563 self.items = IT_ROCKET_LAUNCHER;
564 self.switchweapon = WEP_ROCKET_LAUNCHER;
565 self.ammo_rockets = 999;
571 // will be done later
574 if(cvar("g_minstagib"))
579 self.switchweapon = WEP_NEX;
580 self.ammo_cells = cvar("g_minstagib_ammo_start");
581 self.jump_interval = time;
586 Spawnqueue_Remove(self);
587 Spawnqueue_Mark(self);
590 self.event_damage = PlayerDamage;
592 self.bot_attack = TRUE;
594 self.statdraintime = time + 5;
595 self.button0 = self.button1 = self.button2 = self.button3 = 0;
597 if(self.killcount == -666) {
604 self.cnt = WEP_LASER;
605 self.nixnex_lastchange_id = -1;
607 CL_SpawnWeaponentity();
608 self.alpha = default_player_alpha;
609 self.exteriorweaponentity.alpha = default_weapon_alpha;
611 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
612 self.lms_traveled_distance = 0;
614 if(cvar("spawn_debug"))
616 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
617 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
620 //stuffcmd(self, "chase_active 0");
621 //stuffcmd(self, "set viewsize $tmpviewsize \n");
622 } else if(self.classname == "observer") {
623 PutObserverInServer ();
632 void SetNewParms (void)
642 void SetChangeParms (void)
651 Called when a client types 'kill' in the console
654 void ClientKill (void)
656 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
659 void FixClientCvars(entity e)
661 // send prediction settings to the client
662 stuffcmd(e, "\nin_bindmap 0 0\n");
663 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
664 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
665 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
666 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
667 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
668 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
669 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
670 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
671 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
672 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
673 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
674 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
675 stuffcmd(e, "cl_movement_edgefriction 1\n");
682 Called when a client connects to the server
685 string ColoredTeamName(float t);
686 //void dom_player_join_team(entity pl);
687 void ClientConnect (void)
691 self.classname = "player_joining";
692 self.flags = self.flags | FL_CLIENT;
693 self.version_nagtime = time + 10 + random() * 10;
697 dprint("BUG player count is lower than zero, this cannot happen!\n");
703 //if(cvar("g_domination"))
704 // dom_player_join_team(self);
706 //JoinBestTeam(self, FALSE);
708 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
709 self.classname = "observer";
711 self.classname = "player";
712 campaign_bots_may_start = 1;
715 self.playerid = (playerid_last = playerid_last + 1);
716 if(cvar("sv_eventlog"))
718 if(clienttype(self) == CLIENTTYPE_REAL)
722 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
723 s = strcat(":team:", ftos(self.playerid), ":");
724 s = strcat(s, ftos(self.team));
725 GameLogEcho(s, FALSE);
728 //stuffcmd(self, "set tmpviewsize $viewsize \n");
730 bprint ("^4",self.netname);
731 bprint ("^4 connected");
733 if(cvar("g_domination") || cvar("g_ctf"))
735 bprint(" and joined the ");
736 bprint(ColoredTeamName(self.team));
741 self.welcomemessage_time = 0;
743 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
744 // TODO: is this being used for anything else than cd tracks?
745 // Remember: SVC_CDTRACK exists. Maybe it should be used.
747 FixClientCvars(self);
749 // Wazat's grappling hook
750 SetGrappleHookBindings();
752 // get autoswitch state from player
753 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1; cmd autoswitch $1\"\n");
754 stuffcmd(self, "cmd autoswitch $cl_autoswitch\n");
756 // get version info from player
757 stuffcmd(self, "cmd clientversion $gameversion\n");
759 // get other cvars from player
762 // set cvar for team scoreboard
766 t = cvar("teamplay");
767 // 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
768 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
771 stuffcmd(self, "set teamplay 0\n");
775 self.frags = cvar("fraglimit");
776 // no fraglimit was set, so player gets 999 lives
780 self.frags = LMS_NewPlayerLives();
786 else if(cvar("g_arena"))
788 self.classname = "observer";
789 Spawnqueue_Insert(self);
792 bot_relinkplayerlist();
794 self.jointime = time;
801 Called when a client disconnects from the server
804 void(entity e) DropFlag;
805 .entity chatbubbleentity;
806 .entity teambubbleentity;
807 void ClientDisconnect (void)
810 if(cvar("sv_eventlog"))
811 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
812 bprint ("^4",self.netname);
813 bprint ("^4 disconnected\n");
815 if (self.chatbubbleentity)
817 remove (self.chatbubbleentity);
818 self.chatbubbleentity = world;
821 if (self.teambubbleentity)
823 remove (self.teambubbleentity);
824 self.teambubbleentity = world;
830 DropFlag(self.flagcarried);
832 DistributeFragsAmongTeam(self, self.team, 1);
835 self.flags = self.flags - (self.flags & FL_CLIENT);
836 bot_relinkplayerlist();
840 if(self.weaponentity)
841 if(self.weaponentity.lasertarget)
842 remove(self.weaponentity.lasertarget);
846 Spawnqueue_Unmark(self);
847 Spawnqueue_Remove(self);
855 void() ChatBubbleThink =
857 self.nextthink = time;
858 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
860 self.owner.chatbubbleentity = world;
864 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
865 if (self.owner.buttonchat && !self.owner.deadflag)
866 self.model = self.mdl;
871 void() UpdateChatBubble =
873 if (!self.modelindex)
875 // spawn a chatbubble entity if needed
876 if (!self.chatbubbleentity)
878 self.chatbubbleentity = spawn();
879 self.chatbubbleentity.owner = self;
880 self.chatbubbleentity.exteriormodeltoclient = self;
881 self.chatbubbleentity.think = ChatBubbleThink;
882 self.chatbubbleentity.nextthink = time;
883 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
884 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
885 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
886 self.chatbubbleentity.model = "";
891 void() TeamBubbleThink =
893 self.nextthink = time;
894 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
896 self.owner.teambubbleentity = world;
900 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
901 if (self.owner.buttonchat || self.owner.deadflag)
904 self.model = self.mdl;
908 float() TeamBubble_customizeentityforclient
910 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
913 void() UpdateTeamBubble =
915 if (!self.modelindex || !cvar("teamplay"))
917 // spawn a teambubble entity if needed
918 if (!self.teambubbleentity && cvar("teamplay"))
920 self.teambubbleentity = spawn();
921 self.teambubbleentity.owner = self;
922 self.teambubbleentity.exteriormodeltoclient = self;
923 self.teambubbleentity.think = TeamBubbleThink;
924 self.teambubbleentity.nextthink = time;
925 setmodel(self.teambubbleentity, "models/misc/teambubble.spr");
926 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
927 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
928 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
929 self.teambubbleentity.mdl = self.teambubbleentity.model;
930 self.teambubbleentity.model = self.teambubbleentity.mdl;
931 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
935 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
936 // added to the model skins
937 /*void() UpdateColorModHack =
940 c = self.clientcolors & 15;
941 // LordHavoc: only bothering to support white, green, red, yellow, blue
942 if (teamplay == 0) self.colormod = '0 0 0';
943 else if (c == 0) self.colormod = '1.00 1.00 1.00';
944 else if (c == 3) self.colormod = '0.10 1.73 0.10';
945 else if (c == 4) self.colormod = '1.73 0.10 0.10';
946 else if (c == 12) self.colormod = '1.22 1.22 0.10';
947 else if (c == 13) self.colormod = '0.10 0.10 1.73';
948 else self.colormod = '1 1 1';
957 void player_powerups (void)
959 if (cvar("g_minstagib"))
961 self.effects = EF_FULLBRIGHT;
962 if (self.items & IT_STRENGTH)
964 if (time > self.strength_finished)
966 self.alpha = default_player_alpha;
967 self.exteriorweaponentity.alpha = default_weapon_alpha;
968 self.items = self.items - (self.items & IT_STRENGTH);
969 sprint(self, "^3Invisibility has worn off\n");
974 if (time < self.strength_finished)
976 self.alpha = cvar("g_minstagib_invis_alpha");
977 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
978 self.items = self.items | IT_STRENGTH;
979 sprint(self, "^3You are invisible\n");
983 if (self.items & IT_INVINCIBLE)
985 if (time > self.invincible_finished)
987 self.items = self.items - (self.items & IT_INVINCIBLE);
988 sprint(self, "^3Speed has worn off\n");
993 if (time < self.invincible_finished)
995 self.items = self.items | IT_INVINCIBLE;
996 sprint(self, "^3You are on speed\n");
1002 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1003 if (self.items & IT_STRENGTH)
1005 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1006 if (time > self.strength_finished)
1008 self.items = self.items - (self.items & IT_STRENGTH);
1009 sprint(self, "^3Strength has worn off\n");
1014 if (time < self.strength_finished)
1016 self.items = self.items | IT_STRENGTH;
1017 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1020 if (self.items & IT_INVINCIBLE)
1022 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1023 if (time > self.invincible_finished)
1025 self.items = self.items - (self.items & IT_INVINCIBLE);
1026 sprint(self, "^3Shield has worn off\n");
1031 if (time < self.invincible_finished)
1033 self.items = self.items | IT_INVINCIBLE;
1034 sprint(self, "^3Shield surrounds you\n");
1038 if (cvar("g_fullbrightplayers"))
1039 self.effects = self.effects | EF_FULLBRIGHT;
1041 // midair gamemode: damage only while in the air
1042 // if in midair mode, being on ground grants temporary invulnerability
1043 // (this is so that multishot weapon don't clear the ground flag on the
1044 // first damage in the frame, leaving the player vulnerable to the
1045 // remaining hits in the same frame)
1046 if (self.flags & FL_ONGROUND)
1047 if (cvar("g_midair"))
1048 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1050 if (time < self.spawnshieldtime)
1051 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1054 float CalcRegen(float current, float stable, float maxv, float regenfactor)
1056 if(current > stable)
1058 else if(current > stable - 0.25) // when close enough, "snap"
1061 return bound(0, current + (stable - current) * regenfactor * frametime, maxv);
1064 void player_regen (void)
1066 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1067 maxh = cvar("g_balance_health_stable");
1068 maxa = cvar("g_balance_armor_stable");
1069 limith = cvar("g_balance_health_limit");
1070 limita = cvar("g_balance_armor_limit");
1072 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1075 if(cvar("g_runematch"))
1077 max_mod = regen_mod = rot_mod = limit_mod = 1;
1078 if (self.runes & RUNE_REGEN)
1080 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1082 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1083 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1084 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1088 regen_mod = cvar("g_balance_rune_regen_regenrate");
1089 max_mod = cvar("g_balance_rune_regen_hpmod");
1090 limit_mod = cvar("g_balance_rune_regen_limitmod");
1093 else if (self.runes & CURSE_VENOM)
1095 max_mod = cvar("g_balance_curse_venom_hpmod");
1096 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1097 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1099 rot_mod = cvar("g_balance_curse_venom_rotrate");
1100 limit_mod = cvar("g_balance_curse_venom_limitmod");
1101 //if (!self.runes & RUNE_REGEN)
1102 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1104 maxh = maxh * max_mod;
1105 //maxa = maxa * max_mod;
1107 if (time > self.pauserotarmor_finished)
1109 if (self.armorvalue > maxa)
1110 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1112 if (time > self.pauserothealth_finished)
1114 if (self.health > maxh)
1115 self.health = bound(0, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime, 1000);
1117 if (time > self.pauseregen_finished)
1119 self.health = CalcRegen(self.health, maxh, 1000, regen_mod * cvar("g_balance_health_regen"));
1120 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1125 if (time > self.pauserothealth_finished)
1126 if (self.health > maxh)
1127 self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
1128 if (time > self.pauserotarmor_finished)
1129 if (self.armorvalue > maxa)
1130 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1131 if (time > self.pauseregen_finished)
1133 self.health = CalcRegen(self.health, maxh, 1000, cvar("g_balance_health_regen"));
1134 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1138 if (self.health > limith)
1139 self.health = limith;
1141 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1142 if (self.armorvalue > limita)
1143 self.armorvalue = limita;
1147 ======================
1148 spectate mode routines
1149 ======================
1151 void SpectateCopy(entity spectatee) {
1152 self.armortype = spectatee.armortype;
1153 self.armorvalue = spectatee.armorvalue;
1154 self.currentammo = spectatee.currentammo;
1155 self.effects = spectatee.effects;
1156 self.health = spectatee.health;
1158 self.items = spectatee.items;
1159 self.punchangle = spectatee.punchangle;
1160 self.view_ofs = spectatee.view_ofs;
1161 self.v_angle = spectatee.v_angle;
1162 self.viewzoom = spectatee.viewzoom;
1163 setorigin(self, spectatee.origin);
1164 setsize(self, spectatee.mins, spectatee.maxs);
1167 void SpectateUpdate() {
1169 PutObserverInServer();
1171 if (self != self.enemy) {
1172 if(self.enemy.flags & FL_NOTARGET)
1173 PutObserverInServer();
1174 SpectateCopy(self.enemy);
1175 self.dmg_take = self.enemy.dmg_take;
1176 self.dmg_save = self.enemy.dmg_save;
1177 self.dmg_inflictor = self.enemy.dmg_inflictor;
1178 self.fixangle = TRUE;
1179 self.angles = self.enemy.v_angle;
1180 //msg_entity = self;
1181 //WriteByte(MSG_ONE, SVC_SETANGLE);
1182 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1183 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1184 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1188 float SpectateNext() {
1189 other = find(self.enemy, classname, "player");
1191 other = find(other, classname, "player");
1196 if(self.enemy.classname == "player") {
1198 WriteByte(MSG_ONE, SVC_SETVIEW);
1199 WriteEntity(MSG_ONE, self.enemy);
1200 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1210 ShowRespawnCountdown()
1212 Update a respawn countdown display.
1215 void ShowRespawnCountdown()
1218 if(self.deadflag == DEAD_NO) // just respawned?
1222 number = ceil(self.death_time - time);
1225 if(number <= self.respawn_countdown)
1227 self.respawn_countdown = number - 1;
1228 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
1229 stuffcmd(self, strcat("play2 announcer/robotic/", ftos(number), ".ogg\n"));
1234 void LeaveSpectatorMode()
1236 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1237 self.classname = "player";
1238 if(cvar("g_campaign") || cvar("g_balance_teams"))
1239 JoinBestTeam(self, 0);
1240 if(cvar("g_campaign"))
1241 campaign_bots_may_start = 1;
1242 PutClientInServer();
1243 if(!(self.flags & FL_NOTARGET))
1244 bprint ("^4", self.netname, "^4 is playing now\n");
1245 centerprint(self,"");
1248 stuffcmd(self,"menu_showteamselect\n");
1257 Called every frame for each client before the physics are run
1260 void() ctf_setstatus;
1261 .float vote_nagtime;
1262 void PlayerPreThink (void)
1264 if(strlen(self.netname) > 0)
1265 if(substring(self.netname, strlen(self.netname) - 1, 1) == "^")
1266 self.netname = strzone(strcat(substring(self.netname, 0, strlen(self.netname) - 1), " ")); // BROKEN COLORS can be annoying!
1269 if(self.version_nagtime)
1270 if(self.cvar_g_nexuizversion)
1271 if(time > self.version_nagtime)
1273 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1274 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1276 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");
1277 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1279 self.version_nagtime = 0;
1283 if(self.cvar_scr_centertime)
1284 if(time > self.vote_nagtime)
1287 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1290 if(self.classname == "player") {
1291 local vector m1, m2;
1293 // if(self.netname == "Wazat")
1294 // bprint(self.classname, "\n");
1296 CheckRules_Player();
1299 PrintWelcomeMessage(self);
1301 if(cvar("g_lms") || !cvar("sv_spectate"))
1302 if((time - self.jointime) <= cvar("welcome_message_time"))
1303 PrintWelcomeMessage(self);
1305 if (intermission_running)
1307 IntermissionThink (); // otherwise a button could be missed between
1308 return; // the think tics
1311 if(time > self.teleport_time)
1313 self.effects = self.effects - (self.effects & EF_NODRAW);
1314 if(self.weaponentity)
1315 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1318 Nixnex_GiveCurrentWeapon();
1319 UpdateSelectedPlayer();
1321 if (self.deadflag != DEAD_NO)
1323 float button_pressed, force_respawn;
1325 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1326 force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1327 if (self.deadflag == DEAD_DYING)
1330 self.deadflag = DEAD_RESPAWNING;
1331 else if(!button_pressed)
1332 self.deadflag = DEAD_DEAD;
1334 else if (self.deadflag == DEAD_DEAD)
1337 self.deadflag = DEAD_RESPAWNABLE;
1339 else if (self.deadflag == DEAD_RESPAWNABLE)
1342 self.deadflag = DEAD_RESPAWNING;
1344 else if (self.deadflag == DEAD_RESPAWNING)
1346 if(time > self.death_time)
1349 ShowRespawnCountdown();
1353 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1357 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1358 dist = self.oldorigin - self.origin;
1360 self.lms_traveled_distance += fabs(vlen(dist));
1362 if(cvar("g_campaign"))
1363 if(!campaign_bots_may_start)
1365 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1366 self.lms_traveled_distance = 0;
1369 if(time > self.lms_nextcheck)
1371 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1372 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1374 centerprint(self, cvar_string("g_lms_campcheck_message"));
1375 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1376 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1377 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');
1379 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1380 self.lms_traveled_distance = 0;
1384 if (self.button5 && !self.hook.state)
1389 self.view_ofs = PL_CROUCH_VIEW_OFS;
1390 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1397 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1398 if (!trace_startsolid)
1400 self.crouch = FALSE;
1401 self.view_ofs = PL_VIEW_OFS;
1402 setsize (self, PL_MIN, PL_MAX);
1407 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1408 local string defaultmodel;
1409 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
1411 if (defaultmodel != self.model)
1415 setmodel_lod (self, defaultmodel);
1416 setsize (self, m1, m2);
1419 if (self.skin != cvar("sv_defaultplayerskin"))
1420 self.skin = cvar("sv_defaultplayerskin");
1422 if (self.playermodel != self.model)
1424 self.playermodel = CheckPlayerModel(self.playermodel);
1427 setmodel_lod (self, self.playermodel);
1428 setsize (self, m1, m2);
1433 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1434 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1438 if (self.skin != stof(self.playerskin))
1439 self.skin = stof(self.playerskin);
1443 GrapplingHookFrame();
1447 if (cvar("g_minstagib"))
1449 if (self.jump_interval <= (time + 0.1))
1451 self.jump_interval = time + 1;
1456 float zoomfactor, zoomspeed, zoomdir;
1457 zoomfactor = self.cvar_cl_zoomfactor;
1458 if(zoomfactor < 1 || zoomfactor > 16)
1460 zoomspeed = self.cvar_cl_zoomspeed;
1461 if(zoomspeed >= 0) // < 0 is instant zoom
1462 if(zoomspeed < 0.5 || zoomspeed > 16)
1465 zoomdir = self.button4;
1467 if(self.weapon == WEP_NEX)
1468 if(!cvar("g_minstagib"))
1472 self.has_zoomed = 1;
1476 if(zoomspeed <= 0) // instant zoom
1479 self.viewzoom = 1 / zoomfactor;
1485 // geometric zoom would be:
1486 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1487 // however, testing showed that arithmetic/harmonic zoom works better
1489 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1490 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1491 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1493 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1494 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1495 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1499 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1506 if (cvar("g_minstagib"))
1507 minstagib_ammocheck();
1511 //self.angles_y=self.v_angle_y + 90; // temp
1513 //if (TetrisPreFrame()) return;
1514 } else if(gameover) {
1515 if (intermission_running)
1516 IntermissionThink (); // otherwise a button could be missed between
1518 } else if(self.classname == "observer") {
1520 if (self.flags & FL_JUMPRELEASED) {
1521 if (self.button2 && self.version == cvar("gameversion")) {
1522 self.welcomemessage_time = 0;
1523 self.flags = self.flags - FL_JUMPRELEASED;
1524 LeaveSpectatorMode();
1526 } else if(self.button0 && self.version == cvar("gameversion")) {
1527 self.welcomemessage_time = 0;
1528 self.flags = self.flags - FL_JUMPRELEASED;
1529 if(SpectateNext() == 1) {
1530 self.classname = "spectator";
1534 if (!(self.button0 || self.button2)) {
1535 self.flags = self.flags | FL_JUMPRELEASED;
1538 PrintWelcomeMessage(self);
1539 } else if(self.classname == "spectator") {
1540 if (self.flags & FL_JUMPRELEASED) {
1541 if (self.button2 && self.version == cvar("gameversion")) {
1542 self.welcomemessage_time = 0;
1543 self.flags = self.flags - FL_JUMPRELEASED;
1544 LeaveSpectatorMode();
1546 } else if(self.button0) {
1547 self.welcomemessage_time = 0;
1548 self.flags = self.flags - FL_JUMPRELEASED;
1549 if(SpectateNext() == 1) {
1550 self.classname = "spectator";
1552 self.classname = "observer";
1553 PutClientInServer();
1555 } else if (self.button3) {
1556 self.welcomemessage_time = 0;
1557 self.flags = self.flags - FL_JUMPRELEASED;
1558 self.classname = "observer";
1559 PutClientInServer();
1564 if (!(self.button0 || self.button3)) {
1565 self.flags = self.flags | FL_JUMPRELEASED;
1568 PrintWelcomeMessage(self);
1569 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1578 Called every frame for each client after the physics are run
1581 void PlayerPostThink (void)
1583 // Savage: Check for nameless players
1584 if (strlen(self.netname) < 1) {
1585 self.netname = "Player";
1586 stuffcmd(self, "seta _cl_name Player\n");
1589 if(self.classname == "player") {
1590 CheckRules_Player();
1593 if (self.deadflag == DEAD_NO)
1596 if (intermission_running)
1597 return; // intermission or finale
1599 //PrintWelcomeMessage(self);
1600 //if (TetrisPostFrame()) return;
1601 } else if (self.classname == "observer") {
1603 } else if (self.classname == "spectator") {