Item data

Now that we are finished with the gold creation, we need to create one more thing before we make a shop, that is, items. There are many ways to make items, but it is best to keep an inventory and stats of items through the use of Data Tables. So, let's first create a new C++ FTableRowBase struct similar to the CharacterInfo structs that you previously created. Our files will be called ItemsData.h and ItemsData.cpp, and we will put these files where our other data is; that is, by navigating to Source | RPG | Data. The ItemsData.cpp source file will include the following two header files:

#include "RPG.h"
#include "ItemsData.h"

The ItemsData.h header file will contain definitions of all the item data that we will need. In this case, the item data will be stats that the player has, since items will most likely affect stats. The stats only need to be of the integer type and read-enabled since we won't be changing the value of any of the items directly. Your ItemsData.h file will look something like this:

#pragma once

#include "GameFramework/Actor.h"
#include "ItemsData.generated.h"

/**
 *
 */

USTRUCT( BlueprintType )
struct FItemsData : public FTableRowBase
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 HP;

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 MP;

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 ATK;

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 DEF;

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 Luck;

  UPROPERTY( BlueprintReadOnly, EditAnywhere, Category = "ItemData" )
    int32 Gold;
};

At this point, you can recompile, and you are now ready to create your own Data Table. Since we are creating a shop, let's create a Data Table for the shop in Content Browser and in the Data folder by navigating to Miscellaneous | Data Table, and then using Items Data as the structure.

Item data

Name your new Data Table Items_Shop, and then open the Data Table. Here, you can add as many items as you want with whatever kinds of stat you would like using the Row Editor tab. To make an item, first click on the Add button in Row Editor to add a new row. Then, click on the textbox next to Rename and type in Potion. You will see that you have a potion item with all the other stats zeroed out:

Item data

Next, give it some values. I will make this a healing potion; therefore, I will give it an HP value of 50 and a Gold value of 10.

Item data

The purpose of this Data Table is also to store every item that our shop owner will carry. So, feel free to add more items to this Data Table:

Item data
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.74.66