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,-4,4) != ".zym")
373 if(substring(plyermodel,-4,4) != ".dpm")
374 if(substring(plyermodel,-4,4) != ".md3")
375 if(substring(plyermodel,-4,4) != ".psk")
376 return FallbackPlayerModel;
377 // forbid the LOD models
378 if(substring(plyermodel, -9,5) == "_lod1")
379 return FallbackPlayerModel;
380 if(substring(plyermodel, -9,5) == "_lod2")
381 return FallbackPlayerModel;
382 if(plyermodel != strtolower(plyermodel))
383 return FallbackPlayerModel;
384 if(!fexists(plyermodel))
385 return FallbackPlayerModel;
392 Client_customizeentityforclient
397 void Client_uncustomizeentityforclient()
399 if(self.modelindex == 0) // no need to uncustomize then
401 self.modelindex = self.modelindex_lod0;
402 self.skin = self.skinindex;
405 float Client_customizeentityforclient()
409 if(self.modelindex == 0)
416 t0 = gettime(GETTIME_HIRES); // reference
421 #ifdef ALLOW_FORCEMODELS
422 if(other.cvar_cl_forceplayermodelsfromnexuiz)
423 if not(self.modelindex_lod0_from_nexuiz)
425 if(other.cvar_cl_forceplayermodels && sv_clforceplayermodels)
429 self.skin = modelsource.skinindex;
432 if(modelsource == self)
433 self.skin = modelsource.skinindex;
435 self.skin = mod(modelsource.skinindex, 3); // forbid the fbskins as forced skins
439 // other: the player viewing me
443 if(other.cvar_cl_playerdetailreduction <= 0)
445 if(other.cvar_cl_playerdetailreduction <= -2)
446 self.modelindex = modelsource.modelindex_lod2;
447 else if(other.cvar_cl_playerdetailreduction <= -1)
448 self.modelindex = modelsource.modelindex_lod1;
450 self.modelindex = modelsource.modelindex_lod0;
454 distance = vlen(self.origin - other.origin);
455 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
456 if(f > sv_loddistance2)
457 self.modelindex = modelsource.modelindex_lod2;
458 else if(f > sv_loddistance1)
459 self.modelindex = modelsource.modelindex_lod1;
461 self.modelindex = modelsource.modelindex_lod0;
466 t1 = gettime(GETTIME_HIRES); // reference
467 client_cefc_accumulator += (t1 - t0);
473 void UpdatePlayerSounds();
474 void setmodel_lod(entity e, string modelname)
480 // FIXME: this only supports 3-letter extensions
481 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod1", substring(modelname, -4, 4));
484 setmodel(e, s); // players have high precision
485 self.modelindex_lod1 = self.modelindex;
488 self.modelindex_lod1 = -1;
490 s = strcat(substring(modelname, 0, strlen(modelname)-4), "_lod2", substring(modelname, -4, 4));
493 setmodel(e, s); // players have high precision
494 self.modelindex_lod2 = self.modelindex;
497 self.modelindex_lod2 = -1;
499 precache_model(modelname);
500 setmodel(e, modelname); // players have high precision
501 self.modelindex_lod0 = self.modelindex;
503 if(self.modelindex_lod1 < 0)
504 self.modelindex_lod1 = self.modelindex;
506 if(self.modelindex_lod2 < 0)
507 self.modelindex_lod2 = self.modelindex;
511 precache_model(modelname);
512 setmodel(e, modelname); // players have high precision
513 self.modelindex_lod0 = self.modelindex;
514 // save it for possible player model forcing
517 s = whichpack(self.model);
518 self.modelindex_lod0_from_nexuiz = ((s == "") || (substring(s, 0, 4) == "data"));
520 player_setupanimsformodel();
521 UpdatePlayerSounds();
528 putting a client as observer in the server
531 void FixPlayermodel();
532 void PutObserverInServer (void)
536 race_PreSpawnObserver();
538 spot = SelectSpawnPoint (TRUE);
540 error("No spawnpoints for observers?!?\n");
541 RemoveGrapplingHook(self); // Wazat's Grappling Hook
543 if(clienttype(self) == CLIENTTYPE_REAL)
546 WriteByte(MSG_ONE, SVC_SETVIEW);
547 WriteEntity(MSG_ONE, self);
551 kh_Key_DropAll(self, TRUE);
553 Portal_ClearAll(self);
556 DropFlag(self.flagcarried, world, world);
558 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
560 WaypointSprite_PlayerDead();
562 if(self.killcount != -666)
566 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
567 bprint ("^4", self.netname, "^4 has no more lives left\n");
569 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
572 bprint ("^4", self.netname, "^4 is spectating now\n");
575 PlayerScore_Clear(self); // clear scores when needed
577 self.spectatortime = time;
579 self.classname = "observer";
580 self.iscreature = FALSE;
582 self.takedamage = DAMAGE_NO;
583 self.solid = SOLID_NOT;
584 self.movetype = MOVETYPE_NOCLIP;
585 self.flags = FL_CLIENT | FL_NOTARGET;
586 self.armorvalue = 666;
588 self.armorvalue = cvar("g_balance_armor_start");
589 self.pauserotarmor_finished = 0;
590 self.pauserothealth_finished = 0;
591 self.pauseregen_finished = 0;
592 self.damageforcescale = 0;
599 self.pain_finished = 0;
600 self.strength_finished = 0;
601 self.invincible_finished = 0;
603 self.think = SUB_Null;
607 self.deadflag = DEAD_NO;
608 self.angles = spot.angles;
610 self.fixangle = TRUE;
613 self.view_ofs = PL_VIEW_OFS;
614 setorigin (self, spot.origin);
615 setsize (self, '0 0 0', '0 0 0');
616 self.prevorigin = self.origin;
624 self.weaponmodel = "";
625 self.weaponentity = world;
626 self.exteriorweaponentity = world;
627 self.killcount = -666;
628 self.velocity = '0 0 0';
629 self.avelocity = '0 0 0';
630 self.punchangle = '0 0 0';
631 self.punchvector = '0 0 0';
632 self.oldvelocity = self.velocity;
635 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
641 if(self.version_mismatch)
643 Spawnqueue_Unmark(self);
644 Spawnqueue_Remove(self);
648 Spawnqueue_Insert(self);
653 // Only if the player cannot play at all
654 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
655 self.frags = FRAGS_SPECTATOR;
657 self.frags = FRAGS_LMS_LOSER;
660 self.frags = FRAGS_SPECTATOR;
663 float RestrictSkin(float s)
672 void FixPlayermodel()
674 local string defaultmodel;
675 local float defaultskin, chmdl, oldskin;
680 if(cvar("sv_defaultcharacter") == 1) {
685 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
686 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
689 if(defaultmodel == "")
691 defaultmodel = cvar_string("sv_defaultplayermodel");
692 defaultskin = cvar("sv_defaultplayerskin");
696 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
699 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
700 self.model = ""; // force the != checks to return true
703 if(defaultmodel != "")
705 if (defaultmodel != self.model)
709 setmodel_lod (self, defaultmodel);
710 setsize (self, m1, m2);
714 oldskin = self.skinindex;
715 self.skinindex = defaultskin;
717 if (self.playermodel != self.model)
719 self.playermodel = CheckPlayerModel(self.playermodel);
722 setmodel_lod (self, self.playermodel);
723 setsize (self, m1, m2);
727 oldskin = self.skinindex;
728 self.skinindex = RestrictSkin(stof(self.playerskin));
731 if(chmdl || oldskin != self.skinindex)
732 self.species = player_getspecies(); // model or skin has changed
735 if(strlen(cvar_string("sv_defaultplayercolors")))
736 if(self.clientcolors != cvar("sv_defaultplayercolors"))
737 setcolor(self, cvar("sv_defaultplayercolors"));
740 void PlayerTouchExplode(entity p1, entity p2)
743 org = (p1.origin + p2.origin) * 0.5;
744 org_z += (p1.mins_z + p2.mins_z) * 0.5;
751 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
759 Called when a client spawns in the server
762 //void() ctf_playerchanged;
763 void PutClientInServer (void)
765 if(clienttype(self) == CLIENTTYPE_BOT)
767 self.classname = "player";
769 else if(clienttype(self) == CLIENTTYPE_REAL)
772 WriteByte(MSG_ONE, SVC_SETVIEW);
773 WriteEntity(MSG_ONE, self);
776 // player is dead and becomes observer
777 // FIXME fix LMS scoring for new system
780 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
781 self.classname = "observer";
786 self.classname = "observer";
788 if(self.classname == "player") {
789 entity spot, oldself;
792 JoinBestTeam(self, FALSE, TRUE);
796 spot = SelectSpawnPoint (FALSE);
799 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
800 return; // spawn failed
803 RemoveGrapplingHook(self); // Wazat's Grappling Hook
804 self.campingrifle_bulletcounter = cvar("g_balance_campingrifle_magazinecapacity");
806 self.classname = "player";
807 self.wasplayer = TRUE;
808 self.iscreature = TRUE;
809 self.movetype = MOVETYPE_WALK;
810 self.solid = SOLID_SLIDEBOX;
811 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
812 self.frags = FRAGS_PLAYER;
813 if(independent_players)
814 MAKE_INDEPENDENT_PLAYER(self);
815 self.flags = FL_CLIENT;
816 self.takedamage = DAMAGE_AIM;
818 self.effects = EF_FULLBRIGHT;
821 self.air_finished = time + 12;
826 self.ammo_shells = warmup_start_ammo_shells;
827 self.ammo_nails = warmup_start_ammo_nails;
828 self.ammo_rockets = warmup_start_ammo_rockets;
829 self.ammo_cells = warmup_start_ammo_cells;
830 self.ammo_fuel = warmup_start_ammo_fuel;
831 self.health = warmup_start_health;
832 self.armorvalue = warmup_start_armorvalue;
833 self.weapons = warmup_start_weapons;
837 self.ammo_shells = start_ammo_shells;
838 self.ammo_nails = start_ammo_nails;
839 self.ammo_rockets = start_ammo_rockets;
840 self.ammo_cells = start_ammo_cells;
841 self.ammo_fuel = start_ammo_fuel;
842 self.health = start_health;
843 self.armorvalue = start_armorvalue;
844 self.weapons = start_weapons;
846 self.items = start_items;
847 self.switchweapon = w_getbestweapon(self);
848 self.cnt = self.switchweapon;
850 self.jump_interval = time;
852 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
853 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
854 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
855 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
856 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
857 //extend the pause of rotting if client was reset at the beginning of the countdown
858 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
859 self.spawnshieldtime += game_starttime - time;
860 self.pauserotarmor_finished += game_starttime - time;
861 self.pauserothealth_finished += game_starttime - time;
862 self.pauseregen_finished += game_starttime - time;
864 self.damageforcescale = 2;
871 self.pain_finished = 0;
872 self.strength_finished = 0;
873 self.invincible_finished = 0;
875 //self.speed_finished = 0;
876 //self.slowmo_finished = 0;
877 // players have no think function
878 self.think = SUB_Null;
887 self.deadflag = DEAD_NO;
889 self.angles = spot.angles;
891 self.angles_z = 0; // never spawn tilted even if the spot says to
892 self.fixangle = TRUE; // turn this way immediately
893 self.velocity = '0 0 0';
894 self.avelocity = '0 0 0';
895 self.punchangle = '0 0 0';
896 self.punchvector = '0 0 0';
897 self.oldvelocity = self.velocity;
900 WRITESPECTATABLE_MSG_ONE({
901 WriteByte(MSG_ONE, SVC_TEMPENTITY);
902 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
906 SetCustomizer(self, Client_customizeentityforclient, Client_uncustomizeentityforclient);
912 self.view_ofs = PL_VIEW_OFS;
913 setsize (self, PL_MIN, PL_MAX);
914 self.spawnorigin = spot.origin;
915 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
916 // don't reset back to last position, even if new position is stuck in solid
917 self.oldorigin = self.origin;
918 self.prevorigin = self.origin;
919 self.lastrocket = world; // stop rocket guiding, no revenge from the grave!
923 Spawnqueue_Remove(self);
924 Spawnqueue_Mark(self);
927 self.event_damage = PlayerDamage;
929 self.bot_attack = TRUE;
931 self.statdraintime = time + 5;
932 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
934 if(self.killcount == -666) {
935 PlayerScore_Clear(self);
939 self.cnt = WEP_LASER;
940 self.nixnex_lastchange_id = -1;
942 CL_SpawnWeaponentity();
943 self.alpha = default_player_alpha;
944 self.colormod = '1 1 1' * cvar("g_player_brightness");
945 self.exteriorweaponentity.alpha = default_weapon_alpha;
947 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
948 self.lms_traveled_distance = 0;
949 self.speedrunning = FALSE;
951 race_PostSpawn(spot);
953 if(cvar("spawn_debug"))
955 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
956 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
959 //stuffcmd(self, "chase_active 0");
960 //stuffcmd(self, "set viewsize $tmpviewsize \n");
962 if (cvar("g_spawnsound"))
963 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
966 if(self.team == assault_attacker_team)
967 centerprint(self, "You are attacking!");
969 centerprint(self, "You are defending!");
972 target_voicescript_clear(self);
981 } else if(self.classname == "observer") {
982 PutObserverInServer ();
986 // ctf_playerchanged();
989 float ClientInit_SendEntity(entity to, float sf)
992 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
993 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
994 for(i = 1; i <= 24; ++i)
995 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
996 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
997 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
998 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
1000 if(sv_foginterval && world.fog != "")
1001 WriteString(MSG_ENTITY, world.fog);
1003 WriteString(MSG_ENTITY, "");
1004 WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);
1008 void ClientInit_Spawn()
1010 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
1018 void SetNewParms (void)
1020 // initialize parms for a new player
1021 parm1 = -(86400 * 366);
1029 void SetChangeParms (void)
1031 // save parms for level change
1032 parm1 = self.parm_idlesince - time;
1040 void DecodeLevelParms (void)
1043 self.parm_idlesince = parm1;
1044 if(self.parm_idlesince == -(86400 * 366))
1045 self.parm_idlesince = time;
1047 // whatever happens, allow 60 seconds of idling directly after connect for map loading
1048 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
1055 Called when a client types 'kill' in the console
1059 void ClientKill_Now_TeamChange()
1061 if(self.killindicator_teamchange == -1)
1064 JoinBestTeam( self, FALSE, FALSE );
1067 SV_ChangeTeam(self.killindicator_teamchange - 1);
1070 void ClientKill_Now()
1072 if(self.killindicator_teamchange)
1073 ClientKill_Now_TeamChange();
1076 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1078 if(self.killindicator)
1080 dprint("Cleaned up after a leaked kill indicator.\n");
1081 remove(self.killindicator);
1082 self.killindicator = world;
1085 void KillIndicator_Think()
1087 if (!self.owner.modelindex)
1089 self.owner.killindicator = world;
1097 ClientKill_Now(); // no oldself needed
1103 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1104 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1107 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1108 if(self.owner.killindicator_teamchange)
1110 if(self.owner.killindicator_teamchange == -1)
1111 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1113 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1116 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1118 self.nextthink = time + 1;
1123 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1127 killtime = cvar("g_balance_kill_delay");
1129 if(g_race_qualifying)
1132 self.killindicator_teamchange = targetteam;
1134 if(!self.killindicator)
1136 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1142 self.killindicator = spawn();
1143 self.killindicator.owner = self;
1144 self.killindicator.scale = 0.5;
1145 setattachment(self.killindicator, self, "");
1146 setorigin(self.killindicator, '0 0 52');
1147 self.killindicator.think = KillIndicator_Think;
1148 self.killindicator.nextthink = time + (self.lip) * 0.05;
1149 self.killindicator.cnt = ceil(killtime);
1150 self.killindicator.count = bound(0, ceil(killtime), 10);
1151 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1153 for(e = world; (e = find(e, classname, "body")) != world; )
1157 e.killindicator = spawn();
1158 e.killindicator.owner = e;
1159 e.killindicator.scale = 0.5;
1160 setattachment(e.killindicator, e, "");
1161 setorigin(e.killindicator, '0 0 52');
1162 e.killindicator.think = KillIndicator_Think;
1163 e.killindicator.nextthink = time + (e.lip) * 0.05;
1164 e.killindicator.cnt = ceil(killtime);
1169 if(self.killindicator)
1172 self.killindicator.colormod = TeamColor(targetteam);
1174 self.killindicator.colormod = '0 0 0';
1178 void ClientKill (void)
1180 ClientKill_TeamChange(0);
1183 void DoTeamChange(float destteam)
1189 SetPlayerColors(self, destteam);
1192 if(self.classname == "player")
1195 CheckAllowedTeams(self);
1196 t = FindSmallestTeam(self, TRUE);
1199 case COLOR_TEAM1: c0 = c1; break;
1200 case COLOR_TEAM2: c0 = c2; break;
1201 case COLOR_TEAM3: c0 = c3; break;
1202 case COLOR_TEAM4: c0 = c4; break;
1209 destteam = COLOR_TEAM1;
1213 destteam = COLOR_TEAM2;
1217 destteam = COLOR_TEAM3;
1221 destteam = COLOR_TEAM4;
1227 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1229 ClientKill_TeamChange(destteam);
1232 void FixClientCvars(entity e)
1234 // send prediction settings to the client
1235 stuffcmd(e, "\nin_bindmap 0 0\n");
1237 * we no longer need to stuff this. Remove this comment block if you feel
1238 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1239 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1240 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1241 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1242 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1243 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1244 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1245 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1246 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1247 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1248 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1249 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1250 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1251 stuffcmd(e, "cl_movement_edgefriction 1\n");
1259 Called when a client connects to the server
1262 //void ctf_clientconnect();
1263 string ColoredTeamName(float t);
1264 void DecodeLevelParms (void);
1265 //void dom_player_join_team(entity pl);
1266 void ClientConnect (void)
1271 if(self.flags & FL_CLIENT)
1273 print("Warning: ClientConnect, but already connected!\n");
1277 if(Ban_MaybeEnforceBan(self))
1282 self.classname = "player_joining";
1284 self.flags = FL_CLIENT;
1285 self.version_nagtime = time + 10 + random() * 10;
1289 dprint("BUG player count is lower than zero, this cannot happen!\n");
1293 PlayerScore_Attach(self);
1294 ClientData_Attach();
1296 bot_clientconnect();
1298 race_PreSpawnObserver();
1301 // dom_player_join_team(self);
1303 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1305 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1306 self.classname = "observer";
1310 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1312 self.classname = "player";
1313 campaign_bots_may_start = 1;
1317 self.classname = "observer"; // do it anyway
1322 self.classname = "player";
1323 campaign_bots_may_start = 1;
1327 self.playerid = (playerid_last = playerid_last + 1);
1328 if(cvar("sv_eventlog"))
1330 if(clienttype(self) == CLIENTTYPE_REAL)
1331 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1333 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1334 s = strcat(":team:", ftos(self.playerid), ":");
1335 s = strcat(s, ftos(self.team));
1338 self.netname_previous = strzone(self.netname);
1340 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1342 bprint ("^4",self.netname);
1343 bprint ("^4 connected");
1345 if(g_domination || g_ctf)
1347 bprint(" and joined the ");
1348 bprint(ColoredTeamName(self.team));
1353 self.welcomemessage_time = 0;
1355 stuffcmd(self, strcat(clientstuff, "\n"));
1356 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1357 stuffcmd(self, "cl_particles_reloadeffects\n");
1359 FixClientCvars(self);
1361 // spawnfunc_waypoint sprites
1362 WaypointSprite_InitClient(self);
1364 // Wazat's grappling hook
1365 SetGrappleHookBindings();
1367 // get autoswitch state from player when he toggles it
1368 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1370 // get version info from player
1371 stuffcmd(self, "cmd clientversion $gameversion\n");
1373 // get other cvars from player
1376 // set cvar for team scoreboard
1377 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1379 // notify about available teams
1382 CheckAllowedTeams(self);
1383 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1384 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1387 stuffcmd(self, "set _teams_available 0\n");
1389 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1393 self.classname = "observer";
1394 Spawnqueue_Insert(self);
1398 ctf_clientconnect();
1401 if(teams_matter || sv_cheats)
1404 bot_relinkplayerlist();
1406 self.spectatortime = time;
1409 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"));
1412 self.jointime = time;
1413 self.allowedTimeouts = cvar("sv_timeout_number");
1415 if(clienttype(self) == CLIENTTYPE_REAL)
1417 if(cvar("g_bugrigs") || g_weaponarena == WEPBIT_TUBA)
1418 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1423 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1425 PlayerScore_Add(self, SP_LMS_RANK, 666);
1426 self.frags = FRAGS_SPECTATOR;
1430 if(!sv_foginterval && world.fog != "")
1431 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1433 SoundEntity_Attach(self);
1435 if(cvar("g_hitplots"))
1437 self.hitplotfh = fopen(strcat("hits-", matchid, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1438 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1441 self.hitplotfh = -1;
1448 Called when a client disconnects from the server
1451 .entity chatbubbleentity;
1452 .entity teambubbleentity;
1454 void ClientDisconnect (void)
1456 if not(self.flags & FL_CLIENT)
1458 print("Warning: ClientDisconnect without ClientConnect\n");
1462 if(self.hitplotfh >= 0)
1464 fclose(self.hitplotfh);
1465 self.hitplotfh = -1;
1468 bot_clientdisconnect();
1473 if(cvar("sv_eventlog"))
1474 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1475 bprint ("^4",self.netname);
1476 bprint ("^4 disconnected\n");
1478 SoundEntity_Detach(self);
1481 kh_Key_DropAll(self, TRUE);
1483 Portal_ClearAll(self);
1485 if(self.flagcarried)
1486 DropFlag(self.flagcarried, world, world);
1487 if(self.ballcarried)
1488 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1490 // Here, everything has been done that requires this player to be a client.
1492 self.flags &~= FL_CLIENT;
1494 if (self.chatbubbleentity)
1495 remove (self.chatbubbleentity);
1497 if (self.teambubbleentity)
1498 remove (self.teambubbleentity);
1500 if (self.killindicator)
1501 remove (self.killindicator);
1503 WaypointSprite_PlayerGone();
1505 bot_relinkplayerlist();
1508 if(self.weaponentity)
1509 if(self.weaponentity.lasertarget)
1510 remove(self.weaponentity.lasertarget);
1514 Spawnqueue_Unmark(self);
1515 Spawnqueue_Remove(self);
1518 ClientData_Detach();
1519 PlayerScore_Detach(self);
1521 if(self.netname_previous)
1522 strunzone(self.netname_previous);
1523 if(self.clientstatus)
1524 strunzone(self.clientstatus);
1526 ClearPlayerSounds();
1536 void ChatBubbleThink()
1538 self.nextthink = time;
1539 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1541 if(self.owner) // but why can that ever be world?
1542 self.owner.chatbubbleentity = world;
1546 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1547 self.model = self.mdl;
1552 void UpdateChatBubble()
1554 if (!self.modelindex)
1556 // spawn a chatbubble entity if needed
1557 if (!self.chatbubbleentity)
1559 self.chatbubbleentity = spawn();
1560 self.chatbubbleentity.owner = self;
1561 self.chatbubbleentity.exteriormodeltoclient = self;
1562 self.chatbubbleentity.think = ChatBubbleThink;
1563 self.chatbubbleentity.nextthink = time;
1564 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1565 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1566 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1567 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1568 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1569 self.chatbubbleentity.model = "";
1570 self.chatbubbleentity.effects = EF_LOWPRECISION;
1575 void TeamBubbleThink()
1577 self.nextthink = time;
1578 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1580 if(self.owner) // but why can that ever be world?
1581 self.owner.teambubbleentity = world;
1585 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1586 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1589 self.model = self.mdl;
1593 float TeamBubble_customizeentityforclient()
1595 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1598 void UpdateTeamBubble()
1600 if (!self.modelindex || !teams_matter)
1602 // spawn a teambubble entity if needed
1603 if (!self.teambubbleentity && teams_matter)
1605 self.teambubbleentity = spawn();
1606 self.teambubbleentity.owner = self;
1607 self.teambubbleentity.exteriormodeltoclient = self;
1608 self.teambubbleentity.think = TeamBubbleThink;
1609 self.teambubbleentity.nextthink = time;
1610 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1611 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1612 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1613 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1614 self.teambubbleentity.mdl = self.teambubbleentity.model;
1615 self.teambubbleentity.model = self.teambubbleentity.mdl;
1616 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1617 self.teambubbleentity.effects = EF_LOWPRECISION;
1621 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1622 // added to the model skins
1623 /*void UpdateColorModHack()
1626 c = self.clientcolors & 15;
1627 // LordHavoc: only bothering to support white, green, red, yellow, blue
1628 if (!teams_matter) self.colormod = '0 0 0';
1629 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1630 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1631 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1632 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1633 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1634 else self.colormod = '1 1 1';
1640 self.effects |= EF_NODRAW; // prevent another CopyBody
1641 PutClientInServer();
1644 void play_countdown(float finished, string samp)
1646 if(clienttype(self) == CLIENTTYPE_REAL)
1647 if(floor(finished - time - frametime) != floor(finished - time))
1648 if(finished - time < 6)
1649 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1653 * When sv_timeout is used this function returs strings like
1654 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1655 * Called by centerprint functions
1656 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1658 string getTimeoutText(float addOneSecond) {
1659 if (!cvar("sv_timeout") || !timeoutStatus)
1662 local string retStr;
1663 if (timeoutStatus == 1) {
1664 if (addOneSecond == 1) {
1665 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1668 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1672 else if (timeoutStatus == 2) {
1674 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1675 //don't show messages like "Timeout ends in 0 seconds"...
1676 if ((remainingTimeoutTime + 1) > 0)
1682 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1683 //don't show messages like "Timeout ends in 0 seconds"...
1684 if (remainingTimeoutTime > 0)
1693 void player_powerups (void)
1695 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1697 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, cvar("g_jetpack_attenuation"));
1698 self.modelflags |= MF_ROCKET;
1702 SoundEntity_StopSound(self, CHAN_PLAYER);
1703 self.modelflags &~= MF_ROCKET;
1706 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1708 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1713 self.effects |= EF_FULLBRIGHT;
1715 if (self.items & IT_STRENGTH)
1717 play_countdown(self.strength_finished, "misc/poweroff.wav");
1718 if (time > self.strength_finished)
1720 self.alpha = default_player_alpha;
1721 self.exteriorweaponentity.alpha = default_weapon_alpha;
1722 self.items &~= IT_STRENGTH;
1723 sprint(self, "^3Invisibility has worn off\n");
1728 if (time < self.strength_finished)
1730 self.alpha = g_minstagib_invis_alpha;
1731 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1732 self.items |= IT_STRENGTH;
1733 sprint(self, "^3You are invisible\n");
1737 if (self.items & IT_INVINCIBLE)
1739 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1740 if (time > self.invincible_finished)
1742 self.items = self.items - (self.items & IT_INVINCIBLE);
1743 sprint(self, "^3Speed has worn off\n");
1748 if (time < self.invincible_finished)
1750 self.items = self.items | IT_INVINCIBLE;
1751 sprint(self, "^3You are on speed\n");
1757 if (self.items & IT_STRENGTH)
1759 play_countdown(self.strength_finished, "misc/poweroff.wav");
1760 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1761 if (time > self.strength_finished)
1763 self.items = self.items - (self.items & IT_STRENGTH);
1764 sprint(self, "^3Strength has worn off\n");
1769 if (time < self.strength_finished)
1771 self.items = self.items | IT_STRENGTH;
1772 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1775 if (self.items & IT_INVINCIBLE)
1777 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1778 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1779 if (time > self.invincible_finished)
1781 self.items = self.items - (self.items & IT_INVINCIBLE);
1782 sprint(self, "^3Shield has worn off\n");
1787 if (time < self.invincible_finished)
1789 self.items = self.items | IT_INVINCIBLE;
1790 sprint(self, "^3Shield surrounds you\n");
1794 if (cvar("g_fullbrightplayers"))
1795 self.effects = self.effects | EF_FULLBRIGHT;
1797 // midair gamemode: damage only while in the air
1798 // if in midair mode, being on ground grants temporary invulnerability
1799 // (this is so that multishot weapon don't clear the ground flag on the
1800 // first damage in the frame, leaving the player vulnerable to the
1801 // remaining hits in the same frame)
1802 if (self.flags & FL_ONGROUND)
1804 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1806 if (time >= game_starttime)
1807 if (time < self.spawnshieldtime)
1808 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1811 float CalcRegen(float current, float stable, float regenfactor, float regenframetime)
1813 if(current > stable)
1815 else if(current > stable - 0.25) // when close enough, "snap"
1818 return min(stable, current + (stable - current) * regenfactor * regenframetime);
1821 float CalcRot(float current, float stable, float rotfactor, float rotframetime)
1823 if(current < stable)
1825 else if(current < stable + 0.25) // when close enough, "snap"
1828 return max(stable, current + (stable - current) * rotfactor * rotframetime);
1831 float CalcRotRegen(float current, float regenstable, float regenfactor, float regenlinear, float regenframetime, float rotstable, float rotfactor, float rotlinear, float rotframetime, float limit)
1833 if(current > rotstable)
1835 if(rotframetime > 0)
1837 current = CalcRot(current, rotstable, rotfactor, rotframetime);
1838 current = max(rotstable, current - rotlinear * rotframetime);
1841 else if(current < regenstable)
1843 if(regenframetime > 0)
1845 current = CalcRegen(current, regenstable, regenfactor, regenframetime);
1846 current = min(regenstable, current + regenlinear * regenframetime);
1856 void player_regen (void)
1858 float minh, mina, minf, maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1859 maxh = cvar("g_balance_health_rotstable");
1860 maxa = cvar("g_balance_armor_rotstable");
1861 maxf = cvar("g_balance_fuel_rotstable");
1862 minh = cvar("g_balance_health_regenstable");
1863 mina = cvar("g_balance_armor_regenstable");
1864 minf = cvar("g_balance_fuel_regenstable");
1865 limith = cvar("g_balance_health_limit");
1866 limita = cvar("g_balance_armor_limit");
1867 limitf = cvar("g_balance_fuel_limit");
1869 max_mod = regen_mod = rot_mod = limit_mod = 1;
1871 if (self.runes & RUNE_REGEN)
1873 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1875 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1876 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1877 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1881 regen_mod = cvar("g_balance_rune_regen_regenrate");
1882 max_mod = cvar("g_balance_rune_regen_hpmod");
1883 limit_mod = cvar("g_balance_rune_regen_limitmod");
1886 else if (self.runes & CURSE_VENOM)
1888 max_mod = cvar("g_balance_curse_venom_hpmod");
1889 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1890 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1892 rot_mod = cvar("g_balance_curse_venom_rotrate");
1893 limit_mod = cvar("g_balance_curse_venom_limitmod");
1894 //if (!self.runes & RUNE_REGEN)
1895 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1897 maxh = maxh * max_mod;
1898 //maxa = maxa * max_mod;
1899 //maxf = maxf * max_mod;
1900 minh = minh * max_mod;
1901 //mina = mina * max_mod;
1902 //minf = minf * max_mod;
1903 limith = limith * limit_mod;
1904 limita = limita * limit_mod;
1905 //limitf = limitf * limit_mod;
1910 if (!g_minstagib && (!g_lms || cvar("g_lms_regenerate")))
1912 self.armorvalue = CalcRotRegen(self.armorvalue, mina, cvar("g_balance_armor_regen"), cvar("g_balance_armor_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxa, cvar("g_balance_armor_rot"), cvar("g_balance_armor_rotlinear"), rot_mod * frametime * (time > self.pauserotarmor_finished), limita);
1913 self.health = CalcRotRegen(self.health, minh, cvar("g_balance_health_regen"), cvar("g_balance_health_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished), maxh, cvar("g_balance_health_rot"), cvar("g_balance_health_rotlinear"), rot_mod * frametime * (time > self.pauserothealth_finished), limith);
1915 // if player rotted to death... die!
1917 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1920 self.ammo_fuel = CalcRotRegen(self.ammo_fuel, minf, cvar("g_balance_fuel_regen"), cvar("g_balance_fuel_regenlinear"), regen_mod * frametime * (time > self.pauseregen_finished) * (self.items & IT_FUEL_REGEN != 0), maxf, cvar("g_balance_fuel_rot"), cvar("g_balance_fuel_rotlinear"), rot_mod * frametime * (time > self.pauserotfuel_finished), limitf);
1923 float zoomstate_set;
1924 void SetZoomState(float z)
1926 if(z != self.zoomstate)
1929 ClientData_Touch(self);
1934 void GetPressedKeys(void) {
1935 if (self.movement_x > 0) // get if movement keys are pressed
1936 { // forward key pressed
1937 self.pressedkeys |= KEY_FORWARD;
1938 self.pressedkeys &~= KEY_BACKWARD;
1940 else if (self.movement_x < 0)
1941 { // backward key pressed
1942 self.pressedkeys |= KEY_BACKWARD;
1943 self.pressedkeys &~= KEY_FORWARD;
1947 self.pressedkeys &~= KEY_FORWARD;
1948 self.pressedkeys &~= KEY_BACKWARD;
1951 if (self.movement_y > 0)
1952 { // right key pressed
1953 self.pressedkeys |= KEY_RIGHT;
1954 self.pressedkeys &~= KEY_LEFT;
1956 else if (self.movement_y < 0)
1957 { // left key pressed
1958 self.pressedkeys |= KEY_LEFT;
1959 self.pressedkeys &~= KEY_RIGHT;
1963 self.pressedkeys &~= KEY_RIGHT;
1964 self.pressedkeys &~= KEY_LEFT;
1967 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1968 self.pressedkeys |= KEY_JUMP;
1970 self.pressedkeys &~= KEY_JUMP;
1971 if (self.BUTTON_CROUCH)
1972 self.pressedkeys |= KEY_CROUCH;
1974 self.pressedkeys &~= KEY_CROUCH;
1978 ======================
1979 spectate mode routines
1980 ======================
1982 void SpectateCopy(entity spectatee) {
1983 self.armortype = spectatee.armortype;
1984 self.armorvalue = spectatee.armorvalue;
1985 self.ammo_cells = spectatee.ammo_cells;
1986 self.ammo_shells = spectatee.ammo_shells;
1987 self.ammo_nails = spectatee.ammo_nails;
1988 self.ammo_rockets = spectatee.ammo_rockets;
1989 self.ammo_fuel = spectatee.ammo_fuel;
1990 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1991 self.health = spectatee.health;
1993 self.items = spectatee.items;
1994 self.metertime = spectatee.metertime;
1995 self.strength_finished = spectatee.strength_finished;
1996 self.invincible_finished = spectatee.invincible_finished;
1997 self.pressedkeys = spectatee.pressedkeys;
1998 self.weapons = spectatee.weapons;
1999 self.switchweapon = spectatee.switchweapon;
2000 self.weapon = spectatee.weapon;
2001 self.punchangle = spectatee.punchangle;
2002 self.view_ofs = spectatee.view_ofs;
2003 self.v_angle = spectatee.v_angle;
2004 self.velocity = spectatee.velocity;
2005 self.dmg_take = spectatee.dmg_take;
2006 self.dmg_save = spectatee.dmg_save;
2007 self.dmg_inflictor = spectatee.dmg_inflictor;
2008 self.angles = spectatee.v_angle;
2009 self.fixangle = TRUE;
2010 setorigin(self, spectatee.origin);
2011 setsize(self, spectatee.mins, spectatee.maxs);
2012 SetZoomState(spectatee.zoomstate);
2015 float SpectateUpdate() {
2019 if (self == self.enemy)
2022 if(self.enemy.classname != "player")
2025 SpectateCopy(self.enemy);
2030 float SpectateNext() {
2031 other = find(self.enemy, classname, "player");
2033 other = find(other, classname, "player");
2038 if(self.enemy.classname == "player") {
2040 WriteByte(MSG_ONE, SVC_SETVIEW);
2041 WriteEntity(MSG_ONE, self.enemy);
2042 //stuffcmd(self, "set viewsize $tmpviewsize \n");
2043 if(!SpectateUpdate())
2044 PutObserverInServer();
2053 ShowRespawnCountdown()
2055 Update a respawn countdown display.
2058 void ShowRespawnCountdown()
2061 if(self.deadflag == DEAD_NO) // just respawned?
2065 number = ceil(self.death_time - time);
2068 if(number <= self.respawn_countdown)
2070 self.respawn_countdown = number - 1;
2071 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
2072 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
2077 void LeaveSpectatorMode()
2079 if(isJoinAllowed()) {
2080 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2081 self.classname = "player";
2082 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2083 JoinBestTeam(self, FALSE, TRUE);
2084 if(cvar("g_campaign"))
2085 campaign_bots_may_start = 1;
2086 PutClientInServer();
2087 if(self.classname == "player")
2088 bprint ("^4", self.netname, "^4 is playing now\n");
2089 if(!cvar("g_campaign"))
2090 centerprint(self,""); // clear MOTD
2093 stuffcmd(self,"menu_showteamselect\n");
2098 //player may not join because of g_maxplayers is set
2099 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2104 * Determines whether the player is allowed to join. This depends on cvar
2105 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2106 * it checks whether the number of currently playing players exceeds g_maxplayers.
2107 * @return bool TRUE if the player is allowed to join, false otherwise
2109 float isJoinAllowed() {
2110 if (!cvar("g_maxplayers"))
2114 local float currentlyPlaying;
2115 FOR_EACH_REALPLAYER(e) {
2116 if(e.classname == "player")
2117 currentlyPlaying += 1;
2119 if(currentlyPlaying < cvar("g_maxplayers"))
2126 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2127 * g_maxplayers_spectator_blocktime seconds
2129 void checkSpectatorBlock() {
2130 if(self.classname == "spectator" || self.classname == "observer") {
2131 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2132 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2138 float vercmp_recursive(string v1, string v2)
2144 dot1 = strstrofs(v1, ".", 0);
2145 dot2 = strstrofs(v2, ".", 0);
2149 s1 = substring(v1, 0, dot1);
2153 s2 = substring(v2, 0, dot2);
2155 r = stof(s1) - stof(s2);
2159 r = strcasecmp(s1, s2);
2172 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2175 float vercmp(string v1, string v2)
2177 if(strcasecmp(v1, v2) == 0) // early out check
2179 return vercmp_recursive(v1, v2);
2182 void ObserverThink()
2184 if (self.flags & FL_JUMPRELEASED) {
2185 if (self.BUTTON_JUMP && !self.version_mismatch) {
2186 self.welcomemessage_time = 0;
2187 self.flags &~= FL_JUMPRELEASED;
2188 self.flags |= FL_SPAWNING;
2189 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2190 self.welcomemessage_time = 0;
2191 self.flags &~= FL_JUMPRELEASED;
2192 if(SpectateNext() == 1) {
2193 self.classname = "spectator";
2197 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2198 self.flags |= FL_JUMPRELEASED;
2199 if(self.flags & FL_SPAWNING)
2201 self.flags &~= FL_SPAWNING;
2202 LeaveSpectatorMode();
2207 PrintWelcomeMessage(self);
2210 void SpectatorThink()
2212 if (self.flags & FL_JUMPRELEASED) {
2213 if (self.BUTTON_JUMP && !self.version_mismatch) {
2214 self.welcomemessage_time = 0;
2215 self.flags &~= FL_JUMPRELEASED;
2216 self.flags |= FL_SPAWNING;
2217 } else if(self.BUTTON_ATCK) {
2218 self.welcomemessage_time = 0;
2219 self.flags &~= FL_JUMPRELEASED;
2220 if(SpectateNext() == 1) {
2221 self.classname = "spectator";
2223 self.classname = "observer";
2224 PutClientInServer();
2226 } else if (self.BUTTON_ATCK2) {
2227 self.welcomemessage_time = 0;
2228 self.flags &~= FL_JUMPRELEASED;
2229 self.classname = "observer";
2230 PutClientInServer();
2232 if(!SpectateUpdate())
2233 PutObserverInServer();
2236 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2237 self.flags |= FL_JUMPRELEASED;
2238 if(self.flags & FL_SPAWNING)
2240 self.flags &~= FL_SPAWNING;
2241 LeaveSpectatorMode();
2246 PrintWelcomeMessage(self);
2247 self.flags |= FL_CLIENT | FL_NOTARGET;
2250 .float touchexplode_time;
2256 Called every frame for each client before the physics are run
2259 void() ctf_setstatus;
2260 void() nexball_setstatus;
2262 void PlayerPreThink (void)
2264 self.stat_game_starttime = game_starttime;
2265 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2266 self.stat_leadlimit = cvar("leadlimit");
2268 if(blockSpectators && frametime)
2269 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2270 checkSpectatorBlock();
2274 if(self.netname_previous != self.netname)
2276 if(cvar("sv_eventlog"))
2277 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2278 if(self.netname_previous)
2279 strunzone(self.netname_previous);
2280 self.netname_previous = strzone(self.netname);
2284 if(self.version_nagtime)
2285 if(self.cvar_g_nexuizversion)
2286 if(time > self.version_nagtime)
2288 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2290 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2292 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");
2293 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"));
2298 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2301 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");
2302 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"));
2306 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");
2307 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2311 self.version_nagtime = 0;
2315 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2317 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2318 self.max_armorvalue = 0;
2322 antilag_record(self);
2324 if(self.classname == "player") {
2325 // if(self.netname == "Wazat")
2326 // bprint(self.classname, "\n");
2328 CheckRules_Player();
2330 PrintWelcomeMessage(self);
2332 if (intermission_running)
2334 IntermissionThink (); // otherwise a button could be missed between
2335 return; // the think tics
2338 if(self.teleport_time)
2339 if(time > self.teleport_time)
2341 self.teleport_time = 0;
2342 self.effects = self.effects - (self.effects & EF_NODRAW);
2345 Nixnex_GiveCurrentWeapon();
2347 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2348 UpdateSelectedPlayer();
2350 //don't allow the player to turn around while game is paused!
2351 if(timeoutStatus == 2) {
2352 self.v_angle = self.lastV_angle;
2353 self.angles = self.lastV_angle;
2354 self.fixangle = TRUE;
2360 if (self.deadflag != DEAD_NO)
2362 float button_pressed, force_respawn;
2365 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2366 force_respawn = (g_lms || cvar("g_forced_respawn"));
2367 if (self.deadflag == DEAD_DYING)
2370 self.deadflag = DEAD_RESPAWNING;
2371 else if(!button_pressed)
2372 self.deadflag = DEAD_DEAD;
2374 else if (self.deadflag == DEAD_DEAD)
2377 self.deadflag = DEAD_RESPAWNABLE;
2379 else if (self.deadflag == DEAD_RESPAWNABLE)
2382 self.deadflag = DEAD_RESPAWNING;
2384 else if (self.deadflag == DEAD_RESPAWNING)
2386 if(time > self.death_time)
2388 self.death_time = time + 1; // only retry once a second
2392 ShowRespawnCountdown();
2397 if(time > self.touchexplode_time)
2398 if(self.classname == "player")
2399 if(self.deadflag == DEAD_NO)
2400 if not(IS_INDEPENDENT_PLAYER(self))
2401 FOR_EACH_PLAYER(other) if(self != other)
2403 if(time > other.touchexplode_time)
2404 if(other.classname == "player")
2405 if(other.deadflag == DEAD_NO)
2406 if not(IS_INDEPENDENT_PLAYER(other))
2407 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2409 PlayerTouchExplode(self, other);
2410 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2414 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2418 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2419 dist = self.prevorigin - self.origin;
2421 self.lms_traveled_distance += fabs(vlen(dist));
2423 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2425 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2426 self.lms_traveled_distance = 0;
2429 if(time > self.lms_nextcheck)
2431 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2432 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2434 centerprint(self, cvar_string("g_lms_campcheck_message"));
2435 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2436 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2437 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');
2439 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2440 self.lms_traveled_distance = 0;
2444 self.prevorigin = self.origin;
2446 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2451 self.view_ofs = PL_CROUCH_VIEW_OFS;
2452 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2453 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2460 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2461 if (!trace_startsolid)
2463 self.crouch = FALSE;
2464 self.view_ofs = PL_VIEW_OFS;
2465 setsize (self, PL_MIN, PL_MAX);
2470 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2472 if(self.bloodloss_timer < time)
2474 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2475 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2481 GrapplingHookFrame();
2485 self.items &~= self.items_added;
2489 self.items_added = 0;
2490 if(self.items & IT_JETPACK)
2491 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2492 self.items_added |= IT_FUEL;
2494 self.items |= self.items_added;
2502 minstagib_ammocheck();
2506 nexball_setstatus();
2508 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2510 //self.angles_y=self.v_angle_y + 90; // temp
2512 //if (TetrisPreFrame()) return;
2513 } else if(gameover) {
2514 if (intermission_running)
2515 IntermissionThink (); // otherwise a button could be missed between
2517 } else if(self.classname == "observer") {
2519 } else if(self.classname == "spectator") {
2524 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2526 float oldspectatee_status;
2527 oldspectatee_status = self.spectatee_status;
2528 if(self.classname == "spectator")
2529 self.spectatee_status = num_for_edict(self.enemy);
2530 else if(self.classname == "observer")
2531 self.spectatee_status = num_for_edict(self);
2533 self.spectatee_status = 0;
2534 if(self.spectatee_status != oldspectatee_status)
2536 ClientData_Touch(self);
2538 race_InitSpectator();
2541 if(self.teamkill_soundtime)
2542 if(time > self.teamkill_soundtime)
2544 self.teamkill_soundtime = 0;
2546 entity oldpusher, oldself;
2548 oldself = self; self = self.teamkill_soundsource;
2549 oldpusher = self.pusher; self.pusher = oldself;
2551 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2553 self.pusher = oldpusher;
2557 if(self.taunt_soundtime)
2558 if(time > self.taunt_soundtime)
2560 self.taunt_soundtime = 0;
2561 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2564 target_voicescript_next(self);
2570 .float dragspeed; // speed of mouse wheel action
2571 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
2572 .vector draglocalvector; // local attachment vector of the dragentity
2573 .float draglocalangle;
2576 .float dragmovetype;
2577 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
2581 draggee.dragmovetype = draggee.movetype;
2582 draggee.draggravity = draggee.gravity;
2583 draggee.movetype = MOVETYPE_WALK;
2584 draggee.gravity = 0.00001;
2585 draggee.flags &~= FL_ONGROUND;
2586 draggee.draggedby = dragger;
2588 dragger.dragentity = draggee;
2590 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
2591 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
2592 touchpoint = touchpoint - gettaginfo(draggee, 0);
2593 tagscale = pow(vlen(v_forward), -2);
2594 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
2595 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
2596 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
2598 dragger.dragspeed = 64;
2601 void Drag_Finish(entity dragger)
2604 draggee = dragger.dragentity;
2606 dragger.dragentity = world;
2607 draggee.draggedby = world;
2608 draggee.movetype = draggee.dragmovetype;
2609 draggee.gravity = draggee.draggravity;
2611 switch(draggee.movetype)
2616 case MOVETYPE_FLYMISSILE:
2617 case MOVETYPE_BOUNCE:
2618 case MOVETYPE_BOUNCEMISSILE:
2621 draggee.velocity = '0 0 0';
2625 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
2627 draggee.velocity = '0 0 0';
2628 draggee.flags |= FL_ONGROUND; // floating items are FUN
2632 float Drag_IsDraggable(entity draggee)
2634 // TODO add more checks for bad stuff here
2635 if(draggee.classname == "func_bobbing")
2637 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)
2639 if(draggee.classname == "plat")
2641 if(draggee.classname == "func_button")
2643 if(draggee.model == "")
2645 if(draggee.classname == "spectator")
2647 if(draggee.classname == "observer")
2649 if(draggee.classname == "exteriorweaponentity")
2655 float Drag_MayChangeAngles(entity draggee)
2657 // TODO add more checks for bad stuff here
2658 if(substring(draggee.model, 0, 1) == "*")
2663 void Drag_MoveForward(entity dragger)
2665 dragger.dragdistance += dragger.dragspeed;
2668 void Drag_SetSpeed(entity dragger, float s)
2670 dragger.dragspeed = pow(2, s);
2673 void Drag_MoveBackward(entity dragger)
2675 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
2678 void Drag_Update(entity dragger)
2680 vector curorigin, neworigin, goodvelocity;
2684 draggee = dragger.dragentity;
2685 draggee.flags &~= FL_ONGROUND;
2687 curorigin = gettaginfo(draggee, 0);
2688 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
2689 makevectors(dragger.v_angle);
2690 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
2691 goodvelocity = (neworigin - curorigin) * (1 / frametime);
2693 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
2694 dragger.draglocalangle += 360;
2695 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
2696 dragger.draglocalangle -= 360;
2698 f = min(frametime * 10, 1);
2699 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
2701 if(Drag_MayChangeAngles(draggee))
2702 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
2704 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
2706 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
2709 float Drag_CanDrag(entity dragger)
2711 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
2714 float Drag_IsDragging(entity dragger)
2716 if(!dragger.dragentity)
2718 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
2720 dragger.dragentity = world;
2723 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
2725 Drag_Finish(dragger);
2731 void Drag_MoveDrag(entity from, entity to)
2735 to.draggedby = from.draggedby;
2736 to.draggedby.dragentity = to;
2737 from.draggedby = world;
2745 Called every frame for each client after the physics are run
2748 .float idlekick_lasttimeleft;
2749 void PlayerPostThink (void)
2751 // Savage: Check for nameless players
2752 if (strlen(self.netname) < 1) {
2753 self.netname = "Player";
2754 stuffcmd(self, "seta _cl_name Player\n");
2757 if(sv_maxidle && frametime)
2759 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2761 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2764 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2765 announce(self, "announcer/robotic/terminated.wav");
2769 else if(timeleft <= 10)
2771 if(timeleft != self.idlekick_lasttimeleft)
2773 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2774 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2779 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2781 self.idlekick_lasttimeleft = timeleft;
2784 if(sv_cheats || self.maycheat)
2785 if(Drag_CanDrag(self))
2786 if(self.BUTTON_DRAG)
2787 if(!self.dragentity)
2788 if(self.cursor_trace_ent)
2789 if(Drag_IsDraggable(self.cursor_trace_ent))
2791 if(self.cursor_trace_ent.draggedby)
2792 Drag_Finish(self.cursor_trace_ent.draggedby);
2793 if(self.cursor_trace_ent.tag_entity)
2794 detach_sameorigin(self.cursor_trace_ent);
2795 Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
2798 if(Drag_IsDragging(self))
2800 if(self.BUTTON_DRAG)
2802 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
2804 Drag_MoveForward(self);
2807 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
2809 Drag_MoveBackward(self);
2812 else if(self.impulse >= 1 && self.impulse <= 9)
2814 Drag_SetSpeed(self, self.impulse - 1);
2816 else if(self.impulse == 14)
2818 Drag_SetSpeed(self, 9);
2830 if(self.classname == "player") {
2831 CheckRules_Player();
2836 if (intermission_running)
2837 return; // intermission or finale
2839 //if (TetrisPostFrame()) return;
2842 } else if (self.classname == "observer") {
2844 } else if (self.classname == "spectator") {
2850 for(i = 0; i < 1000; ++i)
2853 end = self.origin + '0 0 1024' + 512 * randomvec();
2854 tracebox(self.origin, self.mins, self.maxs, end, MOVE_NORMAL, self);
2855 if(trace_fraction < 1)
2856 if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
2858 print("I HIT SOLID: ", vtos(self.origin), " -> ", vtos(end), "\n");
2866 //pointparticles(particleeffectnum("machinegun_impact"), self.origin + self.view_ofs + '0 0 7', '0 0 0', 1);
2868 if(self.waypointsprite_attachedforcarrier)
2869 WaypointSprite_UpdateHealth(self.waypointsprite_attachedforcarrier, '1 0 0' * healtharmor_maxdamage(self.health, self.armorvalue, cvar("g_balance_armor_blockpercent")));