• How to properly predict bullets?
    2 replies, posted
A while ago I talked about a turret thing and with some advice, got it to call on both the client and server when you're firing it, opening the doors for prediction. However I'm encountering a problem: the bullets are firing twice. Once on the server, once on the client. If I call it only on the client then it does no damage and the effect only shows up for the shooter, but if I only call it on the server no prediction. Here's the shooty code I'm calling in the Think while ENT.Firing=true [lua] function ENT:DoShot() if self.LastShot+self.ShotInterval<CurTime() then if CLIENT then local effectPosAng=self:GetAttachment(self.MuzzleAttachment) local effectdata = EffectData() effectdata:SetStart( effectPosAng.Pos) effectdata:SetOrigin( effectPosAng.Pos ) effectdata:SetAngles(effectPosAng.Ang) effectdata:SetEntity(self) effectdata:SetScale( 1 ) util.Effect( "MuzzleEffect", effectdata ) elseif SERVER then self:EmitSound(self.ShotSound,50,100) end if IsValid(self.shootPos) then --This is an entity to simulate where the bullets come from self.shootPos:FireBullets({ Num=1, Src=self.shootPos:GetPos()+self.shootPos:GetAngles():Forward()*10, Dir=self.shootPos:GetAngles():Forward()*1, Spread=Vector(0.02,0.02,0), Tracer=0, Force=2, Damage=10, Entity=self.Shooter, Callback=function(attacker,trace,dmginfo) if CLIENT then --This is only called on the shooter's client however, the other clients can't detect that they're shooting (ENT.Firing=false) therefore this is not called local tracerEffect=EffectData() tracerEffect:SetStart(self.shootPos:GetPos()) tracerEffect:SetOrigin(trace.HitPos) tracerEffect:SetScale(6000) util.Effect("AR2Tracer",tracerEffect) end end }) end self.LastShot=CurTime() end end[/lua] If anyone at all could assist here I'd be very grateful. I don't really understand how prediction works.
You should try making 'Firing' a networked boolean or something, and only fire bullets [b]serverside[/b]. also for delaying the shots, you can do this instead (Which makes it easier) [lua]local NextShot = CurTime(); local Delay = 0.25; -- 250 milliseconds if ( CurTime() >= NextShot ) then -- Do shit here NextShot = CurTime() + Delay; end [/lua]
[QUOTE=Walrus Viking;41049752]You should try making 'Firing' a networked boolean or something, and only fire bullets [b]serverside[/b]. also for delaying the shots, you can do this instead (Which makes it easier) [lua]local NextShot = CurTime() local Delay = 0.25 -- 250 milliseconds if ( CurTime() >= NextShot ) then -- Do shit here NextShot = CurTime() + Delay end [/lua][/QUOTE] that won't predict though
Sorry, you need to Log In to post a reply to this thread.