Team Game Score off by one

Discussions about Coding and Scripting
Post Reply
-=CoN=-Strych9
Average
Posts: 34
Joined: Wed Jun 19, 2013 2:17 am

Team Game Score off by one

Post by -=CoN=-Strych9 » Sat Dec 31, 2016 2:57 am

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

User avatar
sektor2111
Godlike
Posts: 4138
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Team Game Score off by one

Post by sektor2111 » Sat Dec 31, 2016 9:24 am

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...

-=CoN=-Strych9
Average
Posts: 34
Joined: Wed Jun 19, 2013 2:17 am

Re: Team Game Score off by one

Post by -=CoN=-Strych9 » Sat Dec 31, 2016 4:30 pm

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

User avatar
sektor2111
Godlike
Posts: 4138
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Team Game Score off by one

Post by sektor2111 » Sat Dec 31, 2016 4:41 pm

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.

User avatar
Barbie
Godlike
Posts: 1722
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Team Game Score off by one

Post by Barbie » Sat Dec 31, 2016 7:08 pm

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
Show

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
		}
	}
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett

-=CoN=-Strych9
Average
Posts: 34
Joined: Wed Jun 19, 2013 2:17 am

Re: Team Game Score off by one

Post by -=CoN=-Strych9 » Sat Dec 31, 2016 11:35 pm

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

Post Reply