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 (strcat("^4", self.netname, "^4 has no more lives left\n"));
299 else if(self.killcount != -666)
300 bprint (strcat("^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.armorvalue = cvar("g_balance_armor_start");
417 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
418 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
419 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
420 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
421 self.damageforcescale = 2;
430 self.pain_finished = 0;
431 self.strength_finished = 0;
432 self.invincible_finished = 0;
434 //self.speed_finished = 0;
435 //self.slowmo_finished = 0;
436 // players have no think function
437 self.think = SUB_Null;
440 self.switchweapon = 0;
445 self.deadflag = DEAD_NO;
447 self.angles = spot.angles;
449 self.angles_z = 0; // never spawn tilted even if the spot says to
450 self.fixangle = TRUE; // turn this way immediately
451 self.velocity = '0 0 0';
452 self.avelocity = '0 0 0';
453 self.punchangle = '0 0 0';
454 self.punchvector = '0 0 0';
455 self.oldvelocity = self.velocity;
459 self.customizeentityforclient = Client_customizeentityforclient;
461 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
462 local string defaultmodel;
463 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
464 setmodel_lod (self, defaultmodel);
465 self.skin = stof(cvar_string("sv_defaultplayerskin"));
467 self.playermodel = CheckPlayerModel(self.playermodel);
468 setmodel_lod (self, self.playermodel);
470 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
472 self.skin = stof(self.playerskin);
476 self.view_ofs = PL_VIEW_OFS;
477 setsize (self, PL_MIN, PL_MAX);
478 self.spawnorigin = spot.origin;
479 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
480 // don't reset back to last position, even if new position is stuck in solid
481 self.oldorigin = self.origin;
485 self.ammo_shells = cvar("g_lms_start_ammo_shells");
486 self.ammo_nails = cvar("g_lms_start_ammo_nails");
487 self.ammo_rockets = cvar("g_lms_start_ammo_rockets");
488 self.ammo_cells = cvar("g_lms_start_ammo_cells");
489 self.health = cvar("g_lms_start_health");
490 self.armorvalue = cvar("g_lms_start_armor");
492 else if (cvar("g_use_ammunition")) {
493 self.ammo_shells = cvar("g_start_ammo_shells");
494 self.ammo_nails = cvar("g_start_ammo_nails");
495 self.ammo_rockets = cvar("g_start_ammo_rockets");
496 self.ammo_cells = cvar("g_start_ammo_cells");
498 self.ammo_shells = 999;
499 self.ammo_nails = 999;
500 self.ammo_rockets = 999;
501 self.ammo_cells = 999;
505 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
507 self.items = self.items | IT_LASER;
508 self.switchweapon = WEP_LASER;
510 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
512 self.items = self.items | IT_SHOTGUN;
513 self.switchweapon = WEP_SHOTGUN;
515 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
517 self.items = self.items | IT_UZI;
518 self.switchweapon = WEP_UZI;
520 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
522 self.items = self.items | IT_GRENADE_LAUNCHER;
523 self.switchweapon = WEP_GRENADE_LAUNCHER;
525 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
527 self.items = self.items | IT_ELECTRO;
528 self.switchweapon = WEP_ELECTRO;
530 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
532 self.items = self.items | IT_CRYLINK;
533 self.switchweapon = WEP_CRYLINK;
535 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
537 self.items = self.items | IT_NEX;
538 self.switchweapon = WEP_NEX;
540 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
542 self.items = self.items | IT_HAGAR;
543 self.switchweapon = WEP_HAGAR;
545 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
547 self.items = self.items | IT_ROCKET_LAUNCHER;
548 self.switchweapon = WEP_ROCKET_LAUNCHER;
551 if(cvar("g_instagib"))
554 self.switchweapon = WEP_NEX;
555 self.ammo_cells = 999;
558 if(cvar("g_rocketarena"))
560 self.items = IT_ROCKET_LAUNCHER;
561 self.switchweapon = WEP_ROCKET_LAUNCHER;
562 self.ammo_rockets = 999;
568 // will be done later
571 if(cvar("g_minstagib"))
576 self.switchweapon = WEP_NEX;
577 self.ammo_cells = cvar("g_minstagib_ammo_start");
578 self.jump_interval = time;
583 Spawnqueue_Remove(self);
584 Spawnqueue_Mark(self);
587 self.event_damage = PlayerDamage;
589 self.bot_attack = TRUE;
591 self.statdraintime = time + 5;
592 self.button0 = self.button1 = self.button2 = self.button3 = 0;
594 if(self.killcount == -666) {
601 self.cnt = WEP_LASER;
602 self.nixnex_lastchange_id = -1;
604 CL_SpawnWeaponentity();
605 self.alpha = default_player_alpha;
606 self.exteriorweaponentity.alpha = default_weapon_alpha;
608 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
609 self.lms_traveled_distance = 0;
611 if(cvar("spawn_debug"))
613 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
614 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
617 //stuffcmd(self, "chase_active 0");
618 //stuffcmd(self, "set viewsize $tmpviewsize \n");
619 } else if(self.classname == "observer") {
620 PutObserverInServer ();
629 void SetNewParms (void)
639 void SetChangeParms (void)
648 Called when a client types 'kill' in the console
651 void ClientKill (void)
653 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
660 Called when a client connects to the server
663 string ColoredTeamName(float t);
664 //void dom_player_join_team(entity pl);
665 void ClientConnect (void)
669 self.classname = "player_joining";
670 self.flags = self.flags | FL_CLIENT;
671 self.version_nagtime = time + 10 + random() * 10;
675 dprint("BUG player count is lower than zero, this cannot happen!\n");
681 //if(cvar("g_domination"))
682 // dom_player_join_team(self);
684 //JoinBestTeam(self, FALSE);
686 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
687 self.classname = "observer";
689 self.classname = "player";
690 campaign_bots_may_start = 1;
693 self.playerid = (playerid_last = playerid_last + 1);
694 if(cvar("sv_eventlog"))
696 if(clienttype(self) == CLIENTTYPE_REAL)
700 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
701 s = strcat(":team:", ftos(self.playerid), ":");
702 s = strcat(s, ftos(self.team));
703 GameLogEcho(s, FALSE);
706 //stuffcmd(self, "set tmpviewsize $viewsize \n");
708 bprint ("^4",self.netname);
709 bprint ("^4 connected");
711 if(cvar("g_domination") || cvar("g_ctf"))
713 bprint(" and joined the ");
714 bprint(ColoredTeamName(self.team));
719 self.welcomemessage_time = 0;
721 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
722 // TODO: is this being used for anything else than cd tracks?
723 // Remember: SVC_CDTRACK exists. Maybe it should be used.
725 // send prediction settings to the client
726 stuffcmd(self, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
727 stuffcmd(self, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
728 stuffcmd(self, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
729 stuffcmd(self, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
730 stuffcmd(self, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
731 stuffcmd(self, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
732 stuffcmd(self, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
733 stuffcmd(self, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
734 stuffcmd(self, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
735 stuffcmd(self, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
736 stuffcmd(self, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
737 stuffcmd(self, strcat("cl_movement_edgefriction 0\n"));
738 // Wazat's grappling hook
739 SetGrappleHookBindings();
741 // get autoswitch state from player
742 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1; cmd autoswitch $1\"\n");
743 stuffcmd(self, "cmd autoswitch $cl_autoswitch\n");
745 // get version info from player
746 stuffcmd(self, "cmd clientversion $gameversion\n");
748 // get other cvars from player
751 // set cvar for team scoreboard
755 t = cvar("teamplay");
756 // 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
757 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
760 stuffcmd(self, strcat("set teamplay 0\n"));
764 self.frags = cvar("fraglimit");
765 // no fraglimit was set, so player gets 999 lives
769 self.frags = LMS_NewPlayerLives();
775 else if(cvar("g_arena"))
777 self.classname = "observer";
778 Spawnqueue_Insert(self);
781 bot_relinkplayerlist();
783 self.jointime = time;
790 Called when a client disconnects from the server
793 void(entity e) DropFlag;
794 .entity chatbubbleentity;
795 .entity teambubbleentity;
796 void ClientDisconnect (void)
799 if(cvar("sv_eventlog"))
800 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
801 bprint ("^4",self.netname);
802 bprint ("^4 disconnected\n");
804 if (self.chatbubbleentity)
806 remove (self.chatbubbleentity);
807 self.chatbubbleentity = world;
810 if (self.teambubbleentity)
812 remove (self.teambubbleentity);
813 self.teambubbleentity = world;
819 DropFlag(self.flagcarried);
821 DistributeFragsAmongTeam(self, self.team, 1);
824 self.flags = self.flags - (self.flags & FL_CLIENT);
825 bot_relinkplayerlist();
829 if(self.weaponentity)
830 if(self.weaponentity.lasertarget)
831 remove(self.weaponentity.lasertarget);
835 Spawnqueue_Unmark(self);
836 Spawnqueue_Remove(self);
844 void() ChatBubbleThink =
846 self.nextthink = time;
847 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
849 self.owner.chatbubbleentity = world;
853 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
854 if (self.owner.buttonchat && !self.owner.deadflag)
855 self.model = self.mdl;
860 void() UpdateChatBubble =
862 if (!self.modelindex)
864 // spawn a chatbubble entity if needed
865 if (!self.chatbubbleentity)
867 self.chatbubbleentity = spawn();
868 self.chatbubbleentity.owner = self;
869 self.chatbubbleentity.exteriormodeltoclient = self;
870 self.chatbubbleentity.think = ChatBubbleThink;
871 self.chatbubbleentity.nextthink = time;
872 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
873 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
874 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
875 self.chatbubbleentity.model = "";
880 void() TeamBubbleThink =
882 self.nextthink = time;
883 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
885 self.owner.teambubbleentity = world;
889 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
890 if (self.owner.buttonchat || self.owner.deadflag)
893 self.model = self.mdl;
897 float() TeamBubble_customizeentityforclient
899 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
902 void() UpdateTeamBubble =
904 if (!self.modelindex || !cvar("teamplay"))
906 // spawn a teambubble entity if needed
907 if (!self.teambubbleentity && cvar("teamplay"))
909 self.teambubbleentity = spawn();
910 self.teambubbleentity.owner = self;
911 self.teambubbleentity.exteriormodeltoclient = self;
912 self.teambubbleentity.think = TeamBubbleThink;
913 self.teambubbleentity.nextthink = time;
914 setmodel(self.teambubbleentity, "models/misc/teambubble.spr");
915 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
916 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
917 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
918 self.teambubbleentity.mdl = self.teambubbleentity.model;
919 self.teambubbleentity.model = self.teambubbleentity.mdl;
920 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
924 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
925 // added to the model skins
926 /*void() UpdateColorModHack =
929 c = self.clientcolors & 15;
930 // LordHavoc: only bothering to support white, green, red, yellow, blue
931 if (teamplay == 0) self.colormod = '0 0 0';
932 else if (c == 0) self.colormod = '1.00 1.00 1.00';
933 else if (c == 3) self.colormod = '0.10 1.73 0.10';
934 else if (c == 4) self.colormod = '1.73 0.10 0.10';
935 else if (c == 12) self.colormod = '1.22 1.22 0.10';
936 else if (c == 13) self.colormod = '0.10 0.10 1.73';
937 else self.colormod = '1 1 1';
944 When you press the jump key
947 void PlayerJump (void)
951 mjumpheight = cvar("g_balance_jumpheight");
952 if (self.waterlevel >= 2)
954 if (self.watertype == CONTENT_WATER)
955 self.velocity_z = 200;
956 else if (self.watertype == CONTENT_SLIME)
957 self.velocity_z = 80;
959 self.velocity_z = 50;
965 if (!(self.flags & FL_ONGROUND))
968 if (!(self.flags & FL_JUMPRELEASED))
971 if(cvar("g_runematch"))
973 if(self.runes & RUNE_SPEED)
975 if(self.runes & CURSE_SLOW)
976 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
978 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
980 else if(self.runes & CURSE_SLOW)
982 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
986 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
988 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
991 self.velocity_z = self.velocity_z + mjumpheight;
992 self.oldvelocity_z = self.velocity_z;
994 self.flags = self.flags - FL_ONGROUND;
995 self.flags = self.flags - FL_JUMPRELEASED;
998 void() CheckWaterJump =
1000 local vector start, end;
1002 // check for a jump-out-of-water
1003 makevectors (self.angles);
1004 start = self.origin;
1005 start_z = start_z + 8;
1007 normalize(v_forward);
1008 end = start + v_forward*24;
1009 traceline (start, end, TRUE, self);
1010 if (trace_fraction < 1)
1012 start_z = start_z + self.maxs_z - 8;
1013 end = start + v_forward*24;
1014 self.movedir = trace_plane_normal * -50;
1015 traceline (start, end, TRUE, self);
1016 if (trace_fraction == 1)
1017 { // open at eye level
1018 self.flags = self.flags | FL_WATERJUMP;
1019 self.velocity_z = 225;
1020 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
1021 self.teleport_time = time + 2; // safety net
1031 PutClientInServer();
1034 void player_powerups (void)
1036 if (cvar("g_minstagib"))
1038 self.effects = EF_FULLBRIGHT;
1039 if (self.items & IT_STRENGTH)
1041 if (time > self.strength_finished)
1043 self.alpha = default_player_alpha;
1044 self.exteriorweaponentity.alpha = default_weapon_alpha;
1045 self.items = self.items - (self.items & IT_STRENGTH);
1046 sprint(self, "^3Invisibility has worn off\n");
1051 if (time < self.strength_finished)
1053 self.alpha = cvar("g_minstagib_invis_alpha");
1054 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
1055 self.items = self.items | IT_STRENGTH;
1056 sprint(self, "^3You are invisible\n");
1060 if (self.items & IT_INVINCIBLE)
1062 if (time > self.invincible_finished)
1064 self.items = self.items - (self.items & IT_INVINCIBLE);
1065 sprint(self, "^3Speed has worn off\n");
1070 if (time < self.invincible_finished)
1072 self.items = self.items | IT_INVINCIBLE;
1073 sprint(self, "^3You are on speed\n");
1079 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1080 if (self.items & IT_STRENGTH)
1082 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1083 if (time > self.strength_finished)
1085 self.items = self.items - (self.items & IT_STRENGTH);
1086 sprint(self, "^3Strength has worn off\n");
1091 if (time < self.strength_finished)
1093 self.items = self.items | IT_STRENGTH;
1094 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1097 if (self.items & IT_INVINCIBLE)
1099 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1100 if (time > self.invincible_finished)
1102 self.items = self.items - (self.items & IT_INVINCIBLE);
1103 sprint(self, "^3Shield has worn off\n");
1108 if (time < self.invincible_finished)
1110 self.items = self.items | IT_INVINCIBLE;
1111 sprint(self, "^3Shield surrounds you\n");
1115 if (cvar("g_fullbrightplayers"))
1116 self.effects = self.effects | EF_FULLBRIGHT;
1118 // midair gamemode: damage only while in the air
1119 // if in midair mode, being on ground grants temporary invulnerability
1120 // (this is so that multishot weapon don't clear the ground flag on the
1121 // first damage in the frame, leaving the player vulnerable to the
1122 // remaining hits in the same frame)
1123 if (self.flags & FL_ONGROUND)
1124 if (cvar("g_midair"))
1125 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1127 if (time < self.spawnshieldtime)
1128 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1131 float CalcRegen(float current, float stable, float maxv, float regenfactor)
1133 if(current > stable)
1135 else if(current > stable - 0.25) // when close enough, "snap"
1138 return bound(0, current + (stable - current) * regenfactor * frametime, maxv);
1141 void player_regen (void)
1143 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1144 maxh = cvar("g_balance_health_stable");
1145 maxa = cvar("g_balance_armor_stable");
1146 limith = cvar("g_balance_health_limit");
1147 limita = cvar("g_balance_armor_limit");
1149 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1152 if(cvar("g_runematch"))
1154 max_mod = regen_mod = rot_mod = limit_mod = 1;
1155 if (self.runes & RUNE_REGEN)
1157 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1159 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1160 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1161 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1165 regen_mod = cvar("g_balance_rune_regen_regenrate");
1166 max_mod = cvar("g_balance_rune_regen_hpmod");
1167 limit_mod = cvar("g_balance_rune_regen_limitmod");
1170 else if (self.runes & CURSE_VENOM)
1172 max_mod = cvar("g_balance_curse_venom_hpmod");
1173 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1174 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1176 rot_mod = cvar("g_balance_curse_venom_rotrate");
1177 limit_mod = cvar("g_balance_curse_venom_limitmod");
1178 //if (!self.runes & RUNE_REGEN)
1179 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1181 maxh = maxh * max_mod;
1182 //maxa = maxa * max_mod;
1184 if (time > self.pauserotarmor_finished)
1186 if (self.armorvalue > maxa)
1187 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1189 if (time > self.pauserothealth_finished)
1191 if (self.health > maxh)
1192 self.health = bound(0, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime, 1000);
1194 if (time > self.pauseregen_finished)
1196 self.health = CalcRegen(self.health, maxh, 1000, regen_mod * cvar("g_balance_health_regen"));
1197 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1202 if (time > self.pauserothealth_finished)
1203 if (self.health > maxh)
1204 self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
1205 if (time > self.pauserotarmor_finished)
1206 if (self.armorvalue > maxa)
1207 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1208 if (time > self.pauseregen_finished)
1210 self.health = CalcRegen(self.health, maxh, 1000, cvar("g_balance_health_regen"));
1211 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1215 if (self.health > limith)
1216 self.health = limith;
1218 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1219 if (self.armorvalue > limita)
1220 self.armorvalue = limita;
1224 ======================
1225 spectate mode routines
1226 ======================
1228 void SpectateCopy(entity spectatee) {
1229 self.armortype = spectatee.armortype;
1230 self.armorvalue = spectatee.armorvalue;
1231 self.currentammo = spectatee.currentammo;
1232 self.effects = spectatee.effects;
1233 self.health = spectatee.health;
1235 self.items = spectatee.items;
1236 self.punchangle = spectatee.punchangle;
1237 self.view_ofs = spectatee.view_ofs;
1238 self.v_angle = spectatee.v_angle;
1239 self.viewzoom = spectatee.viewzoom;
1240 setorigin(self, spectatee.origin);
1241 setsize(self, spectatee.mins, spectatee.maxs);
1244 void SpectateUpdate() {
1246 PutObserverInServer();
1248 if (self != self.enemy) {
1249 if(self.enemy.flags & FL_NOTARGET)
1250 PutObserverInServer();
1251 SpectateCopy(self.enemy);
1252 self.dmg_take = self.enemy.dmg_take;
1253 self.dmg_save = self.enemy.dmg_save;
1254 self.dmg_inflictor = self.enemy.dmg_inflictor;
1255 self.fixangle = TRUE;
1256 self.angles = self.enemy.v_angle;
1257 //msg_entity = self;
1258 //WriteByte(MSG_ONE, SVC_SETANGLE);
1259 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1260 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1261 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1265 float SpectateNext() {
1266 other = find(self.enemy, classname, "player");
1268 other = find(other, classname, "player");
1273 if(self.enemy.classname == "player") {
1275 WriteByte(MSG_ONE, SVC_SETVIEW);
1276 WriteEntity(MSG_ONE, self.enemy);
1277 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1287 ShowRespawnCountdown()
1289 Update a respawn countdown display.
1292 void ShowRespawnCountdown()
1295 if(self.deadflag == DEAD_NO) // just respawned?
1299 number = ceil(self.death_time - time);
1302 if(number <= self.respawn_countdown)
1304 self.respawn_countdown = number - 1;
1305 if(ceil(self.death_time - (time + 0.5)) == number) // only say it if it is the same number even in 0.5s; to prevent overlapping sounds
1306 stuffcmd(self, strcat("play2 announcer/robotic/", ftos(number), ".ogg\n"));
1311 void LeaveSpectatorMode()
1313 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1314 self.classname = "player";
1315 if(cvar("g_campaign") || cvar("g_balance_teams"))
1316 JoinBestTeam(self, 0);
1317 if(cvar("g_campaign"))
1318 campaign_bots_may_start = 1;
1319 PutClientInServer();
1320 if(!(self.flags & FL_NOTARGET))
1321 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
1322 centerprint(self,"");
1325 stuffcmd(self,"menu_showteamselect\n");
1334 Called every frame for each client before the physics are run
1337 void() ctf_setstatus;
1338 void PlayerPreThink (void)
1341 if(self.version_nagtime)
1342 if(self.cvar_g_nexuizversion)
1343 if(time > self.version_nagtime)
1345 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1346 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1348 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");
1349 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1351 self.version_nagtime = 0;
1354 if(self.classname == "player") {
1355 local vector m1, m2;
1357 // if(self.netname == "Wazat")
1358 // bprint(strcat(self.classname, "\n"));
1360 CheckRules_Player();
1362 Nixnex_GiveCurrentWeapon();
1365 PrintWelcomeMessage(self);
1367 if(cvar("g_lms") || !cvar("sv_spectate"))
1368 if((time - self.jointime) <= cvar("welcome_message_time"))
1369 PrintWelcomeMessage(self);
1371 if (intermission_running)
1373 IntermissionThink (); // otherwise a button could be missed between
1374 return; // the think tics
1377 if (self.deadflag != DEAD_NO)
1379 float button_pressed, force_respawn;
1381 button_pressed = (self.button0 || self.button2 || self.button3 || self.button6 || self.buttonuse);
1382 force_respawn = (cvar("g_lms") || cvar("g_forced_respawn"));
1383 if (self.deadflag == DEAD_DYING)
1386 self.deadflag = DEAD_RESPAWNING;
1387 else if(!button_pressed)
1388 self.deadflag = DEAD_DEAD;
1390 else if (self.deadflag == DEAD_DEAD)
1393 self.deadflag = DEAD_RESPAWNABLE;
1395 else if (self.deadflag == DEAD_RESPAWNABLE)
1398 self.deadflag = DEAD_RESPAWNING;
1400 else if (self.deadflag == DEAD_RESPAWNING)
1402 if(time > self.death_time)
1405 ShowRespawnCountdown();
1409 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1413 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1414 dist = self.oldorigin - self.origin;
1416 self.lms_traveled_distance += fabs(vlen(dist));
1418 if(cvar("g_campaign"))
1419 if(!campaign_bots_may_start)
1421 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1422 self.lms_traveled_distance = 0;
1425 if(time > self.lms_nextcheck)
1427 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1428 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1430 centerprint(self, cvar_string("g_lms_campcheck_message"));
1431 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1432 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1433 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');
1435 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1436 self.lms_traveled_distance = 0;
1440 if (self.button5 && !self.hook.state)
1445 self.view_ofs = PL_CROUCH_VIEW_OFS;
1446 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1453 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1454 if (!trace_startsolid)
1456 self.crouch = FALSE;
1457 self.view_ofs = PL_VIEW_OFS;
1458 setsize (self, PL_MIN, PL_MAX);
1463 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1464 local string defaultmodel;
1465 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
1467 if (defaultmodel != self.model)
1471 setmodel_lod (self, defaultmodel);
1472 setsize (self, m1, m2);
1475 if (self.skin != cvar("sv_defaultplayerskin"))
1476 self.skin = cvar("sv_defaultplayerskin");
1478 if (self.playermodel != self.model)
1480 self.playermodel = CheckPlayerModel(self.playermodel);
1483 setmodel_lod (self, self.playermodel);
1484 setsize (self, m1, m2);
1489 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1490 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1494 if (self.skin != stof(self.playerskin))
1495 self.skin = stof(self.playerskin);
1499 GrapplingHookFrame();
1503 if (self.button4 || (self.weapon == WEP_NEX && self.button3))
1505 if (cvar("g_minstagib") && self.button3)
1507 if (self.jump_interval <= (time + 0.1))
1509 self.jump_interval = time + 1;
1513 else if (self.viewzoom > 0.4)
1514 self.viewzoom = max (0.4, self.viewzoom - frametime * 2);
1516 else if (self.viewzoom < 1.0)
1517 self.viewzoom = min (1.0, self.viewzoom + frametime);
1523 self.flags = self.flags | FL_JUMPRELEASED;
1529 if (cvar("g_minstagib"))
1530 minstagib_ammocheck();
1534 //self.angles_y=self.v_angle_y + 90; // temp
1536 if (self.waterlevel == 2)
1539 //if (TetrisPreFrame()) return;
1540 } else if(gameover) {
1541 if (intermission_running)
1542 IntermissionThink (); // otherwise a button could be missed between
1544 } else if(self.classname == "observer") {
1546 if (self.flags & FL_JUMPRELEASED) {
1547 if (self.button2 && self.version == cvar("gameversion")) {
1548 self.flags = self.flags - FL_JUMPRELEASED;
1549 LeaveSpectatorMode();
1551 } else if(self.button0 && self.version == cvar("gameversion")) {
1552 self.flags = self.flags - FL_JUMPRELEASED;
1553 if(SpectateNext() == 1) {
1554 self.classname = "spectator";
1558 if (!(self.button0 || self.button2)) {
1559 self.flags = self.flags | FL_JUMPRELEASED;
1562 PrintWelcomeMessage(self);
1563 } else if(self.classname == "spectator") {
1564 if (self.flags & FL_JUMPRELEASED) {
1565 if (self.button2 && self.version == cvar("gameversion")) {
1566 self.flags = self.flags - FL_JUMPRELEASED;
1567 LeaveSpectatorMode();
1569 } else if(self.button0) {
1570 self.flags = self.flags - FL_JUMPRELEASED;
1571 if(SpectateNext() == 1) {
1572 self.classname = "spectator";
1574 self.classname = "observer";
1575 PutClientInServer();
1577 } else if (self.button3) {
1578 self.flags = self.flags - FL_JUMPRELEASED;
1579 self.classname = "observer";
1580 PutClientInServer();
1585 if (!(self.button0 || self.button3)) {
1586 self.flags = self.flags | FL_JUMPRELEASED;
1589 PrintWelcomeMessage(self);
1590 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1599 Called every frame for each client after the physics are run
1602 void PlayerPostThink (void)
1604 // Savage: Check for nameless players
1605 if (strlen(self.netname) < 1) {
1606 self.netname = "Player";
1607 stuffcmd(self, "seta _cl_name Player\n");
1610 if(self.classname == "player") {
1611 CheckRules_Player();
1614 if (self.deadflag == DEAD_NO)
1617 if (intermission_running)
1618 return; // intermission or finale
1620 //PrintWelcomeMessage(self);
1621 //if (TetrisPostFrame()) return;
1622 } else if (self.classname == "observer") {
1624 } else if (self.classname == "spectator") {