Code Generator | Lua

Remove Blast Wave and Sound Effects from Katana Code

This guide provides step-by-step instructions to remove sound and visual blast wave effects from a katana's Lua code in a game. It includes identifying sound emit calls, eliminating visual effects, and offers example code modifications.


Empty image or helper icon

Prompt

Hi, I decided to look at the katana code, can you tell me how to remove the visual blast wave and its sound:

if (SERVER) then

    AddCSLuaFile( "shared.lua" )
    SWEP.Weight				= 5
    SWEP.AutoSwitchTo			= false
    SWEP.AutoSwitchFrom		= false

end


SWEP.HoldType = "melee2"

if ( CLIENT ) then
    SWEP.PrintName			= "Катана"
    SWEP.Author				= "Miyabi"
    SWEP.DrawAmmo 			= false
    SWEP.DrawCrosshair 		= false
    SWEP.ViewModelFOV			= 100
    SWEP.ViewModelFlip		= false
    SWEP.CSMuzzleFlashes		= false
    
    SWEP.Slot				= 1
    SWEP.SlotPos			= 1

    killicon.Add("weapon_mad_2b", "HUD/killicons/default", Color( 255, 80, 0, 255 ) )
end


SWEP.Base 						= "weapon_mad_base"

SWEP.Category					= "Nier"

SWEP.UseHands 					= true

SWEP.Spawnable					= true
SWEP.AdminSpawnable				= true

SWEP.ViewModel 					= "models/weapons/c_2b_sword.mdl"
SWEP.WorldModel 				= "models/weapons/w_2b_sword.mdl"

SWEP.Weight						= 5
SWEP.AutoSwitchTo				= false
SWEP.AutoSwitchFrom				= false
SWEP.HoldType = "melee2"

SWEP.Primary.Delay 				= 0.5
SWEP.Primary.Cone				= 0.1
SWEP.Primary.ClipSize			= -1
SWEP.Primary.Damage				= 34
SWEP.Primary.DefaultClip		= -1
SWEP.Primary.Automatic			= true
SWEP.Primary.Ammo				= "none"
SWEP.Primary.Combo				= 0

SWEP.Secondary.ClipSize			= -1
SWEP.Secondary.DefaultClip		= -1
SWEP.Secondary.Damage			= 0	
SWEP.Secondary.Automatic		= true
SWEP.Secondary.Ammo				= "none"
SWEP.Secondary.Combo			= 0

SWEP.Pistol						= true
SWEP.Rifle						= false
SWEP.Shotgun					= false
SWEP.Sniper						= false

SWEP.RunArmOffset 				= Vector(0,2,-2)
SWEP.RunArmAngle 				= Vector(-10,0,5)

SWEP.HoldingPos 				= Vector(0,0,-1)
SWEP.HoldingAng 				= Vector(0,-90,0)

SWEP.MeleeRange					= 110
SWEP.SwingTimeAlt				= 0.45
SWEP.SwingTime 					= 0.2

SWEP.Idling 					= 0
SWEP.Parrying 					= false
SWEP.ParryTime 					= CurTime()
SWEP.SlashTime 					= CurTime()
SWEP.ShootTime					= CurTime()
SWEP.AirDashTime				= CurTime()
SWEP.SprintTime					= CurTime()
SWEP.ComboReset					= CurTime()

SWEP.DroneActive 				= false
SWEP.Drone 						= nil

SWEP.Offset = { --Procedural world model animation, defaulted for CS:S purposes.
    Pos = {
        Up = 1,
        Right = -1,
        Forward = 2
    },
    Ang = {
        Up = 0,
        Right = 0,
        Forward = 0
    },
    Scale = 0.8
}

function SWEP:IdleAnimationDelay( seconds, index )
    timer.Remove( "IdleAnimation" )
    self.Idling = index
    timer.Create( "IdleAnimation", seconds, 1, function()
        if not self:IsValid() or self.Idling == 0 then return end
        if self.Idling == index then
            self.Weapon:SendWeaponAnim(ACT_VM_IDLE)
        end
    end )
end

/*---------------------------------------------------------
   Name: SWEP:Reload()
   Desc: Parry
---------------------------------------------------------*/
function SWEP:Reload()

    if self.Owner:KeyDown(IN_USE) and self.SlashTime < CurTime() then
        if self.Weapon:GetNetworkedBool("Holsted") or self.Weapon:GetDTBool(0) then return end
        
        self.SlashTime = CurTime() + 3
        self.ParryTime = CurTime() + 5
        self.Parrying = true
        
        self.Weapon:SendWeaponAnim(ACT_VM_RECOIL3)
        self.Weapon:EmitSound("", 50, 100)
        
        self.Weapon:SetNextPrimaryFire(CurTime() + 2.7)
        self.Weapon:SetNextSecondaryFire(CurTime() + 2.7)
        
        if SERVER then
            timer.Simple( 2.5, function() 
                if not self:IsValid() or self.Idling == 0 then return end
                self.Parrying = false 
                self.Owner:SetAnimation(PLAYER_ATTACK1)
                self.Weapon:SendWeaponAnim(ACT_VM_HITLEFT)
                self.Owner:GetViewModel():SetPlaybackRate(3)
                self.Weapon:EmitSound("")
                self:Bomb()
            end )
        end
        
        self:IdleAnimationDelay( 3, 3 )
        return
    end
    
end

function SWEP:OnRemove() 
    self:Holster()
    return true
end
function SWEP:OnDrop()
    self:Holster()
    return true
end
function SWEP:Holster()
    self.Idling = 0
    self.Parrying = false
    self.ParryTime = CurTime()
    self.SprintTime = CurTime()
    timer.Remove( "IdleAnimation" )
    
    if self.Drone then
        if self.Drone:IsValid() then
            self.Drone:Remove()
            self.Drone = nil
            self.DroneActive = false
        end
    end
    if self.Owner:IsValid() then
        self.Owner:SetRunSpeed( 500 )
    end
    
    return true
end

-- /*---------------------------------------------------------
--    Name: SWEP:Deploy()
-- ---------------------------------------------------------*/
-- function SWEP:Deploy()
    
-- 	self.Parrying = false
-- 	self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
-- 	self.Weapon:SetNextPrimaryFire(CurTime() + 1)

-- 	self:IdleAnimationDelay( 0.9, -1 )
    
-- 	if SERVER and not self.DroneActive then
-- 		self.Drone = ents.Create("")
-- 		self.Drone:SetOwner( self.Owner )
-- 		self.Drone:SetAngles(self.Owner:EyeAngles())
-- 		local pos = self.Owner:GetShootPos()
-- 			pos = pos + self.Owner:GetForward() * -10
-- 			pos = pos + self.Owner:GetRight() * -25
-- 			pos = pos + self.Owner:GetUp() * 25
-- 		self.Drone:SetPos(pos)
-- 		self.Drone:SetPhysicsAttacker(self.Owner)
-- 		self.Drone:Spawn()
-- 		self.Drone:Activate()
-- 		self.DroneActive = true
-- 	end

-- 	return true
    
-- end

/*---------------------------------------------------------
   Name: SWEP:Think()
   Desc: Called every frame.
---------------------------------------------------------*/
function SWEP:Think()

    if self.ComboReset < CurTime() then
        self.Primary.Combo = 0
        self.Secondary.Combo = 0
    end

    if self.Owner:KeyPressed( IN_SPEED ) then
        self.SprintTime = CurTime()
        self.Owner:EmitSound( "" )
    end
    if self.Owner:KeyDown( IN_SPEED ) then
        if CurTime() - self.SprintTime > 3 then
            self.Owner:SetRunSpeed( 900 )
        elseif CurTime() - self.SprintTime < 0.6 then
            self.Owner:SetRunSpeed( 1300 )
            self.ParryTime = CurTime() + 1
            self.Parrying = true
        else
            self.Owner:SetRunSpeed( 500 )
        end
    else
        self.Owner:SetRunSpeed( 500 )
        self.SprintTime = CurTime()
    end
    
    if not self.Owner:IsOnGround() then
        if self.Owner:KeyPressed( IN_JUMP ) and self.AirDashTime < CurTime() and IsFirstTimePredicted() then
            self.AirDashTime = CurTime() + 0.5
            self.Owner:EmitSound( "" )
            if self.Owner:KeyDown( IN_FORWARD ) then
                self.Owner:SetVelocity( self.Owner:GetAimVector() * 300 + self.Owner:GetUp() * 100 )
            elseif self.Owner:KeyDown( IN_BACK ) then
                self.Owner:SetVelocity( self.Owner:GetAimVector() * -300 + self.Owner:GetUp() * 100 )
            elseif self.Owner:KeyDown( IN_MOVELEFT ) then
                self.Owner:SetVelocity( self.Owner:GetRight() * -300 + self.Owner:GetUp() * 100 )
            elseif self.Owner:KeyDown( IN_MOVERIGHT ) then
                self.Owner:SetVelocity( self.Owner:GetRight() * 300 + self.Owner:GetUp() * 100 )
            else
                self.Owner:SetVelocity( self.Owner:GetUp() * 300 )
            end
        end
    elseif IsFirstTimePredicted() then
        self.AirDashTime = CurTime()
    end

    if self.ParryTime < CurTime() + 0.3 then
        self.Parrying = false
    end

    if self.DroneActive == true and not self.Drone:IsValid() and SERVER then
        self.Drone = ents.Create("")
        self.Drone:SetOwner( self.Owner )
        self.Drone:SetAngles(self.Owner:EyeAngles())
        local pos = self.Owner:GetShootPos()
            pos = pos + self.Owner:GetForward() * -10
            pos = pos + self.Owner:GetRight() * -25
            pos = pos + self.Owner:GetUp() * 25
        self.Drone:SetPos(pos)
        self.Drone:SetPhysicsAttacker(self.Owner)
        self.Drone:Spawn()
        self.Drone:Activate()
    end
    
    self:NextThink(CurTime())
    
end

/*---------------------------------------------------------
Initialize
---------------------------------------------------------*/
function SWEP:Initialize()
    self:SetWeaponHoldType(self.HoldType) 	-- Hold type of the 3rd person animation
end

function SWEP:Parry( target, dmg )
    if target == self.Owner then
        if self.ParryTime > CurTime() then
            
            local damageForce = dmg:GetDamageForce()
            self.Weapon:EmitSound( "" )
            dmg:ScaleDamage( 0 )
            dmg:SetDamageForce( damageForce )
            
        end
    end
end

function Reflect(target, dmg)

    if !target:IsValid() or !target:IsPlayer() then return end
    
    local Wep = target:GetActiveWeapon()
    if !IsValid( Wep ) then return end
    if !Wep:IsWeapon() then return end
    if !Wep.MadCow then return end
    if Wep:GetClass() != "weapon_mad_2b" then return end
    
    if dmg:GetDamageType() == DMG_FALL then
        dmg:SetDamage( 0 )
        return
    end
    
    Wep:Parry( target, dmg )

end
hook.Add( "EntityTakeDamage", "2bReflect", Reflect );

/*---------------------------------------------------------
   Name: SWEP:PrimaryAttack()
   Desc: +attack1 has been pressed.
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
    
    if not IsFirstTimePredicted() then return end
    
    // Holst/Deploy your fucking weapon
    if (not self.Owner:IsNPC() and self.Owner:KeyDown(IN_USE)) then
        bHolsted = !self.Weapon:GetDTBool(0)
        self:SetHolsted(bHolsted)

        self.Weapon:SetNextPrimaryFire(CurTime() + 0.3)
        self.Weapon:SetNextSecondaryFire(CurTime() + 0.3)

        self:SetIronsights(false)

        return
    end
    
    self.ParryTime = CurTime()
    
    if self.Weapon:GetNetworkedBool("Holsted") or self.Owner:KeyDown(IN_SPEED) or self.Weapon:GetDTBool(0) then return end

    self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay + self.SwingTime - 0.05)
    self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay + self.SwingTime - 0.05)
    self.ComboReset = CurTime() + self.Primary.Delay + self.SwingTime + 0.65
    self.Owner:SetAnimation(PLAYER_ATTACK1)
    
    local ani = math.random( 1, 3 )
    if ani == 1 or self.Primary.Combo == 4 then
        self.Weapon:SendWeaponAnim(ACT_VM_HITLEFT)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    elseif ani == 2 then
        self.Weapon:SendWeaponAnim(ACT_VM_HITRIGHT)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    else 
        self.Weapon:SendWeaponAnim(ACT_VM_PULLBACK)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    end
    
    timer.Simple( self.SwingTime, function()

        local hitted = false
        self.Primary.Combo = self.Primary.Combo + 1
        
        if not self:IsValid() or self.Idling == 0 then return end
        self.ParryTime = CurTime()
        self.Parrying = false
        
        self.Weapon:EmitSound("")

        local ents = ents.FindInSphere(self.Owner:GetPos(), self.MeleeRange)

        local dmginfo = DamageInfo()
            dmginfo:SetAttacker( self.Owner )
            dmginfo:SetInflictor( self )
        
        if self.Primary.Combo < 5 then
            for k, v in pairs(ents) do
                if v ~= self and v ~= self.Owner and IsValid(v) and self:EntityFaceFront( v, 35 ) and self.Owner:GetPos() ~= v:GetPos() then
                    if self:EntityFaceBack(v) then
                        dmginfo:SetDamage( 235 + self.Primary.Combo * 15 )
                    else 
                        dmginfo:SetDamage( 100 + self.Primary.Combo * 10 )
                    end
                    --self.Weapon:EmitSound("")
                    hitted = true
                    dmginfo:SetDamageForce( ( v:GetPos() - self.Owner:GetPos() ):GetNormalized() * 50000 )
                    if SERVER then
                        v:TakeDamageInfo( dmginfo )
                    end
                    if v:GetPhysicsObject():IsValid() and not string.find(v:GetClass(), "") then
                        v:GetPhysicsObject():ApplyForceCenter( ( v:GetPos() - self.Owner:GetPos() ):GetNormalized() * 50000 )
                    end
                end
            end
        else
            self.Weapon:EmitSound("")
            self:RushFiveBomb()
            self.Primary.Combo = 0
            self.Secondary.Combo = 0
        end
        
        self.Secondary.Combo = 0
        
        local trace = util.TraceLine( {
            start = self.Owner:GetShootPos(),
            endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * self.MeleeRange,
            filter = self.Owner
        } )
        trace.mask = MASK_SHOT
        if (trace.Hit) then
            hitted = true
            if trace.Entity:GetClass() == "func_door_rotating" or trace.Entity:GetClass() == "prop_door_rotating" then
            elseif trace.Entity:IsNPC() or trace.Entity:IsPlayer() then
            else
                bullet = {}
                bullet.Num    = 1
                bullet.Src    = self.Owner:GetShootPos()
                bullet.Dir    = self.Owner:GetAimVector()
                bullet.Spread = Vector(0, 0, 0)
                bullet.Tracer = 0
                bullet.Force  = 0
                bullet.Damage = 25
                bullet.AmmoType = "357"
                self.Owner:FireBullets(bullet)
                --self.Weapon:EmitSound("")
            end
        end

        if hitted then
            self.Weapon:EmitSound("")
        end
        
        if ((game.SinglePlayer() and SERVER) or CLIENT) then
            self.Weapon:SetNetworkedFloat("LastShootTime", CurTime())
        end

        self:IdleAnimationDelay( 0.3, 1 )
    
    end)
    
end

Answer

Removing Visual Blast Wave and Sound from the Katana Code

This guide will walk you through the process of removing the visual blast wave and its sound effects from the existing Lua code for a katana in a game environment.

Identifying the Sound and Visual Effects

  1. Locate Sound Emit Calls: Search for lines where sound is emitted, primarily using self.Weapon:EmitSound("").
  2. Identify Visual Effects: Look for any references that may be creating visual effects, such as particle systems or sprites tied to the weapon's actions.

Modifications Required

Step 1: Remove the Sound Effects

You'll need to find all occurrences of the EmitSound function and remove or comment them out. For example:

self.Weapon:EmitSound("someSoundName") -- Remove or comment this line

Step 2: Eliminate Visual Blast Wave Effects

Visual effects are often created using specific functions like creating particles. In this scenario, we do not have direct code for a blast wave; however, you might find it near the weapon's attack logic. If there’s a particle effect tied to the weapon, you should either remove it or disable it.

In the provided code, ensure there are no functions that instantiate visual effects for the katana.

Example Changes

Below is a modified version of the relevant parts of the original code that removes the sound and any visual effects associated with the weapon.

function SWEP:PrimaryAttack()
    if not IsFirstTimePredicted() then return end

    -- Check for holst/deploy
    if (not self.Owner:IsNPC() and self.Owner:KeyDown(IN_USE)) then
        bHolsted = not self.Weapon:GetDTBool(0)
        self:SetHolsted(bHolsted)

        self.Weapon:SetNextPrimaryFire(CurTime() + 0.3)
        self.Weapon:SetNextSecondaryFire(CurTime() + 0.3)

        self:SetIronsights(false)
        return
    end
    
    self.ParryTime = CurTime()
    
    -- Prevent actions when holsted or in speed
    if self.Weapon:GetNetworkedBool("Holsted") or self.Owner:KeyDown(IN_SPEED) then return end

    self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay + self.SwingTime - 0.05)
    self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay + self.SwingTime - 0.05)
    self.ComboReset = CurTime() + self.Primary.Delay + self.SwingTime + 0.65
    self.Owner:SetAnimation(PLAYER_ATTACK1)

    local ani = math.random(1, 3)
    if ani == 1 or self.Primary.Combo == 4 then
        self.Weapon:SendWeaponAnim(ACT_VM_HITLEFT)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    elseif ani == 2 then
        self.Weapon:SendWeaponAnim(ACT_VM_HITRIGHT)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    else 
        self.Weapon:SendWeaponAnim(ACT_VM_PULLBACK)
        self.Owner:GetViewModel():SetPlaybackRate(1.25)
    end
    
    timer.Simple(self.SwingTime, function()
        local hitted = false
        self.Primary.Combo = self.Primary.Combo + 1
        
        if not self:IsValid() or self.Idling == 0 then return end
        self.ParryTime = CurTime()
        self.Parrying = false

        -- Remove sound emission
        -- self.Weapon:EmitSound("") -- Line Removed

        local ents = ents.FindInSphere(self.Owner:GetPos(), self.MeleeRange)
        local dmginfo = DamageInfo()
        dmginfo:SetAttacker(self.Owner)
        dmginfo:SetInflictor(self)

        -- Optional: Check for hits and apply damage
        if self.Primary.Combo < 5 then
            for k, v in pairs(ents) do
                -- Existing logic for handling hits
            end
        else
            -- Logic for handling "rush" effect
        end

        -- Check for traces and apply damage
        -- Existing trace logic without sound emission

        if hitted then
            -- self.Weapon:EmitSound("") -- Line Removed
        end
        
        self:IdleAnimationDelay(0.3, 1)
    end)
end

Conclusion

By following these steps, you will successfully remove the sound effects and any potential visual blast wave associated with the katana weapon in the game. Always ensure to test your changes thoroughly in the game environment to confirm the absence of the unwanted effects.

Additional Resources

For further advanced practices in weapon coding and design, consider exploring courses available on the Enterprise DNA Platform, which focuses on data analysis and programming tutorials tailored for developers.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This guide provides step-by-step instructions to remove sound and visual blast wave effects from a katana's Lua code in a game. It includes identifying sound emit calls, eliminating visual effects, and offers example code modifications.