• Remove entities after a few secounds.
    10 replies, posted
  • [B]Hello! I have added a helicopter entity to my DarkRP server, but when it crashes / explode, it wont remove the 2 props it leaves behind, is there way to make the props disappear after a few seconds ? SakariasHelicopter init.lua[/B] [lua] AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include('shared.lua') ENT.SmokeTimer = CurTime() ENT.TopProp = NULL ENT.BackProp = NULL ENT.Unbalance = NULL ENT.PlyUser = NULL ENT.Gunner = 1 ENT.PlyUsers = {} ENT.Seats = {} ENT.OccupiedSeats = {} ENT.CanFly = 0 ENT.PropellerForceDel = CurTime() ENT.TakeForceDelOnce = 0 ENT.RotorDustEffectOnce = 0 ENT.RotorDustEffect = NULL ENT.SoundLoopDelay = CurTime() ENT.StopSoundOnce = 0 ENT.HeliStart = NULL ENT.HeliStop = NULL ENT.HeliExt = NULL ENT.HeliInt = NULL ENT.MissileAlert = NULL ENT.MissileAlertDel = CurTime() ENT.MissileShootDel = CurTime() ENT.CrashAlarmDel = CurTime() ENT.BladesAlarmDel = CurTime() ENT.LowHealthDel = CurTime() ENT.HeliCreakDel = CurTime() ENT.CrashAlarm = NULL ENT.LowHealth = NULL ENT.MinorAlarm = NULL ENT.MissileShoot = NULL ENT.MissileShootTimer = CurTime() ENT.SpawnMissiles = 0 ENT.SpawnLaserMissileDel = CurTime() ENT.SpawnLaserMissileRelSound = 1 ENT.UpdateLaserPosDel = CurTime() ENT.SpawnMissileRelSound = 1 ENT.ShootBulletSoundDel = CurTime() ENT.ShootSound = NULL ENT.StopShootSound = NULL ENT.ShootStopSoundOnce = 1 ENT.BulletDel = CurTime() ENT.WeaponType = 1 ENT.Seat = NULL ENT.SeatTwo = NULL ENT.SeatThree = NULL ENT.SeatFour = NULL ENT.TopPropellerHealth = 100 ENT.ChopperHealth = 300 ENT.PropSpeedDel = 0 ENT.FireEffectOnce = 0 ENT.SmokeEffectOnce = 0 ENT.RedDotLaser = 1 --Damage ENT.RemoveTopPropOnce = 0 ENT.MediumDamageEffect = 0 ENT.TakeHealth = CurTime() ENT.DieOnce = 0 ENT.CrashOnce = 0 ENT.CrashVector = NULL ENT.OldSpeed = 0 ------------------------------------VARIABLES END function ENT:SpawnFunction( ply, tr ) --------Spawning the entity and getting some sounds i use. if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * 10 + Vector(0,0,200) local ent = ents.Create( "sent_SakariasHelicopter" ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() ent.Owner = ply self.PlyUsers[1] = ply ent.UserOne = ply return ent end function ENT:Initialize() self.Entity:SetModel("models/military2/air/air_h500.mdl") --self.Entity:SetMaterial("Glad/BlueEye.vtf") self.Entity:SetOwner(self.Owner) self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) local phys = self.Entity:GetPhysicsObject() if(phys:IsValid()) then phys:Wake() end self.TopProp = ents.Create( "prop_physics" ) self.TopProp:SetModel("models/military2/air/air_h500_r.mdl") --self.TopProp:SetAngles(self.Entity:GetAngles()) self.TopProp:SetPos(self.Entity:GetPos() + (self.Entity:GetUp() * 50)) self.TopProp:SetOwner(self.Owner) self.TopProp:Spawn() self.TopProp.IsHeliPart = 1 --self.TopProp:GetPhysicsObject():SetMass(200) self.BackProp = ents.Create( "prop_physics" ) self.BackProp:SetModel("models/military2/air/air_h500_sr.mdl") --self.BackProp:SetAngles(self.Entity:GetAngles()) self.BackProp:SetPos(self.Entity:GetPos() + (self.Entity:GetForward() * -185) + (self.Entity:GetUp() * 13) + (self.Entity:GetRight() * -3) ) self.BackProp:SetOwner(self.Owner) self.BackProp:Spawn() self.BackProp.IsHeliPart = 2 --Spawning a new seat self.Seats[1] = ents.Create("prop_vehicle_prisoner_pod") self.Seats[1]:SetKeyValue("vehiclescript","scripts/vehicles/HeliSeat.txt") self.Seats[1]:SetModel( "models/nova/airboat_seat.mdl" ) self.Seats[1]:SetPos( self.Entity:GetPos() + ( self.Entity:GetForward() * 28 ) + ( self.Entity:GetRight() * -14.5 ) + ( self.Entity:GetUp() * -14 ) ) self.Seats[1]:SetAngles(self.Entity:GetAngles() + Angle(0,-90,0)) self.Seats[1]:SetKeyValue("limitview", "0") self.Seats[1]:SetColor(255,255,255,0) self.Seats[1]:Spawn() self.Seats[1]:GetPhysicsObject():EnableGravity(true); self.Seats[1]:GetPhysicsObject():SetMass(1) self.Entity.SeatOne = self.Seats[1] self.Seats[1].EntOwner = self.Entity self.Seats[1].SeatNum = 1 self.Entity.UseSeatOne = 0 -- --Spawning a new seatTwo self.Seats[2] = ents.Create("prop_vehicle_prisoner_pod") self.Seats[2]:SetKeyValue("vehiclescript","scripts/vehicles/HeliSeat.txt") self.Seats[2]:SetModel( "models/nova/airboat_seat.mdl" ) self.Seats[2]:SetPos( self.Entity:GetPos() + ( self.Entity:GetForward() * 28 ) + ( self.Entity:GetRight() * 14.5 ) + ( self.Entity:GetUp() * -14 ) ) self.Seats[2]:SetAngles(self.Entity:GetAngles() + Angle(0,-90,0)) self.Seats[2]:SetKeyValue("limitview", "0") self.Seats[2]:SetColor(255,255,255,0) self.Seats[2]:Spawn() self.Seats[2]:GetPhysicsObject():EnableGravity(true); self.Seats[2]:GetPhysicsObject():SetMass(1) self.Entity.SeatTwo = self.Seats[2] self.Seats[2].EntOwner = self.Entity self.Seats[2].SeatNum = 2 self.Entity.UseSeatTwo = 0 -- --Spawning a new seatThree self.Seats[3] = ents.Create("prop_vehicle_prisoner_pod") self.Seats[3]:SetKeyValue("vehiclescript","scripts/vehicles/HeliSeat.txt") self.Seats[3]:SetModel( "models/nova/airboat_seat.mdl" ) self.Seats[3]:SetPos( self.Entity:GetPos() + ( self.Entity:GetForward() * -10 ) + ( self.Entity:GetRight() * 10 ) + ( self.Entity:GetUp() * -14 ) ) self.Seats[3]:SetAngles(self.Entity:GetAngles() + Angle(0,-90,0)) self.Seats[3]:SetKeyValue("limitview", "0") self.Seats[3]:SetColor(255,255,255,0) self.Seats[3]:Spawn() self.Seats[3]:GetPhysicsObject():EnableGravity(true); self.Seats[3]:GetPhysicsObject():SetMass(1) self.Entity.SeatThree = self.Seats[3] self.Seats[3].EntOwner = self.Entity self.Seats[3].SeatNum = 3 self.Entity.UseSeatThree = 0 -- --Spawning a new seatFour self.Seats[4] = ents.Create("prop_vehicle_prisoner_pod") self.Seats[4]:SetKeyValue("vehiclescript","scripts/vehicles/HeliSeat.txt") self.Seats[4]:SetModel( "models/nova/airboat_seat.mdl" ) self.Seats[4]:SetPos( self.Entity:GetPos() + ( self.Entity:GetForward() * -10 ) + ( self.Entity:GetRight() * -10 ) + ( self.Entity:GetUp() * -14 ) ) self.Seats[4]:SetAngles(self.Entity:GetAngles() + Angle(0,-90,0)) self.Seats[4]:SetKeyValue("limitview", "0") self.Seats[4]:SetColor(255,255,255,0) self.Seats[4]:Spawn() self.Seats[4]:GetPhysicsObject():EnableGravity(true); self.Seats[4]:GetPhysicsObject():SetMass(1) self.Entity.SeatFour = self.Seats[4] self.Seats[4].EntOwner = self.Entity self.Seats[4].SeatNum = 4 self.Entity.UseSeatFour = 0 -- local Lpos1 = self.Entity:GetLocalPos() local Wpos1 = self.Entity:GetPos() local Lpos2 = self.BackProp:GetLocalPos() local Wpos2 = self.BackProp:GetPos() constraint.Weld( self.Entity, self.Seats[1], 0, 0, 0, 1 ) constraint.Weld( self.Entity, self.Seats[2], 0, 0, 0, 1 ) constraint.Weld( self.Entity, self.Seats[3], 0, 0, 0, 1 ) constraint.Weld( self.Entity, self.Seats[4], 0, 0, 0, 1 ) --constraint.Weld( self.Entity, self.BackProp, 0, 0, 0, 1 ) constraint.Axis( self.Entity, self.TopProp, 0, 0, (Vector(0,0,0)), Vector(0,0,0) , 0, 0, 0, 1 ) constraint.Axis( self.Entity, self.BackProp, 0, 0, Vector(-185,-3,13) , Vector(0,0,0), 0, 0, 1, 1 ) --Vector(-185,13,-3) constraint.Keepupright( self.TopProp, Angle(0,0,0), 0, 15 ) --constraint.Axis( Entity Ent1, Entity Ent2, number Bone1, number Bone2, Vector LPos1, Vector LPos2, number forcelimit, number torquelimit, number friction, number nocollide ) self.HeliStart = CreateSound(self.Entity,"HelicopterVehicle/HeliStart.mp3") self.HeliStop = CreateSound(self.Entity,"HelicopterVehicle/HeliStop.mp3") self.HeliExt = CreateSound(self.Entity,"HelicopterVehicle/HeliLoopExt.mp3") self.HeliInt = CreateSound(self.Entity,"HelicopterVehicle/HeliLoopInt.mp3") self.MissileAlert = CreateSound(self.Entity,"HelicopterVehicle/MissileNearby.mp3") self.ShootSound = CreateSound(self.Entity,"HelicopterVehicle/Shooting.mp3") self.StopShootSound = CreateSound(
  • Avatar of Commander11
  • When you create the entities you could use [lua] timer.Simple(5, function() entity:Remove(); end) [/lua]
  • Avatar of Rimbas
  • [QUOTE=Commander11;34622599]When you create the entities you could use [lua] timer.Simple(5, function() entity:Remove(); end) [/lua][/QUOTE] like this [lua] function ENT:Initialize() timer.Simple(5, function() self:Remove() end) end [/lua]
  • Thanks for the support! I have pasted your codes in where i thought i should, but it seems to that i have pasted the code in wrong :/, where would you paste the code in ? and thanks for your interest!
  • Avatar of Wizard of Ass
  • [QUOTE=Commander11;34622599]When you create the entities you could use [lua] timer.Simple(5, function() entity:Remove(); end) [/lua][/QUOTE] Shit way. [lua] timer.Simple(1, _R.Entity.Remove, entity)[/lua] Proper way.
  • Avatar of raBBish
  • [QUOTE=Wizard of Ass;34624169]Shit way. [lua] timer.Simple(_R.Entity.Remove, entity)[/lua] Proper way.[/QUOTE] [lua]SafeRemoveEntityDelayed( ent, 5 )[/lua] [img]http://www.facepunch.com/fp/emoot/smug.gif[/img]
  • Avatar of Wizard of Ass
  • [QUOTE=raBBish;34624990][lua]SafeRemoveEntityDelayed( ent, 5 )[/lua] [img]http://www.facepunch.com/fp/emoot/smug.gif[/img][/QUOTE] [lua] /*--------------------------------------------------------- Safely remove an entity ---------------------------------------------------------*/ function SafeRemoveEntity( ent ) if ( !ent || !ent:IsValid() || ent:IsPlayer() ) then return end ent:Remove() end /*--------------------------------------------------------- Safely remove an entity (delayed) ---------------------------------------------------------*/ function SafeRemoveEntityDelayed( ent, timedelay ) if (!ent || !ent:IsValid()) then return end timer.Simple( timedelay, function() SafeRemoveEntity( ent ) end ) end [/lua] [QUOTE=Wizard of Ass;34624169] [lua] timer.Simple(1, _R.Entity.Remove, entity)[/lua] Proper way.[/QUOTE]
  • Avatar of raBBish
  • [QUOTE=Wizard of Ass;34625333]-stuff-[/QUOTE] Reinventing the wheel and no error checking? No thanks. Actually on topic: I assume the two props are TopProp and BackProp. They're removed in ENT:Remove if they're valid, so I'm not really sure why they wouldn't get removed...
  • [QUOTE=raBBish;34625494]Reinventing the wheel and no error checking? No thanks. Actually on topic: I assume the two props are TopProp and BackProp. They're removed in ENT:Remove if they're valid, so I'm not really sure why they wouldn't get removed...[/QUOTE] Exactly! its really strange..