1 void info_player_start (void)
3 info_player_deathmatch();
6 void info_player_deathmatch (void)
8 self.classname = "info_player_deathmatch";
14 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
16 local entity spot, player, nextspot, previousspot, newfirstspot;
25 nextspot = spot.chain;
26 // count team mismatches as bad spots
28 local float spotactive;
31 // filter out spots for assault
32 if(spot.target != "") {
34 ent = find(world, targetname, spot.target);
36 if(ent.classname == "target_objective")
37 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
39 ent = find(ent, targetname, spot.target);
43 if (spot.team == teamcheck && spotactive > 0)
50 if (vlen(player.origin - spot.origin) < mindist)
52 player = player.chain;
58 previousspot.chain = spot;
65 spawn_allgood = FALSE;
69 // if we couldn't find ANY good points, return the original list
71 newfirstspot = firstspot;
75 entity Spawn_RandomPoint(entity firstspot)
79 // count number of spots
84 numspots = numspots + 1;
88 numspots = numspots * random();
90 while (spot.chain && numspots >= 1)
92 numspots = numspots - 1;
98 entity Spawn_FurthestPoint(entity firstspot, entity playerlist)
100 local entity best, spot, player;
101 local float bestrating, rating;
103 bestrating = -1000000;
112 rating = min(rating, vlen(player.origin - spot.origin));
113 player = player.chain;
115 rating = rating + random() * 16;
116 if (bestrating < rating)
130 Finds a point to respawn
133 entity SelectSpawnPoint (float anypoint)
135 local float teamcheck;
136 local entity spot, firstspot, playerlist;
138 spot = find (world, classname, "testplayerstart");
144 if(!anypoint && (g_ctf || g_assault))
145 teamcheck = self.team;
147 // get the list of players
148 playerlist = findchain(classname, "player");
149 // get the entire list of spots
150 firstspot = findchain(classname, "info_player_deathmatch");
151 // filter out the bad ones
152 // (note this returns the original list if none survived)
153 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
155 // there is 50/50 chance of choosing a random spot or the furthest spot
156 // (this means that roughly every other spawn will be furthest, so you
157 // usually won't get fragged at spawn twice in a row)
158 if (arena_roundbased)
160 firstspot = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
161 spot = Spawn_RandomPoint(firstspot);
163 else if (random() > 0.5 || spawn_allbad || spawn_allgood)
164 spot = Spawn_RandomPoint(firstspot);
166 spot = Spawn_FurthestPoint(firstspot, playerlist);
170 if(cvar("spawn_debug"))
173 error ("PutClientInServer: no start points on level");
183 Checks if the argument string can be a valid playermodel.
184 Returns a valid one in doubt.
187 string FallbackPlayerModel = "models/player/marine.zym";
188 string CheckPlayerModel(string plyermodel) {
189 if(strlen(plyermodel) < 4)
190 return FallbackPlayerModel;
191 if( substring(plyermodel,0,14) != "models/player/")
192 return FallbackPlayerModel;
193 else if(cvar("sv_servermodelsonly"))
195 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
196 return FallbackPlayerModel;
197 if(!fexists(plyermodel))
198 return FallbackPlayerModel;
205 Client_customizeentityforclient
210 float Client_customizeentityforclient()
212 #ifdef ALLOW_VARIABLE_LOD
214 // other: the player viewing me
218 if(self.flags & FL_NOTARGET) // we don't need LOD for spectators
221 if(other.cvar_cl_playerdetailreduction <= 0)
223 if(other.cvar_cl_playerdetailreduction <= -2)
224 self.modelindex = self.modelindex_lod2;
225 else if(other.cvar_cl_playerdetailreduction <= -1)
226 self.modelindex = self.modelindex_lod1;
228 self.modelindex = self.modelindex_lod0;
232 distance = vlen(self.origin - other.origin);
233 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
235 self.modelindex = self.modelindex_lod2;
237 self.modelindex = self.modelindex_lod1;
239 self.modelindex = self.modelindex_lod0;
246 void setmodel_lod(entity e, string modelname)
248 #ifdef ALLOW_VARIABLE_LOD
251 // FIXME: this only supports 3-letter extensions
252 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
256 setmodel(e, s); // players have high precision
257 self.modelindex_lod1 = self.modelindex;
260 self.modelindex_lod1 = -1;
262 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
266 setmodel(e, s); // players have high precision
267 self.modelindex_lod2 = self.modelindex;
270 self.modelindex_lod2 = -1;
272 precache_model(modelname);
273 setmodel(e, modelname); // players have high precision
274 self.modelindex_lod0 = self.modelindex;
276 if(self.modelindex_lod1 < 0)
277 self.modelindex_lod1 = self.modelindex;
279 if(self.modelindex_lod2 < 0)
280 self.modelindex_lod2 = self.modelindex;
282 precache_model(modelname);
283 setmodel(e, modelname); // players have high precision
285 player_setupanimsformodel();
292 putting a client as observer in the server
295 void PutObserverInServer (void)
298 spot = SelectSpawnPoint (TRUE);
299 RemoveGrapplingHook(self); // Wazat's Grappling Hook
301 if(clienttype(self) == CLIENTTYPE_REAL)
304 WriteByte(MSG_ONE, SVC_SETVIEW);
305 WriteEntity(MSG_ONE, self);
309 kh_Key_DropAll(self, TRUE);
312 DropFlag(self.flagcarried);
314 WaypointSprite_PlayerDead();
316 DistributeFragsAmongTeam(self, self.team, 1);
318 if(self.frags <= 0 && self.frags > -666 && g_lms && self.killcount != -666)
319 bprint ("^4", self.netname, "^4 has no more lives left\n");
320 else if(self.killcount != -666)
321 bprint ("^4", self.netname, "^4 is spectating now\n");
323 self.classname = "observer";
325 self.takedamage = DAMAGE_NO;
326 self.solid = SOLID_NOT;
327 self.movetype = MOVETYPE_NOCLIP;
328 self.flags = FL_CLIENT | FL_NOTARGET;
329 self.armorvalue = 666;
331 self.armorvalue = cvar("g_balance_armor_start");
332 self.pauserotarmor_finished = 0;
333 self.pauserothealth_finished = 0;
334 self.pauseregen_finished = 0;
335 self.damageforcescale = 0;
343 self.pain_finished = 0;
344 self.strength_finished = 0;
345 self.invincible_finished = 0;
347 self.think = SUB_Null;
351 self.deadflag = DEAD_NO;
352 self.angles = spot.angles;
354 self.fixangle = TRUE;
357 self.view_ofs = PL_VIEW_OFS;
358 setorigin (self, spot.origin);
359 setsize (self, '0 0 0', '0 0 0');
360 self.oldorigin = self.origin;
365 self.weaponmodel = "";
366 self.weaponentity = world;
367 self.killcount = -666;
368 self.velocity = '0 0 0';
369 self.avelocity = '0 0 0';
370 self.punchangle = '0 0 0';
371 self.punchvector = '0 0 0';
372 self.oldvelocity = self.velocity;
373 self.customizeentityforclient = Client_customizeentityforclient;
379 Spawnqueue_Insert(self);
383 Spawnqueue_Unmark(self);
384 Spawnqueue_Remove(self);
396 Called when a client spawns in the server
399 void PutClientInServer (void)
401 if(clienttype(self) == CLIENTTYPE_BOT)
403 self.classname = "player";
405 else if(clienttype(self) == CLIENTTYPE_REAL)
408 WriteByte(MSG_ONE, SVC_SETVIEW);
409 WriteEntity(MSG_ONE, self);
412 // player is dead and becomes observer
413 if(g_lms && self.frags < 1)
414 self.classname = "observer";
418 self.classname = "observer";
420 if(self.classname == "player") {
423 spot = SelectSpawnPoint (FALSE);
425 RemoveGrapplingHook(self); // Wazat's Grappling Hook
427 self.classname = "player";
428 self.iscreature = TRUE;
429 self.movetype = MOVETYPE_WALK;
430 self.solid = SOLID_SLIDEBOX;
431 self.flags = FL_CLIENT;
432 self.takedamage = DAMAGE_AIM;
434 self.air_finished = time + 12;
437 self.ammo_shells = start_ammo_shells;
438 self.ammo_nails = start_ammo_nails;
439 self.ammo_rockets = start_ammo_rockets;
440 self.ammo_cells = start_ammo_cells;
441 self.health = start_health;
442 self.armorvalue = start_armorvalue;
443 self.items = start_items;
444 self.switchweapon = start_switchweapon;
446 self.jump_interval = time;
448 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
449 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
450 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
451 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
452 self.damageforcescale = 2;
459 self.pain_finished = 0;
460 self.strength_finished = 0;
461 self.invincible_finished = 0;
463 //self.speed_finished = 0;
464 //self.slowmo_finished = 0;
465 // players have no think function
466 self.think = SUB_Null;
472 self.deadflag = DEAD_NO;
474 self.angles = spot.angles;
476 self.angles_z = 0; // never spawn tilted even if the spot says to
477 self.fixangle = TRUE; // turn this way immediately
478 self.velocity = '0 0 0';
479 self.avelocity = '0 0 0';
480 self.punchangle = '0 0 0';
481 self.punchvector = '0 0 0';
482 self.oldvelocity = self.velocity;
487 self.customizeentityforclient = Client_customizeentityforclient;
489 if(cvar("sv_defaultcharacter") == 1) {
490 local string defaultmodel;
491 defaultmodel = cvar_string("sv_defaultplayermodel");
492 setmodel_lod (self, defaultmodel);
493 self.skin = stof(cvar_string("sv_defaultplayerskin"));
495 self.playermodel = CheckPlayerModel(self.playermodel);
496 setmodel_lod (self, self.playermodel);
500 s = stof(self.playerskin);
509 self.skin = stof(self.playerskin);
512 if(strlen(cvar_string("sv_defaultplayercolors")))
513 setcolor(self, cvar("sv_defaultplayercolors"));
516 self.view_ofs = PL_VIEW_OFS;
517 setsize (self, PL_MIN, PL_MAX);
518 self.spawnorigin = spot.origin;
519 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
520 // don't reset back to last position, even if new position is stuck in solid
521 self.oldorigin = self.origin;
525 Spawnqueue_Remove(self);
526 Spawnqueue_Mark(self);
529 self.event_damage = PlayerDamage;
531 self.bot_attack = TRUE;
533 self.statdraintime = time + 5;
534 self.button0 = self.button1 = self.button2 = self.button3 = 0;
536 if(self.killcount == -666) {
543 self.cnt = WEP_LASER;
544 self.nixnex_lastchange_id = -1;
546 CL_SpawnWeaponentity();
547 self.alpha = default_player_alpha;
548 self.exteriorweaponentity.alpha = default_weapon_alpha;
550 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
551 self.lms_traveled_distance = 0;
553 if(cvar("spawn_debug"))
555 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
556 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
559 //stuffcmd(self, "chase_active 0");
560 //stuffcmd(self, "set viewsize $tmpviewsize \n");
562 if (cvar("g_spawnsound"))
563 sound (self, CHAN_AUTO, "misc/spawn.wav", 1, ATTN_NORM);
566 if(self.team == assault_attacker_team)
567 centerprint(self, "You are attacking!\n");
569 centerprint(self, "You are defending!\n");
572 } else if(self.classname == "observer") {
573 PutObserverInServer ();
582 void SetNewParms (void)
592 void SetChangeParms (void)
601 Called when a client types 'kill' in the console
604 void ClientKill (void)
606 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
609 void FixClientCvars(entity e)
612 // send prediction settings to the client
613 stuffcmd(e, "\nin_bindmap 0 0\n");
614 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
615 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
616 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
617 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
618 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
619 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
620 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
621 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
622 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
623 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
624 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
625 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
626 stuffcmd(e, "cl_movement_edgefriction 1\n");
628 // notify about available teams
631 CheckAllowedTeams(e);
632 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
633 stuffcmd(e, strcat("set _teams_available ", ftos(t), "\n"));
636 stuffcmd(e, "set _teams_available 0\n");
643 Called when a client connects to the server
646 string ColoredTeamName(float t);
647 //void dom_player_join_team(entity pl);
648 void ClientConnect (void)
653 if(Ban_IsClientBanned(self))
655 s = strcat("^1NOTE:^7 banned client ", self.netaddress, " just tried to enter\n");
661 self.classname = "player_joining";
662 self.flags = self.flags | FL_CLIENT;
663 self.version_nagtime = time + 10 + random() * 10;
667 dprint("BUG player count is lower than zero, this cannot happen!\n");
674 // dom_player_join_team(self);
676 //JoinBestTeam(self, FALSE);
678 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
679 self.classname = "observer";
681 self.classname = "player";
682 campaign_bots_may_start = 1;
685 self.playerid = (playerid_last = playerid_last + 1);
686 if(cvar("sv_eventlog"))
688 if(clienttype(self) == CLIENTTYPE_REAL)
692 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
693 s = strcat(":team:", ftos(self.playerid), ":");
694 s = strcat(s, ftos(self.team));
695 GameLogEcho(s, FALSE);
698 //stuffcmd(self, "set tmpviewsize $viewsize \n");
700 bprint ("^4",self.netname);
701 bprint ("^4 connected");
703 if(g_domination || g_ctf)
705 bprint(" and joined the ");
706 bprint(ColoredTeamName(self.team));
711 self.welcomemessage_time = 0;
713 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
714 // TODO: is this being used for anything else than cd tracks?
715 // Remember: SVC_CDTRACK exists. Maybe it should be used.
717 FixClientCvars(self);
720 WaypointSprite_InitClient(self);
722 // Wazat's grappling hook
723 SetGrappleHookBindings();
725 // get autoswitch state from player when he toggles it
726 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n");
728 // get version info from player
729 stuffcmd(self, "cmd clientversion $gameversion\n");
731 // send all weapon info strings
732 stuffcmd(self, "register_bestweapon clear\n"); // clear the Quake stuff
734 while (wep <= WEP_LAST)
736 weapon_action(wep, WR_REGISTER);
740 // get other cvars from player
743 // set cvar for team scoreboard
747 t = cvar("teamplay");
748 // 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
749 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
752 stuffcmd(self, "set teamplay 0\n");
756 self.frags = LMS_NewPlayerLives();
762 self.classname = "observer";
763 Spawnqueue_Insert(self);
766 bot_relinkplayerlist();
768 self.jointime = time;
775 Called when a client disconnects from the server
778 void(entity e) DropFlag;
779 .entity chatbubbleentity;
780 .entity teambubbleentity;
781 void ClientDisconnect (void)
784 if(cvar("sv_eventlog"))
785 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
786 bprint ("^4",self.netname);
787 bprint ("^4 disconnected\n");
789 if (self.chatbubbleentity)
791 remove (self.chatbubbleentity);
792 self.chatbubbleentity = world;
795 if (self.teambubbleentity)
797 remove (self.teambubbleentity);
798 self.teambubbleentity = world;
801 WaypointSprite_PlayerGone();
804 kh_Key_DropAll(self, TRUE);
807 DropFlag(self.flagcarried);
809 DistributeFragsAmongTeam(self, self.team, 1);
812 self.flags = self.flags - (self.flags & FL_CLIENT);
813 bot_relinkplayerlist();
817 if(self.weaponentity)
818 if(self.weaponentity.lasertarget)
819 remove(self.weaponentity.lasertarget);
823 Spawnqueue_Unmark(self);
824 Spawnqueue_Remove(self);
832 void() ChatBubbleThink =
834 self.nextthink = time;
835 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
837 self.owner.chatbubbleentity = world;
841 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
842 if (self.owner.buttonchat && !self.owner.deadflag)
843 self.model = self.mdl;
848 void() UpdateChatBubble =
850 if (!self.modelindex)
852 // spawn a chatbubble entity if needed
853 if (!self.chatbubbleentity)
855 self.chatbubbleentity = spawn();
856 self.chatbubbleentity.owner = self;
857 self.chatbubbleentity.exteriormodeltoclient = self;
858 self.chatbubbleentity.think = ChatBubbleThink;
859 self.chatbubbleentity.nextthink = time;
860 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
861 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
862 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
863 self.chatbubbleentity.model = "";
864 self.chatbubbleentity.effects = EF_LOWPRECISION;
869 void() TeamBubbleThink =
871 self.nextthink = time;
872 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
874 self.owner.teambubbleentity = world;
878 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
879 if (self.owner.buttonchat || self.owner.deadflag)
882 self.model = self.mdl;
886 float() TeamBubble_customizeentityforclient
888 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
891 void() UpdateTeamBubble =
893 if (!self.modelindex || !cvar("teamplay"))
895 // spawn a teambubble entity if needed
896 if (!self.teambubbleentity && cvar("teamplay"))
898 self.teambubbleentity = spawn();
899 self.teambubbleentity.owner = self;
900 self.teambubbleentity.exteriormodeltoclient = self;
901 self.teambubbleentity.think = TeamBubbleThink;
902 self.teambubbleentity.nextthink = time;
903 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
904 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
905 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
906 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
907 self.teambubbleentity.mdl = self.teambubbleentity.model;
908 self.teambubbleentity.model = self.teambubbleentity.mdl;
909 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
910 self.teambubbleentity.effects = EF_LOWPRECISION;
914 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
915 // added to the model skins
916 /*void() UpdateColorModHack =
919 c = self.clientcolors & 15;
920 // LordHavoc: only bothering to support white, green, red, yellow, blue
921 if (teamplay == 0) self.colormod = '0 0 0';
922 else if (c == 0) self.colormod = '1.00 1.00 1.00';
923 else if (c == 3) self.colormod = '0.10 1.73 0.10';
924 else if (c == 4) self.colormod = '1.73 0.10 0.10';
925 else if (c == 12) self.colormod = '1.22 1.22 0.10';
926 else if (c == 13) self.colormod = '0.10 0.10 1.73';
927 else self.colormod = '1 1 1';
936 void player_powerups (void)
940 self.effects = EF_FULLBRIGHT;
941 if (self.items & IT_STRENGTH)
943 if (time > self.strength_finished)
945 self.alpha = default_player_alpha;
946 self.exteriorweaponentity.alpha = default_weapon_alpha;
947 self.items = self.items - (self.items & IT_STRENGTH);
948 sprint(self, "^3Invisibility has worn off\n");
953 if (time < self.strength_finished)
955 self.alpha = cvar("g_minstagib_invis_alpha");
956 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
957 self.items = self.items | IT_STRENGTH;
958 sprint(self, "^3You are invisible\n");
962 if (self.items & IT_INVINCIBLE)
964 if (time > self.invincible_finished)
966 self.items = self.items - (self.items & IT_INVINCIBLE);
967 sprint(self, "^3Speed has worn off\n");
972 if (time < self.invincible_finished)
974 self.items = self.items | IT_INVINCIBLE;
975 sprint(self, "^3You are on speed\n");
981 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
982 if (self.items & IT_STRENGTH)
984 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
985 if (time > self.strength_finished)
987 self.items = self.items - (self.items & IT_STRENGTH);
988 sprint(self, "^3Strength has worn off\n");
993 if (time < self.strength_finished)
995 self.items = self.items | IT_STRENGTH;
996 sprint(self, "^3Strength infuses your weapons with devastating power\n");
999 if (self.items & IT_INVINCIBLE)
1001 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1002 if (time > self.invincible_finished)
1004 self.items = self.items - (self.items & IT_INVINCIBLE);
1005 sprint(self, "^3Shield has worn off\n");
1010 if (time < self.invincible_finished)
1012 self.items = self.items | IT_INVINCIBLE;
1013 sprint(self, "^3Shield surrounds you\n");
1017 if (cvar("g_fullbrightplayers"))
1018 self.effects = self.effects | EF_FULLBRIGHT;
1020 // midair gamemode: damage only while in the air
1021 // if in midair mode, being on ground grants temporary invulnerability
1022 // (this is so that multishot weapon don't clear the ground flag on the
1023 // first damage in the frame, leaving the player vulnerable to the
1024 // remaining hits in the same frame)
1025 if (self.flags & FL_ONGROUND)
1027 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1029 if (time < self.spawnshieldtime)
1030 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1033 float CalcRegen(float current, float stable, float regenfactor)
1035 if(current > stable)
1037 else if(current > stable - 0.25) // when close enough, "snap"
1040 return min(stable, current + (stable - current) * regenfactor * frametime);
1043 void player_regen (void)
1045 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1046 maxh = cvar("g_balance_health_stable");
1047 maxa = cvar("g_balance_armor_stable");
1048 limith = cvar("g_balance_health_limit");
1049 limita = cvar("g_balance_armor_limit");
1051 if (g_minstagib || (g_lms && !cvar("g_lms_regenerate")))
1054 max_mod = regen_mod = rot_mod = limit_mod = 1;
1056 if (self.runes & RUNE_REGEN)
1058 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1060 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1061 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1062 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1066 regen_mod = cvar("g_balance_rune_regen_regenrate");
1067 max_mod = cvar("g_balance_rune_regen_hpmod");
1068 limit_mod = cvar("g_balance_rune_regen_limitmod");
1071 else if (self.runes & CURSE_VENOM)
1073 max_mod = cvar("g_balance_curse_venom_hpmod");
1074 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1075 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1077 rot_mod = cvar("g_balance_curse_venom_rotrate");
1078 limit_mod = cvar("g_balance_curse_venom_limitmod");
1079 //if (!self.runes & RUNE_REGEN)
1080 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1082 maxh = maxh * max_mod;
1083 //maxa = maxa * max_mod;
1084 limith = limith * limit_mod;
1085 limita = limita * limit_mod;
1087 if (self.armorvalue > maxa)
1089 if (time > self.pauserotarmor_finished)
1091 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1092 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1095 else if (self.armorvalue < maxa)
1097 if (time > self.pauseregen_finished)
1099 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1100 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1103 if (self.health > maxh)
1105 if (time > self.pauserothealth_finished)
1107 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1108 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1111 else if (self.health < maxh)
1113 if (time > self.pauseregen_finished)
1115 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1116 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1120 if (self.health > limith)
1121 self.health = limith;
1122 if (self.armorvalue > limita)
1123 self.armorvalue = limita;
1125 // if player rotted to death... die!
1127 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1131 ======================
1132 spectate mode routines
1133 ======================
1135 void SpectateCopy(entity spectatee) {
1136 self.armortype = spectatee.armortype;
1137 self.armorvalue = spectatee.armorvalue;
1138 self.currentammo = spectatee.currentammo;
1139 self.effects = spectatee.effects;
1140 self.health = spectatee.health;
1142 self.items = spectatee.items;
1143 self.punchangle = spectatee.punchangle;
1144 self.view_ofs = spectatee.view_ofs;
1145 self.v_angle = spectatee.v_angle;
1146 self.viewzoom = spectatee.viewzoom;
1147 setorigin(self, spectatee.origin);
1148 setsize(self, spectatee.mins, spectatee.maxs);
1151 void SpectateUpdate() {
1153 PutObserverInServer();
1155 if (self != self.enemy) {
1156 if(self.enemy.flags & FL_NOTARGET)
1157 PutObserverInServer();
1158 SpectateCopy(self.enemy);
1159 self.dmg_take = self.enemy.dmg_take;
1160 self.dmg_save = self.enemy.dmg_save;
1161 self.dmg_inflictor = self.enemy.dmg_inflictor;
1162 self.fixangle = TRUE;
1163 self.angles = self.enemy.v_angle;
1164 //msg_entity = self;
1165 //WriteByte(MSG_ONE, SVC_SETANGLE);
1166 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1167 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1168 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1172 float SpectateNext() {
1173 other = find(self.enemy, classname, "player");
1175 other = find(other, classname, "player");
1180 if(self.enemy.classname == "player") {
1182 WriteByte(MSG_ONE, SVC_SETVIEW);
1183 WriteEntity(MSG_ONE, self.enemy);
1184 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1194 ShowRespawnCountdown()
1196 Update a respawn countdown display.
1199 void ShowRespawnCountdown()
1202 if(self.deadflag == DEAD_NO) // just respawned?
1206 number = ceil(self.death_time - time);
1209 if(number <= self.respawn_countdown)
1211 self.respawn_countdown = number - 1;
1212 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
1213 play2(self, strcat("announcer/robotic/", ftos(number), ".ogg"));
1218 void LeaveSpectatorMode()
1220 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1221 self.classname = "player";
1222 if(cvar("g_campaign") || cvar("g_balance_teams"))
1223 JoinBestTeam(self, 0);
1224 if(cvar("g_campaign"))
1225 campaign_bots_may_start = 1;
1226 PutClientInServer();
1227 if(!(self.flags & FL_NOTARGET))
1228 bprint ("^4", self.netname, "^4 is playing now\n");
1229 centerprint(self,"");
1232 stuffcmd(self,"menu_showteamselect\n");
1241 Called every frame for each client before the physics are run
1244 void() ctf_setstatus;
1245 .float vote_nagtime;
1246 void PlayerPreThink (void)
1249 if(self.version_nagtime)
1250 if(self.cvar_g_nexuizversion)
1251 if(time > self.version_nagtime)
1253 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1254 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1256 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");
1257 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1259 self.version_nagtime = 0;
1263 if(self.cvar_scr_centertime)
1264 if(time > self.vote_nagtime)
1267 self.vote_nagtime = time + self.cvar_scr_centertime * 0.6;
1271 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
1273 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
1274 self.max_armorvalue = 0;
1277 if(self.classname == "player") {
1278 local vector m1, m2;
1280 // if(self.netname == "Wazat")
1281 // bprint(self.classname, "\n");
1283 CheckRules_Player();
1286 PrintWelcomeMessage(self);
1288 if(g_lms || !cvar("sv_spectate"))
1289 if((time - self.jointime) <= cvar("welcome_message_time"))
1290 PrintWelcomeMessage(self);
1292 if (intermission_running)
1294 IntermissionThink (); // otherwise a button could be missed between
1295 return; // the think tics
1298 if(time > self.teleport_time)
1300 self.effects = self.effects - (self.effects & EF_NODRAW);
1301 if(self.weaponentity)
1302 self.weaponentity.flags = self.weaponentity.flags - (self.weaponentity.flags & EF_NODRAW);
1305 Nixnex_GiveCurrentWeapon();
1307 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
1308 UpdateSelectedPlayer();
1310 if (self.deadflag != DEAD_NO)
1312 float button_pressed, force_respawn;
1314 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1315 force_respawn = (g_lms || cvar("g_forced_respawn"));
1316 if (self.deadflag == DEAD_DYING)
1319 self.deadflag = DEAD_RESPAWNING;
1320 else if(!button_pressed)
1321 self.deadflag = DEAD_DEAD;
1323 else if (self.deadflag == DEAD_DEAD)
1326 self.deadflag = DEAD_RESPAWNABLE;
1328 else if (self.deadflag == DEAD_RESPAWNABLE)
1331 self.deadflag = DEAD_RESPAWNING;
1333 else if (self.deadflag == DEAD_RESPAWNING)
1335 if(time > self.death_time)
1338 ShowRespawnCountdown();
1342 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
1346 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1347 dist = self.oldorigin - self.origin;
1349 self.lms_traveled_distance += fabs(vlen(dist));
1351 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < restart_countdown))
1353 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1354 self.lms_traveled_distance = 0;
1357 if(time > self.lms_nextcheck)
1359 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1360 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1362 centerprint(self, cvar_string("g_lms_campcheck_message"));
1363 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1364 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1365 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');
1367 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1368 self.lms_traveled_distance = 0;
1372 if (self.button5 && !self.hook.state)
1377 self.view_ofs = PL_CROUCH_VIEW_OFS;
1378 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1379 player_setanim(self.anim_duck, FALSE, TRUE, TRUE);
1386 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1387 if (!trace_startsolid)
1389 self.crouch = FALSE;
1390 self.view_ofs = PL_VIEW_OFS;
1391 setsize (self, PL_MIN, PL_MAX);
1396 if(cvar("sv_defaultcharacter") == 1) {
1397 local string defaultmodel;
1398 defaultmodel = cvar_string("sv_defaultplayermodel");
1400 if (defaultmodel != self.model)
1404 setmodel_lod (self, defaultmodel);
1405 setsize (self, m1, m2);
1408 if (self.skin != cvar("sv_defaultplayerskin"))
1409 self.skin = cvar("sv_defaultplayerskin");
1411 if (self.playermodel != self.model)
1413 self.playermodel = CheckPlayerModel(self.playermodel);
1416 setmodel_lod (self, self.playermodel);
1417 setsize (self, m1, m2);
1422 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1423 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1427 if (self.skin != stof(self.playerskin))
1428 self.skin = stof(self.playerskin);
1432 if(strlen(cvar_string("sv_defaultplayercolors")))
1433 if(self.clientcolors != cvar("sv_defaultplayercolors"))
1434 setcolor(self, cvar("sv_defaultplayercolors"));
1436 GrapplingHookFrame();
1441 float zoomfactor, zoomspeed, zoomdir;
1442 zoomfactor = self.cvar_cl_zoomfactor;
1443 if(zoomfactor < 1 || zoomfactor > 16)
1445 zoomspeed = self.cvar_cl_zoomspeed;
1446 if(zoomspeed >= 0) // < 0 is instant zoom
1447 if(zoomspeed < 0.5 || zoomspeed > 16)
1450 zoomdir = self.button4;
1452 if(self.weapon == WEP_NEX)
1457 self.has_zoomed = 1;
1461 if(zoomspeed <= 0) // instant zoom
1464 self.viewzoom = 1 / zoomfactor;
1470 // geometric zoom would be:
1471 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom * pow(zoomfactor, (zoomdir ? -1 : 1) * frametime * zoomspeed), 1);
1472 // however, testing showed that arithmetic/harmonic zoom works better
1474 // self.viewzoom = 1 / bound(1, 1 / self.viewzoom + (zoomdir ? 1 : -1) * frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1475 // zoom in = arithmetic: 1x, 2x, 3x, 4x, ..., 8x
1476 self.viewzoom = 1 / bound(1, 1 / self.viewzoom + frametime * zoomspeed * (zoomfactor - 1), zoomfactor);
1478 // self.viewzoom = bound(1 / zoomfactor, self.viewzoom + (zoomdir ? -1 : 1) * frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1479 // zoom out = harmonic: 8/1x, 8/2x, 8/3x, 8/4x, ..., 8/8x
1480 self.viewzoom = bound(1 / zoomfactor, self.viewzoom + frametime * zoomspeed * (1 - 1 / zoomfactor), 1);
1484 self.viewzoom = min(1, self.viewzoom + frametime); // spawn zoom-in
1492 minstagib_ammocheck();
1497 //self.angles_y=self.v_angle_y + 90; // temp
1499 //if (TetrisPreFrame()) return;
1500 } else if(gameover) {
1501 if (intermission_running)
1502 IntermissionThink (); // otherwise a button could be missed between
1504 } else if(self.classname == "observer") {
1506 if (self.flags & FL_JUMPRELEASED) {
1507 if (self.button2 && self.version == cvar("gameversion")) {
1508 self.welcomemessage_time = 0;
1509 self.flags = self.flags - FL_JUMPRELEASED;
1510 LeaveSpectatorMode();
1512 } else if(self.button0 && self.version == cvar("gameversion")) {
1513 self.welcomemessage_time = 0;
1514 self.flags = self.flags - FL_JUMPRELEASED;
1515 if(SpectateNext() == 1) {
1516 self.classname = "spectator";
1520 if (!(self.button0 || self.button2)) {
1521 self.flags = self.flags | FL_JUMPRELEASED;
1524 PrintWelcomeMessage(self);
1525 } else if(self.classname == "spectator") {
1526 if (self.flags & FL_JUMPRELEASED) {
1527 if (self.button2 && self.version == cvar("gameversion")) {
1528 self.welcomemessage_time = 0;
1529 self.flags = self.flags - FL_JUMPRELEASED;
1530 LeaveSpectatorMode();
1532 } else if(self.button0) {
1533 self.welcomemessage_time = 0;
1534 self.flags = self.flags - FL_JUMPRELEASED;
1535 if(SpectateNext() == 1) {
1536 self.classname = "spectator";
1538 self.classname = "observer";
1539 PutClientInServer();
1541 } else if (self.button3) {
1542 self.welcomemessage_time = 0;
1543 self.flags = self.flags - FL_JUMPRELEASED;
1544 self.classname = "observer";
1545 PutClientInServer();
1550 if (!(self.button0 || self.button3)) {
1551 self.flags = self.flags | FL_JUMPRELEASED;
1554 PrintWelcomeMessage(self);
1555 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1564 Called every frame for each client after the physics are run
1567 void PlayerPostThink (void)
1569 // Savage: Check for nameless players
1570 if (strlen(self.netname) < 1) {
1571 self.netname = "Player";
1572 stuffcmd(self, "seta _cl_name Player\n");
1575 if(self.classname == "player") {
1576 CheckRules_Player();
1581 if (intermission_running)
1582 return; // intermission or finale
1584 //PrintWelcomeMessage(self);
1585 //if (TetrisPostFrame()) return;
1587 // restart countdown
1588 if(time < restart_countdown)
1593 sec = ceil(restart_countdown-time);
1594 s = strcat(NEWLINES, "^1Game starts in ", ftos(sec), " seconds");
1595 centerprint(self, s);
1596 self.movetype = MOVETYPE_NONE;
1597 self.velocity = '0 0 0';
1598 self.avelocity = '0 0 0';
1599 self.movement = '0 0 0';
1601 else if(self.movetype == MOVETYPE_NONE)
1603 self.movetype = MOVETYPE_WALK;
1604 centerprint(self, "\n");
1606 } else if (self.classname == "observer") {
1608 } else if (self.classname == "spectator") {