Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- global 'plugin'
- local toolbar = plugin:CreateToolbar("Waypoint Creator");
- local isPluginActive = false;
- local shiftDown = false;
- local newPointButton_isActive = false;
- local connectPointsButton_isActive = false;
- local newPointButton = toolbar:CreateButton(
- "New Waypoint",
- "Click on a surface to create a waypoint piece there.",
- "http://www.roblox.com/asset/?id=1109508861"
- );
- local connectPointsButton = toolbar:CreateButton(
- "Connect Waypoints",
- "Click a waypoint, then click another different waypoint to connect them.",
- "http://www.roblox.com/asset/?id=1109509029"
- );
- local connections = {};
- local folder;
- local function generateWaypoint(pos)
- if (not folder or not folder.Parent) then
- print("Cannot create a waypoint. There is no folder named Plugin_Waypoints in the Workspace!");
- return
- end
- local point = Instance.new("Part")
- point.Size = Vector3.new(3,1,3)
- point.BrickColor = BrickColor.new("Really blue")
- point.Name = "Waypoint"
- local mesh = Instance.new("SpecialMesh", point)
- mesh.MeshType = "FileMesh"
- mesh.MeshId = "http://www.roblox.com/Asset/?id=9756362"
- mesh.Scale = Vector3.new(3,3,3)
- point.Anchored = true
- point.CanCollide = false
- point.TopSurface = "Smooth"
- point.BottomSurface = "Smooth"
- point.CFrame = CFrame.new(pos)
- point.Parent = folder
- return point
- end
- local function removeConnection(p1,p2)
- for i,v in pairs(p1:GetChildren()) do
- if (v:IsA("ObjectValue")) then
- if (v.Value == p2) then
- if (v:FindFirstChild("RodValue")) then
- v.RodValue.Value:Destroy()
- end
- v:Destroy()
- break
- end
- end
- end
- for i,v in pairs(p2:GetChildren()) do
- if (v:IsA("ObjectValue")) then
- if (v.Value == p1) then
- if (v:FindFirstChild("RodValue")) then
- v.RodValue.Value:Destroy()
- end
- v:Destroy()
- break
- end
- end
- end
- end
- local function determineIfConnected(p1,p2)
- local c1, c2 = false, false;
- for i,v in pairs(p1:GetChildren()) do
- if (v:IsA("ObjectValue")) then
- if (v.Value == p2) then
- c1 = true
- break
- end
- end
- end
- for i,v in pairs(p2:GetChildren()) do
- if (v:IsA("ObjectValue")) then
- if (v.Value == p1) then
- c2 = true
- break
- end
- end
- end
- print("Not connected.");
- return (c1 == true and c2 == true);
- end
- local function connectWaypoints(p1, p2)
- if (determineIfConnected(p1,p2) == false) then
- local obv1 = Instance.new("ObjectValue", p1)
- obv1.Name = "Connection"
- obv1.Value = p2
- local obv2 = Instance.new("ObjectValue", p2)
- obv2.Name = "Connection"
- obv2.Value = p1
- local rod = Instance.new("Part")
- local distance = (p2.Position - p1.Position).magnitude
- rod.BrickColor = BrickColor.new("New Yeller")
- rod.CanCollide = false;
- rod.Anchored = true;
- rod.Name = "Rod"
- rod.Size = Vector3.new(0.25,0.25,distance)
- rod.CFrame = CFrame.new(p1.Position, p2.Position)
- rod.CFrame = rod.CFrame * CFrame.new(0,0,-distance/2);
- rod.Parent = folder;
- local rodValue = Instance.new("ObjectValue", obv1)
- rodValue.Name = "RodValue"
- rodValue.Value = rod;
- p1.BrickColor = BrickColor.new("Really blue");
- p2.BrickColor = BrickColor.new("Really blue");
- end
- if (p1:FindFirstChild("Fire")) then
- p1.Fire:Destroy()
- end
- if (p2:FindFirstChild("Fire")) then
- p2.Fire:Destroy()
- end
- end
- local function removeReferences(waypoint)
- for i,v in pairs(waypoint:GetChildren()) do
- if (v:IsA("ObjectValue")) then
- if (v:FindFirstChild("RodValue")) then
- v.RodValue.Value:Destroy();
- end
- local part = v.Value;
- for k, j in pairs(part:GetChildren()) do
- if (j:IsA("ObjectValue")) then
- if (j.Value == waypoint) then
- if (j:FindFirstChild("RodValue")) then
- j.RodValue.Value:Destroy();
- end
- j:Destroy()
- end
- end
- end
- end
- end
- end
- local function off()
- isPluginActive = false;
- newPointButton_isActive = false;
- newPointButton:SetActive(false);
- connectPointsButton:SetActive(false);
- connectPointsButton_isActive = false;
- for i,v in pairs(connections) do
- v:disconnect()
- end
- connections = {};
- end
- local function saveProgress()
- local pointName = tostring(os.time());
- game:GetService("ChangeHistoryService"):SetWaypoint(pointName);
- end
- local function fire(waypoint)
- local fire = Instance.new("Fire", waypoint)
- end
- connectPointsButton.Click:connect(function()
- spawn(function()
- isPluginActive = not isPluginActive;
- if (isPluginActive) then
- plugin:Activate(true);
- isPluginActive = true;
- end
- connectPointsButton_isActive = true;
- connectPointsButton:SetActive(true);
- if (isPluginActive) then
- local mouse = plugin:GetMouse();
- local currentPaintedTarget;
- local waypoint1;
- table.insert(connections, mouse.Button1Down:connect(function()
- if (mouse.Target) then
- if (shiftDown == true) then
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- saveProgress();
- removeReferences(mouse.Target);
- mouse.Target:Destroy();
- end
- else
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- if not (waypoint1) then
- fire(mouse.Target)
- waypoint1 = mouse.Target
- else
- connectWaypoints(waypoint1, mouse.Target)
- waypoint1 = nil
- saveProgress();
- end
- end
- end
- end
- end));
- table.insert(connections, mouse.Move:connect(function()
- if (currentPaintedTarget) then
- if (mouse.Target ~= currentPaintedTarget) then
- currentPaintedTarget.BrickColor = BrickColor.new("Really blue")
- currentPaintedTarget = nil;
- end
- else
- if (mouse.Target) then
- if (shiftDown) then
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- currentPaintedTarget = mouse.Target;
- currentPaintedTarget.BrickColor = BrickColor.new("Really red");
- end
- else
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- currentPaintedTarget = mouse.Target;
- currentPaintedTarget.BrickColor = BrickColor.new("Lime green");
- end
- end
- end
- end
- end));
- table.insert(connections, mouse.KeyDown:connect(function(key)
- local keyCode = key:byte()
- if (keyCode == 48) then
- shiftDown = true;
- end
- end));
- table.insert(connections, mouse.KeyUp:connect(function(key)
- local keyCode = key:byte()
- if (keyCode == 48) then
- shiftDown = false;
- end
- end));
- else
- off()
- end
- end)
- end)
- newPointButton.Click:connect(function()
- spawn(function()
- isPluginActive = not isPluginActive;
- if (isPluginActive) then
- plugin:Activate(true);
- isPluginActive = true;
- end
- newPointButton_isActive = true;
- newPointButton:SetActive(true);
- if (isPluginActive) then
- if not (workspace:FindFirstChild("Plugin_Waypoints")) then
- folder = Instance.new("Folder", workspace)
- folder.Name = "Plugin_Waypoints"
- else
- folder = workspace.Plugin_Waypoints;
- end
- local mouse = plugin:GetMouse();
- local currentPaintedTarget;
- table.insert(connections, mouse.Button1Down:connect(function()
- if (mouse.Target) then
- if (shiftDown == false) then
- generateWaypoint(mouse.Hit.p)
- saveProgress();
- else
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- removeReferences(mouse.Target);
- mouse.Target:Destroy();
- saveProgress();
- end
- end
- end
- end));
- table.insert(connections, mouse.Move:connect(function()
- if (currentPaintedTarget) then
- if (mouse.Target ~= currentPaintedTarget) then
- currentPaintedTarget.BrickColor = BrickColor.new("Really blue")
- currentPaintedTarget = nil;
- end
- else
- if (mouse.Target and shiftDown) then
- if (mouse.Target.Parent == folder and mouse.Target.Name == "Waypoint") then
- currentPaintedTarget = mouse.Target;
- currentPaintedTarget.BrickColor = BrickColor.new("Really red");
- end
- end
- end
- end));
- table.insert(connections, mouse.KeyDown:connect(function(key)
- local keyCode = key:byte()
- if (keyCode == 48) then
- shiftDown = true;
- end
- end));
- table.insert(connections, mouse.KeyUp:connect(function(key)
- local keyCode = key:byte()
- if (keyCode == 48) then
- shiftDown = false;
- end
- end));
- else
- off()
- end
- end)
- end)
- plugin.Deactivation:connect(function()
- if (isPluginActive) then
- off()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement