- Home /
Random loot - rarity
Hi!
I'm trying to work out a system (in javascript) that will spawn an item in a pre-placed loot pile. Using Random.Range, I could have easily just had it so that any item spawns randomly, but I want different items to be rarer/more common than others. If you're not sure what I'm on about I'm trying to replicate the Day-Z loot system Day-Z wiki.
So far I've created an 'item list' that just has an array for an item, with it's name and then it's object. The variable name is the item's 'data value'.
static var i4310 = Array("Riot Shotgun Slugs", Resources.Load("i4310"));
Also I have another script that says how rare it is in certain areas.
//Rarity out of 100
/*i4310 - riot shotgun ammo*/ static var i4310Rarity = 40; //40 for testing purposes
So my question is; How can you make items spawn at pre-placed loot spawn locations, and have a different rarity for each item?
Hopefully that wasn't too much to ask, thanks in advance!
crushy I'd say yours is correct but your answer isn't appearing, its only in my e-mails :(
Weird, the same thing is happening to me now :/ I think I just replied to someone and he deleted his answer.
Answer by Raigex · Jul 11, 2012 at 08:50 PM
Use a table of rarity values and ranges for instance item x has a rarity of 5 so it a random generated value is between 0 and 5 spawn that item or use percents aka have a imaginary bar of 0-1000 and divide that by the rarity of an item again lets say item x has a 5% chance of getting discovered then if random number drops in the first 5% of 1000 then generate that loot.
Answer by TheDarkVoid · Jul 11, 2012 at 04:17 PM
you can use a Random.Range(0, Rarity), this can be used to determine if it will spawn an item. although the higher the rarity the rarer the item would be.
Your answer
Follow this Question
Related Questions
AI spawning areas. What are the ways to make them? 1 Answer
How to spawn player randomly in one of certain positions? 1 Answer
Spawning different items from different prefabs 2 Answers
Advanced Wave Spawner (Spawn Waves in random order) 1 Answer
How do I spawn objects randomly near an object then delete them? 1 Answer