Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Make RPG move with the mouse [closed]

Asked by 10 years ago

Here are my scripts, plz tell me if u know how to improve them, thnx.

Tool = script.Parent

local arms = nil
local torso = nil
local weld33 = nil -- right arm
local weld55 = nil -- left arm
local welds = {}
local reloading = false

function ReloadSequence() -- this will be a pain in my blocky butt.
wait(.05)
weld33.C1 = CFrame.new(-0.75, -0.8, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
wait(.05)
local mag2 = Instance.new("Part")
mag2.Size = Vector3.new(1,1,1)
mag2.BrickColor = BrickColor.new("Sand green")
mag2.Parent = game.Workspace
local magmesh2 = Instance.new("SpecialMesh")
magmesh2.Scale = Vector3.new(.6,.6,1.6)
magmesh2.MeshType = "Sphere"
magmesh2.Parent = mag2
local magweld = Instance.new("Weld")
leftarm = Tool.Parent["Left Arm"]
magweld.Parent = mag2
magweld.Part0 = mag2
magweld.Part1 = leftarm
magweld.C0 = CFrame.new(-1,0,0.3)
magweld.C0 = magweld.C0 * CFrame.fromEulerAnglesXYZ(0,0.6,1.6)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(260), -1.2, math.rad(-50))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(270), -1, math.rad(-60))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(280), -0.8, math.rad(-70))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), -0.6, math.rad(-80))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), -0.4, math.rad(-90))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), -0.2, math.rad(-90))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.5, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0.2, math.rad(-90))
Tool.Handle.Click:play()
wait(.1)
weld55.C1 = CFrame.new(-0.35, 1.1, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0.2, math.rad(-90))
mag2:remove()
Tool.R1.Transparency = 0
Tool.R2.Transparency = 0
Tool.R3.Transparency = 0
Tool.R4.Transparency = 0
Tool.R5.Transparency = 0
wait(0.3)
weld55.C1 = CFrame.new(-0.35, 1.2, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
weld33.C1 = CFrame.new(-0.75, -0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
end

function Reload()
    if script.Parent.Ammo.Value < script.Parent.MaxAmmo.Value and reloading == false and script.Parent.StoredAmmo.Value >= 1 then
        reloading = true
        script.Parent.Ammo.Value = 0
        Tool.Handle.Reload:play()
        ReloadSequence()
        -- ...
        if script.Parent.StoredAmmo.Value >= script.Parent.MaxAmmo.Value then
            script.Parent.Ammo.Value = script.Parent.MaxAmmo.Value
            script.Parent.StoredAmmo.Value = script.Parent.StoredAmmo.Value - script.Parent.MaxAmmo.Value
            script.Parent.Recoil.Value = 7.5
        elseif script.Parent.StoredAmmo.Value < script.Parent.MaxAmmo.Value and script.Parent.StoredAmmo.Value >= 1 then
            script.Parent.Ammo.Value = script.Parent.StoredAmmo.Value
            script.Parent.StoredAmmo.Value = 0
            script.Parent.Recoil.Value = 7.5
        end
        reloading = false
    end
end

function Equip(mouse)
wait(0.01)
arms = {Tool.Parent:FindFirstChild("Left Arm"), Tool.Parent:FindFirstChild("Right Arm")}
torso = Tool.Parent:FindFirstChild("Torso")
if arms ~= nil and torso ~= nil then
local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
if sh ~= nil then
local yes = true
if yes then
yes = false
sh[1].Part1 = nil
sh[2].Part1 = nil
falsearm1 = arms[1]:clone()
local mesh1 = Instance.new("BlockMesh")
mesh1.Scale = Vector3.new(.9,.9,.9)
mesh1.Parent = falsearm1
local armweld1 = Instance.new("Weld")
falsearm1.BrickColor = BrickColor.new(26)
falsearm1.Parent = Tool
armweld1.Parent = falsearm1
armweld1.Part0 = falsearm1
armweld1.Part1 = arms[1]
falsearm2 = arms[2]:clone()
local mesh2 = Instance.new("BlockMesh")
mesh2.Scale = Vector3.new(.9,.9,.9)
mesh2.Parent = falsearm2
local armweld2 = Instance.new("Weld")
falsearm2.BrickColor = BrickColor.new(26)
falsearm2.Parent = Tool
armweld2.Parent = falsearm2
armweld2.Part0 = falsearm2
armweld2.Part1 = arms[2]
local weld1 = Instance.new("Weld") -- left arm
weld55 = weld1
weld1.Part0 = torso
weld1.Parent = torso
weld1.Part1 = arms[1]
weld1.C1 = CFrame.new(-0.35, 1.2, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
welds[1] = weld1
local weld2 = Instance.new("Weld") -- right arm
weld33 = weld2
weld2.Part0 = torso
weld2.Parent = torso
weld2.Part1 = arms[2]
weld2.C1 = CFrame.new(-0.75, -0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
welds[2] = weld2
end
else
print("sh")
end
else
print("arms")
end
end

local legs = nil
local torso2 = nil
local welds2 = {}
local bodyforce = nil

function Unequip(mouse)
if arms ~= nil and torso ~= nil then
local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
if sh ~= nil then
local yes = true
if yes then
yes = false
sh[1].Part1 = arms[1]
sh[2].Part1 = arms[2]
welds[1].Parent = nil
welds[2].Parent = nil
falsearm1:remove()
falsearm2:remove()
end
else
print("sh")
end
else
print("arms")
end
end

function fire(v)

    Tool.Handle.Fire:play()


    local vCharacter = Tool.Parent
    local vPlayer = game.Players:playerFromCharacter(vCharacter)

    local missile = Instance.new("Part")



    local spawnPos = vCharacter.PrimaryPart.Position



    spawnPos  = spawnPos + (v * 8)

    missile.Position = spawnPos
    missile.Size = Vector3.new(1,1,2)
    missile.Velocity = v * 400
    missile.BrickColor = BrickColor.new(26)
    missile.Shape = 0
    missile.BottomSurface = 0
    missile.TopSurface = 0
    missile.Name = "Grenade"
    missile.Elasticity = 0
    missile.Reflectance = 0
    missile.Friction = 0.9
    Tool.Explosion:clone().Parent = missile
   missile.BrickColor = BrickColor.new("Sand green")
   local force = Instance.new("BodyForce")
    force.force = Vector3.new(0,50,0)
    force.Parent = missile

    local mesh = Instance.new("SpecialMesh")
    mesh.Scale = Vector3.new(.6,.6,.6)
    mesh.MeshType = "Sphere"
    mesh.Parent = missile

    local new_script = script.Parent.GrenadeScript:clone()
    new_script.Disabled = false
    new_script.Parent = missile

    local creator_tag = Instance.new("ObjectValue")
    creator_tag.Value = vPlayer
    creator_tag.Name = "creator"
    creator_tag.Parent = missile



    missile.Parent = game.Workspace

    cam = game.Workspace.CurrentCamera
    local cam_rot = cam.CoordinateFrame - cam.CoordinateFrame.p
    local cam_scroll = (cam.CoordinateFrame.p - cam.Focus.p).magnitude
    local ncf = CFrame.new(cam.Focus.p)*cam_rot*CFrame.fromEulerAnglesXYZ(0.33, 0, 0)
    cam.CoordinateFrame = ncf*CFrame.new(0, 0, cam_scroll)
   weld33.C1 = CFrame.new(-0.75, -0.4, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
    weld55.C1 = CFrame.new(-0.35, 1, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
   Tool.Smoke.Smoke.Enabled = true
   Tool.Smoke1.Smoke.Enabled = true
   Tool.R1.Transparency = 1
   Tool.R2.Transparency = 1
   Tool.R3.Transparency = 1
   Tool.R4.Transparency = 1
   Tool.R5.Transparency = 1
    wait(0.1)
    weld33.C1 = CFrame.new(-0.75, -0.4, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
    weld55.C1 = CFrame.new(-0.35, 1, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
    wait(0.1)
    weld33.C1 = CFrame.new(-0.75, -0.2, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-15), 0)
    weld55.C1 = CFrame.new(-0.35, 1.2, 0.6) * CFrame.fromEulerAnglesXYZ(math.rad(290), 0, math.rad(-90))
   wait(0.1)
   Tool.Smoke.Smoke.Enabled = false
   Tool.Smoke1.Smoke.Enabled = false
end

function KeyDownFunctions(key)
    if key == "r" then
        Reload()
    end
end

Tool.Enabled = true
function onActivated()

    if not Tool.Enabled then
        return
    end

    Tool.Enabled = false

    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end
    local ammo = script.Parent.Ammo
    local maxammo = script.Parent.MaxAmmo
    if reloading == false and humanoid.Health >= 1 then
        if ammo.Value >= 1 then
            ammo.Value = ammo.Value - 1
            local targetPos = humanoid.TargetPoint
            local lookAt = (targetPos - character.Head.Position).unit
            if script.Parent.Recoil.Value < 20 then
                script.Parent.Recoil.Value = script.Parent.Recoil.Value + math.random(5,10)
            end
            fire(lookAt)
        else
            Reload()
        end
    end
    Tool.Enabled = true
end

function onEquippedLocal(mouse)

    if mouse == nil then
        print("Mouse not found")
        return 
    end

    mouse.Icon = "rbxasset://textures\\GunCursor.png"
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
    mouse.KeyDown:connect(KeyDownFunctions)
    while true do
        wait()
        script.Parent.Name = "RPG["..script.Parent.Ammo.Value.."]"
    end
end


Tool.Equipped:connect(onEquippedLocal)


script.Parent.Activated:connect(onActivated)
Tool.Equipped:connect(Equip)
Tool.Unequipped:connect(Unequip)

local Tool = script.Parent
wut = Tool.Parent

function onEquipped(mouse2)
    mouse2.KeyDown:connect(onkeyDown)
    mouse = mouse2
end
function onkeyDown(key) 
    if key == "z" then
    if not a then 
        Tool.Recoil.Value = 5
        Tool.Aim.Value = 0.01
        Tool.ZoomedIn.Value = true
        Tool.Parent.Humanoid.WalkSpeed = 7
        a=true
        Tool.GripPos = Vector3.new(0, -0.1, 0.1)
    wait(0.07)
        Tool.GripPos = Vector3.new(0.1,-0.2,0.75)
    wait(0.07)
        Tool.GripPos = Vector3.new(0.2,-0.35,0.5)
    wait(0.07)
        Tool.GripPos = Vector3.new(0.3,-0.5,0.25)
    else
        Tool.ZoomedIn.Value = false
        Tool.Recoil.Value = 7.5
        Tool.Aim.Value = 15
        Tool.Parent.Humanoid.WalkSpeed = 10
        a=false
        Tool.GripPos = Vector3.new(0.3,-0.5,0.25)
    wait(0.07)
        Tool.GripPos = Vector3.new(0.2,-0.35,0.5)
    wait(0.07)
        Tool.GripPos = Vector3.new(0.1,-0.2,0.75)
    wait(0.07)
        Tool.GripPos = Vector3.new(0, -0.1, 1)
    end
end 
end




script.Parent.Equipped:connect(onEquipped)

Closed as Not Constructive by User#2

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?