1 .float spectatee_status;
3 .float bloodloss_timer;
7 float ClientData_Send(entity to, float sf)
18 if(to.classname == "spectator")
24 sf |= 1; // forced scoreboard
25 if(to.spectatee_status)
26 sf |= 2; // spectator ent number follows
29 if(e.porto_v_angle_held)
30 sf |= 8; // angles held
32 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
33 WriteByte(MSG_ENTITY, sf);
36 WriteByte(MSG_ENTITY, to.spectatee_status);
40 WriteAngle(MSG_ENTITY, e.v_angle_x);
41 WriteAngle(MSG_ENTITY, e.v_angle_y);
47 void ClientData_Attach()
49 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
50 self.clientdata.drawonlytoclient = self;
51 self.clientdata.owner = self;
54 void ClientData_Detach()
56 remove(self.clientdata);
57 self.clientdata = world;
60 void ClientData_Touch(entity e)
62 e.clientdata.SendFlags = 1;
64 // make it spectatable
66 FOR_EACH_REALCLIENT(e2)
69 if(e2.classname == "spectator")
71 e2.clientdata.SendFlags = 1;
76 #define SPAWNPOINT_SCORE frags
78 .string netname_previous;
80 void spawnfunc_info_player_survivor (void)
82 spawnfunc_info_player_deathmatch();
85 void spawnfunc_info_player_start (void)
87 spawnfunc_info_player_deathmatch();
90 void spawnfunc_info_player_deathmatch (void)
92 self.classname = "info_player_deathmatch";
93 relocate_spawnpoint();
101 self.team = activator.team;
102 some_spawn_has_been_used = 1;
107 // -1 if a spawn can't be used
108 // otherwise, a weight of the spawnpoint
109 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
111 float shortest, thisdist;
114 // filter out spots for the wrong team
116 if(spot.team != teamcheck)
120 if(spot.target == "")
123 if(clienttype(self) == CLIENTTYPE_REAL)
125 if(spot.restriction == 1)
130 if(spot.restriction == 2)
134 // filter out spots for assault
135 if(spot.target != "") {
138 ent = find(world, targetname, spot.target);
140 if(ent.classname == "target_objective")
143 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
147 else if(ent.classname == "trigger_race_checkpoint")
150 if(self.classname == "player") // spectators may spawn everywhere
152 if(g_race_qualifying)
155 if(ent.race_checkpoint != 0)
157 if(spot.race_place != race_lowest_place_spawn)
162 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
165 pl = self.race_place;
166 if(pl > race_highest_place_spawn)
168 if(spot.race_place != pl)
174 ent = find(ent, targetname, spot.target);
182 shortest = vlen(world.maxs - world.mins);
183 for(player = playerlist; player; player = player.chain)
186 thisdist = vlen(player.origin - spot.origin);
187 if (thisdist < shortest)
195 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
197 local entity spot, spotlist, spotlistend;
198 spawn_allgood = TRUE;
204 for(spot = firstspot; spot; spot = spot.chain)
206 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
208 if(cvar("spawn_debugview"))
210 setmodel(spot, "models/runematch/rune.mdl");
211 if(spot.SPAWNPOINT_SCORE < mindist)
213 spot.colormod = '1 0 0';
218 spot.colormod = '0 1 0';
219 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
223 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
225 if(spot.SPAWNPOINT_SCORE < mindist)
227 // too short distance
228 spawn_allgood = FALSE;
233 spawn_allbad = FALSE;
236 spotlistend.chain = spot;
243 if(spot.team != teamcheck)
244 error("invalid spawn added");
246 print("added ", etos(spot), "\n");
252 spotlistend.chain = world;
257 for(e = spotlist; e; e = e.chain)
259 print("seen ", etos(e), "\n");
260 if(e.team != teamcheck)
261 error("invalid spawn found");
268 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
270 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
271 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
274 RandomSelection_Init();
275 for(spot = firstspot; spot; spot = spot.chain)
276 RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
278 return RandomSelection_chosen_ent;
285 Finds a point to respawn
288 entity SelectSpawnPoint (float anypoint)
290 local float teamcheck;
291 local entity firstspot_new;
292 local entity spot, firstspot, playerlist;
294 spot = find (world, classname, "testplayerstart");
300 if(!anypoint && have_team_spawns)
301 teamcheck = self.team;
303 // get the list of players
304 playerlist = findchain(classname, "player");
305 // get the entire list of spots
306 firstspot = findchain(classname, "info_player_deathmatch");
307 // filter out the bad ones
308 // (note this returns the original list if none survived)
309 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
311 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
312 firstspot = firstspot_new;
314 // there is 50/50 chance of choosing a random spot or the furthest spot
315 // (this means that roughly every other spawn will be furthest, so you
316 // usually won't get fragged at spawn twice in a row)
317 if (arena_roundbased)
319 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
321 firstspot = firstspot_new;
322 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
324 else if (random() > cvar("g_spawn_furthest"))
325 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
327 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
329 if(cvar("spawn_debugview"))
331 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
335 for(e = firstspot; e; e = e.chain)
336 if(e.team != teamcheck)
337 error("invalid spawn found");
342 if(cvar("spawn_debug"))
346 if(some_spawn_has_been_used)
347 return world; // team can't spawn any more, because of actions of other team
349 error("Cannot find a spawn point - please fix the map!");
360 Checks if the argument string can be a valid playermodel.
361 Returns a valid one in doubt.
364 string FallbackPlayerModel = "models/player/marine.zym";
365 string CheckPlayerModel(string plyermodel) {
366 if(strlen(plyermodel) < 4)
367 return FallbackPlayerModel;
368 if( substring(plyermodel,0,14) != "models/player/")
369 return FallbackPlayerModel;
370 else if(cvar("sv_servermodelsonly"))
372 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
373 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
374 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
375 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
376 return FallbackPlayerModel;
377 #ifdef ALLOW_VARIABLE_LOD
378 // forbid the LOD models
379 if(substring(plyermodel, strlen(plyermodel)-6,2) == "_1")
380 return FallbackPlayerModel;
381 if(substring(plyermodel, strlen(plyermodel)-6,2) == "_2")
382 return FallbackPlayerModel;
384 if(plyermodel != strtolower(plyermodel))
385 return FallbackPlayerModel;
386 if(!fexists(plyermodel))
387 return FallbackPlayerModel;
394 Client_customizeentityforclient
399 float Client_customizeentityforclient()
403 if(self.modelindex == 0)
407 if(other.cvar_cl_forceplayermodelsfromnexuiz)
408 if not(self.modelindex_lod0_from_nexuiz)
410 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
413 if(modelsource == self)
414 self.skin = modelsource.skinindex;
416 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
418 #ifdef ALLOW_VARIABLE_LOD
420 // other: the player viewing me
424 if(self.classname != "player")
427 if(other.cvar_cl_playerdetailreduction <= 0)
429 if(other.cvar_cl_playerdetailreduction <= -2)
430 self.modelindex = modelsource.modelindex_lod2;
431 else if(other.cvar_cl_playerdetailreduction <= -1)
432 self.modelindex = modelsource.modelindex_lod1;
434 self.modelindex = modelsource.modelindex_lod0;
438 distance = vlen(self.origin - other.origin);
439 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
441 self.modelindex = modelsource.modelindex_lod2;
443 self.modelindex = modelsource.modelindex_lod1;
445 self.modelindex = modelsource.modelindex_lod0;
448 self.modelindex = modelsource.modelindex_lod0;
454 void UpdatePlayerSounds();
455 void setmodel_lod(entity e, string modelname)
457 #ifdef ALLOW_VARIABLE_LOD
460 // FIXME: this only supports 3-letter extensions
461 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
465 setmodel(e, s); // players have high precision
466 self.modelindex_lod1 = self.modelindex;
469 self.modelindex_lod1 = -1;
471 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
475 setmodel(e, s); // players have high precision
476 self.modelindex_lod2 = self.modelindex;
479 self.modelindex_lod2 = -1;
481 precache_model(modelname);
482 setmodel(e, modelname); // players have high precision
483 self.modelindex_lod0 = self.modelindex;
485 if(self.modelindex_lod1 < 0)
486 self.modelindex_lod1 = self.modelindex;
488 if(self.modelindex_lod2 < 0)
489 self.modelindex_lod2 = self.modelindex;
491 precache_model(modelname);
492 setmodel(e, modelname); // players have high precision
493 self.modelindex_lod0 = self.modelindex;
494 // save it for possible player model forcing
498 s = whichpack(self.model);
499 self.modelindex_lod0_from_nexuiz = ((s == "") || (substring(s, 0, 4) == "data"));
501 player_setupanimsformodel();
502 UpdatePlayerSounds();
509 putting a client as observer in the server
512 void PutObserverInServer (void)
516 race_PreSpawnObserver();
518 spot = SelectSpawnPoint (TRUE);
520 error("No spawnpoints for observers?!?\n");
521 RemoveGrapplingHook(self); // Wazat's Grappling Hook
523 if(clienttype(self) == CLIENTTYPE_REAL)
526 WriteByte(MSG_ONE, SVC_SETVIEW);
527 WriteEntity(MSG_ONE, self);
531 kh_Key_DropAll(self, TRUE);
533 Portal_ClearAll(self);
536 DropFlag(self.flagcarried, world, world);
538 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
540 WaypointSprite_PlayerDead();
542 if(self.killcount != -666)
546 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
547 bprint ("^4", self.netname, "^4 has no more lives left\n");
549 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
552 bprint ("^4", self.netname, "^4 is spectating now\n");
555 PlayerScore_Clear(self); // clear scores when needed
557 self.spectatortime = time;
559 self.classname = "observer";
560 self.iscreature = FALSE;
562 self.takedamage = DAMAGE_NO;
563 self.solid = SOLID_NOT;
564 self.movetype = MOVETYPE_NOCLIP;
565 self.flags = FL_CLIENT | FL_NOTARGET;
566 self.armorvalue = 666;
568 self.armorvalue = cvar("g_balance_armor_start");
569 self.pauserotarmor_finished = 0;
570 self.pauserothealth_finished = 0;
571 self.pauseregen_finished = 0;
572 self.damageforcescale = 0;
579 self.pain_finished = 0;
580 self.strength_finished = 0;
581 self.invincible_finished = 0;
583 self.think = SUB_Null;
587 self.deadflag = DEAD_NO;
588 self.angles = spot.angles;
590 self.fixangle = TRUE;
593 self.view_ofs = PL_VIEW_OFS;
594 setorigin (self, spot.origin);
595 setsize (self, '0 0 0', '0 0 0');
596 self.prevorigin = self.origin;
602 self.weaponmodel = "";
603 self.weaponentity = world;
604 self.exteriorweaponentity = world;
605 self.killcount = -666;
606 self.velocity = '0 0 0';
607 self.avelocity = '0 0 0';
608 self.punchangle = '0 0 0';
609 self.punchvector = '0 0 0';
610 self.oldvelocity = self.velocity;
611 self.customizeentityforclient = Client_customizeentityforclient;
617 if(self.version_mismatch)
619 Spawnqueue_Unmark(self);
620 Spawnqueue_Remove(self);
624 Spawnqueue_Insert(self);
629 // Only if the player cannot play at all
630 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
631 self.frags = FRAGS_SPECTATOR;
633 self.frags = FRAGS_LMS_LOSER;
636 self.frags = FRAGS_SPECTATOR;
639 float RestrictSkin(float s)
648 void FixPlayermodel()
650 local string defaultmodel;
651 local float defaultskin, chmdl, oldskin;
656 if(cvar("sv_defaultcharacter") == 1) {
661 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
662 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
665 if(defaultmodel == "")
667 defaultmodel = cvar_string("sv_defaultplayermodel");
668 defaultskin = cvar("sv_defaultplayerskin");
672 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
675 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
676 self.model = ""; // force the != checks to return true
679 if(defaultmodel != "")
681 if (defaultmodel != self.model)
685 setmodel_lod (self, defaultmodel);
686 setsize (self, m1, m2);
690 oldskin = self.skinindex;
691 self.skinindex = defaultskin;
693 if (self.playermodel != self.model)
695 self.playermodel = CheckPlayerModel(self.playermodel);
698 setmodel_lod (self, self.playermodel);
699 setsize (self, m1, m2);
703 oldskin = self.skinindex;
704 self.skinindex = RestrictSkin(stof(self.playerskin));
707 if(chmdl || oldskin != self.skinindex)
708 self.species = player_getspecies(); // model or skin has changed
711 if(strlen(cvar_string("sv_defaultplayercolors")))
712 if(self.clientcolors != cvar("sv_defaultplayercolors"))
713 setcolor(self, cvar("sv_defaultplayercolors"));
716 void PlayerTouchExplode(entity p1, entity p2)
719 org = (p1.origin + p2.origin) * 0.5;
720 org_z += (p1.mins_z + p2.mins_z) * 0.5;
727 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
735 Called when a client spawns in the server
738 //void() ctf_playerchanged;
739 void PutClientInServer (void)
741 if(clienttype(self) == CLIENTTYPE_BOT)
743 self.classname = "player";
745 else if(clienttype(self) == CLIENTTYPE_REAL)
748 WriteByte(MSG_ONE, SVC_SETVIEW);
749 WriteEntity(MSG_ONE, self);
752 // player is dead and becomes observer
753 // FIXME fix LMS scoring for new system
756 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
757 self.classname = "observer";
762 self.classname = "observer";
764 if(self.classname == "player") {
765 entity spot, oldself;
768 JoinBestTeam(self, FALSE, TRUE);
772 spot = SelectSpawnPoint (FALSE);
775 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
776 return; // spawn failed
779 RemoveGrapplingHook(self); // Wazat's Grappling Hook
780 self.campingrifle_bulletcounter = 0;
782 self.classname = "player";
783 self.wasplayer = TRUE;
784 self.iscreature = TRUE;
785 self.movetype = MOVETYPE_WALK;
786 self.solid = SOLID_SLIDEBOX;
787 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
788 self.frags = FRAGS_PLAYER;
789 if(independent_players)
790 MAKE_INDEPENDENT_PLAYER(self);
791 self.flags = FL_CLIENT;
792 self.takedamage = DAMAGE_AIM;
794 self.effects = EF_FULLBRIGHT;
797 self.air_finished = time + 12;
802 self.ammo_shells = warmup_start_ammo_shells;
803 self.ammo_nails = warmup_start_ammo_nails;
804 self.ammo_rockets = warmup_start_ammo_rockets;
805 self.ammo_cells = warmup_start_ammo_cells;
806 self.ammo_fuel = warmup_start_ammo_fuel;
807 self.health = warmup_start_health;
808 self.armorvalue = warmup_start_armorvalue;
809 self.weapons = warmup_start_weapons;
813 self.ammo_shells = start_ammo_shells;
814 self.ammo_nails = start_ammo_nails;
815 self.ammo_rockets = start_ammo_rockets;
816 self.ammo_cells = start_ammo_cells;
817 self.ammo_fuel = start_ammo_fuel;
818 self.health = start_health;
819 self.armorvalue = start_armorvalue;
820 self.weapons = start_weapons;
822 self.items = start_items;
823 self.switchweapon = w_getbestweapon(self);
824 self.cnt = self.switchweapon;
826 self.jump_interval = time;
828 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
829 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
830 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
831 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
832 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
833 //extend the pause of rotting if client was reset at the beginning of the countdown
834 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
835 self.spawnshieldtime += game_starttime - time;
836 self.pauserotarmor_finished += game_starttime - time;
837 self.pauserothealth_finished += game_starttime - time;
838 self.pauseregen_finished += game_starttime - time;
840 self.damageforcescale = 2;
847 self.pain_finished = 0;
848 self.strength_finished = 0;
849 self.invincible_finished = 0;
851 //self.speed_finished = 0;
852 //self.slowmo_finished = 0;
853 // players have no think function
854 self.think = SUB_Null;
863 self.deadflag = DEAD_NO;
865 self.angles = spot.angles;
867 self.angles_z = 0; // never spawn tilted even if the spot says to
868 self.fixangle = TRUE; // turn this way immediately
869 self.velocity = '0 0 0';
870 self.avelocity = '0 0 0';
871 self.punchangle = '0 0 0';
872 self.punchvector = '0 0 0';
873 self.oldvelocity = self.velocity;
876 WRITESPECTATABLE_MSG_ONE({
877 WriteByte(MSG_ONE, SVC_TEMPENTITY);
878 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
881 self.customizeentityforclient = Client_customizeentityforclient;
887 self.view_ofs = PL_VIEW_OFS;
888 setsize (self, PL_MIN, PL_MAX);
889 self.spawnorigin = spot.origin;
890 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
891 // don't reset back to last position, even if new position is stuck in solid
892 self.oldorigin = self.origin;
893 self.prevorigin = self.origin;
894 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
898 Spawnqueue_Remove(self);
899 Spawnqueue_Mark(self);
902 self.event_damage = PlayerDamage;
904 self.bot_attack = TRUE;
906 self.statdraintime = time + 5;
907 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
909 if(self.killcount == -666) {
910 PlayerScore_Clear(self);
914 self.cnt = WEP_LASER;
915 self.nixnex_lastchange_id = -1;
917 CL_SpawnWeaponentity();
918 self.alpha = default_player_alpha;
919 self.colormod = '1 1 1' * cvar("g_player_brightness");
920 self.exteriorweaponentity.alpha = default_weapon_alpha;
922 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
923 self.lms_traveled_distance = 0;
924 self.speedrunning = FALSE;
926 race_PostSpawn(spot);
928 if(cvar("spawn_debug"))
930 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
931 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
934 //stuffcmd(self, "chase_active 0");
935 //stuffcmd(self, "set viewsize $tmpviewsize \n");
937 if (cvar("g_spawnsound"))
938 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
941 if(self.team == assault_attacker_team)
942 centerprint(self, "You are attacking!");
944 centerprint(self, "You are defending!");
947 target_voicescript_clear(self);
956 } else if(self.classname == "observer") {
957 PutObserverInServer ();
961 // ctf_playerchanged();
964 float ClientInit_SendEntity(entity to, float sf)
967 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
968 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
969 for(i = 1; i <= 24; ++i)
970 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
971 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
972 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
973 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
975 if(sv_foginterval && world.fog != "")
976 WriteString(MSG_ENTITY, world.fog);
978 WriteString(MSG_ENTITY, "");
979 WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);
983 void ClientInit_Spawn()
985 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
993 void SetNewParms (void)
995 // initialize parms for a new player
996 parm1 = -(86400 * 366);
1004 void SetChangeParms (void)
1006 // save parms for level change
1007 parm1 = self.parm_idlesince - time;
1015 void DecodeLevelParms (void)
1018 self.parm_idlesince = parm1;
1019 if(self.parm_idlesince == -(86400 * 366))
1020 self.parm_idlesince = time;
1022 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1023 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1030 Called when a client types 'kill' in the console
1034 void ClientKill_Now_TeamChange()
1036 if(self.killindicator_teamchange == -1)
1039 JoinBestTeam( self, FALSE, FALSE );
1042 SV_ChangeTeam(self.killindicator_teamchange - 1);
1045 void ClientKill_Now()
1047 if(self.killindicator_teamchange)
1048 ClientKill_Now_TeamChange();
1051 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1053 if(self.killindicator)
1055 dprint("Cleaned up after a leaked kill indicator.\n");
1056 remove(self.killindicator);
1057 self.killindicator = world;
1060 void KillIndicator_Think()
1062 if (!self.owner.modelindex)
1064 self.owner.killindicator = world;
1072 ClientKill_Now(); // no oldself needed
1078 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1079 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1082 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1083 if(self.owner.killindicator_teamchange)
1085 if(self.owner.killindicator_teamchange == -1)
1086 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1088 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1091 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1093 self.nextthink = time + 1;
1098 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1102 killtime = cvar("g_balance_kill_delay");
1104 self.killindicator_teamchange = targetteam;
1106 if(!self.killindicator)
1108 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1114 self.killindicator = spawn();
1115 self.killindicator.owner = self;
1116 self.killindicator.scale = 0.5;
1117 setattachment(self.killindicator, self, "");
1118 setorigin(self.killindicator, '0 0 52');
1119 self.killindicator.think = KillIndicator_Think;
1120 self.killindicator.nextthink = time + (self.lip) * 0.05;
1121 self.killindicator.cnt = ceil(killtime);
1122 self.killindicator.count = bound(0, ceil(killtime), 10);
1123 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1125 for(e = world; (e = find(e, classname, "body")) != world; )
1129 e.killindicator = spawn();
1130 e.killindicator.owner = e;
1131 e.killindicator.scale = 0.5;
1132 setattachment(e.killindicator, e, "");
1133 setorigin(e.killindicator, '0 0 52');
1134 e.killindicator.think = KillIndicator_Think;
1135 e.killindicator.nextthink = time + (e.lip) * 0.05;
1136 e.killindicator.cnt = ceil(killtime);
1141 if(self.killindicator)
1144 self.killindicator.colormod = TeamColor(targetteam);
1146 self.killindicator.colormod = '0 0 0';
1150 void ClientKill (void)
1152 ClientKill_TeamChange(0);
1155 void DoTeamChange(float destteam)
1161 SetPlayerColors(self, destteam);
1164 if(self.classname == "player")
1167 CheckAllowedTeams(self);
1168 t = FindSmallestTeam(self, TRUE);
1171 case COLOR_TEAM1: c0 = c1; break;
1172 case COLOR_TEAM2: c0 = c2; break;
1173 case COLOR_TEAM3: c0 = c3; break;
1174 case COLOR_TEAM4: c0 = c4; break;
1181 destteam = COLOR_TEAM1;
1185 destteam = COLOR_TEAM2;
1189 destteam = COLOR_TEAM3;
1193 destteam = COLOR_TEAM4;
1199 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1201 ClientKill_TeamChange(destteam);
1204 void FixClientCvars(entity e)
1206 // send prediction settings to the client
1207 stuffcmd(e, "\nin_bindmap 0 0\n");
1209 * we no longer need to stuff this. Remove this comment block if you feel
1210 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1211 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1212 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1213 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1214 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1215 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1216 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1217 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1218 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1219 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1220 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1221 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1222 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1223 stuffcmd(e, "cl_movement_edgefriction 1\n");
1231 Called when a client connects to the server
1234 //void ctf_clientconnect();
1235 string ColoredTeamName(float t);
1236 void DecodeLevelParms (void);
1237 //void dom_player_join_team(entity pl);
1238 void ClientConnect (void)
1243 if(self.flags & FL_CLIENT)
1245 print("Warning: ClientConnect, but already connected!\n");
1249 if(Ban_MaybeEnforceBan(self))
1254 self.classname = "player_joining";
1256 self.flags = FL_CLIENT;
1257 self.version_nagtime = time + 10 + random() * 10;
1261 dprint("BUG player count is lower than zero, this cannot happen!\n");
1265 PlayerScore_Attach(self);
1266 ClientData_Attach();
1268 bot_clientconnect();
1270 race_PreSpawnObserver();
1273 // dom_player_join_team(self);
1275 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1277 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1278 self.classname = "observer";
1282 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1284 self.classname = "player";
1285 campaign_bots_may_start = 1;
1289 self.classname = "observer"; // do it anyway
1294 self.classname = "player";
1295 campaign_bots_may_start = 1;
1299 self.playerid = (playerid_last = playerid_last + 1);
1300 if(cvar("sv_eventlog"))
1302 if(clienttype(self) == CLIENTTYPE_REAL)
1303 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1305 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1306 s = strcat(":team:", ftos(self.playerid), ":");
1307 s = strcat(s, ftos(self.team));
1310 self.netname_previous = strzone(self.netname);
1312 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1314 bprint ("^4",self.netname);
1315 bprint ("^4 connected");
1317 if(g_domination || g_ctf)
1319 bprint(" and joined the ");
1320 bprint(ColoredTeamName(self.team));
1325 self.welcomemessage_time = 0;
1327 stuffcmd(self, strcat(clientstuff, "\n"));
1328 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1329 stuffcmd(self, "cl_particles_reloadeffects\n");
1331 FixClientCvars(self);
1333 // spawnfunc_waypoint sprites
1334 WaypointSprite_InitClient(self);
1336 // Wazat's grappling hook
1337 SetGrappleHookBindings();
1339 // get autoswitch state from player when he toggles it
1340 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1342 // get version info from player
1343 stuffcmd(self, "cmd clientversion $gameversion\n");
1345 // get other cvars from player
1348 // set cvar for team scoreboard
1349 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1351 // notify about available teams
1354 CheckAllowedTeams(self);
1355 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1356 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1359 stuffcmd(self, "set _teams_available 0\n");
1361 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1365 self.classname = "observer";
1366 Spawnqueue_Insert(self);
1370 ctf_clientconnect();
1373 if(teams_matter || sv_cheats)
1376 bot_relinkplayerlist();
1378 self.spectatortime = time;
1381 sprint(self, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1384 self.jointime = time;
1385 self.allowedTimeouts = cvar("sv_timeout_number");
1387 if(clienttype(self) == CLIENTTYPE_REAL)
1389 if(cvar("g_bugrigs") || g_weaponarena == WEPBIT_TUBA)
1390 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1395 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1397 PlayerScore_Add(self, SP_LMS_RANK, 666);
1398 self.frags = FRAGS_SPECTATOR;
1402 if(!sv_foginterval && world.fog != "")
1403 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1405 SoundEntity_Attach(self);
1407 if(cvar("g_hitplots"))
1409 self.hitplotfh = fopen(strcat("hits-", matchid, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1410 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1413 self.hitplotfh = -1;
1420 Called when a client disconnects from the server
1423 .entity chatbubbleentity;
1424 .entity teambubbleentity;
1426 void ClientDisconnect (void)
1428 if not(self.flags & FL_CLIENT)
1430 print("Warning: ClientDisconnect without ClientConnect\n");
1434 if(self.hitplotfh >= 0)
1436 fclose(self.hitplotfh);
1437 self.hitplotfh = -1;
1440 bot_clientdisconnect();
1445 if(cvar("sv_eventlog"))
1446 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1447 bprint ("^4",self.netname);
1448 bprint ("^4 disconnected\n");
1450 SoundEntity_Detach(self);
1453 kh_Key_DropAll(self, TRUE);
1455 Portal_ClearAll(self);
1457 if(self.flagcarried)
1458 DropFlag(self.flagcarried, world, world);
1459 if(self.ballcarried)
1460 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1462 // Here, everything has been done that requires this player to be a client.
1464 self.flags &~= FL_CLIENT;
1466 if (self.chatbubbleentity)
1467 remove (self.chatbubbleentity);
1469 if (self.teambubbleentity)
1470 remove (self.teambubbleentity);
1472 if (self.killindicator)
1473 remove (self.killindicator);
1475 WaypointSprite_PlayerGone();
1477 bot_relinkplayerlist();
1480 if(self.weaponentity)
1481 if(self.weaponentity.lasertarget)
1482 remove(self.weaponentity.lasertarget);
1486 Spawnqueue_Unmark(self);
1487 Spawnqueue_Remove(self);
1490 ClientData_Detach();
1491 PlayerScore_Detach(self);
1493 if(self.netname_previous)
1494 strunzone(self.netname_previous);
1495 if(self.clientstatus)
1496 strunzone(self.clientstatus);
1498 ClearPlayerSounds();
1508 void ChatBubbleThink()
1510 self.nextthink = time;
1511 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1513 if(self.owner) // but why can that ever be world?
1514 self.owner.chatbubbleentity = world;
1518 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1519 self.model = self.mdl;
1524 void UpdateChatBubble()
1526 if (!self.modelindex)
1528 // spawn a chatbubble entity if needed
1529 if (!self.chatbubbleentity)
1531 self.chatbubbleentity = spawn();
1532 self.chatbubbleentity.owner = self;
1533 self.chatbubbleentity.exteriormodeltoclient = self;
1534 self.chatbubbleentity.think = ChatBubbleThink;
1535 self.chatbubbleentity.nextthink = time;
1536 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1537 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1538 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1539 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1540 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1541 self.chatbubbleentity.model = "";
1542 self.chatbubbleentity.effects = EF_LOWPRECISION;
1547 void TeamBubbleThink()
1549 self.nextthink = time;
1550 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1552 if(self.owner) // but why can that ever be world?
1553 self.owner.teambubbleentity = world;
1557 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1558 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1561 self.model = self.mdl;
1565 float TeamBubble_customizeentityforclient()
1567 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1570 void UpdateTeamBubble()
1572 if (!self.modelindex || !teams_matter)
1574 // spawn a teambubble entity if needed
1575 if (!self.teambubbleentity && teams_matter)
1577 self.teambubbleentity = spawn();
1578 self.teambubbleentity.owner = self;
1579 self.teambubbleentity.exteriormodeltoclient = self;
1580 self.teambubbleentity.think = TeamBubbleThink;
1581 self.teambubbleentity.nextthink = time;
1582 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1583 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1584 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1585 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1586 self.teambubbleentity.mdl = self.teambubbleentity.model;
1587 self.teambubbleentity.model = self.teambubbleentity.mdl;
1588 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1589 self.teambubbleentity.effects = EF_LOWPRECISION;
1593 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1594 // added to the model skins
1595 /*void UpdateColorModHack()
1598 c = self.clientcolors & 15;
1599 // LordHavoc: only bothering to support white, green, red, yellow, blue
1600 if (!teams_matter) self.colormod = '0 0 0';
1601 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1602 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1603 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1604 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1605 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1606 else self.colormod = '1 1 1';
1612 self.effects |= EF_NODRAW; // prevent another CopyBody
1613 PutClientInServer();
1616 void play_countdown(float finished, string samp)
1618 if(clienttype(self) == CLIENTTYPE_REAL)
1619 if(floor(finished - time - frametime) != floor(finished - time))
1620 if(finished - time < 6)
1621 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1625 * When sv_timeout is used this function returs strings like
1626 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1627 * Called by centerprint functions
1628 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1630 string getTimeoutText(float addOneSecond) {
1631 if (!cvar("sv_timeout") || !timeoutStatus)
1634 local string retStr;
1635 if (timeoutStatus == 1) {
1636 if (addOneSecond == 1) {
1637 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1640 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1644 else if (timeoutStatus == 2) {
1646 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1647 //don't show messages like "Timeout ends in 0 seconds"...
1648 if ((remainingTimeoutTime + 1) > 0)
1654 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1655 //don't show messages like "Timeout ends in 0 seconds"...
1656 if (remainingTimeoutTime > 0)
1665 void player_powerups (void)
1667 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1669 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));
1670 self.modelflags |= MF_ROCKET;
1674 SoundEntity_StopSound(self, CHAN_PLAYER);
1675 self.modelflags &~= MF_ROCKET;
1678 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1680 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1685 self.effects |= EF_FULLBRIGHT;
1687 if (self.items & IT_STRENGTH)
1689 play_countdown(self.strength_finished, "misc/poweroff.wav");
1690 if (time > self.strength_finished)
1692 self.alpha = default_player_alpha;
1693 self.exteriorweaponentity.alpha = default_weapon_alpha;
1694 self.items &~= IT_STRENGTH;
1695 sprint(self, "^3Invisibility has worn off\n");
1700 if (time < self.strength_finished)
1702 self.alpha = g_minstagib_invis_alpha;
1703 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1704 self.items |= IT_STRENGTH;
1705 sprint(self, "^3You are invisible\n");
1709 if (self.items & IT_INVINCIBLE)
1711 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1712 if (time > self.invincible_finished)
1714 self.items = self.items - (self.items & IT_INVINCIBLE);
1715 sprint(self, "^3Speed has worn off\n");
1720 if (time < self.invincible_finished)
1722 self.items = self.items | IT_INVINCIBLE;
1723 sprint(self, "^3You are on speed\n");
1729 if (self.items & IT_STRENGTH)
1731 play_countdown(self.strength_finished, "misc/poweroff.wav");
1732 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1733 if (time > self.strength_finished)
1735 self.items = self.items - (self.items & IT_STRENGTH);
1736 sprint(self, "^3Strength has worn off\n");
1741 if (time < self.strength_finished)
1743 self.items = self.items | IT_STRENGTH;
1744 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1747 if (self.items & IT_INVINCIBLE)
1749 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1750 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1751 if (time > self.invincible_finished)
1753 self.items = self.items - (self.items & IT_INVINCIBLE);
1754 sprint(self, "^3Shield has worn off\n");
1759 if (time < self.invincible_finished)
1761 self.items = self.items | IT_INVINCIBLE;
1762 sprint(self, "^3Shield surrounds you\n");
1766 if (cvar("g_fullbrightplayers"))
1767 self.effects = self.effects | EF_FULLBRIGHT;
1769 // midair gamemode: damage only while in the air
1770 // if in midair mode, being on ground grants temporary invulnerability
1771 // (this is so that multishot weapon don't clear the ground flag on the
1772 // first damage in the frame, leaving the player vulnerable to the
1773 // remaining hits in the same frame)
1774 if (self.flags & FL_ONGROUND)
1776 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1778 if (time >= game_starttime)
1779 if (time < self.spawnshieldtime)
1780 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1783 float CalcRegen(float current, float stable, float regenfactor)
1785 if(current > stable)
1787 else if(current > stable - 0.25) // when close enough, "snap"
1790 return min(stable, current + (stable - current) * regenfactor * frametime);
1793 void player_regen (void)
1795 float maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1796 maxh = cvar("g_balance_health_stable");
1797 maxa = cvar("g_balance_armor_stable");
1798 maxf = cvar("g_balance_fuel_stable");
1799 limith = cvar("g_balance_health_limit");
1800 limita = cvar("g_balance_armor_limit");
1801 limitf = cvar("g_balance_fuel_limit");
1803 max_mod = regen_mod = rot_mod = limit_mod = 1;
1805 if (self.runes & RUNE_REGEN)
1807 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1809 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1810 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1811 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1815 regen_mod = cvar("g_balance_rune_regen_regenrate");
1816 max_mod = cvar("g_balance_rune_regen_hpmod");
1817 limit_mod = cvar("g_balance_rune_regen_limitmod");
1820 else if (self.runes & CURSE_VENOM)
1822 max_mod = cvar("g_balance_curse_venom_hpmod");
1823 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1824 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1826 rot_mod = cvar("g_balance_curse_venom_rotrate");
1827 limit_mod = cvar("g_balance_curse_venom_limitmod");
1828 //if (!self.runes & RUNE_REGEN)
1829 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1831 maxh = maxh * max_mod;
1832 //maxa = maxa * max_mod;
1833 //maxf = maxf * max_mod;
1834 limith = limith * limit_mod;
1835 limita = limita * limit_mod;
1836 //limitf = limitf * limit_mod;
1838 if (!g_minstagib && (!g_lms || cvar("g_lms_regenerate")))
1840 if (self.armorvalue > maxa)
1842 if (time > self.pauserotarmor_finished)
1844 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1845 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1848 else if (self.armorvalue < maxa)
1850 if (time > self.pauseregen_finished)
1852 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1853 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1856 if (self.armorvalue > limita)
1857 self.armorvalue = limita;
1859 if (self.health > maxh)
1861 if (time > self.pauserothealth_finished)
1863 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1864 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1867 else if (self.health < maxh)
1869 if (time > self.pauseregen_finished)
1871 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1872 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1875 if (self.health > limith)
1876 self.health = limith;
1878 // if player rotted to death... die!
1880 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1883 if (self.ammo_fuel > maxf)
1885 if (time > self.pauserotfuel_finished)
1887 self.ammo_fuel = max(maxf, self.ammo_fuel + (maxf - self.ammo_fuel) * rot_mod*cvar("g_balance_fuel_rot") * frametime);
1888 self.ammo_fuel = max(maxf, self.ammo_fuel - rot_mod*cvar("g_balance_fuel_rotlinear") * frametime);
1891 else if (self.ammo_fuel < maxf)
1893 if(self.items & IT_FUEL_REGEN)
1895 if (time > self.pauseregen_finished)
1897 self.ammo_fuel = CalcRegen(self.ammo_fuel, maxf, regen_mod * cvar("g_balance_fuel_regen"));
1898 self.ammo_fuel = min(maxf, self.ammo_fuel + regen_mod*cvar("g_balance_fuel_regenlinear") * frametime);
1902 if (self.ammo_fuel > limitf)
1903 self.ammo_fuel = limitf;
1906 float zoomstate_set;
1907 void SetZoomState(float z)
1909 if(z != self.zoomstate)
1912 ClientData_Touch(self);
1917 void GetPressedKeys(void) {
1918 if (self.movement_x > 0) // get if movement keys are pressed
1919 { // forward key pressed
1920 self.pressedkeys |= KEY_FORWARD;
1921 self.pressedkeys &~= KEY_BACKWARD;
1923 else if (self.movement_x < 0)
1924 { // backward key pressed
1925 self.pressedkeys |= KEY_BACKWARD;
1926 self.pressedkeys &~= KEY_FORWARD;
1930 self.pressedkeys &~= KEY_FORWARD;
1931 self.pressedkeys &~= KEY_BACKWARD;
1934 if (self.movement_y > 0)
1935 { // right key pressed
1936 self.pressedkeys |= KEY_RIGHT;
1937 self.pressedkeys &~= KEY_LEFT;
1939 else if (self.movement_y < 0)
1940 { // left key pressed
1941 self.pressedkeys |= KEY_LEFT;
1942 self.pressedkeys &~= KEY_RIGHT;
1946 self.pressedkeys &~= KEY_RIGHT;
1947 self.pressedkeys &~= KEY_LEFT;
1950 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1951 self.pressedkeys |= KEY_JUMP;
1953 self.pressedkeys &~= KEY_JUMP;
1954 if (self.BUTTON_CROUCH)
1955 self.pressedkeys |= KEY_CROUCH;
1957 self.pressedkeys &~= KEY_CROUCH;
1961 ======================
1962 spectate mode routines
1963 ======================
1965 void SpectateCopy(entity spectatee) {
1966 self.armortype = spectatee.armortype;
1967 self.armorvalue = spectatee.armorvalue;
1968 self.ammo_cells = spectatee.ammo_cells;
1969 self.ammo_shells = spectatee.ammo_shells;
1970 self.ammo_nails = spectatee.ammo_nails;
1971 self.ammo_rockets = spectatee.ammo_rockets;
1972 self.ammo_fuel = spectatee.ammo_fuel;
1973 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1974 self.health = spectatee.health;
1976 self.items = spectatee.items;
1977 self.metertime = spectatee.metertime;
1978 self.strength_finished = spectatee.strength_finished;
1979 self.invincible_finished = spectatee.invincible_finished;
1980 self.pressedkeys = spectatee.pressedkeys;
1981 self.weapons = spectatee.weapons;
1982 self.switchweapon = spectatee.switchweapon;
1983 self.weapon = spectatee.weapon;
1984 self.punchangle = spectatee.punchangle;
1985 self.view_ofs = spectatee.view_ofs;
1986 self.v_angle = spectatee.v_angle;
1987 self.velocity = spectatee.velocity;
1988 self.dmg_take = spectatee.dmg_take;
1989 self.dmg_save = spectatee.dmg_save;
1990 self.dmg_inflictor = spectatee.dmg_inflictor;
1991 self.angles = spectatee.v_angle;
1992 self.fixangle = TRUE;
1993 setorigin(self, spectatee.origin);
1994 setsize(self, spectatee.mins, spectatee.maxs);
1995 SetZoomState(spectatee.zoomstate);
1998 float SpectateUpdate() {
2002 if (self == self.enemy)
2005 if(self.enemy.classname != "player")
2008 SpectateCopy(self.enemy);
2013 float SpectateNext() {
2014 other = find(self.enemy, classname, "player");
2016 other = find(other, classname, "player");
2021 if(self.enemy.classname == "player") {
2023 WriteByte(MSG_ONE, SVC_SETVIEW);
2024 WriteEntity(MSG_ONE, self.enemy);
2025 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2026 if(!SpectateUpdate())
2027 PutObserverInServer();
2036 ShowRespawnCountdown()
2038 Update a respawn countdown display.
2041 void ShowRespawnCountdown()
2044 if(self.deadflag == DEAD_NO) // just respawned?
2048 number = ceil(self.death_time - time);
2051 if(number <= self.respawn_countdown)
2053 self.respawn_countdown = number - 1;
2054 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
2055 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
2060 void LeaveSpectatorMode()
2062 if(isJoinAllowed()) {
2063 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2064 self.classname = "player";
2065 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2066 JoinBestTeam(self, FALSE, TRUE);
2067 if(cvar("g_campaign"))
2068 campaign_bots_may_start = 1;
2069 PutClientInServer();
2070 if(self.classname == "player")
2071 bprint ("^4", self.netname, "^4 is playing now\n");
2072 if(!cvar("g_campaign"))
2073 centerprint(self,""); // clear MOTD
2076 stuffcmd(self,"menu_showteamselect\n");
2081 //player may not join because of g_maxplayers is set
2082 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2087 * Determines whether the player is allowed to join. This depends on cvar
2088 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2089 * it checks whether the number of currently playing players exceeds g_maxplayers.
2090 * @return bool TRUE if the player is allowed to join, false otherwise
2092 float isJoinAllowed() {
2093 if (!cvar("g_maxplayers"))
2097 local float currentlyPlaying;
2098 FOR_EACH_REALPLAYER(e) {
2099 if(e.classname == "player")
2100 currentlyPlaying += 1;
2102 if(currentlyPlaying < cvar("g_maxplayers"))
2109 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2110 * g_maxplayers_spectator_blocktime seconds
2112 void checkSpectatorBlock() {
2113 if(self.classname == "spectator" || self.classname == "observer") {
2114 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2115 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2121 float vercmp_recursive(string v1, string v2)
2127 dot1 = strstrofs(v1, ".", 0);
2128 dot2 = strstrofs(v2, ".", 0);
2132 s1 = substring(v1, 0, dot1);
2136 s2 = substring(v2, 0, dot2);
2138 r = stof(s1) - stof(s2);
2142 r = strcasecmp(s1, s2);
2155 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2158 float vercmp(string v1, string v2)
2160 if(strcasecmp(v1, v2) == 0) // early out check
2162 return vercmp_recursive(v1, v2);
2165 void ObserverThink()
2167 if (self.flags & FL_JUMPRELEASED) {
2168 if (self.BUTTON_JUMP && !self.version_mismatch) {
2169 self.welcomemessage_time = 0;
2170 self.flags &~= FL_JUMPRELEASED;
2171 self.flags |= FL_SPAWNING;
2172 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2173 self.welcomemessage_time = 0;
2174 self.flags &~= FL_JUMPRELEASED;
2175 if(SpectateNext() == 1) {
2176 self.classname = "spectator";
2180 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2181 self.flags |= FL_JUMPRELEASED;
2182 if(self.flags & FL_SPAWNING)
2184 self.flags &~= FL_SPAWNING;
2185 LeaveSpectatorMode();
2190 PrintWelcomeMessage(self);
2193 void SpectatorThink()
2195 if (self.flags & FL_JUMPRELEASED) {
2196 if (self.BUTTON_JUMP && !self.version_mismatch) {
2197 self.welcomemessage_time = 0;
2198 self.flags &~= FL_JUMPRELEASED;
2199 self.flags |= FL_SPAWNING;
2200 } else if(self.BUTTON_ATCK) {
2201 self.welcomemessage_time = 0;
2202 self.flags &~= FL_JUMPRELEASED;
2203 if(SpectateNext() == 1) {
2204 self.classname = "spectator";
2206 self.classname = "observer";
2207 PutClientInServer();
2209 } else if (self.BUTTON_ATCK2) {
2210 self.welcomemessage_time = 0;
2211 self.flags &~= FL_JUMPRELEASED;
2212 self.classname = "observer";
2213 PutClientInServer();
2215 if(!SpectateUpdate())
2216 PutObserverInServer();
2219 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2220 self.flags |= FL_JUMPRELEASED;
2221 if(self.flags & FL_SPAWNING)
2223 self.flags &~= FL_SPAWNING;
2224 LeaveSpectatorMode();
2229 PrintWelcomeMessage(self);
2230 self.flags |= FL_CLIENT | FL_NOTARGET;
2233 .float touchexplode_time;
2239 Called every frame for each client before the physics are run
2242 void() ctf_setstatus;
2243 void() nexball_setstatus;
2245 void PlayerPreThink (void)
2247 self.stat_game_starttime = game_starttime;
2248 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2249 self.stat_leadlimit = cvar("leadlimit");
2251 if(blockSpectators && frametime)
2252 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2253 checkSpectatorBlock();
2257 if(self.netname_previous != self.netname)
2259 if(cvar("sv_eventlog"))
2260 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2261 if(self.netname_previous)
2262 strunzone(self.netname_previous);
2263 self.netname_previous = strzone(self.netname);
2267 if(self.version_nagtime)
2268 if(self.cvar_g_nexuizversion)
2269 if(time > self.version_nagtime)
2271 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2273 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2275 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2276 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), " (beta)^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2281 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2284 dprint("^1NOTE^7 to ", self.netname, "^7 - ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n");
2285 sprint(self, strcat("\{1}^1NOTE: ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7 is out, and you still have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1 - get the update from ^4http://www.nexuiz.com/^1!\n"));
2289 dprint("^1NOTE^7 to ", self.netname, "^7 - the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n");
2290 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2294 self.version_nagtime = 0;
2298 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2300 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2301 self.max_armorvalue = 0;
2305 antilag_record(self);
2307 if(self.classname == "player") {
2308 // if(self.netname == "Wazat")
2309 // bprint(self.classname, "\n");
2311 CheckRules_Player();
2313 PrintWelcomeMessage(self);
2315 if (intermission_running)
2317 IntermissionThink (); // otherwise a button could be missed between
2318 return; // the think tics
2321 if(self.teleport_time)
2322 if(time > self.teleport_time)
2324 self.teleport_time = 0;
2325 self.effects = self.effects - (self.effects & EF_NODRAW);
2328 Nixnex_GiveCurrentWeapon();
2330 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2331 UpdateSelectedPlayer();
2333 //don't allow the player to turn around while game is paused!
2334 if(timeoutStatus == 2) {
2335 self.v_angle = self.lastV_angle;
2336 self.angles = self.lastV_angle;
2337 self.fixangle = TRUE;
2343 if (self.deadflag != DEAD_NO)
2345 float button_pressed, force_respawn;
2348 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2349 force_respawn = (g_lms || cvar("g_forced_respawn"));
2350 if (self.deadflag == DEAD_DYING)
2353 self.deadflag = DEAD_RESPAWNING;
2354 else if(!button_pressed)
2355 self.deadflag = DEAD_DEAD;
2357 else if (self.deadflag == DEAD_DEAD)
2360 self.deadflag = DEAD_RESPAWNABLE;
2362 else if (self.deadflag == DEAD_RESPAWNABLE)
2365 self.deadflag = DEAD_RESPAWNING;
2367 else if (self.deadflag == DEAD_RESPAWNING)
2369 if(time > self.death_time)
2371 self.death_time = time + 1; // only retry once a second
2375 ShowRespawnCountdown();
2380 if(time > self.touchexplode_time)
2381 if(self.classname == "player")
2382 if(self.deadflag == DEAD_NO)
2383 if not(IS_INDEPENDENT_PLAYER(self))
2384 FOR_EACH_PLAYER(other) if(self != other)
2386 if(time > other.touchexplode_time)
2387 if(other.classname == "player")
2388 if(other.deadflag == DEAD_NO)
2389 if not(IS_INDEPENDENT_PLAYER(other))
2390 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2392 PlayerTouchExplode(self, other);
2393 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2397 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2401 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2402 dist = self.prevorigin - self.origin;
2404 self.lms_traveled_distance += fabs(vlen(dist));
2406 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2408 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2409 self.lms_traveled_distance = 0;
2412 if(time > self.lms_nextcheck)
2414 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2415 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2417 centerprint(self, cvar_string("g_lms_campcheck_message"));
2418 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2419 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2420 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');
2422 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2423 self.lms_traveled_distance = 0;
2427 self.prevorigin = self.origin;
2429 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2434 self.view_ofs = PL_CROUCH_VIEW_OFS;
2435 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2436 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2443 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2444 if (!trace_startsolid)
2446 self.crouch = FALSE;
2447 self.view_ofs = PL_VIEW_OFS;
2448 setsize (self, PL_MIN, PL_MAX);
2453 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2455 if(self.bloodloss_timer < time)
2457 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2458 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2464 GrapplingHookFrame();
2468 self.items &~= self.items_added;
2472 self.items_added = 0;
2473 if(self.items & IT_JETPACK)
2474 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2475 self.items_added |= IT_FUEL;
2477 self.items |= self.items_added;
2485 minstagib_ammocheck();
2489 nexball_setstatus();
2491 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2493 //self.angles_y=self.v_angle_y + 90; // temp
2495 //if (TetrisPreFrame()) return;
2496 } else if(gameover) {
2497 if (intermission_running)
2498 IntermissionThink (); // otherwise a button could be missed between
2500 } else if(self.classname == "observer") {
2502 } else if(self.classname == "spectator") {
2507 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2509 float oldspectatee_status;
2510 oldspectatee_status = self.spectatee_status;
2511 if(self.classname == "spectator")
2512 self.spectatee_status = num_for_edict(self.enemy);
2513 else if(self.classname == "observer")
2514 self.spectatee_status = num_for_edict(self);
2516 self.spectatee_status = 0;
2517 if(self.spectatee_status != oldspectatee_status)
2519 ClientData_Touch(self);
2521 race_InitSpectator();
2524 if(self.teamkill_soundtime)
2525 if(time > self.teamkill_soundtime)
2527 self.teamkill_soundtime = 0;
2529 entity oldpusher, oldself;
2531 oldself = self; self = self.teamkill_soundsource;
2532 oldpusher = self.pusher; self.pusher = oldself;
2534 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2536 self.pusher = oldpusher;
2540 if(self.taunt_soundtime)
2541 if(time > self.taunt_soundtime)
2543 self.taunt_soundtime = 0;
2544 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2547 target_voicescript_next(self);
2553 .float dragspeed; // speed of mouse wheel action
2554 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
2555 .vector draglocalvector; // local attachment vector of the dragentity
2556 .float draglocalangle;
2559 .float dragmovetype;
2560 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
2564 draggee.dragmovetype = draggee.movetype;
2565 draggee.draggravity = draggee.gravity;
2566 draggee.movetype = MOVETYPE_WALK;
2567 draggee.gravity = 0.00001;
2568 draggee.flags &~= FL_ONGROUND;
2569 draggee.draggedby = dragger;
2571 dragger.dragentity = draggee;
2573 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
2574 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
2575 touchpoint = touchpoint - gettaginfo(draggee, 0);
2576 tagscale = pow(vlen(v_forward), -2);
2577 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
2578 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
2579 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
2581 dragger.dragspeed = 64;
2584 void Drag_Finish(entity dragger)
2587 draggee = dragger.dragentity;
2589 dragger.dragentity = world;
2590 draggee.draggedby = world;
2591 draggee.movetype = draggee.dragmovetype;
2592 draggee.gravity = draggee.draggravity;
2594 switch(draggee.movetype)
2599 case MOVETYPE_FLYMISSILE:
2600 case MOVETYPE_BOUNCE:
2601 case MOVETYPE_BOUNCEMISSILE:
2604 draggee.velocity = '0 0 0';
2608 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
2610 draggee.velocity = '0 0 0';
2611 draggee.flags |= FL_ONGROUND; // floating items are FUN
2615 float Drag_IsDraggable(entity draggee)
2617 // TODO add more checks for bad stuff here
2618 if(draggee.classname == "func_bobbing")
2620 if(draggee.classname == "door") // FIXME find out why these must be excluded, or work around the problem (trying to drag these causes like 4 fps)
2622 if(draggee.classname == "plat")
2624 if(draggee.classname == "func_button")
2626 if(draggee.model == "")
2628 if(draggee.classname == "spectator")
2630 if(draggee.classname == "observer")
2632 if(draggee.classname == "exteriorweaponentity")
2638 float Drag_MayChangeAngles(entity draggee)
2640 // TODO add more checks for bad stuff here
2641 if(substring(draggee.model, 0, 1) == "*")
2646 void Drag_MoveForward(entity dragger)
2648 dragger.dragdistance += dragger.dragspeed;
2651 void Drag_SetSpeed(entity dragger, float s)
2653 dragger.dragspeed = pow(2, s);
2656 void Drag_MoveBackward(entity dragger)
2658 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
2661 void Drag_Update(entity dragger)
2663 vector curorigin, neworigin, goodvelocity;
2667 draggee = dragger.dragentity;
2668 draggee.flags &~= FL_ONGROUND;
2670 curorigin = gettaginfo(draggee, 0);
2671 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
2672 makevectors(dragger.v_angle);
2673 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
2674 goodvelocity = (neworigin - curorigin) * (1 / frametime);
2676 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
2677 dragger.draglocalangle += 360;
2678 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
2679 dragger.draglocalangle -= 360;
2681 f = min(frametime * 10, 1);
2682 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
2684 if(Drag_MayChangeAngles(draggee))
2685 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
2687 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
2689 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
2692 float Drag_CanDrag(entity dragger)
2694 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
2697 float Drag_IsDragging(entity dragger)
2699 if(!dragger.dragentity)
2701 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
2703 dragger.dragentity = world;
2706 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
2708 Drag_Finish(dragger);
2714 void Drag_MoveDrag(entity from, entity to)
2718 to.draggedby = from.draggedby;
2719 to.draggedby.dragentity = to;
2720 from.draggedby = world;
2728 Called every frame for each client after the physics are run
2731 .float idlekick_lasttimeleft;
2732 .float race_penalty;
2733 .float race_penalty_nagged;
2734 .float race_penalty_nagtime;
2735 void PlayerPostThink (void)
2737 // Savage: Check for nameless players
2738 if (strlen(self.netname) < 1) {
2739 self.netname = "Player";
2740 stuffcmd(self, "seta _cl_name Player\n");
2743 if(sv_maxidle && frametime)
2745 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2747 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2750 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2751 announce(self, "announcer/robotic/terminated.wav");
2755 else if(timeleft <= 10)
2757 if(timeleft != self.idlekick_lasttimeleft)
2759 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2760 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2765 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2767 self.idlekick_lasttimeleft = timeleft;
2770 if(sv_cheats || self.maycheat)
2771 if(Drag_CanDrag(self))
2772 if(self.BUTTON_DRAG)
2773 if(!self.dragentity)
2774 if(self.cursor_trace_ent)
2775 if(Drag_IsDraggable(self.cursor_trace_ent))
2777 if(self.cursor_trace_ent.draggedby)
2778 Drag_Finish(self.cursor_trace_ent.draggedby);
2779 if(self.cursor_trace_ent.tag_entity)
2780 detach_sameorigin(self.cursor_trace_ent);
2781 Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
2784 if(Drag_IsDragging(self))
2786 if(self.BUTTON_DRAG)
2788 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
2790 Drag_MoveForward(self);
2793 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
2795 Drag_MoveBackward(self);
2798 else if(self.impulse >= 1 && self.impulse <= 9)
2800 Drag_SetSpeed(self, self.impulse - 1);
2802 else if(self.impulse == 14)
2804 Drag_SetSpeed(self, 9);
2816 if(self.classname == "player") {
2817 CheckRules_Player();
2822 if (intermission_running)
2823 return; // intermission or finale
2825 //if (TetrisPostFrame()) return;
2827 // restart countdown
2828 if(time < game_starttime) {
2829 if (!cvar("sv_ready_restart_after_countdown"))
2831 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2833 if(time < game_starttime - 2)
2835 if(!self.race_penalty_nagged)
2837 // TODO better notification for this!
2838 self.race_penalty_nagtime = 0;
2839 self.race_penalty_nagged = 1;
2842 else if(!self.race_penalty)
2844 self.race_penalty_nagtime = 0;
2845 self.race_penalty = time + 5;
2848 if(time > self.race_penalty_nagtime)
2850 if(self.race_penalty > time)
2852 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2854 else if(self.race_penalty_nagged && time < game_starttime - 2)
2856 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2858 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2860 self.movetype = MOVETYPE_NONE;
2861 self.velocity = '0 0 0';
2862 self.avelocity = '0 0 0';
2863 self.movement = '0 0 0';
2866 else if (time < self.race_penalty)
2868 self.movetype = MOVETYPE_NONE;
2869 self.velocity = '0 0 0';
2870 self.avelocity = '0 0 0';
2871 self.movement = '0 0 0';
2875 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2876 if (!cvar("sv_ready_restart_after_countdown"))
2878 if(self.movetype == MOVETYPE_NONE)
2880 self.movetype = MOVETYPE_WALK;
2882 self.race_penalty = 0;
2883 self.race_penalty_nagged = 0;
2887 } else if (self.classname == "observer") {
2889 } else if (self.classname == "spectator") {
2895 for(i = 0; i < 1000; ++i)
2898 end = self.origin + '0 0 1024' + 512 * randomvec();
2899 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2900 if(trace_fraction < 1)
2901 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2903 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2911 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);