1 .float spectatee_status;
3 .float bloodloss_timer;
6 float ClientData_Send(entity to, float sf)
17 if(to.classname == "spectator")
23 sf |= 1; // forced scoreboard
24 if(to.spectatee_status)
25 sf |= 2; // spectator ent number follows
28 if(e.porto_v_angle_held)
29 sf |= 8; // angles held
31 WriteByte(MSG_ENTITY, ENT_CLIENT_CLIENTDATA);
32 WriteByte(MSG_ENTITY, sf);
35 WriteByte(MSG_ENTITY, to.spectatee_status);
39 WriteAngle(MSG_ENTITY, e.v_angle_x);
40 WriteAngle(MSG_ENTITY, e.v_angle_y);
46 void ClientData_Attach()
48 Net_LinkEntity(self.clientdata = spawn(), FALSE, 0, ClientData_Send);
49 self.clientdata.drawonlytoclient = self;
50 self.clientdata.owner = self;
53 void ClientData_Detach()
55 remove(self.clientdata);
56 self.clientdata = world;
59 void ClientData_Touch(entity e)
61 e.clientdata.SendFlags = 1;
63 // make it spectatable
65 FOR_EACH_REALCLIENT(e2)
68 if(e2.classname == "spectator")
70 e2.clientdata.SendFlags = 1;
75 #define SPAWNPOINT_SCORE frags
77 .string netname_previous;
79 void spawnfunc_info_player_survivor (void)
81 spawnfunc_info_player_deathmatch();
84 void spawnfunc_info_player_start (void)
86 spawnfunc_info_player_deathmatch();
89 void spawnfunc_info_player_deathmatch (void)
91 self.classname = "info_player_deathmatch";
92 relocate_spawnpoint();
100 self.team = activator.team;
101 some_spawn_has_been_used = 1;
106 // -1 if a spawn can't be used
107 // otherwise, a weight of the spawnpoint
108 float Spawn_Score(entity spot, entity playerlist, float teamcheck)
110 float shortest, thisdist;
113 // filter out spots for the wrong team
115 if(spot.team != teamcheck)
119 if(spot.target == "")
122 // filter out spots for assault
123 if(spot.target != "") {
126 ent = find(world, targetname, spot.target);
128 if(ent.classname == "target_objective")
131 if(ent.health < 0 || ent.health >= ASSAULT_VALUE_INACTIVE)
135 else if(ent.classname == "trigger_race_checkpoint")
138 if(self.classname == "player") // spectators may spawn everywhere
140 if(g_race_qualifying)
143 if(ent.race_checkpoint != 0)
145 if(spot.race_place != race_lowest_place_spawn)
150 if(ent.race_checkpoint != race_PreviousCheckpoint(self.race_checkpoint))
153 pl = self.race_place;
154 if(pl > race_highest_place_spawn)
156 if(spot.race_place != pl)
162 ent = find(ent, targetname, spot.target);
170 shortest = vlen(world.maxs - world.mins);
171 for(player = playerlist; player; player = player.chain)
174 thisdist = vlen(player.origin - spot.origin);
175 if (thisdist < shortest)
183 entity Spawn_FilterOutBadSpots(entity firstspot, entity playerlist, float mindist, float teamcheck)
185 local entity spot, spotlist, spotlistend;
186 spawn_allgood = TRUE;
192 for(spot = firstspot; spot; spot = spot.chain)
194 spot.SPAWNPOINT_SCORE = Spawn_Score(spot, playerlist, teamcheck);
196 if(cvar("spawn_debugview"))
198 setmodel(spot, "models/runematch/rune.mdl");
199 if(spot.SPAWNPOINT_SCORE < mindist)
201 spot.colormod = '1 0 0';
206 spot.colormod = '0 1 0';
207 spot.scale = spot.SPAWNPOINT_SCORE / mindist;
211 if(spot.SPAWNPOINT_SCORE >= 0) // spawning allowed here
213 if(spot.SPAWNPOINT_SCORE < mindist)
215 // too short distance
216 spawn_allgood = FALSE;
221 spawn_allbad = FALSE;
224 spotlistend.chain = spot;
231 if(spot.team != teamcheck)
232 error("invalid spawn added");
234 print("added ", etos(spot), "\n");
240 spotlistend.chain = world;
245 for(e = spotlist; e; e = e.chain)
247 print("seen ", etos(e), "\n");
248 if(e.team != teamcheck)
249 error("invalid spawn found");
256 entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exponent)
258 // weight of a point: bound(lower, mindisttoplayer, upper)^exponent
259 // multiplied by spot.cnt (useful if you distribute many spawnpoints in a small area)
262 RandomSelection_Init();
263 for(spot = firstspot; spot; spot = spot.chain)
264 RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.SPAWNPOINT_SCORE, upper), exponent) * spot.cnt, spot.SPAWNPOINT_SCORE >= lower);
266 return RandomSelection_chosen_ent;
273 Finds a point to respawn
276 entity SelectSpawnPoint (float anypoint)
278 local float teamcheck;
279 local entity firstspot_new;
280 local entity spot, firstspot, playerlist;
282 spot = find (world, classname, "testplayerstart");
288 if(!anypoint && have_team_spawns)
289 teamcheck = self.team;
291 // get the list of players
292 playerlist = findchain(classname, "player");
293 // get the entire list of spots
294 firstspot = findchain(classname, "info_player_deathmatch");
295 // filter out the bad ones
296 // (note this returns the original list if none survived)
297 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 100, teamcheck);
299 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, -1, teamcheck);
300 firstspot = firstspot_new;
302 // there is 50/50 chance of choosing a random spot or the furthest spot
303 // (this means that roughly every other spawn will be furthest, so you
304 // usually won't get fragged at spawn twice in a row)
305 if (arena_roundbased)
307 firstspot_new = Spawn_FilterOutBadSpots(firstspot, playerlist, 800, teamcheck);
309 firstspot = firstspot_new;
310 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
312 else if (random() > cvar("g_spawn_furthest"))
313 spot = Spawn_WeightedPoint(firstspot, 1, 1, 1);
315 spot = Spawn_WeightedPoint(firstspot, 1, 5000, 5); // chooses a far far away spawnpoint
317 if(cvar("spawn_debugview"))
319 print("spot mindistance: ", ftos(spot.SPAWNPOINT_SCORE), "\n");
323 for(e = firstspot; e; e = e.chain)
324 if(e.team != teamcheck)
325 error("invalid spawn found");
330 if(cvar("spawn_debug"))
334 if(some_spawn_has_been_used)
335 return world; // team can't spawn any more, because of actions of other team
337 error("Cannot find a spawn point - please fix the map!");
348 Checks if the argument string can be a valid playermodel.
349 Returns a valid one in doubt.
352 string FallbackPlayerModel = "models/player/marine.zym";
353 string CheckPlayerModel(string plyermodel) {
354 if(strlen(plyermodel) < 4)
355 return FallbackPlayerModel;
356 if( substring(plyermodel,0,14) != "models/player/")
357 return FallbackPlayerModel;
358 else if(cvar("sv_servermodelsonly"))
360 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".zym")
361 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".dpm")
362 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".md3")
363 if(substring(plyermodel,strlen(plyermodel)-4,4) != ".psk")
364 return FallbackPlayerModel;
365 #ifdef ALLOW_VARIABLE_LOD
366 // forbid the LOD models
367 if(substring(plyermodel, strlen(plyermodel)-6,2) == "_1")
368 return FallbackPlayerModel;
369 if(substring(plyermodel, strlen(plyermodel)-6,2) == "_2")
370 return FallbackPlayerModel;
372 if(plyermodel != strtolower(plyermodel))
373 return FallbackPlayerModel;
374 if(!fexists(plyermodel))
375 return FallbackPlayerModel;
382 Client_customizeentityforclient
387 float Client_customizeentityforclient()
389 #ifdef ALLOW_VARIABLE_LOD
391 // other: the player viewing me
395 if(self.classname != "player")
398 if(other.cvar_cl_playerdetailreduction <= 0)
400 if(other.cvar_cl_playerdetailreduction <= -2)
401 self.modelindex = self.modelindex_lod2;
402 else if(other.cvar_cl_playerdetailreduction <= -1)
403 self.modelindex = self.modelindex_lod1;
405 self.modelindex = self.modelindex_lod0;
409 distance = vlen(self.origin - other.origin);
410 f = (distance + 100.0) * other.cvar_cl_playerdetailreduction;
412 self.modelindex = self.modelindex_lod2;
414 self.modelindex = self.modelindex_lod1;
416 self.modelindex = self.modelindex_lod0;
423 void UpdatePlayerSounds();
424 void setmodel_lod(entity e, string modelname)
426 #ifdef ALLOW_VARIABLE_LOD
429 // FIXME: this only supports 3-letter extensions
430 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_1", substring(modelname, 0, strlen(modelname) - 4));
434 setmodel(e, s); // players have high precision
435 self.modelindex_lod1 = self.modelindex;
438 self.modelindex_lod1 = -1;
440 s = strcat(substring(modelname, 0, strlen(modelname) - 4), "_2", substring(modelname, 0, strlen(modelname) - 4));
444 setmodel(e, s); // players have high precision
445 self.modelindex_lod2 = self.modelindex;
448 self.modelindex_lod2 = -1;
450 precache_model(modelname);
451 setmodel(e, modelname); // players have high precision
452 self.modelindex_lod0 = self.modelindex;
454 if(self.modelindex_lod1 < 0)
455 self.modelindex_lod1 = self.modelindex;
457 if(self.modelindex_lod2 < 0)
458 self.modelindex_lod2 = self.modelindex;
460 precache_model(modelname);
461 setmodel(e, modelname); // players have high precision
463 player_setupanimsformodel();
464 UpdatePlayerSounds();
471 putting a client as observer in the server
474 void PutObserverInServer (void)
478 race_PreSpawnObserver();
480 spot = SelectSpawnPoint (TRUE);
482 error("No spawnpoints for observers?!?\n");
483 RemoveGrapplingHook(self); // Wazat's Grappling Hook
485 if(clienttype(self) == CLIENTTYPE_REAL)
488 WriteByte(MSG_ONE, SVC_SETVIEW);
489 WriteEntity(MSG_ONE, self);
493 kh_Key_DropAll(self, TRUE);
495 Portal_ClearAll(self);
498 DropFlag(self.flagcarried, world, world);
500 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
502 WaypointSprite_PlayerDead();
504 if(self.killcount != -666)
508 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
509 bprint ("^4", self.netname, "^4 has no more lives left\n");
511 bprint ("^4", self.netname, "^4 is spectating now\n"); // TODO turn this into a proper forfeit?
514 bprint ("^4", self.netname, "^4 is spectating now\n");
517 PlayerScore_Clear(self); // clear scores when needed
519 self.spectatortime = time;
521 self.classname = "observer";
522 self.iscreature = FALSE;
524 self.takedamage = DAMAGE_NO;
525 self.solid = SOLID_NOT;
526 self.movetype = MOVETYPE_NOCLIP;
527 self.flags = FL_CLIENT | FL_NOTARGET;
528 self.armorvalue = 666;
530 self.armorvalue = cvar("g_balance_armor_start");
531 self.pauserotarmor_finished = 0;
532 self.pauserothealth_finished = 0;
533 self.pauseregen_finished = 0;
534 self.damageforcescale = 0;
541 self.pain_finished = 0;
542 self.strength_finished = 0;
543 self.invincible_finished = 0;
545 self.think = SUB_Null;
549 self.deadflag = DEAD_NO;
550 self.angles = spot.angles;
552 self.fixangle = TRUE;
555 self.view_ofs = PL_VIEW_OFS;
556 setorigin (self, spot.origin);
557 setsize (self, '0 0 0', '0 0 0');
558 self.prevorigin = self.origin;
564 self.weaponmodel = "";
565 self.weaponentity = world;
566 self.exteriorweaponentity = world;
567 self.killcount = -666;
568 self.velocity = '0 0 0';
569 self.avelocity = '0 0 0';
570 self.punchangle = '0 0 0';
571 self.punchvector = '0 0 0';
572 self.oldvelocity = self.velocity;
573 self.customizeentityforclient = Client_customizeentityforclient;
579 if(self.version_mismatch)
581 Spawnqueue_Unmark(self);
582 Spawnqueue_Remove(self);
586 Spawnqueue_Insert(self);
591 // Only if the player cannot play at all
592 if(PlayerScore_Add(self, SP_LMS_RANK, 0) == 666)
593 self.frags = FRAGS_SPECTATOR;
595 self.frags = FRAGS_LMS_LOSER;
598 self.frags = FRAGS_SPECTATOR;
601 float RestrictSkin(float s)
610 void FixPlayermodel()
612 local string defaultmodel;
613 local float defaultskin, chmdl, oldskin;
618 if(cvar("sv_defaultcharacter") == 1) {
623 defaultmodel = cvar_string(strcat("sv_defaultplayermodel_", Team_ColorNameLowerCase(self.team)));
624 defaultskin = cvar(strcat("sv_defaultplayerskin_", Team_ColorNameLowerCase(self.team)));
627 if(defaultmodel == "")
629 defaultmodel = cvar_string("sv_defaultplayermodel");
630 defaultskin = cvar("sv_defaultplayerskin");
634 if(self.modelindex == 0 && self.deadflag == DEAD_NO)
637 bprint("\{1}^1Player ", self.netname, "^1 has a zero modelindex, trying to fix...\n");
638 self.model = ""; // force the != checks to return true
641 if(defaultmodel != "")
643 if (defaultmodel != self.model)
647 setmodel_lod (self, defaultmodel);
648 setsize (self, m1, m2);
651 self.skin = defaultskin;
652 self.species = player_getspecies();
654 if (self.playermodel != self.model)
656 self.playermodel = CheckPlayerModel(self.playermodel);
659 setmodel_lod (self, self.playermodel);
660 setsize (self, m1, m2);
665 self.skin = RestrictSkin(stof(self.playerskin));
667 if(chmdl || oldskin != self.skin)
668 self.species = player_getspecies(); // model or skin has changed
672 if(strlen(cvar_string("sv_defaultplayercolors")))
673 if(self.clientcolors != cvar("sv_defaultplayercolors"))
674 setcolor(self, cvar("sv_defaultplayercolors"));
677 void PlayerTouchExplode(entity p1, entity p2)
680 org = (p1.origin + p2.origin) * 0.5;
681 org_z += (p1.mins_z + p2.mins_z) * 0.5;
688 RadiusDamage(e, world, g_touchexplode_damage, g_touchexplode_edgedamage, g_touchexplode_radius, world, g_touchexplode_force, DEATH_TOUCHEXPLODE, world);
696 Called when a client spawns in the server
699 //void() ctf_playerchanged;
700 void PutClientInServer (void)
702 if(clienttype(self) == CLIENTTYPE_BOT)
704 self.classname = "player";
706 else if(clienttype(self) == CLIENTTYPE_REAL)
709 WriteByte(MSG_ONE, SVC_SETVIEW);
710 WriteEntity(MSG_ONE, self);
713 // player is dead and becomes observer
714 // FIXME fix LMS scoring for new system
717 if(PlayerScore_Add(self, SP_LMS_RANK, 0) > 0)
718 self.classname = "observer";
723 self.classname = "observer";
725 if(self.classname == "player") {
726 entity spot, oldself;
729 JoinBestTeam(self, FALSE, TRUE);
733 spot = SelectSpawnPoint (FALSE);
736 centerprint(self, "Sorry, no spawnpoints available!\nHope your team can fix it...");
737 return; // spawn failed
740 RemoveGrapplingHook(self); // Wazat's Grappling Hook
741 self.campingrifle_bulletcounter = 0;
743 self.classname = "player";
744 self.wasplayer = TRUE;
745 self.iscreature = TRUE;
746 self.movetype = MOVETYPE_WALK;
747 self.solid = SOLID_SLIDEBOX;
748 self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
749 self.frags = FRAGS_PLAYER;
750 if(independent_players)
751 MAKE_INDEPENDENT_PLAYER(self);
752 self.flags = FL_CLIENT;
753 self.takedamage = DAMAGE_AIM;
755 self.effects = EF_FULLBRIGHT;
758 self.air_finished = time + 12;
763 self.ammo_shells = warmup_start_ammo_shells;
764 self.ammo_nails = warmup_start_ammo_nails;
765 self.ammo_rockets = warmup_start_ammo_rockets;
766 self.ammo_cells = warmup_start_ammo_cells;
767 self.ammo_fuel = warmup_start_ammo_fuel;
768 self.health = warmup_start_health;
769 self.armorvalue = warmup_start_armorvalue;
770 self.weapons = warmup_start_weapons;
774 self.ammo_shells = start_ammo_shells;
775 self.ammo_nails = start_ammo_nails;
776 self.ammo_rockets = start_ammo_rockets;
777 self.ammo_cells = start_ammo_cells;
778 self.ammo_fuel = start_ammo_fuel;
779 self.health = start_health;
780 self.armorvalue = start_armorvalue;
781 self.weapons = start_weapons;
783 self.items = start_items;
784 self.switchweapon = w_getbestweapon(self);
785 self.cnt = self.switchweapon;
787 self.jump_interval = time;
789 self.spawnshieldtime = time + cvar("g_spawnshieldtime");
790 self.pauserotarmor_finished = time + cvar("g_balance_pause_armor_rot_spawn");
791 self.pauserothealth_finished = time + cvar("g_balance_pause_health_rot_spawn");
792 self.pauserotfuel_finished = time + cvar("g_balance_pause_fuel_rot_spawn");
793 self.pauseregen_finished = time + cvar("g_balance_pause_health_regen_spawn");
794 //extend the pause of rotting if client was reset at the beginning of the countdown
795 if(!cvar("sv_ready_restart_after_countdown") && time < game_starttime) { // TODO why is this cvar NOTted?
796 self.spawnshieldtime += game_starttime - time;
797 self.pauserotarmor_finished += game_starttime - time;
798 self.pauserothealth_finished += game_starttime - time;
799 self.pauseregen_finished += game_starttime - time;
801 self.damageforcescale = 2;
808 self.pain_finished = 0;
809 self.strength_finished = 0;
810 self.invincible_finished = 0;
812 //self.speed_finished = 0;
813 //self.slowmo_finished = 0;
814 // players have no think function
815 self.think = SUB_Null;
824 self.deadflag = DEAD_NO;
826 self.angles = spot.angles;
828 self.angles_z = 0; // never spawn tilted even if the spot says to
829 self.fixangle = TRUE; // turn this way immediately
830 self.velocity = '0 0 0';
831 self.avelocity = '0 0 0';
832 self.punchangle = '0 0 0';
833 self.punchvector = '0 0 0';
834 self.oldvelocity = self.velocity;
837 WRITESPECTATABLE_MSG_ONE({
838 WriteByte(MSG_ONE, SVC_TEMPENTITY);
839 WriteByte(MSG_ONE, TE_CSQC_SPAWN);
842 self.customizeentityforclient = Client_customizeentityforclient;
848 self.view_ofs = PL_VIEW_OFS;
849 setsize (self, PL_MIN, PL_MAX);
850 self.spawnorigin = spot.origin;
851 setorigin (self, spot.origin + '0 0 1' * (1 - self.mins_z - 24));
852 // don't reset back to last position, even if new position is stuck in solid
853 self.oldorigin = self.origin;
854 self.prevorigin = self.origin;
858 Spawnqueue_Remove(self);
859 Spawnqueue_Mark(self);
862 self.event_damage = PlayerDamage;
864 self.bot_attack = TRUE;
866 self.statdraintime = time + 5;
867 self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = 0;
869 if(self.killcount == -666) {
870 PlayerScore_Clear(self);
874 self.cnt = WEP_LASER;
875 self.nixnex_lastchange_id = -1;
877 CL_SpawnWeaponentity();
878 self.alpha = default_player_alpha;
879 self.colormod = '1 1 1' * cvar("g_player_brightness");
880 self.exteriorweaponentity.alpha = default_weapon_alpha;
882 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
883 self.lms_traveled_distance = 0;
884 self.speedrunning = FALSE;
886 race_PostSpawn(spot);
888 if(cvar("spawn_debug"))
890 sprint(self, strcat("spawnpoint origin: ", vtos(spot.origin), "\n"));
891 remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
894 //stuffcmd(self, "chase_active 0");
895 //stuffcmd(self, "set viewsize $tmpviewsize \n");
897 if (cvar("g_spawnsound"))
898 sound (self, CHAN_TRIGGER, "misc/spawn.wav", VOL_BASE, ATTN_NORM);
901 if(self.team == assault_attacker_team)
902 centerprint(self, "You are attacking!");
904 centerprint(self, "You are defending!");
907 target_voicescript_clear(self);
916 } else if(self.classname == "observer") {
917 PutObserverInServer ();
921 // ctf_playerchanged();
924 float ClientInit_SendEntity(entity to, float sf)
927 WriteByte(MSG_ENTITY, ENT_CLIENT_INIT);
928 WriteByte(MSG_ENTITY, g_nexball_meter_period * 32);
929 for(i = 1; i <= 24; ++i)
930 WriteByte(MSG_ENTITY, (get_weaponinfo(i)).impulse + 1);
931 WriteCoord(MSG_ENTITY, hook_shotorigin_x);
932 WriteCoord(MSG_ENTITY, hook_shotorigin_y);
933 WriteCoord(MSG_ENTITY, hook_shotorigin_z);
935 if(sv_foginterval && world.fog != "")
936 WriteString(MSG_ENTITY, world.fog);
938 WriteString(MSG_ENTITY, "");
939 WriteByte(MSG_ENTITY, cvar("g_balance_armor_blockpercent") * 255.0);
943 void ClientInit_Spawn()
945 Net_LinkEntity(spawn(), FALSE, 0, ClientInit_SendEntity);
953 void SetNewParms (void)
955 // initialize parms for a new player
956 parm1 = -(86400 * 366);
964 void SetChangeParms (void)
966 // save parms for level change
967 parm1 = self.parm_idlesince - time;
975 void DecodeLevelParms (void)
978 self.parm_idlesince = parm1;
979 if(self.parm_idlesince == -(86400 * 366))
980 self.parm_idlesince = time;
982 // whatever happens, allow 60 seconds of idling directly after connect for map loading
983 self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60);
990 Called when a client types 'kill' in the console
994 void ClientKill_Now_TeamChange()
996 if(self.killindicator_teamchange == -1)
999 JoinBestTeam( self, FALSE, FALSE );
1002 SV_ChangeTeam(self.killindicator_teamchange - 1);
1005 void ClientKill_Now()
1007 if(self.killindicator_teamchange)
1008 ClientKill_Now_TeamChange();
1011 Damage(self, self, self, 100000, DEATH_KILL, self.origin, '0 0 0');
1013 if(self.killindicator)
1015 dprint("Cleaned up after a leaked kill indicator.\n");
1016 remove(self.killindicator);
1017 self.killindicator = world;
1020 void KillIndicator_Think()
1022 if (!self.owner.modelindex)
1024 self.owner.killindicator = world;
1032 ClientKill_Now(); // no oldself needed
1038 setmodel(self, strcat("models/sprites/", ftos(self.cnt), ".spr32"));
1039 if(clienttype(self.owner) == CLIENTTYPE_REAL)
1042 announce(self.owner, strcat("announcer/robotic/", ftos(self.cnt), ".wav"));
1043 if(self.owner.killindicator_teamchange)
1045 if(self.owner.killindicator_teamchange == -1)
1046 centerprint(self.owner, strcat("Changing team in ", ftos(self.cnt), " seconds"));
1048 centerprint(self.owner, strcat("Changing to ", ColoredTeamName(self.owner.killindicator_teamchange), " in ", ftos(self.cnt), " seconds"));
1051 centerprint(self.owner, strcat("^1Suicide in ", ftos(self.cnt), " seconds"));
1053 self.nextthink = time + 1;
1058 void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto
1062 killtime = cvar("g_balance_kill_delay");
1064 self.killindicator_teamchange = targetteam;
1066 if(!self.killindicator)
1068 if(killtime <= 0 || !self.modelindex || self.deadflag != DEAD_NO)
1074 self.killindicator = spawn();
1075 self.killindicator.owner = self;
1076 self.killindicator.scale = 0.5;
1077 setattachment(self.killindicator, self, "");
1078 setorigin(self.killindicator, '0 0 52');
1079 self.killindicator.think = KillIndicator_Think;
1080 self.killindicator.nextthink = time + (self.lip) * 0.05;
1081 self.killindicator.cnt = ceil(killtime);
1082 self.killindicator.count = bound(0, ceil(killtime), 10);
1083 sprint(self, strcat("^1You'll be dead in ", ftos(self.killindicator.cnt), " seconds\n"));
1085 for(e = world; (e = find(e, classname, "body")) != world; )
1089 e.killindicator = spawn();
1090 e.killindicator.owner = e;
1091 e.killindicator.scale = 0.5;
1092 setattachment(e.killindicator, e, "");
1093 setorigin(e.killindicator, '0 0 52');
1094 e.killindicator.think = KillIndicator_Think;
1095 e.killindicator.nextthink = time + (e.lip) * 0.05;
1096 e.killindicator.cnt = ceil(killtime);
1101 if(self.killindicator)
1104 self.killindicator.colormod = TeamColor(targetteam);
1106 self.killindicator.colormod = '0 0 0';
1110 void ClientKill (void)
1112 ClientKill_TeamChange(0);
1115 void DoTeamChange(float destteam)
1121 SetPlayerColors(self, destteam);
1124 if(self.classname == "player")
1127 CheckAllowedTeams(self);
1128 t = FindSmallestTeam(self, TRUE);
1131 case COLOR_TEAM1: c0 = c1; break;
1132 case COLOR_TEAM2: c0 = c2; break;
1133 case COLOR_TEAM3: c0 = c3; break;
1134 case COLOR_TEAM4: c0 = c4; break;
1141 destteam = COLOR_TEAM1;
1145 destteam = COLOR_TEAM2;
1149 destteam = COLOR_TEAM3;
1153 destteam = COLOR_TEAM4;
1159 if(destteam == self.team && destteam >= 0 && !self.killindicator)
1161 ClientKill_TeamChange(destteam);
1164 void FixClientCvars(entity e)
1166 // send prediction settings to the client
1167 stuffcmd(e, "\nin_bindmap 0 0\n");
1169 * we no longer need to stuff this. Remove this comment block if you feel
1170 * 2.3 and higher (or was it 2.2.3?) don't need these any more
1171 stuffcmd(e, strcat("cl_gravity ", ftos(cvar("sv_gravity")), "\n"));
1172 stuffcmd(e, strcat("cl_movement_accelerate ", ftos(cvar("sv_accelerate")), "\n"));
1173 stuffcmd(e, strcat("cl_movement_friction ", ftos(cvar("sv_friction")), "\n"));
1174 stuffcmd(e, strcat("cl_movement_maxspeed ", ftos(cvar("sv_maxspeed")), "\n"));
1175 stuffcmd(e, strcat("cl_movement_airaccelerate ", ftos(cvar("sv_airaccelerate")), "\n"));
1176 stuffcmd(e, strcat("cl_movement_maxairspeed ", ftos(cvar("sv_maxairspeed")), "\n"));
1177 stuffcmd(e, strcat("cl_movement_stopspeed ", ftos(cvar("sv_stopspeed")), "\n"));
1178 stuffcmd(e, strcat("cl_movement_jumpvelocity ", ftos(cvar("sv_jumpvelocity")), "\n"));
1179 stuffcmd(e, strcat("cl_movement_stepheight ", ftos(cvar("sv_stepheight")), "\n"));
1180 stuffcmd(e, strcat("set cl_movement_friction_on_land ", ftos(cvar("sv_friction_on_land")), "\n"));
1181 stuffcmd(e, strcat("set cl_movement_airaccel_qw ", ftos(cvar("sv_airaccel_qw")), "\n"));
1182 stuffcmd(e, strcat("set cl_movement_airaccel_sideways_friction ", ftos(cvar("sv_airaccel_sideways_friction")), "\n"));
1183 stuffcmd(e, "cl_movement_edgefriction 1\n");
1191 Called when a client connects to the server
1194 //void ctf_clientconnect();
1195 string ColoredTeamName(float t);
1196 void DecodeLevelParms (void);
1197 //void dom_player_join_team(entity pl);
1198 void ClientConnect (void)
1203 if(self.flags & FL_CLIENT)
1205 print("Warning: ClientConnect, but already connected!\n");
1209 if(Ban_MaybeEnforceBan(self))
1214 self.classname = "player_joining";
1216 self.flags = FL_CLIENT;
1217 self.version_nagtime = time + 10 + random() * 10;
1221 dprint("BUG player count is lower than zero, this cannot happen!\n");
1225 PlayerScore_Attach(self);
1226 ClientData_Attach();
1228 bot_clientconnect();
1230 race_PreSpawnObserver();
1233 // dom_player_join_team(self);
1235 JoinBestTeam(self, FALSE, FALSE); // if the team number is valid, keep it
1237 if((cvar("sv_spectate") == 1 && !g_lms) || cvar("g_campaign")) {
1238 self.classname = "observer";
1242 if(cvar("g_balance_teams") || cvar("g_balance_teams_force"))
1244 self.classname = "player";
1245 campaign_bots_may_start = 1;
1249 self.classname = "observer"; // do it anyway
1254 self.classname = "player";
1255 campaign_bots_may_start = 1;
1259 self.playerid = (playerid_last = playerid_last + 1);
1260 if(cvar("sv_eventlog"))
1262 if(clienttype(self) == CLIENTTYPE_REAL)
1263 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":", self.netaddress, ":", self.netname));
1265 GameLogEcho(strcat(":join:", ftos(self.playerid), ":", ftos(num_for_edict(self)), ":bot:", self.netname));
1266 s = strcat(":team:", ftos(self.playerid), ":");
1267 s = strcat(s, ftos(self.team));
1270 self.netname_previous = strzone(self.netname);
1272 //stuffcmd(self, "set tmpviewsize $viewsize \n");
1274 bprint ("^4",self.netname);
1275 bprint ("^4 connected");
1277 if(g_domination || g_ctf)
1279 bprint(" and joined the ");
1280 bprint(ColoredTeamName(self.team));
1285 self.welcomemessage_time = 0;
1287 stuffcmd(self, strcat(clientstuff, "\n"));
1288 stuffcmd(self, strcat("exec maps/", mapname, ".cfg\n"));
1289 stuffcmd(self, "cl_particles_reloadeffects\n");
1291 FixClientCvars(self);
1293 // spawnfunc_waypoint sprites
1294 WaypointSprite_InitClient(self);
1296 // Wazat's grappling hook
1297 SetGrappleHookBindings();
1299 // get autoswitch state from player when he toggles it
1300 stuffcmd(self, "alias autoswitch \"set cl_autoswitch $1 ; cmd autoswitch $1\"\n"); // default.cfg-ed in 2.4.1
1302 // get version info from player
1303 stuffcmd(self, "cmd clientversion $gameversion\n");
1305 // get other cvars from player
1308 // set cvar for team scoreboard
1309 stuffcmd(self, strcat("set teamplay ", ftos(teamplay), "\n"));
1311 // notify about available teams
1314 CheckAllowedTeams(self);
1315 t = 0; if(c1 >= 0) t |= 1; if(c2 >= 0) t |= 2; if(c3 >= 0) t |= 4; if(c4 >= 0) t |= 8;
1316 stuffcmd(self, strcat("set _teams_available ", ftos(t), "\n"));
1319 stuffcmd(self, "set _teams_available 0\n");
1321 stuffcmd(self, strcat("set gametype ", ftos(game), "\n"));
1325 self.classname = "observer";
1326 Spawnqueue_Insert(self);
1330 ctf_clientconnect();
1333 if(teams_matter || sv_cheats)
1336 bot_relinkplayerlist();
1338 self.spectatortime = time;
1341 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"));
1344 self.jointime = time;
1345 self.allowedTimeouts = cvar("sv_timeout_number");
1347 if(clienttype(self) == CLIENTTYPE_REAL)
1349 if(cvar("g_bugrigs"))
1350 stuffcmd(self, "cl_cmd settemp chase_active 1\n");
1355 if(PlayerScore_Add(self, SP_LMS_LIVES, LMS_NewPlayerLives()) <= 0)
1357 PlayerScore_Add(self, SP_LMS_RANK, 666);
1358 self.frags = FRAGS_SPECTATOR;
1362 if(!sv_foginterval && world.fog != "")
1363 stuffcmd(self, strcat("\nfog ", world.fog, "\nr_fog_exp2 0\nr_drawfog 1\n"));
1365 SoundEntity_Attach(self);
1367 if(cvar("g_hitplots"))
1369 self.hitplotfh = fopen(strcat("hits-", matchid, "-", ftos(self.playerid), ".plot"), FILE_WRITE);
1370 fputs(self.hitplotfh, strcat("#name ", self.netname, "\n"));
1373 self.hitplotfh = -1;
1380 Called when a client disconnects from the server
1383 .entity chatbubbleentity;
1384 .entity teambubbleentity;
1386 void ClientDisconnect (void)
1388 if not(self.flags & FL_CLIENT)
1390 print("Warning: ClientDisconnect without ClientConnect\n");
1394 if(self.hitplotfh >= 0)
1396 fclose(self.hitplotfh);
1397 self.hitplotfh = -1;
1400 bot_clientdisconnect();
1405 if(cvar("sv_eventlog"))
1406 GameLogEcho(strcat(":part:", ftos(self.playerid)));
1407 bprint ("^4",self.netname);
1408 bprint ("^4 disconnected\n");
1410 SoundEntity_Detach(self);
1413 kh_Key_DropAll(self, TRUE);
1415 Portal_ClearAll(self);
1417 if(self.flagcarried)
1418 DropFlag(self.flagcarried, world, world);
1419 if(self.ballcarried)
1420 DropBall(self.ballcarried, self.origin + self.ballcarried.origin, self.velocity);
1422 // Here, everything has been done that requires this player to be a client.
1424 self.flags &~= FL_CLIENT;
1426 if (self.chatbubbleentity)
1427 remove (self.chatbubbleentity);
1429 if (self.teambubbleentity)
1430 remove (self.teambubbleentity);
1432 if (self.killindicator)
1433 remove (self.killindicator);
1435 WaypointSprite_PlayerGone();
1437 bot_relinkplayerlist();
1440 if(self.weaponentity)
1441 if(self.weaponentity.lasertarget)
1442 remove(self.weaponentity.lasertarget);
1446 Spawnqueue_Unmark(self);
1447 Spawnqueue_Remove(self);
1450 ClientData_Detach();
1451 PlayerScore_Detach(self);
1453 if(self.netname_previous)
1454 strunzone(self.netname_previous);
1456 ClearPlayerSounds();
1466 void ChatBubbleThink()
1468 self.nextthink = time;
1469 if (!self.owner.modelindex || self.owner.chatbubbleentity != self)
1471 if(self.owner) // but why can that ever be world?
1472 self.owner.chatbubbleentity = world;
1476 if (self.owner.BUTTON_CHAT && !self.owner.deadflag)
1477 self.model = self.mdl;
1482 void UpdateChatBubble()
1484 if (!self.modelindex)
1486 // spawn a chatbubble entity if needed
1487 if (!self.chatbubbleentity)
1489 self.chatbubbleentity = spawn();
1490 self.chatbubbleentity.owner = self;
1491 self.chatbubbleentity.exteriormodeltoclient = self;
1492 self.chatbubbleentity.think = ChatBubbleThink;
1493 self.chatbubbleentity.nextthink = time;
1494 setmodel(self.chatbubbleentity, "models/misc/chatbubble.spr"); // precision set below
1495 //setorigin(self.chatbubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1496 setorigin(self.chatbubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1497 setattachment(self.chatbubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1498 self.chatbubbleentity.mdl = self.chatbubbleentity.model;
1499 self.chatbubbleentity.model = "";
1500 self.chatbubbleentity.effects = EF_LOWPRECISION;
1505 void TeamBubbleThink()
1507 self.nextthink = time;
1508 if (!self.owner.modelindex || self.owner.teambubbleentity != self)
1510 if(self.owner) // but why can that ever be world?
1511 self.owner.teambubbleentity = world;
1515 // setorigin(self, self.owner.origin + '0 0 15' + self.owner.maxs_z * '0 0 1'); // bandwidth hog. setattachment does this now
1516 if (self.owner.BUTTON_CHAT || self.owner.deadflag || self.owner.killindicator)
1519 self.model = self.mdl;
1523 float TeamBubble_customizeentityforclient()
1525 return (self.owner != other && self.owner.team == other.team && other.killcount > -666);
1528 void UpdateTeamBubble()
1530 if (!self.modelindex || !teams_matter)
1532 // spawn a teambubble entity if needed
1533 if (!self.teambubbleentity && teams_matter)
1535 self.teambubbleentity = spawn();
1536 self.teambubbleentity.owner = self;
1537 self.teambubbleentity.exteriormodeltoclient = self;
1538 self.teambubbleentity.think = TeamBubbleThink;
1539 self.teambubbleentity.nextthink = time;
1540 setmodel(self.teambubbleentity, "models/misc/teambubble.spr"); // precision set below
1541 // setorigin(self.teambubbleentity, self.origin + '0 0 15' + self.maxs_z * '0 0 1');
1542 setorigin(self.teambubbleentity, '0 0 15' + self.maxs_z * '0 0 1');
1543 setattachment(self.teambubbleentity, self, ""); // sticks to moving player better, also conserves bandwidth
1544 self.teambubbleentity.mdl = self.teambubbleentity.model;
1545 self.teambubbleentity.model = self.teambubbleentity.mdl;
1546 self.teambubbleentity.customizeentityforclient = TeamBubble_customizeentityforclient;
1547 self.teambubbleentity.effects = EF_LOWPRECISION;
1551 // LordHavoc: this hack will be removed when proper _pants/_shirt layers are
1552 // added to the model skins
1553 /*void UpdateColorModHack()
1556 c = self.clientcolors & 15;
1557 // LordHavoc: only bothering to support white, green, red, yellow, blue
1558 if (!teams_matter) self.colormod = '0 0 0';
1559 else if (c == 0) self.colormod = '1.00 1.00 1.00';
1560 else if (c == 3) self.colormod = '0.10 1.73 0.10';
1561 else if (c == 4) self.colormod = '1.73 0.10 0.10';
1562 else if (c == 12) self.colormod = '1.22 1.22 0.10';
1563 else if (c == 13) self.colormod = '0.10 0.10 1.73';
1564 else self.colormod = '1 1 1';
1570 self.effects |= EF_NODRAW; // prevent another CopyBody
1571 PutClientInServer();
1574 void play_countdown(float finished, string samp)
1576 if(clienttype(self) == CLIENTTYPE_REAL)
1577 if(floor(finished - time - frametime) != floor(finished - time))
1578 if(finished - time < 6)
1579 sound (self, CHAN_AUTO, samp, VOL_BASE, ATTN_NORM);
1583 * When sv_timeout is used this function returs strings like
1584 * "Timeout begins in 2 seconds!\n" or "Timeout ends in 23 seconds!\n".
1585 * Called by centerprint functions
1586 * @param addOneSecond boolean, set to 1 if the welcome-message centerprint asks for the text
1588 string getTimeoutText(float addOneSecond) {
1589 if (!cvar("sv_timeout") || !timeoutStatus)
1592 local string retStr;
1593 if (timeoutStatus == 1) {
1594 if (addOneSecond == 1) {
1595 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime + 1), " seconds!\n");
1598 retStr = strcat("Timeout begins in ", ftos(remainingLeadTime), " seconds!\n");
1602 else if (timeoutStatus == 2) {
1604 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime + 1), " seconds!\n");
1605 //don't show messages like "Timeout ends in 0 seconds"...
1606 if ((remainingTimeoutTime + 1) > 0)
1612 retStr = strcat("Timeout ends in ", ftos(remainingTimeoutTime), " seconds!\n");
1613 //don't show messages like "Timeout ends in 0 seconds"...
1614 if (remainingTimeoutTime > 0)
1623 void player_powerups (void)
1625 if((self.items & IT_USING_JETPACK) && !self.deadflag)
1627 SoundEntity_StartSound(self, CHAN_PLAYER, "misc/jetpack_fly.wav", VOL_BASE, ATTN_IDLE);
1628 self.modelflags |= MF_ROCKET;
1632 SoundEntity_StopSound(self, CHAN_PLAYER);
1633 self.modelflags &~= MF_ROCKET;
1636 self.effects &~= (EF_RED | EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1638 if(!self.modelindex || self.deadflag) // don't apply the flags if the player is gibbed
1643 self.effects |= EF_FULLBRIGHT;
1645 if (self.items & IT_STRENGTH)
1647 play_countdown(self.strength_finished, "misc/poweroff.wav");
1648 if (time > self.strength_finished)
1650 self.alpha = default_player_alpha;
1651 self.exteriorweaponentity.alpha = default_weapon_alpha;
1652 self.items &~= IT_STRENGTH;
1653 sprint(self, "^3Invisibility has worn off\n");
1658 if (time < self.strength_finished)
1660 self.alpha = g_minstagib_invis_alpha;
1661 self.exteriorweaponentity.alpha = g_minstagib_invis_alpha;
1662 self.items |= IT_STRENGTH;
1663 sprint(self, "^3You are invisible\n");
1667 if (self.items & IT_INVINCIBLE)
1669 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1670 if (time > self.invincible_finished)
1672 self.items = self.items - (self.items & IT_INVINCIBLE);
1673 sprint(self, "^3Speed has worn off\n");
1678 if (time < self.invincible_finished)
1680 self.items = self.items | IT_INVINCIBLE;
1681 sprint(self, "^3You are on speed\n");
1687 if (self.items & IT_STRENGTH)
1689 play_countdown(self.strength_finished, "misc/poweroff.wav");
1690 self.effects = self.effects | (EF_BLUE | EF_ADDITIVE | EF_FULLBRIGHT);
1691 if (time > self.strength_finished)
1693 self.items = self.items - (self.items & IT_STRENGTH);
1694 sprint(self, "^3Strength has worn off\n");
1699 if (time < self.strength_finished)
1701 self.items = self.items | IT_STRENGTH;
1702 sprint(self, "^3Strength infuses your weapons with devastating power\n");
1705 if (self.items & IT_INVINCIBLE)
1707 play_countdown(self.invincible_finished, "misc/poweroff.wav");
1708 self.effects = self.effects | (EF_RED | EF_ADDITIVE | EF_FULLBRIGHT);
1709 if (time > self.invincible_finished)
1711 self.items = self.items - (self.items & IT_INVINCIBLE);
1712 sprint(self, "^3Shield has worn off\n");
1717 if (time < self.invincible_finished)
1719 self.items = self.items | IT_INVINCIBLE;
1720 sprint(self, "^3Shield surrounds you\n");
1724 if (cvar("g_fullbrightplayers"))
1725 self.effects = self.effects | EF_FULLBRIGHT;
1727 // midair gamemode: damage only while in the air
1728 // if in midair mode, being on ground grants temporary invulnerability
1729 // (this is so that multishot weapon don't clear the ground flag on the
1730 // first damage in the frame, leaving the player vulnerable to the
1731 // remaining hits in the same frame)
1732 if (self.flags & FL_ONGROUND)
1734 self.spawnshieldtime = max(self.spawnshieldtime, time + cvar("g_midair_shieldtime"));
1736 if (time >= game_starttime)
1737 if (time < self.spawnshieldtime)
1738 self.effects = self.effects | (EF_ADDITIVE | EF_FULLBRIGHT);
1741 float CalcRegen(float current, float stable, float regenfactor)
1743 if(current > stable)
1745 else if(current > stable - 0.25) // when close enough, "snap"
1748 return min(stable, current + (stable - current) * regenfactor * frametime);
1751 void player_regen (void)
1753 float maxh, maxa, maxf, limith, limita, limitf, max_mod, regen_mod, rot_mod, limit_mod;
1754 maxh = cvar("g_balance_health_stable");
1755 maxa = cvar("g_balance_armor_stable");
1756 maxf = cvar("g_balance_fuel_stable");
1757 limith = cvar("g_balance_health_limit");
1758 limita = cvar("g_balance_armor_limit");
1759 limitf = cvar("g_balance_fuel_limit");
1761 max_mod = regen_mod = rot_mod = limit_mod = 1;
1763 if (self.runes & RUNE_REGEN)
1765 if (self.runes & CURSE_VENOM) // do we have both rune/curse?
1767 regen_mod = cvar("g_balance_rune_regen_combo_regenrate");
1768 max_mod = cvar("g_balance_rune_regen_combo_hpmod");
1769 limit_mod = cvar("g_balance_rune_regen_combo_limitmod");
1773 regen_mod = cvar("g_balance_rune_regen_regenrate");
1774 max_mod = cvar("g_balance_rune_regen_hpmod");
1775 limit_mod = cvar("g_balance_rune_regen_limitmod");
1778 else if (self.runes & CURSE_VENOM)
1780 max_mod = cvar("g_balance_curse_venom_hpmod");
1781 if (self.runes & RUNE_REGEN) // do we have both rune/curse?
1782 rot_mod = cvar("g_balance_rune_regen_combo_rotrate");
1784 rot_mod = cvar("g_balance_curse_venom_rotrate");
1785 limit_mod = cvar("g_balance_curse_venom_limitmod");
1786 //if (!self.runes & RUNE_REGEN)
1787 // rot_mod = cvar("g_balance_curse_venom_rotrate");
1789 maxh = maxh * max_mod;
1790 //maxa = maxa * max_mod;
1791 //maxf = maxf * max_mod;
1792 limith = limith * limit_mod;
1793 limita = limita * limit_mod;
1794 //limitf = limitf * limit_mod;
1796 if (!g_minstagib && (!g_lms || cvar("g_lms_regenerate")))
1798 if (self.armorvalue > maxa)
1800 if (time > self.pauserotarmor_finished)
1802 self.armorvalue = max(maxa, self.armorvalue + (maxa - self.armorvalue) * cvar("g_balance_armor_rot") * frametime);
1803 self.armorvalue = max(maxa, self.armorvalue - cvar("g_balance_armor_rotlinear") * frametime);
1806 else if (self.armorvalue < maxa)
1808 if (time > self.pauseregen_finished)
1810 self.armorvalue = CalcRegen(self.armorvalue, maxa, cvar("g_balance_armor_regen"));
1811 self.armorvalue = min(maxa, self.armorvalue + cvar("g_balance_armor_regenlinear") * frametime);
1814 if (self.armorvalue > limita)
1815 self.armorvalue = limita;
1817 if (self.health > maxh)
1819 if (time > self.pauserothealth_finished)
1821 self.health = max(maxh, self.health + (maxh - self.health) * rot_mod*cvar("g_balance_health_rot") * frametime);
1822 self.health = max(maxh, self.health - rot_mod*cvar("g_balance_health_rotlinear") * frametime);
1825 else if (self.health < maxh)
1827 if (time > self.pauseregen_finished)
1829 self.health = CalcRegen(self.health, maxh, regen_mod * cvar("g_balance_health_regen"));
1830 self.health = min(maxh, self.health + regen_mod*cvar("g_balance_health_regenlinear") * frametime);
1833 if (self.health > limith)
1834 self.health = limith;
1836 // if player rotted to death... die!
1838 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
1841 if (self.ammo_fuel > maxf)
1843 if (time > self.pauserotfuel_finished)
1845 self.ammo_fuel = max(maxf, self.ammo_fuel + (maxf - self.ammo_fuel) * rot_mod*cvar("g_balance_fuel_rot") * frametime);
1846 self.ammo_fuel = max(maxf, self.ammo_fuel - rot_mod*cvar("g_balance_fuel_rotlinear") * frametime);
1849 else if (self.ammo_fuel < maxf)
1851 if(self.items & IT_FUEL_REGEN)
1853 if (time > self.pauseregen_finished)
1855 self.ammo_fuel = CalcRegen(self.ammo_fuel, maxf, regen_mod * cvar("g_balance_fuel_regen"));
1856 self.ammo_fuel = min(maxf, self.ammo_fuel + regen_mod*cvar("g_balance_fuel_regenlinear") * frametime);
1860 if (self.ammo_fuel > limitf)
1861 self.ammo_fuel = limitf;
1864 float zoomstate_set;
1865 void SetZoomState(float z)
1867 if(z != self.zoomstate)
1868 ClientData_Touch(self);
1872 void GetPressedKeys(void) {
1873 if (self.movement_x > 0) // get if movement keys are pressed
1874 { // forward key pressed
1875 self.pressedkeys |= KEY_FORWARD;
1876 self.pressedkeys &~= KEY_BACKWARD;
1878 else if (self.movement_x < 0)
1879 { // backward key pressed
1880 self.pressedkeys |= KEY_BACKWARD;
1881 self.pressedkeys &~= KEY_FORWARD;
1885 self.pressedkeys &~= KEY_FORWARD;
1886 self.pressedkeys &~= KEY_BACKWARD;
1889 if (self.movement_y > 0)
1890 { // right key pressed
1891 self.pressedkeys |= KEY_RIGHT;
1892 self.pressedkeys &~= KEY_LEFT;
1894 else if (self.movement_y < 0)
1895 { // left key pressed
1896 self.pressedkeys |= KEY_LEFT;
1897 self.pressedkeys &~= KEY_RIGHT;
1901 self.pressedkeys &~= KEY_RIGHT;
1902 self.pressedkeys &~= KEY_LEFT;
1905 if (self.BUTTON_JUMP) // get if jump and crouch keys are pressed
1906 self.pressedkeys |= KEY_JUMP;
1908 self.pressedkeys &~= KEY_JUMP;
1909 if (self.BUTTON_CROUCH)
1910 self.pressedkeys |= KEY_CROUCH;
1912 self.pressedkeys &~= KEY_CROUCH;
1916 ======================
1917 spectate mode routines
1918 ======================
1920 void SpectateCopy(entity spectatee) {
1921 self.armortype = spectatee.armortype;
1922 self.armorvalue = spectatee.armorvalue;
1923 self.ammo_cells = spectatee.ammo_cells;
1924 self.ammo_shells = spectatee.ammo_shells;
1925 self.ammo_nails = spectatee.ammo_nails;
1926 self.ammo_rockets = spectatee.ammo_rockets;
1927 self.ammo_fuel = spectatee.ammo_fuel;
1928 self.effects = spectatee.effects & EFMASK_CHEAP; // eat performance
1929 self.health = spectatee.health;
1931 self.items = spectatee.items;
1932 self.metertime = spectatee.metertime;
1933 self.strength_finished = spectatee.strength_finished;
1934 self.invincible_finished = spectatee.invincible_finished;
1935 self.pressedkeys = spectatee.pressedkeys;
1936 self.weapons = spectatee.weapons;
1937 self.switchweapon = spectatee.switchweapon;
1938 self.weapon = spectatee.weapon;
1939 self.punchangle = spectatee.punchangle;
1940 self.view_ofs = spectatee.view_ofs;
1941 self.v_angle = spectatee.v_angle;
1942 self.velocity = spectatee.velocity;
1943 self.dmg_take = spectatee.dmg_take;
1944 self.dmg_save = spectatee.dmg_save;
1945 self.dmg_inflictor = spectatee.dmg_inflictor;
1946 self.angles = spectatee.v_angle;
1947 self.fixangle = TRUE;
1948 setorigin(self, spectatee.origin);
1949 setsize(self, spectatee.mins, spectatee.maxs);
1950 SetZoomState(spectatee.zoomstate);
1953 float SpectateUpdate() {
1957 if (self == self.enemy)
1960 if(self.enemy.classname != "player")
1963 SpectateCopy(self.enemy);
1968 float SpectateNext() {
1969 other = find(self.enemy, classname, "player");
1971 other = find(other, classname, "player");
1976 if(self.enemy.classname == "player") {
1978 WriteByte(MSG_ONE, SVC_SETVIEW);
1979 WriteEntity(MSG_ONE, self.enemy);
1980 //stuffcmd(self, "set viewsize $tmpviewsize \n");
1981 if(!SpectateUpdate())
1982 PutObserverInServer();
1991 ShowRespawnCountdown()
1993 Update a respawn countdown display.
1996 void ShowRespawnCountdown()
1999 if(self.deadflag == DEAD_NO) // just respawned?
2003 number = ceil(self.death_time - time);
2006 if(number <= self.respawn_countdown)
2008 self.respawn_countdown = number - 1;
2009 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
2010 announce(self, strcat("announcer/robotic/", ftos(number), ".wav"));
2015 void LeaveSpectatorMode()
2017 if(isJoinAllowed()) {
2018 if(!teams_matter || cvar("g_campaign") || cvar("g_balance_teams") || (self.wasplayer && cvar("g_changeteam_banned"))) {
2019 self.classname = "player";
2020 if(cvar("g_campaign") || cvar("g_balance_teams") || cvar("g_balance_teams_force"))
2021 JoinBestTeam(self, FALSE, TRUE);
2022 if(cvar("g_campaign"))
2023 campaign_bots_may_start = 1;
2024 PutClientInServer();
2025 if(self.classname == "player")
2026 bprint ("^4", self.netname, "^4 is playing now\n");
2027 if(!cvar("g_campaign"))
2028 centerprint(self,""); // clear MOTD
2031 stuffcmd(self,"menu_showteamselect\n");
2036 //player may not join because of g_maxplayers is set
2037 centerprint_atprio(self, CENTERPRIO_MAPVOTE, PREVENT_JOIN_TEXT);
2042 * Determines whether the player is allowed to join. This depends on cvar
2043 * g_maxplayers, if it isn't used this function always return TRUE, otherwise
2044 * it checks whether the number of currently playing players exceeds g_maxplayers.
2045 * @return bool TRUE if the player is allowed to join, false otherwise
2047 float isJoinAllowed() {
2048 if (!cvar("g_maxplayers"))
2052 local float currentlyPlaying;
2053 FOR_EACH_REALPLAYER(e) {
2054 if(e.classname == "player")
2055 currentlyPlaying += 1;
2057 if(currentlyPlaying < cvar("g_maxplayers"))
2064 * Checks whether the client is an observer or spectator, if so, he will get kicked after
2065 * g_maxplayers_spectator_blocktime seconds
2067 void checkSpectatorBlock() {
2068 if(self.classname == "spectator" || self.classname == "observer") {
2069 if( time > (self.spectatortime + cvar("g_maxplayers_spectator_blocktime")) ) {
2070 sprint(self, "^7You were kicked from the server because you are spectator and spectators aren't allowed at the moment.\n");
2076 float vercmp_recursive(string v1, string v2)
2082 dot1 = strstrofs(v1, ".", 0);
2083 dot2 = strstrofs(v2, ".", 0);
2087 s1 = substring(v1, 0, dot1);
2091 s2 = substring(v2, 0, dot2);
2093 r = stof(s1) - stof(s2);
2097 r = strcasecmp(s1, s2);
2110 return vercmp_recursive(substring(v1, dot1 + 1, 999), substring(v2, dot2 + 1, 999));
2113 float vercmp(string v1, string v2)
2115 if(strcasecmp(v1, v2) == 0) // early out check
2117 return vercmp_recursive(v1, v2);
2120 void ObserverThink()
2122 if (self.flags & FL_JUMPRELEASED) {
2123 if (self.BUTTON_JUMP && !self.version_mismatch) {
2124 self.welcomemessage_time = 0;
2125 self.flags &~= FL_JUMPRELEASED;
2126 self.flags |= FL_SPAWNING;
2127 } else if(self.BUTTON_ATCK && !self.version_mismatch) {
2128 self.welcomemessage_time = 0;
2129 self.flags &~= FL_JUMPRELEASED;
2130 if(SpectateNext() == 1) {
2131 self.classname = "spectator";
2135 if (!(self.BUTTON_ATCK || self.BUTTON_JUMP)) {
2136 self.flags |= FL_JUMPRELEASED;
2137 if(self.flags & FL_SPAWNING)
2139 self.flags &~= FL_SPAWNING;
2140 LeaveSpectatorMode();
2145 PrintWelcomeMessage(self);
2148 void SpectatorThink()
2150 if (self.flags & FL_JUMPRELEASED) {
2151 if (self.BUTTON_JUMP && !self.version_mismatch) {
2152 self.welcomemessage_time = 0;
2153 self.flags &~= FL_JUMPRELEASED;
2154 self.flags |= FL_SPAWNING;
2155 } else if(self.BUTTON_ATCK) {
2156 self.welcomemessage_time = 0;
2157 self.flags &~= FL_JUMPRELEASED;
2158 if(SpectateNext() == 1) {
2159 self.classname = "spectator";
2161 self.classname = "observer";
2162 PutClientInServer();
2164 } else if (self.BUTTON_ATCK2) {
2165 self.welcomemessage_time = 0;
2166 self.flags &~= FL_JUMPRELEASED;
2167 self.classname = "observer";
2168 PutClientInServer();
2170 if(!SpectateUpdate())
2171 PutObserverInServer();
2174 if (!(self.BUTTON_ATCK || self.BUTTON_ATCK2)) {
2175 self.flags |= FL_JUMPRELEASED;
2176 if(self.flags & FL_SPAWNING)
2178 self.flags &~= FL_SPAWNING;
2179 LeaveSpectatorMode();
2184 PrintWelcomeMessage(self);
2185 self.flags |= FL_CLIENT | FL_NOTARGET;
2188 .float touchexplode_time;
2194 Called every frame for each client before the physics are run
2197 void() ctf_setstatus;
2198 void() nexball_setstatus;
2200 void PlayerPreThink (void)
2202 self.stat_sys_ticrate = cvar("sys_ticrate");
2203 self.stat_game_starttime = game_starttime;
2204 self.stat_allow_oldnexbeam = cvar("g_allow_oldnexbeam");
2206 if(blockSpectators && frametime)
2207 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2208 checkSpectatorBlock();
2212 if(self.netname_previous != self.netname)
2214 if(cvar("sv_eventlog"))
2215 GameLogEcho(strcat(":name:", ftos(self.playerid), ":", self.netname));
2216 if(self.netname_previous)
2217 strunzone(self.netname_previous);
2218 self.netname_previous = strzone(self.netname);
2222 if(self.version_nagtime)
2223 if(self.cvar_g_nexuizversion)
2224 if(time > self.version_nagtime)
2226 if(strstr(self.cvar_g_nexuizversion, "svn", 0) < 0)
2228 if(strstr(cvar_string("g_nexuizversion"), "svn", 0) >= 0)
2230 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");
2231 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"));
2236 r = vercmp(self.cvar_g_nexuizversion, cvar_string("g_nexuizversion"));
2239 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");
2240 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"));
2244 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");
2245 sprint(self, strcat("\{1}^1NOTE: ^7the server is running ^3Nexuiz ", cvar_string("g_nexuizversion"), "^7, you have ^3Nexuiz ", self.cvar_g_nexuizversion, "^1\n"));
2249 self.version_nagtime = 0;
2253 if(!(self.flags & FL_GODMODE)) if(self.max_armorvalue)
2255 sprint(self, strcat("godmode saved you ", ftos(self.max_armorvalue), " units of damage, cheater!\n"));
2256 self.max_armorvalue = 0;
2260 antilag_record(self);
2262 if(self.classname == "player") {
2263 // if(self.netname == "Wazat")
2264 // bprint(self.classname, "\n");
2266 CheckRules_Player();
2268 PrintWelcomeMessage(self);
2270 if (intermission_running)
2272 IntermissionThink (); // otherwise a button could be missed between
2273 return; // the think tics
2276 if(self.teleport_time)
2277 if(time > self.teleport_time)
2279 self.teleport_time = 0;
2280 self.effects = self.effects - (self.effects & EF_NODRAW);
2283 Nixnex_GiveCurrentWeapon();
2285 if(frametime > 0) // don't do this in cl_movement frames, just in server ticks
2286 UpdateSelectedPlayer();
2288 //don't allow the player to turn around while game is paused!
2289 if(timeoutStatus == 2) {
2290 self.v_angle = self.lastV_angle;
2291 self.angles = self.lastV_angle;
2292 self.fixangle = TRUE;
2298 if (self.deadflag != DEAD_NO)
2300 float button_pressed, force_respawn;
2303 button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
2304 force_respawn = (g_lms || cvar("g_forced_respawn"));
2305 if (self.deadflag == DEAD_DYING)
2308 self.deadflag = DEAD_RESPAWNING;
2309 else if(!button_pressed)
2310 self.deadflag = DEAD_DEAD;
2312 else if (self.deadflag == DEAD_DEAD)
2315 self.deadflag = DEAD_RESPAWNABLE;
2317 else if (self.deadflag == DEAD_RESPAWNABLE)
2320 self.deadflag = DEAD_RESPAWNING;
2322 else if (self.deadflag == DEAD_RESPAWNING)
2324 if(time > self.death_time)
2326 self.death_time = time + 1; // only retry once a second
2330 ShowRespawnCountdown();
2335 if(time > self.touchexplode_time)
2336 if(self.classname == "player")
2337 if(self.deadflag == DEAD_NO)
2338 if not(IS_INDEPENDENT_PLAYER(self))
2339 FOR_EACH_PLAYER(other) if(self != other)
2341 if(time > other.touchexplode_time)
2342 if(other.classname == "player")
2343 if(other.deadflag == DEAD_NO)
2344 if not(IS_INDEPENDENT_PLAYER(other))
2345 if(boxesoverlap(self.absmin, self.absmax, other.absmin, other.absmax))
2347 PlayerTouchExplode(self, other);
2348 self.touchexplode_time = other.touchexplode_time = time + 0.2;
2352 if(g_lms && !self.deadflag && cvar("g_lms_campcheck_interval"))
2356 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
2357 dist = self.prevorigin - self.origin;
2359 self.lms_traveled_distance += fabs(vlen(dist));
2361 if((cvar("g_campaign") && !campaign_bots_may_start) || (time < game_starttime))
2363 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval")*2;
2364 self.lms_traveled_distance = 0;
2367 if(time > self.lms_nextcheck)
2369 //sprint(self, "distance: ", ftos(self.lms_traveled_distance), "\n");
2370 if(self.lms_traveled_distance < cvar("g_lms_campcheck_distance"))
2372 centerprint(self, cvar_string("g_lms_campcheck_message"));
2373 // FIXME KadaverJack: gibbing player here causes playermodel to bounce around, instead of eye.md3
2374 // I wasn't able to find out WHY that happens, so I put a workaround in place that shall prevent players from being gibbed :(
2375 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');
2377 self.lms_nextcheck = time + cvar("g_lms_campcheck_interval");
2378 self.lms_traveled_distance = 0;
2382 self.prevorigin = self.origin;
2384 if ((self.BUTTON_CROUCH && !self.hook.state) || self.health <= g_bloodloss)
2389 self.view_ofs = PL_CROUCH_VIEW_OFS;
2390 setsize (self, PL_CROUCH_MIN, PL_CROUCH_MAX);
2391 setanim(self, self.anim_duck, FALSE, TRUE, TRUE);
2398 tracebox(self.origin, PL_MIN, PL_MAX, self.origin, FALSE, self);
2399 if (!trace_startsolid)
2401 self.crouch = FALSE;
2402 self.view_ofs = PL_VIEW_OFS;
2403 setsize (self, PL_MIN, PL_MAX);
2408 if(self.health <= g_bloodloss && self.deadflag == DEAD_NO)
2410 if(self.bloodloss_timer < time)
2412 self.event_damage(self, self, 1, DEATH_ROT, self.origin, '0 0 0');
2413 self.bloodloss_timer = time + 0.5 + random() * 0.5;
2419 GrapplingHookFrame();
2423 self.items &~= self.items_added;
2427 self.items_added = 0;
2428 if(self.items & IT_JETPACK)
2429 if(self.items & IT_FUEL_REGEN || self.ammo_fuel >= 0.01)
2430 self.items_added |= IT_FUEL;
2432 self.items |= self.items_added;
2440 minstagib_ammocheck();
2444 nexball_setstatus();
2446 self.dmg_team = max(0, self.dmg_team - cvar("g_teamdamage_resetspeed") * frametime);
2448 //self.angles_y=self.v_angle_y + 90; // temp
2450 //if (TetrisPreFrame()) return;
2451 } else if(gameover) {
2452 if (intermission_running)
2453 IntermissionThink (); // otherwise a button could be missed between
2455 } else if(self.classname == "observer") {
2457 } else if(self.classname == "spectator") {
2462 SetZoomState(self.BUTTON_ZOOM || (self.BUTTON_ATCK2 && self.weapon == WEP_NEX));
2464 float oldspectatee_status;
2465 oldspectatee_status = self.spectatee_status;
2466 if(self.classname == "spectator")
2467 self.spectatee_status = num_for_edict(self.enemy);
2468 else if(self.classname == "observer")
2469 self.spectatee_status = num_for_edict(self);
2471 self.spectatee_status = 0;
2472 if(self.spectatee_status != oldspectatee_status)
2474 ClientData_Touch(self);
2476 race_InitSpectator();
2479 if(self.teamkill_soundtime)
2480 if(time > self.teamkill_soundtime)
2482 self.teamkill_soundtime = 0;
2484 entity oldpusher, oldself;
2486 oldself = self; self = self.teamkill_soundsource;
2487 oldpusher = self.pusher; self.pusher = oldself;
2489 PlayerSound(playersound_teamshoot, CHAN_VOICE, VOICETYPE_LASTATTACKER_ONLY);
2491 self.pusher = oldpusher;
2495 if(self.taunt_soundtime)
2496 if(time > self.taunt_soundtime)
2498 self.taunt_soundtime = 0;
2499 PlayerSound(playersound_taunt, CHAN_VOICE, VOICETYPE_AUTOTAUNT);
2502 target_voicescript_next(self);
2508 .float dragspeed; // speed of mouse wheel action
2509 .float dragdistance; // distance of dragentity's draglocalvector from view_ofs
2510 .vector draglocalvector; // local attachment vector of the dragentity
2511 .float draglocalangle;
2514 .float dragmovetype;
2515 void Drag_Begin(entity dragger, entity draggee, vector touchpoint)
2519 draggee.dragmovetype = draggee.movetype;
2520 draggee.draggravity = draggee.gravity;
2521 draggee.movetype = MOVETYPE_WALK;
2522 draggee.gravity = 0.00001;
2523 draggee.flags &~= FL_ONGROUND;
2524 draggee.draggedby = dragger;
2526 dragger.dragentity = draggee;
2528 dragger.dragdistance = vlen(touchpoint - dragger.origin - dragger.view_ofs);
2529 dragger.draglocalangle = draggee.angles_y - dragger.v_angle_y;
2530 touchpoint = touchpoint - gettaginfo(draggee, 0);
2531 tagscale = pow(vlen(v_forward), -2);
2532 dragger.draglocalvector_x = touchpoint * v_forward * tagscale;
2533 dragger.draglocalvector_y = touchpoint * v_right * tagscale;
2534 dragger.draglocalvector_z = touchpoint * v_up * tagscale;
2536 dragger.dragspeed = 64;
2539 void Drag_Finish(entity dragger)
2542 draggee = dragger.dragentity;
2544 dragger.dragentity = world;
2545 draggee.draggedby = world;
2546 draggee.movetype = draggee.dragmovetype;
2547 draggee.gravity = draggee.draggravity;
2549 switch(draggee.movetype)
2554 case MOVETYPE_FLYMISSILE:
2555 case MOVETYPE_BOUNCE:
2556 case MOVETYPE_BOUNCEMISSILE:
2559 draggee.velocity = '0 0 0';
2563 if((draggee.flags & FL_ITEM) && (vlen(draggee.velocity) < 32))
2565 draggee.velocity = '0 0 0';
2566 draggee.flags |= FL_ONGROUND; // floating items are FUN
2570 float Drag_IsDraggable(entity draggee)
2572 // TODO add more checks for bad stuff here
2573 if(draggee.classname == "func_bobbing")
2575 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)
2577 if(draggee.classname == "plat")
2579 if(draggee.classname == "func_button")
2581 if(draggee.model == "")
2583 if(draggee.classname == "spectator")
2585 if(draggee.classname == "observer")
2587 if(draggee.classname == "exteriorweaponentity")
2593 float Drag_MayChangeAngles(entity draggee)
2595 // TODO add more checks for bad stuff here
2596 if(substring(draggee.model, 0, 1) == "*")
2601 void Drag_MoveForward(entity dragger)
2603 dragger.dragdistance += dragger.dragspeed;
2606 void Drag_SetSpeed(entity dragger, float s)
2608 dragger.dragspeed = pow(2, s);
2611 void Drag_MoveBackward(entity dragger)
2613 dragger.dragdistance = max(0, dragger.dragdistance - dragger.dragspeed);
2616 void Drag_Update(entity dragger)
2618 vector curorigin, neworigin, goodvelocity;
2622 draggee = dragger.dragentity;
2623 draggee.flags &~= FL_ONGROUND;
2625 curorigin = gettaginfo(draggee, 0);
2626 curorigin = curorigin + v_forward * dragger.draglocalvector_x + v_right * dragger.draglocalvector_y + v_up * dragger.draglocalvector_z;
2627 makevectors(dragger.v_angle);
2628 neworigin = dragger.origin + dragger.view_ofs + v_forward * dragger.dragdistance;
2629 goodvelocity = (neworigin - curorigin) * (1 / frametime);
2631 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle > 180)
2632 dragger.draglocalangle += 360;
2633 while(draggee.angles_y - dragger.v_angle_y - dragger.draglocalangle <= -180)
2634 dragger.draglocalangle -= 360;
2636 f = min(frametime * 10, 1);
2637 draggee.velocity = draggee.velocity * (1 - f) + goodvelocity * f;
2639 if(Drag_MayChangeAngles(draggee))
2640 draggee.angles_y = draggee.angles_y * (1 - f) + (dragger.v_angle_y + dragger.draglocalangle) * f;
2642 draggee.ltime = max(servertime + serverframetime, draggee.ltime); // fixes func_train breakage
2644 te_lightning1(dragger, dragger.origin + dragger.view_ofs, curorigin);
2647 float Drag_CanDrag(entity dragger)
2649 return (dragger.deadflag == DEAD_NO) || (dragger.classname == "player");
2652 float Drag_IsDragging(entity dragger)
2654 if(!dragger.dragentity)
2656 if(wasfreed(dragger.dragentity) || dragger.dragentity.draggedby != dragger)
2658 dragger.dragentity = world;
2661 if(!Drag_CanDrag(dragger) || !Drag_IsDraggable(dragger.dragentity))
2663 Drag_Finish(dragger);
2669 void Drag_MoveDrag(entity from, entity to)
2673 to.draggedby = from.draggedby;
2674 to.draggedby.dragentity = to;
2675 from.draggedby = world;
2683 Called every frame for each client after the physics are run
2686 .float idlekick_lasttimeleft;
2687 .float race_penalty;
2688 .float race_penalty_nagged;
2689 .float race_penalty_nagtime;
2690 void PlayerPostThink (void)
2692 // Savage: Check for nameless players
2693 if (strlen(self.netname) < 1) {
2694 self.netname = "Player";
2695 stuffcmd(self, "seta _cl_name Player\n");
2698 if(sv_maxidle && frametime)
2700 // WORKAROUND: only use dropclient in server frames (frametime set). Never use it in cl_movement frames (frametime zero).
2702 timeleft = ceil(sv_maxidle - (time - self.parm_idlesince));
2705 bprint("^3", self.netname, "^3 was kicked for idling.\n");
2706 announce(self, "announcer/robotic/terminated.wav");
2710 else if(timeleft <= 10)
2712 if(timeleft != self.idlekick_lasttimeleft)
2714 centerprint_atprio(self, CENTERPRIO_IDLEKICK, strcat("^3Stop idling!\n^3Disconnecting in ", ftos(timeleft), "..."));
2715 announce(self, strcat("announcer/robotic/", ftos(timeleft), ".wav"));
2720 centerprint_expire(self, CENTERPRIO_IDLEKICK);
2722 self.idlekick_lasttimeleft = timeleft;
2726 if(Drag_CanDrag(self))
2727 if(self.BUTTON_DRAG)
2728 if(!self.dragentity)
2729 if(self.cursor_trace_ent)
2730 if(Drag_IsDraggable(self.cursor_trace_ent))
2732 if(self.cursor_trace_ent.draggedby)
2733 Drag_Finish(self.cursor_trace_ent.draggedby);
2734 if(self.cursor_trace_ent.tag_entity)
2735 detach_sameorigin(self.cursor_trace_ent);
2736 Drag_Begin(self, self.cursor_trace_ent, self.cursor_trace_endpos);
2739 if(Drag_IsDragging(self))
2741 if(self.BUTTON_DRAG)
2743 if(self.impulse == 10 || self.impulse == 15 || self.impulse == 18)
2745 Drag_MoveForward(self);
2748 else if(self.impulse == 12 || self.impulse == 16 || self.impulse == 19)
2750 Drag_MoveBackward(self);
2753 else if(self.impulse >= 1 && self.impulse <= 9)
2755 Drag_SetSpeed(self, self.impulse - 1);
2757 else if(self.impulse == 14)
2759 Drag_SetSpeed(self, 9);
2771 if(self.classname == "player") {
2772 CheckRules_Player();
2777 if (intermission_running)
2778 return; // intermission or finale
2780 //if (TetrisPostFrame()) return;
2782 // restart countdown
2783 if(time < game_starttime) {
2784 if (!cvar("sv_ready_restart_after_countdown"))
2786 if(self.movement != '0 0 0' && g_race && !g_race_qualifying)
2788 if(time < game_starttime - 2)
2790 if(!self.race_penalty_nagged)
2792 // TODO better notification for this!
2793 self.race_penalty_nagtime = 0;
2794 self.race_penalty_nagged = 1;
2797 else if(!self.race_penalty)
2799 self.race_penalty_nagtime = 0;
2800 self.race_penalty = time + 5;
2803 if(time > self.race_penalty_nagtime)
2805 if(self.race_penalty > time)
2807 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1FIVE SECONDS PENALTY.");
2809 else if(self.race_penalty_nagged && time < game_starttime - 2)
2811 centerprint_atprio(self, CENTERPRIO_IDLEKICK, "^1DO NOT MOVE DURING THE COUNTDOWN.");
2813 self.race_penalty_nagtime = time + self.cvar_scr_centertime * 0.6;
2815 self.movetype = MOVETYPE_NONE;
2816 self.velocity = '0 0 0';
2817 self.avelocity = '0 0 0';
2818 self.movement = '0 0 0';
2821 else if (time < self.race_penalty)
2823 self.movetype = MOVETYPE_NONE;
2824 self.velocity = '0 0 0';
2825 self.avelocity = '0 0 0';
2826 self.movement = '0 0 0';
2830 //allow the player to move again if sv_ready_restart_after_countdown is not used and countdown is over
2831 if (!cvar("sv_ready_restart_after_countdown"))
2833 if(self.movetype == MOVETYPE_NONE)
2835 self.movetype = MOVETYPE_WALK;
2837 self.race_penalty = 0;
2838 self.race_penalty_nagged = 0;
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);