Announcement

Collapse
No announcement yet.

PlayerController enters NormPlay state on game start, but then immediately leaves

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

    PlayerController enters NormPlay state on game start, but then immediately leaves

    In my PlayerController class I am attempting to implement states. I'm very new to states, so I just added a single state, NormPlay. When I load the game, the log shows the state being entered, and then immediately exiting before play begins. I can't think what is wrong, though if I'm lucky it's something very simple

    Here's the state:

    Code:
    auto state NormPlay
    {	
    	event BeginState(Name PreviousStateName)
    	{
    		`log("Entering state "$GetStateName());
    	}
    	
    	event EndState(Name NextStateName)
    	{
    		`log("Leaving state "$GetStateName());
    	}
      Begin:
    }
    And here's the relevant log:

    Code:
    [0002.35] Log: Game class is 'SpacePiratesGameInfo'
    [0002.36] Log: Primary PhysX scene will be in software.
    [0002.36] Log: Creating Primary PhysX Scene.
    [0002.37] Log: Bringing World exampleentry.TheWorld up for play (0) at 2013.03.26-20.38.23
    [0002.37] Log: Bringing up level for play took: 0.009413
    [0002.37] ScriptLog: Entering state NormPlay
    [0002.37] ScriptLog: Leaving state NormPlay
    [0002.37] Error: Can't start an online game that hasn't been created
    [0002.37] Error: StartLocalVoiceProcessing(): Device is currently owned by another user
    [0002.37] Log: ########### Finished loading level: 0.351185 seconds
    [0002.37] Init: Game engine initialized
    [0002.37] Log: Initializing Engine Completed
    [0002.37] Log: >>>>>>>>>>>>>> Initial startup: 2.37s <<<<<<<<<<<<<<<
    I'm not sure if the rest of the class is relevant, but if it is...:

    Code:
    class SpacePiratesPlayerController extends UDKPlayerController
        config(Game);
    
    var SpacePiratesPawn SPPawn;
    
    var float CurrentFOV;
    var float NewFOV; // Desired FOV
    
    var int HUDCurrentOpacity;
    var bool bHUDOn;
    var float HUDFadeOutRate; // How fast fade out
    var float HUDFadeInRate; // How fast fade in
    var float HUDFadeOutTime; // Time to stay visible
    
    var bool bInCombat; // Player is in combat
    var bool bInvMenu; // Player is using inventory menu
    
    simulated event PostBeginPlay()
    {
        Super.PostBeginPlay();
        
        NewFOV = DefaultFOV;
    }
    
    /*
    exec function ToggleInvMenu()
    {
    	bInvMenu = !bInvMenu;
    	if (bInvMenu)
    	{
    		ActivateInvMenu();
    	}
    	else
    	{
    		DeactivateInvMenu();
    	}
    }
    */
    
    exec function StartFire ( optional byte FireModeNum )
    {
    	Super.StartFire(FireModeNum);
    	FadeInHUD();
    }
    
    exec function StopFire( optional byte FireModeNum )
    {
    	Super.StopFire(FireModeNum);
    	FadeInHUD();
    }
    
    exec function Reload()
    {
    	FadeInHUD();
    }
    
    exec function use() // Only for debug purposes, remove eventually
    {
        local vector X,Y,Z;
        
        if( Pawn != none && Pawn.Weapon != none )
        {
            GetAxes(Pawn.Rotation,X,Y,Z);
            
            Pawn.Weapon.DropFrom(Pawn.Location + X * 82 + vect(0,0,16), vect(0,0,0));
        }
        
        FadeInHUD();
    }
    
    simulated function ActivateInvMenu()
    {
    	// bInvMenu already set correctly in exec function
    	if( !IsPaused() )
    		Pause();
    	SpacePiratesInventoryManager(Pawn.InvManager).bInvMenuOpen = true;
    }
    
    simulated function DeactivateInvMenu()
    {
    	// bInvMenu already set correctly in exec function
    	if( IsPaused() )
    		Pause();
    	SpacePiratesInventoryManager(Pawn.InvManager).bInvMenuOpen = false;
    }
    
    simulated function FadeInHUD()
    {
    	bHUDOn = true;
    	if (IsTimerActive('FadeOutHUD')) {
    		ClearTimer('FadeOutHUD');
    	}
    	SetTimer(HUDFadeOutTime,,'FadeOutHUD');
    }
    
    simulated function FadeOutHUD()
    {
    	if (!SpacePiratesWeaponBase(Pawn.Weapon).PlayerIsAiming())
    		bHUDOn = false;
    }
    
    exec function StartWeaponZoom()
    {
        local SpacePiratesWeaponBase SPWeapon;
        
        SPWeapon = SpacePiratesWeaponBase(Pawn.Weapon);
        
        if( SPWeapon != none )
        {
            NewFOV = SPWeapon.AimZoomAmount;
            SPWeapon.bAiming = true;
        }
        
        FadeInHUD();
    }
    
    exec function StopWeaponZoom()
    {
        local SpacePiratesWeaponBase SPWeapon;
        
        SPWeapon = SpacePiratesWeaponBase(Pawn.Weapon);
        
        NewFOV = PlayerCamera.DefaultFOV;
        
        if( SPWeapon != none )
        {
            SPWeapon.bAiming = false;
        }
    	
    	FadeInHUD();
    }
    
    event PlayerTick( float DeltaTime )
    {
    	local SpacePiratesHUDBase SPHUD;
    	
        Super.PlayerTick(DeltaTime);
        
        // Interp to desired FOV (NewFOV)
        CurrentFOV = PlayerCamera.GetFOVAngle();
        
        PlayerCamera.SetFOV(FInterpTo(CurrentFOV, NewFOV, DeltaTime, 10.f));
        
        if (myHUD != none)
        {
        	SPHUD = SpacePiratesHUDBase(myHUD);
    
        	if (bHUDOn && SPHUD.masterOpacity < 255 || bInCombat && SPHUD.masterOpacity < 255)
        		HUDCurrentOpacity += HUDFadeInRate;
        	else if (!bHUDOn && SPHUD.masterOpacity > 0 && !bInCombat)
        		HUDCurrentOpacity -= HUDFadeOutRate;
        	
        	SPHUD.masterOpacity = Clamp(HUDCurrentOpacity,0,255);
    		
    		if (Pawn.Weapon != none)
    			SpacePiratesWeaponBase(Pawn.Weapon).masterOpacity = Clamp(HUDCurrentOpacity,0,255);
        }
    }
    
    /* Double click fire delay fix */
    simulated function BurstWeaponModify()
    {
        local vector2D MPos;
    
        if (LocalPlayer(Player) != None)
        {
            MPos = LocalPlayer(Player).ViewportClient.GetMousePosition();
            LocalPlayer(Player).ViewportClient.SetMouse(MPos.X, MPos.Y+2);
        }
    }
    
    event Possess( Pawn aPawn, bool bVehicleTransition )
    {
        if ( SpacePiratesPawn(Pawn) != none )
        {
            SPPawn = SpacePiratesPawn(Pawn);
        }
        
        super.Possess(aPawn, bVehicleTransition);
    }
    
    auto state NormPlay
    {	
    	event BeginState(Name PreviousStateName)
    	{
    		`log("Entering state "$GetStateName());
    	}
    	
    	event EndState(Name NextStateName)
    	{
    		`log("Leaving state "$GetStateName());
    	}
      Begin:
    }
    
    defaultproperties
    {
        CameraClass=class'SpacePiratesGame.SpacePiratesCamera'
        
        DefaultFOV = 70.f
        
    	bHUDOn = false
    	HUDFadeOutRate = 5.f
    	HUDFadeInRate = 15.f
    	HUDFadeOutTime = 4.f // Seconds until fade out
    }

    #2
    Try adding LandmovementState = NormPlay
    to the pawns defaultproperties :P

    Comment


      #3
      I had just wondered if there wasn't something going on in the parent states right before you posted that lol. Thanks a lot, I put that in the Pawn's default properties and now it's working!

      Comment

      Working...
      X