Alexware
|
  |
| Joined: 07 May 2010 |
| Total Posts: 661 |
|
|
| 07 May 2015 09:36 PM |
What I want is instead of clicking to shoot a grapple hook, I want it so when you press, h, the script acts the same way, but with a key activation... Script:
local maxDistance = 200 local canFireWhileGrappling = true
local Tool = script.Parent; local torso = nil local human = nil local bolt = nil local targetPos = Vector3.new(0,0,0) local boltconnect = nil local holdweld = nil
local rope = Instance.new("Part") rope.BrickColor = BrickColor.new("Black") rope.TopSurface = 0 rope.BottomSurface = 0 rope.formFactor = "Symmetric" rope.Name = "Rope" rope.CanCollide = false rope.Anchored = true local mesh = Instance.new("CylinderMesh") mesh.Parent = rope mesh.Scale = Vector3.new(0.1,1,0.1)
local bodyPos = Instance.new("BodyPosition") bodyPos.D = 1e+003 bodyPos.P = 3e+003 bodyPos.maxForce = Vector3.new(1e+006, 1e+006, 1e+006)
local bodyGyro = Instance.new("BodyGyro") bodyGyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
function adjustRope() if rope.Parent == nil or bolt == nil then return end local pos1 = Tool.Handle.Position local pos2 = bolt.Position rope.Size = Vector3.new(0, 1, 0) rope.Mesh.Scale = Vector3.new(0.1, (pos1-pos2).magnitude, 0.1) rope.CFrame = CFrame.new((pos1 + pos2)/2, pos2) * CFrame.fromEulerAnglesXYZ(-math.pi/2,0,0) end
function onBoltHit(hit) if bolt == nil or hit == rope or bolt.Name ~= "Bolt" or hit.Parent == Tool or hit.Parent == Tool.Parent or hit.Parent.Parent == Tool.Parent or hit.Parent.Name == "Attached Bolt" then return end if (bolt.Position - torso.Position).magnitude > maxDistance then bolt.Parent = nil bolt = nil return end bolt.Name = "Attached Bolt" local boltFrame = CFrame.new(hit.Position)
local C0 = hit.CFrame:inverse() * boltFrame local C1 = bolt.CFrame:inverse() * boltFrame local weld = Instance.new("Weld") weld.Part0 = hit weld.Part1 = bolt weld.C0 = C0 weld.C1 = C1 weld.Parent = bolt
bolt.HitSound:play() local backupbolt = bolt wait(0.4) if bolt == nil or bolt ~= backupbolt then return end bolt.ConnectSound:play() Tool.Handle.ConnectSound:play()
targetPos = bolt.Position backupPos = bolt.Position
bodyPos.position = targetPos bodyPos.Parent = torso bodyGyro.cframe = torso.CFrame bodyGyro.Parent = torso
while targetPos == backupPos and bolt ~= nil do bodyPos.position = bolt.Position wait() end
end
enabled = true
function onButton1Down(mouse)
if not enabled then return end
if bolt ~= nil and not canFireWhileGrappling then return end if bolt ~= nil then if boltconnect ~= nil then print("Disconnecting") boltconnect:disconnect() end bolt:remove() targetPos = Vector3.new(0,0,0) end
Tool.Handle.FireSound:play()
enabled = false
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
bolt = game:GetService("InsertService"):LoadAsset(33393977)
local instances = bolt:GetChildren() if #instances == 0 then bolt:Remove() return end bolt = bolt:FindFirstChild("Bolt") bolt.CFrame = CFrame.new(Tool.Handle.Position + (mouse.Hit.p - Tool.Handle.Position).unit * 5,mouse.Hit.p) * CFrame.fromEulerAnglesXYZ(0,math.pi,0) bolt.Transparency = 0 bolt.CanCollide = false bolt.Velocity = bolt.CFrame.lookVector * -70 if bolt:findFirstChild("BodyPosition") ~= nil then bolt.BodyPosition:remove() end local force = Instance.new("BodyForce") force.force = Vector3.new(0,70,0) force.Parent = bolt bolt.Parent = workspace boltconnect = bolt.AncestryChanged:connect(function() onKeyDown("q") end) bolt.Touched:connect(onBoltHit)
rope.Parent = Tool
bolt.Parent = game.Workspace
Tool.Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=30308256" wait(2)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true end
function onKeyDown(key) key = key:lower() if key == "q" then if human then human.Sit = false end rope.Parent = nil bodyPos.Parent = nil bodyGyro.Parent = nil if bolt ~= nil then bolt.Parent = nil end if holdweld ~= nil then holdweld.Parent = nil end holdweld = nil bolt = nil Tool.Handle.Mesh.MeshId = "http://www.roblox.com/asset/?id=33393806" --script.Parent.Bolt.Transparency = 0 end end
function getHumanoid(obj) for i,child in pairs(obj:getChildren()) do if child.className == "Humanoid" then return child end end end
function onEquippedLocal(mouse) if mouse == nil then print("Mouse not found") return end
torso = Tool.Parent:findFirstChild("Torso") human = Tool.Parent:FindFirstChild("Humanoid")--getHumanoid(Tool.Parent) if torso == nil or human == nil then return end human.Jumping:connect(function() onKeyDown("q") end)
mouse.Icon = "rbxasset://textures\\GunCursor.png" mouse.Button1Down:connect(function() onButton1Down(mouse) end) mouse.KeyDown:connect(onKeyDown) end
Tool.Equipped:connect(onEquippedLocal) Tool.Unequipped:connect(function() onKeyDown("q") end)
while true do adjustRope() wait() end
|
|
|
| Report Abuse |
|