ColdSmoke
|
  |
| Joined: 02 Jan 2012 |
| Total Posts: 5784 |
|
|
| 21 Aug 2013 03:14 PM |
In this dynamic fire I'm trying to create, things have a different chance of catching fire depending on their material, and In order to make this efficient I put material names and catch chances in tables and instead of having 9 ifs I have
local ML = {"Concrete","CorrodedMetal","DiamondPlate","Foil","Grass","Ice","Plastic","Slate","Wood"} local MLT = {9,8,6,5,0.2,1,3,10,1} for e = 1, #ML do --SPREAD START if obj.Material == ML[e] then local seed = math.random(1, 2*MLT[e]) -stuff if seed <= 1 then --stuff end end end
But I'm having an issue. There's no error output, and the script seems to think that The blocks material doesn't match any of those in the table, even though the words in table match PERFECTLY with the actual material names. I'm not sure if this is a roblox bug or what's going on, but you can experiment in this uncopylocked place:
http://www.roblox.com/--place?id=127216292
And here's the whole unedited script: ____________________________________________________________________ function mngtude (subject) local Volume = (subject.Size.x*subject.Size.y*subject.Size.z) local Mag = (Volume+(Volume^.5))/512 if Mag > 1 then Mag = 1 end return Mag end
local multiplier = mngtude(script.Parent)*25 print(mngtude(script.Parent)) print(multiplier)
local ML = {"Concrete","CorrodedMetal","DiamondPlate","Foil","Grass","Ice","Plastic","Slate","Wood"} local MLT = {9,8,6,5,0.2,1,3,10,1}
while wait() do local objects = game.Workspace:FindPartsInRegion3( Region3.new( Vector3.new( (script.Parent.Position.x - script.Parent.Size.x/2) - multiplier, (script.Parent.Position.y - script.Parent.Size.y/2) - multiplier, (script.Parent.Position.z - script.Parent.Size.z/2) - multiplier ), Vector3.new( (script.Parent.Position.x + script.Parent.Size.x/2) + multiplier, (script.Parent.Position.y + script.Parent.Size.y/2) + multiplier, (script.Parent.Position.z + script.Parent.Size.z/2) + multiplier ) ), script.Parent, 100 ) print(unpack(objects)) for i, obj in pairs(objects) do print(obj.Name.."yolo") for e = 1, #ML do --SPREAD START if obj.Material == ML[e] then local seed = math.random(1, 2*MLT[e]) print(seed) print(obj) if seed <= 1 then print("Spread") Instance.new("Fire", obj) Fire = script:clone() Fire.Parent = obj end end end end end
|
|
|
| Report Abuse |
|
|
| |
|
ZachBloxx
|
  |
| Joined: 26 Jun 2013 |
| Total Posts: 2833 |
|
|
| 21 Aug 2013 04:09 PM |
| You can use a string to set a material. |
|
|
| Report Abuse |
|
|
mic144
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 1598 |
|
|
| 21 Aug 2013 04:10 PM |
^ Plus, it's mostlikely a bug. |
|
|
| Report Abuse |
|
|
| |
|
mic144
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 1598 |
|
|
| 21 Aug 2013 04:15 PM |
| Maybe. Idk. Lets just wait and see. |
|
|
| Report Abuse |
|
|
ColdSmoke
|
  |
| Joined: 02 Jan 2012 |
| Total Posts: 5784 |
|
|
| 21 Aug 2013 04:19 PM |
Em
Enum?
I'll go to wiki then...
Lobster in disguise |
|
|
| Report Abuse |
|
|
| |
|
mic144
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 1598 |
|
|
| 21 Aug 2013 04:30 PM |
Try this!:
function mngtude (subject) local Volume = (subject.Size.x*subject.Size.y*subject.Size.z) local Mag = Volume/512 if Mag < 1 then Mag = 1 end return Mag end
local multiplier = mngtude(script.Parent)*8
print(multiplier)
local ML = {Enum.Material.Concrete,Enum.Material.CorrodedMetal,Enum.Material.DiamondPlate,Enum.Material.Foil,Enum.Material.Grass,Enum.Material.Ice,Enum.Material.Plastic,Enum.Material.Slate,Enum.Material.Wood} local MLT = {9,8,6,5,0.2,1,3,10,1}
while wait() do local objects = game.Workspace:FindPartsInRegion3( Region3.new( Vector3.new( (script.Parent.Position.x - script.Parent.Size.x/2) - multiplier, (script.Parent.Position.y - script.Parent.Size.y/2) - multiplier, (script.Parent.Position.z - script.Parent.Size.z/2) - multiplier ), Vector3.new( (script.Parent.Position.x + script.Parent.Size.x/2) + multiplier, (script.Parent.Position.y + script.Parent.Size.y/2) + multiplier, (script.Parent.Position.z + script.Parent.Size.z/2) + multiplier ) ), script.Parent, 100 ) print(unpack(objects)) for i, obj in pairs(objects) do for i = 1, #ML do --SPREAD START if obj.Material == ML[i] then local seed = math.random(1, 2*MLT[i]) if seed <= 1 then Instance.new("Fire", obj) Fire = script:clone() Fire.Parent = obj end end end end end |
|
|
| Report Abuse |
|
|
ColdSmoke
|
  |
| Joined: 02 Jan 2012 |
| Total Posts: 5784 |
|
|
| 21 Aug 2013 04:46 PM |
Ah! Thanks a ton! it works perfectly.
Now to finish the script and control the fires c:
Lobster in disguise |
|
|
| Report Abuse |
|
|
|
| 21 Aug 2013 04:46 PM |
If Part.Material.Name == String then
Also, you can do
{"Material Name" == ThatNumber, "Material Name 2" == ThatNumber} |
|
|
| Report Abuse |
|
|
mic144
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 1598 |
|
| |
|
ColdSmoke
|
  |
| Joined: 02 Jan 2012 |
| Total Posts: 5784 |
|
|
| 21 Aug 2013 04:57 PM |
So down where the script copies itself, I changed the if to this
if seed <= 1 and not obj:FindFirstChild("Fire")then print("Spread") Instance.new("Fire", obj) Fire = script:clone() Fire.Parent = obj wait(1) end
But it still continues even if the obj has a child named Fire Any idea why this is?
Lobster in disguise |
|
|
| Report Abuse |
|
|
| |
|
|
| 21 Aug 2013 04:58 PM |
@Constructor189: ""yolo""
Please implode. |
|
|
| Report Abuse |
|
|
ZachBloxx
|
  |
| Joined: 26 Jun 2013 |
| Total Posts: 2833 |
|
| |
|
mic144
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 1598 |
|
|
| 21 Aug 2013 05:01 PM |
if (seed <= 1) and (obj:FindFirstChild("Fire") ~= nil) then print("Spread") Instance.new("Fire", obj) Fire = script:clone() Fire.Parent = obj wait(1) end
|
|
|
| Report Abuse |
|
|