Redemp
(Redemp)
May 25, 2019, 9:02pm
1
Hi guys,
I’ve got a problem with my weapons display.
I’m trying to make a system similar that in PUBG with two main weapons, primary and secondary.
When one is use, attached to hands I call it CurrentWeapon, and the other one should be attach in the back .
My system works on the server but not on the clients where weapons don’t show up for others people.
Can you help me ?
Redemp
(Redemp)
May 25, 2019, 9:04pm
2
Here is my code
header
/** currently equipped weapon */
UPROPERTY(BluePrintReadWrite,Transient, Replicated/*Using = OnRep_CurrentWeapon*/)
class ABaseWeapon* CurrentWeapon;
UPROPERTY(BluePrintReadWrite,Transient, ReplicatedUsing = OnRep_PrimaryWeapon)
class ABaseWeapon* PrimaryWeapon;
UPROPERTY(BluePrintReadWrite,Transient, ReplicatedUsing = OnRep_SecondaryWeapon )
class ABaseWeapon* SecondaryWeapon;
//utilisé pour équiper une arme depuis l'inventaire
UFUNCTION(BlueprintCallable, Category = Inventory)
void EquipWeapon( EWeaponSlot WeaponSlot);
/** equip weapon */
UFUNCTION(reliable, server, WithValidation)
void ServerEquipWeapon( EWeaponSlot weaponslot);
void UnequipWeapon(ABaseWeapon* WeaponToUnequip);
/** current weapon rep handler */
UFUNCTION()
void OnRep_PrimaryWeapon(class ABaseWeapon* LastWeapon);
UFUNCTION()
void OnRep_SecondaryWeapon(class ABaseWeapon* LastWeapon);
//Pour accrocher une arme au socket de la main
void AttachToHand(APickable* WeaponToEquip);
//pour accrocher une arme à un socket sur le corps
void AttachToBody(APickable* WeaponToEquip, EWeaponSlot SocketToEquip);
FName GetSocket(EWeaponSlot SocketToGet);
Redemp
(Redemp)
May 25, 2019, 9:37pm
3
void ABaseCharacter::EquipWeapon(EWeaponSlot weaponslot)
{
if (Role == ROLE_Authority)
{
if (CurrentWeapon != NULL)
{
UnequipWeapon(CurrentWeapon);
}
IsEquiping = true;
switch (weaponslot)
{
case (EWeaponSlot::Primary):
if (PrimaryWeapon != NULL)
{
CurrentWeapon = PrimaryWeapon;
AttachToHand(CurrentWeapon);
CurrentWeapon->OnEquip(CurrentWeapon);
}
OnEquipFinish();
break;
case (EWeaponSlot::Secondary):
if (SecondaryWeapon != NULL)
{
CurrentWeapon = SecondaryWeapon;
AttachToHand(CurrentWeapon);
CurrentWeapon->OnEquip(CurrentWeapon);
}
OnEquipFinish();
break;
case (EWeaponSlot::SideGun):
if (SideGun != NULL)
{
CurrentWeapon = SideGun;
AttachToHand(CurrentWeapon);
CurrentWeapon->OnEquip(CurrentWeapon);
}
OnEquipFinish();
break;
}
}
//if role isn't autorithy
else
{
/*if (CurrentWeapon != NULL)
{
UnequipWeapon(CurrentWeapon);
}*/
ServerEquipWeapon(weaponslot);
}
}
bool ABaseCharacter::ServerEquipWeapon_Validate(EWeaponSlot weaponslot)
{
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("true , serverequipweaponvalidate"));
return true;
}
void ABaseCharacter::ServerEquipWeapon_Implementation( EWeaponSlot weaponslot)
{
//weipweapon with autority"));
EquipWeapon (weaponslot);
}
void ABaseCharacter::UnequipWeapon(ABaseWeapon* WeaponToUnequip)
{
if (CurrentWeapon != NULL)
{
//CurrentWeapon->OnUnEquip();
AttachToBody(WeaponToUnequip, WeaponToUnequip->CurrentSlot);
CurrentWeapon = NULL;
}
}
void ABaseCharacter::AttachToHand(APickable* WeaponToEquip)
{
FName AttachPoint= GetWeaponAttachPoint();
WeaponToEquip->Mesh1P->SetHiddenInGame(false);
WeaponToEquip->Mesh3P->SetHiddenInGame(false);
WeaponToEquip->Mesh1P->AttachToComponent(Mesh1P, FAttachmentTransformRules::SnapToTargetNotIncludingScale, AttachPoint);
WeaponToEquip->Mesh3P->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, AttachPoint);
//on s'assure que l'arme soit bien en place sur chaque mesh
WeaponToEquip->Mesh3P->SetRelativeTransform(WeaponToEquip->TpsSocket);
WeaponToEquip->Mesh1P->SetRelativeTransform(WeaponToEquip->FpsSocket);
}
void ABaseCharacter::AttachToBody(APickable* WeaponToEquip, EWeaponSlot SocketToEquip)
{
FName AttachPoint = GetSocket(SocketToEquip);
WeaponToEquip->Mesh1P->SetHiddenInGame(true);
WeaponToEquip->Mesh3P->SetHiddenInGame(false);
//WeaponToEquip->Mesh1P->AttachToComponent(Mesh1P, FAttachmentTransformRules::KeepRelativeTransform, AttachPoint);
WeaponToEquip->Mesh3P->AttachToComponent(GetMesh(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, AttachPoint);
WeaponToEquip->Mesh3P->SetRelativeTransform(WeaponToEquip->GetSocket(SocketToEquip));
}
FName ABaseCharacter::GetSocket(EWeaponSlot SocketToGet)
{
FName Socket;
switch (SocketToGet)
{
case (EWeaponSlot::Primary):
Socket = PrimaryAttachPoint;
break;
case (EWeaponSlot::Secondary):
Socket = SecondaryAttachPoint;
break;
case (EWeaponSlot::SideGun):
Socket = SideGunAttachPoint;
break;
}
return Socket;
}
ajeets1978
(ajeets1978)
September 6, 2020, 12:00pm
4
Surprising that no body ever replied.