A client script will be created that will generate the axes. It will select a random blade and handle from the data tables, and also randomize the color of the parts.
Storing all the colors for each part as an attribute for the NFT can be a little too much, especially if you are manually creating the attributes on OpenSea. A better approach to this that we will be using, is storing the seed used.
Create NFTAxeGeneratorClient Script
Create a new script called NFTAxeGeneratorClient and place it into a Client Context folder. This script will need references to the container so it can spawn the objects, the blades, and the handles.
Add the Container group inside the Dummy Object as a custom property called Container.
Add the Blades data table as a custom property called Blades.
Add the Handles data table as a custom property called Handles.
Add Variables
Add the variables below to the script.
The currentItem variable will hold information about the current Axe that was generated.
The list variable will hold all the axes generated so the data can be printed that can be used for helping create the NFTs.
RNG and ColorRNG are instances of RandomStream. This allows us to use a seeded random number, in this case, the seed is the year 2022.
local CONTAINER = script:GetCustomProperty("Container"):WaitForObject()
local BLADES = require(script:GetCustomProperty("Blades"))
local HANDLES = require(script:GetCustomProperty("Handles"))
local currentItem = nillocal list = {}
local RNG = RandomStream.New(2022)
local ColorRNG = RandomStream.New(2022)
Code language:Lua(lua)
Enable Cursor
Enable the cursor so it is visible when clicking on the screen.
Create a function called ClearPrevious. This function will clear the previous objects that were spawned. This will prevent objects from overlapping when creating a random Axe.
localfunctionClearPrevious()if currentItem ~= nilthenif Object.IsValid(currentItem.blade) then currentItem.blade:Destroy()
endif Object.IsValid(currentItem.handle) then currentItem.handle:Destroy()
endend currentItem = nilendCode language:Lua(lua)
Create InList Function
Create a function called InList. This function will check to see if an item already exists in the list. Because we want unique axes for NFTs, we can prevent duplicates by checking the current mutated seed against the seeds in the list table.
localfunctionInList(seed)for i, item inipairs(list) doif item.seed == seed thenreturntrueendendreturnfalseendCode language:Lua(lua)
Create ColorMeshes Function
Create a function called ColorMeshes. This function will find all static meshes and randomly set the color of each material slot. If a mesh has a custom property of Ignore, then the loop will ignore that static mesh.
localfunctionColorMeshes(item)local meshes = item:FindDescendantsByType("StaticMesh")
for m, mesh inipairs(meshes) doif mesh:GetCustomProperty("Ignore") == nilornot mesh:GetCustomProperty("Ignore") thenlocal material_slots = mesh:GetMaterialSlots()
for s, slot inipairs(material_slots) do slot:SetColor(Color.New(ColorRNG:GetNumber(), ColorRNG:GetNumber(), ColorRNG:GetNumber()))
endendendendCode language:Lua(lua)
Create Generate Function
Create a function called Generate. This function will clear the previously generated Axe, mutate RNG, and try to spawn a random blade and handle. If it is a unique Axe, then it is randomly colored. Each blade and handle is spawned into the CONTAINER.
Create a function called Output. This function is responsible for outputting all the information about each Axe into the Event Log. This information can then be used to create the NFTs.
To generate an Axe, we need to check what action is being pressed. We can check a few different actions which will call different functions.
If the action is Shoot, which is the left mouse button by default. It will call the Generate function and generate an Axe.
If the action is Jump, which is space bar by default. It will call the Output function and generate the information about all the generated axes in the Event Log.
If the action is Aim, which is the right mouse button by default. It will add the current Axe generated to the list. You may not want all axes to be added to the list.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!