• Addon spamming info entities causing engine crash
    1 replies, posted
I'm spawning info entities, but I shouldn't be spawning thousands. I can't quite spot out where the entities are being spammed and how to fix it, so I'm here. Thank you in advance. [CODE] --[[ ©2016 Metamorphics (STEAM_0:1:52851671 is the one and only author) Do not reupload this addon even if you made modifications. ]]-- AddCSLuaFile() SWEP.PrintName = "The Flash SWEP" SWEP.Author = "Metamorphics" SWEP.Instructions = "Shift to run. Left click to punch. Right click for slow motion." SWEP.Category = "The Flash Redux" SWEP.Spawnable = true SWEP.AdminOnly = false SWEP.ViewModel = "models/weapons/c_arms.mdl" SWEP.WorldModel = "" SWEP.Base = "weapon_base" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.speedmod = false SWEP.timemod = false SWEP.jumpcd = 0 SWEP.modAcceleration = 0.5 SWEP.HoldType = "normal" SWEP.TrailMaterial = "trails/laser.vmt" -----------------------------------------------Intialization----------------------------------------------- if SERVER then hook.Add( "OnEntityCreated", "PlayerTrail", function( player ) if ( player:IsPlayer() ) then player.Trail0 = NULL player.Trail1 = NULL player.Trail2 = NULL player.Trail3 = NULL player.Trail4 = NULL player.Trail5 = NULL player.Trail6 = NULL player.Trail7 = NULL player.Trail8 = NULL player.Trail9 = NULL player.Trail10 = NULL player.Trail11 = NULL player.Blur0 = NULL end end) end function SWEP:Deploy() local owner = self.Owner self:SetNetworkedInt( "DCFOV", self.Owner:GetFOV() ) self.Owner:SetMaxSpeed(10000) self:SetHoldType(self.HoldType) self.Owner:SetFOV(120, 0.5) self.speedmod = true if SERVER then self.TrailTarget0 = ents.Create('info_target') self.TrailTarget0:Spawn() self.TrailTarget1 = ents.Create('info_target') self.TrailTarget1:Spawn() self.TrailTarget2 = ents.Create('info_target') self.TrailTarget2:Spawn() self.TrailTarget3 = ents.Create('info_target') self.TrailTarget3:Spawn() self.TrailTarget4 = ents.Create('info_target') self.TrailTarget4:Spawn() self.TrailTarget5 = ents.Create('info_target') self.TrailTarget5:Spawn() self.TrailTarget6 = ents.Create('info_target') self.TrailTarget6:Spawn() self.TrailTarget7 = ents.Create('info_target') self.TrailTarget7:Spawn() self.TrailTarget8 = ents.Create('info_target') self.TrailTarget8:Spawn() self.TrailTarget9 = ents.Create('info_target') self.TrailTarget9:Spawn() self.TrailTarget10 = ents.Create('info_target') self.TrailTarget10:Spawn() end end function SWEP:Holster() self.Owner:SetRunSpeed(400) self.Owner:SetFOV(self:GetNetworkedInt("DCFOV"), 0.5) self.Owner:SetWalkSpeed(200) self.Owner:SetJumpPower(200) self.speedmod = false self.CanPlayLightning = false if ( SERVER ) then local owner = self:GetOwner() game.SetTimeScale(1) if ( owner:IsValid() and owner.Trail0:IsValid() and self.TrailTarget0:IsValid() ) then owner.Trail0:Remove() owner.Trail1:Remove() owner.Trail2:Remove() owner.Trail3:Remove() owner.Trail4:Remove() owner.Trail5:Remove() owner.Trail6:Remove() owner.Trail7:Remove() owner.Trail8:Remove() owner.Trail9:Remove() owner.Trail10:Remove() owner.Trail11:Remove() //owner.Blur0:Remove() self.TrailTarget0:Remove() self.TrailTarget1:Remove() self.TrailTarget2:Remove() self.TrailTarget3:Remove() self.TrailTarget4:Remove() self.TrailTarget5:Remove() self.TrailTarget6:Remove() self.TrailTarget7:Remove() self.TrailTarget8:Remove() self.TrailTarget9:Remove() self.TrailTarget10:Remove() end end return true end function SWEP:DrawHUD() Width = surface local Speed = tostring(math.Round(self.Owner:GetVelocity():Length())) local tachyonequipstatus = tostring(self.Owner:GetNWBool( "Tachyon Status", false )) draw.SimpleText("Speed: ".. Speed, "ChatFont", 8, 8, Color(255,255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER ) draw.SimpleText("Tachyon Device: "..tachyonequipstatus, "ChatFont", 8, 24, Color(255,255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER ) draw.SimpleText("Version: 2.0 [dev]", "ChatFont", ScrW()-128, 8, Color(255,255,255,255), TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER ) end -----------------------------------------------Attacks----------------------------------------------- function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire(CurTime() + 0.05) self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER) self.Owner:SetAnimation(PLAYER_ATTACK1) local trace = self.Owner:GetEyeTrace() vel = self.Owner:GetVelocity():Length() if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 then bullet = {} bullet.Num = 1 bullet.Damage = vel*0.1 bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector(0, 0, 0) bullet.Tracer = 0 bullet.Force = 100000000000000000 self.Owner:FireBullets(bullet) self.Weapon:SendWeaponAnim( PLAYER_ATTACK1 ); if SERVER then local hitposent = ents.Create("info_target") local trace = self.Owner:GetEyeTrace() local hitpos = trace.HitPos local tr = {} tr.start = self.Owner:GetShootPos() tr.endpos = self.Owner:GetShootPos() + ( self.Owner:GetAimVector() * 50 ) tr.filter = self.Owner tr.mask = MASK_SHOT local trac = util.TraceLine( tr ) if ( trac.Hit ) then return end self.Weapon:SendWeaponAnim(PLAYER_ATTACK1) end end end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + 0.2 ) if (SERVER) then self.timemod = !self.timemod if self.timemod == true then game.SetTimeScale(0.2) elseif self.timemod == false then game.SetTimeScale(1) end end end -----------------------------------------------Trails----------------------------------------------- function SWEP:TrailFollow() local owner = self:GetOwner() self.BoneID0 = owner:LookupBone("ValveBiped.Bip01_Spine") self.BoneID1 = owner:LookupBone("ValveBiped.Bip01_L_Thigh") self.BoneID2 = owner:LookupBone("ValveBiped.Bip01_R_Thigh") self.BoneID3 = owner:LookupBone("ValveBiped.Bip01_L_Calf") self.BoneID4 = owner:LookupBone("ValveBiped.Bip01_R_Calf") self.BoneID5 = owner:LookupBone("ValveBiped.Bip01_L_Foot") self.BoneID6 = owner:LookupBone("ValveBiped.Bip01_R_Foot") self.BoneID7 = owner:LookupBone("ValveBiped.Bip01_Spine2") self.BoneID8 = owner:LookupBone("ValveBiped.Bip01_L_UpperArm") self.BoneID9 = owner:LookupBone("ValveBiped.Bip01_R_UpperArm") self.BoneID10 = owner:LookupBone("ValveBiped.Bip01_Pelvis") self.Pos0 = owner:GetBonePosition( self.BoneID0 ) self.Pos1 = owner:GetBonePosition( self.BoneID1 ) self.Pos2 = owner:GetBonePosition( self.BoneID2 ) self.Pos3 = owner:GetBonePosition( self.BoneID3 ) self.Pos4 = owner:GetBonePosition( self.BoneID4 ) self.Pos5 = owner:GetBonePosition( self.BoneID5 ) self.Pos6 = owner:GetBonePosition( self.BoneID6 ) self.Pos7 = owner:GetBonePosition( self.BoneID7 ) self.Pos8 = owner:GetBonePosition( self.BoneID8 ) self.Pos9 = owner:GetBonePosition( self.BoneID9 ) self.Pos10 = owner:GetBonePosition( self.BoneID10 ) self.TrailTarget0:SetPos( self.Pos0 ) self.TrailTarget1:SetPos( self.Pos1 ) self.TrailTarget2:SetPos( self.Pos2 ) self.TrailTarget3:SetPos( self.Pos3 ) self.TrailTarget4:SetPos( self.Pos4 ) self.TrailTarget5:SetPos( self.Pos5 ) self.TrailTarget6:SetPos( self.Pos6 ) sel
SWEP:Holster() isn't fully reliable for removing the entities, like if the player dies. That stuff should be in SWEP:OnRemove(), or both (specially in this case) Or simply have the weapon check if the entities already exist before spawning them, that way you pretty much dont have to change anything par adding one if statement to check one of them. Would be nice to know more, like how long does it take for the crash to happen etc, but i'm guessing that your server runs for a while with players using it before it will crash. Either of these 2 should work for you. Enjoy~
Sorry, you need to Log In to post a reply to this thread.