Mdbook

Untitled

Mar 6th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.42 KB | None | 0 0
  1. COLOR="White"
  2. SIZE=0.25
  3. player = game:GetService('Players').LocalPlayer
  4. Debris = game:GetService("Debris")
  5. Http = game:GetService("HttpService")
  6.  
  7. for i,v in pairs(player.PlayerGui:children())do
  8. if v:IsA'HandlesBase'then v:Destroy()end
  9. end
  10.  
  11. MODELNAME="M DrawingParts "..player.Name
  12.  
  13. partCount=0
  14.  
  15. local ExistingModel = Workspace.Terrain:FindFirstChild (MODELNAME)
  16.  
  17. if ExistingModel then
  18. print("Found existing model")
  19. for i,v in pairs(ExistingModel:children()) do
  20. if v:IsA'Part' then
  21. table.insert(partList,v)
  22. partCount=partCount+1
  23. end
  24. end
  25. Parts = ExistingModel
  26. else
  27. Parts = Instance.new("Model",Workspace.Terrain)
  28. Parts.Name=MODELNAME
  29. end
  30.  
  31. c=CFrame.new
  32. a=function(x,y,z)return CFrame.Angles(x or 0,y or 0,z or 0)end
  33. IS=Instance.new
  34. bcol = BrickColor.new
  35.  
  36. doAnchor=false
  37.  
  38. pcall(function() player.Backpack.DrawFreely:Destroy() end) --Remove old tool
  39.  
  40. Tool=Instance.new("Tool",player.Backpack)
  41.  
  42. Tool.Name="DrawFreely"
  43. Tool.TextureId="http://www.roblox.com/asset/?id=53252159"
  44. Tool.CanBeDropped=false
  45.  
  46. partParent=nil
  47. function P(x,y,z,col,tr)
  48. local part=Instance.new("Part",partParent)
  49. part.Size=Vector3.new(x,y,z)
  50. for i,v in pairs(Enum.NormalId:GetEnumItems())do --Easy way to set all surfaces to smooth.
  51. part[v.Name..'Surface']=10
  52. end
  53. part.Locked=true
  54. part.Transparency = tr or 0
  55. part.BrickColor=BrickColor.new(col or "")
  56. return part
  57. end
  58.  
  59. function E(what)
  60. local tab={}
  61. if type(what) ~= "table" then
  62. table.insert(tab,what)
  63. else
  64. tab=what
  65. end
  66. return function(args)
  67. for i,object in pairs(tab) do
  68. for arg,value in pairs(args) do
  69. local argExists=(object[arg] ~= nil)
  70. if argExists then
  71. object[arg]=value
  72. end
  73. end
  74. end
  75. return what
  76. end
  77. end
  78.  
  79. handle=P(.4,1,.4,'Black')
  80. handle.Parent=Tool
  81. handle.Name="Handle"
  82.  
  83. function C(what)
  84. return function(bar)
  85. local obj=Instance.new(what)
  86. for arg,val in pairs(bar) do
  87. if arg == "_P" then
  88. obj.Parent = val
  89. else
  90. if obj[arg] then
  91. obj[arg]=val
  92. end
  93. end
  94. end
  95. return obj
  96. end
  97. end
  98.  
  99. E(Instance.new("SpecialMesh",handle)){MeshId="http://www.roblox.com/asset/?id=100454579";
  100. TextureId="http://www.roblox.com/asset/?id=202074573";
  101. Scale=Vector3.new(1.5,1.5,1.5) }
  102.  
  103. Active=false
  104. mouse = player:GetMouse()
  105. mouse.TargetFilter=Parts
  106.  
  107. Undoing=false
  108.  
  109. function spaceWord(text,spaces)
  110. local result=""
  111. for word in text:gmatch "%w+" do
  112. for pos,letter in word:gmatch "()(%w)" do
  113. if pos > 0 then
  114. result = result..string.rep(" ",(spaces or 1))..letter
  115. end
  116. end
  117. result = result..string.rep(" ",(spaces or 1))
  118. end
  119. return result
  120. end
  121.  
  122. udim=function(a,b,c,d)
  123. if type(a)=='string'then
  124. x,y=tostring(a):match('(%d*%.*%d*),(%d*%.*%d*)')
  125. return UDim2.new(x or 0,x2 or 0,y or 0,y2 or 0)
  126. else
  127. return UDim2.new(a or 0,c or 0,b or 0,d or 0)
  128. end end
  129.  
  130. pcall(function() player.PlayerGui.M_DrawingGui:Destroy() end)
  131. Gui=Instance.new("ScreenGui",player.PlayerGui)
  132. Gui.Name = "M_DrawingGui"
  133.  
  134. function count_all_parts(obj2)
  135. local value=0
  136. local function recurse(obj)
  137. if obj:IsA'Part'then
  138. value=value+1
  139. end
  140. for _,v in pairs(obj:GetChildren()) do
  141. recurse(v)
  142. end
  143. end
  144. recurse(obj2)
  145. return value
  146. end
  147.  
  148. do --gui
  149. mainFrame = E(IS("Frame",Gui)){
  150. Size = udim(0,0,200,200);
  151. Position = udim(0,.5);
  152. }
  153.  
  154. topbar = E(IS("TextLabel",mainFrame)){
  155. Size=udim(1,.1);
  156. Text=spaceWord("Configuration",2);
  157. BackgroundTransparency=1;
  158. TextXAlignment="Center";
  159. BorderSizePixel=4;
  160. }
  161.  
  162. othersFrame=E(IS("Frame",mainFrame)){
  163. Size=udim(1,.9);
  164. Position=udim(0,.1);
  165. }
  166.  
  167. infobox = E(IS("Frame",othersFrame)){
  168. Size = udim(.3,.9);
  169. Position = udim(.65,.05);
  170. BorderSizePixel=0;
  171. }
  172.  
  173. div = 1/4
  174.  
  175. tab = {}
  176. frame = E(IS("Frame",infobox)){
  177. Size = udim(1,div);
  178. }
  179. lab = E(IS("TextLabel",frame)){
  180. Size = udim(.5,1);
  181. Text = "Parts";
  182. TextScaled=true;
  183. BackgroundTransparency=1;
  184. }
  185. partCount = count_all_parts(Parts)
  186. partcountLab = E(IS("TextLabel",frame)){
  187. Size = udim(.5,1); Position = udim(.5,0);
  188. Text = partCount;
  189. BackgroundTransparency=1;
  190. TextXAlignment = "Right";
  191. }
  192.  
  193. frame = E(IS("Frame",infobox)){
  194. Size = udim(1,div);
  195. Position = udim(0,div*2);
  196. }
  197. lab = E(IS("TextLabel",frame)){
  198. Size = udim(.5,1);
  199. Text = "Color";
  200. TextScaled=true;
  201. BackgroundTransparency=1;
  202. }
  203. colorLab = E(IS("Frame",frame)){
  204. Size=udim(.5,1);Position=udim(.5,0);
  205. BackgroundColor=BrickColor.new(COLOR);
  206. BorderSizePixel=0;
  207. }
  208.  
  209. frame = E(IS("Frame",infobox)){
  210. Size = udim(1,div);
  211. Position = udim(0,.7);
  212. }
  213. lab = E(IS("TextLabel",frame)){
  214. Size = udim(.5,1);
  215. Text = "Size";
  216. TextScaled=true;
  217. BackgroundTransparency=1;
  218. }
  219. sizeBox=E(IS("TextBox",frame)){
  220. Size = udim(.45,1);Position = udim(.5,0);
  221. BackgroundTransparency = 1;
  222. Text = SIZE;
  223. TextScaled = true;
  224. }
  225.  
  226. frame = E(IS("Frame",infobox)){
  227. Size = udim(1,.1);
  228. Position = udim(0,1/5*4);
  229. }
  230. lab = E(IS("TextLabel",frame)){
  231. Size = udim(.5,1);
  232. Text = "Lock Y movement on drag";
  233. TextScaled=true;
  234. BackgroundTransparency=1;
  235. }
  236. checkBox=E(IS("TextButton",frame)){
  237. Size = udim(.45,1);Position = udim(.5,0);
  238. BackgroundTransparency = 1;
  239. Text = "X";
  240. TextScaled = true;
  241. }
  242.  
  243. div = 1/#infobox:children()
  244. for i,v in pairs(infobox:children()) do
  245. v.Size = udim(1,div)
  246. v.Position = udim(0,(-1+i)*div)
  247. end
  248.  
  249. checkBox.MouseButton1Click:connect(function()
  250. lock_y_movement = not lock_y_movement
  251. if lock_y_movement then
  252. checkBox.Text = "X"
  253. else
  254. checkBox.Text = ""
  255. end
  256. end)
  257.  
  258. sizeBox.FocusLost:connect(function()
  259. SIZE=tonumber(sizeBox.Text)
  260. end)
  261.  
  262. onFor,onBak=function()
  263. SIZE=SIZE+.1
  264. sizeBox.Text=SIZE
  265. end,function()
  266. SIZE=SIZE-.1
  267. sizeBox.Text=SIZE
  268. end
  269.  
  270. sizeBox.MouseWheelForward:connect(onFor)
  271. sizeBox.MouseWheelBackward:connect(onBak)
  272. lab.MouseWheelForward:connect(onFor)
  273. lab.MouseWheelBackward:connect(onBak)
  274.  
  275. colorFrame=E(IS("Frame",othersFrame)){
  276. Size=udim(.6,1);
  277. }
  278.  
  279. --Color Palette
  280. for x = 0,7 do
  281. for y = 0,7 do
  282. local but=E(IS("TextButton",colorFrame)){
  283. Size = udim(1/8,1/8);
  284. Position = udim(1/8*x,1/8*y);
  285. Text = '';
  286. BackgroundColor = BrickColor.palette(x+y*8);
  287. }
  288. but.MouseButton1Click:connect(function()
  289. COLOR=but.BackgroundColor.Name
  290. colorLab.BackgroundColor = but.BackgroundColor
  291. end)
  292. end
  293. end
  294. for i,v in pairs(mainFrame:children()) do
  295. v.BorderSizePixel=0;
  296. end
  297.  
  298. end
  299.  
  300. do --gui2
  301. local prev_frame_pos = mainFrame.Position
  302. local prev_frame_size = mainFrame.AbsoluteSize
  303. local mainFrame = C'Frame'{_P=Gui;
  304. Size = udim(0,0,100,200);
  305. Position = prev_frame_pos + udim(0,0,prev_frame_size.x/2+100)
  306. }
  307.  
  308. local topBar = C'TextLabel'{_P=mainFrame;
  309. Size=udim'1,.1';
  310. Text = spaceWord("Layers", 4);
  311. }
  312. local layerFrame = C'Frame'{_P=mainFrame;
  313. Size = udim'1,.9';
  314. Position = udim'0,.1';
  315. }
  316. local add_button = C'TextButton'{_P=mainFrame;
  317. Text='+';
  318. FontSize=10;
  319. Size=udim'.3,.1';
  320. Position = udim'.7,.9';
  321. BackgroundColor = bcol'Mint';
  322. }
  323.  
  324. Selected_layer = 0
  325. Layers = {}
  326.  
  327. max_layers = 10
  328. layer_height = 1/max_layers
  329.  
  330. layer_bg_col = bcol"White"
  331. local h,s,v = Color3.toHSV(layer_bg_col.Color)
  332. highlight_col = bcol(Color3.fromHSV(h,s,v-.15))
  333. h,s,v = nil,nil,nil
  334.  
  335. function getLayers()
  336. local res = {}
  337. for i,v in pairs(Parts:children()) do
  338. if v:IsA'Model' then
  339. table.insert(res,v)
  340. end
  341. end
  342. return res
  343. end
  344.  
  345. layer_position = 0
  346.  
  347. prev_click_t=tick()
  348. function update_layers()
  349. layerFrame:ClearAllChildren()
  350. for i,layer in pairs(getLayers()) do
  351. layer.Position.Value = i
  352. local layer_frame = C'Frame'{_P = layerFrame;
  353. Size = udim(1,layer_height);
  354. Position = udim(0,(-1+i)*layer_height);
  355. }
  356. local remove_button = C'TextButton'{_P=layer_frame;
  357. Size = udim'.2,1';
  358. Text = 'X';
  359. BackgroundColor = bcol'Bright red';
  360. TextScaled= true;
  361. }
  362. local hide_button = C'TextButton'{_P=layer_frame;
  363. Size = udim'.2,1';
  364. Position = udim'.2,0';
  365. Text = 'H';
  366. TextScaled = true;
  367. Name = 'Hidebutton'
  368. }
  369. local name_box = C'TextButton'{_P=layer_frame;
  370. Size = udim'.6,1';
  371. Position = udim'.4,0';
  372. Text = layer.Name;
  373. TextScaled=true;
  374. BackgroundColor = layer_bg_col;
  375. AutoButtonColor = false;
  376. }
  377. layer.name_box.Value = name_box
  378. hideLayer(layer,true)
  379. -- print(layer.Visible.Value)
  380. if layer.Selected.Value == true then
  381. name_box.BackgroundColor = highlight_col
  382. else
  383. name_box.BackgroundColor = layer_bg_col
  384. end
  385.  
  386. -- for i,v in pairs(layer:children())do
  387. -- if v:IsA'Part'then
  388.  
  389.  
  390. remove_button.MouseButton1Down:connect(function()
  391. removeLayer(layer)
  392. end)
  393.  
  394. hide_button.MouseButton1Down:connect(function()
  395. hideLayer(layer)
  396. end)
  397.  
  398. name_box.MouseButton2Down:connect(function()
  399. popupRenameWindow(layer)
  400. end)
  401.  
  402. name_box.MouseButton1Down:connect(function()
  403. select_layer(layer)
  404. end)
  405.  
  406. end
  407. end
  408.  
  409. function mergeLayer(layer)
  410. local prev_layer = getLayers()[layer.Position.Value-1] --previous layer
  411. if not prev_layer then warn("Cant do merging") return end
  412. local part_t = {} --collect parts to this
  413.  
  414. for i,v in pairs(layer:children()) do
  415. if v:IsA'Part'then
  416. table.insert(part_t,v)
  417. end
  418. end
  419. for _,v in pairs(part_t) do
  420. v.Parent = prev_layer
  421. end
  422. removeLayer(layer)
  423. update_layers()
  424. end
  425.  
  426. function cloneLayer(layer)
  427. local cl=layer:Clone()
  428. cl.Parent=Parts
  429. cl.Name = layer.Name..'_cl'
  430. cl.Position.Value = #getLayers()
  431. update_layers()
  432. select_layer(cl)
  433. end
  434.  
  435. function removeLayer(layer)
  436. if #getLayers() == 0 then return end
  437. local pos1 = layer.Position.Value
  438. local pos2 = Selected_Layer.Position.Value
  439. local fou=getLayers()[pos1-1]
  440. layer:Destroy()
  441. update_layers()
  442.  
  443.  
  444. if pos1 == pos2 and getLayers()[pos2-1] then
  445. select_layer(getLayers()[pos2-1])
  446. elseif pos1 == pos2 and pos2 == 1 then
  447. select_layer(getLayers()[#getLayers()])
  448. end
  449.  
  450. end
  451.  
  452. function hideLayer(layer,se)
  453. if not layer:FindFirstChild'name_box' then return end
  454. local back = layer.name_box.Value.Parent:FindFirstChild'Hidebutton'
  455. if not se then
  456. layer.Visible.Value = not layer.Visible.Value
  457. end
  458.  
  459. if layer.Visible.Value == true then
  460. for i,v in pairs(layer:children()) do
  461. if v:IsA'Part' then
  462. v.Transparency = 0
  463. end
  464. end
  465. -- layer.name_box.Value.Text = layer.Name
  466. back.BackgroundColor=bcol'White'
  467.  
  468. elseif layer.Visible.Value == false then
  469. for i,v in pairs(layer:children()) do
  470. if v:IsA'Part' then
  471. v.Transparency = 1
  472. end
  473. end
  474. -- layer.name_box.Value.Text = layer.Name.." (h)"
  475. back.BackgroundColor = bcol'Mint'
  476. end
  477. end
  478.  
  479. lock_y_movement = true
  480. function moveLayer(layer,mouse)
  481. Moving = true
  482. local layerframe = layer:GetModelCFrame()
  483. local y = layerframe.Y
  484. while Moving do
  485. local poos = Vector3.new(mouse.hit.p.x,y,mouse.hit.p.z)
  486. poos = (lock_y_movement and poos or mouse.hit.p)
  487. layer:TranslateBy((layer:GetModelCFrame().p-poos)*-1)
  488. wait()
  489. end
  490. end
  491.  
  492. do ---PRECISE MOVEMENT
  493. handle_part = nil
  494. local handle = nil
  495. function preciseMove(layer,mouse)
  496. if not handle_part then
  497. handle_part = P(1,1,1,'Black',1)
  498. local layer_size = layer:GetExtentsSize()
  499. -- E{handle_part}{Anchored = true; CanCollide = false;
  500. -- Size = layer_size;}
  501. handle_part.Anchored = true
  502. handle_part.CanCollide = false
  503. -- handle_part.Size = layer_size
  504. handle_part.CFrame = CFrame.new(layer:GetModelCFrame().p)
  505.  
  506. handle_part.Parent = Workspace
  507. handle = C'Handles'{
  508. Style = Enum.HandlesStyle.Movement;
  509. }
  510. handle.Faces = Faces.new(Enum.NormalId.Top,Enum.NormalId.Right,
  511. Enum.NormalId.Front)
  512. -- Enum.NormalId.Bottom,Enum.NormalId.Back,Enum.NormalId.Left)
  513. handle.Adornee = handle_part
  514. handle.Parent = player.PlayerGui
  515.  
  516. local previous,fake_handle_part
  517. handle.MouseButton1Down:connect(function()
  518. previous = handle_part.CFrame
  519. fake_handle_part = handle_part:Clone()
  520. fake_handle_part.Parent=Workspace
  521. -- handle.Adornee = fake_handle_part
  522. end)
  523. local snap = 1
  524. handle.MouseDrag:connect(function(face,drag_distance)
  525. local difference = drag_distance % snap
  526.  
  527. local lower_deg = drag_distance - difference
  528. local upper_deg = drag_distance - difference + snap
  529.  
  530. local lower_deg_prox = math.abs(drag_distance - lower_deg)
  531. local upper_deg_prox = math.abs(drag_distance - upper_deg)
  532.  
  533. if lower_deg_prox <= upper_deg_prox then
  534. drag_distance = lower_deg
  535. else
  536. drag_distance = upper_deg
  537. end
  538.  
  539. local increase = drag_distance;
  540.  
  541. local cf
  542. --main thingy--
  543. if face == Enum.NormalId.Top then
  544. cf = CFrame.new(previous.p):toWorldSpace(
  545. CFrame.new(0,increase,0) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  546. elseif face == Enum.NormalId.Bottom then
  547. cf = CFrame.new(previous.p):toWorldSpace(
  548. CFrame.new(0,-increase,0) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  549. elseif face == Enum.NormalId.Right then
  550. cf = CFrame.new(previous.p):toWorldSpace(
  551. CFrame.new(increase,0,0) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  552. elseif face == Enum.NormalId.Left then
  553. cf = CFrame.new(previous.p):toWorldSpace(
  554. CFrame.new(-increase,0,0) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  555. elseif face == Enum.NormalId.Front then
  556. cf = CFrame.new(previous.p):toWorldSpace(
  557. CFrame.new(0,0,-increase) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  558. elseif face == Enum.NormalId.Back then
  559. cf = CFrame.new(previous.p):toWorldSpace(
  560. CFrame.new(0,0,increase) * CFrame.Angles (previous:toEulerAnglesXYZ() ) )
  561. end
  562.  
  563. layer:TranslateBy( (layer:GetModelCFrame().p - cf.p)*-1 )
  564. handle_part.CFrame = c(layer:GetModelCFrame().p)
  565. end)
  566. else
  567. handle_part:Destroy()
  568. handle:Destroy()
  569. handle_part = nil
  570. handle = nil
  571. end
  572. end
  573.  
  574. end
  575.  
  576. resize_handle=nil
  577. function resizeLayer(layer)
  578.  
  579. if not resize_handle then
  580.  
  581. local nearest={p=nil,m=math.huge}
  582. for i,v in pairs(layer:children()) do --Get Nearest Part to torso
  583. if v:IsA'Part'then
  584. if (v.Position-torso.Position).magnitude < nearest.m then
  585. nearest.m = (v.Position-torso.Position).magnitude
  586. nearest.p=v
  587. end
  588. end
  589. end
  590. if not nearest.p then return end
  591. resize_handle = C'Handles'{
  592. Style = Enum.HandlesStyle.Resize;
  593. Adornee = nearest.p;
  594. Faces = Faces.new(Enum.NormalId.Right,Enum.NormalId.Left,
  595. Enum.NormalId.Front,Enum.NormalId.Back);
  596. }
  597. resize_handle.Style = Enum.HandlesStyle.Resize
  598. resize_handle.Adornee = nearest.p;
  599. resize_handle.Parent=player.PlayerGui
  600. local snap = .1
  601. local previous
  602. local previous_cframes
  603. resize_handle.MouseButton1Down:connect(function()
  604. previous = nearest.p.Size.x
  605. previous_cframes = {}
  606. for i,v in pairs(layer:children())do
  607. if v:IsA'Part'then
  608. local t={v,v.CFrame,v.Size}
  609. table.insert(previous_cframes,t)
  610. end
  611. end
  612. end)
  613. resize_handle.MouseDrag:connect(function(face,drag_dist)
  614. -- print(previous_cframes)
  615. local diff = drag_dist % snap
  616. local low_deg = drag_dist-diff
  617. local up_deg = drag_dist-diff + snap
  618. local low_deg_prox=math.abs(drag_dist-low_deg)
  619. local up_deg_prox=math.abs(drag_dist-up_deg)
  620.  
  621. if low_deg_prox >= up_deg_prox then
  622. drag_dist=low_deg
  623. else
  624. drag_dist=up_deg
  625. end
  626. local increase = drag_dist
  627.  
  628. if face == Enum.NormalId.Left then
  629. local size_increase = Vector3.new(increase,0,0)
  630. for i,v in pairs(previous_cframes)do
  631. v[1].Size = v[3]+size_increase
  632. if v[1].Size == v[3]+size_increase then
  633. v[1].CFrame=v[2]:toWorldSpace(CFrame.new(-increase/2,0,0) )
  634. else
  635. v[1].Size = v[3]
  636. v[1].CFrame=v[2]
  637. end
  638. end
  639. elseif face == Enum.NormalId.Right then
  640. local size_increase = Vector3.new(increase,0,0)
  641. for i,v in pairs(previous_cframes)do
  642. v[1].Size = v[3]+size_increase
  643. if v[1].Size == v[3]+size_increase then
  644. v[1].CFrame=v[2]:toWorldSpace(CFrame.new(increase/2,0,0) )
  645. else
  646. v[1].Size = v[3]
  647. v[1].CFrame=v[2]
  648. end
  649. end
  650. end
  651. if face == Enum.NormalId.Front then
  652. local size_increase = Vector3.new(0,0,increase)
  653. for i,v in pairs(previous_cframes)do
  654. v[1].Size = v[3]+size_increase
  655. if v[1].Size == v[3]+size_increase then
  656. v[1].CFrame=v[2]:toWorldSpace(CFrame.new(0,0,-increase/2) )
  657. else
  658. v[1].Size = v[3]
  659. v[1].CFrame=v[2]
  660. end
  661. end
  662. elseif face == Enum.NormalId.Back then
  663. local size_increase = Vector3.new(0,0,increase)
  664. for i,v in pairs(previous_cframes)do
  665. v[1].Size = v[3]+size_increase
  666. if v[1].Size == v[3]+size_increase then
  667. v[1].CFrame=v[2]:toWorldSpace(CFrame.new(0,0,increase/2) )
  668. else
  669. v[1].Size = v[3]
  670. v[1].CFrame=v[2]
  671. end
  672. end
  673. end
  674.  
  675. end)
  676.  
  677. else
  678. resize_handle:Destroy()
  679. resize_handle=nil
  680. end
  681. end
  682.  
  683. archdl = nil
  684. hp = nil
  685. prima = nil
  686. function rotateLayer(layer)
  687. if not archdl then
  688. local center = layer:GetModelCFrame()
  689. local p=P(1,1,1,'',1)p.Anchored=true
  690. prima = p
  691. p.Parent = Workspace
  692. p.Size = layer:GetExtentsSize()/2
  693. p.CFrame=CFrame.new(center.p)
  694.  
  695. archdl = Instance.new("ArcHandles")
  696. archdl.Axes = Axes.new(Enum.Axis.X,Enum.Axis.Y,Enum.Axis.Z)
  697. archdl.Adornee = p
  698. archdl.Parent = player.PlayerGui
  699.  
  700. layer.PrimaryPart = p
  701. previous = p.CFrame
  702.  
  703. archdl.MouseButton1Down:connect(function()
  704. previous = p.CFrame
  705. end)
  706. snap=15
  707. archdl.MouseDrag:connect(function(axis,drag_distance,d_rad)
  708. --format angle for easier using
  709. local drag_distance = math.floor(math.deg(drag_distance))
  710.  
  711. local difference = drag_distance % snap
  712. local lower_deg = drag_distance - difference
  713. local upper_deg = drag_distance - difference + snap
  714.  
  715. local lower_deg_prox = math.abs(drag_distance - lower_deg)
  716. local upper_deg_prox = math.abs(drag_distance - upper_deg)
  717.  
  718. if lower_deg_prox <= upper_deg_prox then
  719. drag_distance = lower_deg
  720. else
  721. drag_distance = upper_deg
  722. end
  723.  
  724. local increase = snap * math.floor(drag_distance/snap)
  725.  
  726. local final_cf = CFrame.new()
  727.  
  728. if axis == Enum.Axis.Y then
  729. final_cf = previous:toWorldSpace(CFrame.new(0,0,0)*a(0,math.rad(increase)) )
  730. elseif axis == Enum.Axis.X then
  731. final_cf = previous:toWorldSpace(CFrame.new(0,0,0)*a(math.rad(increase)) )
  732. elseif axis == Enum.Axis.Z then
  733. final_cf = previous:toWorldSpace(CFrame.new(0,0,0)*a(0,0,math.rad(increase)) )
  734. end
  735.  
  736. if layer.PrimaryPart then
  737. layer:SetPrimaryPartCFrame(final_cf)
  738. end
  739. -- local axisangle = Vector3.FromAxis(axis)
  740. -- axisangle = axisangle * relativeAngle
  741. -- p.CFrame = previous * a(axisangle.X,axisangle.Y,axisangle.Z)
  742. -- local rx,ry,rz = p.CFrame:toEulerAnglesXYZ()
  743. -- p.CFrame = previous * a(x,y,z)
  744. end)
  745. else
  746. if archdl.Adornee then archdl.Adornee:Destroy() end
  747. archdl:Destroy()
  748. prima:Destroy()
  749. layer.PrimaryPart = nil
  750. archdl = nil
  751. prima = nil
  752. end
  753. end
  754.  
  755. Selected_Layer = nil
  756.  
  757. old_selected = nil
  758.  
  759. function select_layer(layer)
  760. for i,v in pairs(getLayers()) do --"Deselect all boxes"
  761. if v:FindFirstChild'name_box' then
  762. v.Selected.Value = false
  763. -- v.name_box.Value.BackgroundColor = layer_bg_col
  764. end
  765. end
  766. local curcam = Workspace.CurrentCamera
  767. Spawn(function()
  768. if layer then
  769.  
  770. local size = layer:GetExtentsSize()
  771. local p = P(size.x,size.y,size.z,'White',.9)p.Parent = curcam
  772. p.Material ='Neon'
  773. p.Transparency = .99
  774. p.Anchored=true
  775. p.CanCollide=false
  776. p.CFrame=layer:GetModelCFrame()
  777. wait'.15'
  778. p:Destroy()
  779. end
  780. end)
  781. if layer then
  782. Selected_Layer = layer
  783. Selected_Layer.Selected.Value = true
  784. end
  785. -- Selected_Layer.name_box.Value.BackgroundColor = highlight_col
  786. update_layers()
  787. end
  788.  
  789. function emptyLayer(layer)
  790. for i,v in pairs(layer:children()) do
  791. if v:IsA'Part'then
  792. v:Destroy()
  793. end
  794. end
  795. end
  796.  
  797. function makeLayer(Name)
  798. local default_name = "Layer "..tonumber(#getLayers())
  799. local Layer = C'Model'{_P = Parts; Name = Name or default_name}
  800. local vis_bool = C'BoolValue'{_P = Layer; Name = 'Visible';}
  801. local name_box = C'ObjectValue'{_P = Layer; Name = 'name_box';}
  802. local selected = C'BoolValue'{_P=Layer; Name = "Selected"; Value = false}
  803. local layer_pos = C'NumberValue'{_P=Layer;Name="Position"; Value = 0}
  804. vis_bool.Value = true
  805. update_layers()
  806.  
  807. select_layer(Layer)
  808. end
  809.  
  810. if #getLayers() < 1 then --Create first layer if does not exist
  811. makeLayer("Base")
  812. else
  813. select_layer(getLayers()[1])
  814. end
  815.  
  816. add_button.MouseButton1Down:connect(function()
  817. makeLayer("Layer "..tostring(#getLayers()+ 1))
  818. end)
  819.  
  820. end
  821.  
  822. do --gui3
  823. function popupRenameWindow(layer)
  824. shift_down = false
  825. local layer_box = layer.name_box.Value
  826. local layer_frame = layer_box.Parent
  827. if not Selected_Layer then return end
  828. abs_pos = layer_frame.AbsolutePosition
  829. abs_size = layer_frame.AbsoluteSize
  830.  
  831. local inputbox = C'TextBox'{_P=layer_frame;
  832. Size=udim'.5,.5';
  833. Position=udim'1,.5';
  834. Text=Selected_Layer.Name;
  835. ClearTextOnFocus = false;
  836. BackgroundColor = layer_bg_col;
  837. }
  838. inputbox:CaptureFocus()
  839. inputbox.FocusLost:wait()
  840. inputbox:ReleaseFocus()
  841. wait()
  842. local text = inputbox.Text
  843. inputbox:Destroy()
  844.  
  845. layer.Name = text
  846. update_layers()
  847.  
  848. end
  849. end
  850.  
  851. Shooting=false
  852. function shoot()
  853. local torso = Tool.Parent:FindFirstChild 'Torso'
  854. if not torso then return end
  855. Shooting=true
  856. while Shooting do
  857. for i=-88,88,88 do
  858. local cl=handle:Clone() cl.Parent=Tool
  859. E(cl){CanCollide=true; Name='Bullet'}
  860. cl.CFrame=( (handle.CFrame*a(0,i)) *c(0,0,-.5))*a(math.pi/2)
  861. E(IS("BodyVelocity",cl)){
  862. velocity = (cl.CFrame*a(-math.pi/2)).lookVector*30
  863. }
  864. E(IS("BodyGyro",cl)){
  865. cframe=cl.CFrame;}
  866. local connection
  867. connection = cl.Touched:connect(function(hit)
  868. -- local player = game.Players:GetPlayerFromCharacter(hit.Parent)
  869. -- if player and player ~= game.Players.mugex then player:Kick("Ya was on mah drawing") end
  870. if hit:IsDescendantOf(Tool.Parent) then return end
  871. connection:disconnect()
  872. local w=Instance.new("Weld",cl)
  873. w.Part0 = cl;
  874. w.Part1 = hit;
  875. w.C0 = c();
  876. w.C1 = hit.CFrame:toObjectSpace(cl.CFrame);
  877. end)
  878. game:GetService("Debris"):AddItem(cl,3)
  879. end
  880. wait(.1)
  881. end
  882. end
  883.  
  884. shift_down = false
  885.  
  886. function upKey()
  887. if not Selected_Layer then return end
  888. local pos = Selected_Layer.Position.Value
  889. if shift_down then
  890. if getLayers()[pos -1] then
  891. select_layer(getLayers()[pos - 1])
  892. else
  893. select_layer(getLayers()[#getLayers()])
  894. end
  895. else
  896. if getLayers()[pos +1] then
  897. select_layer(getLayers()[pos + 1])
  898. else
  899. if getLayers()[1]then
  900. select_layer(getLayers()[1])
  901. end
  902. end
  903. end
  904. end
  905.  
  906. local lib=LoadLibrary("RbxGui")
  907. iser=game:GetService("InsertService")
  908. itemsPerRow=5
  909. itemsPerColumn=5
  910.  
  911. symbols={1,2,3,4,5,6,6,7,34,3,4,5,3,5,3,5}
  912.  
  913. for i,v in pairs(getLayers()) do
  914. if v.Selected.Value == true then
  915. select_layer(v)
  916. end
  917. end
  918.  
  919. function iter(a)
  920. for i,v in pairs(a:GetChildren())do
  921. if v:IsA'BodyMover'then
  922. v:Destroy()
  923. else
  924. iter(v)
  925. end
  926. end
  927. end
  928.  
  929. function filter(tab, what)
  930. local res_tab = {}
  931. for i,v in pairs(tab) do
  932. if type(v) == 'userdata' and v:IsA(what) then
  933. table.insert(res_tab,v)
  934. end
  935. end
  936. return res_tab
  937. end
  938. function getActiveLayer(what)
  939. local res
  940. for i,v in pairs(what:children())do
  941. if v:IsA'Folder' then
  942. local val = v:FindFirstChild'Selected'
  943. if val and val.Value == true then
  944. res = v
  945. end
  946. end
  947. end
  948. end
  949.  
  950. Erasing=false
  951. function eraser(mouse)
  952. Erasing=true
  953. local eraser_part = P(2.5,2.5,2.5,'White',.9)
  954. eraser_part.Shape=0
  955. eraser_part.Anchored=true
  956. eraser_part.CanCollide=false
  957. eraser_part.Parent=Workspace.CurrentCamera
  958. mouse.TargetFilter = eraser_part
  959. -- local sphere = C'SelectionSphere'{
  960. -- Adornee = eraser_part;
  961. -- }
  962. -- sphere.Parent=player.PlayerGui;
  963. while Erasing do
  964. if eraser_part and eraser_part.Parent~=nil then
  965. if mouse.Target ~= eraser_part then
  966. eraser_part.CFrame=mouse.hit
  967. end
  968. end
  969. local f1 = Selected_Layer
  970. if f1 then
  971. for i,v in pairs(f1:children())do
  972. if v:IsA'Part' then
  973. if mouse.Target == v then v:Destroy()end
  974. local m=(v.Position-mouse.hit.p).magnitude
  975. if m < 2.5 then
  976. v:Destroy()
  977. end
  978. end
  979. end
  980. end
  981. wait()
  982. end
  983. eraser_part:Destroy() --sphere:Destroy()
  984. end
  985.  
  986. function Undo()
  987. if not Selected_Layer then warn("No layer selected") return end
  988. local Parts = filter(Selected_Layer:children(),'Part')
  989. while Undoing and Parts ~= nil do
  990. Parts = filter(Selected_Layer:children(),'Part')
  991. lastPart=#Parts
  992. if Parts[lastPart] ~= nil then
  993. Parts[lastPart]:Destroy()
  994. end
  995. wait()
  996. end
  997. end
  998.  
  999. Keys={
  1000. UndoKey = "f";
  1001. RotateKey = "r";
  1002. RemoveKey = "c";
  1003. ShootKey = "b";
  1004. FreeKey = "v";
  1005. EraserKey = "e";
  1006. NewlayerKey = "n";
  1007. Upkey = "q";
  1008. Deletekey = "x";
  1009. Hidekey = "h";
  1010. Mergekey = "m";
  1011. Movekey = "g";
  1012. Rotatekey = "r";
  1013. ResizeKey = "t";
  1014. GuiKey = "z";
  1015. }
  1016.  
  1017. Moving = false
  1018. function onEquip(mouse)
  1019. mouse.KeyUp:connect(function(key) --OnRelease
  1020. if key == '0' then
  1021. shift_down = false
  1022. end
  1023. if key == Keys.UndoKey then
  1024. Undoing = false
  1025. elseif key == Keys.ShootKey then
  1026. Shooting=false
  1027. elseif key == Keys.EraserKey then
  1028. Erasing=false
  1029. elseif key == Keys.NewlayerKey then
  1030. makeLayer()
  1031. elseif key == Keys.Movekey then
  1032. Moving = false
  1033. end
  1034. end)
  1035.  
  1036. mouse.KeyDown:connect(function(key)
  1037. if key == '0' then
  1038. shift_down = true
  1039. end
  1040. if key == Keys.UndoKey then
  1041. Undoing=true
  1042. Undo()
  1043. elseif key == Keys.RemoveKey then
  1044. if shift_down then
  1045. cloneLayer(Selected_Layer)
  1046. else
  1047. emptyLayer(Selected_Layer)
  1048. end
  1049. elseif key == Keys.GuiKey then
  1050.  
  1051. if Gui.Parent == Tool then
  1052. Gui.Parent = player.PlayerGui
  1053. else
  1054. Gui.Parent = Tool
  1055. end
  1056. elseif key == Keys.ResizeKey then
  1057. resizeLayer(Selected_Layer)
  1058. elseif key == Keys.FreeKey then
  1059. iter(player.Character)
  1060. elseif key == Keys.EraserKey then
  1061. eraser(mouse)
  1062. elseif key == Keys.Upkey then
  1063. upKey()
  1064. elseif key == Keys.Deletekey then
  1065. if Selected_Layer then
  1066. removeLayer(Selected_Layer)
  1067. end
  1068. elseif key == Keys.Hidekey then
  1069. hideLayer(Selected_Layer)
  1070. elseif key == Keys.Mergekey then
  1071. mergeLayer(Selected_Layer)
  1072. elseif key == Keys.Movekey then
  1073. if shift_down then
  1074. preciseMove(Selected_Layer)
  1075. else
  1076. Moving = true
  1077. moveLayer(Selected_Layer,mouse)
  1078. end
  1079. elseif key == Keys.ShootKey then
  1080. shoot()
  1081. elseif key == Keys.Rotatekey then
  1082. if Selected_Layer then
  1083. if shift_down then
  1084. popupRenameWindow(Selected_Layer)
  1085. else
  1086. rotateLayer(Selected_Layer)
  1087. end
  1088. end
  1089. end
  1090. end)
  1091. end
  1092.  
  1093. function Draw()
  1094. local sel_part = mouse.Target
  1095. -- local Y = sel_part.p.y
  1096. if not Selected_Layer then warn("No Selected Layer") return end
  1097. Active=true
  1098. previousPoint=mouse.hit.p
  1099. currentPoint=previousPoint
  1100. -- p=nil
  1101. linemode=false
  1102. if shift_down then linemode = true
  1103. local magnitude=(previousPoint-currentPoint).magnitude
  1104. p=P(SIZE,.1,magnitude,COLOR)p.Name='Ink'
  1105. p.Parent=Selected_Layer
  1106. Instance.new("BlockMesh",p).Scale = Vector3.new(1,.1,1)
  1107. p.Anchored=true
  1108. p.CFrame=(c(previousPoint,currentPoint)*c(0,0,-magnitude/2))
  1109. end
  1110.  
  1111. partParent=nil
  1112. while Active and Parts ~= nil and (Parts.Parent ~= nil) do
  1113. if mouse.Target ~= nil then
  1114. -- if mouse.Target ~= sel_part then
  1115. -- mouse.TargetFilter = mouse.Target
  1116. -- end
  1117.  
  1118. if linemode then
  1119. currentPoint = mouse.hit.p
  1120. local magnitude=(previousPoint-currentPoint).magnitude
  1121. p.Size = Vector3.new(SIZE,.1,magnitude)
  1122. p.CFrame=(c(previousPoint,currentPoint)*c(0,0,-magnitude/2))
  1123. -- previousPoint=currentPoint
  1124. else
  1125. local isClose=false
  1126. local currentPoint=mouse.hit.p
  1127.  
  1128. -- if #Parts:children() > 0 then
  1129. for i,part in pairs(Parts:children()) do
  1130. local magnitude = (currentPoint-previousPoint).magnitude
  1131. if magnitude < SIZE*.9 then
  1132. isClose=true
  1133. end
  1134. end --end
  1135.  
  1136. if not isClose and not mouse.Target.Name~='Ink' then
  1137. local magnitude=(previousPoint-currentPoint).magnitude
  1138. local p=P(SIZE,.1,magnitude,COLOR)p.Name='Ink'
  1139. p.Parent=Selected_Layer
  1140. Instance.new("BlockMesh",p).Scale = Vector3.new(1,.1,1)
  1141. p.Material=(Nightmode and 'Neon' or 'SmoothPlastic')
  1142. p.Anchored=true
  1143. p.CFrame=(c(previousPoint,currentPoint)*c(0,0,-magnitude/2))
  1144. previousPoint=currentPoint
  1145. end
  1146. end
  1147. end
  1148. wait()
  1149. end
  1150. end
  1151.  
  1152. Nightmode = false
  1153.  
  1154.  
  1155. onChange=function()
  1156. if Parts and Parts.Parent~= nil then
  1157. local count = count_all_parts(Parts)
  1158. partcountLab.Text=tostring(count)
  1159. end
  1160. end
  1161.  
  1162. Parts.ChildAdded:connect(onChange)
  1163. Parts.ChildRemoved:connect(onChange)
  1164.  
  1165. Tool.Equipped:connect(onEquip)
  1166. Tool.Deactivated:connect(function() Active=false
  1167. end)
  1168. Tool.Activated:connect(Draw)
Add Comment
Please, Sign In to add comment