/////////////////////////INVENTORY//////////////////////////////////// void APlayerCharacter::GiveItem(FInventoryItemStruct Item) { int32 idx = ItemInventoryStructure.Find(Item); // Grab the index of the item if (!ItemInventoryStructure.IsValidIndex(idx)) // If the index is NOT valid it means the item isnt in our inventory / array { //Then the item can be added! ItemInventoryStructure.Add(Item); RefreshInventory(); // Update our Ui } }
void APlayerCharacter::UseItem(FInventoryItemStruct Item, FInventoryItemStruct &InventoryItem) { if (!TrapInConstruction) { AInventoryItem* WorldItem = GetWorld()->SpawnActor<AInventoryItem>(Item.ItemClass, GetActorLocation(), FRotator(0, 0, 0)); // Spawn the item in the world WorldItem->UseItem(this, InventoryItem); // call the blueprint event //ItemInventoryStructure.Remove(Item); // Remove it from the array ItemInventoryStructure.Remove(Item); ItemBeingCrafted = WorldItem; TrapInConstruction = true; printMSG(TEXT("Hold X to place trap"), 5.0); RefreshInventory(); // Update our UI } }
void APlayerCharacter::DropItem(FInventoryItemStruct Item) { AInventoryItem* WorldItem = GetWorld()->SpawnActor<AInventoryItem>(Item.ItemClass, FVector(SentryLocation.X, SentryLocation.Y,SentryLocation.Z), FRotator(0, 0, 0)); // Spawn the item in the world WorldItem->ItemInfo = Item; // Assign the item info of the newly spawned item in the world to the one we dropped int32 idx = ItemInventoryStructure.Find(Item); // Grab the index of the item we want to drop if (ItemInventoryStructure.IsValidIndex(idx)) // Make sure its valid { if (ItemInventoryStructure[idx] == Item) // Make sure the item in our inventory matches the one we want to drop { ItemInventoryStructure.Remove(Item); // Remove it from the array RefreshInventory(); // Update our UI GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Removed item from player inventory"))); } } }
void AMainGameMode::OnInventorySlotReleased(AItem *Item) { GrabbedItem = nullptr; Inventory.Remove(Item); RefreshInventory(); }
void AMainGameMode::AddToInventory(AItem *AnItem) { Inventory.Add(AnItem); RefreshInventory(); }
void APlayerCharacter::UpdateInventory() { RefreshInventory(); }