|
| 20 Jul 2017 09:06 PM |
Eyo! I'm working on a 2-d platformer with my bro and decided to work on a script that involves higher-point coins having a higher spawn chance as you progress through the game. The main problem is that I don't know how to make these coins even spawn, not to mention the whole higher-chance-spawn stuff. I've been looking everywhere about spawning, but block themselves (except for vehicle spawners) are nowhere to be found. I just started coding on the Roblox engine yesterday, but my bro said he doesn't know either (he's slightly better than me at coding). Here's what I have so far for the script:
t = time r = math.random(if t < 100 or t = 100, then r < 20 or r = 20 if 100 < t < 130 or t = 130, then 10 < r < 30 or r = 30 if 130 < t < 200 or t = 200, then 20 < r < 40 or r = 40 if 200 < t < 300 or t = 130, then 45 < r < 80 or r = 80 if 300 < t < 345 or t = 400, then 60 < r < 85 or r = 85 if 345 < t < 410 or t = 410, then 70 < r < 90 or r = 90 if 410 < t < 430 or t = 430, then 90 < r < 95 or r = 95 if 430 < t < 530 or t = 530, then 95 < r < 100 or r = 100 if t > 530 , then r = 100) end
r < 10 or r = 10, then SBronze 10 < r < 25 or r = 15, then SSilver 25 < r < 50 or r = 50, then SGold 50 < r < 75 or r = 75, then SPlatnium r > 75, then SRainbow end end
SRainbow = SPlatnium = SGold = SSilver = SBronze =
I don't know what to put for the last 5 lines (these are the five coins, each having their varying value. The S before each coin-type means spawn. The crazy if, then statements is me attempting to put my ideas into code)
Thanks! |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 09:30 PM |
I think this is what you intended:
t = time -- not sure if you meant the time built-in function here local lrand = 0 local urand = 0 if t <= 100 then urand = 20 elseif t <= 130 then lrand = 10 urand = 30 elseif t <= 200 then lrand = 20 urand = 40 elseif t <= 300 then lrand = 45 urand = 80 elseif t <= 345 then lrand = 60 urand = 85 elseif t <= 410 then lrand = 70 urand = 90 elseif t <= 430 then lrand = 90 urand = 95 elseif t <= 530 then lrand = 95 urand = 100 else lrand = 100 urand = 100 end local r = urand - (urand-lrand)*math.random() local coin = SBronze if r > 75 then coin = SRainbow elseif r > 50 then coin = SPlatinum elseif r > 25 then coin = SGold elseif r > 10 then coin = SSilver end
SRainbow = -- ??? Don't know what you want here SPlatnium = SGold = SSilver = SBronze = |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2017 10:12 PM |
Lua doesn't support A < B < C You can only do one of those operations at a time. |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 20 Jul 2017 10:14 PM |
You can't place an 'if' in the arguments in the math.random() function, you can use ternary operations tho
Also, math.random() doesn't need an 'end'
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
|
| 21 Jul 2017 09:39 AM |
| Thanks! You guys are awesome. I'll see if it works Bunny (The SRainbow etc are unnecessary now that I see what you've done in the code.) So will this replace a physical object with the object I want based on the probability? |
|
|
| Report Abuse |
|
|
|
| 21 Jul 2017 09:47 AM |
| Also, what measurement does the time (function?) use? (ex. Milliseconds, seconds, minutes etc.) |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 21 Jul 2017 11:39 AM |
Use the wiki man, that's why it exists.
http://wiki.roblox.com/index.php?title=Global_namespace/Roblox_namespace#time
Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil) |
|
|
| Report Abuse |
|
|
marfit
|
  |
| Joined: 10 Jan 2013 |
| Total Posts: 2539 |
|
|
| 21 Jul 2017 12:02 PM |
| Just have a loop that when each block is created, its position is math.random in every direction. For the color, you can have a table that selects colors based on their corresponding number with math.random. For material, same thing, |
|
|
| Report Abuse |
|
|