Implement a function to spectate previous player and add possibility to spectate...
authorterencehill <piuntn@gmail.com>
Sun, 14 Apr 2013 10:19:47 +0000 (12:19 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 15 Apr 2013 21:49:32 +0000 (23:49 +0200)
qcsrc/client/hud.qc
qcsrc/server/cl_client.qc

index bf72c2f467bd9b08551278e36b8eb799a47e7d4b..90dac2e096aa333f8029410e5149bb046d1428bb 100644 (file)
@@ -3656,7 +3656,7 @@ void HUD_InfoMessages(void)
                        if(spectatee_status == -1)
                                s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
                        else
                        if(spectatee_status == -1)
                                s = sprintf(_("^1Press ^3%s^1 to spectate"), getcommandkey("primary fire", "+fire"));
                        else
-                               s = sprintf(_("^1Press ^3%s^1 for another player"), getcommandkey("primary fire", "+fire"));
+                               s = sprintf(_("^1Press ^3%s^1 or ^3%s^1 for next or previous player"), getcommandkey("next weapon", "weapnext"), getcommandkey("previous weapon", "weapprev"));
                        drawInfoMessage(s)
 
                        if(spectatee_status == -1)
                        drawInfoMessage(s)
 
                        if(spectatee_status == -1)
index 8d84988b411af58825ad35d31d881c2db231fea1..3f6006838e7665bc31933aa8b5742ce7d5c5cfac 100644 (file)
@@ -2274,6 +2274,44 @@ float SpectateNext()
        return setSpectator();
 }
 
        return setSpectator();
 }
 
+float SpectatePrev()
+{
+       // NOTE: chain order is from the highest to the lower entnum (unlike find)
+       other = findchain(classname, "player");
+       if not(other) // no player
+               return FALSE;
+
+       entity first = other;
+       // skip players until current spectated player
+       if(self.enemy)
+       while(other && other != self.enemy)
+               other = other.chain;
+
+       if (g_ca && !autocvar_g_ca_spectate_enemies && self.caplayer)
+       {
+               do { other = other.chain; }
+               while(other && other.team != self.team);
+
+               if not(other)
+               {
+                       other = first;
+                       while(other.team != self.team)
+                               other = other.chain;
+                       if(other == self.enemy)
+                               return TRUE;
+               }
+       }
+       else
+       {
+               if(other.chain)
+                       other = other.chain;
+               else
+                       other = first;
+       }
+       self.enemy = other;
+       return setSpectator();
+}
+
 /*
 =============
 ShowRespawnCountdown()
 /*
 =============
 ShowRespawnCountdown()
@@ -2458,7 +2496,7 @@ void SpectatorThink()
                if (self.BUTTON_JUMP && !self.version_mismatch) {
                        self.flags &~= FL_JUMPRELEASED;
                        self.flags |= FL_SPAWNING;
                if (self.BUTTON_JUMP && !self.version_mismatch) {
                        self.flags &~= FL_JUMPRELEASED;
                        self.flags |= FL_SPAWNING;
-               } else if(self.BUTTON_ATCK) {
+               } else if(self.BUTTON_ATCK || self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || self.impulse >= 200 && self.impulse <= 209) {
                        self.flags &~= FL_JUMPRELEASED;
                        if(SpectateNext()) {
                                self.classname = "spectator";
                        self.flags &~= FL_JUMPRELEASED;
                        if(SpectateNext()) {
                                self.classname = "spectator";
@@ -2466,6 +2504,16 @@ void SpectatorThink()
                                self.classname = "observer";
                                PutClientInServer();
                        }
                                self.classname = "observer";
                                PutClientInServer();
                        }
+                       self.impulse = 0;
+               } else if(self.impulse == 12 || self.impulse == 16  || self.impulse == 19 || self.impulse >= 220 && self.impulse <= 229) {
+                       self.flags &~= FL_JUMPRELEASED;
+                       if(SpectatePrev()) {
+                               self.classname = "spectator";
+                       } else {
+                               self.classname = "observer";
+                               PutClientInServer();
+                       }
+                       self.impulse = 0;
                } else if (self.BUTTON_ATCK2) {
                        self.flags &~= FL_JUMPRELEASED;
                        self.classname = "observer";
                } else if (self.BUTTON_ATCK2) {
                        self.flags &~= FL_JUMPRELEASED;
                        self.classname = "observer";