• Help, please? Lua Weapon is not playing my sound!
    41 replies, posted
If this is the wrong sub-forum to post in, please let me know where I should post it and I will cut this entire post. In reference to [URL="http://facepunch.com/showthread.php?t=1257110"]this[/URL], I am only asking for help on my code, I am not asking for someone to script the entire thing for me. In reference to [URL="http://facepunch.com/showthread.php?t=1250283"]this[/URL], that is the only reason I posted this here. The wiki can't really help me any more here than it already has. Here is a video of a number of my current weapons, and the weapon I am posting about is included in the mix. Skip to 10:48 if you only want to see this weapon, and my aim sucks anymore, not that that's related... [video=youtube;_hhf7KecKDc]http://www.youtube.com/watch?v=_hhf7KecKDc[/video] Here is all of the code: [lua]if CLIENT then SWEP.PrintName = "Pulse Minigun v0.8.2" SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true SWEP.HoldType = "ar2" language.Add( "HeliCharge_ammo", "R.E. Pulse Core" ) end if SERVER then SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = true SWEP.HoldType = "ar2" end -- TODO! TODO! TODO! GET THE RECHARGE SOUND WORKING!!! TODO! TODO! TODO! -- game.AddAmmoType( { name = "HeliCharge", dmgtype = bit.bor(DMG_AIRBOAT, DMG_ALWAYSGIB), tracer = 4, plydmg = 5, npcdmg = 4, force = 5, minsplash = 3, maxsplash = 4 } ) SWEP.Author = "LuaVirusFree" SWEP.Contact = "5kyl3r469@gmail.com" SWEP.Purpose = "Demonstrate percent display mode. This is the Helicopter's Gun!" SWEP.Instructions = "Primary shoots." SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_irifle.mdl" SWEP.WorldModel = "models/weapons/w_irifle.mdl" SWEP.Primary.ClipSize = 100 SWEP.Primary.DefaultClip = 37 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "HeliCharge" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.HoldType = "ar2" SWEP.ActualAmmo = 105 SWEP.Base = "base_rc" SWEP.Burrets = 2 SWEP.ShotsTaken = 1 SWEP.Primary.Delay = 0.05 SWEP.Spread = 0.20 SWEP.BurretForce = 35 SWEP.DMGMin = 4 SWEP.DMGMax = 5 SWEP.Primary.Recoil = 2.5 SWEP.Tracenum = 1 SWEP.Tracer = "AR2Tracer" SWEP.CanSwitch = false SWEP.NoChamberRound = true SWEP.NoORS = true SWEP.ShootSound = Sound( "Airboat.FireGunHeavy" ) SWEP.EmptySound = Sound( "Weapon_AR2.Empty" ) SWEP.FiringLoop = Sound( "NPC_AttackHelicopter.FireGun" ) SWEP.FiringEnd = Sound( "NPC_AttackHelicopter.ChargeDownGun" ) SWEP.ChargeSound = Sound( "NPC_Strider.Charge" ) SWEP.RechargeSound = Sound( "NPC_AttackHelicopter.ChargeGun" ) SWEP.LSound = nil SWEP.CSound = nil SWEP.RCSound = nil SWEP.Shot1 = false SWEP.DoCrits=false SWEP.CritMax = 6 SWEP.CritVar = 3 SWEP.CritScale = 9 SWEP.ReloadDone = CurTime() SWEP.JustStop = false SWEP.CurClip = 0 SWEP.FirstShot = true SWEP.IsCharging = false SWEP.ChargeStart = CurTime() SWEP.ChargeLVL = 0 function SWEP:Initialize() self.DefaultClipSize = self.Primary.ClipSize self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) self.LSound = CreateSound( self, self.FiringLoop ) self.CSound = CreateSound( self, self.ChargeSound ) self.RCSound = CreateSound( self, self.RechargeSound ) self:SetWeaponHoldType( "ar2" ) end SWEP.Recharging = false SWEP.NextCharge = CurTime() function SWEP:Think() if CurTime() >= self.ReloadDone && !self.FirstShot then self.FirstShot=true end if !self.Owner:KeyDown( IN_ATTACK ) then self.LSound:Stop() end if !self.Owner:KeyDown( IN_ATTACK ) && self.JustStop then self:EmitSound( self.FiringEnd ); self.JustStop = false; self:Reload() end if !self.Owner:KeyDown( IN_ATTACK2 ) then self.CSound:Stop(); self.IsCharging = false end if self.ActualAmmo <= 2 then self:Reload() end if self.ChargeLVL >= 0.8 or CurTime() > (self.ChargeStart+1.2) then self:FireExplosive() end if self.Owner:KeyDown( IN_ATTACK ) then self.Recharging = false end if self.Owner:KeyDown( IN_ATTACK2 ) && self.ActualAmmo >= 105 then self.Recharging = false end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) && self.ActualAmmo < 105 then self:Reload() end if self.Recharging && CurTime() >= self.NextCharge && self.ActualAmmo < 105 then if !self.PlayedSound then self:EmitSound( self.RechargeSound ) self.PlayedSound = true end self.ActualAmmo = self.ActualAmmo + 1 if self.ActualAmmo < 105 then self.NextCharge = CurTime() + 0.02 end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) end if self.ActualAmmo >= 105 then self.Recharging = false; self:StopSound( self.RechargeSound ) end end SWEP.PlayedSound = false function SWEP:Reload() if self.Recharging then return end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) then if !self.Recharging then self.Recharging = true self.NextCharge = CurTime() self.PlayedSound = false self:EmitSound( self.RechargeSound ) end else self.Recharging = falseqq end end function SWEP:PrimaryAttack() if self.Owner:KeyDown( IN_ATTACK2 ) then return end OldClip = self.ActualAmmo self.ActualAmmo = self.ActualAmmo-1 NewClip = self.ActualAmmo if !self:CanPrimaryAttack() then self:EmitSound( self.EmptySound ) self:SetNextPrimaryFire( CurTime()+self.Primary.Delay ) self.LSound:Stop() self:EmitSound( self.FiringEnd ) self.JustStop = false return end self.JustStop = true if self.DoCrits then self.CanCrit = false self.RandChance=math.random(1,self.CritMAX) if self.RandChance==self.CritVar then self.CanCrit = true end end local OldClip = self.ActualAmmo local NewClip = self.ActualAmmo if self.Shot1 then self.Shot1 = false else self.Shot1 = true end local Player = self.Owner if NewClip < OldClip or self.FirstShot then self.LSound:Play(); self.FirstShot = false end local burret = {} burret.Attacker = self.Owner burret.Num = self.Burrets if self.Shot1 then burret.Num = 2 else burret.Num = 3 end burret.Src = self.Owner:GetShootPos() burret.Dir = self.Owner:GetAimVector() burret.Spread = Vector(self.Spread,self.Spread) burret.Hull = 6 burret.Tracer = 1 burret.TracerName = self.Tracer burret.Force = self.BurretForce burret.Damage = math.random(self.DMGMin,self.DMGMax) burret.AmmoType = self.Primary.Ammo if self.DoCrits then if self.CanCrit then burret.Damage = burret.Damage+(self.CritScale*burret.Damage) end end self.Owner:FireBullets( burret ) self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self:SetNextPrimaryFire( CurTime()+self.Primary.Delay ) self:ApplyRecoil(self.Primary.Recoil) if self:Clip1() <= 0 then self:Reload() end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) if self.ActualAmmo <= 0 then self.LSound:Stop() end end function SWEP:SecondaryAttack() -- 1250 damage explosion, take 100% ammo away! if self.Owner:KeyDown( IN_ATTACK ) or self:Clip1() < 100 then return end if !self.IsCharging then self.ChargeStart = CurTime(); self.IsCharging = true; self.CSound:Play() end self.ChargeLVL = (CurTime() - self.ChargeStart)/2 end function SWEP:FireExplosive() if self.IsCharging then self:EmitSound( "npc/env_headcrabcanister/launch.wav", 100, 77 ) self.ChargeLVL = 0 self.ActualAmmo = 0 self:TakePrimaryAmmo(100) self.IsCharging = false local Tr = self.Owner:GetEyeTrace() local TrEnd = Tr.HitPos util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) local EffectD = EffectData() EffectD:SetOrigin(TrEnd) EffectD:SetStart(TrEnd) EffectD:SetMagnitude(500) EffectD:SetNormal( Tr.HitNormal ) EffectD:SetRadius(82) util.Effect( "cball_explode", EffectD, true, true ) util.Effect( "cball_explode", EffectD, true, true ) util.Effect( "cball_explode", EffectD
[QUOTE=luavirusfree;40084575]If this is the wrong sub-forum to post in, please let me know where I should post it and I will cut this entire post. In reference to [URL="http://facepunch.com/showthread.php?t=1257110"]this[/URL], I am only asking for help on my code, I am not asking for someone to script the entire thing for me. In reference to [URL="http://facepunch.com/showthread.php?t=1250283"]this[/URL], that is the only reason I posted this here. The wiki can't really help me any more here than it already has. Here is a video of a number of my current weapons, and the weapon I am posting about is included in the mix. Skip to 10:48 if you only want to see this weapon, and my aim sucks anymore, not that that's related... [video=youtube;_hhf7KecKDc]http://www.youtube.com/watch?v=_hhf7KecKDc[/video] Here is all of the code: [lua]if CLIENT then SWEP.PrintName = "Pulse Minigun v0.8.2" SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true SWEP.HoldType = "ar2" language.Add( "HeliCharge_ammo", "R.E. Pulse Core" ) end if SERVER then SWEP.Weight = 5 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = true SWEP.HoldType = "ar2" end -- TODO! TODO! TODO! GET THE RECHARGE SOUND WORKING!!! TODO! TODO! TODO! -- game.AddAmmoType( { name = "HeliCharge", dmgtype = bit.bor(DMG_AIRBOAT, DMG_ALWAYSGIB), tracer = 4, plydmg = 5, npcdmg = 4, force = 5, minsplash = 3, maxsplash = 4 } ) SWEP.Author = "LuaVirusFree" SWEP.Contact = "5kyl3r469@gmail.com" SWEP.Purpose = "Demonstrate percent display mode. This is the Helicopter's Gun!" SWEP.Instructions = "Primary shoots." SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/weapons/v_irifle.mdl" SWEP.WorldModel = "models/weapons/w_irifle.mdl" SWEP.Primary.ClipSize = 100 SWEP.Primary.DefaultClip = 37 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "HeliCharge" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.HoldType = "ar2" SWEP.ActualAmmo = 105 SWEP.Base = "base_rc" SWEP.Burrets = 2 SWEP.ShotsTaken = 1 SWEP.Primary.Delay = 0.05 SWEP.Spread = 0.20 SWEP.BurretForce = 35 SWEP.DMGMin = 4 SWEP.DMGMax = 5 SWEP.Primary.Recoil = 2.5 SWEP.Tracenum = 1 SWEP.Tracer = "AR2Tracer" SWEP.CanSwitch = false SWEP.NoChamberRound = true SWEP.NoORS = true SWEP.ShootSound = Sound( "Airboat.FireGunHeavy" ) SWEP.EmptySound = Sound( "Weapon_AR2.Empty" ) SWEP.FiringLoop = Sound( "NPC_AttackHelicopter.FireGun" ) SWEP.FiringEnd = Sound( "NPC_AttackHelicopter.ChargeDownGun" ) SWEP.ChargeSound = Sound( "NPC_Strider.Charge" ) SWEP.RechargeSound = Sound( "NPC_AttackHelicopter.ChargeGun" ) SWEP.LSound = nil SWEP.CSound = nil SWEP.RCSound = nil SWEP.Shot1 = false SWEP.DoCrits=false SWEP.CritMax = 6 SWEP.CritVar = 3 SWEP.CritScale = 9 SWEP.ReloadDone = CurTime() SWEP.JustStop = false SWEP.CurClip = 0 SWEP.FirstShot = true SWEP.IsCharging = false SWEP.ChargeStart = CurTime() SWEP.ChargeLVL = 0 function SWEP:Initialize() self.DefaultClipSize = self.Primary.ClipSize self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) self.LSound = CreateSound( self, self.FiringLoop ) self.CSound = CreateSound( self, self.ChargeSound ) self.RCSound = CreateSound( self, self.RechargeSound ) self:SetWeaponHoldType( "ar2" ) end SWEP.Recharging = false SWEP.NextCharge = CurTime() function SWEP:Think() if CurTime() >= self.ReloadDone && !self.FirstShot then self.FirstShot=true end if !self.Owner:KeyDown( IN_ATTACK ) then self.LSound:Stop() end if !self.Owner:KeyDown( IN_ATTACK ) && self.JustStop then self:EmitSound( self.FiringEnd ); self.JustStop = false; self:Reload() end if !self.Owner:KeyDown( IN_ATTACK2 ) then self.CSound:Stop(); self.IsCharging = false end if self.ActualAmmo <= 2 then self:Reload() end if self.ChargeLVL >= 0.8 or CurTime() > (self.ChargeStart+1.2) then self:FireExplosive() end if self.Owner:KeyDown( IN_ATTACK ) then self.Recharging = false end if self.Owner:KeyDown( IN_ATTACK2 ) && self.ActualAmmo >= 105 then self.Recharging = false end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) && self.ActualAmmo < 105 then self:Reload() end if self.Recharging && CurTime() >= self.NextCharge && self.ActualAmmo < 105 then if !self.PlayedSound then self:EmitSound( self.RechargeSound ) self.PlayedSound = true end self.ActualAmmo = self.ActualAmmo + 1 if self.ActualAmmo < 105 then self.NextCharge = CurTime() + 0.02 end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) end if self.ActualAmmo >= 105 then self.Recharging = false; self:StopSound( self.RechargeSound ) end end SWEP.PlayedSound = false function SWEP:Reload() if self.Recharging then return end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) then if !self.Recharging then self.Recharging = true self.NextCharge = CurTime() self.PlayedSound = false self:EmitSound( self.RechargeSound ) end else self.Recharging = falseqq end end function SWEP:PrimaryAttack() if self.Owner:KeyDown( IN_ATTACK2 ) then return end OldClip = self.ActualAmmo self.ActualAmmo = self.ActualAmmo-1 NewClip = self.ActualAmmo if !self:CanPrimaryAttack() then self:EmitSound( self.EmptySound ) self:SetNextPrimaryFire( CurTime()+self.Primary.Delay ) self.LSound:Stop() self:EmitSound( self.FiringEnd ) self.JustStop = false return end self.JustStop = true if self.DoCrits then self.CanCrit = false self.RandChance=math.random(1,self.CritMAX) if self.RandChance==self.CritVar then self.CanCrit = true end end local OldClip = self.ActualAmmo local NewClip = self.ActualAmmo if self.Shot1 then self.Shot1 = false else self.Shot1 = true end local Player = self.Owner if NewClip < OldClip or self.FirstShot then self.LSound:Play(); self.FirstShot = false end local burret = {} burret.Attacker = self.Owner burret.Num = self.Burrets if self.Shot1 then burret.Num = 2 else burret.Num = 3 end burret.Src = self.Owner:GetShootPos() burret.Dir = self.Owner:GetAimVector() burret.Spread = Vector(self.Spread,self.Spread) burret.Hull = 6 burret.Tracer = 1 burret.TracerName = self.Tracer burret.Force = self.BurretForce burret.Damage = math.random(self.DMGMin,self.DMGMax) burret.AmmoType = self.Primary.Ammo if self.DoCrits then if self.CanCrit then burret.Damage = burret.Damage+(self.CritScale*burret.Damage) end end self.Owner:FireBullets( burret ) self:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self:SetNextPrimaryFire( CurTime()+self.Primary.Delay ) self:ApplyRecoil(self.Primary.Recoil) if self:Clip1() <= 0 then self:Reload() end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) if self.ActualAmmo <= 0 then self.LSound:Stop() end end function SWEP:SecondaryAttack() -- 1250 damage explosion, take 100% ammo away! if self.Owner:KeyDown( IN_ATTACK ) or self:Clip1() < 100 then return end if !self.IsCharging then self.ChargeStart = CurTime(); self.IsCharging = true; self.CSound:Play() end self.ChargeLVL = (CurTime() - self.ChargeStart)/2 end function SWEP:FireExplosive() if self.IsCharging then self:EmitSound( "npc/env_headcrabcanister/launch.wav", 100, 77 ) self.ChargeLVL = 0 self.ActualAmmo = 0 self:TakePrimaryAmmo(100) self.IsCharging = false local Tr = self.Owner:GetEyeTrace() local TrEnd = Tr.HitPos util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) util.BlastDamage( self, self.Owner, TrEnd, 82, 420 ) local EffectD = EffectData() EffectD:SetOrigin(TrEnd) EffectD:SetStart(TrEnd) EffectD:SetMagnitude(500) EffectD:SetNormal( Tr.HitNormal ) EffectD:SetRadius(82) util.Effect( "cball_explode", EffectD, true, true ) util.Effect( "cball_explode", EffectD, true, true ) util.Eff
You can use EmitSound() with one argument.
[QUOTE=RetTurtl3;40085898]Hello LuaTheVirus [URL]http://wiki.garrysmod.com/page/Entity/EmitSound[/URL] ent:EmitSound requires 3 arquements, so it should look like this ent:EmitSound("Sound",500, 100) First is sound, second is the pitch, i think your problem is the sound and pitch aren't being called so you cannot hear it.[/QUOTE] No, I tried it. It didn't work. The code you see is without all of the comments of the old code, because this website doesn't code it properly, it thought a lot more was commented than what actually was. I used self:EmitSound( SWEP.RechargeSound ) and when it had to stop, I used self:StopSound( SWEP.RechargeSound ) but it didn't even play at all!! [editline]29th March 2013[/editline] Oh, yeah, and I tried it with all the self:StopSound( SWEP.RechargeSound ) instances commented out, there still wasn't any sound. I wrote print( "It should work" ) to see if it was actually calling the block of code, and it was, but still no sound! I also tried it without variables, just writing in the sound itself. It didn't error out, and I've written other sounds like this before, but there still WAS NO SOUND even though it was being told to EmitSound()!!! The looping firing sound works great! The charging sound for the secondary attack works fine, too! But I can't get the charging sound to work. I had it working with a reload function, but I'd much rather have it charge your ammo. I want the sound to stop when it shouldn't be playing, and that is especially true for the Recharge sound! I should say I have gotten the sound to play with EmitSound(), but it just played at every frame until it was done recharging. I don't want that, it makes it sound nearly silent since the next time it hears that it needs to play that sound from the same entity, it stops the old play and starts a new one. [editline]29th March 2013[/editline] [QUOTE=jaooe;40086042]You can use EmitSound() with one argument.[/QUOTE] Yeah, I know, but it won't categorize it and the sound won't come from the weapon. EmitSound( "sounds/blah.wav" ) doesn't do the same thing as self:EmitSound( "sounds/blah.wav" ) !! [editline]29th March 2013[/editline] Oh, yeah... and if I ever stop talking, the world is a much better place, but in the past I haven't needed the pitch nor the sound level. For all of my other, simpler weapons I don't specify those, and the first time I did it just stopped the sound, the second time I tried it with only pitch and it caused an error. [editline]29th March 2013[/editline] I'm putting this work on hold until I get responses for things I haven't tried, yet. I think I'm going to try for my two-year-long desire, make a swep for the Vectors from Elfen Lied.
[QUOTE=luavirusfree;40088331]No, I tried it. It didn't work. The code you see is without all of the comments of the old code, because this website doesn't code it properly, it thought a lot more was commented than what actually was. I used self:EmitSound( SWEP.RechargeSound ) and when it had to stop, I used self:StopSound( SWEP.RechargeSound ) but it didn't even play at all!! [editline]29th March 2013[/editline] Oh, yeah, and I tried it with all the self:StopSound( SWEP.RechargeSound ) instances commented out, there still wasn't any sound. I wrote print( "It should work" ) to see if it was actually calling the block of code, and it was, but still no sound! I also tried it without variables, just writing in the sound itself. It didn't error out, and I've written other sounds like this before, but there still WAS NO SOUND even though it was being told to EmitSound()!!! The looping firing sound works great! The charging sound for the secondary attack works fine, too! But I can't get the charging sound to work. I had it working with a reload function, but I'd much rather have it charge your ammo. I want the sound to stop when it shouldn't be playing, and that is especially true for the Recharge sound! I should say I have gotten the sound to play with EmitSound(), but it just played at every frame until it was done recharging. I don't want that, it makes it sound nearly silent since the next time it hears that it needs to play that sound from the same entity, it stops the old play and starts a new one. [editline]29th March 2013[/editline] Yeah, I know, but it won't categorize it and the sound won't come from the weapon. EmitSound( "sounds/blah.wav" ) doesn't do the same thing as self:EmitSound( "sounds/blah.wav" ) !! [editline]29th March 2013[/editline] Oh, yeah... and if I ever stop talking, the world is a much better place, but in the past I haven't needed the pitch nor the sound level. For all of my other, simpler weapons I don't specify those, and the first time I did it just stopped the sound, the second time I tried it with only pitch and it caused an error. [editline]29th March 2013[/editline] I'm putting this work on hold until I get responses for things I haven't tried, yet. I think I'm going to try for my two-year-long desire, make a swep for the Vectors from Elfen Lied.[/QUOTE] Tbh, I didn't even read your post cause they're so long so i watched the video and skipped to your weapon and assumed it was a pitch issue. :v:
No, it's not a pitch issue, it just doesn't play. I've gotten it to play before, but you wouldn't hear the whole thing until it was done playing it. Now it just doesn't play at all. I hate people like you, you should know, people who say "Oh, it's too long, didn't read it!" or "tldr" [editline]29th March 2013[/editline] Also, I can get it working perfectly fine with Reload, but I don't like the instant jump from 0% to 100%, I like it to charge just like the Airboat Gun and Helicopter's Gun.
[QUOTE=luavirusfree;40089934]No, it's not a pitch issue, it just doesn't play. I've gotten it to play before, but you wouldn't hear the whole thing until it was done playing it. Now it just doesn't play at all. I hate people like you, you should know, people who say "Oh, it's too long, didn't read it!" or "tldr" [editline]29th March 2013[/editline] Also, I can get it working perfectly fine with Reload, but I don't like the instant jump from 0% to 100%, I like it to charge just like the Airboat Gun and Helicopter's Gun.[/QUOTE] I've figured out your problem now Short code sounds doesn't like to be ran serverside but love being ran clientside [lua] if CLIENT then self:EmitSound( .. code .. ) print("test") end [/lua] And that will work i've tested my self [b]Edited:[/b] I've tested it doesn't run serverside in singleplayer but fine on clientside multiplayer it works on client and serverside
[QUOTE=RetTurtl3;40093529]I've figured out your problem now Short code sounds doesn't like to be ran serverside but love being ran clientside if CLIENT thenself:EmitSound( .. code .. ) print("test")end And that will work i've tested my self [B]Edited:[/B] I've tested it doesn't run serverside in singleplayer but fine on clientside multiplayer it works on client and serverside[/QUOTE] No, that's still not working! [editline]30th March 2013[/editline] It's not even printing test... [editline]30th March 2013[/editline] I'm not sure this needs another thread, by the way, but I don't know how to use Bullet CallBack functions. Is there a page on the wiki, because I can't find it? That is to say, I can't find the help I need, the variables I can use, the variables the callback function takes.
[QUOTE=luavirusfree;40093746]No, that's still not working! [editline]30th March 2013[/editline] It's not even printing test... [editline]30th March 2013[/editline] I'm not sure this needs another thread, by the way, but I don't know how to use Bullet CallBack functions. Is there a page on the wiki, because I can't find it? That is to say, I can't find the help I need, the variables I can use, the variables the callback function takes.[/QUOTE] [lua]AddCSLuaFile()[/lua] at the top of your weapon file when using if CLIENT then derp emd [editline]30th March 2013[/editline] [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7161.html]Bullet CallBack function[/url]
That's not the callback function!! I mean a function used for every single bullet, where I can get hit pos and if I wanted to I could make an explosion at every hit point, or an effect, etc. My weapon shoots two OR three (it alternates) bullets in one shot, so I can't make the AR2Impact effect at the hit position, especially since it doesn't shoot straight... how would I do that? [URL="http://wiki.garrysmod.com/page/Structures/Bullet"]Look here![/URL] In this case, it'd be this: [lua]burret.Callback = function(<Variables>) <Do Effects> end[/lua] [editline]30th March 2013[/editline] Oh, and even with AddCSLuaFile() at the top of the file, it's only one file, shared.lua, it doesn't play the sound!!! Do I have to do AddCSLuaFile( "shared.lua" ) or something?? [editline]30th March 2013[/editline] Another thing is this: If I remove the explosive attack from secondary fire, which fires all bullets at one time in one place causing an explosion, and use secondary fire to re-charge instead, I can get this working fine. I don't want to get rid of the explosive attack, though. I notice that the AirBoat's Gun doesn't play a charging sound, but I would much rather have the charging sound, especially with my plans... oh, and this attack kills GMan and the Antlion Guardian in one hit! (Watch the video starting at 12:10, GMan at 11:50 and Dog at 16:00)
[QUOTE=luavirusfree;40096818]That's not the callback function!! I mean a function used for every single bullet, where I can get hit pos and if I wanted to I could make an explosion at every hit point, or an effect, etc. My weapon shoots two OR three (it alternates) bullets in one shot, so I can't make the AR2Impact effect at the hit position, especially since it doesn't shoot straight... how would I do that? [editline]30th March 2013[/editline] Oh, and even with AddCSLuaFile() at the top of the file, it's only one file, shared.lua, it doesn't play the sound!!! Do I have to do AddCSLuaFile( "shared.lua" ) or something?? [editline]30th March 2013[/editline] Another thing is this: If I remove the explosive attack from secondary fire, which fires all bullets at one time in one place causing an explosion, and use secondary fire to re-charge instead, I can get this working fine. I don't want to get rid of the explosive attack, though. I notice that the AirBoat's Gun doesn't play a charging sound, but I would much rather have the charging sound, especially with my plans... oh, and this attack kills GMan and the Antlion Guardian in one hit! (Watch the video starting at 12:10, GMan at 11:50 and Dog at 16:00)[/QUOTE] Ok let's do it bit by bit Send me your files upload to dropbox, and try [lua]/* -- Disable */[/lua] [lua]function SWEP:Think() if CurTime() >= self.ReloadDone && !self.FirstShot then self.FirstShot=true end if !self.Owner:KeyDown( IN_ATTACK ) then self.LSound:Stop() end if !self.Owner:KeyDown( IN_ATTACK ) && self.JustStop then self:EmitSound( self.FiringEnd ); self.JustStop = false; self:Reload() end if !self.Owner:KeyDown( IN_ATTACK2 ) then self.CSound:Stop(); self.IsCharging = false end if self.ActualAmmo <= 2 then self:Reload() end if self.ChargeLVL >= 0.8 or CurTime() > (self.ChargeStart+1.2) then self:FireExplosive() end if self.Owner:KeyDown( IN_ATTACK ) then self.Recharging = false end if self.Owner:KeyDown( IN_ATTACK2 ) && self.ActualAmmo >= 105 then self.Recharging = false end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) && self.ActualAmmo < 105 then self:Reload() end if self.Recharging && CurTime() >= self.NextCharge && self.ActualAmmo < 105 then if !self.PlayedSound then self:EmitSound( self.RechargeSound ) self.PlayedSound = true end self.ActualAmmo = self.ActualAmmo + 1 if self.ActualAmmo < 105 then self.NextCharge = CurTime() + 0.02 end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) end if self.ActualAmmo >= 105 then self.Recharging = false; self:StopSound( self.RechargeSound ) end end[/lua] Try disabling SWEP:Think() since your coding is weird and let's start with seeing if the sound plays :headache: That means to [lua] /* function SWEP:Think() if CurTime() >= self.ReloadDone && !self.FirstShot then self.FirstShot=true end if !self.Owner:KeyDown( IN_ATTACK ) then self.LSound:Stop() end if !self.Owner:KeyDown( IN_ATTACK ) && self.JustStop then self:EmitSound( self.FiringEnd ); self.JustStop = false; self:Reload() end if !self.Owner:KeyDown( IN_ATTACK2 ) then self.CSound:Stop(); self.IsCharging = false end if self.ActualAmmo <= 2 then self:Reload() end if self.ChargeLVL >= 0.8 or CurTime() > (self.ChargeStart+1.2) then self:FireExplosive() end if self.Owner:KeyDown( IN_ATTACK ) then self.Recharging = false end if self.Owner:KeyDown( IN_ATTACK2 ) && self.ActualAmmo >= 105 then self.Recharging = false end if !self.Owner:KeyDown( bit.bor( IN_ATTACK, IN_ATTACK2 ) ) && self.ActualAmmo < 105 then self:Reload() end if self.Recharging && CurTime() >= self.NextCharge && self.ActualAmmo < 105 then if !self.PlayedSound then self:EmitSound( self.RechargeSound ) self.PlayedSound = true end self.ActualAmmo = self.ActualAmmo + 1 if self.ActualAmmo < 105 then self.NextCharge = CurTime() + 0.02 end self:SetClip1( math.floor( ( self.ActualAmmo / 105 ) * 100 ) ) end if self.ActualAmmo >= 105 then self.Recharging = false; self:StopSound( self.RechargeSound ) end end */[/lua] And see if there is any problem if the sound works then you know it's coming from here :headache:
I need the think function, though! I'm not going to rely on timer.Simple, it isn't as accurate! [editline]30th March 2013[/editline] I already know it works without using think, but I don't want it to instantaneously re-charge to 100% ammo!!! Oh, and my code has changed. I would re-upload but I don't want to have to remove all of the comments again! For an example on how it has changed, the secondary fire now takes six shots to kill a Helicopter rather than 5. Okay, I guess I found what I needed: [quote=wiki.garrysmod.com][B]Additional Notes[/B] The arguments of the callback function are (CTakeDamageInfo dmgInfo, Vector hitPos, Vector direction)[/quote] That still doesn't help me with the sound problem, though. [editline]30th March 2013[/editline] Where is this "Dropbox" and how do I share it?? [URL]http://youtu.be/vBhPCZEWLOE[/URL] It doesn't seem to want to embed it as a video, I just get this: [IMG]http://youtu.be/vBhPCZEWLOE[/IMG] or this [IMG]http://www.youtube.com/watch?v=vBhPCZEWLOE&feature=youtu.be[/IMG]
The weapon still doesn't emit the sound, and I ran into a similar problem when another weapon: the Half-Life 2 shotgun, but where you must use it similarly to the way the NPC's do. When you go to reload it tells it to play self.ReloadSound which is set to Sound( "Weapon_Shotgun.NPC_Reload" ). When you fire, it automatically pumps for you and has to play self.Pump: Sound( "Weapon_Shotgun.Special1" ). These variables are set as such within the start of the file: [lua]SWEP.ShootSound = Sound( "Weapon_Shotgun.NPC_Single" ) SWEP.EmptySound = Sound( "Weapon_Shotgun.Empty" ) SWEP.ReloadSound = Sound( "Weapon_Shotgun.NPC_Reload" ) SWEP.Pump = Sound( "Weapon_Shotgun.Special1" )[/lua] I've even tried making a separate function for playing the pump sound where it doesn't play if you're reloading, but the sound keeps playing when I reload, self.Pump. The only reason I say that's similar is that both problems involve sounds not playing; the reloading sound doesn't play at all! [editline]3rd April 2013[/editline] Oh, and it's kinda funny since I have another working shotgun where you have to manually pump it, and all of its sounds work perfectly fine.
Okay I've read your code and honestly it's a little bit messy. For instance what's the exact point of ActualAmmo? I understand that you want to display your ammo as a percentage, but that also brings a lot more potential issues. For instance your weapon will not work correctly on a multiplayer server at all, because its state will not be consistent between the client and the server, and you will end up displaying a false ammo counter. It also means that the state of your weapon is really hard to predict. You said you made sure that the recharging sound is played, but are you sure nothing causes it to stop right afterwards? Also be careful, some soundscripts (soundscripts are basically sound names that don't end with .wav or .mp3, just in case you didn't know) are set to play on a specific sound channel, and some sound channels can have a maximum number of sounds playing at once. If you don't know where to start, try replacing "NPC_AttackHelicopter.ChargeGun" with "npc/attack_helicopter/aheli_charge_up.wav" and see what happens. Also add prints everywhere to make sure that your weapon isn't doing something it's not supposed to do. It could be trying to stop the reloading sound right after it starts, or playing another sound on top of it, possibly overriding it. Sometimes it's hard to tell just by looking at the code. Also RetTurtl3, no offense but stop helping people please.
ActualAmmo lets me display the ammo as a percent... Let me make up a variable, totalclip = 169. It sets the clip size to (ActualAmmo / totalclip) * 100 to make it display as a percentage. It has to round that, though. I only made it for singleplayer, and I can't test multiplayer anymore... laptop's going to shit. I checked about 43 times to see if there was any code telling it to stop, I can't find any. I even used the search function for some of those checks. I've also gotten the sound to play before, and it wants to play when the only thing you can hear is the birds in construct, or jack shit on flat grass. AND I'VE ALREADY TRIED USING THE RAW NAME, it didn't change a thing except the code! I've done the prints, and the prints work perfectly... as for trying to stop the sound, unless its something written in the source code/garry's code, that's not part of my weapon. If it is, please let me know! Don't be an ass to RetTurtl3! He's probably my only hope... :rolleyes: [editline]4th April 2013[/editline] He, She? I'm not sure which...
[QUOTE=luavirusfree;40156343]ActualAmmo lets me display the ammo as a percent... Let me make up a variable, totalclip = 169. It sets the clip size to (ActualAmmo / totalclip) * 100 to make it display as a percentage. It has to round that, though. I only made it for singleplayer, and I can't test multiplayer anymore... laptop's going to shit. I checked about 43 times to see if there was any code telling it to stop, I can't find any. I even used the search function for some of those checks. I've also gotten the sound to play before, and it wants to play when the only thing you can hear is the birds in construct, or jack shit on flat grass. AND I'VE ALREADY TRIED USING THE RAW NAME, it didn't change a thing except the code! I've done the prints, and the prints work perfectly... as for trying to stop the sound, unless its something written in the source code/garry's code, that's not part of my weapon. If it is, please let me know! Don't be an ass to RetTurtl3! He's probably my only hope... :rolleyes:[/QUOTE] Well then... I don't know. The only weird thing I see in your code is the fact that you're playing the reloading sound twice, but that shouldn't be a problem. Is the code in your first post the most recent one? Could you post your base too? I'll try to debug this myself and see why this screws up, because looking at your code, it really shouldn't. In the meantime, try emitting the sound from self.Owner rather than self. It's not a good way to do it but it's just for testing. If that still doesn't work then the problem definitely comes from your code. If you want to debug it further by yourself, try adding more prints. I know you've already done prints, but have you added a print right before every single EmitSound and StopSound, and every Play/Stop call from sounds created using CreateSound? In those desperate cases you should really consider every possibility.
The reload sound plays twice? No, it isn't the most recent. The actual code has comments that screw up this forum's lua scripting thing, making it think half of the thing is a comment! I play the Recharge Sound twice because I'm just trying to get it to actually play!!! [editline]4th April 2013[/editline] ...once didn't cut it...
[QUOTE=luavirusfree;40160946]The reload sound plays twice? No, it isn't the most recent. The actual code has comments that screw up this forum's lua scripting thing, making it think half of the thing is a comment! I play the Recharge Sound twice because I'm just trying to get it to actually play!!! [editline]4th April 2013[/editline] ...once didn't cut it...[/QUOTE] I've sent you a pm Ps: Don't listen to _Kilburn he'll give you all the wrong answers. As you can see he's dumb from his title + avatar :downs:.
[QUOTE=RetTurtl3;40170178]I've sent you a pm Ps: Don't listen to _Kilburn he'll give you all the wrong answers. As you can see he's dumb from his title + avatar :downs:.[/QUOTE] Funny you say that, but... according to my title I'm dumb, even though I've now found out my brain damage was caused by my friend's idiocy...
[QUOTE=luavirusfree;40170603]Funny you say that, but... according to my title I'm dumb, even though I've now found out my brain damage was caused by my friend's idiocy...[/QUOTE] Listen to the pro's not the con's. :v:
Yeah, and apparently... according to brandonj4 it's dumb of me to listen to evidence... okay, cool, so I guess every legal system in the world is dumb, my parents are dumb... hell, everyone on this planet is dumb. Awesome! That might actually be true, "everyone on this planet is dumb." [editline]5th April 2013[/editline] Would you like me to explain? Okay, [U][highlight]he was[/highlight] being an idiot[/U] [highlight]hanging out the window[/highlight] of my car trying to [highlight]"enjoy himself," a quote from his mouth[/highlight] and deposition. The next thing he knew [highlight]he was laying on the ground in a ditch! I was still in the car[/highlight], but [highlight]that freaked me out[/highlight] and I immediately [highlight]went to turn around[/highlight], which caused my car to [highlight]skid off of the road[/highlight], bounce [highlight]6 feet into the air[/highlight] when it hit some landscaping and slammed into two trees, the second one being [highlight]at least 4 feet thick.[/highlight] I will highlight that which I believe matters.
[QUOTE=luavirusfree;40173047] Would you like me to explain? Okay, [U][highlight]he was[/highlight] being an idiot[/U] [highlight]hanging out the window[/highlight] of my car trying to [highlight]"enjoy himself," a quote from his mouth[/highlight] and deposition. The next thing he knew [highlight]he was laying on the ground in a ditch! I was still in the car[/highlight], but [highlight]that freaked me out[/highlight] and I immediately [highlight]went to turn around[/highlight], which caused my car to [highlight]skid off of the road[/highlight], bounce [highlight]6 feet into the air[/highlight] when it hit some landscaping and slammed into two trees, the second one being [highlight]at least 4 feet thick.[/highlight] I will highlight that which I believe matters.[/QUOTE] Seriously, who the fuck cares?
Just upload the full code of your weapon and its base already. Been waiting since yesterday.
[QUOTE=brandonj4;40174402]Seriously, who the fuck cares?[/QUOTE] Uh, admins? Just because you don't care, that isn't a reason to rate it dumb. Late is better, Useful is a good rating because I'm being a tool/, optimistic is the rating I would give myself just because I look for every opportunity to say it just for the off chance of getting my title changed. [QUOTE=_Kilburn;40174403]Just upload the full code of your weapon and its base already. Been waiting since yesterday.[/QUOTE] I don't want to release it early -_- releasing that much code was already huge leap for me... there are very few people I can trust with the code. [editline]5th April 2013[/editline] Oh, yeah, and this comment is dumb, too, isn't it?
[QUOTE=luavirusfree;40173047]Yeah, and apparently... according to brandonj4 it's dumb of me to listen to evidence... okay, cool, so I guess every legal system in the world is dumb, my parents are dumb... hell, everyone on this planet is dumb. Awesome! That might actually be true, "everyone on this planet is dumb." [editline]5th April 2013[/editline] Would you like me to explain? Okay, [U][highlight]he was[/highlight] being an idiot[/U] [highlight]hanging out the window[/highlight] of my car trying to [highlight]"enjoy himself," a quote from his mouth[/highlight] and deposition. The next thing he knew [highlight]he was laying on the ground in a ditch! I was still in the car[/highlight], but [highlight]that freaked me out[/highlight] and I immediately [highlight]went to turn around[/highlight], which caused my car to [highlight]skid off of the road[/highlight], bounce [highlight]6 feet into the air[/highlight] when it hit some landscaping and slammed into two trees, the second one being [highlight]at least 4 feet thick.[/highlight] I will highlight that which I believe matters.[/QUOTE] Didn't you mention that you were driving drunk/high at 90mph?
I WASN'T HIGH... fuck it. You are now dead to me Ericson666, yes I was driving drunk but I've done that before with no repercussions. The accident only happened because A: The road was shitty, B: He told me "dirt roads are the best roads for speeding", and C: He was fucking around which caused him to fall out of the window, distracting me, making me want to turn around, causing me to turn too fast for the speed and skid. The evidence proves that about 90% of it is his fault, 20% being our drinking and 10% being my drinking, 10% being his. And even that is generous to him, I didn't want to drink but he convinced me to... how did he? that I don't know. 90 is an estimate, the true speed is unknown, no one knows how fast I was going, not even the police. They only estimate that it was a very fast speed, and the road has no posted speed limit. And that's only LOOSELY summing it up... now, yes... there was THC in my blood, but it was a very minute trace amount. Why? Because a couple of months before that day I had smoked, and Marijuana stays in your blood stream for many, many months! Marijuana stays in your body for up to 90 days! It doesn't mean I'm dumb, it means I'm easily persuaded, and even saying that is giving it too much. He has a very sly tongue. Honestly, I've NEVER wanted to drive drunk, and I didn't even want to drink that day. I also wasn't very easily convinced to break my will, but he somehow did it. I don't recall how, though. Why don't I recall? I can't recall because his idiocy caused me traumatic brain damage, wiping weeks of my memories away. Oh, and yeah... I was 17 and I had just gotten the car maybe a month before. The alignment was off, but no one in my family was aware of that. I was fighting to get the car checked out and brought up to pristine health, but my family didn't, and still doesn't, have much money. And anyway you look at it, what I said in the past was only speculation. What I said in that post, and this post, are all true, proven facts! [editline]5th April 2013[/editline] [highlight]But enough of this, please? I didn't bring that to the table to change the topic of this thread, back on topic, please? Thank you.[/highlight]
Does his thread actually have anything to do with lua? If you need our help, we need your scripts; it's as simple as that.
Yes, it does. That's what I feared, and that's why I want the thread to go back to its original topic!!!
[QUOTE=luavirusfree;40176404]Yes, it does. That's what I feared, and that's why I want the thread to go back to its original topic!!![/QUOTE] You're so god damn uncooperative I'm not even sure I should be spending my time trying to help you. No one cares about your personal life, now send me your code already. By private message if you're really so scared of people stealing it. It's not like you're going to risk leaking 2 years worth of hard work.
_Killburn has a point. Nobody lurks around facepunch looking to steal broken code snippets from the help threads. Well, At least i don't. If you do this, please be sure to prove me wrong.
Sorry, you need to Log In to post a reply to this thread.