Juank2359

Solar3 Module for I.T

Apr 11th, 2024
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.51 KB | Source Code | 0 0
  1. --> Solar3.lua (ModuleScript)
  2. --> Library of functions used globally in my game: Ivory Tower aka Blocks Simulator
  3. --> Build, modify parts and protect parts by users
  4.  
  5.  
  6. local plrSvc = game:GetService("Players");
  7. local Get = {}
  8. function Get.UserId(name:string)
  9.     return plrSvc:GetUserIdFromNameAsync(name);
  10. end
  11.  
  12. local function Check(value,datatype,enum)
  13.     if type(value) ~= datatype then
  14.         return error("\nUnable to use "..type(value)" as "..datatype..". Use "..datatype.." instead".." \nAt value #"..tostring(enum))
  15.     end
  16. end
  17.  
  18.  
  19. local x,y,z = Enum.Axis.Y,Enum.Axis.Y,Enum.Axis.Z
  20.  
  21. local Solar3 = {}
  22. Solar3.__index = Solar3
  23.  
  24. function Solar3.New(inst:Instance)
  25.     if not inst then return error("Expected . not : on calling 'New', or Instance == nil") end
  26.     if not inst.ClassName then return error("Expected Instance on calling 'New'") end
  27.  
  28.     local self =    {};
  29.     self.Instance = inst;
  30.  
  31.     for i,v in pairs(Solar3.Enum.Modifiers) do
  32.         self.Instance:SetAttribute(v,Solar3.Enum.PermissionLevel.Allowed)
  33.     end
  34.     self.Instance:SetAttribute("PlayerOwnership",0)
  35.     return self
  36. end
  37.  
  38. Solar3.Enum = {
  39.     Modifiers = {
  40.         ["CanHandle"] = "CanHandle", --- can handle children
  41.         ["Paintable"] = "Paintble", --- can be recolored
  42.         ["Deletable"] = "Deletable", --- can be destroyed
  43.         ["Modificable"] = "Modificable", --- can change properties
  44.         ["SuperModificable"] = "SuperModificable", -- can change special properties
  45.         ["Movable"] = "Movable", --- can be moved
  46.         ["Rotable"] = "Rotable", --- can be rotated
  47.         ["Scalable"] = "Scalable", --- can be scaled
  48.         ["CanHandleConstraints"] = "CanHandleConstraints", --- the name says it
  49.     },
  50.     SubModifiers = {
  51.         --- child = subInstance, not a person lol
  52.         ["Public"] = "Public"; --- valid child
  53.         ["Private"] = "Private"; --- protected child
  54.         ["Internal"] = "Internal" --- builtin or required child
  55.     },
  56.     PermissionLevel = {
  57.         ["Allowed"] = true, --- yes
  58.         ["Restringed"] = false --- no
  59.     }
  60. }
  61.  
  62. function Solar3.Surfaces(am:number)
  63.     Check(am,"number",1)
  64.     return {
  65.         [Enum.NormalId.Top] = {Scale=Vector3.new(0,am,0),Position=Vector3.new(0,am,0)},
  66.         [Enum.NormalId.Bottom] = {Scale=Vector3.new(0,am,0),Position=Vector3.new(0,-am,0)},
  67.         [Enum.NormalId.Right] = {Scale=Vector3.new(am,0,0),Position=Vector3.new(am,0,0)},
  68.         [Enum.NormalId.Left] = {Scale=Vector3.new(am,0,0),Position=Vector3.new(-am,0,0)},
  69.         [Enum.NormalId.Front] = {Scale=Vector3.new(0,0,am),Position=Vector3.new(0,0,am)},
  70.         [Enum.NormalId.Back] = {Scale=Vector3.new(0,0,am),Position=Vector3.new(0,0,-am)},
  71.     }
  72. end
  73.  
  74. function Solar3:Scale(Surface:Enum.NormalId,Increment:number,IgnoreCollisions:boolean,CenterOfMass:boolean)
  75.     local Part = self.Instance
  76.  
  77.  
  78.  
  79.     Check(Part,"userdata",1)Check(Surface,"userdata",2)Check(Increment,"number",3)
  80.     Check(IgnoreCollisions,"boolean",4)
  81.     Check(CenterOfMass,"boolean",5)
  82.  
  83.     local MaxStuds = Increment
  84.  
  85.     local prop = (not IgnoreCollisions) and 'Position' or 'CFrame'
  86.     Part.Size = Part.Size + Solar3.Surfaces(Increment)[Surface].Scale*MaxStuds
  87.     if CenterOfMass then
  88.         Part[prop] = Part[prop] + Solar3.Surfaces(Increment)[Surface].Position*(MaxStuds/2)
  89.     end
  90.     return Part.Size, Part[prop]
  91. end
  92.  
  93. function Solar3.SmoothRot(Part:BasePart,Radians:number,EnumAxis:Enum.Axis)
  94.  
  95.  
  96.     Check(Part,"userdata",1)Check(Radians,"number",2)
  97.     if not EnumAxis == Enum.Axis.Y or not EnumAxis == Enum.Axis.X or not EnumAxis == Enum.Axis.Z then
  98.         return error("\nUnable to use "..type(EnumAxis).." as Axis Use Enum.Axis.X (or .Y or .Z) instead".." \nAt value #3")
  99.     end
  100.  
  101.  
  102.  
  103.     if EnumAxis == x then
  104.         Part.CFrame = Part.Orientation*CFrame.Angles(math.pi/Radians,0,0)
  105.         return Part.CFrame
  106.  
  107.  
  108.     elseif EnumAxis == y then
  109.         Part.CFrame = Part.Orientation*CFrame.Angles(0,math.pi/Radians,0)
  110.         return Part.CFrame
  111.  
  112.  
  113.     elseif EnumAxis == z then
  114.         Part.CFrame = Part.Orientation*CFrame.Angles(0,0,math.pi/Radians)
  115.         return Part.CFrame
  116.  
  117.  
  118.     end
  119. end
  120.  
  121. function Solar3:Move(Surface:Enum.NormalId,Increment:number,IgnoreCollisions:boolean)
  122.     local Part = self.Instance
  123.  
  124.  
  125.     Check(Part,"userdata",1)Check(Surface,"userdata",2)
  126.     Check(Increment,"number",3)Check(IgnoreCollisions,"boolean",4)
  127.  
  128.     local MaxStuds = Increment
  129.  
  130.     local prop = (not IgnoreCollisions) and 'Position' or 'CFrame'
  131.     Part[prop] += Solar3.Surfaces(Increment)[Surface].Position*(MaxStuds/2)
  132.     return Part[prop]
  133. end
  134.  
  135. function Solar3:Rotate(EnumAxis:Enum.Axis,Increment:number,IgnoreCollisions:boolean)
  136.     local Part = self.Instance
  137.  
  138.  
  139.     Check(Part,"userdata",1)Check(Increment,"number",3)Check(IgnoreCollisions,"boolean",4)
  140.     if not EnumAxis == Enum.Axis.Y or not EnumAxis == Enum.Axis.X or not EnumAxis == Enum.Axis.Z then
  141.         return error("\nUnable to use "..type(EnumAxis).." as Axis Use Enum.Axis.X (or .Y or .Z) instead".." \nAt value #3")
  142.     end
  143.  
  144.  
  145.     local prop = (not IgnoreCollisions) and 'Orientation'
  146.  
  147.     if EnumAxis == x then
  148.         Part[prop] += Vector3.new(Increment,0,0)
  149.         return Part[prop]
  150.  
  151.  
  152.     elseif EnumAxis == y then
  153.         Part[prop] += Vector3.new(0,Increment,0)
  154.         return Part[prop]
  155.  
  156.  
  157.     elseif EnumAxis == z then
  158.         Part[prop] += Vector3.new(Increment,0,0)
  159.         return Part[prop]
  160.  
  161.  
  162.     end
  163. end
  164.  
  165.  
  166. function Solar3:Disappear()
  167.     local Part = self.Instance
  168.     Part.CanCollide = false
  169.     Part.Transparency = 1
  170. end
  171.  
  172.  
  173. function Solar3:Color(Color:Color3)
  174.     local Part = self.Instance
  175.     Part.Color = Color
  176. end
  177.  
  178.  
  179. function Solar3:GotoOrigin()
  180.     local Part = self.Instance
  181.     Part.Position = Vector3.new(0,0,0)
  182. end
  183.  
  184.  
  185. function Solar3:Smaller()
  186.     local Part = self.Instance
  187.     Part.Size = Vector3.new(0,0,0)
  188. end
  189.  
  190.  
  191. function Solar3:ReturnValidChildren()
  192.     local inst = self.Instance
  193.     local count = 1
  194.     local tab = {}
  195.     if inst:GetAttribute("CanHandle") then
  196.         for i,v in ipairs(inst:GetChildren()) do
  197.             if v:GetAttribute("ValidChildren") then
  198.                 table.insert(tab,count,v)
  199.                 count += 1
  200.             end
  201.         end
  202.     end
  203.     if #tab > 0 then
  204.         return tab
  205.     else
  206.         return {}
  207.     end
  208. end
  209.  
  210.  
  211. function Solar3:SetPlayerOwnership(plr:Player)
  212.     if self then
  213.         if not self.Instance then
  214.             error("Expected : not . on calling 'SetPlayerOwnership'")
  215.         end
  216.         if not type(self.Instance) == "userdata" then
  217.             error("Expected instance on calling 'SetPlayerOwnership'")
  218.         end
  219.     end
  220.  
  221.     if not plr then
  222.         self.Instance:SetAttribute("PlayerOwnership",821967424)
  223.         print("Setted the Ownership of instance "..self.Instance.Name.." to Game Owner (SolarDev)")
  224.     else
  225.         self.Instance:SetAttribute("PlayerOwnership",Get.UserId(plr.Name))
  226.         print("Setted the Ownership of instance "..self.Instance.Name.." to "..tostring(plr))
  227.     end
  228.  
  229.     return self.Instance
  230. end
  231.  
  232.  
  233.  
  234. function Solar3:DelPlayerOwnership()
  235.     if self then
  236.         if not self.Instance then
  237.             error("Expected : not . on calling 'DelPlayerOwnership'")
  238.         end
  239.         if not type(self.Instance) == "userdata" then
  240.             error("Expected instance on calling 'DelPlayerOwnership'")
  241.         end
  242.     end
  243.  
  244.     self.Instance:SetAttribute("PlayerOwnership",0)
  245. end
  246.  
  247.  
  248.  
  249. function Solar3:GetPlayerOwnership()
  250.     if self then
  251.         if not self.Instance then
  252.             error("Expected : not . on calling 'GetPlayerOwnership'")
  253.         end
  254.         if not type(self.Instance) == "userdata" then
  255.             error("Expected instance on calling 'GetPlayerOwnership'")
  256.         end
  257.     end
  258.  
  259.     return self.Instance:GetAttribute("PlayerOwnership")
  260. end
  261.  
  262.  
  263.  
  264. function Solar3:CheckPlayerOwnership(plr:Player)
  265.     if self then
  266.         if not self.Instance then
  267.             error("Expected : not . on calling 'CheckPlayerOwnership'")
  268.         end
  269.         if not type(self.Instance) == "userdata" then
  270.             error("Expected instance on calling 'CheckPlayerOwnership'")
  271.         end
  272.     end
  273.  
  274.     return self.Instance:GetAttribute("PlayerOwnership") == (Get.UserId(plr.Name))
  275. end
  276.  
  277.  
  278.  
  279. return Solar3
Tags: I.T
Advertisement
Add Comment
Please, Sign In to add comment