nickcool9999

GUI Compiler v1

Jun 12th, 2015
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.88 KB | None | 0 0
  1. local plugin = PluginManager():CreatePlugin()
  2. local toolbar = plugin:CreateToolbar("Compile Interface")
  3. local module = {}
  4. --[[
  5. Name: Model Compiler
  6. Author: popinman322 & nickcool9999 (partly!)
  7. Description: Compiles models (and Guis) into scripts
  8. Usage: Click the button over your selection :) It should be a GUI as that is what is mostly recognized.
  9. --]]
  10. local MemberNames = {'Version', 'Instance', 'ClassName', 'Name', 'Name', 'Color', 'Material', 'stop', 'stop', 'undo', 'undo', 'redo', 'redo', 'Camera', 'Offset', 'Scale', 'BaseUrl', 'Script', 'Render', 'FrameRateManager', 'Abort', 'Value', 'Sound', 'Priority', 'Time', 'Insert', 'Resize', 'Clone', 'Clone', 'MembershipType', 'ChatMode', 'Network', 'Ping', 'Size', 'Disabled', 'Heartbeat', 'Heartbeat', 'FriendRequestEvent', 'Faces', 'Axes', 'BrickColor', 'Part', 'Chat', 'Texture', 'Snap', 'Hole', 'Fire', 'Workspace', 'Humanoid', 'Controller', 'StarterScript', 'RequestQueueSize', 'CFrame', 'Lua', 'BinType', 'Slingshot', 'RobloxModelItem', 'CameraType', 'Jump', 'Torso', 'CoordinateFrame', 'FormFactor', 'MeshType', 'hasCustomStatus', 'removeStatus', 'hasStatus', 'addStatus', 'InOut', 'Boing', 'Bomb', 'Break', 'Click', 'Clock', 'Page', 'Splat', 'Step', 'StepOn', 'Swoosh', 'Victory', 'BodyPart', 'LeftLeg', 'RightLeg', 'Neutral', 'TopBottom', 'LeftRight', 'MoveState', 'Throttle', 'Steer', 'FontSize', 'Font', 'TextXAlignment', 'TextYAlignment', 'Pause', 'Pause', 'Style', 'SizeConstraint', 'ReportAbuse', 'shape', 'CanCollide', 'Anchored', 'Run', 'Run', 'Reset', 'Reset', 'Visible', 'TextColor', 'BackgroundColor', 'Locked', 'Position', 'Enabled', 'Selected', 'Browsable', 'Deprecated', 'Preliminary', 'ExplorerOrder', 'ExplorerImageIndex', 'LoadData', 'SaveData', 'SaveLeaderboardData', 'DataComplexity', 'DataComplexityLimit', 'DataReady', 'WaitForDataReady', 'RequestFriendship', 'RevokeFriendship', 'RemoteFriendServiceSignal', 'LoadString', 'SaveString', 'LoadBoolean', 'SaveBoolean', 'LoadNumber', 'SaveNumber', 'LoadInstance', 'SaveInstance', 'LoadCharacter', 'RemoveCharacter', 'SetUnder13', 'SetSuperSafeChat', 'SetMembershipType', 'SetAccountAge', 'HasBuildPermission', 'Character', 'CharacterAppearance', 'DistanceFromCharacter', 'GetFriendStatus', 'IsFriendsWith', 'IsBestFriendsWith', 'IsInGroup', 'SuperSafeChatReplicate', 'SimulationRadius', 'OsPlatform', 'TeamColor', 'Guest', 'MembershipTypeReplicate', 'AccountAgeReplicate', 'BuildPermissions', 'Chatted', 'Chatted', 'CharacterAdded', 'CharacterRemoving', 'Idled', 'FriendStatusChanged', 'Kill', 'ScriptSecurityError', 'RemoteInsert', 'RequestLock', 'LockResult', 'RequestUnlock', 'StatsAvailable', 'NumPlayers', 'MaxPlayers', 'GetPlayerByID', 'TeamChat', 'WhisperChat', 'PlayerChatted', 'GameAnnounce', 'GetPlayers', 'CreateLocalPlayer', 'SetAbuseReportUrl', 'SetChatFilterUrl', 'SetBuildToolsUrl', 'SetBuildUserPermissionsUrl', 'playerFromCharacter', 'GetPlayerFromCharacter', 'PlayerAddedEarly', 'PlayerAdded', 'PlayerRemoving', 'PlayerRemovingLate', 'SetSysStatsUrl', 'SetSysStatsUrlId', 'SetLoadDataUrl', 'SetSaveDataUrl', 'SetSaveLeaderboardDataUrl', 'AddLeaderboardKey', 'SetChatStyle', 'ClassicChat', 'Start', 'GetClientCount', 'SetIsPlayerAuthenticationRequired', 'IncommingConnection', 'ApplyNetworkSimulator', 'SetOutgoingKBPSLimit', 'Archivable', 'Archivable', 'IsA', 'IsA', 'FindFirstChild', 'FindFirstChild', 'Remove', 'Remove', 'GetChildren', 'GetChildren', 'GetFullName', 'GetFullName', 'IsDescendantOf', 'IsDescendantOf', 'IsAncestorOf', 'IsAncestorOf', 'GetDebugId', 'GetDebugId', 'DataCost', 'DataCost', 'Parent', 'Parent', 'RobloxLocked', 'RobloxLocked', 'ChildAdded', 'ChildAdded', 'ChildRemoved', 'ChildRemoved', 'DescendantAdded', 'DescendantAdded', 'DescendantRemoving', 'DescendantRemoving', 'AncestryChanged', 'AncestryChanged', 'Changed', 'Changed', 'Stepped', 'Stepped', 'DopplerScale', 'DopplerScale', 'DistanceFactor', 'DistanceFactor', 'RolloffScale', 'RolloffScale', 'AmbientReverb', 'AmbientReverb', 'PlayStockSound', 'PlayStockSound', 'SoundId', 'Volume', 'Pitch', 'PlayCount', 'Looped', 'IsPlaying', 'IsPaused', 'PlayOnRemove', 'Play', 'ReloadShaders', 'ReloadShaders', 'EnableQueue', 'EnableQueue', 'DisableQueue', 'DisableQueue', 'CaptureMetrics', 'CaptureMetrics', 'ResizeWindow', 'ResizeWindow', 'GetPresentTime', 'GetPresentTime', 'GetGPUDelay', 'GetGPUDelay', 'GetRenderAve', 'GetRenderAve', 'GetDeltaAve', 'GetDeltaAve', 'GetDrawCallBucketNum', 'GetDrawCallBucketNum', 'GetTriCount', 'GetTriCount', 'GetDrawCallBucketValue', 'GetDrawCallBucketValue', 'GetDrawCallBucketLimit', 'GetDrawCallBucketLimit', 'AddMaterialFilter', 'AddMaterialFilter', 'ClearMaterialFilter', 'ClearMaterialFilter', 'Score', 'AutoAssignable', 'AutoColorCharacters', 'SetCreateFriendRequestUrl', 'SetDeleteFriendRequestUrl', 'SetMakeFriendUrl', 'SetBreakFriendUrl', 'SetGetFriendsUrl', 'SetEnabled', 'SetEnabled', 'RemoteFriendEventSignal', 'RemoteFriendStatusSignal', 'Set', 'Set', 'ModelInPrimary', 'ModelInPrimary', 'PrimaryPart', 'BreakJoints', 'BreakJoints', 'MakeJoints', 'MakeJoints', 'GetModelSize', 'GetModelSize', 'GetModelCFrame', 'GetModelCFrame', 'location', 'MoveTo', 'MoveTo', 'TranslateBy', 'TranslateBy', 'SetWaypoint', 'SetWaypoint', 'ResetWaypoints', 'ResetWaypoints', 'GetCanUndo', 'GetCanUndo', 'GetCanRedo', 'GetCanRedo', 'NonScriptableAccess', 'CamelCaseViolation', 'AddStarterScript', 'RegisterRobloxLibrary', 'RegisterLibrary', 'RegisterDevelopmentLibrary', 'LibraryRegistrationComplete', 'AddCoreScript', 'SetTimeout', 'GetHeapStats', 'GetScriptStats', 'GarbageCollectionLimit', 'GarbageCollectionFrequency', 'SetCollectScriptStats', 'TextureId', 'Active', 'ReplicatedSelected', 'Deselected', 'ToggleSelect', 'Disable', 'ReplicatedSelectedConnectionCount', 'DeselectedConnectionCount', 'Grip', 'GripPos', 'GripForward', 'GripUp', 'GripRight', 'BackendToolState', 'ActivationState', 'Equipped', 'Unequipped', 'Activated', 'Deactivated', 'Source', 'LinkedSource', 'GetHash', 'DistributedGameTime', 'InsertContent', 'FindPartsInRegion3', 'FindPartOnRay', 'SetPhysicsThrottleEnabled', 'ZoomToExtents', 'CurrentCamera', 'ShowDevelopmentModelItem', 'AttachmentPoint', 'AttachmentPos', 'AttachmentForward', 'AttachmentUp', 'AttachmentRight', 'BackendAccoutrementState', 'Specular', 'Shiny', 'Transparency', 'StudsPerTileU', 'StudsPerTileV', 'SetBaseUrl', 'SetAssetUrl', 'SetThreadPool', 'SetCacheSize', 'Preload', 'GetRequestQueue', 'GetRequestedUrls', 'BlastRadius', 'BlastPressure', 'Hit', 'Focus', 'CameraSubject', 'Zoom', 'PanUnits', 'TiltUnits', 'BindButton', 'UnbindButton', 'GetButton', 'ButtonChanged', 'Velocity', 'RotVelocity', 'GetMass', 'Elasticity', 'Friction', 'AlphaModifier', 'Reflectance', 'ResizeableFaces', 'ResizeIncrement', 'NetworkIsSleeping', 'LocalSimulationTouched', 'Touched', 'OutfitChanged', 'DraggingV1', 'SetUploadUrl', 'GetUploadUrl', 'SetPing', 'RegisterActiveKeyframeSequence', 'RegisterKeyframeSequence', 'GetKeyframeSequence', 'AnimationId', 'MeshId', 'SetOldSchoolBackpack', 'GetOldSchoolBackpack', 'Health', 'MaxHealth', 'WalkSpeed', 'WalkToPart', 'WalkToPoint', 'TargetPoint', 'Sit', 'PlatformStand', 'WalkDirection', 'WalkAngleError', 'Strafe', 'TakeDamage', 'SetClickToWalkEnabled', 'Died', 'Running', 'Climbing', 'Jumping', 'FreeFalling', 'GettingUp', 'Strafing', 'FallingDown', 'Seated', 'PlatformStanding', 'HealthChanged', 'AddCustomStatus', 'RemoveCustomStatus', 'GetStatuses', 'StatusAdded', 'StatusRemoved', 'CustomStatusAdded', 'CustomStatusRemoved', 'LoadAnimation', 'GetSubPoses', 'AddSubPose', 'RemoveSubPose', 'Weight', 'MaskWeight', 'GetPoses', 'AddPose', 'RemovePose', 'GetKeyframes', 'AddKeyframe', 'RemoveKeyframe', 'Loop', 'TextColor3', 'TextTransparency', 'TextWrap', 'TextBounds', 'TextFits', 'Image', 'Duration', 'AllowTeamChangeOnTouch', 'Graphic', 'Outfit1', 'Outfit2', 'ShirtTemplate', 'PantsTemplate', 'SkinColor', 'HeadColor', 'LeftArmColor', 'RightArmColor', 'TorsoColor', 'LeftLegColor', 'RightLegColor', 'RebalanceTeams', 'RebalanceTeams', 'GetTeams', 'GetTeams', 'SetFriendUrl', 'SetBestFriendUrl', 'SetGroupUrl', 'SetStuffUrl', 'SetPackageContentsUrl', 'MinValue', 'MaxValue', 'ConstrainedValue', 'TweenSizeAndPosition', 'TweenPosition', 'TweenSize', 'BorderSizePixel', 'ZIndex', 'BorderColor', 'BorderColor3', 'BackgroundColor3', 'BackgroundTransparency', 'Draggable', 'MouseEnter', 'MouseLeave', 'MouseMoved', 'DragStopped', 'DragBegin', 'MouseEnterConnectionCount', 'MouseLeaveConnectionCount', 'MouseMovedConnectionCount', 'DragStoppedConnectionCount', 'DragBeginConnectionCount', 'SetVerb', 'MouseButton1Click', 'MouseButton2Click', 'MouseButton1Down', 'MouseButton1Up', 'MouseButton2Down', 'MouseButton2Up', 'MouseButton1ClickConnectionCount', 'MouseButton2ClickConnectionCount', 'MouseButton1DownConnectionCount', 'MouseButton1UpConnectionCount', 'MouseButton2DownConnectionCount', 'MouseButton2UpConnectionCount', 'AutoButtonColor', 'Modal', 'InsertRequest', 'InsertRequestAsset', 'InsertRequestAssetVersion', 'InsertReady', 'InsertError', 'SetBaseCategoryUrl', 'SetUserCategoryUrl', 'SetTrustLevel', 'SetBaseSetsUrl', 'SetUserSetsUrl', 'SetFreeModelUrl', 'SetFreeDecalUrl', 'SetCollectionUrl', 'SetAssetVersionUrl', 'GetBaseCategories', 'GetUserCategories', 'SetAdvancedResults', 'GetFreeModels', 'GetFreeDecals', 'GetBaseSets', 'GetUserSets', 'GetCollection', 'GetCollection', 'LoadAsset', 'LoadAssetVersion', 'SetAccessKey', 'MultiLine', 'ClearTextOnFocus', 'CaptureFocus', 'FocusLost', 'LightingChanged', 'LightingChanged', 'TimeOfDay', 'TimeOfDay', 'GeographicLatitude', 'GeographicLatitude', 'GetMoonPhase', 'GetMoonPhase', 'GetMoonDirection', 'GetMoonDirection', 'GetSunDirection', 'GetSunDirection', 'GetMinutesAfterMidnight', 'GetMinutesAfterMidnight', 'SetMinutesAfterMidnight', 'SetMinutesAfterMidnight', 'ShadowColor', 'ShadowColor', 'Brightness', 'Brightness', 'ColorShift_Top', 'ColorShift_Top', 'ColorShift_Bottom', 'ColorShift_Bottom', 'Ambient', 'Ambient', 'Part0', 'Part1', 'Surface0', 'Surface1', 'C0', 'C1', 'F0', 'F1', 'F2', 'F3', 'BaseAngle', 'MaxVelocity', 'DesiredAngle', 'SetDesiredAngle', 'CurrentAngle', 'AssemblyAdded', 'AssemblyRemoved', 'Bevel', 'Bevel Roundness', 'Bulge', 'LODX', 'LODY', 'VertexColor', 'Adornee', 'StudsOffset', 'ExtentsOffset', 'SizeOffset', 'BaseTextureId', 'OverlayTextureId', 'MouseClick', 'FrontendMouseClick', 'MaxActivationDistance', 'ItemAdded', 'ItemAdded', 'ItemRemoved', 'ItemRemoved', 'ClickButton1', 'ClickButton1', 'Button1Down', 'Button1Down', 'Button1Up', 'Button1Up', 'ClickButton2', 'ClickButton2', 'Button2Down', 'Button2Down', 'Button2Up', 'Button2Up', 'MoveMouse', 'MoveMouse', 'TypeKey', 'TypeKey', 'SetKeyDown', 'SetKeyDown', 'SetKeyUp', 'SetKeyUp', 'MaxItems', 'MaxItems', 'AddItem', 'AddItem', 'SetLegacyMaxItems', 'SetLegacyMaxItems', 'InitialPrompt', 'Purpose', 'Tone', 'ConversationDistance', 'InUse', 'SignalDialogChoiceSelected', 'DialogChoiceSelected', 'UserDialog', 'ResponseDialog', 'Description', 'Timeout', 'Ended', 'Failed', 'SetCookieValue', 'SetCookieValue', 'GetCookieValue', 'GetCookieValue', 'DeleteCookieValue', 'DeleteCookieValue', 'FaceId', 'SecondaryColor', 'Heat', 'size_xml', 'heat_xml', 'FlagCaptured', 'Target', 'TargetOffset', 'TargetRadius', 'MaxSpeed', 'MaxThrust', 'ThrustP', 'ThrustD', 'TurnP', 'TurnD', 'MaxTorque', 'CartoonFactor', 'ReachedTarget', 'maxForce', 'lastForce', 'GetLastForce', 'angularvelocity', 'force', 'MouseDrag', 'MouseDragConnectionCount', 'SkyboxUp', 'SkyboxLf', 'SkyboxRt', 'SkyboxBk', 'SkyboxFt', 'SkyboxDn', 'StarCount', 'CelestialBodiesShown', 'StickyWheels', 'MoveStateChanged', 'ControllingHumanoid', 'ApplySpecificImpulse', 'AxisChanged', 'Opacity', 'RiseVelocity', 'opacity_xml', 'riseVelocity_xml', 'SparkleColor', 'TargetSurface', 'TurnSpeed', 'Torque', 'HeadsUpDisplay', 'AreHingesDetected', 'MouseDown', 'MouseMove', 'MouseUp', 'AxisRotate', 'TopSurface', 'TopSurfaceInput', 'TopParamA', 'TopParamB', 'BottomSurface', 'BottomSurfaceInput', 'BottomParamA', 'BottomParamB', 'LeftSurface', 'LeftSurfaceInput', 'LeftParamA', 'LeftParamB', 'RightSurface', 'RightSurfaceInput', 'RightParamA', 'RightParamB', 'FrontSurface', 'FrontSurfaceInput', 'FrontParamA', 'FrontParamB', 'BackSurface', 'BackSurfaceInput', 'BackParamA', 'BackParamB', 'AbsoluteSize', 'AbsolutePosition', 'UserHasBadge', 'AwardBadge', 'IsDisabled', 'IsLegal', 'SetHasBadgeCooldown', 'SetAwardBadgeUrl', 'SetHasBadgeUrl', 'SetIsBadgeDisabledUrl', 'SetIsBadgeLegalUrl', 'SetFilterUrl', 'SetFilterLimits', 'KeyPressed', 'SpecialKeyPressed', 'AddKey', 'AddSpecialKey', 'SendNotification', 'AddCenterDialog', 'RemoveCenterDialog', 'SetGlobalSizeOffsetPixel', 'ShowLegacyPlayerList', 'Text', 'TopImage', 'ScrollBarThickness', 'ScrollingEnabled', 'CanvasSize', 'CanvasPosition', 'BottomImage', 'MidImage'}
  11. local ManualBlacklist = {
  12. GuiObject = {
  13. Transparency = true,
  14. BackgroundColor = true,
  15. TextColor = true
  16. }
  17. }
  18.  
  19. local NewLine = string.char(0x0d) .. string.char(0x0a)
  20. local Tab = [[ ]]
  21.  
  22. function approx(number)
  23. -- omit insignificant digits in a number
  24. local str = tostring(number)
  25. local z = 0
  26. local cur = ""
  27. for i = 1, str:len() do
  28. if str:sub(i, i) == "0" then
  29. z=z+1
  30. elseif z < 4 then
  31. cur=cur..string.rep("0", z) .. str:sub(i, i)
  32. z = 0
  33. end
  34. end
  35. -- if answer is 0 then converting will be nil, return 0 instead
  36. return tonumber(cur) or 0
  37. end
  38.  
  39. function approxc3(tab)
  40. -- omit insignificant digits in color3 table
  41. local cur=""
  42. for i = 1, #tab do
  43. if tab[i] ~= 0 and tab[i] ~= 1 then
  44. cur = cur.. (tab[i]*255).. "/255"
  45. else
  46. cur = cur.. tab[i]
  47. end
  48. if i ~= #tab then
  49. cur=cur..", "
  50. end
  51. end
  52. return cur
  53. end
  54.  
  55. function omitStr(str, omit)
  56. -- omit characters from a string
  57. local cur = ""
  58. for i = 1, str:len() do
  59. local check = true
  60. for x = 1, omit:len() do
  61. if str:sub(i, i) == omit:sub(x, x) then
  62. check = false
  63. end
  64. end
  65. if check then
  66. cur = cur .. str:sub(i, i)
  67. end
  68. end
  69. return cur
  70. end
  71.  
  72. function isBlacklisted(item, prop)
  73. for n,c in pairs(ManualBlacklist) do
  74. if item:IsA(n) then
  75. return c[prop] or false
  76. end
  77. end
  78. return false
  79. end
  80.  
  81. function isProp(item, prop)
  82. local check = true
  83. local Safe, Return = pcall(function() return item[prop] end)
  84. local NSafe, New = pcall(function() return Instance.new(item.ClassName) end)
  85. if not Safe or not NSafe then check = -1 end
  86. if type(Return) == "function" then check = -2 end
  87. if pcall(function() return Return["connect"] end) and Return["connect"] ~= nil then check = -3 end
  88. if not pcall(function() New[prop] = New[prop] end) then check = -4 end
  89. if isBlacklisted(item, prop) then check = -5 end
  90. return (check == true)
  91. end
  92.  
  93. function isObject(item)
  94. if isProp(item, "Name") and isProp(item, "ClassName") then
  95. return true
  96. end
  97. return false
  98. end
  99.  
  100. function GetProps(item)
  101. local Props = {}
  102. local Done = {}
  103. for _, name in pairs(MemberNames) do
  104. if isProp(item, name) and not Done[name] then Done[name] = 0 table.insert(Props, name) end
  105. end
  106. return Props
  107. end
  108.  
  109. function HandleUData(item)
  110. if item == nil then return end
  111. local Safe, Tab = pcall(function() return loadstring("return {" .. tostring(item) .. "}")() end)
  112. if not Safe then
  113. if BrickColor.new(tostring(item)) == item then
  114. return "BrickColor.new(\"" .. tostring(item) .. "\")"
  115. end
  116. end
  117. local Safe2, IsUDim = pcall(function() return loadstring("return {" .. tostring(#Tab[2]) .. "}")() end)
  118. if #Tab == 3 then
  119. if pcall(function() local a = item.r; end) then
  120. return "Color3.new(" .. approxc3(Tab) .. ")"
  121. else
  122. return "Vector3.new(" .. tostring(item) .. ")"
  123. end
  124. elseif #Tab == 12 then
  125. return "CFrame.new(" .. tostring(item) .. ")"
  126. elseif #Tab == 2 and Safe2 then
  127. return "UDim2.new(" .. omitStr(tostring(item), "{}") .. ")"
  128. elseif #Tab == 1 then -- Should be an Enum
  129. return tostring(item)
  130. elseif #Tab == 0 then
  131. if isObject(item) then return "nil" end
  132. if BrickColor.new(tostring(item)) == item then
  133. return "BrickColor.new(\"" .. tostring(item) .. "\")"
  134. end
  135. elseif #Tab > 10 then
  136. local Safe, Return = pcall(function()
  137. return "UDim2.new(" .. item.X.Scale .. ", " .. item.X.Offset .. ", " .. item.Y.Scale .. ", " .. item.Y.Offset .. ")"
  138. end)
  139. if Return then return Return end
  140. end
  141. return ""
  142. end
  143.  
  144. function PToString(item, prop)
  145. local Prop = item[prop]
  146. if type(Prop) == "userdata" or type(Prop) == "nil" or not type(Prop) then
  147. return HandleUData(Prop)
  148. elseif type(Prop) == "string" then
  149. return "\"" .. Prop .. "\""
  150. elseif type(Prop) == "number" then
  151. return tostring(approx(Prop))
  152. elseif type(Prop) == "string" then
  153. return "\"" .. Prop .. "\""
  154. elseif type(Prop) == "table" then
  155. return "{}"
  156. elseif type(Prop) == "boolean" then
  157. if Prop then return "true" else return "false" end
  158. end
  159. print(type(Prop))
  160. return ""
  161. end
  162.  
  163. accounted={}
  164.  
  165. count=0
  166. function Compile(ModelItem, ParentName, TableName, Storage, Index, Level, FullName)
  167. count=count+1
  168. FullName=FullName or ""
  169. if not ModelItem then return end
  170. local Props = GetProps(ModelItem)
  171. local Safe, New = pcall(function() return Instance.new(ModelItem.ClassName) end)
  172. if not Safe then print("Cannot compile ModelItem, ERR_NEW_INSTANCE") return end
  173. if not ParentName then -- This is the root of the model
  174. Storage = {}
  175. Index = 1
  176. Level = 1
  177. TableName = TableName or "CompiledModel"
  178. ParentName = "nil"
  179. FullName = FullName .. "." .. ModelItem.Name
  180. table.insert(Storage, "comp={}" ..NewLine)
  181. table.insert(Storage, "function comp." ..ModelItem.Name.. "()" ..NewLine)
  182. table.insert(Storage, Tab.. "local " .. TableName .. " = {}")
  183. local Self = TableName .. "." .. FullName:sub(2)
  184. table.insert(Storage, NewLine .. string.rep(Tab, Level+1) .. Self .. " = Instance.new(\"" .. ModelItem.ClassName .. "\", " .. ParentName .. ")")
  185. for _, prop in pairs(Props) do
  186. if ModelItem[prop] ~= New[prop] and prop ~= "Parent" then
  187. table.insert(Storage, NewLine)
  188. table.insert(Storage, string.rep(Tab, Level+1) .. Self .. "[\"" .. prop .. "\"] = " .. PToString(ModelItem, prop))
  189. end
  190. end
  191. for _, child in pairs(ModelItem:GetChildren()) do
  192. Compile(child, Self, TableName, Storage, Index + 1, Level + 1, FullName)
  193. end
  194. table.insert(Storage, NewLine)
  195. table.insert(Storage, Tab.."return " ..TableName)
  196. table.insert(Storage, NewLine)
  197. table.insert(Storage, "end" .. NewLine.. "return comp." ..ModelItem.Name.. "()")
  198. accounted[ModelItem.Name]=(accounted[ModelItem.Name] or 0)+1
  199. return table.concat(Storage, "")
  200. else
  201. FullName = FullName .. "." .. ModelItem.Name
  202. accounted[ModelItem.Name]=(accounted[ModelItem.Name] or 0)+1
  203. local Self
  204. if accounted[ModelItem.Name] > 1 then
  205. Self = TableName .. "[\"" .. FullName:sub(2) .. accounted[ModelItem.Name] .. "\"]"
  206. else
  207. Self = TableName .. "[\"" .. FullName:sub(2) .. "\"]"
  208. end
  209. table.insert(Storage, NewLine)
  210. table.insert(Storage, string.rep(Tab, Level+1) .. string.rep("-", 2) .. " " ..TableName.. FullName)
  211. table.insert(Storage, NewLine)
  212. table.insert(Storage, string.rep(Tab, Level+1) .. Self .. " = Instance.new(\"" .. ModelItem.ClassName .. "\", " .. ParentName .. ")")
  213. for _, prop in pairs(Props) do
  214. if ModelItem[prop] ~= New[prop] and prop ~= "Parent" then
  215. table.insert(Storage, NewLine)
  216. table.insert(Storage, string.rep(Tab, Level+1) .. Self .. "[\"" .. prop .. "\"] = " .. PToString(ModelItem, prop))
  217. end
  218. end
  219. for _, child in pairs(ModelItem:GetChildren()) do
  220. Compile(child, Self, TableName, Storage, Index + 1, Level + 1, FullName)
  221. end
  222. end
  223. end
  224.  
  225. module.Compiler = {}
  226. module.Compiler.Compile = function(...)
  227. count = 0
  228. return Compile(...)
  229. end
  230. module.Quick = function(selection)
  231. if #selection ~= 1 then print 'must have only 1 selection' return end
  232. local tmp = selection[1]
  233. local par = tmp.Parent
  234. local s
  235. local c=0
  236. while par:FindFirstChild("CompiledModel" ..c+1) do c=c+1 wait() end
  237. s = Instance.new("ModuleScript", par)
  238. s.Name = "Interface" ..(c+1)
  239. count = 0
  240. s.Source = Compile(tmp, nil, "Interface")
  241. end
  242. local button = toolbar:CreateButton("Compile Item to ModuleScript", "Compiles items into ModuleScripts (Preferably Interfaces).", "")
  243. button.Click:connect(function()
  244. local selection = game.Selection:Get()
  245. local sel = game.Selection
  246. module.Quick(selection)
  247. end)
Advertisement
Add Comment
Please, Sign In to add comment