Page 1 of 1

Team Game Score off by one

Posted: Sat Dec 31, 2016 2:57 am
by -=CoN=-Strych9
Hello,

I am working on a small project and had a question about team score. I have the following code:

Code: Select all


function ScoreKill (Pawn Killer, Pawn Other)
{
   local Pawn p;
   local TeamInfo bestTeam;
   local TeamGamePlus teamGame;
   local int index;

  super.ScoreKill(Killer,Other);
  teamGame = TeamGamePlus(level.game);
  if (Killer.bIsPlayer && Level.Game.IsA('TeamGamePlus'))
  {
		for (index = 0; index < teamGame.maxTeams; index++)
        {
			if ((bestTeam == none) || (bestTeam.score < teamGame.teams[index].score))
            {
				bestTeam = teamGame.teams[index];
  	        }
		}
		if (Killer.PlayerReplicationInfo.Team == BestTeam.TeamIndex)
		{
  		     //do something here. code not written yet
		}
  }

  if (NextMutator != none)
       NextMutator.ScoreKill(Killer, Other);
}
The problem is that the team score is always off by 1. For example, if the score is Red 2 and Blue 0 and blue kills someone the code displays Red 2 - Blue 0 but the score is Red 2 - Blue 1. Next blue kills someone and the code displays Red 2 - Blue 1 and the score is actually Red 2 - Blue 2. It just seems that the teamscore has not updated when scorekill happens. What can I use to get the current teamscore at this point?

Thank you in advance for the help!

S9

Re: Team Game Score off by one

Posted: Sat Dec 31, 2016 9:24 am
by sektor2111
First problem is you don't have sanity checks. What does exactly hurts in wrapping codes first ?

Code: Select all

if (Killer != None)
then

Code: Select all

if (killer.PlayerreplicationInfo != None)
if you want to access playerreplicationInfo.score, and it's the same for everything which is accessed. bIsPlayer is not that relevant.
Aside doesn't hurt a check "if (teamGame != None)". Then if you want to update each time team Score you have to deliver a point for Killer's team with any matter not only if is in the best team

Code: Select all

if (Killer !=None && Killer.PlayerReplicationInfo != None && Other.PlayerReplicationInfo != None )
{
		if ( Killer == Other )
			Teams[Other.PlayerReplicationInfo.Team].Score -= 1;
		else if ( Killer.PlayerReplicationInfo.Team != Other.PlayerReplicationInfo.Team )
			Teams[Killer.PlayerReplicationInfo.Team].Score += 1;
}
I can copy paste more from TeamGamePlus if you cannot use copy-paste...

Code: Select all

function bool SetEndCams(string Reason)
{
	local TeamInfo BestTeam;
	local int i;
	local pawn P, Best;
	local PlayerPawn player;

	// find individual winner
	for ( P=Level.PawnList; P!=None; P=P.nextPawn )
		if ( (P.bIsPlayer && P.PlayerReplicationInfo != None) && ((Best == None) || (P.PlayerReplicationInfo.Score > Best.PlayerReplicationInfo.Score)) )
			Best = P;

	// find winner
	BestTeam = Teams[0];
	for ( i=1; i<MaxTeams; i++ )
		if ( Teams[i].Score > BestTeam.Score )
			BestTeam = Teams[i];

	for ( i=0; i<MaxTeams; i++ )
		if ( (BestTeam.TeamIndex != i) && (BestTeam.Score == Teams[i].Score) )
		{
			BroadcastLocalizedMessage( DMMessageClass, 0 );
			return false;
		}
....
Codes exist more or less fine tuned...

Re: Team Game Score off by one

Posted: Sat Dec 31, 2016 4:30 pm
by -=CoN=-Strych9
Thank you for the reply, however I am not wanting to update the score, I am only wanting to check the current score after a kill.

Thank you,

S9

Re: Team Game Score off by one

Posted: Sat Dec 31, 2016 4:41 pm
by sektor2111
Then look well at MOMENT when your check do happens, it should be done "later" or even externally checked VIA something similar to CTFAnnouncer, this is not a need to happen all time in ScoreKill or whatever kill instance.

Re: Team Game Score off by one

Posted: Sat Dec 31, 2016 7:08 pm
by Barbie
Because of the last two code lines ("NextMutator") in your first post I assume that your ScoreKill() is a Mutator function and not the ScoreKill() of GameInfo.

You may run into problems if NextMutator is not None, because it is called twice then: first time in Super.ScoreKill() (have a look at Mutator.ScoreKill() code) and the next time in your code statement NextMutator.ScoreKill(Killer, Other).

Attached a (untested) corrected code snippet:
Spoiler

Code: Select all

function ScoreKill (Pawn Killer, Pawn Other) {
local TeamInfo bestTeam;
local TeamGamePlus teamGame;
local int index;

	super.ScoreKill(Killer,Other);
	if (Killer == None || Killer.PlayerReplicationInfo == None)
		return;
	teamGame = TeamGamePlus(level.game);
	if (Killer.bIsPlayer && teamGame != None)
	{
		for (index = 0; index < teamGame.maxTeams; index++)
			if ((bestTeam == none) || (bestTeam.score < teamGame.teams[index].score))
				bestTeam = teamGame.teams[index];

		if (Killer.PlayerReplicationInfo.Team == BestTeam.TeamIndex)
		{
			//do something here. code not written yet
		}
	}
}

Re: Team Game Score off by one

Posted: Sat Dec 31, 2016 11:35 pm
by -=CoN=-Strych9
Thank you! I will look at both, however the NextMutator was not always in there, I was just trying to see if it would work.

Thanks again

S9