Announcement

Collapse
No announcement yet.

Replacing PlayerController

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

    Replacing PlayerController

    I made a custom PlayerController class, but I'm not sure what I'm doing wrong to replace it in my mutator...

    Code:
    class MutQUB extends Mutator;
    
    function bool CheckReplacement(Actor Other, out byte bSuperRelevant)
    {
    	bSuperRelevant = 0;
    
    	if(Other.IsA('xPlayer'))
    	{
    		if(!Other.IsA('QUBPC'))
    		{
    			ReplaceWith( Other, "QUB.QUBPC");
    			return false;
    		}
    		return true;
    	}
    
    	return true;
    }
    Code:
    class QUBPC extends xPlayer;
    
    exec function Say( string Msg )
    {
    	Msg = "This is a test.";
    
    	if ( AllowTextMessage(Msg) )
    		ServerSay(Msg);
    }

    When I try to play a level with the mutator enabled it crashes and tells me...

    UT2004 Build UT2004_Build_[2005-02-15_17.02]

    Could not spawn player

    History: MatchViewportsToActors <- (DM-DE-Grendelkeep) <- ClientInit <- UGameEngine::LoadMap <- LocalMapURL <- UGameEngine::Browse <- ClientTravel <- UGameEngine::Tick <- Level Grendelkeep <- UpdateWorld <- MainLoop <- FMallocWindows::Free <- FMallocWindows::Realloc <- 676F4C57 0 FArray <- FArray::Realloc <- 0*2 <- FMallocWindows::Free


    I have tried using CheckReplacement and subclassing my class from both xPlayer and PlayerController, they both seem to give the same error. What am I doing wrong?

    #2
    Code:
    event PreBeginPlay()
    {
        Level.Game.PlayerControllerClass = class'MyPlayerController';
        Level.Game.PlayerControllerClassName = "MyPlayerController";
    }

    Comment


      #3
      Actually, the following code is a better (package name is required in string representations of classes):

      Code:
      event PreBeginPlay()
      {
          Level.Game.PlayerControllerClass = class'MyPlayerController';
          Level.Game.PlayerControllerClassName = string(Level.Game.PlayerControllerClass);
      }
      Anyway, replacing core elements, like the playercontroller, is something mutators shouldn't do. Because it might break compatibility with other mods. So try to avoid it as much as possible.
      And if you do replace is make sure you triple check the replacement, e.g. if the original playercontrollerclass is not what you expected it to be abort, and also check if the playercontrollerclass was changed again after you did it (e.g. an other mod might have changed it too).

      Comment


        #4
        Another useful tip is when aborting, log the string of the playercontroller that WAS found so the admin or whomever can know that another mutator is causing a conflict.

        Comment


          #5
          Thanks very much all, for the insight.

          Comment

          Working...
          X