Merge remote branch 'origin/fruitiex/ctsfix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index 2b8dc18..475771f 100644 (file)
@@ -1270,6 +1270,11 @@ void KillIndicator_Think()
                ClientKill_Now(); // no oldself needed
                return;
        }
                ClientKill_Now(); // no oldself needed
                return;
        }
+    else if(g_cts && self.health == 1) // health == 1 means that it's silent
+    {
+        self.nextthink = time + 1;
+        self.cnt -= 1;
+    }
        else
        {
                if(self.cnt <= 10)
        else
        {
                if(self.cnt <= 10)
@@ -1301,12 +1306,21 @@ void ClientKill_TeamChange (float targetteam) // 0 = don't change, -1 = auto, -2
        entity e;
        killtime = autocvar_g_balance_kill_delay;
 
        entity e;
        killtime = autocvar_g_balance_kill_delay;
 
-       if(g_race_qualifying)
+       if(g_race_qualifying || g_cts)
                killtime = 0;
 
                killtime = 0;
 
+    if(g_cts && self.killindicator && self.killindicator.health == 1) // self.killindicator.health == 1 means that the kill indicator was spawned by CTS_ClientKill
+    {
+               remove(self.killindicator);
+               self.killindicator = world;
+
+        ClientKill_Now(); // allow instant kill in this case
+        return;
+    }
+
        self.killindicator_teamchange = targetteam;
 
        self.killindicator_teamchange = targetteam;
 
-       if(!self.killindicator)
+    if(!self.killindicator)
        {
                if(self.modelindex && self.deadflag == DEAD_NO)
                {
        {
                if(self.modelindex && self.deadflag == DEAD_NO)
                {
@@ -1374,20 +1388,15 @@ void ClientKill (void)
                ClientKill_TeamChange(0);
 }
 
                ClientKill_TeamChange(0);
 }
 
-void CTS_ClientKill_Think (void)
+void CTS_ClientKill (entity e) // silent version of ClientKill, used when player finishes a CTS run. Useful to prevent cheating by running back to the start line and starting out with more speed
 {
 {
-       self = self.owner; // set self to the player to be killed
-       sprint(self, "^1You were killed in order to prevent cheating!");
-       ClientKill_Now();
-}
-
-void CTS_ClientKill (float t) // silent version of ClientKill
-{
-       entity e;
-       e = spawn();
-       e.owner = self;
-       e.think = CTS_ClientKill_Think;
-       e.nextthink = t;
+    e.killindicator = spawn();
+    e.killindicator.owner = e;
+    e.killindicator.think = KillIndicator_Think;
+    e.killindicator.nextthink = time + (e.lip) * 0.05;
+    e.killindicator.cnt = ceil(autocvar_g_cts_finish_kill_delay);
+    e.killindicator.health = 1; // this is used to indicate that it should be silent
+    e.lip = 0;
 }
 
 void DoTeamChange(float destteam)
 }
 
 void DoTeamChange(float destteam)
@@ -2737,7 +2746,7 @@ void PlayerPreThink (void)
                                if(frametime)
                                        player_anim();
                                button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
                                if(frametime)
                                        player_anim();
                                button_pressed = (self.BUTTON_ATCK || self.BUTTON_JUMP || self.BUTTON_ATCK2 || self.BUTTON_HOOK || self.BUTTON_USE);
-                               force_respawn = (g_lms || (g_ca) || autocvar_g_forced_respawn);
+                               force_respawn = (g_lms || g_ca || g_cts || autocvar_g_forced_respawn);
                                if (self.deadflag == DEAD_DYING)
                                {
                                        if(force_respawn)
                                if (self.deadflag == DEAD_DYING)
                                {
                                        if(force_respawn)