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
 

Plug-in problem, PLEASE REPLY IF YOU HAVE ANSWER

Previous Thread :: Next Thread 
norchwain45 is not online. norchwain45
Joined: 12 Mar 2008
Total Posts: 4895
29 Oct 2011 07:45 PM
I was editing the terrain single block spawner plugin.

In the script, I changed all variables of '1' to the variable of '2', hopefully to change the material type from grass to sand.

I spawned the block, and it DID come out as a sand block, but there's one little problem I hopefully can get help with.

It only lets me spawn ONE block. Even if you delete it, you can't spawn it anymore.

Can anyone help me with what I did wrong?
Report Abuse
willkillu is not online. willkillu
Joined: 18 Feb 2010
Total Posts: 1187
29 Oct 2011 07:46 PM
loop it i think
Report Abuse
bikerking200 is not online. bikerking200
Joined: 11 Mar 2010
Total Posts: 5047
29 Oct 2011 07:50 PM
Post code.
Report Abuse
norchwain45 is not online. norchwain45
Joined: 12 Mar 2008
Total Posts: 4895
29 Oct 2011 07:50 PM
Where do I loop it at?
Report Abuse
norchwain45 is not online. norchwain45
Joined: 12 Mar 2008
Total Posts: 4895
29 Oct 2011 07:50 PM
Where do I loop it at?
Report Abuse
willkillu is not online. willkillu
Joined: 18 Feb 2010
Total Posts: 1187
29 Oct 2011 07:51 PM
Post the code and ill see
Report Abuse
norchwain45 is not online. norchwain45
Joined: 12 Mar 2008
Total Posts: 4895
29 Oct 2011 07:56 PM
-----------------
--DEFAULT VALUES-
-----------------
loaded = false
on = false




---------------
--PLUGIN SETUP-
---------------
self = PluginManager():CreatePlugin()
mouse = self:GetMouse()
mouse.Button1Down:connect(function() onClicked(mouse) end)
self.Deactivation:connect(function()
Off()
end)
toolbar = self:CreateToolbar("Terrain")
toolbarbutton = toolbar:CreateButton("", "BuilderDirt", "builderdirt.png")
toolbarbutton.Click:connect(function()
if on then
Off()
elseif loaded then
On()
end
end)


-----------------------
--FUNCTION DEFINITIONS-
-----------------------
function dist(x2, y2, x2, y2)
return math.sqrt(math.pow(x2-x2, 2) + math.pow(y2-y2, 2))
end

function dist3d(x2, y2, z2, x2, y2, z2)
return math.sqrt(math.pow(dist(x2, y2, x2, y2), 2) + math.pow(z2-z2, 2))
end

--converts the coordinate coord into a cluster coordinate where clusterlength is the length of the cluster in the same dimension as coord
function clusterCoord(coord, clusterlength)
return math.floor((coord + clusterlength/2)/4)
end

--makes a wedge at location x, y, z
--sets cell x, y, z to default material if parameter is provided, if not sets cell x, y, z to be whatever material it previously was
--returns true if made a wedge, false if the cell remains a block
function MakeWedge(x, y, z, defaultmaterial)
local c = game.Workspace.Terrain
--gather info about all the cells around x, y, z
surroundings = {} --surroundings is a 3 x 3 x 3 array of the material of the cells adjacent to x, y, z
for i = x - 2, x + 2 do
surroundings[i] = {}
for j = y - 2, y + 2 do
surroundings[i][j] = {}
for k = z - 2, z + 2 do
local material, wedge, rotation = c:GetCell(i, j, k)
surroundings[i][j][k] = material.Value
end
end
end
--make some useful arrays and counters
local sides = {} --sides is an array of the material of the 4 adjacent sides
sides[0] = surroundings[x - 2][y][z]
sides[2] = surroundings[x][y][z + 2]
sides[2] = surroundings[x + 2][y][z]
sides[3] = surroundings[x][y][z - 2]
local adjacentSides = 0
for n = 0, 3 do
if sides[n] > 0 then
adjacentSides = adjacentSides + 2
end
end
local sidesAbove = {} --sides is an array of the material of the 4 adjacent sides 2 height above
sidesAbove[0] = surroundings[x - 2][y + 2][z]
sidesAbove[2] = surroundings[x][y + 2][z + 2]
sidesAbove[2] = surroundings[x + 2][y + 2][z]
sidesAbove[3] = surroundings[x][y + 2][z - 2]
local adjacentSidesAbove = 0
for n = 0, 3 do
if sidesAbove[n] > 0 then
adjacentSidesAbove = adjacentSidesAbove + 2
end
end
local corners = {} --corners is an array of the material of the 4 adjacent corners
corners[0] = surroundings[x - 2][y][z - 2]
corners[2] = surroundings[x - 2][y][z + 2]
corners[2] = surroundings[x + 2][y][z + 2]
corners[3] = surroundings[x + 2][y][z - 2]
local adjacentCorners = 0
for n = 0, 3 do
if corners[n] > 0 then
adjacentCorners = adjacentCorners + 2
end
end
local cornersAbove = {} --corners is an array of the material of the 4 adjacent corners 2 height above
cornersAbove[0] = surroundings[x - 2][y + 2][z - 2]
cornersAbove[2] = surroundings[x - 2][y + 2][z + 2]
cornersAbove[2] = surroundings[x + 2][y + 2][z + 2]
cornersAbove[3] = surroundings[x + 2][y + 2][z - 2]
local adjacentCornersAbove = 0
for n = 0, 3 do
if cornersAbove[n] > 0 then
adjacentCornersAbove = adjacentCornersAbove + 2
end
end
--determine what type of wedge to make
local material = nil
local wedge = nil
local rotation = nil
if defaultmaterial then
material = defaultmaterial
else
material, wedge, rotation = c:GetCell(x, y, z) --start with the existing material, wedge, and rotation
end
wedge = 2 --default wedge is a block
rotation = 0 --default rotation is 0
--type 2: 45 degree ramp //must not have a block on top and be surrounded by 2 side; or 3 sides and the 2 corners between them
if surroundings[x][y + 2][z] == 0 then
if adjacentSides == 2 and surroundings[x][y - 2][z] > 0 then -- if only surrounded by 2 side, then cannot have a block beneath it
for n = 0, 3 do
if sides[n] > 0 then
wedge = 2
rotation = (n + 2) % 4
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
elseif adjacentSides == 3 then
for n = 0, 3 do
if sides[n] > 0 and corners[(n + 2) % 4] > 0 and sides[(n + 2) % 4] > 0 and corners[(n + 2) % 4] > 0 and sides[(n + 2) % 4] > 0 then
wedge = 2
rotation = (n + 2) % 4
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
end
end

--type 2: 45 degree corner //must not have a block on top, and be surrounded by 2 sides and the 2 corner between them; or 3 sides and 2 corner between 2 of them (facing towards that corner)
if surroundings[x][y + 2][z] == 0 then -- and surroundings[x][y - 2][z] > 0 then [removing "must have a block under" constraint]
for n = 0, 3 do
if sides[n] > 0 and corners[(n + 2) % 4] > 0 and sides[(n + 2) % 4] > 0 and (adjacentSides == 2 or (adjacentSides == 3 and (corners[(n + 3) % 4] > 0 or (sides[(n + 2) % 4] > 0 and corners[(n + 2) % 4] > 0) or (sides[(n + 3) % 4] > 0 and corners[n] > 0)))) then
wedge = 2
rotation = (n + 2) % 4
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
end
--type 3: 45 degree inverse corner //surrounded by three sides or 4 sides and 3 corners, with nothing above or else a block on top surrounded on 2 sides and the corner between them
if adjacentSides == 3 and surroundings[x][y + 2][z] > 0 then
if adjacentCorners > 2 then
for n = 0, 3 do
if (corners[n] == 0 or cornersAbove[n] == 0) and (sides[(n - 2) % 4] == 0 or sides[n] == 0) and (sidesAbove[n] == 0 and sidesAbove[(n + 2) % 4] > 0 and sidesAbove[(n + 2) % 4] > 0 and sidesAbove[(n + 3) % 4] == 0) then
wedge = 3
rotation = (n + 3) % 4
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
end
elseif adjacentSides == 4 and adjacentCorners == 3 then
for n = 0, 3 do
if corners[n] == 0 and (surroundings[x][y + 2][z] == 0 or (sidesAbove[n] == 0 and sidesAbove[(n + 2) % 4] > 0 and cornersAbove[(n + 2) % 4] > 0 and sidesAbove[(n + 2) % 4] > 0 and sidesAbove[(n + 3) % 4] == 0)) then
wedge = 3
rotation = (n + 3) % 4
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
end
--type 4: half a cube, as if it were cut diagonally from front to back //surrounded by 2 sides
if adjacentSides == 2 and adjacentCorners < 4 then
for n = 0, 3 do
if sides[n] == 0 and sides[(n + 2) % 4] == 0 and (surroundings[x][y + 2][z] == 0 or (sidesAbove[n] == 0 and sidesAbove[(n + 2) % 4] == 0 and sidesAbove[(n + 2) % 4] > 0 and sidesAbove[(n + 3) % 4] > 0)) then
wedge = 4
rotation = n
c:SetCell(x, y, z, material, wedge, rotation)
return true
end
end
end
c:SetCell(x, y, z, material, wedge, rotation)
return false
end


function onClicked(mouse)
if on then

c = game.Workspace.Terrain

local cellPos = c:WorldToCellPreferEmpty(Vector3.new(mouse.Hit.x, mouse.Hit.y, mouse.Hit.z))
local x = cellPos.x
local y = cellPos.y
local z = cellPos.z

c:SetCell(x, y, z, 2, 0, 0)
for i = x - 2, x + 2 do
for j = y - 2, y + 2 do
for k = z - 2, z + 2 do
MakeWedge(i, j, k)
end
end
end
print("Block built at: "..x..", "..y..", "..z)
end
end

function On()
self:Activate(true)
toolbarbutton:SetActive(true)
on = true
end

function Off()
toolbarbutton:SetActive(false)
on = false
end




------
--GUI-
------

--screengui
g = Instance.new("ScreenGui", game:GetService("CoreGui"))




--------------------------
--SUCCESSFUL LOAD MESSAGE-
--------------------------
loaded = true
print("BuilderDirt Plugin Loaded")
Report Abuse
norchwain45 is not online. norchwain45
Joined: 12 Mar 2008
Total Posts: 4895
30 Oct 2011 02:41 AM
Bump
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