generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Rarity Tables and Loot Spawning

Previous Thread :: Next Thread 
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
14 Dec 2013 12:06 PM
I posted a similar thread yesterday, but I've nailed down the path I wish to take, and am back for more questions and discussion on the subject.

Let's say I have this table:

rarityTable = {
["Hut"] = {
CutStone = 60,
Grass = 10,
Rock = 20,
Stick = 10
},
["AbandonedCamp"] = {
CutStone = 85,
Grass = 5,
Rock = 5,
Stick = 5
},
["DeadBody"] = {
CutStone = 40,
Grass = 10,
Rock = 40,
Stick = 10
},
["Table"] = {
CutStone = 40,
Grass = 10,
Rock = 25,
Stick = 25
}
}

The names represent different sites where loot will spawn, and inside of them you have the different items that could spawn, and their probability of spawning out of 100 for examples sake.

What I'm wanting to do is have one function that will choose one of those randomly based on percentage chance to spawn. Keep in mind not every location will have only 4 items, and they will not always be the same name.

This is my struggle, help is appreciated.

#TheStruggleIsReal

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
14 Dec 2013 12:20 PM
lol simple simple simple... if i am understanding correctly.

I'll use this example

local tab = {
h = 50;
g = 20;
f = 30
}

function randomt(tab)
tat = {}
for i,v in pairs(tab) do
for x = 1,v[i] do
table.insert(tat, v)
end
end
return tat[math.random(1,#tat)]
end

randompick = randomt(tab)

print(randompick)

-- h has a 50% possibility to be chosen
-- g has a 20
-- f has a 30

Report Abuse
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
14 Dec 2013 12:22 PM
Oh wow! I slapped myself when I saw how you did that!

Thanks!

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
crouton04 is not online. crouton04
Joined: 07 Jul 2010
Total Posts: 4459
14 Dec 2013 12:25 PM
fail here..

for x = 1,v do
Report Abuse
DrWaffler is not online. DrWaffler
Joined: 16 Sep 2011
Total Posts: 4248
14 Dec 2013 12:26 PM
I caught the mistake already, it works exceptionally well.

--[Territory Conquest Developer, Valerian Studios Developer, Business Casual Narwhal Moai. ]]--
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image