Advertisement
DarkLord732

Draw tool

Mar 20th, 2016
1,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1.  
  2. players = game.Players
  3. user=players.LocalPlayer;
  4. uname=user.Name;
  5. guis=user.PlayerGui;
  6. pack=user.Backpack;
  7.  
  8. keyDowns={};
  9. freeKeys={};
  10. shortcuts={};
  11.  
  12. _G.mine=_G.mine or{};
  13.  
  14. name='Draw3D';
  15. url='http://www.roblox.com/asset/?id=%d';
  16.  
  17. iconNormal=url:format(96578285);
  18. iconOnDown=url:format(96584484);
  19.  
  20. ver=0;
  21. drawPixel=0.10;
  22. _G.drawLimit=_G.drawLimit or 1000;
  23.  
  24. _G.drawColor=_G.drawColor or Color3.new();
  25.  
  26.  
  27.  
  28.  
  29.  
  30. destroy=game.remove;
  31. find=game.findFirstChild;
  32. new=Instance.new;
  33. with=function(c)
  34. return function(p)
  35. local o=type(c)=='string'and new(c)or c;
  36. local x=p.Parent;p.Parent=nil;
  37. for i,v in next,p do
  38. o[i]=v;
  39. end;
  40. if(x)then
  41. o.Parent=x;
  42. end;
  43. return o;
  44. end;
  45. end;
  46. getPlace=function()
  47. if(find(workspace,'draw')==nil)then
  48. new('Model',workspace).Name='draw';
  49. end;
  50. if(find(workspace.draw,uname)==nil)then
  51. new('Model',workspace.draw).Name=uname;
  52. end;
  53. return workspace.draw[uname];
  54. end;
  55. drawLine=function(start,target)
  56. local gui=with'BlockMesh'{
  57. Parent=with'Part'{
  58. CFrame=CFrame.new(start,target)*CFrame.new(0,0,-(start-target).magnitude/2);
  59. Size=Vector3.new(drawPixel,drawPixel,(start-target).magnitude+.325*drawPixel);
  60. Parent=getPlace();
  61. Color=_G.drawColor;
  62. BottomSurface=0;
  63. Anchored=true;
  64. TopSurface=0;
  65. formFactor=3;
  66. Name=name;
  67. }}.Parent;
  68. table.insert(_G.mine,gui);
  69. return gui;
  70. end;
  71. onDown=function()
  72. if(drawing)then
  73. return nil;
  74. end;
  75. if(selectGui.Adornee)then
  76. destroy(selectGui.Adornee);
  77. end;
  78.  
  79. drawing=true;
  80.  
  81. mouse.Icon=iconOnDown;
  82. ver=ver+1;
  83.  
  84.  
  85. local cVer,start,target=ver,mouse.hit.p;
  86.  
  87. local group={};
  88. repeat
  89. Wait(0.02);
  90.  
  91. if(mouse.target and mouse.target.Name~=name and mouse.hit.p~=start)then
  92.  
  93. target=mouse.hit.p;
  94.  
  95. table.insert(group,drawLine(start,target));
  96.  
  97. start=target;
  98. end;
  99. until ver~=cVer;
  100. drawing=false;
  101.  
  102. local groupM=new('Model',getPlace());
  103. for i,v in next,group do
  104. if(v:IsDescendantOf(Workspace))then
  105. v.Parent=groupM;
  106. end;
  107. end;
  108. if(next(groupM:children())==nil)then
  109. destroy(groupM);
  110. end;
  111. end;
  112. onUp=function()
  113. mouse.Icon=iconNormal;
  114. ver=ver+1;
  115. end;
  116. onKeyDown=function(k)
  117. if(freeKeys[k]==false)then
  118. return false;
  119. end;
  120. freeKeys[k]=false;
  121. Wait(0.01);
  122. if(keyDowns[k])then
  123. keyDowns[k]();
  124. elseif(shortcuts[k])then
  125. shortcuts[k]();
  126. end;
  127. end;
  128. onKeyUp=function(k)
  129. freeKeys[k]=true;
  130. end;
  131. onMove=function()
  132.  
  133. end;
  134. onSelect=function(lmouse)
  135. frame.Visible=true;
  136.  
  137. mouse=lmouse;
  138.  
  139. mouse.Icon=iconNormal;
  140.  
  141. mouse.Button1Down:connect(onDown);
  142. mouse.KeyDown:connect(onKeyDown);
  143. mouse.Button1Up:connect(onUp);
  144. mouse.KeyUp:connect(onKeyUp);
  145. mouse.Move:connect(onMove);
  146. end;
  147. onDeselect=function()
  148. ver=ver+1;
  149. frame.Visible=false;
  150. selectGui.Adornee=nil;
  151. mouse.Icon=iconNormal;
  152. for i,v in next,freeKeys do
  153. freeKeys[i]=true;
  154. end;
  155. end;
  156. addButton=function(title,shortcut,fun)
  157. with'TextButton'{
  158. Text=string.format(' %s (%s)',title,shortcut);
  159. TextXAlignment=0;
  160. Parent=frame;
  161. }.MouseButton1Up:connect(fun);
  162.  
  163. shortcuts[shortcut]=fun;
  164.  
  165. local c=#frame:children();
  166. for i,v in next,frame:children()do
  167. v.Position=UDim2.new(0,0,0,20*(i-1));
  168. v.Size=UDim2.new(1,0,0,20);
  169. end;
  170.  
  171. frame.Position=UDim2.new(1,-152,.5,-c*10);
  172. frame.Size=UDim2.new(0,150,0,c*20);
  173. end;
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182. for i,v in next,{guis;pack;}do
  183. pcall(function()
  184. repeat until destroy(v[name]);
  185. end);
  186. end;
  187.  
  188.  
  189.  
  190. tool=with'HopperBin'{
  191. Parent=pack;
  192. Name=name;
  193. };
  194. tool.Deselected:connect(onDeselect);
  195. tool.Selected:connect(onSelect);
  196.  
  197.  
  198.  
  199.  
  200. screen=with'ScreenGui'{
  201. Parent=guis;
  202. Name=name;
  203. };
  204. frame=with'Frame'{
  205. Parent=screen;
  206. Visible=false;
  207. };
  208. clframe=with'Frame'{
  209. Position=UDim2.new(.5,-50,.5,-50);
  210. Size=UDim2.new(0,100,0,100);
  211. Visible=false;
  212. Parent=screen;
  213. };
  214. selectGui=with'SelectionBox'{
  215. Parent=screen;
  216. };
  217.  
  218. local c=0;
  219. for y=0,7 do
  220. for x=0,7 do
  221. local color=BrickColor.palette(c).Color;
  222.  
  223. with'ImageButton'{
  224. Position=UDim2.new(.125*x,0,.125*y);
  225. Size=UDim2.new(.125,0,.125);
  226. BackgroundColor3=color;
  227. Parent=clframe;
  228. }.MouseButton1Up:connect(function()
  229. clframe.Visible=false;
  230. _G.drawColor=color;
  231. end);
  232.  
  233. c=c+1;
  234. end;
  235. end;
  236.  
  237. addButton('Color','c',function()
  238. clframe.Visible=true;
  239. end);
  240. addButton('Remove your draws','r',function()
  241. repeat
  242. destroy(_G.mine[1]);
  243. table.remove(_G.mine,1);
  244. Wait(0.01);
  245. until nil;
  246. end);
  247. addButton('Remove global draws','k',function()
  248. destroy(workspace.draw);
  249. while(_G.mine[1])do
  250. destroy(_G.mine[1]);
  251. table.remove(_G.mine,1);
  252. end;
  253. end);
  254. addButton('Remove selected','x',function()
  255. repeat
  256. if(find(workspace,'draw'))then
  257. local dt=mouse.target;
  258. if(dt and dt:IsDescendantOf(workspace.draw))then
  259. selectGui.Adornee=dt.Parent;
  260. else
  261. selectGui.Adornee=nil;
  262. end;
  263. else
  264. selectGui.Adornee=nil;
  265. end;
  266. Wait(0.01);
  267. until freeKeys.x;
  268. selectGui.Adornee=nil;
  269. end);
  270.  
  271.  
  272.  
  273.  
  274. repeat
  275. Wait(0.01);
  276. if(next(_G.mine)and _G.mine[_G.drawLimit])then
  277. destroy(_G.mine[1]);
  278. table.remove(_G.mine,1);
  279. end;
  280. until script.Parent==nil or tool.Parent==nil;
  281. script.Disabled=true;
  282. destroy(screen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement