UE3 - UT3 Checking Team Number

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

inferyes

Spaced In
Aug 16, 2009
504
0
0
I wrote a mutator that checks the team of a player/bot and then changes there inventory items but there are some problems.

If I use TeamNum = GetTeamNum() to get the team index of a player. It works and compiles and the team number is correct ingame but for some reason it makes bots and players take no damage and makes bots randomly clip through walls.

How do I fix this? What is the proper way to check a team?

Here is my code:

Code:
class UTMutator_Zombies extends UTMutator;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	WorldInfo.Game.DefaultPawnClass = class'ZombiesMutator.UTPawn_Zombies';

}

defaultproperties
{
}

Code:
class UTPawn_Zombies extends UTPawn;

var int BigFatZero;
var int TeamIndex;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	SetTimer(0.1,true);
}

function Timer()
{
	Super.PostBeginPlay();

	TeamIndex = GetTeamNum();

	if(TeamIndex == 0)
	{
		loginternal("Red Team!");
	}

	if(TeamIndex == 1)
	{
		loginternal("Blue Team!");
	}
}

defaultproperties
{
	BigFatZero=0;
	TeamIndex=0;
}
 
Last edited:

inferyes

Spaced In
Aug 16, 2009
504
0
0
That fixed it. I really don't understand what Super does but the tutorial was telling me to put on there so I did. Guess that was causing some problems with the UTPawn class.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
What is the easiest way to check if a player has died and what is the command to force a player to change teams. I've tried if(Health <= 0) but it doesn't seem to work.

if ( Health <= 0 )
{
loginternal("A survivor has died! Switch him to the zombie team!");
}
 
Last edited:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
That fixed it. I really don't understand what Super does but the tutorial was telling me to put on there so I did. Guess that was causing some problems with the UTPawn class.

It calls the Super or inherited class (see extends/expands class declaration). It can be required in some cases but not if you want to completely override a method. Some checking is needed to see whether overriding risks breaking something upstream.

What is the easiest way to check if a player has died

You can use PreventDeath() in Mutator:
http://wiki.beyondunreal.com/UE3:Mutator_(UDK)#PreventDeath
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
It just returns "Bad or missing expression" when I use it like this.

var bool PlayerDead;
PlayerDead = PreventDeath();

Is there any way to check if a players dead when extending UTPawn? That's what I'm trying to do.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
You need to override the PreventDeath function and put your own code in there. It's called each time a player has been fragged. The reason it's called PreventDeath is that you can stop the frag taking place but you can just intercept the call, execute your code and let things happen normally.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Oh I see. The only problem is that most of my code is in a UTPawn Extension. I guess it would be fine to have this portion of the code in the mutator but I'd perfer it to be in the UTPawn.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
I can't remember if Pawns support some sort of die function. They might but I've never experimented because replacing standard PlayerPawns is a pain in the ass because you need to handle the ReplicationInfo properly. TNSe managed to do this with UTPure on UT1 to foil some hacking techniques but some people didn't approve of the approach because it breaks a few things (it's incompatible with RocketArena for one). You should dig through the standard classes to see where the messages that trigger PreventDeath come from. It's probably linked to the Gametype.
 
Last edited:

inferyes

Spaced In
Aug 16, 2009
504
0
0
Alright. From what I've read about overriding a function, I should just copy the script from UTpawn into my script that extends the UTpawn and then modify it to my liking (leaving the original functionality intact). Correct?

And btw guys. I really appreciate the help.
 
Last edited:

inferyes

Spaced In
Aug 16, 2009
504
0
0
Alright. So I'm looking through the TeamInfo class and I found this:

Code:
		Other.PlayerReplicationInfo.TeamID = 0;

Is this the command I would use to change a players team? And how would I use this in my new UTPawn script?

Is it possible to include this command from teaminfo and then use it in my UTPawn extender?


Scroll down here. The part is bolded out where I need the player to be switched to the blue team. This script works fine in-game (it logs when a player on the Survivor, red team, is killed).
Code:
class UTPawn_Zombies extends UTPawn;

var int BigFatZero;
var int TeamIndex;

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();
	SetTimer(0.01,true);
}

function Timer()
{
	TeamIndex = GetTeamNum();

	if(TeamIndex == 0)
	{
	UTGame(WorldInfo.Game).DefaultInventory[0] = class'UTWeap_RocketLauncher';
	UTGame(WorldInfo.Game).DefaultInventory[1] = class'UTWeap_Enforcer';
	}

	if(TeamIndex == 1)
	{
	UTGame(WorldInfo.Game).DefaultInventory[1] = class'UTWeap_ImpactHammer';
	UTGame(WorldInfo.Game).DefaultInventory[0] = class'UTWeap_ShockRifle';
	bCanPickupInventory = false;
	}
}

function bool Died(Controller Killer, class<DamageType> damageType, vector HitLocation)
{

	if(TeamIndex == 0)
	{
		LogInternal("A survivor has died! Please switch me to the Zombie team!");
[B]/// THIS IS WHERE I NEED THE GAME TO SWITCH THIS PLAYER TO THE ZOMBIE TEAM![/B]
	}

	if (Super.Died(Killer, DamageType, HitLocation))
	{
		StartFallImpactTime = WorldInfo.TimeSeconds;
		bCanPlayFallingImpacts=true;
		if(ArmsMesh[0] != none)
		{
			ArmsMesh[0].SetHidden(true);
			if(ArmsOverlay[0] != none)
			{
				ArmsOverlay[0].SetHidden(true);
			}
		}
		if(ArmsMesh[1] != none)
		{
			ArmsMesh[1].SetHidden(true);
			if(ArmsOverlay[1] != none)
			{
				ArmsOverlay[1].SetHidden(true);
			}
		}
		SetPawnAmbientSound(None);
		SetWeaponAmbientSound(None);
		return true;
	}
	return false;
}

defaultproperties
{
	BigFatZero=0;
	TeamIndex=0;
}

You guys have really helped me a lot so far. Even though I am asking a lot of questions I am researching and learning things on my own as well.
 
Last edited:

inferyes

Spaced In
Aug 16, 2009
504
0
0
Okay. I got a script that causes a team switch when a player dies but there is one annoying problem. Instead of switching the player who died it switches all the players regardless of which player died. So if anyone on red team dies EVERYONE gets switched to blue team.

How the hell do I fix this? Here is my code.

Code:
simulated function bool Died(Controller Killer, class<DamageType> damageType, vector HitLocation)
{
	if(TeamIndexZombies == 0)
	{
		LogInternal("A survivor has died! Please switch me to the Zombie team!");
		self.PlayerReplicationInfo.Team.TeamIndex = 1;
	}
BLAH BLAH BLAH rest of the Died() code.
 

brold9999

New Member
Apr 5, 2009
142
0
0
It looks like you are changing the team index of the team itself, not what team the player is on.

You might want to take a look at ChangeTeam and SetTeam in UTTeamGame.uc.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
This is driving me insane. I used this command in my overrided Died() function and this will compile if I put:
Self.PlayerReplicationInfo.Team = none;
It works fine and compiles and when ingame switches a dead player to the "no team" team basically making them able to kill both red and blue. But if I try to put anything but "none" in that = expression it ****s up when I try to compile and says mismatch. Here's everything I've tried.

Self.PlayerReplicationInfo.Team = 1;
Self.PlayerReplicationInfo.Team = Blue;
Self.PlayerReplicationInfo.Team = BlueTeam;
Self.PlayerReplicationInfo.Team = 'Blue';
Self.PlayerReplicationInfo.Team = 'Blue Team';
Self.PlayerReplicationInfo.Team = "Blue";
Self.PlayerReplicationInfo.Team = Team[1];

And so on and so on. What the hell is the syntax for this command? It's not listed in the stupid UTTeamGame.uc at all.

edited-
I can't write coherent posts when I'm annoyed.
 
Last edited:

brold9999

New Member
Apr 5, 2009
142
0
0
A player replication info's team variable can only be set to a team object. Having said that, you should probably be *calling* ChangeTeam or SetTeam rather than setting PlayerReplicationInfo.Team directly.

You mentioned earlier that you were following a tutorial. Does it not have the answers you need?
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
How do I call the setteam() from a class extending UTPawn?

And no. I've been writing this mutator from memory. I wrote the first partially from a tutorial but mostly from studying the UT game source.
 

brold9999

New Member
Apr 5, 2009
142
0
0
This is getting down to the nitty gritty. Fixing a type mismatch, and using dereferences to call a function in another object are basic skills that you can get from tutorials or the Unreal Wiki.
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Can I have a Global Variable in 1 class and then check to see when it's true in another class? That would solve my problem I believe.

edit-

Is there a way to call a function from another class that your not extending? That would make things easier.
 
Last edited: