x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to Reset Player, Sending Him back to Player Start?

A little background may help to give context to what I am wanting to do. I have a multiplayer game and I want to create a way for players to switch teams whenever they want. I currently have a rough version working by doing the following:

 void AArenaPlayerController::ChangeTeam()
 {
     if (Role == ROLE_Authority)
     {
         AArenaPlayerState* CharacterState = Cast<AArenaPlayerState>(PlayerState);
         if (CharacterState)
         {
             CharacterState->ChangeTeam();
             GetWorld()->GetAuthGameMode()->RestartPlayer(this);
          }
     }
     else
     {
         ServerChangeTeam();
     }
 }

What I want to happen is that upon changing teams you spawn at the enemies base with full health, almost like you died and respawned. However GetWorld()->GetAuthGameMode()->RestartPlayer(this); doesn't accomplish this. Is there a way to basically tell the character to reset, or restart, or respawn?

Product Version: UE 4.10
Tags:
more ▼

asked Jan 28 '16 at 06:19 AM in C++ Programming

avatar image

Janyx
472 66 63 211

avatar image BrUnO XaVIeR Jan 28 '16 at 06:24 AM

Right after restarting player state, move character into new ally base with 'Set Actor Position' functions.

avatar image Janyx Jan 28 '16 at 07:10 AM

I was hoping there would be an easier way than to look at all the player starts and figure out which one works.

avatar image falola Dec 30 '16 at 10:58 AM

You can get all actors of class "PlayerStart" and from there figure out which one is the best

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Kudos to @BrUnO XaVIeR @falola. I didn't use their suggestions but in reality their suggestions are as good as mine. In order to close the thread I'll post my solution.

I simply changed the players team number than destroyed the character. The restart logic was already built to spawn players at PlayerStart's that belonged to their team.

         if (Role == ROLE_Authority)
         {
             AMyCharacter* MyPawn = Cast<AMyCharacter>(GetPawn());
             CharacterState->ChangeTeam();
             //FinishChangeTeam(CharacterState2);
             MyPawn->Destroyed();
             MyPawn->Destroy();
             ChangeState(NAME_Inactive);
             ServerRestartPlayer();
         }
         else
         {
             ServerChangeTeam();
         }

more ▼

answered Apr 03 '17 at 10:14 PM

avatar image

Janyx
472 66 63 211

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question