• Weapon Prediction
    3 replies, posted
I'm trying to make my 3-shot burst weapon properly predict but nothing seems to work. [lua] function SWEP:PrimaryAttack() if not self.Weapon:CanPrimaryAttack() then return end if self.Weapon:GetNWInt( "ShotNum", 1 ) < 3 then self.Weapon:SetNWInt( "ShotNum", self.Weapon:GetNWInt( "ShotNum", 1 ) + 1 ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Burst ) else self.Weapon:SetNWInt( "ShotNum", 1 ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) end self.Weapon:ShootBullets( self.Primary.Damage, self.Primary.NumShots, self.Primary.Cone ) self.Weapon:TakePrimaryAmmo( 1 ) if IsFirstTimePredicted() then self.Weapon:EmitSound( self.Primary.Sound, 100, math.random(95,105) ) if SERVER then local scale = 0.50 if self.Owner:KeyDown( IN_DUCK ) then scale = 0.25 elseif self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) or self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) then scale = 0.60 end local pang, yang = math.Rand( -1 * scale, 0 ) * self.Primary.Recoil, math.Rand( -1 * ( scale / 3 ), ( scale / 3 ) ) * self.Primary.Recoil self.Owner:ViewPunch( Angle( pang, yang, 0 ) ) self.Owner:AddAmmo( -1 ) timer.Simple( math.Rand( 0.4, 0.6 ), function() if IsValid( self ) then sound.Play( table.Random( self.ShellSounds[ self.ShellType ].Wavs ), self.Owner:GetPos(), 75, self.ShellSounds[ self.ShellType ].Pitch + math.random( -5, 5 ) ) end end ) end end end function SWEP:Holster() return self.Weapon:GetNWInt( "ShotNum", 1 ) == 1 end function SWEP:Think() if self.Weapon:GetNextPrimaryFire() < CurTime() and self.Weapon:GetNWInt( "ShotNum", 1 ) < 3 and self.Weapon:GetNWInt( "ShotNum", 1 ) != 1 then self.Weapon:PrimaryAttack() end end[/lua] What would be the proper way to do this?
On the server, call [lua] self.Owner:LagCompensation( true ) self:FireBullets( bullet ) self.Owner:LagCompensation( false ) [/lua] However this can be iffy and print the occasional error (and in GM12 under the wrong circumstances, it could cause a notable jolt of lag). The only other method I know to enforce some form of prediction is on is to have mp_friendlyfire set to 1 (and then use the appropriate hooks to control FF behaviour).
You're supposed to make the player shoot the bullets. Players shooting bullets are automatically lag compensated so you don't manually do Entity.LagCompensation. self.Owner:ShootBullets(bullet) It's that simple.
That's just a convenience function i made. [lua] function SWEP:ShootBullets( damage, numbullets, aimcone ) self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Owner:MuzzleFlash() self.Owner:SetAnimation( PLAYER_ATTACK1 ) local scale = aimcone if self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) or self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) then scale = aimcone * 1.25 elseif self.Owner:KeyDown( IN_DUCK ) then scale = aimcone * 0.5 end local bullet = {} bullet.Num = numbullets bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector( scale, scale, 0 ) bullet.Tracer = 0 bullet.Force = math.Round( damage * 1.5 ) bullet.Damage = damage bullet.AmmoType = "Pistol" bullet.TracerName = "Tracer" bullet.Callback = function ( attacker, tr, dmginfo ) self:BulletCallback( attacker, tr, dmginfo, 0 ) end self.Owner:FireBullets( bullet ) end[/lua] I got tired of fucking with prediction so i just did a hacky workaround and made the weapon fire all 3 bullets at once, then play an extra fire animation and make an additional sound a few milliseconds later. You can't really notice that all the bullets are firing at once since the burst delay is so low.
Sorry, you need to Log In to post a reply to this thread.