Created
January 28, 2018 21:48
-
-
Save Aerodos12/83fd669bb2cd34f8ea45e231ed614438 to your computer and use it in GitHub Desktop.
Loadout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local M3D = require(game.ReplicatedStorage.Module3D) | |
| local UIS = game:GetService("UserInputService") | |
| local InputDown, LastPos | |
| local currentCamera = workspace.CurrentCamera | |
| local V3,CF = Vector3.new, CFrame.new | |
| local CFANG = CFrame.Angles | |
| local SIN, COS = math.sin, math.cos | |
| local RANDOM = math.random | |
| local InventoryService = require(game.ReplicatedStorage.InventoryService) | |
| local player = game.Players.LocalPlayer | |
| local UI = script.Parent | |
| local ReloadConn, turnW | |
| function fromaxisangle(x,y,z) | |
| if not y then | |
| x,y,z=x.x,x.y,x.z | |
| end | |
| local m=(x*x+y*y+z*z)^0.5 | |
| if m>1e-5 then | |
| local si= SIN(m/2)/m | |
| return CF(0,0,0,si*x,si*y,si*z,COS(m/2)) | |
| else | |
| return CF() | |
| end | |
| end | |
| function getLoadoutStageCFrame() | |
| local stages = game.Workspace.Stages:GetChildren() | |
| local stage = stages[RANDOM(#stages)] | |
| return CFrame.new(stage.ViewPart.CFrame.p,stage.ViewPart.CFrame.p + stage.ViewPart.CFrame.lookVector) | |
| end | |
| local weaponImage | |
| script.Parent.Weapon.Changed:connect(function(weapon) | |
| if weapon then | |
| if weaponImage then | |
| weaponImage:End() | |
| for _, item in pairs(UI.Camos:GetChildren()) do | |
| if item:IsA("Frame") then | |
| item:Destroy() | |
| end | |
| end | |
| end | |
| weaponImage = M3D:Attach3D(script.Parent.WeaponImage,InventoryService:GetModel("Blaster",weapon.Name)) | |
| weaponImage:SetActive(true) | |
| weaponImage:SetCFrame(CFANG(0,90,0)) | |
| currentCamera.CameraType = Enum.CameraType.Scriptable | |
| currentCamera.CFrame = getLoadoutStageCFrame() | |
| turnW = UIS.InputChanged:connect(function(object) | |
| local newpos=object.Position | |
| if InputDown then | |
| local type=object.UserInputType.Name | |
| local delta=newpos - LastPos | |
| if type=="MouseMovement" then | |
| if weaponImage.Object3D and weaponImage.Object3D.PrimaryPart then | |
| local b= currentCamera.CFrame | |
| local c=b:inverse()* weaponImage.Object3D.PrimaryPart.CFrame | |
| local rotx=delta.y/2048 | |
| local roty=delta.x/1024 | |
| weaponImage:SetCFrame(((c-c.p)* fromaxisangle(rotx,roty,0))) | |
| end | |
| --elseif type=="MouseWheel" then | |
| -- fireonscroll(pos.z) | |
| end | |
| end | |
| LastPos=newpos | |
| end) | |
| UIS.InputBegan:connect(function(object,gp) | |
| local type=object.UserInputType.Name | |
| if type=="MouseButton1" and not gp then | |
| InputDown=true | |
| end | |
| end) | |
| UIS.InputEnded:connect(function(object) | |
| local type=object.UserInputType.Name | |
| if type=="MouseButton1" then | |
| InputDown=false | |
| end | |
| end) | |
| local camoCounter = 0 | |
| for n, v in pairs(InventoryService:GetAvailableCamos()) do | |
| local camo = InventoryService.Camo.FromReplicatedCamo(v) | |
| local CamoButton = camo:CreateButton(n,player,weaponImage.Object3D,weapon) | |
| CamoButton.Parent = UI.Camos | |
| CamoButton.LayoutOrder = camoCounter | |
| camoCounter = camoCounter + 1 | |
| end | |
| ReloadConn = UI.RefillButton.MouseButton1Click:connect(function() | |
| UI.Parent.AmmoManager.Weapon.Value = UI.Weapon.Value | |
| UI.Parent.ViewController:JumpTo(UI.Parent.AmmoManager) | |
| turnW:disconnect() | |
| end) | |
| for _, upgrade in pairs(weapon.Upgrades:GetChildren()) do | |
| local attachment | |
| end | |
| else | |
| weaponImage:End() | |
| ReloadConn:disconnect() | |
| end | |
| end) | |
| script.Parent.Parent.DeploymentContainer.DeployButton.MouseButton1Click:connect(function() | |
| if weaponImage then | |
| weaponImage:End() | |
| end | |
| end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local DeploymentUI = script.Parent | |
| local RemoteService = require(game.ReplicatedStorage.RemoteService) | |
| local WeaponsLayout = DeploymentUI.Weapons | |
| local WeaponsTemplate = game.ReplicatedStorage.DeploymentUIs.WeaponItem | |
| local ClassLayout = DeploymentUI.CurrentClass | |
| local ClassTemplate = game.ReplicatedStorage.DeploymentUIs.ClassTemplate | |
| local SlotTypeLayout = DeploymentUI.SlotType | |
| local DefaultDeploymentClasses = require(game.ReplicatedStorage.DeploymentClasses) | |
| local ClassConnections = {} | |
| local SlotConnections = {} | |
| local plr = game.Players.LocalPlayer | |
| wait(4) | |
| function Populate() | |
| for i, class in pairs(DefaultDeploymentClasses) do | |
| local classUIObj = ClassTemplate:Clone() | |
| classUIObj.Name = class.Name | |
| classUIObj.Text = class.Name:upper() | |
| classUIObj.LayoutOrder = i | |
| ClassConnections[class.Name] = {} | |
| for _, slotC in pairs(SlotConnections) do | |
| slotC:disconnect() | |
| end | |
| for slotName, items in pairs(class.Weapons(plr):toTable()) do | |
| table.insert(SlotConnections,SlotTypeLayout:FindFirstChild(slotName.."Button").MouseButton1Click:connect(function() | |
| ClassConnections[class.Name][slotName] = {} | |
| for _, item in pairs(WeaponsLayout:GetChildren()) do | |
| if item:IsA("Frame") then | |
| item:Destroy() | |
| end | |
| end | |
| for index, weaponItem in pairs(items) do | |
| local weapon = WeaponsTemplate:Clone() | |
| weapon.LayoutOrder = index | |
| weapon.Name = weaponItem.Name | |
| weapon.WeaponName.Text = weaponItem.Name | |
| if weaponItem.Type.Value == "Blaster" then | |
| weapon.WeaponType.Text = weaponItem.BlasterType.Value | |
| elseif weaponItem.Type.Value == "Saber" then | |
| weapon.WeaponType.Text = "Saber" | |
| elseif weaponItem.Type.Value == "Blade" then | |
| weapon.WeaponType.Text = "Bladed Weapon" | |
| end | |
| table.insert(ClassConnections[class.Name][slotName],weapon.UseButton.MouseButton1Click:connect(function() | |
| RemoteService.send("Server","Change"..slotName.."Weapon",weaponItem) | |
| weapon.BackgroundColor3 = Color3.fromRGB(0,163,255) | |
| for _, item in pairs(WeaponsLayout:GetChildren()) do | |
| if item ~= weapon then | |
| item.BackgroundColor3 = Color3.fromRGB(59, 59, 59) | |
| end | |
| end | |
| end)) | |
| weapon.Parent = WeaponsLayout | |
| end | |
| end)) | |
| end | |
| classUIObj.Parent = ClassLayout | |
| end | |
| ClassLayout.ClassController.Stopped:connect(function(page) | |
| local class = DefaultDeploymentClasses[page.LayoutOrder] | |
| for _, slotC in pairs(SlotConnections) do | |
| slotC:disconnect() | |
| end | |
| for slotName, items in pairs(class.Weapons(plr):toTable()) do | |
| table.insert(SlotConnections,SlotTypeLayout:FindFirstChild(slotName.."Button").MouseButton1Click:connect(function() | |
| ClassConnections[class.Name][slotName] = {} | |
| for _, item in pairs(WeaponsLayout:GetChildren()) do | |
| if item:IsA("Frame") then | |
| item:Destroy() | |
| end | |
| end | |
| for index, weaponItem in pairs(items) do | |
| local weapon = WeaponsTemplate:Clone() | |
| weapon.LayoutOrder = index | |
| weapon.Name = weaponItem.Name | |
| if weaponItem.Type.Value == "Blaster" then | |
| weapon.WeaponType.Text = weaponItem.BlasterType.Value | |
| elseif weaponItem.Type.Value == "Saber" then | |
| weapon.WeaponType.Text = "Saber" | |
| elseif weaponItem.Type.Value == "Blade" then | |
| weapon.WeaponType.Text = "Bladed Weapon" | |
| end weapon.WeaponName.Text = weaponItem.Name | |
| table.insert(ClassConnections[class.Name][slotName],weapon.UseButton.MouseButton1Click:connect(function() | |
| RemoteService.send("Server","Change"..slotName.."Weapon",weaponItem) | |
| weapon.BackgroundColor3 = Color3.fromRGB(0,163,255) | |
| for _, item in pairs(WeaponsLayout:GetChildren()) do | |
| if item ~= weapon then | |
| item.BackgroundColor3 = Color3.fromRGB(59, 59, 59) | |
| end | |
| end | |
| end)) | |
| table.insert(ClassConnections[class.Name][slotName],weapon.UseButton.MouseButton2Click:connect(function() | |
| script.Parent.Parent.GunAppearance.Weapon.Value = weaponItem | |
| script.Parent.Parent.ViewController:JumpTo(script.Parent.Parent.GunAppearance) | |
| end)) | |
| weapon.Parent = WeaponsLayout | |
| end | |
| end)) | |
| end | |
| end) | |
| end | |
| Populate() | |
| DeploymentUI.NextClass.MouseButton1Click:connect(function() | |
| DeploymentUI.CurrentClass.ClassController:Next() | |
| end) | |
| DeploymentUI.PreviousClass.MouseButton1Click:connect(function() | |
| DeploymentUI.CurrentClass.ClassController:Previous() | |
| end) | |
| DeploymentUI.PackageButton.MouseButton1Click:connect(function() | |
| script.Parent.Parent.ViewController:JumpTo() | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment