Setting rarity in nfts engine

Hello,
after i searched intensively through the whole internet for a solution i consider to ask here.
I watched this tutorial Generate NFTs with this simple code (this could make you millions) PART 2 and i’m not able to setup rarity for the nft-generation. I tried everything, but i only get a full NFT with the same rarity level and thats not right.
Did no one run into the same problem?
How can i set up the rarity right?
This engine pregenerate the NFT after configuration and deploy it to ipfs.
Appreciate any help/advice!

What is the rarity level that you want to change? For what particular feature?

I want that the engine takes traits from 3 different directories: common, rare and super_rare. The goal is to generate a bunch of NFTS (10000 pieces). The traits in the “super_rare” directory are rarier then the traits in “rare” and the same pattern between “rare” and “common”.

did you look at part one?

Yes i watched it a few times to get sure, if i really don’t missed something important.
In the whole tutorial he said, that the rarity is just setable and in the tutorial he only worked with the ‘common’ directory, but thats not enough to set it up advanced.
Thanks for your answer!
I then gave my best to set it up. Inspected the whole code and tried a lot of things.
The best result i get was, that the generated NFTS had different rarity types, but the rarity level of traits within an NFTS was always the same.
Then i gaved it up and switched to another engine.
Sure it could be worked, when adding a lot of individual self scripted functions etc. but it’s not recommended to invent the wheel new, when there is a well written and tested solution anywhere in the internet.

I know what you mean, I’m actually running into this same issue as well. This is the section of the code you’re talking about correct?

/ create required weights
// for each weight, call 'addRarity' with the id and from which to which element this rarity should be applied
let rarityWeights = [
  /* 
  addRarity("super_rare", 1, 1),
  addRarity("rare", 1, 1),
  */
  addRarity("common", 1, editionSize),
  addRarity("rare", 1, editionSize),
  addRarity("uncommon", 1, editionSize),
  addRarity("super_rare", 1, editionSize),
  addRarity("legendary", 1, editionSize),
];

// create required layers
// for each layer, call 'addLayer' with the id and optionally the positioning and size
// the id would be the name of the folder in your input directory, e.g. 'ball' for ./input/ball
const layers = [
  addLayer("Background", { x: 0, y: 0 }, { width: width, height: height }),
  addLayer("Base_head"),
  addLayer("Face_art"),
  addLayer("Pins"),
  addLayer("Mustache"),
  addLayer("Ties"),
  addLayer("Snoozes"),
  addLayer("Eye_masks"),
  addLayer("Face_masks"),
  addLayer("Headgear"),
];

// provide any specific percentages that are required for a given layer and rarity level
// all provided options are used based on their percentage values to decide which layer to select from
addRarityPercentForLayer("common", "Background", {
  legendary: 5,
  super_rare: 10,
  rare: 20,
  uncommon: 40,
  common: 60,
});

specifically the last part that says "addRarityPercentForLayer(“common”, “Background”,

That seems t only be setting rarity levels for that one layer, but it’s not really working for every other layer. I did try a workaround by repeating this code over and over for every layer and every rarity, but it’s not really working the way it should. There has to be a better way to code this section without adding 100 lines of repetitive code. It ends up looking like this

addRarityPercentForLayer("uncommon", "Background", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Background", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Background", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Background", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Face_art", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Face_art", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Face_art", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Face_art", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Face_art", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Pins", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Pins", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Pins", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Pins", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Pins", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Mustache", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Mustache", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Mustache", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Mustache", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Mustache", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Ties", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Snoozes", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Snoozes", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Snoozes", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Snoozes", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Snoozes", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("common", "Eye_masks", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("uncommon", "Eye_masks", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("rare", "Eye_masks", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("super_rare", "Eye_masks", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });
  
  addRarityPercentForLayer("legendary", "Eye_masks", {
    legendary: 5,
    super_rare: 10,
    rare: 20,
    uncommon: 40,
    common: 60,
  });

I could be completely out of the ball park on this though. I just wish the man in the video actually took the time to properly explain the various sections of code, specifically the ones that are the most important like rarity levels. Instead he said it was too complicated, too much to get into, glossed over it, said he could talk about it in another video, and never did. I mean, if you’re going to make a video about how to create an NFT collection with your code, the least you can do is properly explain your code and give clear instructions on how to configure it all without glossing over essential details.

1 Like

Exactly, i mean this part!
I think that code is still not ready to get in use to provide a nfts engine solution. And that’s only one of many problems someone can run into with that code.
For example, how people can handle multiple characters with the same traits, but different versions of that trait (e.G male-, female- clothing)?
Or i simply cant get the .json-Metadata from generating without uploading it to ipfs before.
This has simply just too many not fullfilled requirements. After i struggled around 10 hours with that, i finally found the nfts-engine from ‘hashlips’ and i works perfectly, and only after an half hour.
So i just can recommend it, because it’s well explained in his video and documentation. And the community is very strong and willing to help in discord. Also there are utility tools provided, like a rarity-checker, so the creator can test it very well before uploading it to ipfs or going further. :slight_smile:

2 Likes

I’m guessing the HashLips code is what you went with? I got stuck on these issues and sad to see nobody provided a solution lol so I guess I’ll give HashLips a try.

1 Like

This video is why we have questions lol

1 Like

Did anyone ever figure this one out?