• I have a great issue in charge-up SWEP.
    8 replies, posted
So... I made a code that makes weapon fire with a delay (Charge-up). It works well besides the fact that i can't see the projectile traces when shooting. Without timed shots traces were visible. [CODE]function SWEP:FireProj() local bullet = {} bullet.Num = self.Primary.NumberofShots bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0) bullet.Tracer = 1 bullet.TracerName = "ToolTracer" bullet.Force = 2 bullet.Damage = 300 bullet.AmmoType = self.Primary.Ammo local rnda = self.Primary.Recoil * -1 local rndb = self.Primary.Recoil * math.random(-0.1, 0.1) util.ScreenShake( self.Owner:GetPos(), 2000, 1, 2, 50 ) self:ShootEffects() self.Owner:FireBullets( bullet ) self:EmitSound( shootsound ) self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) ) self:TakePrimaryAmmo(self.Primary.TakeAmmo) end function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end self:SetNextPrimaryFire( CurTime() + 5 ) self:EmitSound("weapons/cguard/charging.wav") if self.Owner:IsValid() and self.Owner:GetActiveWeapon():GetClass() == "weapon_ion_handheld" then timer.Create( "Chargeup", 1, 1, function() self:FireProj() end ) end end[/CODE]
Using FireBullets in a timer ruins lag compensation which probably screws with the tracer effect. Track the time in a Think hook instead.
[QUOTE=code_gs;50762778]Using FireBullets in a timer ruins lag compensation which probably screws with the tracer effect. Track the time in a Think hook instead.[/QUOTE] is there a possiblity to run it without lag compensation? Timer simple also failed.
[QUOTE=xgdg;50762780]is there a possiblity to run it without lag compensation? Timer simple also failed.[/QUOTE] It uses lag compensation internally. Just use a Think hook to track it -- don't use timers for predicted functions.
[QUOTE=code_gs;50762792]It uses lag compensation internally. Just use a Think hook to track it -- don't use timers for predicted functions.[/QUOTE] Could you give an example?
[QUOTE=xgdg;50762817]Could you give an example?[/QUOTE] [code]function SWEP:Think() if ( self.m_bShouldFire and self.m_flFireTime <= CurTime() ) then self.m_bShouldFire = false self:FireProj() end end function SWEP:PrimaryAttack() -- Stuff self.m_bShouldFire = true self.m_flFireTime = CurTime() + 1 end[/code]
[QUOTE=code_gs;50762926][code]function SWEP:Think() if ( self.m_bShouldFire and self.m_flFireTime <= CurTime() ) then self.m_bShouldFire = false self:FireProj() end end function SWEP:PrimaryAttack() -- Stuff self.m_bShouldFire = true self.m_flFireTime = CurTime() + 1 end[/code][/QUOTE] Now it detected <eof> on empty line ;_;
Post your full code.
[QUOTE=code_gs;50762926][code]function SWEP:Think() if ( self.m_bShouldFire and self.m_flFireTime <= CurTime() ) then self.m_bShouldFire = false self:FireProj() end end function SWEP:PrimaryAttack() -- Stuff self.m_bShouldFire = true self.m_flFireTime = CurTime() + 1 end[/code][/QUOTE] Now it works fine, thanks a lot, scripting hero.
Sorry, you need to Log In to post a reply to this thread.