Download

How do I use Apply Point Damage on multiplayer?

I have a weapon object called AItem. I made it a rifle in blueprints and I can attach it to my character perfectly. I want to deal damage to my other players on a dedicated server and I cant figure it out. I have my function


Fire()

running on the server and within it is this :


void AItem::Fire()
{

FVector EyeLocation;
FRotator EyeRotation;
EyeLocation = FPSCharacterRef->GunMesh->GetSocketLocation("MuzzleFlash");
EyeRotation = FPSCharacterRef->GunMesh->GetSocketRotation("MuzzleFlash");

FVector ShotDirection = EyeRotation.Vector();

FVector TraceEnd = EyeLocation + (ShotDirection * 10000);
FHitResult Hit;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(this);
QueryParams.AddIgnoredActor(FPSCharacterRef->GetOwner());
QueryParams.bTraceComplex = true;

if (GetWorld()->LineTraceSingleByChannel(Hit, EyeLocation, TraceEnd, ECC_Visibility, QueryParams) && FPSCharacterRef->IsLocallyControlled()) {

AActor*HitActor = Hit.GetActor();
//if we hit a player we want to subtract the health from that player
UE_LOG(LogTemp, Warning, TEXT("%s"), *HitActor->GetName());

//if the hit actor IS an enemy player

UGameplayStatics::ApplyPointDamage(HitActor, DPS, ShotDirection, Hit, HitActor->GetInstigatorController(), this, DamageType);



}
DrawDebugLine(GetWorld(), EyeLocation, TraceEnd, FColor::Red, false, 1.0f, 0, 1.0f);

}


On my character I have this :


void AFPSCharacter::ServerFire_Implementation()
{
if (Item && Item->bPickedUp) {
if (GetLocalRole() == ROLE_Authority) {
NetFire();
UE_LOG(LogTemp, Warning, TEXT("Server Fire"));
}
}
}

bool AFPSCharacter::ServerFire_Validate()
{
return true;
}

void AFPSCharacter::Fire()
{

if (Item && Item->bPickedUp) {

if (GetLocalRole() < ROLE_Authority) {
ServerFire();
UE_LOG(LogTemp, Warning, TEXT("Fire"));
}

}
}


void AFPSCharacter::NetFire_Implementation()
{
if (Item && Item->bPickedUp) {
Item->Fire();
UE_LOG(LogTemp, Warning, TEXT("NetFire"));
}
}


As you can see, I have


ApplyPointDamage()

but it doesnt deal the damage after the line tracing hits, its also running on server. Can someone please explain this to me? The debug draw line works and everything else works as intended. I’ve also tried using Tom Looman as a reference and he uses event ApplyPointDamage in Blueprints and that works for him but for me it doesnt. Finally, I tried to follow another video , that used this


 void UHealthComponent::TakeDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser)

I created this and put a pain volume in my world along with an Event ApplyAnyDamage in my player BP and it works for the pain volume but not for my line trace, how can I get this to work?

Can someone help?