void MyGameMode::GenerateItems() { EItemType LocItemType{};//Used locally to fill its return type function int32 LocNumbers{}; //Used locally to fill its return type function FST_ItemTypeAndID LocItemID{};//Used locally to fill its return type function TArray ItemsTypeArr{};//used to Stores the randomly selected item types TArray ItemsIDArr{};//used to Stores the randomly selected item types and ID's FST_ItemTypeAndID TempItemTypeAndID_var{};//Used locally to set id and type TArray Available{}; //Used to store the available Transforms for locations out from transformsout TArray UsedLocations{}; //Used to represent an array of already used locations of spawn items FTransform SpawnLocation{}; //Used to represent an array of already used locations of spawn items FTransform Location{}; //Used to store the actual Location out from RandomLocationout for an item EItemType SpawnType{}; //saving item type in local variable which needs to be spawned FName SpawnID{}; //saving the item ID in the local variable which needs to be spawned if (const UDataTable* LobbySpawnLocationRows = LoadObject(GetWorld(), TEXT("/Game/DataTables/ItemsGeneration/Locationtesting"))) { for (auto Array : LobbySpawnLocationRows->GetRowNames()) { if (const UDataTable * LobbySpawnLocationRowNames{ LoadObject(GetWorld(), TEXT("/Game/DataTables/ItemsGeneration/Locationtesting")) }) { if (const FST_ItemGroupLocation * OutRow_LSN{ LobbySpawnLocationRowNames->FindRow(FName(Array), "") }) { FVector SpawnTransform{}; FTransform MakeTransform_Ret{}; SpawnTransform = FVector(OutRow_LSN->Location); MakeTransform_Ret = UKismetMathLibrary::MakeTransform(SpawnTransform, FRotator(0.000000, 0.000000, 0.000000), FVector(1.000000, 1.000000, 1.000000)); AActor* BeginSpawnClass = UGameplayStatics::BeginDeferredActorSpawnFromClass(this, AItemGroup::StaticClass(), MakeTransform_Ret, ESpawnActorCollisionHandlingMethod::Undefined, ((AActor*)nullptr)); MakeTransform_Ret = UKismetMathLibrary::MakeTransform(SpawnTransform, FRotator(0.000000, 0.000000, 0.000000), FVector(1.000000, 1.000000, 1.000000)); ItemGroupRef = CastChecked(UGameplayStatics::FinishSpawningActor(BeginSpawnClass, MakeTransform_Ret), ECastCheckedType::NullAllowed); } } RandomItemNumber(LocNumbers); //printf100s("Ramdom Array Group. Contains Rows:: %d", LocNumbers); for (int i = 1; i <= LocNumbers; i++) { RandomItemType(LocItemType);//Randomize items by type if (ItemsTypeArr.Find(LocItemType) == -1) //check for duplicates { ItemsTypeArr.Add(LocItemType); // add all items to array if not duplicated } else { RandomItemType(LocItemType);//Re-randomize items to avoid any duplicate } } for (auto& Array : ItemsTypeArr) //For each loop { //RandomItemID(Array, LocItemID); RandomItemID(Array, LocItemID); ItemsIDArr.Add(LocItemID); } //--------------------------DEBUGGING----------------------------------------- //Testing purpose to print the values if they are correctly generated /*for (auto& Array : ItemsTypeArr) //For each loop { FString DisplayName = UEnum::GetDisplayValueAsText(Array).ToString(); printf100s("%s", *DisplayName); UE_LOG(LogTemp, Log, TEXT("The Elements in Array: %s"), *UEnum::GetValueAsString(Array)); } print100s("__________________________");*/ //---------------------------DEBUGGING---------------------------------------- ItemsTypeArr.Empty(); //Find Weapon type, if true, so spawn the bullets belongs to that weapon type, every weapon has its own bullet to be used. for (auto& Array : ItemsIDArr) { if (Array.Type == EItemType::E_Weapon) { if (const UDataTable* DT_ItamWeapon{ LoadObject(GetWorld(), TEXT("/Game/DataTables/Items/Weapon/DT_ItamWeapon")) }) { if (const FST_ItemWeapon* OutRow{ DT_ItamWeapon->FindRow(FName(Array.ID), "") }) { if (OutRow) { TempTypeAndID_Setter.Type = EItemType::E_Ammo; TempTypeAndID_Setter.ID = OutRow->UseAmmoID; ItemsIDArr.Add(TempTypeAndID_Setter); //Remove any item from the array if this is not a weapon for (auto& Array : ItemsIDArr) { if (Array.Type != EItemType::E_Weapon) { ItemsIDArr.RemoveAt(1); break; } } } } } } } //Looping all items ready to be generated //Once the looping completes all the item groups will be generated for (auto SpawnArrayElements : ItemsIDArr) { SpawnType = SpawnArrayElements.Type; SpawnID = SpawnArrayElements.ID; ItemGroupRef->GetAllTransforms(Available); //RandomLocation(Available, Location); do { RandomLocation(Available, Location); } while (UsedLocations.ContainsByPredicate([Location](const FTransform Transform) { return Transform.GetLocation() == Location.GetLocation() && Transform.GetRotation() == Location.GetRotation() && Transform.GetScale3D() == Location.GetScale3D(); })); SpawnLocation = Location; UsedLocations.Add(SpawnLocation); //FString SpawnLoc = SpawnLocation.ToString(); //printf100s("Spawn Location: %s", *SpawnLoc); } ItemsIDArr.Empty(); //print100s("---------------------------------------"); //----------------------------------Testing Debugging------------------------------------------ //this should print the items generated and should print the ammo ID with its corresponding weapon /*for (auto& Array : ItemsIDArr) { FString ItemTypeLog = UEnum::GetDisplayValueAsText(Array.Type).ToString(); //FName ItemIDLOG = FName(Array.ID); FString ItemIDLOG = Array.ID.ToString(); //printf100s("Item Type: %s", *ItemTypeLog, " -- %S", *Array.ID.ToString()); printf100s("Item Type: %s. %s", *ItemTypeLog, *ItemIDLOG); } print100s("----");*/ //----------------------------------Testing Debugging-------------------------------------------- } } }