Hello,
I can’t make my clients damage others in the game.
So I wrote a function called TakeHealth() and ServerTakeHealth() [Reliable, Server, WithValidation] and my TakeHealth() looks like:
void AMasterCharacter::TakeHealth(float Value)
{
if (HasAuthority())
{
float newHealth = Health -= Value;
SetHealth(newHealth);
}
else
{
ServerTakeHealth(Value);
}
}
And the _Implementation is
void AMasterCharacter::ServerTakeHealth_Implementation(float Amount)
{
GEngine->AddOnScreenDebugMessage(3, 3.0f, FColor::Cyan, TEXT("Is it even executed?!"));
}
And I call it like:
BaseHero* Hero = Cast<ABaseHero>(Hit.GetActor());
if (Hero && Hero != Character)
{
if (Role < ROLE_Authority)
{
Hero->ServerTakeHealth(WeaponConfig.Damage);
}
else if (Role == ROLE_Authority)
{
Hero->TakeHealth(WeaponConfig.Damage);
}
GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, FString::Printf(TEXT("Health: %.2f"), Hero->GetHealth()));
}
And I get no message on my screen. Any ideas how to fix it? Been trying for 4 days.