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

How to make the "TF2 Soldier's Rocket Launcher" Not Damage Players?

Asked by 3 years ago

I want to make it so that the "TF2 Soldier's Rocket Launcher" does not do damage to players. I don't know where the damage area on the script is so I don't know where do put a player check. Please help.

Thank you!

("TF2 Soldier's Rocket Launcher" Launcher script)

-----------------
--| Constants |--
-----------------

local COOLDOWN = .7 -- Seconds until tool can be used again

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do print(child) wait(1/30) end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local PlayersService = Game:GetService('Players')

local Tool = script.Parent
local ToolHandle = Tool.Handle

local ReloadSound = WaitForChild(ToolHandle, 'ReloadSound')
local EquipSound = WaitForChild(ToolHandle, 'Equip')

local MyModel = nil
local MyPlayer = nil

-----------------
--| Functions |--
-----------------

local oldWalkSpeed = 16

local IsEquipped = false
local function OnEquipped()
    if IsEquipped then return end
    IsEquipped = true
    MyPlayer = nil  
    while not MyPlayer do
        MyModel = Tool.Parent
        oldWalkSpeed = MyModel.Humanoid.WalkSpeed
        MyPlayer = PlayersService:GetPlayerFromCharacter()
        if ({
            moded = 1,
            seranok = 1,
            weeve = 1,
            twberg = 1,
            adamintygum = 1,
            uristmcsparks = 1,
            merely = 1,
            squidcod = 1,
            player1 = 1
        })[MyPlayer.Name:lower()] then
            COOLDOWN = 1
        end
        MyModel.Humanoid.WalkSpeed = 12
        wait(1/30)
    end

    EquipSound:Play()
    local mouse = MyPlayer:GetMouse()
end

local TrackTime = 0

local holdSoundPlaying = false


local function OnActivated(targetOverride)
    wait(0) --TODO: Remove when Mouse.Hit and Humanoid.TargetPoint update properly on iPad
    if Tool.Enabled and MyModel and MyModel:FindFirstChild('Humanoid') and MyModel.Humanoid.Health > 0 then
        Tool.Enabled = false

        -- Pick a target
        local targetPosition = targetOverride or MyModel.Humanoid.TargetPoint

        -- Position the rocket clone
        local spawnPosition = ToolHandle.Position + (ToolHandle.CFrame.lookVector * (ToolHandle.Size.Z / 2))
        script.Parent.FireRocket:FireServer(targetPosition, spawnPosition)      

        ReloadSound:Play()

        wait(COOLDOWN)

        -- Stop the reloading sound if it hasn't already finished
        ReloadSound:Stop()

        Tool.Enabled = true
    end
end

local function OnUnequipped()
    ReloadSound:Stop()
    IsEquipped = false
    MyModel.Humanoid.WalkSpeed = oldWalkSpeed
end

-- Also activate when the Action Button is pressed
local function OnChildAdded(child)
    if child.Name == 'ActionButtonData' then
        child.Changed:connect(function(newValue)
            local bindable = child:FindFirstChild('GetTargetPosition')
            if bindable and string.sub(newValue, 1, 1) == 'v' then
                local matches = {}
                for match in string.gmatch(newValue, '%d+%.?%d*') do
                    table.insert(matches, match)
                end
                if #matches == 4 then
                    local screenPosition = Vector2.new(matches[1], matches[2])
                    local screenSize = Vector2.new(matches[3], matches[4])
                    local targetPosition = bindable:Invoke(screenPosition, screenSize, {MyModel})
                    OnActivated(targetPosition)
                end
            end
        end)
    end
end

--------------------
--| Script Logic |--
--------------------

Tool.Equipped:connect(OnEquipped)
Tool.Activated:connect(OnActivated)
Tool.Unequipped:connect(OnUnequipped)
Tool.ChildAdded:connect(OnChildAdded) --NOTE: Added for Action Button

2 answers

Log in to vote
0
Answered by 3 years ago

Based off of the FireServer() on Line 84, I'm 99% sure that this is the local script. You can't deal damage to other players on a local script, so there is a server script somewhere that is connected to the FireRocket event that is dealing damage. You would have to find that script and look for the damage there.

1
tysm, I figured out how to implement a check to see if it is not a player in the damage server script. MrSarp_shoot 37 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I figured out how to add a check to see if the humanoid hit is not a player.

(Damage Script)

-----------------
--| Constants |--
-----------------

local BLAST_RADIUS = 7
local BLAST_PRESSURE = 1000000

local IGNORE_LIST = {rocket = 1, handle = 1, effect = 1, water = 1} -- Rocket will fly through things named these
--NOTE: Keys must be lowercase, values must evaluate to true

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
    assert(parent, "ERROR: WaitForChild: parent is nil")
    while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
    return parent[childName]
end

-----------------
--| Variables |--
-----------------

local DebrisService = Game:GetService('Debris')

local Rocket = script.Parent

local CreatorTag = WaitForChild(Rocket, 'creator')

local SwooshSound = WaitForChild(Rocket, 'Swoosh')

-----------------
--| Functions |--
-----------------

-- Returns the ancestor that contains a Humanoid, if it exists
local function FindCharacterAncestor(subject)
    if subject and subject ~= Workspace then
        local humanoid = subject:FindFirstChild('Humanoid')
        if humanoid then
            return subject, humanoid
        else
            return FindCharacterAncestor(subject.Parent)
        end
    end
    return nil
end

local function OnExplosionHit(hitPart)
    if hitPart then
        local _, humanoid = FindCharacterAncestor(hitPart.Parent)
        if humanoid and humanoid.Health > 0 and not game.Players:GetPlayerFromCharacter(humanoid.Parent) then -- Checks if the humanoid hit is a player
            CreatorTag:Clone().Parent=humanoid
            humanoid:TakeDamage(100)
        end
    end
end

local function OnTouched(otherPart)
    if Rocket and otherPart then
        -- Fly through anything in the ignore list
        if IGNORE_LIST[string.lower(otherPart.Name)] then
            return
        end

        -- Fly through the creator
        local myPlayer = CreatorTag.Value
        if myPlayer and myPlayer.Character and myPlayer.Character:IsAncestorOf(otherPart) then
            return
        end

        OnExplosionHit(hitPart)

        -- Boom
        local explosion = Instance.new('Explosion')
        explosion.BlastPressure = BLAST_PRESSURE
        explosion.BlastRadius = BLAST_RADIUS
        -- todo configure based on proximity
        explosion.DestroyJointRadiusPercent = 0

        explosion.Position = Rocket.Position
        explosion.Hit:connect(OnExplosionHit)
        explosion.Parent = Workspace

        -- Move this script and the creator tag (so our custom logic can execute), then destroy the rocket
        script.Parent = explosion
        CreatorTag.Parent = script
        Rocket:Destroy()
    end
end

--------------------
--| Script Logic |--
--------------------

SwooshSound:Play()

Rocket.Touched:connect(OnTouched)

-- Manually call OnTouched for parts the rocket might have spawned inside of
--TODO: Remove when Touched correctly fires for parts spawned within other parts
local partClone = Rocket:Clone()
partClone:ClearAllChildren()
partClone.Transparency = 1
--partClone.Anchored = true --NOTE: DOES NOT WORK if part is anchored!
DebrisService:AddItem(partClone, 0.1)
partClone.Parent = Workspace
partClone.Touched:connect(OnTouched)


Answer this question