Hi!
I am trying to implement a shooting function in C++ for a multiplayer game but me being a total noob in C++, I a currently runnning into an issue where I have successfully managed to create a function that runs in the server but the content of it only runs if I play as the server.
.h file:
UFUNCTION(Server, Reliable, WithValidation)
void ApplyDamageServer();
void ApplyDamageServer_Implementation();
bool ApplyDamageServer_Validate();
.cpp file:
// Fraction of the shooting function
if (WpnFireHit.GetActor()->ActorHasTag(FName(TEXT("Damageable"))))
{
TestResult = WpnFireHit;
TestController = Controller;
TestDamageTypeClass = DamageTypeClass;
TestActorCause = this;
ApplyDamageServer();
}
else
{
GLog->Log(TEXT("No damage"));
}
//Apply Damage Server Implementation
void AWeaponBase::ApplyDamageServer_Implementation()
{
GLog->Log("Damage Implement");
if (GetLocalRole() == ROLE_Authority)
{
UGameplayStatics::ApplyPointDamage(TestResult.GetActor(), Damage, TestResult.ImpactPoint, TestResult, TestController, TestActorCause, TestDamageTypeClass); // Apply Damage
GLog->Log("Authority");
}
else
{
GLog->Log("No Authority");
}
}
//Apply Damage Server Validate
bool AWeaponBase::ApplyDamageServer_Validate()
{
return true;
}
My problem is that when playing as the server, everything runs as expected but when on the clients everything runs but the damage does not run or does not apply but the rest of the funtion does.
For exemple, on the clients “GLog->Log(“Authority”);” runs but the damage does not apply.