Announcement

Collapse
No announcement yet.

Player respawns incorrectly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Player respawns incorrectly

    Hi,

    I am having troubles respawning player-controlled pawns/characters.

    All I did was plot regular playerstarts and leave teamIndex to default value under its properties.

    However, whenever my pawn/character dies it respawns back to player start, but it only shows a floating gun (the link gun).

    My game is a MOBA game so the camera displays the pawn in 3rd person view.

    I figure I might as well show some of my code not sure if this has an affect on the playerstart.

    Code:
    /*General team assignment and behaviour for all bots (minions and turrets)*/
    class GBBotBase extends UTBot;
    
    
    //#TODO Add Textures to the SetSpriteBasedOnIndex function in the GBPawn class
    var protectedwrite int teamIndex;
    function SetTeamIndex(int index)
    {
    	local GBPawn p;
    
    	teamIndex = index;
    	p = GBPawn(Pawn);
    	if (p != None)
    	{
    		p.SetSpriteBasedOnIndex(index);
    	}
    }
    
    function Pawn GetClosestEnemy()
    {
    	local pawn iterpawn, closestPawn;
    	local PlayerController pc;
    	local GBBotBase bot;
    
    	closestPawn = None;
    
    	if (pawn == none || pawn.IsInState('Dead')) return None;// If I don't have a pawn or my pawn is dead, return None
    	foreach AllActors(class'Pawn', iterpawn){// Iterate over all pawns
    		pc = PlayerController(iterPawn.Controller);
    		bot = GBBotBase(iterPawn.Controller);
    
    		if (bot != None && bot.teamIndex != teamIndex || pc != None && teamIndex != 0) {
    			/*check this pawn's distance to my pawn*/
    			if (closestPawn == None || VSize(Pawn.Location - iterpawn.Location) < VSize(pawn.location - closestPawn.Location)) //  If distance is less than currently "closest" distance, set this iterated pawn as the closest pawn
    				closestPawn = iterpawn;
    		}
    	}
    
    	// Return whatever ended up being the closest pawn
    	return closestPawn;
    }
    
    DefaultProperties
    {
    }
    Code:
    /*Bot behaviour in greater detail*/
    class GBBot extends GBBotBase;
    
    var float AggroDistance;
    var float EscapeDistance;
    var float AttackDistance;
    var float PatrolPointReachedThreshold;
    var GBMainPath NextPatrolPoint;
    var GBAISpawner MySpawner;
    
    var private Actor _intermediate;
    var private float _dist;
    
    function EnterPatrolPath(GBMainPath path)
    {
    	NextPatrolPoint = path;
    	MySpawner = GBAISpawner(path);
    
    	if (path != None)
    	{
    		if (!IsInState('FollowingPatrolPath'))
    		{
    			GotoState('FollowingPatrolPath');
    		}
    	}
    	else
    	{
    		GotoState('');
    	}
    }
    
    function PawnDied(Pawn p)
    {
    	if (MySpawner != None)
    		MySpawner.BotsToSpawn++;
    	super.PawnDied(p);
    }
    
    function HuntEnemy(Pawn p)
    {
    	if (P == None) return;
    	Enemy = P;
    	Focus = P;
    	GotoState('HuntingPlayer', 'Begin');
    }
    
    function NotifyTakeHit(Controller InstigatedBy, Vector HitLocation, int Damage, class<DamageType> damageType, Vector momentum)
    {
    	super.NotifyTakeHit(InstigatedBy, HitLocation, Damage, damageType, Momentum);
    	if (InstigatedBy != None && InstigatedBy.Pawn != None)
    	{
    		HuntEnemy(InstigatedBy.Pawn);
    	}
    }
    
    function bool IsPawnTouchingActor(Actor other)
    {
    	if (other == None || Pawn == None) return false;
    
    	return VSize(other.Location - Pawn.Location) <= PatrolPointReachedThreshold;
    }
    
    protected event ExecuteWhatToDoNext()
    {
    	local Pawn potential;
    
    	if (Pawn == None)
    	{
    		Destroy();
    		return;
    	}
    
    	// Should we chase and attack the player?
    
    	// Replace below with:
    	// GetClosestEnemy()
    	// If distance from my pawn to closest enemy is aggrodistance or less, hunt that enemy and return
    
    	potential = GetClosestEnemy();
    	if (potential != None && VSize(Pawn.Location - potential.Location) <= AggroDistance)
    	{
    		HuntEnemy(potential);
    		return;
    	}
    
    	// If not attacking, follow route
    	if (NextPatrolPoint != None)
    	{
    		if (IsPawnTouchingActor(NextPatrolPoint))
    		{
    			NextPatrolPoint = NextPatrolPoint.NextNode;
    		}
    
    		if (NextPatrolPoint != None) GotoState('FollowingPatrolPath', 'Begin');
    	}
    }
    
    function Possess(Pawn aPawn, bool bVehicleTransition)
    {
    	super.Possess(aPawn, bVehicleTransition);
    	if (NextPatrolPoint != None)
    		GotoState('FollowingPatrolPath', 'Begin');
    }
    
    auto state FollowingPatrolPath
    {
    Begin:
    	if (NextPatrolPoint != None)
    	{
    		if (ActorReachable(NextPatrolPoint))
    		{
    			MoveToward(NextPatrolPoint);
    		}
    		else
    		{
    			_intermediate = FindPathToward(NextPatrolPoint);
    			MoveToward(_intermediate);
    		}
    	}
    
    	LatentWhatToDoNext();
    }
    
    state HuntingPlayer
    {
    Begin:
    	if (Enemy != None && Pawn != None)
    	{
    		_dist = VSize(Enemy.Location - Pawn.Location);
    		if (!FastTrace(Enemy.Location, Pawn.location) && _dist > EscapeDistance)
    		{
    			Enemy = None;
    		}
    		else if (_dist <= AttackDistance)
    		{
    			if (Pawn.Weapon != Pawn.InvManager.GetBestWeapon())
    				SwitchToBestWeapon();
    			FireWeaponAt(Enemy);
    		}
    		else
    		{
    			if (ActorReachable(Enemy))
    			{
    				MoveToward(Enemy);
    			}
    			else
    			{
    				_intermediate = FindPathToward(Enemy);
    				MoveToward(Enemy);
    			}
    		}
    	}
    	LatentWhatToDoNext();
    }
    
    DefaultProperties
    {
    	PatrolPointReachedThreshold=50
    	AggroDistance=600
    	EscapeDistance=1500
    	AttackDistance=300
    }
    Code:
    /*Spawn definition for the minions*/
    class GBAISpawner extends GBMainPath
    	placeable
    	ClassGroup(GB);
    var(Spawner) int teamIndex;
    var(Spawner) int BotsToSpawn;
    var(Spawner) float SpawnInterval;
    
    function PostBeginPlay()
    {
    	super.PostBeginPlay();
    	SetTimer(SpawnInterval, true);
    }
    
    function Timer()
    {
    	if (BotsToSpawn <= 0)
    	{
    		return;
    	}
    
    	if (SpawnBot() != None)	BotsToSpawn--;
    }
    
    function GBBot SpawnBot()
    {
    	local GBBot NewBot;
    	local Pawn NewPawn;
    	local rotator StartRotation;
    	
    	NewBot = Spawn(class'GBBot');
    	if (NewBot == None)
    	{
    		`log("Couldn't spawn "$class'GBBot'$" at "$self);
    		return None;
    	}
    
    	StartRotation = Rotation;
    	StartRotation.Yaw = Rotation.Yaw;
    
    	NewPawn = Spawn(class'UTPawn',,,Location,StartRotation);
    	if ( NewPawn == None )
    	{
    		`log("Couldn't spawn "$class'UTPawn'$" at "$self);
    		NewBot.Destroy();
    		return None;
    	}
    
    	NewPawn.SetAnchor(self);
    	NewPawn.LastStartTime = WorldInfo.TimeSeconds;
    	NewBot.Possess(NewPawn, false);
    	NewBot.Pawn.PlayTeleportEffect(true, true);
    	NewBot.ClientSetRotation(NewBot.Pawn.Rotation, TRUE);
    	WorldInfo.Game.AddDefaultInventory(NewPawn);
    	WorldInfo.Game.SetPlayerDefaults(NewPawn);
    
    	NewBot.EnterPatrolPath(self);
        //#TODO BOTS INVENTORY INITIALIZATION HERE
    
    
    	// Assign my team index to the spawned bot
    	NewBot.SetTeamIndex(teamIndex);
    
    	return NewBot;
    }
    
    DefaultProperties
    {
    	Begin Object Name=Sprite
    		Sprite=Texture2D'EnvyEditorResources.S_Player_Red'
    	End Object
    
    	BotsToSpawn = 4
    	SpawnInterval = 4
    
    	bStatic = false
    }
Working...
X