• Broken swep-odd unchangeable cone
    11 replies, posted
Hello, i've been trying to fix this old Swep from Gmod in 2010 for about an hour and a half now and i've hit a bump Everthing else on this swep is perfectly functional except for the spread! Normally i would think this is just a simple change a number and done type deal but it seems to be something more complex then that. [code] SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Primary.Empty = Sound( "Weapon_Shotgun.Empty" ) SWEP.Primary.Reload = Sound( "Weapon_Shotgun.Reload" ) SWEP.Primary.ReloadNPC = Sound( "Weapon_Shotgun.NPC_Reload" ) SWEP.Primary.Special1 = Sound( "Weapon_Shotgun.Special1" ) SWEP.Primary.Sound = Sound( "Weapon_Shotgun.Single" ) SWEP.Primary.SoundNPC = Sound( "Weapon_Shotgun.NPC_Single" ) SWEP.Primary.Damage = 8 SWEP.Primary.NumShots = 7 SWEP.Primary.NumAmmo = 1 SWEP.Primary.Cone = VECTOR_CONE_10DEGREES SWEP.Primary.ClipSize = 6 // Size of a clip SWEP.Primary.Delay = 0.7 SWEP.Primary.DefaultClip = 6 // Default number of bullets in a clip SWEP.Primary.Automatic = true // Automatic/Semi Auto SWEP.Primary.Ammo = "Buckshot" SWEP.Primary.Tracer = 4 SWEP.Primary.TracerName = "Tracer" SWEP.Secondary.Sound = Sound( "Weapon_Shotgun.Double" ) SWEP.Secondary.Damage = 8 SWEP.Secondary.NumShots = 12 SWEP.Secondary.NumAmmo = 2 SWEP.Secondary.ClipSize = -1 // Size of a clip SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip SWEP.Secondary.Automatic = true // Automatic/Semi Auto SWEP.Secondary.Ammo = "None" function SWEP:GetBulletSpread() local cone = self.Primary.Cone; return cone; end [/code] This is the original part i suspect of being behind it all, i decided to try changing the Swep primary cone but it doesn't have any affect on it what so ever. [code] SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Primary.Empty = Sound( "Weapon_Shotgun.Empty" ) SWEP.Primary.Reload = Sound( "Weapon_Shotgun.Reload" ) SWEP.Primary.ReloadNPC = Sound( "Weapon_Shotgun.NPC_Reload" ) SWEP.Primary.Special1 = Sound( "Weapon_Shotgun.Special1" ) SWEP.Primary.Sound = Sound( "Weapon_Shotgun.Single" ) SWEP.Primary.SoundNPC = Sound( "Weapon_Shotgun.NPC_Single" ) SWEP.Primary.Damage = 8 SWEP.Primary.NumShots = 7 SWEP.Primary.NumAmmo = 1 SWEP.Primary.Cone = 8 <---- This is what i changed SWEP.Primary.ClipSize = 6 // Size of a clip SWEP.Primary.Delay = 0.7 SWEP.Primary.DefaultClip = 6 // Default number of bullets in a clip SWEP.Primary.Automatic = true // Automatic/Semi Auto SWEP.Primary.Ammo = "Buckshot" SWEP.Primary.Tracer = 4 SWEP.Primary.TracerName = "Tracer" SWEP.Secondary.Sound = Sound( "Weapon_Shotgun.Double" ) SWEP.Secondary.Damage = 8 SWEP.Secondary.NumShots = 12 SWEP.Secondary.NumAmmo = 2 SWEP.Secondary.ClipSize = -1 // Size of a clip SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip SWEP.Secondary.Automatic = true // Automatic/Semi Auto SWEP.Secondary.Ammo = "None" function SWEP:GetBulletSpread() local cone = self.Primary.Cone; return cone; end [/code] Above here is what i had changed but it didn't change anything, This function to get the bullet spread is used in the secondary fire on this shotgun as well so that's why i so firmly believe it's something here. But i'm not exactly sure. Any help of any sort would be greatly appreciated, i'm willing to post other parts of the code (or all of it) if no one else can help me figure it out based on what i've given.
I'm guessing the cone should be a vector. Look at how the primary attack method uses GetBulletSpread.
[QUOTE=code_gs;50705553]I'm guessing the cone should be a vector. Look at how the primary attack method uses GetBulletSpread.[/QUOTE] Isn't it already a vector though? forgive me if i'm wrong i'm rather new to lua. More of a C++ person myself but i really really want to fix this.
[QUOTE=GLf20;50705578]Isn't it already a vector though? forgive me if i'm wrong i'm rather new to lua. More of a C++ person myself but i really really want to fix this.[/QUOTE] Sorry, thought your second code snippet was the new one. Can you post the base code so we can see how VECTOR_CONE_10DEGREES is defined and how the cone is used?
Facepunch won't let me post all of it, here the primary fire part [code] function SWEP:PrimaryAttack() local pOwner = self.Owner; if (!pOwner) then return; end // Make sure we can shoot first if ( !self:CanPrimaryAttack() ) then return end if (self.m_bNeedPump) then return; end self.m_bDelayedFire1 = false; if ( (self.Weapon:Clip1() <= 0 && self.Primary.ClipSize > -1) || ( self.Primary.ClipSize <= -1 && pOwner:GetAmmoCount(self.Primary.Ammo) <= 0 ) ) then if (pOwner:GetAmmoCount(self.Primary.Ammo) <= 0) then self:DryFire(); return; else self:StartReload(); return; end // Fire underwater? elseif (pOwner:WaterLevel() == 3 && self.m_bFiresUnderwater == false) then self.Weapon:EmitSound(self.Primary.Empty); self.Weapon:SetNextPrimaryFire( CurTime() + 0.2 ); self.Weapon:SetNextSecondaryFire( CurTime() + 0.2 ); self.m_flNextPrimaryAttack = CurTime() + 0.2; return; else // If the firing button was just pressed, reset the firing time local pPlayer = self.Owner; if ( !pPlayer:IsNPC() ) then if ( pPlayer && pPlayer:KeyPressed( IN_ATTACK ) ) then self.Weapon:SetNextPrimaryFire( CurTime() ); self.Weapon:SetNextSecondaryFire( CurTime() ); self.m_flNextPrimaryAttack = CurTime(); end end end [/code]
I don't see where any shooting is actually taking place. Post any functions that use GetBulletSpread or FireBullets.
[QUOTE=code_gs;50705833]I don't see where any shooting is actually taking place. Post any functions that use GetBulletSpread or FireBullets.[/QUOTE] So sorry, Please forgive my "noobieness" if that can even been counted as a word [code] function SWEP:ShootBullet( damage, num_bullets, aimcone ) // Only the player fires this way so we can cast local pPlayer = self.Owner; if ( !pPlayer ) then return; end local vecSrc = pPlayer:GetShootPos(); local vecAiming = pPlayer:GetAimVector(); local info = { Num = num_bullets, Src = vecSrc, Dir = vecAiming, Spread = aimcone, Tracer = self.Primary.Tracer, Damage = damage }; info.Attacker = pPlayer; info.TracerName = self.Primary.TracerName; info.Owner = self.Owner info.Weapon = self.Weapon info.ShootCallback = self.ShootCallback; info.Callback = function( attacker, trace, dmginfo ) return info:ShootCallback( attacker, trace, dmginfo ); end // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer:FireBullets( info ); end [/code] Here you go.
Now post what calls SWEP:ShootBullet. The arg aimcone should equate to a vector and is being used correctly in the function you posted.
[QUOTE=code_gs;50705882]Now post what calls SWEP:ShootBullet. The arg aimcone should equate to a vector and is being used correctly in the function you posted.[/QUOTE] It's strange it's called right above it [code] function SWEP:Deploy() self.Weapon:SendWeaponAnim( ACT_VM_DRAW ) self:SetDeploySpeed( self.Weapon:SequenceDuration() ) return true end /*--------------------------------------------------------- Name: SWEP:ShootBullet( ) Desc: A convenience function to shoot bullets ---------------------------------------------------------*/ function SWEP:ShootBullet( damage, num_bullets, aimcone ) // Only the player fires this way so we can cast local pPlayer = self.Owner; if ( !pPlayer ) then return; end local vecSrc = pPlayer:GetShootPos(); local vecAiming = pPlayer:GetAimVector(); local info = { Num = num_bullets, Src = vecSrc, Dir = vecAiming, Spread = aimcone, Tracer = self.Primary.Tracer, Damage = damage }; info.Attacker = pPlayer; info.TracerName = self.Primary.TracerName; info.Owner = self.Owner info.Weapon = self.Weapon info.ShootCallback = self.ShootCallback; info.Callback = function( attacker, trace, dmginfo ) return info:ShootCallback( attacker, trace, dmginfo ); end // Fire the bullets, and force the first shot to be perfectly accuracy pPlayer:FireBullets( info ); end [/code] Thats the only part that uses SWEP:ShootBullet in all of it. If you'd like to look at the whole thing yourself and not wait for me its here at this google link [url]https://code.google.com/archive/p/swep-bases/downloads[/url] i'm afraid it may be hopeless effort for me i've gone through this at least 3 or 4 times and trying several things only to get no where just promise me that if you figure out the fix for the shotgun you'll post it please. i really really really want to get this to work.
self:ShootBullet( self.Primary.Damage, self.Primary.NumShots, self:GetBulletSpread() ) That's in the shotgun's primary attack. Redefine SWEP.Primary.Cone to Vector( 0.08716, 0.08716, 0.08716 ); that's equivalent to VECTOR_CONE_10DEGREES.
Wow. Thank you! Can i ask how you know that Vector_cone_10degrees is equal to 0.08716? i'd like to know.
Cones are represented by sin(degrees / 2), and FireBullets will shoot the bullet at any ray in that cone radius using Gaussian distribution.
Sorry, you need to Log In to post a reply to this thread.