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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to set it up so a client can request a new powerup from the server?

Yo! Let's say I have two vehicles loaded into the game. One is the listen server, the other a client. alt text

I have these functions for picking a random powerup from a list. However, I'm not sure how to get each vehicle to be picking a different powerup. I'm pretty sure this is just picking one random powerup and replicating it to every client, but I want every client to randomize their own power up when they need to.

They use the power up, ping the server that they consumed it, and then server eventually assigns them a new powerup. How should I be looking to implement this?

Product Version: UE 4.15
Tags:
more ▼

asked Apr 07 '17 at 08:37 PM in C++ Programming

avatar image

KhaosComplex
1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

This is how I would look at it:

 AMyPickupActor::AMyPickupActor( )
 {
     BoxCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider");
     BoxCollider->OnComponentBeginOverlap.AddDynamic(this, &AMyPickupActor::Overlap);
     SetRootComponent(BoxCollider);
     
     MyBuffClass = UMySuperBuffClass::StaticClass( );
     
     bReplicates = true;
 }    
 
 void AMyPickupActor::Overlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
     if(Role == ROLE_Authority)
     {
         AMyVehicleClass *Vehicle = Cast<AMyVehicleClass>(OtherActor);
         if(Vehicle)
         {
             Vehicle->GrantBuff(MyBuffClass);
         }
     }
     else
     {
         // Sound
         // FX
         // Other client side event(s) on overlap....
     }
 }
 
 // Vehicle
 
 void AMyVehicleClass::GrantBuff(TSubclassOf<UMySuperBuffClass> InBuff)
 {
     if(Role < ROLE_Authority)
     {
         Server_GrantBuff(InBuff);
     }
     else
     {
         // However you want to grant the buff, either to "this" vehicle
         // or, send a multicast out here for all "team" vehicles
         SendOutBuffs( );
     }
 }
 
 bool AMyVehicleClass::Server_GrantBuff_Validate(TSubclassOf<UMySuperBuffClass> InBuff)
 {
     return true;
 }
 
 void AMyVehicleClass::Server_GrantBuff_Implementation(TSubclassOf<UMySuperBuffClass> InBuff)
 {
     GrantBuff(InBuff);
 }

You would create a Actor "Pickup" class, that is replicated. This class would have a collider component with a overlap function bound. When a vehicle overlapped it, i would then tell the vehicle to handle the buff (because all clients will have a copy of the vehicle class as I am guessing its from APawn). From there, I would check if its the server calling it - which is 100% will be as setup but if you had another call from the client, this would handle that too.

If it isn't the server, it forwards the "buff" class in as a server function, which then goes back around to the GrandBuff, but this time as authority, and then can handle the event from the server side.

more ▼

answered Apr 07 '17 at 09:47 PM

avatar image

ImVawx ♦♦ STAFF
6.8k 114 18 127

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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