TTT Gun making a constant sound.

It isn’t supposed to be original gun either, but I liked the gun in Saints Row 4, so…

The DUBSTEP GUN! :smiley:

The problem I’m having is getting the gun to do a constant sound while holding down the mouse button, and when released, the sound stops. When the mouse button is pressed again, the music starts at the beginning of the track.

My current shared.lua:

if SERVER then

AddCSLuaFile( “shared.lua” )
end

if CLIENT then
SWEP.PrintName = “DUI3”
SWEP.Slot = 8

SWEP.ViewModelFOV = 72
SWEP.ViewModelFlip = false
end

SWEP.Base = “weapon_tttbase”
SWEP.HoldType = “ar2”

SWEP.Primary.Delay = 0.1
SWEP.Primary.Recoil = 0.0
SWEP.Primary.Automatic = true
SWEP.Primary.Damage = 0
SWEP.Primary.Cone = 0.025
SWEP.Primary.Ammo = “”
SWEP.Primary.ClipSize = 500
SWEP.Primary.ClipMax = 0
SWEP.Primary.DefaultClip = 500
SWEP.Primary.Sound = Sound( “sound/weapons/dubstepgun/dubstepgunmusic.wav” )

SWEP.IronSightPos = Vector( 6.05, -5, 2.4 )
SWEP.IronSightPos = Vector( 2.2, -0.1, 0 )

SWEP.ViewModel = “models/weapons/v_irifle.mdl”
SWEP.WorldModel = “models/weapons/w_irifle.mdl”

SWEP.Kind = WEAPON_EQUIP2

SWEP.AutoSpawnable = false

SWEP.AmmoEnt = “”

SWEP.AllowDrop = true

SWEP.IsSilent = false

SWEP.NoSights = true

if CLIENT then
SWEP.Icon = “VGUI/ttt/icon_windfrontier_dubstep”

SWEP.EquipMenuData = {
type = “Weapon”,
desc = “The DU13, best weapon ever.”
};
end

if SERVER then
resource.AddFile(“materials/VGUI/ttt/icon_windfrontier_dubstep.vmt”)
end

Thanks in advance! :smiley:

[lua]function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end

if ( self.LoopSound ) then
		self.LoopSound = CreateSound( self.Owner, Sound( "sound/weapons/dubstepgun/dubstepgunmusic.wav" )
		if ( self.LoopSound ) then self.LoopSound:Play() end
end

end[/lua]

Try that.

Gave all my players an error. :frowning:

What’s the error?

I couldn’t get it to a bug my server host has, the console goes blank, so I really can’t find it out. Could it be the spaces between the paranthesises?

I doubt it. Can you test it in singleplayer and see for yourself? Currently, my graphics card is broken so I have no way of testing it myself.

You could also ask one of your players what error they’re getting.

My players don’t know either, it all said “Too many lua errors” for them. I’m thinking it could be the !self thing, does it need the ! in there?

Your players can easily look in console after they are kicked to see the lua error.

Also, add sv_kickerrornum 0 to your server.cfg to prevent error kicking.

Do you have an idea of why it is making errors?

No and I won’t until you tell me what it is.

My players checked console and only saw “Too many lua errors!” so, I dunno.

Then put sv_kickerrornum 0 in your server.cfg, and then they can tell you what they see without being kicked.

Error is;

[ERROR] gamemodes/terrortown/entities/weapons/weapon_zm_dubstep/shared.lua:53: ‘)’ expected (to close ‘(’ at line 52) near ‘if’

  1. unknown - gamemodes/terrortown/entities/weapons/weapon_zm_dubstep/shared.lua:0

Paste the code you have in [lua] tags so I can see the line numbers.

Shouldn’t this have a extra paranthesises at the end?
[lua]
self.LoopSound = CreateSound( self.Owner, Sound( “sound/weapons/dubstepgun/dubstepgunmusic.wav” ) )
[/lua]
Like that?

Yea ^, I fixed that error, then it doesn’t play the sound while holding the left mouse button, it’s just silence…

Bump

You have to make sure that the sound file is meant for something that shoots that fast.

I even made my delay like 300, it still didn’t play music while clicking/holding down the mouse button.