Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 KB | None | 0 0
  1. local module = {}
  2.  
  3. function module.Main(a1, a3, tooldebug, m)
  4.     local primaryregionpart = Instance.new("Part", game.Lighting) -- make the box that will determine the region3
  5.     primaryregionpart.Transparency = 1
  6.     if tooldebug then primaryregionpart.Transparency = 0.5 end
  7.     primaryregionpart.CanCollide = false
  8.     primaryregionpart.Anchored = true
  9.     primaryregionpart.CastShadow = false
  10.     primaryregionpart.Parent = game.Workspace -- prepare this
  11.     local cam = workspace.CurrentCamera -- make sure our camera is up to date
  12.     local camcf = cam.CFrame -- save this before calculations to prevent bad stuff
  13.  
  14.     -- documentation for the questionable mental state code below if you want to understand it:
  15.     --[[
  16.     a1, a2, a3, a4 are the corners of the selection gui when the player started and ended holding left mouse button
  17.     r means that it is the ray casted from the camera for that location
  18.     s means that it is the on screen position, aka the vector3 of the vector2 of the camera
  19.     d = distance
  20.     m = midpoint
  21.     p = prime (this means it was farther away)
  22.     tmp = temp, as in it's only going to be used once and i couldn't be asked to make another letter for it
  23.     a letter added on means its one of those things above
  24.     for example
  25.     a123ms would be the midpoint of a1, a2, and a3 at the player's coordinates (the corners of the gui they dragged)
  26.     ]]
  27.     local a2 = Vector2.new(a1.X, a3.Y) -- make a vector2 for a2
  28.     local a4 = Vector2.new(a3.X, a1.Y)
  29.     if tooldebug then print("All points:", a1, a2, a3) end
  30.     local a1r = cam:ScreenPointToRay(a1.X, a1.Y) -- get the thing from lego game
  31.     local a2r = cam:ScreenPointToRay(a2.X, a2.Y)
  32.     local a3r = cam:ScreenPointToRay(a3.X, a3.Y)
  33.     local a4r = cam:ScreenPointToRay(a4.X, a4.Y)
  34.     local a1r = Ray.new(a1r.Origin, a1r.Direction * 0) -- make the rays
  35.     local a2r = Ray.new(a2r.Origin, a2r.Direction * 0)
  36.     local a3r = Ray.new(a3r.Origin, a3r.Direction * 0)
  37.     local a4r = Ray.new(a4r.Origin, a4r.Direction * 0)
  38.     local _, a1s = workspace:FindPartOnRay(a1r, cam) -- get the position, we don't actually care about the part xd
  39.     local _, a2s = workspace:FindPartOnRay(a2r, cam)
  40.     local _, a3s = workspace:FindPartOnRay(a3r, cam)
  41.     local _, a4s = workspace:FindPartOnRay(a4r, cam)
  42.     local a1p = (CFrame.new(a1s, camcf.p) * CFrame.new(0, 0, 300)).p -- get our prime values
  43.     local a2p = (CFrame.new(a2s, camcf.p) * CFrame.new(0, 0, 300)).p
  44.     local a3p = (CFrame.new(a3s, camcf.p) * CFrame.new(0, 0, 300)).p
  45.     local a4p = (CFrame.new(a4s, camcf.p) * CFrame.new(0, 0, 300)).p
  46.    
  47.     local function makepointparts(x) -- debug function
  48.         print("Creating debug parts.")
  49.         for i, v in pairs(x) do
  50.             local p = Instance.new("Part", game.Workspace)
  51.             p.Anchored = true
  52.             p.CanCollide = false
  53.             p.CastShadow = false
  54.             p.BrickColor = BrickColor.new("Storm blue")
  55.             p.Material = Enum.Material.Neon
  56.             p.Size = Vector3.new(0.05, 0.05, 0.05)
  57.             p.Position = v
  58.             p.Name = "dbgpart"
  59.             if i > 4 then p.Size = Vector3.new(10, 10, 10) end
  60.         end
  61.     end
  62.  
  63.     local a1234pm = (a1p + a2p + a3p + a4p) / 4
  64.     local a1234sm = (a1s + a2s + a3s + a4s) / 4
  65.     local a1234spm = (a1234pm + a1234sm) / 2
  66.     local a1234dspm = (a1234pm - a1234sm).magnitude
  67.     local a12pd = (a1p - a2p).magnitude -- used to be height
  68.     local a14pd = (a1p - a4p).magnitude -- used to be thick
  69.    
  70.     local function calcpoints(a1s, a2s, a1p, a2p, mod1, mod2) -- function works in terms of a1 and a2 but really takes any two points
  71.         -- still requries thick and height though
  72.         local removebox = Instance.new("Part") -- make the removebox, and set basic properties
  73.         removebox.Anchored = true
  74.         removebox.CanCollide = false
  75.         removebox.CastShadow = false
  76.         removebox.Transparency = 1
  77.         removebox.BrickColor = BrickColor.new("Really red")
  78.         removebox.Size = Vector3.new(1, 1, 1)
  79.         removebox.Locked = true
  80.         if tooldebug then removebox.Transparency = 0.5 end -- debugging
  81.         removebox.Parent = game.Workspace
  82.         local a12sm = (a1s + a2s) / 2
  83.         local a12pm = (a1p + a2p) / 2 -- get the mid between the two points given
  84.         local a12dpsm = (a12sm - a12pm).magnitude -- get the magnitude between those
  85.         removebox.Size = Vector3.new(a14pd, a12pd, a12dpsm) -- set the size
  86.         local a14pdtmp
  87.         local a12pdtmp
  88.         if mod2 then -- determines what changes to the operation need to be made based off of orientation
  89.             a14pdtmp = a14pd / mod1
  90.             a12pdtmp = 1
  91.         else
  92.             a14pdtmp = 1
  93.             a12pdtmp = a12pd / mod1
  94.         end
  95.         removebox.CFrame = (CFrame.new(a12sm, a12pm) * CFrame.new(a14pdtmp, a12pdtmp, a1234dspm / -2)) -- set the cframe
  96.         return removebox
  97.     end
  98.  
  99.     local bp1 = calcpoints(a1s, a2s, a1p, a2p, 2, true)
  100.     local bp2 = calcpoints(a2s, a3s, a2p, a3p, -2, false) -- inv
  101.     local bp3 = calcpoints(a3s, a4s, a3p, a4p, -2, true)
  102.     local bp4 = calcpoints(a4s, a1s, a4p, a1p, 2, false) -- inv
  103.  
  104.     primaryregionpart.Position = a1234spm
  105.     primaryregionpart.Size = Vector3.new(a12pd, a14pd, a1234dspm)
  106.     primaryregionpart.CFrame = CFrame.new(primaryregionpart.Position, a1234pm)
  107.  
  108.     if tooldebug then makepointparts({a1s, a2s, a3s, a4s, a1p, a2p, a3p, a4p}) end
  109.     return primaryregionpart, bp1, bp2, bp3, bp4
  110. end
  111.  
  112. return module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement