Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.71 KB | None | 0 0
  1. local v=script.Parent local f=game.Players.LocalPlayer local x=v:WaitForChild("PortafabConstructionMenu")local a=v:WaitForChild("Handle")local y=v:WaitForChild("Remote")local q=require(v:WaitForChild("InterfaceModule"))local s=require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("ContextHint"))local e=game.Players.LocalPlayer.PlayerScripts:WaitForChild("ContextButtons").CurrentContextButton local c=require(game.ReplicatedStorage.Utilities.StructureUtil)local b=game:GetService("UserInputService")local A=game:GetService("ContextActionService")local n=false local r={}local t local j=game:GetService("UserInputService")local k local p=false local w local l=false local g=game:GetService("RunService").Heartbeat local m function GetPC()local b=game.Players.LocalPlayer local a=b.Character return b,a end function GetSG()local b,a=GetPC()local a=b.PlayerGui local a=a.ScreenGui return a end function GetMouseInfo()local b,a=GetPC()local b=b:GetMouse()local b=workspace.CurrentCamera:ScreenPointToRay(b.X,b.Y)b=Ray.new(b.Origin,b.Direction*1024)return workspace:FindPartOnRayWithIgnoreList(b,{a,workspace:FindFirstChild("Effects")})end local u,o,d function ActiveLoop()if n then return end n=true end local a=15 local h=1/a local i=0 local function a()u,o,d=GetMouseInfo()updateContextHint()if tick()-i>h then i=tick()y:FireServer("TargetUpdated",o,u)end end local z,i,h function updateContextHint()if p then return end if u and q:CanInterface(u)and q:IsInRange(o)then if u==workspace.Terrain then if z then z:Remove()end z=s:AddHint({{"E","Pull"}})else if z then z:Remove()end z=s:AddHint({{"L Click","Push"},{"E","Pull"}})end elseif z then z:Remove()z=nil end local a=q:FindStructure(u)if a and q:IsInRange(o)then if a:FindFirstChild("Health")and a:FindFirstChild("MaxHealth")and not a:FindFirstChild("IsBlueprint")and a.Health.Value<a.MaxHealth.Value and not e.Value then if not i then i=s:AddHint({{"L Click","Repair"}})end elseif i then i:Remove()i=nil end if c:PlayerCanInteract(a,f)then if not h then h=s:AddHint({{"G","Destroy"}})end elseif h then h:Remove()h=nil end else if i then i:Remove()i=nil end if h then h:Remove()h=nil end end end function Activate()local c,b,a=GetMouseInfo()y:FireServer("Activated",b,c)ActiveLoop()end function Deactivate()y:FireServer("Deactivated")n=false end function OnLeftMouse(a,b,a)if b==Enum.UserInputState.Begin then y:FireServer("ModeChanged","Extract")Activate()else Deactivate()end end function OnKeyE(a,b,a)if b==Enum.UserInputState.Begin then y:FireServer("ModeChanged","Extrude")Activate()else Deactivate()end end function OnKeyG(a,b,a)if b==Enum.UserInputState.Begin then ActiveLoop()UpdateTarget()local b,c,a=GetMouseInfo()y:FireServer("DestroyActivated",c,b)else n=false y:FireServer("DestroyDeactivated")end end function UpdateTarget()local a,b,a=GetMouseInfo()y:FireServer("TargetUpdated",b)end function Thumbnail(a)return"https://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId="..a end function GuiShowFolder(e)SlotButtonHovered()if not e then return end game.ReplicatedStorage.Remotes.EventReported:FireServer({Name="PortafabCategoryChosen",Category=e.Name,Player=game.Players.LocalPlayer})local c={}local b={}for a,a in pairs(e:GetChildren())do if a:IsA("Model")then table.insert(c,a)elseif a:IsA("Folder")and a.Name~="CustomBlueprints"then table.insert(b,a)end end local d={"Z","X","C","V"}local f=1 local a=function(b,a)b=(b:FindFirstChild("Importance")or{Value=0}).Value a=(a:FindFirstChild("Importance")or{Value=0}).Value return b<a end table.sort(c,a)table.sort(b,a)for a,b in pairs(c)do local a=d[f]r[a]=b local a=x.SlotsFrame["Slot"..a.."Frame"]a.Visible=true a.LabelImage.LabelText.Text=b.Name a.CostImage.CostText.Text=b.Cost.Value a.CostImage.Visible=true a.SlotImage.Image=Thumbnail(b.ImageId.Value)f=f+1 end for a,a in pairs(b)do local b=d[f]r[b]=a local b=x.SlotsFrame["Slot"..b.."Frame"]b.Visible=true b.LabelImage.LabelText.Text=a.Name b.CostImage.Visible=false b.SlotImage.Image=""f=f+1 end for a=f,#d do local a=d[a]x.SlotsFrame["Slot"..a.."Frame"].Visible=false r[a]=nil end t=e.Parent if t==game.ReplicatedStorage then t=nil end x.BackBackgroundImage.Visible=t~=nil end function OnPlace(a,b,a)if b==Enum.UserInputState.Begin and w:ConfirmPlacement()then game.ReplicatedStorage.Remotes.EventReported:FireServer({Name="PortafabBlueprintPlaced",Player=game.Players.LocalPlayer})OnAbortPlacement()end end function OnRotate(a,a,c)if c.KeyCode==Enum.KeyCode.R and a==Enum.UserInputState.Begin then w:Rotate()elseif c.UserInputType==Enum.UserInputType.MouseWheel and b:IsKeyDown(Enum.KeyCode.LeftShift)then if c.Position.Z==1 then w:Rotate(15)elseif c.Position.Z==-1 then w:Rotate(-15)end end end function ShiftDown(a,b,a)if b==Enum.UserInputState.Begin then A:BindAction("PortafabFineRotate",OnRotate,false,Enum.UserInputType.MouseWheel)elseif b==Enum.UserInputState.End then A:UnbindAction("PortafabFineRotate")end end function OnChangeSnapPoint(a,b,a)if b==Enum.UserInputState.Begin then w:ChangeSnapPoint()end end local d function OnAbortPlacement(a,a,a)if not p then return end p=false w:AbortPlacement()A:UnbindAction("PortafabRotate")A:UnbindAction("PortafabShift")A:UnbindAction("PortafabFineRotate")A:UnbindAction("PortafabChangeSnapPoint")A:UnbindAction("PortafabEscape")A:UnbindAction("PortafabPlace")if d then d:Remove()d=nil end end function PlaceModel(c)OnAbortPlacement()local b,a=GetPC()w=require(script.Parent.StructurePlacer)p=true w:EnterPlacementMode(c.Name)game.ReplicatedStorage.Remotes.EventReported:FireServer({Name="PortafabBlueprintChosen",Blueprint=c.Name,Player=b})A:BindAction("PortafabRotate",OnRotate,false,Enum.KeyCode.R)A:BindAction("PortafabShift",ShiftDown,false,Enum.KeyCode.LeftShift)A:BindAction("PortafabChangeSnapPoint",OnChangeSnapPoint,false,Enum.KeyCode.T)A:BindAction("PortafabEscape",OnAbortPlacement,false,Enum.KeyCode.E)A:BindAction("PortafabPlace",OnPlace,false,Enum.UserInputType.MouseButton1)d=s:AddHint({{"L Click","Place"},{"E","Cancel"},{"R","Rotate 90"},{"Shift + Scroll","Fine Rotate"},{"T","Change Snap"}})end y.OnClientEvent:connect(function(a,...)if a=="PlaceModel"then PlaceModel(...)end end)function SlotSelected(a)local a=r[a]if not a then return end if a:IsA("Folder")then GuiShowFolder(a)else PlaceModel(a)end end function OnGuiKeyPress(a)if a.UserInputState~=Enum.UserInputState.Begin then return end if j:GetFocusedTextBox()then return end local a=a.KeyCode local b=Enum.KeyCode if a==b.Q then GuiShowFolder(t)elseif a==b.Z then SlotSelected("Z")elseif a==b.X then SlotSelected("X")elseif a==b.C then SlotSelected("C")elseif a==b.V then SlotSelected("V")end end function ActivateGui()x.Parent=GetSG()k=j.InputBegan:connect(OnGuiKeyPress)GuiShowFolder(game.ReplicatedStorage.Structures)m=g:connect(a)end function DeactivateGui()x.Parent=v if k then k:disconnect()end OnAbortPlacement()if m then m:disconnect()end if i then i:Remove()i=nil end if z then z:Remove()z=nil end if d then d:Remove()d=nil end if h then h:Remove()h=nil end end function OnEquipped()if l then return end l=true ActivateGui()A:BindAction("PortafabLeftActivation",OnLeftMouse,false,Enum.KeyCode.E)A:BindAction("PortafabRightActivation",OnKeyE,false,Enum.UserInputType.MouseButton1)A:BindAction("PortafabDestroyActivation",OnKeyG,false,Enum.KeyCode.G)l=false end v.Equipped:connect(OnEquipped)function OnUnequipped()DeactivateGui()A:UnbindAction("PortafabLeftActivation")A:UnbindAction("PortafabRightActivation")A:UnbindAction("PortafabDestroyActivation")end v.Unequipped:connect(OnUnequipped)local c function SlotButtonHovered(a,b)if c then c:Destroy()c=nil end if not a then return end if not b then return end local a=r[a]if not a then return end local a=a:FindFirstChild("Description")if not a then return end local d=Instance.new("TextLabel")d.BackgroundColor3=Color3.new(0,0,0)d.BorderColor3=Color3.new(0,0,0,0)d.BackgroundTransparency=0.5 d.TextColor3=Color3.new(1,1,1)d.Font="SciFi"d.TextSize=16 d.TextXAlignment="Left"d.TextWrapped=true d.Text=a.Value d.AnchorPoint=Vector2.new(0,0.5)d.Position=UDim2.new(1,10,0.5,0)d.Size=UDim2.new(0,240,0,d.TextSize*10)d.Parent=b d.Size=UDim2.new(0,d.TextBounds.X+2,0,d.TextBounds.Y)c=d end function PrepareButtons()local a={"Z","X","C","V"}for a,b in pairs(a)do do local a=x.SlotsFrame["Slot"..b.."Frame"]local c=a.Button local a=true c.MouseEnter:connect(function()c.BackgroundTransparency=0.5 end)c.MouseLeave:connect(function()c.BackgroundTransparency=1 end)c.MouseButton1Click:connect(function()if not a then return end a=false delay(0.075,function()a=true end)SlotSelected(b)end)c.MouseMoved:connect(function()SlotButtonHovered(b,c)end)c.MouseLeave:connect(function()SlotButtonHovered()end)end end local a=x.BackBackgroundImage.Button a.MouseEnter:connect(function()a.BackgroundTransparency=0.5 end)a.MouseLeave:connect(function()a.BackgroundTransparency=1 end)a.MouseButton1Click:connect(function()GuiShowFolder(t)end)end PrepareButtons()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement