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);
290 if (cvar("g_runematch"))
293 DistributeFragsAmongTeam(self, self.team, 1);
295 if(self.frags <= 0 && self.frags > -666 && cvar("g_lms") && self.killcount != -666)
296 bprint (strcat("^4", self.netname, "^4 has no more lives left\n"));
297 else if(self.killcount != -666)
298 bprint (strcat("^4", self.netname, "^4 is spectating now\n"));
300 self.classname = "observer";
302 self.takedamage = DAMAGE_NO;
303 self.solid = SOLID_NOT;
304 self.movetype = MOVETYPE_NOCLIP;
305 self.flags = FL_CLIENT | FL_NOTARGET;
306 self.armorvalue = 666;
308 self.armorvalue = cvar("g_balance_armor_start");
309 self.pauserotarmor_finished = 0;
310 self.pauserothealth_finished = 0;
311 self.pauseregen_finished = 0;
312 self.damageforcescale = 0;
322 self.pain_finished = 0;
323 self.strength_finished = 0;
324 self.invincible_finished = 0;
326 self.think = SUB_Null;
330 self.deadflag = DEAD_NO;
331 self.angles = spot.angles;
333 self.fixangle = TRUE;
336 self.view_ofs = PL_VIEW_OFS;
337 setorigin (self, spot.origin);
338 setsize (self, '0 0 0', '0 0 0');
339 self.oldorigin = self.origin;
344 self.weaponmodel = "";
345 self.weaponentity = world;
346 self.killcount = -666;
347 self.velocity = '0 0 0';
348 self.avelocity = '0 0 0';
349 self.punchangle = '0 0 0';
350 self.punchvector = '0 0 0';
351 self.oldvelocity = self.velocity;
352 self.customizeentityforclient = Client_customizeentityforclient;
358 Spawnqueue_Insert(self);
362 Spawnqueue_Unmark(self);
363 Spawnqueue_Remove(self);
366 else if(!cvar("g_lms"))
375 Called when a client spawns in the server
378 void PutClientInServer (void)
380 if(clienttype(self) == CLIENTTYPE_BOT)
382 self.classname = "player";
384 else if(clienttype(self) == CLIENTTYPE_REAL)
387 WriteByte(MSG_ONE, SVC_SETVIEW);
388 WriteEntity(MSG_ONE, self);
391 // player is dead and becomes observer
392 if(cvar("g_lms") && self.frags < 1)
393 self.classname = "observer";
397 self.classname = "observer";
399 if(self.classname == "player") {
402 spot = SelectSpawnPoint (FALSE);
404 RemoveGrapplingHook(self); // Wazat's Grappling Hook
406 self.classname = "player";
407 self.iscreature = TRUE;
408 self.movetype = MOVETYPE_WALK;
409 self.solid = SOLID_SLIDEBOX;
410 self.flags = FL_CLIENT;
411 self.takedamage = DAMAGE_AIM;
413 self.health = cvar("g_balance_health_start");
414 self.armorvalue = cvar("g_balance_armor_start");
415 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
416 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
417 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
418 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
419 self.damageforcescale = 2;
428 self.pain_finished = 0;
429 self.strength_finished = 0;
430 self.invincible_finished = 0;
432 //self.speed_finished = 0;
433 //self.slowmo_finished = 0;
434 // players have no think function
435 self.think = SUB_Null;
438 self.switchweapon = 0;
443 self.deadflag = DEAD_NO;
445 self.angles = spot.angles;
447 self.angles_z = 0; // never spawn tilted even if the spot says to
448 self.fixangle = TRUE; // turn this way immediately
449 self.velocity = '0 0 0';
450 self.avelocity = '0 0 0';
451 self.punchangle = '0 0 0';
452 self.punchvector = '0 0 0';
453 self.oldvelocity = self.velocity;
457 self.customizeentityforclient = Client_customizeentityforclient;
459 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
460 local string defaultmodel;
461 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
462 setmodel_lod (self, defaultmodel);
463 self.skin = stof(cvar_string("sv_defaultplayerskin"));
465 self.playermodel = CheckPlayerModel(self.playermodel);
466 setmodel_lod (self, self.playermodel);
468 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
470 self.skin = stof(self.playerskin);
474 self.view_ofs = PL_VIEW_OFS;
475 setsize (self, PL_MIN, PL_MAX);
476 self.spawnorigin = spot.origin;
477 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
478 // don't reset back to last position, even if new position is stuck in solid
479 self.oldorigin = self.origin;
483 self.ammo_shells = cvar("g_lms_start_ammo_shells");
484 self.ammo_nails = cvar("g_lms_start_ammo_nails");
485 self.ammo_rockets = cvar("g_lms_start_ammo_rockets");
486 self.ammo_cells = cvar("g_lms_start_ammo_cells");
487 self.health = cvar("g_lms_start_health");
488 self.armorvalue = cvar("g_lms_start_armor");
490 else if (cvar("g_use_ammunition")) {
491 self.ammo_shells = cvar("g_start_ammo_shells");
492 self.ammo_nails = cvar("g_start_ammo_nails");
493 self.ammo_rockets = cvar("g_start_ammo_rockets");
494 self.ammo_cells = cvar("g_start_ammo_cells");
496 self.ammo_shells = 999;
497 self.ammo_nails = 999;
498 self.ammo_rockets = 999;
499 self.ammo_cells = 999;
503 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
505 self.items = self.items | IT_LASER;
506 self.switchweapon = WEP_LASER;
508 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
510 self.items = self.items | IT_SHOTGUN;
511 self.switchweapon = WEP_SHOTGUN;
513 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
515 self.items = self.items | IT_UZI;
516 self.switchweapon = WEP_UZI;
518 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
520 self.items = self.items | IT_GRENADE_LAUNCHER;
521 self.switchweapon = WEP_GRENADE_LAUNCHER;
523 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
525 self.items = self.items | IT_ELECTRO;
526 self.switchweapon = WEP_ELECTRO;
528 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
530 self.items = self.items | IT_CRYLINK;
531 self.switchweapon = WEP_CRYLINK;
533 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
535 self.items = self.items | IT_NEX;
536 self.switchweapon = WEP_NEX;
538 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
540 self.items = self.items | IT_HAGAR;
541 self.switchweapon = WEP_HAGAR;
543 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
545 self.items = self.items | IT_ROCKET_LAUNCHER;
546 self.switchweapon = WEP_ROCKET_LAUNCHER;
549 if(cvar("g_instagib"))
552 self.switchweapon = WEP_NEX;
553 self.ammo_cells = 999;
556 if(cvar("g_rocketarena"))
558 self.items = IT_ROCKET_LAUNCHER;
559 self.switchweapon = WEP_ROCKET_LAUNCHER;
560 self.ammo_rockets = 999;
566 // will be done later
569 if(cvar("g_minstagib"))
574 self.switchweapon = WEP_NEX;
575 self.ammo_cells = cvar("g_minstagib_ammo_start");
576 self.jump_interval = time;
581 Spawnqueue_Remove(self);
582 Spawnqueue_Mark(self);
585 self.event_damage = PlayerDamage;
587 self.bot_attack = TRUE;
589 self.statdraintime = time + 5;
590 self.button0 = self.button1 = self.button2 = self.button3 = 0;
592 if(self.killcount == -666) {
599 self.cnt = WEP_LASER;
600 self.nixnex_lastchange_id = -1;
602 CL_SpawnWeaponentity();
603 self.alpha = default_player_alpha;
604 self.exteriorweaponentity.alpha = default_weapon_alpha;
606 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
607 self.lms_traveled_distance = 0;
609 if(cvar("spawn_debug"))
611 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
612 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
615 //stuffcmd(self, "chase_active 0");
616 //stuffcmd(self, "set viewsize $tmpviewsize \n");
617 } else if(self.classname == "observer") {
618 PutObserverInServer ();
627 void SetNewParms (void)
637 void SetChangeParms (void)
646 Called when a client types 'kill' in the console
649 void ClientKill (void)
651 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
658 Called when a client connects to the server
661 string ColoredTeamName(float t);
662 //void dom_player_join_team(entity pl);
663 void ClientConnect (void)
668 self.classname = "player_joining";
669 self.flags = self.flags | FL_CLIENT;
670 self.version_nagtime = time + 10 + random() * 10;
674 dprint("BUG player count is lower than zero, this cannot happen!\n");
680 //if(cvar("g_domination"))
681 // dom_player_join_team(self);
683 //JoinBestTeam(self, FALSE);
685 if((cvar("sv_spectate") == 1 && !cvar("g_lms")) || cvar("g_campaign")) {
686 self.classname = "observer";
688 self.classname = "player";
689 campaign_bots_may_start = 1;
692 self.playerid = (playerid_last = playerid_last + 1);
693 if(cvar("sv_eventlog"))
695 if(clienttype(self) == CLIENTTYPE_REAL)
699 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", s, ":", self.netname), TRUE);
700 s = strcat(":team:", ftos(self.playerid), ":");
701 s = strcat(s, ftos(self.team));
702 GameLogEcho(s, FALSE);
705 //stuffcmd(self, "set tmpviewsize $viewsize \n");
707 bprint ("^4",self.netname);
708 bprint ("^4 connected");
710 if(cvar("g_domination") || cvar("g_ctf"))
712 bprint(" and joined the ");
713 bprint(ColoredTeamName(self.team));
718 self.welcomemessage_time = time + cvar("welcome_message_time");
719 self.welcomemessage_time2 = 0;
722 // the client might not have his maps/%s.cfg file yet!
723 // so send the one from the server...
724 fh = fopen(strcat("maps/", mapname, ".cfg"), FILE_READ);
727 while((s = fgets(fh)))
728 stuffcmd(self, strcat(s, "\n"));
731 // and then execute the client's so he can still override CD tracks
733 not needed any more: current map download system disconnects and reconnects
734 after the download, and then the file will be there
736 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
738 // TODO: is this being used for anything else than cd tracks?
739 // Remember: SVC_CDTRACK exists. Maybe it should be used.
741 // send prediction settings to the client
742 stuffcmd(self, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
743 stuffcmd(self, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
744 stuffcmd(self, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
745 stuffcmd(self, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
746 stuffcmd(self, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
747 stuffcmd(self, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
748 stuffcmd(self, strcat("cl_movement_jumpvelocity ", ftos(cvar("g_balance_jumpheight")), "\n"));
749 stuffcmd(self, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
750 stuffcmd(self, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
751 stuffcmd(self, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
752 stuffcmd(self, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
753 stuffcmd(self, strcat("cl_movement_edgefriction 0\n"));
754 // Wazat's grappling hook
755 SetGrappleHookBindings();
757 // get autoswitch state from player
758 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1; cmd autoswitch $1\"\n");
759 stuffcmd(self, "cmd autoswitch $cl_autoswitch\n");
761 // get version info from player
762 stuffcmd(self, "cmd clientversion $gameversion\n");
764 // get other cvars from player
767 // set cvar for team scoreboard
771 t = cvar("teamplay");
772 // 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
773 stuffcmd(self, strcat("set teamplay ", ftos(t), "\n"));
776 stuffcmd(self, strcat("set teamplay 0\n"));
780 self.frags = cvar("fraglimit");
781 // no fraglimit was set, so player gets 999 lives
785 self.frags = LMS_NewPlayerLives();
791 else if(cvar("g_arena"))
793 self.classname = "observer";
794 Spawnqueue_Insert(self);
797 bot_relinkplayerlist();
799 self.jointime = time;
806 Called when a client disconnects from the server
809 void(entity e) DropFlag;
810 .entity chatbubbleentity;
811 .entity teambubbleentity;
812 void ClientDisconnect (void)
815 if(cvar("sv_eventlog"))
816 GameLogEcho(strcat(":part:", ftos(self.playerid)), FALSE);
817 bprint ("^4",self.netname);
818 bprint ("^4 disconnected\n");
820 if (self.chatbubbleentity)
822 remove (self.chatbubbleentity);
823 self.chatbubbleentity = world;
826 if (self.teambubbleentity)
828 remove (self.teambubbleentity);
829 self.teambubbleentity = world;
835 DropFlag(self.flagcarried);
837 DistributeFragsAmongTeam(self, self.team, 1);
840 self.flags = self.flags - (self.flags & FL_CLIENT);
841 bot_relinkplayerlist();
845 if(self.weaponentity)
846 if(self.weaponentity.lasertarget)
847 remove(self.weaponentity.lasertarget);
851 Spawnqueue_Unmark(self);
852 Spawnqueue_Remove(self);
860 void() ChatBubbleThink =
862 self.nextthink = time;
863 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
865 self.owner.chatbubbleentity = world;
869 setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1');
870 if (self.owner.buttonchat && !self.owner.deadflag)
871 self.model = self.mdl;
876 void() UpdateChatBubble =
878 if (!self.modelindex)
880 // spawn a chatbubble entity if needed
881 if (!self.chatbubbleentity)
883 self.chatbubbleentity = spawn();
884 self.chatbubbleentity.owner = self;
885 self.chatbubbleentity.exteriormodeltoclient = self;
886 self.chatbubbleentity.think = ChatBubbleThink;
887 self.chatbubbleentity.nextthink = time;
888 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr");
889 setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
890 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
891 self.chatbubbleentity.model = "";
896 void() TeamBubbleThink =
898 self.nextthink = time;
899 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
901 self.owner.teambubbleentity = world;
905 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
906 if (self.owner.buttonchat || self.owner.deadflag)
909 self.model = self.mdl;
913 float() TeamBubble_customizeentityforclient
915 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
918 void() UpdateTeamBubble =
920 if (!self.modelindex || !cvar("teamplay"))
922 // spawn a teambubble entity if needed
923 if (!self.teambubbleentity && cvar("teamplay"))
925 self.teambubbleentity = spawn();
926 self.teambubbleentity.owner = self;
927 self.teambubbleentity.exteriormodeltoclient = self;
928 self.teambubbleentity.think = TeamBubbleThink;
929 self.teambubbleentity.nextthink = time;
930 setmodel(self.teambubbleentity, "models/misc/teambubble.spr");
931 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
932 setorigin(self.teambubbleentity, self.teambubbleentity.origin + '0 0 15' + self.maxs_z * '0 0 1');
933 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
934 self.teambubbleentity.mdl = self.teambubbleentity.model;
935 self.teambubbleentity.model = self.teambubbleentity.mdl;
936 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
940 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
941 // added to the model skins
942 /*void() UpdateColorModHack =
945 c = self.clientcolors & 15;
946 // LordHavoc: only bothering to support white, green, red, yellow, blue
947 if (teamplay == 0) self.colormod = '0 0 0';
948 else if (c == 0) self.colormod = '1.00 1.00 1.00';
949 else if (c == 3) self.colormod = '0.10 1.73 0.10';
950 else if (c == 4) self.colormod = '1.73 0.10 0.10';
951 else if (c == 12) self.colormod = '1.22 1.22 0.10';
952 else if (c == 13) self.colormod = '0.10 0.10 1.73';
953 else self.colormod = '1 1 1';
960 When you press the jump key
963 void PlayerJump (void)
967 mjumpheight = cvar("g_balance_jumpheight");
968 if (self.waterlevel >= 2)
970 if (self.watertype == CONTENT_WATER)
971 self.velocity_z = 200;
972 else if (self.watertype == CONTENT_SLIME)
973 self.velocity_z = 80;
975 self.velocity_z = 50;
981 if (!(self.flags & FL_ONGROUND))
984 if (!(self.flags & FL_JUMPRELEASED))
987 if(cvar("g_runematch"))
989 if(self.runes & RUNE_SPEED)
991 if(self.runes & CURSE_SLOW)
992 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_combo_jumpheight");
994 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
996 else if(self.runes & CURSE_SLOW)
998 mjumpheight = mjumpheight * cvar("g_balance_curse_slow_jumpheight");
1002 if(cvar("g_minstagib") && (self.items & IT_INVINCIBLE))
1004 mjumpheight = mjumpheight * cvar("g_balance_rune_speed_jumpheight");
1007 self.velocity_z = self.velocity_z + mjumpheight;
1008 self.oldvelocity_z = self.velocity_z;
1010 self.flags = self.flags - FL_ONGROUND;
1011 self.flags = self.flags - FL_JUMPRELEASED;
1014 void() CheckWaterJump =
1016 local vector start, end;
1018 // check for a jump-out-of-water
1019 makevectors (self.angles);
1020 start = self.origin;
1021 start_z = start_z + 8;
1023 normalize(v_forward);
1024 end = start + v_forward*24;
1025 traceline (start, end, TRUE, self);
1026 if (trace_fraction < 1)
1028 start_z = start_z + self.maxs_z - 8;
1029 end = start + v_forward*24;
1030 self.movedir = trace_plane_normal * -50;
1031 traceline (start, end, TRUE, self);
1032 if (trace_fraction == 1)
1033 { // open at eye level
1034 self.flags = self.flags | FL_WATERJUMP;
1035 self.velocity_z = 225;
1036 self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
1037 self.teleport_time = time + 2; // safety net
1047 PutClientInServer();
1050 void player_powerups (void)
1052 if (cvar("g_minstagib"))
1054 self.effects = EF_FULLBRIGHT;
1055 if (self.items & IT_STRENGTH)
1057 if (time > self.strength_finished)
1059 self.alpha = default_player_alpha;
1060 self.exteriorweaponentity.alpha = default_weapon_alpha;
1061 self.items = self.items - (self.items & IT_STRENGTH);
1062 sprint(self, "^3Invisibility has worn off\n");
1067 if (time < self.strength_finished)
1069 self.alpha = cvar("g_minstagib_invis_alpha");
1070 self.exteriorweaponentity.alpha = cvar("g_minstagib_invis_alpha");
1071 self.items = self.items | IT_STRENGTH;
1072 sprint(self, "^3You are invisible\n");
1076 if (self.items & IT_INVINCIBLE)
1078 if (time > self.invincible_finished)
1080 self.items = self.items - (self.items & IT_INVINCIBLE);
1081 sprint(self, "^3Speed has worn off\n");
1086 if (time < self.invincible_finished)
1088 self.items = self.items | IT_INVINCIBLE;
1089 sprint(self, "^3You are on speed\n");
1095 self.effects = self.effects - (self.effects & (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT));
1096 if (self.items & IT_STRENGTH)
1098 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1099 if (time > self.strength_finished)
1101 self.items = self.items - (self.items & IT_STRENGTH);
1102 sprint(self, "^3Strength has worn off\n");
1107 if (time < self.strength_finished)
1109 self.items = self.items | IT_STRENGTH;
1110 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1113 if (self.items & IT_INVINCIBLE)
1115 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1116 if (time > self.invincible_finished)
1118 self.items = self.items - (self.items & IT_INVINCIBLE);
1119 sprint(self, "^3Shield has worn off\n");
1124 if (time < self.invincible_finished)
1126 self.items = self.items | IT_INVINCIBLE;
1127 sprint(self, "^3Shield surrounds you\n");
1131 if (cvar("g_fullbrightplayers"))
1132 self.effects = self.effects | EF_FULLBRIGHT;
1134 // midair gamemode: damage only while in the air
1135 // if in midair mode, being on ground grants temporary invulnerability
1136 // (this is so that multishot weapon don't clear the ground flag on the
1137 // first damage in the frame, leaving the player vulnerable to the
1138 // remaining hits in the same frame)
1139 if (self.flags & FL_ONGROUND)
1140 if (cvar("g_midair"))
1141 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1143 if (time < self.spawnshieldtime)
1144 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1147 float CalcRegen(float current, float stable, float maxv, float regenfactor)
1149 if(current > stable)
1151 else if(current > stable - 0.25) // when close enough, "snap"
1154 return bound(0, current + (stable - current) * regenfactor * frametime, maxv);
1157 void player_regen (void)
1159 float maxh, maxa, limith, limita, max_mod, regen_mod, rot_mod, limit_mod;
1160 maxh = cvar("g_balance_health_stable");
1161 maxa = cvar("g_balance_armor_stable");
1162 limith = cvar("g_balance_health_limit");
1163 limita = cvar("g_balance_armor_limit");
1165 if (cvar("g_minstagib") || (cvar("g_lms") && !cvar("g_lms_regenerate")))
1168 if(cvar("g_runematch"))
1170 max_mod = regen_mod = rot_mod = limit_mod = 1;
1171 if (self.runes & RUNE_REGEN)
1173 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1175 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1176 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1177 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1181 regen_mod = cvar("g_balance_rune_regen_regenrate");
1182 max_mod = cvar("g_balance_rune_regen_hpmod");
1183 limit_mod = cvar("g_balance_rune_regen_limitmod");
1186 else if (self.runes & CURSE_VENOM)
1188 max_mod = cvar("g_balance_curse_venom_hpmod");
1189 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1190 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1192 rot_mod = cvar("g_balance_curse_venom_rotrate");
1193 limit_mod = cvar("g_balance_curse_venom_limitmod");
1194 //if (!self.runes & RUNE_REGEN)
1195 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1197 maxh = maxh * max_mod;
1198 //maxa = maxa * max_mod;
1200 if (time > self.pauserotarmor_finished)
1202 if (self.armorvalue > maxa)
1203 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1205 if (time > self.pauserothealth_finished)
1207 if (self.health > maxh)
1208 self.health = bound(0, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime, 1000);
1210 if (time > self.pauseregen_finished)
1212 self.health = CalcRegen(self.health, maxh, 1000, regen_mod * cvar("g_balance_health_regen"));
1213 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1218 if (time > self.pauserothealth_finished)
1219 if (self.health > maxh)
1220 self.health = bound(0, self.health + (maxh - self.health) * cvar("g_balance_health_rot") * frametime, 1000);
1221 if (time > self.pauserotarmor_finished)
1222 if (self.armorvalue > maxa)
1223 self.armorvalue = bound(0, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime, 1000);
1224 if (time > self.pauseregen_finished)
1226 self.health = CalcRegen(self.health, maxh, 1000, cvar("g_balance_health_regen"));
1227 self.armorvalue = CalcRegen(self.armorvalue, maxa, 1000, cvar("g_balance_armor_regen"));
1231 if (self.health > limith)
1232 self.health = limith;
1234 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1235 if (self.armorvalue > limita)
1236 self.armorvalue = limita;
1240 ======================
1241 spectate mode routines
1242 ======================
1244 void SpectateCopy(entity spectatee) {
1245 self.armortype = spectatee.armortype;
1246 self.armorvalue = spectatee.armorvalue;
1247 self.currentammo = spectatee.currentammo;
1248 self.effects = spectatee.effects;
1249 self.health = spectatee.health;
1251 self.items = spectatee.items;
1252 self.punchangle = spectatee.punchangle;
1253 self.view_ofs = spectatee.view_ofs;
1254 self.v_angle = spectatee.v_angle;
1255 self.viewzoom = spectatee.viewzoom;
1256 setorigin(self, spectatee.origin);
1257 setsize(self, spectatee.mins, spectatee.maxs);
1260 void SpectateUpdate() {
1262 PutObserverInServer();
1264 if (self != self.enemy) {
1265 if(self.enemy.flags & FL_NOTARGET)
1266 PutObserverInServer();
1267 SpectateCopy(self.enemy);
1268 self.dmg_take = self.enemy.dmg_take;
1269 self.dmg_save = self.enemy.dmg_save;
1270 self.dmg_inflictor = self.enemy.dmg_inflictor;
1271 self.fixangle = TRUE;
1272 self.angles = self.enemy.v_angle;
1273 //msg_entity = self;
1274 //WriteByte(MSG_ONE, SVC_SETANGLE);
1275 //WriteAngle(MSG_ONE, self.enemy.v_angle_x);
1276 //WriteAngle(MSG_ONE, self.enemy.v_angle_y);
1277 //WriteAngle(MSG_ONE, self.enemy.v_angle_z);
1281 float SpectateNext() {
1282 other = find(self.enemy, classname, "player");
1284 other = find(other, classname, "player");
1289 if(self.enemy.classname == "player") {
1291 WriteByte(MSG_ONE, SVC_SETVIEW);
1292 WriteEntity(MSG_ONE, self.enemy);
1293 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1305 Called every frame for each client before the physics are run
1308 void() ctf_setstatus;
1309 void PlayerPreThink (void)
1312 if(self.version_nagtime)
1313 if(self.cvar_g_nexuizversion)
1314 if(time > self.version_nagtime)
1316 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
1317 if(self.cvar_g_nexuizversion != cvar_string("g_nexuizversion"))
1319 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");
1320 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "\n"));
1322 self.version_nagtime = 0;
1325 if(self.classname == "player") {
1326 local vector m1, m2;
1328 // if(self.netname == "Wazat")
1329 // bprint(strcat(self.classname, "\n"));
1331 CheckRules_Player();
1333 Nixnex_GiveCurrentWeapon();
1336 PrintWelcomeMessage(self);
1338 if(cvar("g_lms") || !cvar("sv_spectate"))
1339 if((time - self.jointime) <= cvar("welcome_message_time"))
1340 PrintWelcomeMessage(self);
1342 if (intermission_running)
1344 IntermissionThink (); // otherwise a button could be missed between
1345 return; // the think tics
1348 if (self.deadflag != DEAD_NO)
1351 if (self.deadflag == DEAD_DYING)
1353 if (time > self.dead_time)
1354 self.deadflag = DEAD_DEAD;
1356 else if (self.deadflag == DEAD_DEAD)
1358 if (cvar("g_lms") || cvar("g_arena") || cvar("g_forced_respawn"))
1359 self.deadflag = DEAD_RESPAWNABLE;
1360 else if (!self.button0 && !self.button2 && !self.button3)
1361 self.deadflag = DEAD_RESPAWNABLE;
1363 else if (self.deadflag == DEAD_RESPAWNABLE)
1375 cvar("g_forced_respawn"))
1381 if(cvar("g_lms") && !self.deadflag && cvar("g_lms_campcheck_interval"))
1385 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
1386 dist = self.oldorigin - self.origin;
1388 self.lms_traveled_distance += fabs(vlen(dist));
1390 if(cvar("g_campaign"))
1391 if(!campaign_bots_may_start)
1393 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
1394 self.lms_traveled_distance = 0;
1397 if(time > self.lms_nextcheck)
1399 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
1400 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
1402 centermsg_set(CENTERMSG_CAMP, cvar_string("g_lms_campcheck_message"));
1403 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
1404 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
1405 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');
1407 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
1408 self.lms_traveled_distance = 0;
1412 if (self.button5 && !self.hook.state)
1417 self.view_ofs = PL_CROUCH_VIEW_OFS;
1418 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
1425 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
1426 if (!trace_startsolid)
1428 self.crouch = FALSE;
1429 self.view_ofs = PL_VIEW_OFS;
1430 setsize (self, PL_MIN, PL_MAX);
1435 if(cvar("sv_defaultcharacter") == 1 && !teams_matter) {
1436 local string defaultmodel;
1437 defaultmodel = CheckPlayerModel(cvar_string("sv_defaultplayermodel"));
1439 if (defaultmodel != self.model)
1443 setmodel_lod (self, defaultmodel);
1444 setsize (self, m1, m2);
1447 if (self.skin != cvar("sv_defaultplayerskin"))
1448 self.skin = cvar("sv_defaultplayerskin");
1450 if (self.playermodel != self.model)
1452 self.playermodel = CheckPlayerModel(self.playermodel);
1455 setmodel_lod (self, self.playermodel);
1456 setsize (self, m1, m2);
1461 if (self.skin != math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY))
1462 self.skin = math_mod(stof(self.playerskin), NUM_PLAYERSKINS_TEAMPLAY);
1466 if (self.skin != stof(self.playerskin))
1467 self.skin = stof(self.playerskin);
1470 // Savage: Check for nameless players
1471 if (strlen(self.netname) < 1) {
1472 self.netname = "Player";
1473 stuffcmd(self, "name Player\n");
1476 GrapplingHookFrame();
1480 if (self.button4 || (self.weapon == WEP_NEX && self.button3))
1482 if (cvar("g_minstagib") && self.button3)
1484 if (self.jump_interval <= (time + 0.1))
1486 self.jump_interval = time + 1;
1490 else if (self.viewzoom > 0.4)
1491 self.viewzoom = max (0.4, self.viewzoom - frametime * 2);
1493 else if (self.viewzoom < 1.0)
1494 self.viewzoom = min (1.0, self.viewzoom + frametime);
1500 self.flags = self.flags | FL_JUMPRELEASED;
1506 if (cvar("g_minstagib"))
1507 minstagib_ammocheck();
1511 //self.angles_y=self.v_angle_y + 90; // temp
1513 if (self.waterlevel == 2)
1516 //if (TetrisPreFrame()) return;
1517 } else if(gameover) {
1518 if (intermission_running)
1519 IntermissionThink (); // otherwise a button could be missed between
1521 } else if(self.classname == "observer") {
1523 if (self.flags & FL_JUMPRELEASED) {
1524 if (self.button2 && self.version == cvar("gameversion")) {
1525 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1526 self.flags = self.flags & !FL_JUMPRELEASED;
1527 self.classname = "player";
1528 if(cvar("g_campaign") || cvar("g_balance_teams"))
1529 JoinBestTeam(self, 0);
1530 if(cvar("g_campaign"))
1531 campaign_bots_may_start = 1;
1532 PutClientInServer();
1533 if(self.flags & !FL_NOTARGET)
1534 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
1538 self.flags = self.flags & !FL_JUMPRELEASED;
1539 stuffcmd(self,"menu_showteamselect\n");
1542 } else if(self.button0 && self.version == cvar("gameversion")) {
1543 self.flags = self.flags & !FL_JUMPRELEASED;
1544 if(SpectateNext() == 1) {
1545 self.classname = "spectator";
1549 if (!(self.button0 || self.button2)) {
1550 self.flags = self.flags | FL_JUMPRELEASED;
1553 PrintWelcomeMessage(self);
1554 } else if(self.classname == "spectator") {
1555 if (self.flags & FL_JUMPRELEASED) {
1556 if (self.button2 && self.version == cvar("gameversion")) {
1557 if(!cvar("teamplay") || cvar("g_campaign") || cvar("g_balance_teams")) {
1558 self.flags = self.flags & !FL_JUMPRELEASED;
1559 self.classname = "player";
1561 bprint (strcat("^4", self.netname, "^4 is playing now\n"));
1563 if(cvar("g_campaign") || cvar("g_balance_teams"))
1564 JoinBestTeam(self, 0);
1565 if(cvar("g_campaign"))
1566 campaign_bots_may_start = 1;
1567 PutClientInServer();
1571 self.flags = self.flags & !FL_JUMPRELEASED;
1572 stuffcmd(self,"menu_showteamselect\n");
1575 } else if(self.button0) {
1576 self.flags = self.flags & !FL_JUMPRELEASED;
1577 if(SpectateNext() == 1) {
1578 self.classname = "spectator";
1580 self.classname = "observer";
1581 PutClientInServer();
1583 } else if (self.button3) {
1584 self.flags = self.flags & !FL_JUMPRELEASED;
1585 self.classname = "observer";
1586 PutClientInServer();
1591 if (!(self.button0 || self.button3)) {
1592 self.flags = self.flags | FL_JUMPRELEASED;
1595 PrintWelcomeMessage(self);
1596 self.flags = self.flags | FL_CLIENT | FL_NOTARGET;
1605 Called every frame for each client after the physics are run
1608 void PlayerPostThink (void)
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") {