1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Team code: Can anyone help me?

Discussion in 'Programming' started by Dexter13, Feb 8, 2002.

  1. Dexter13

    Dexter13 The Coding Machine

    Joined:
    Dec 18, 2001
    Messages:
    111
    Likes Received:
    0
    Hi,
    I want to make it so that a team wins when the other team is eliminated. I have come up with the following code thanks to help from the forum:

    Function CheckTeams()
    {
    local int NumMarine, NumGuer;
    local Pawn P;

    for ( P=Level.PawnList; P!=None; P=P.NextPawn )
    {
    if (P.PlayerReplicationInfo.Team == 0 && !P.PlayerReplicationInfo.bIsSpectator && !P.IsInState('Dying')&& !P.IsInState('GameEnded')&& !P.PlayerReplicationInfo.bWaitingPlayer)
    NumMarine++;
    else if (P.PlayerReplicationInfo.Team == 1 && !P.PlayerReplicationInfo.bIsSpectator && !P.IsInState('Dying')&& !P.IsInState('GameEnded')&& !P.PlayerReplicationInfo.bWaitingPlayer)
    NumGuer++;
    }

    if(NumMarine==0)
    EndGame("lastmanstanding");
    else if(NumGuer==0)
    EndGame("lastmanstanding");


    }

    I call this in the Killed() and logout() functions.
    However, it doesn't seem to work. If one team is eliminated, the game continues.
    I have noticed however, that if if the other team is gone, and I commit suicide, my team then wins!?

    Can anyone please help, I would be most grateful?

    Thanks,
     
  2. RegularX

    RegularX Master of Dagoth Lies

    Joined:
    Feb 2, 2000
    Messages:
    1,215
    Likes Received:
    0
    What's likely happening is your Check isn't passing in time to catch all your newly spectated person.

    So when you suicide, the check passes.

    Place your check in a seperate function, and place a call to that function in a Timer() {} .

    rgx
     
  3. Dexter13

    Dexter13 The Coding Machine

    Joined:
    Dec 18, 2001
    Messages:
    111
    Likes Received:
    0
    Sorry

    Sorry for being naive, but how would I lay out the timer, and where would I put it?

    Thanks again, I really appreciate the help,
     
  4. mr.s-d

    mr.s-d CHiMERiC Moderator

    Joined:
    Aug 30, 2001
    Messages:
    65
    Likes Received:
    0
    Here's some code I wrote ages ago that does what you want:
    Code:
    // Remove frag limit
    event InitGame( string Options, out string Error )
    {
      Super.InitGame(Options, Error);
      
      FragLimit = 0;
      GoalTeamScore = 0;
    }
    
    // Override RestartPlayer() to stop dead players respawning
    function bool RestartPlayer( pawn aPlayer )
    {
      local NavigationPoint startSpot;
      local bool foundStart;
    
      if( bRestartLevel && Level.NetMode!=NM_DedicatedServer && Level.NetMode!=NM_ListenServer )
        return true;
    
      startSpot = FindPlayerStart(aPlayer, 255);
      if(startSpot == None)
      {
        log(" Player start not found!!!");
        return false;
      }
      // Make dead player's become spectators, but not get moved to a PlayerStart
      if (aPlayer.PlayerReplicationInfo.Deaths >= 1)
      {
        if (aPlayer.IsA('TournamentPlayer'))
        {
          aPlayer.bHidden = true;
          aPlayer.PlayerRestartState = 'PlayerSpectating';
          return true;
        }
        else
        {
          aPlayer.PlayerReplicationInfo.bIsSpectator = true;
          aPlayer.PlayerReplicationInfo.bWaitingPlayer = true;
          aPlayer.GotoState('GameEnded');
          return false; // bots don't respawn when they're ghosts
        }
      }
      else
      {
        foundStart = aPlayer.SetLocation(startSpot.Location);
        if(foundStart)
        {
          startSpot.PlayTeleportEffect(aPlayer, true);
          aPlayer.SetRotation(startSpot.Rotation);
          aPlayer.ViewRotation = aPlayer.Rotation;
          aPlayer.Acceleration = vect(0,0,0);
          aPlayer.Velocity = vect(0,0,0);
          aPlayer.SetCollision( true, true, true );
          aPlayer.ClientSetLocation( startSpot.Location, startSpot.Rotation );
          aPlayer.bHidden = false;
          aPlayer.DamageScaling = aPlayer.Default.DamageScaling;
          aPlayer.SoundDampening = aPlayer.Default.SoundDampening;
          aPlayer.JumpZ = aPlayer.Default.JumpZ * PlayerJumpZScaling();
          // Setup player class
          SetupClass(aPlayer);
          AddDefaultInventory(aPlayer);
        }
        else
          log(startspot$" Player start not useable!!!");
    
        if (aPlayer.IsA('TournamentPlayer'))
          TournamentPlayer(aPlayer).StartSpot = LastStartSpot;
        return foundStart;
      }
    }
    
    // Override Killed() to check if all of a team are dead
    function Killed( pawn killer, pawn Other, name damageType )
    {
      Super.Killed(Killer, Other, damageType);
    
      CheckEndGame();
    }
    
    // Check whether an entire team has been killed
    function CheckEndGame()
    {
      local Pawn aPawn;
      local int NumDead[2]; // Number of dead players on each team
      local int InTeam[2]; // Number of players on each team
    
      if ( bGameEnded )
        return;
    
      NumDead[0] = 0;
      NumDead[1] = 0;
      InTeam[0] = 0;
      InTeam[1] = 0;
    
      // Go through player list and calculate number of dead players
      for (aPawn=Level.PawnList; aPawn!=None; aPawn=aPawn.nextPawn)
      {
        if ( aPawn.bIsPlayer )
        {
          InTeam[aPawn.PlayerReplicationInfo.Team]++;
          if (aPawn.PlayerReplicationInfo.Deaths >= 1)
            NumDead[aPawn.PlayerReplicationInfo.Team]++;
        }
      }
      // If an entire team is dead then end the game
      if (NumDead[0] >= InTeam[0])
        EndGame("Team 0 Dead");
      if (NumDead[1] >= InTeam[1])
        EndGame("Team 1 Dead");
    }
    
     

Share This Page