thumbnail blueprint
blueprint

Picking between 3 items

  • Exposure: public
  • UE Version: 5.3

avatar author

MercuryPrime

December 9, 2023, 7:01 am

I made a function called "Get_Reward" that you would run to randomly select what reward you would receive.

There are 6 variables for this blueprint: Item_Key_Owned (boolean) false means you don't have it, true means you do. Item_Key (integer) default value 0 since you don't have it, value increments when you get it. Item_Sword (integer) default value 0 since you don't have one, value increments when you get it. Item_Shield (integer) default value 0 since you don't have one, value increments when you get it. Reward_Number_Max (integer) default value 0, we will adjust with blueprint logic. Reward_Number (integer) default value 0, we will adjust with blueprint logic.

The blueprint starts out with a branch node that checks your Item_Key_Owned boolean. If it is true, then it sets your Reward_Number_Max to 2 since you only want to pick between 2 items, your sword or shield. If Item_Key_Owned is fale, it sets Reward_Number_Max to 3, since you will now have 3 different items to possibly receive.

After then Reward_Number_Max is set, then it is fed into a Random Integer in Range node as the max number, and the minimum number being 1. The resulting random number will then set the value for Reward_Number.

The Reward_Number value is then checked with an equal operator and the result is fed into a branch node. For the section where you have the key, if the value of Reward_Number is 1, then it gets the value of the Item_Sword, adds 1 to the value, and then sets the new Item_Sword value and prints a string to let you know what you received. If the value is not 1, it does the same thing, but for Item_Shield.

If you did not have the key, then the Reward_Number_Max will have been 3, so it will check if Reward_Number was 1 and follow the same steps, then check if it was 2 to give you a shield, and if it was not 1 or 2, then you get the key and your Item_Key_Owned boolean is changed to true so that when you run the function again in the future you will only get a sword or shield.

Click the button above, it will automatically copy blueprint in your clipboard. Then in Unreal Engine blueprint editor, paste it with ctrl + v