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: Random loot value script

Previous Thread :: Next Thread 
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 04:53 PM
ItemSpawnLoop = script.Parent:GetChildren(LoopItem)
wait(600)
function getRandomCard()
local CivSpawnRate = math.random(3)
local MiltSpawnRate = math.random(1300)
local SpawnArea = math.random(game.Workspace.MiltItemSpawnPoint)
local Loot = script.Parent.Loot:GetChildren(Loot)
local Item = math.random(CivSpawnRate,MiltSpawnRate)
if SpawnRate <= 3 then script.Parent.LootValue.Value = "Civ"
elseif Item == CivSpawnRate then
LootValue.Value = "Civ"
elseif Item == MiltSpawnRate then
LootValue = "Milt"
end
end

This is REALLY confusing, I know.

I want the script to make a string in the Parent either Civ or Milt, based on the chance of the spawnrate. The value never changes, and I get no output
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:00 PM
b
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:03 PM
Not sure if this helps, but here's my random number generator to spawn pokemon:

--scripted by Subete

local storage = game:GetService("ServerStorage").Mobs

local commonmobs = {
["Pidgy"] = 1;
["Rattata"] = 2;
["Caterpie"] = 3;
["Weedle"] = 4;
}

local uncommonmobs = {
["Pikachu"] = 1;
["Squirtle"] = 2;
["Charmander"] = 3;
["Bulbasaur"] = 4;
}

local legendmobs = {
["Moltres"] = 1;
}


function getrandomnum()
local rng = math.random(1,1000)
return rng
end

function slctmonsternumber() --common rng
local rng = math.random(1,4)
return rng
end

function uncslctmonsternumber() --uncommon rng
local rng = math.random(1,4)
return rng
end

function slctlegendmonsternumber() --legendary rng
local rng = math.random(1,1)
return rng
end

function getrandompos()
local randomvector = Vector3.new(math.random(-200,200),1,math.random(-200,200))
return randomvector
end

function makecommon()
local monsnum = slctmonsternumber()
for i,v in pairs(commonmobs) do
if v == monsnum then
print(i.." Selected.")
local mon = storage:findFirstChild(i)
if mon then
local monclone = mon:clone()
monclone.Parent = game.Workspace
monclone:MakeJoints()
monclone:MoveTo(getrandompos())
end
end
end
end

function makeuncommon()
local monsnum = uncslctmonsternumber()
for i,v in pairs(uncommonmobs) do
if v == monsnum then
print(i.." Selected.")
local mon = storage:findFirstChild(i)
if mon then
local monclone = mon:clone()
monclone.Parent = game.Workspace
monclone:MakeJoints()
monclone:MoveTo(getrandompos())
end
end
end
end

function makelegend()
local legendmonsnum = slctlegendmonsternumber()
for i,v in pairs(legendmobs) do
if v >= legendmonsnum then
print(i.." Selected.")
local mon = storage:findFirstChild(i)
if mon then
local monclone = mon:clone()
monclone.Parent = game.Workspace
monclone:MakeJoints()
monclone:MoveTo(getrandompos())
end
end
end
end

function makemonster()
local randomnum = getrandomnum()
if randomnum < 895 then --89.5% chance of common
print('common')
makecommon()
elseif randomnum >= 895 and randomnum < 995 then --10% chance of uncommon
print('uncommon')
makeuncommon()
elseif randomnum >= 995 then --0.5% chance of legendary
print('legend')
makelegend()
end
end

while wait(3) do
local modelnum = 0
for x, y in pairs(game.Workspace:GetChildren()) do
if y:IsA("Model") and y:findFirstChild("Pokemon") then
modelnum = modelnum + 1
end
end
print(modelnum)
if modelnum < 15 then
makemonster()
else
print('full game')
end
end
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:07 PM
what is this sht

I'm not in the mood for jokes
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:10 PM
bump, please help
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
07 Sep 2014 05:11 PM
math.random(MINIMUM, MAXIMUM)

math.random(1,3) will choose either 1, 2 or 3.
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:13 PM
Thank you!

Is there a way to.. add in a chance of one of the values being picked?
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:13 PM
Narb pls. My RNG is the same concept as your loot system.


I ain't got time for jokes either.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:14 PM
I suggest you read the RNG I posted, because it answers all of your questions.
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:16 PM
I'm not using tables though

The script is practically completed, I just need to know why the value doesn't change
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:17 PM
If you used a loot table it would simplify your life a ton. :/
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
07 Sep 2014 05:17 PM
^
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:22 PM
The thing is, I dont know how to index random things from a table

Plus, I think this method requires less typing :P
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
07 Sep 2014 05:25 PM
table = {workspace.Thing1, workspace.Thing2}
table[math.random(1, #table)]
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:25 PM
If you use tables in the way I did in the script posted above, updating the game and adding to the script becomes 1000x easier.

To add a new pokemon to spawn in my game, I just need to put another table entry and change the math.random to 1 number higher ..

Example on indexing random value of table:

table = {v1,v2,v3,v4,v5}

num = math.random(1,5)

print(table[num])
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:25 PM
But what about getting the chance of the item spawning?
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
07 Sep 2014 05:28 PM
refer to my rng

It spawns random pokemon in random positions on the map at set chances.

ie legendary has a 0.5% rate.

Best way to read it is by going to the bottom to the while loop, and following the functions it calls
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
07 Sep 2014 05:31 PM
I'll make a function for you
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
07 Sep 2014 05:33 PM
--
stuff = {["lol"] = 1, ["ROFL"] = 1}

function getThing()
local thingy = {}

for i,v in pairs(stuff) do
for i2 = 1,v do
table.insert(thingy, i)
end
end

return thingy[math.random(1,#thingy)]
end

print(getThing())
--

Increase the number to increase the chances.
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:42 PM
Let me explain,

The script I posted makes "Item" either civ or milt every 600 seconds

if Item is Civ then another script spawns an Item from CivLoot into workspace

if script.Parent.LootValue.Value == "Civ" then
script.Parent.CivLoot:GetChildren(CivL)
CivL:Clone(LootClone).Parent = game.Workspace
CivL:MoveTo(game.Workspace.CivItemSpawnPoint.Position)
elseif script.Parent.LootValue.Value == "Milt" then
script.Parent.MiltLoot:GetChildren(MiltL)
MiltL:Clone(LootClone).Parent = game.Workspace
MiltL:MoveTo(game.Workspace.MiltItemSpawnPoint.Position)
wait(300)
if CivL.Parent == game.Workspace then
CivL:Destroy()
if MiltL.Parent == game.Workspace then
CivL:Destroy()
end
end
end

and spawns miltloot if the lootvalue is milt

but the value never changes and nothing spawns to the coressponding points
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:46 PM
b
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
07 Sep 2014 05:51 PM
yo
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