How do you make a Party ID or Party code that other players can use to join your party. I already created an ID generator once the player clickes the create party button, but I can’t make it so other players can join the party using this party ID. Here is all my code.
partyinfocomponent:
// Fill out your copyright notice in the Description page of Project Settings.
include “PartyInfoComponent.h”
// Sets default values for this component’s properties
UPartyInfoComponent::UPartyInfoComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don’t need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UPartyInfoComponent::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void UPartyInfoComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
PollMenu();
if (Menu) {
InitParty();
}
}
void UPartyInfoComponent::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const {
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(UPartyInfoComponent, PartyID);
DOREPLIFETIME(UPartyInfoComponent, AllPartyID);
DOREPLIFETIME(UPartyInfoComponent, bIsLeader);
DOREPLIFETIME(UPartyInfoComponent, AttemptedPartyID);
}
void UPartyInfoComponent::OnRep_PartyID() {
}
void UPartyInfoComponent::OnRep_AllPartyID() {
}
void UPartyInfoComponent::OnRep_bIsLeader() {
}
void UPartyInfoComponent::OnRep_AttemptedPartyID() {
}
void UPartyInfoComponent::PollMenu() {
if (Menu == nullptr) {
TArray<UUserWidget*> WidgetsFound;
UWidgetBlueprintLibrary::GetAllWidgetsOfClass(GetWorld(), WidgetsFound, MenuClass);
if (WidgetsFound.Num() > 0) {
Menu = Cast<UMenu>(WidgetsFound[0]);
}
}
}
void UPartyInfoComponent::InitParty() {
if (Menu) {
PartyID = Menu->PartyID;
AllPartyID = Menu->AllPartyID;
AttemptedPartyID = Menu->AttemptedPartyID;
bPartyCreated = Menu->bPartyCreated;
if (AllPartyID.Contains(AttemptedPartyID) && PartyID != 0) {
GEngine->AddOnScreenDebugMessage(-1, 15.0F, FColor::Yellow, "Party is open");
}
}
ServerInitParty();
}
void UPartyInfoComponent::ServerInitParty_Implementation() {
if (Menu) {
PartyID = Menu->PartyID;
AllPartyID = Menu->AllPartyID;
AttemptedPartyID = Menu->AttemptedPartyID;
bPartyCreated = Menu->bPartyCreated;
if (AllPartyID.Contains(AttemptedPartyID) && PartyID != 0) {
GEngine->AddOnScreenDebugMessage(-1, 15.0F, FColor::Yellow, "Party is open");
}
}
}
menu widget cpp:
void UMenu::PartyIDTextboxButtonCommited(const FText& Text, ETextCommit::Type CommitMethod) {
FString PartyIDString = PartyIDTextbox->GetText().ToString();
AttemptedPartyID = UKismetStringLibrary::Conv_StringToInt(PartyIDString);
PartyIDTextbox->SetVisibility(ESlateVisibility::Collapsed);
GEngine->AddOnScreenDebugMessage(-1, 50.0F, FColor::Yellow, "Actual " + UKismetStringLibrary::Conv_IntToString(PartyID));
GEngine->AddOnScreenDebugMessage(-1, 50.0F, FColor::Yellow, "Attempted " + UKismetStringLibrary::Conv_IntToString(AttemptedPartyID));
}