OK, so I have a swep that spawns bullets that fly and kill stuff. It works perfectly in single player and gives no errors in single player or multi player. In multi player, though, it has a long delay (about .15 seconds) between initiating the primary fire function and actually spawning the bullet. The delay doesn't depend on ping; it's constant no matter how laggy you are. Here is the spawning code;
function SWEP:PrimaryAttack()
if self:CanPrimaryAttack() then
self:FireRocket()
self.Weapon:EmitSound("AK5F.single")
self.Weapon:TakePrimaryAmmo(1)
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
local fx = EffectData()
fx:SetEntity(self.Weapon)
fx:SetOrigin(self.Owner:GetShootPos())
fx:SetNormal(self.Owner:GetAimVector())
fx:SetAttachment(self.MuzzleAttachment)
util.Effect("gdcw_muzzle",fx)
util.Effect("gdcw_shells",fx)
self.Owner:SetAnimation( PLAYER_ATTACK1 )
if self:Clip1() == 0 then
self:Reload()
end
else
self.Weapon:EmitSound("Buttons.snd14")
end
self.Weapon:SetNextPrimaryFire(CurTime()+self.Primary.Delay)
end
function SWEP:FireRocket()
local anglo = Angle(math.Rand(-0.3,0.3), math.Rand(-0.3,0.3), 0)
local aim = self.Owner:GetAimVector()
local side = aim:Cross(Vector(0,0,1))
local up = side:Cross(aim)
local pos = self.Owner:GetShootPos() + aim * 30 + side * 3 + up * -1 --offsets the rocket so it spawns from the muzzle (hopefully)
if SERVER then
local rocket = ents.Create("gdcwa_5.56x45_fast")
if !rocket:IsValid() then return false end
rocket:SetAngles(aim:Angle()+Angle(90,0,0))
rocket:SetPos(pos)
rocket:SetOwner(self.Owner)
rocket:Spawn()
rocket:Activate()
end
if !self.Owner:IsNPC() then
self.Owner:ViewPunch(anglo)
local eyeang = self.Owner:EyeAngles() - anglo
self.Owner:SetEyeAngles(eyeang)
end
end
I don't see any reason why the bullets don't spawn on the first tick after initiating like they do in single player. Can anybody help? Thanks!
Weird.. :/ I am not a god of lua, but the fire rocket function is called by the primaryAttack(), so it should work. And it does workin singleplayer, but not in multyplayer.. Realy weird.
Use [noparse][lua][/lua][/noparse] tags to hold your code.
The problem is probably in the "gdcwa_5.56x45_fast" entity. Please post its code too.
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
math.randomseed(CurTime())
self.Owner = self.Entity:GetVar("owner",Entity(1))
self.exploded = false
self.armed = true
self.ticking = true
self.smoking = false
self.penetrate = 12
self.flightvector = self.Entity:GetUp() * 600
self.timeleft = CurTime() + 5
self.Entity:SetModel( "models/led.mdl" )
self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
self.Entity:SetMoveType( MOVETYPE_NONE ) --after all, gmod is a physics
self.Entity:SetSolid( SOLID_VPHYSICS ) -- CHEESECAKE! >:3
self:Think()
end
function ENT:Think()
if (self.smoking == false) then
self.smoking = true
FireTrail = ents.Create("env_spritetrail")
FireTrail:SetKeyValue("lifetime","0.10")
FireTrail:SetKeyValue("startwidth","20")
FireTrail:SetKeyValue("endwidth","0")
FireTrail:SetKeyValue("spritename","trails/laser.vmt")
FireTrail:SetKeyValue("rendermode","5")
FireTrail:SetKeyValue("rendercolor","255 150 100")
FireTrail:SetPos(self.Entity:GetPos())
FireTrail:SetParent(self.Entity)
FireTrail:Spawn()
FireTrail:Activate()
end
if self.timeleft < CurTime() then
self.exploded = true
self.Entity:Remove()
end
local trace = {}
trace.start = self.Entity:GetPos()
trace.endpos = self.Entity:GetPos() + self.flightvector
trace.filter = self.Entity
local tr = util.TraceLine( trace )
if tr.HitSky then
self.Entity:Remove()
return true
end
if tr.Hit and !tr.Entity:IsPlayer() and !tr.Entity:IsNPC() then
util.BlastDamage(self.Entity, self.Owner, tr.HitPos, 50, 50)
local effectdata = EffectData()
effectdata:SetOrigin(tr.HitPos)
effectdata:SetNormal(tr.HitNormal)
effectdata:SetScale(1)
effectdata:SetRadius(1)
util.Effect( "gdcw_impact", effectdata )
util.ScreenShake(tr.HitPos, 10, 5, 0.3, 150 )
util.Decal("ExplosiveGunshot", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
end
if tr.Hit and tr.Entity:IsPlayer() || tr.Entity:IsNPC() then
util.BlastDamage(self.Entity, self.Owner, tr.HitPos, 70, 65)
end
local trace = {}
trace.start = tr.HitPos + self.flightvector:GetNormalized() * 12
trace.endpos = tr.HitPos
trace.filter = self.Entity
local pr = util.TraceLine( trace )
if tr.Hit and !pr.Hit || tr.Hit and pr.Hit and (tr.HitPos:Distance(pr.HitPos))==0 then
self.Entity:Remove()
end
if pr.Hit then
self.penetrate = self.penetrate - (tr.HitPos:Distance(pr.HitPos))
end
if self.penetrate<0 then
self.exploded = true
self.Entity:Remove()
return true
end
if pr.Hit and self.penetrate>0 and !pr.Entity:IsPlayer() and !pr.Entity:IsNPC() then
util.BlastDamage(self.Entity, self.Owner, pr.HitPos, 50, 50)
self.Entity:SetPos(pr.HitPos + self.flightvector:GetNormalized()*5)
local effectdata = EffectData()
effectdata:SetOrigin(pr.HitPos)
effectdata:SetNormal(self.flightvector:GetNormalized())
effectdata:SetScale(1)
effectdata:SetRadius(1)
util.Effect( "gdcw_penetrate", effectdata )
util.ScreenShake(tr.HitPos, 10, 5, 0.3, 150 )
util.Decal("ExplosiveGunshot", pr.HitPos + pr.HitNormal, pr.HitPos - pr.HitNormal)
end
if tr.Entity:IsValid() and !tr.Entity:IsPlayer() and !tr.Entity:IsNPC() then
local effectdata = EffectData()
effectdata:SetOrigin(tr.HitPos)
effectdata:SetStart(tr.HitPos)
util.Effect( "gdca_sparks", effectdata )
end
if !pr.Hit then
self.Entity:SetPos(self.Entity:GetPos() + self.flightvector)
end
self.flightvector = self.flightvector - self.flightvector/100 + Vector(math.Rand(-0.3,0.3), math.Rand(-0.3,0.3),math.Rand(-0.3,0.3)) + Vector(0,0,-0.06)
self.Entity:SetAngles(self.flightvector:Angle() + Angle(90,0,0))
self.Entity:NextThink( CurTime() )
return true
end
[/lua]
That's the server side init file. cl_init and shared shouldn't matter because they don't really do anything important. This is a base_anim entity. Don't bother trying to figure it out, most of the stuff is for impacts and penetration.
That is a horrible mangle of bad code, but I can't see anything that would cause that problem.
Sorry, you need to Log In to post a reply to this thread.